:root {
  --bg: #0f0d22;
  --bg-2: #17142f;
  --panel: #1d1a3a;
  --panel-2: #29254f;
  --line: rgba(255, 255, 255, 0.09);
  --text: #f4efe6;
  --muted: #a8a3c9;
  --sand: #f6e7c8;
  --sand-edge: #b98d4f;
  --sand-ink: #2a1c0c;
  --sun: #ffc145;
  --sun-2: #ff8a3d;
  --moon: #7cc4ff;
  --sun-ink: #9a4a0a;
  --moon-ink: #1f5fbf;
  --bad: #ff5470;
  /* Every button has a thick lower edge, like the letter tiles, and sinks into it when pressed. */
  --btn-edge: #14112b;
  --sun-edge: #b9792a;
  --moon-edge: #3f7fbf;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
.sprites { position: absolute; }

body {
  margin: 0;
  min-height: 100dvh;
  font-family: "Noto Kufi Arabic", system-ui, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1000px 520px at 50% -12%, rgba(124, 92, 255, 0.24), transparent 70%),
    radial-gradient(1.5px 1.5px at 14% 22%, rgba(255, 255, 255, 0.55), transparent),
    radial-gradient(1.5px 1.5px at 78% 12%, rgba(255, 255, 255, 0.45), transparent),
    radial-gradient(1px 1px at 62% 34%, rgba(255, 255, 255, 0.5), transparent),
    radial-gradient(1px 1px at 30% 70%, rgba(255, 255, 255, 0.35), transparent),
    radial-gradient(1.5px 1.5px at 88% 64%, rgba(255, 255, 255, 0.35), transparent),
    var(--bg);
  background-attachment: fixed;
}

.screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.panel {
  width: 100%;
  max-width: 440px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 28px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
}
.panel.wide { max-width: 720px; }

.logo {
  font-family: Lalezar, serif;
  font-weight: 400;
  font-size: 54px;
  line-height: 1.15;
  margin: 0;
  color: var(--sand);
}
.lead { color: var(--muted); margin: 4px 0 24px; }
.eyebrow { margin: 0; font-size: 13px; color: var(--muted); }
.muted { color: var(--muted); text-align: center; margin: 14px 0 0; }

.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field span { font-size: 14px; color: var(--muted); }

input {
  width: 100%;
  height: 50px;
  padding: 0 14px;
  font: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
}
input:focus-visible { outline: 2px solid var(--sun); outline-offset: 1px; }

.btn {
  height: 50px;
  padding: 0 20px;
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--edge, var(--btn-edge));
  transition: filter 0.12s, transform 0.08s, box-shadow 0.08s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(4px); box-shadow: 0 0 0 var(--edge, var(--btn-edge)); }
button:focus-visible, a.btn:focus-visible { outline: 2px solid var(--sun); outline-offset: 2px; }
.btn:disabled { opacity: 0.45; cursor: default; filter: none; transform: none; box-shadow: 0 4px 0 var(--edge, var(--btn-edge)); }
.btn.primary {
  --edge: var(--sun-edge);
  width: 100%;
  color: #2b1300;
  background: var(--sun);
  border: 0;
}
.btn.sand {
  --edge: var(--sand-edge);
  color: var(--sand-ink);
  background: var(--sand);
  border: 0;
}
a.btn { display: inline-grid; place-items: center; text-decoration: none; }
.btn.small { height: 40px; font-size: 14px; box-shadow: 0 3px 0 var(--edge, var(--btn-edge)); }
.btn.small:active { transform: translateY(3px); box-shadow: 0 0 0 var(--edge, var(--btn-edge)); }
.btn.link, .btn.link:active {
  box-shadow: none;
  transform: none;
}
.btn.link {
  display: block;
  height: auto;
  margin: 10px auto 0;
  padding: 6px 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  background: none;
  border: 0;
  text-decoration: underline;
  text-underline-offset: 6px;
}

.sound-toggle {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 11px;
  box-shadow: 0 3px 0 var(--btn-edge);
  cursor: pointer;
}
.sound-toggle svg { width: 21px; height: 21px; }
.sound-toggle[aria-pressed="false"] { color: var(--muted); }
.sound-toggle:active { transform: translateY(3px); box-shadow: none; }

.home-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }

/* Your snake, moving, before you've even joined a room. */
.my-snake { display: grid; gap: 6px; margin-bottom: 16px; }
.my-snake .eyebrow { font-size: 14px; }
#snake-preview { display: block; width: 100%; height: 56px; background: var(--bg-2); border-radius: 14px; }
#home-skins { justify-content: space-between; flex-wrap: nowrap; }

.offscreen { position: fixed; top: 0; opacity: 0; }
.invited { margin: 0 0 12px; }
/* Long text, like an email address, wraps instead of making the panel wider than the screen. */
#home { grid-template-columns: minmax(0, 1fr); }
.stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.stack .field, .stack .invited, .stack .notice, .stack .setting-hint { margin: 0; }
.stack .btn.link { margin: 0 auto; }
#code-sent { overflow-wrap: anywhere; }
.code-input { text-align: center; letter-spacing: 0.4em; font-size: 22px; font-weight: 800; }
.signed-in { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 12px; margin: 0 0 12px; font-size: 14px; color: var(--muted); }
.signed-in b { color: var(--text); overflow-wrap: anywhere; }
.signed-in .btn.link { margin: 0; }
.invited b { color: var(--sun); letter-spacing: 0.15em; }

.or {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0 10px;
  font-size: 13px;
  color: var(--muted);
}
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.join-row { display: flex; gap: 8px; }
.join-row input { text-align: center; text-transform: uppercase; letter-spacing: 0.3em; font-weight: 700; }
.join-row .btn { flex: none; }

.error { min-height: 1.4em; margin: 12px 0 0; font-size: 14px; color: var(--bad); }

.rules {
  display: grid;
  gap: 8px;
  margin: 8px 0 0;
  padding: 18px 0 0;
  list-style: none;
  font-size: 14px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  counter-reset: rule;
}
.rules li { display: flex; gap: 10px; align-items: baseline; counter-increment: rule; }
.rules li::before {
  content: counter(rule, arabic-indic);
  flex: none;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  font-size: 12px;
  font-weight: 800;
  color: var(--sand-ink);
  background: var(--sand);
  border-radius: 7px;
}

/* Lobby */
.lobby-head { display: flex; justify-content: space-between; align-items: end; gap: 16px; flex-wrap: wrap; }
#room-code {
  margin: 0;
  font-family: Lalezar, serif;
  font-weight: 400;
  font-size: 46px;
  line-height: 1.1;
  letter-spacing: 0.12em;
  color: var(--sand);
}
.invite-actions { display: flex; flex: 1 1 280px; gap: 8px; max-width: 380px; }
.invite-actions .btn { padding: 0 12px; font-size: 15px; white-space: nowrap; }
#share-link { flex: 1.3; }
#copy-link { flex: 1; }
.invite-link {
  margin: 10px 0 20px;
  font-size: 13px;
  color: var(--muted);
  direction: ltr;
  text-align: right;
  word-break: break-all;
  user-select: all;
}

.teams { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 18px; }
.team {
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 16px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--c) 14%, var(--bg-2)), var(--bg-2) 55%);
  border: 1px solid color-mix(in srgb, var(--c) 30%, transparent);
  border-radius: 18px;
}
.sun { --c: var(--sun); }
.moon { --c: var(--moon); }
.team h3 { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 17px; color: var(--c); }
.team h3 svg, .team-name svg { width: 22px; height: 22px; flex: none; }

.team-edit { display: flex; flex: 1; align-items: center; gap: 6px; min-width: 0; cursor: text; }
.team-input {
  flex: 1;
  min-width: 0;
  height: 32px;
  padding: 0 2px;
  font-size: 17px;
  font-weight: 700;
  color: var(--c);
  background: transparent;
  border: 0;
  border-bottom: 1px dashed color-mix(in srgb, var(--c) 55%, transparent);
  border-radius: 0;
}
.team-input:focus-visible { outline: none; border-bottom: 1px solid var(--c); }
.team-edit .pencil { width: 16px; height: 16px; opacity: 0.7; }

.slots { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.slots li {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 46px;
  padding: 0 14px;
  font-weight: 600;
  background: var(--panel-2);
  border-radius: 12px;
}
.player-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slots .tag, .people .tag { flex: none; }
.slots li.open {
  font-weight: 400;
  color: var(--muted);
  background: transparent;
  border: 1px dashed rgba(255, 255, 255, 0.16);
}
.tag {
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.08);
  border-radius: 99px;
}
.tag.you { color: #1a1230; background: var(--c); }
.tag.away { color: var(--bad); background: rgba(255, 84, 112, 0.14); }

.notice {
  margin: 0 0 14px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  background: var(--panel-2);
  border-radius: 12px;
}

/* Shows on top of whatever is on screen while the connection comes back. */
#reconnecting {
  position: fixed;
  top: 12px;
  inset-inline: 0;
  z-index: 20;
  width: fit-content;
  margin: 0 auto;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 700;
  color: var(--sand-ink);
  background: var(--sand);
  border-radius: 99px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
}

#shuffle { display: block; width: 100%; margin: 0 0 18px; }

/* Everyone in the room who isn't on a team: side by side, under the teams. */
.sidelines { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin: 0 0 18px; }
.sideline {
  --c: var(--sand);
  display: grid;
  align-content: start;
  gap: 10px;
  min-width: 0;
  padding: 16px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 18px;
}
.sideline-head { display: flex; align-items: center; gap: 8px; }
.sideline h3 { margin: 0; font-size: 16px; }
.people { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.people li {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
  min-height: 44px;
  padding: 4px;
  padding-inline: 12px 8px;
  font-weight: 600;
  background: var(--panel-2);
  border-radius: 12px;
}
.move {
  flex: none;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: 9px;
  cursor: pointer;
}
.slots .move { margin-inline-start: auto; }
.move svg { width: 18px; height: 18px; }
.move:hover, .move[aria-expanded="true"] { color: var(--text); filter: brightness(1.25); }

#move-menu {
  position: fixed;
  z-index: 10;
  display: grid;
  gap: 2px;
  width: max-content;
  min-width: 180px;
  max-width: calc(100vw - 16px);
  max-height: calc(100dvh - 16px);
  overflow: auto;
  padding: 6px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}
#move-menu h4 { margin: 6px 8px 2px; font-size: 12px; font-weight: 600; color: var(--muted); }
#move-menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 40px;
  padding: 0 8px;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  text-align: start;
  color: var(--text);
  background: none;
  border: 0;
  border-radius: 9px;
  cursor: pointer;
}
#move-menu button:hover, #move-menu button:focus-visible { background: rgba(255, 255, 255, 0.09); outline: none; }
#move-menu svg { width: 18px; height: 18px; flex: none; color: var(--c); }

.skins { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 0 0 16px; }
.skin-row { display: flex; gap: 8px; flex-wrap: wrap; }
.skin {
  width: 34px;
  height: 34px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 50%;
  background-clip: padding-box;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);
  cursor: pointer;
}
.skin[aria-pressed="true"] { border-color: var(--text); }
.skin { position: relative; }
.skin .lock { display: none; }
.skin.locked .lock {
  display: block;
  position: absolute;
  inset-inline-end: -5px;
  bottom: -5px;
  width: 17px;
  height: 17px;
  padding: 3px;
  color: var(--sand-ink);
  background: var(--sun);
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--panel);
}

/* The buy sheet. */
.sheet {
  width: min(360px, calc(100vw - 32px));
  padding: 22px 22px 18px;
  color: var(--text);
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}
.sheet::backdrop { background: rgba(8, 6, 20, 0.72); }
.sheet canvas { display: block; width: 100%; height: 76px; margin: 0 0 6px; }
.sheet h2 { margin: 0; font-size: 24px; }
.sheet .price { margin: 4px 0 10px; font-size: 20px; font-weight: 800; color: var(--sun); }
.sheet .setting-hint { margin: 0 0 4px; font-size: 14px; line-height: 1.7; }
.sheet .error { margin: 0 0 8px; }
.sheet .error:empty { min-height: 0; }
.receipt {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 6px 14px;
  margin: 4px 0 14px;
  padding: 12px 14px;
  font-size: 13px;
  text-align: start;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.receipt dt { color: var(--muted); }
.receipt dd { margin: 0; overflow-wrap: anywhere; }
.receipt .receipt-title { grid-column: 1 / -1; color: var(--text); font-weight: 700; }
.receipt .receipt-note { grid-column: 1 / -1; color: var(--muted); font-size: 12px; }
.swatch { width: 14px; height: 14px; flex: none; border-radius: 50%; }

.settings {
  display: grid;
  gap: 14px;
  margin: 0 0 18px;
  padding: 16px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 18px;
}
.settings h3 { margin: 0; font-size: 16px; }
#settings { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; }
.setting { display: grid; align-content: start; justify-items: start; gap: 6px; }
.setting.full { grid-column: 1 / -1; }
.setting-label { font-size: 14px; color: var(--muted); }
.setting-hint { margin: 0; font-size: 12px; color: var(--muted); }
.setting-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }

.stepper { display: inline-flex; align-items: center; gap: 6px; }
.stepper button {
  width: 36px;
  height: 36px;
  padding: 0;
  font: inherit;
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 2px 0 var(--btn-edge);
  cursor: pointer;
}
.stepper button:active { transform: translateY(2px); box-shadow: none; }
.stepper button:disabled { opacity: 0.35; cursor: default; transform: none; box-shadow: 0 2px 0 var(--btn-edge); }
.stepper input { width: 60px; height: 36px; padding: 0 4px; font-size: 15px; font-weight: 800; text-align: center; border-radius: 10px; }
.stepper .unit { font-size: 12px; color: var(--muted); }

.segmented { display: flex; flex-wrap: wrap; gap: 6px; }
.segmented button {
  height: 36px;
  padding: 0 14px;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 2px 0 var(--btn-edge);
  cursor: pointer;
}
.segmented button:active { transform: translateY(2px); box-shadow: none; }
.segmented button[aria-checked="true"] { color: #2b1300; background: var(--sun); border-color: var(--sun); box-shadow: 0 2px 0 var(--sun-edge); }
/* The settings are long, so starting the match stays within reach. */
#start { position: sticky; bottom: 12px; z-index: 1; }

.toggle { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); cursor: pointer; }
.toggle input { width: 20px; height: 20px; accent-color: var(--sun); }

/* Game */
/* The word on top, the board in the middle, one team on each side of it. */
#game {
  --side: clamp(150px, 17vw, 220px);
  grid-template-columns: var(--side) auto var(--side);
  grid-template-areas:
    "sound word end"
    "sun arena moon";
  justify-content: center;
  align-content: start;
  justify-items: stretch;
  align-items: start;
  gap: 12px 16px;
  padding-top: 16px;
}
:root[dir="ltr"] #game {
  grid-template-areas:
    "sound word end"
    "moon arena sun";
}
#game { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
#game[data-team="0"] { --mine: var(--sun); --mine-ink: #2b1300; --mine-edge: var(--sun-edge); }
#game[data-team="1"] { --mine: var(--moon); --mine-ink: #0c2a4a; --mine-edge: var(--moon-edge); }
#game .hint, #game-error { grid-column: 1 / -1; }

.hud { display: contents; }
#card-0 { grid-area: sun; }
#card-1 { grid-area: moon; }
.word-wrap { grid-area: word; }
.arena-wrap { grid-area: arena; justify-self: center; }

/* Only the host sees this. The first press asks, the second ends the match for everyone. */
#end-match { grid-area: end; justify-self: end; align-self: center; }
#end-match.armed { --edge: #a32a3f; color: #fff; background: var(--bad); border-color: transparent; }
#game-sound { grid-area: sound; justify-self: start; align-self: center; }

.team-card {
  display: grid;
  justify-items: start;
  gap: 10px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
}
.team-card.mine { border-color: var(--c); }
.team-name { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; font-weight: 800; color: var(--c); }
.team-name .tag { display: none; }
.team-card.mine .team-name .tag { display: inline-block; }

/* Who is on the team; a player fades while they wait to come back after a crash. */
.members { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; font-weight: 600; }
.member { display: flex; align-items: center; gap: 6px; transition: opacity 0.2s; }
.member.me { color: var(--sand); }
.member.out { opacity: 0.4; }
.member.away::after {
  content: attr(data-away);
  padding: 1px 6px;
  font-size: 10px;
  color: var(--bad);
  background: rgba(255, 84, 112, 0.14);
  border-radius: 99px;
}

.stats { display: grid; grid-template-columns: auto auto; justify-content: start; align-items: center; gap: 4px 12px; margin: 0; }
.stats dt { font-size: 12px; color: var(--muted); }
.stats dd { margin: 0; }
/* Words won, out of the words needed to win. */
.pips { display: flex; flex-wrap: wrap; gap: 6px; }
.pips.count { font-size: 14px; font-weight: 800; color: var(--c); }
.pips i { width: 14px; height: 14px; border: 2px solid var(--c); border-radius: 50%; opacity: 0.45; }
.pips i.on { background: var(--c); opacity: 1; }
/* The current word, with the letters this team has collected lit up. */
.letters { font-size: 20px; font-weight: 800; line-height: 1.5; white-space: nowrap; color: rgba(255, 255, 255, 0.22); }
.letters .on { color: var(--c); }

.word-wrap { display: flex; align-items: center; justify-content: center; gap: 14px; }
/* The word as a row of tiles. Done letters take the team colour, later ones stay dark, and the next letter is the only bright tile. */
.word { --t: 46px; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.word-tile {
  display: grid;
  place-items: center;
  width: var(--t);
  height: calc(var(--t) * 1.1);
  padding-bottom: 0.14em;
  font-size: calc(var(--t) * 0.62);
  font-weight: 800;
  line-height: 1;
  color: var(--sand-ink);
  background: var(--sand);
  border-radius: 22%;
  box-shadow: 0 3px 0 var(--sand-edge);
}
.word-tile.done { color: var(--mine-ink); background: var(--mine); box-shadow: 0 3px 0 var(--mine-edge); }
.word-tile.later { color: var(--muted); background: var(--panel-2); box-shadow: 0 3px 0 var(--btn-edge); }
.word-tile.next {
  position: relative;
  z-index: 1;
  outline: 3px solid var(--mine);
  outline-offset: 2px;
  transform: scale(1.1);
  animation: next-letter 1.1s ease-in-out infinite;
}
@keyframes next-letter { 50% { outline-offset: 5px; } }

#watching { padding: 5px 12px; font-size: 13px; }

.arena-wrap { position: relative; }
#arena {
  display: block;
  border-radius: 16px;
  box-shadow: 0 0 0 1px var(--line), 0 30px 80px rgba(0, 0, 0, 0.45);
  touch-action: none;
}

.over {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: safe center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  overflow: auto;
  overflow-x: hidden;
  background: var(--bg);
}
/* The report reads top to bottom: who won, the score, then each player. Everything shares one width, so it all lines up. */
.over-card { position: relative; display: grid; gap: 16px; width: 100%; max-width: 480px; }
.over h2 { margin: 0; font-family: Lalezar, serif; font-weight: 400; font-size: clamp(32px, 9vw, 44px); line-height: 1.2; text-align: center; color: var(--sand); animation: over-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) both; }
.over[data-winner="0"] h2 { color: var(--sun); }
.over[data-winner="1"] h2 { color: var(--moon); }
@keyframes over-pop { from { opacity: 0; transform: scale(0.7); } }

.over-score { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.score-side {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
  gap: 2px;
  padding: 12px 10px 8px;
  color: var(--c);
  background: var(--bg-2);
  border: 1px solid color-mix(in srgb, var(--c) 30%, transparent);
  border-radius: 16px;
}
.score-side.won { color: var(--ink); background: var(--c); border-color: var(--c); box-shadow: 0 5px 0 var(--edge); }
.score-side.sun.won { --ink: #2b1300; --edge: var(--sun-edge); }
.score-side.moon.won { --ink: #0c2a4a; --edge: var(--moon-edge); }
.score-side > svg { position: absolute; top: -14px; width: 28px; height: 28px; color: var(--sun); filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.45)); }
.score-side.sun.won > svg { color: var(--sand); }
.score-name { display: flex; align-items: center; justify-content: center; gap: 6px; max-width: 100%; font-size: 15px; font-weight: 800; }
.score-name svg { flex: none; width: 18px; height: 18px; }
.score-name span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-number { font-family: Lalezar, serif; font-weight: 400; font-size: 54px; line-height: 1.1; }

/* The one big moment: the word's own letters rain down on the winners. */
#over-rain { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
#over-rain i {
  position: absolute;
  top: calc(var(--size) * -1.4);
  inset-inline-start: var(--x);
  display: grid;
  place-items: center;
  width: var(--size);
  height: var(--size);
  font-size: calc(var(--size) * 0.66);
  font-style: normal;
  font-weight: 800;
  color: var(--sand-ink);
  background: var(--sand);
  border-radius: 24%;
  box-shadow: 0 3px 0 var(--sand-edge);
  animation: rain 2.1s cubic-bezier(0.45, 0.05, 0.75, 0.6) var(--delay) forwards;
}
#over-rain[data-letters="en"] i { font-family: Nunito, "Noto Kufi Arabic", system-ui, sans-serif; }
@keyframes rain { to { top: 105%; transform: rotate(var(--spin)); } }

/* Fixed columns: every number sits under its heading, level with its player's name, however much is written under the name. */
.stats-table { width: 100%; table-layout: fixed; border-collapse: collapse; font-size: 14px; }
.stats-table th { padding: 0 2px 6px; font-size: 12px; font-weight: 600; text-align: center; vertical-align: bottom; color: var(--muted); }
.stats-table th:not(:first-child) { width: clamp(46px, 14vw, 64px); }
.stats-table td { padding: 9px 2px; font-weight: 700; line-height: 22px; text-align: center; vertical-align: top; border-top: 1px solid var(--line); }
.stats-table th:first-child, .stats-table td:first-child { padding-inline-start: 10px; text-align: start; }
.stats-table tr.next-team td { border-top: 2px solid rgba(255, 255, 255, 0.22); }
.stats-table tr.me td { background: rgba(255, 255, 255, 0.05); }
.stats-table tr.me .player-name { color: var(--sand); }
.stats-table td.zero { font-weight: 600; color: var(--muted); }
.who { display: flex; align-items: center; gap: 8px; min-width: 0; height: 22px; }
.who .swatch { outline: 2px solid var(--c); outline-offset: 1px; }
.award { display: block; margin-top: 2px; margin-inline-start: 22px; font-size: 12px; font-weight: 600; line-height: 18px; color: var(--muted); }
.tag.best { flex: none; color: var(--sand-ink); background: var(--sand); }
.over-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.over-actions .btn { width: 100%; padding: 0 8px; }
.over .muted { margin: 0; }
/* Small phones held upright: the same report, a little tighter, so the buttons stay on screen. */
@media (max-height: 620px) and (orientation: portrait) {
  .over { padding-block: 10px; }
  .over-card { gap: 10px; }
  .over h2 { font-size: 28px; }
  .score-side { padding: 10px 8px 4px; }
  .score-number { font-size: 36px; }
  .stats-table td { padding: 5px 2px; line-height: 20px; }
  .who { height: 20px; }
  .award { margin-top: 0; line-height: 16px; }
  .over-actions .btn { height: 44px; }
}

.hint { margin: 0; font-size: 13px; color: var(--muted); text-align: center; }

/* On a touch screen the whole game steers by swiping, and the first countdown explains how. */
@media (pointer: coarse) {
  #game { touch-action: none; }
  .over { touch-action: pan-y; }
  #controls-hint { display: none; }
  body:has(#game:not([hidden])) { overscroll-behavior: none; }
}

@media (max-width: 720px) {
  .panel { padding: 22px; }
  .teams { grid-template-columns: 1fr; }
  .sidelines { grid-template-columns: 1fr; }
  #settings { grid-template-columns: 1fr; }
  .word { --t: 38px; }
}

/* Phones held upright: the word and scores take as little height as possible, and the board gets the rest. */
@media (orientation: portrait) and (max-width: 700px), (max-width: 700px) and (min-height: 521px) {
  #game {
    position: relative;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas:
      "word word"
      "sun moon"
      "arena arena";
    gap: 6px;
    padding: max(6px, env(safe-area-inset-top)) 6px 6px;
  }
  :root[dir="ltr"] #game {
    grid-template-areas:
      "word word"
      "moon sun"
      "arena arena";
  }
  .word-wrap { gap: 12px; min-height: 48px; }
  /* Six tiles fit between the sound button and End match. */
  .word { --t: clamp(24px, 7.8vw, 34px); gap: 4px; flex-wrap: nowrap; }
  /* No room for this note beside the word here, and someone watching can already see they have no snake. */
  #watching { display: none; }
  .word-tile.next { outline-width: 2px; }

  .team-card { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; padding: 3px 8px; border-radius: 10px; }
  .team-name > span, .members, .stats dt { display: none !important; }
  .team-name svg { width: 16px; height: 16px; }
  .stats { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; }
  .pips { gap: 3px; }
  .pips i { width: 9px; height: 9px; border-width: 1.5px; }
  .pips.count { font-size: 12px; }
  .letters { font-size: 15px; line-height: 1.5; }

  #end-match {
    position: absolute;
    top: max(6px, env(safe-area-inset-top));
    inset-inline-end: 6px;
    z-index: 1;
    width: 74px;
    height: 44px;
    padding: 0 4px;
    font-size: 11px;
    line-height: 1.2;
  }
  #game-sound {
    position: absolute;
    top: max(6px, env(safe-area-inset-top));
    inset-inline-start: 6px;
    z-index: 1;
  }
}

/* Phones held sideways: nothing above the board. The teams and the word sit on either side, so the board gets the full height. */
@media (orientation: landscape) and (max-height: 520px) {
  #game {
    --side: clamp(112px, 16vw, 150px);
    grid-template-rows: auto auto 1fr;
    grid-template-areas:
      "sun arena moon"
      "word arena next"
      "sound arena end";
    gap: 6px 8px;
    padding: 4px max(6px, env(safe-area-inset-right)) 4px max(6px, env(safe-area-inset-left));
  }
  :root[dir="ltr"] #game {
    grid-template-areas:
      "moon arena sun"
      "word arena next"
      "sound arena end";
  }
  .word-wrap { display: contents; }
  .word { --t: 26px; grid-area: word; justify-self: stretch; gap: 5px; }
  .word-tile.next { outline-width: 2px; }
  #watching { grid-area: next; justify-self: center; }
  .team-card { padding: 6px 8px; gap: 4px; border-radius: 12px; }
  .team-name { font-size: 13px; }
  .team-name .tag, .stats dt { display: none !important; }
  .team-name svg { width: 16px; height: 16px; }
  .stats { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; }
  .members { font-size: 11px; gap: 2px 8px; }
  .pips { gap: 3px; }
  .pips i { width: 9px; height: 9px; border-width: 1.5px; }
  .letters { font-size: 15px; }
  .hint { display: none; }
  #end-match { justify-self: stretch; align-self: end; height: 34px; padding: 0 4px; font-size: 12px; }
  #game-sound { justify-self: start; align-self: end; width: 34px; height: 34px; }
  /* Too short to stack: who won and the buttons on one side, the players on the other. */
  .over { padding: 10px max(14px, env(safe-area-inset-right)) 10px max(14px, env(safe-area-inset-left)); }
  .over-card { max-width: 780px; grid-template-columns: minmax(0, 0.85fr) minmax(0, 1fr); grid-template-rows: auto auto 1fr; gap: 12px 20px; align-items: start; }
  .over-card > :not(.stats-table) { grid-column: 1; }
  .stats-table { grid-column: 2; grid-row: 1 / span 3; align-self: center; }
  .over h2 { font-size: 26px; }
  .score-side { padding: 10px 6px 4px; }
  .score-number { font-size: 36px; }
  .score-name { font-size: 13px; }
  .stats-table td { padding: 4px 2px; line-height: 20px; }
  .who { height: 20px; }
  .award { margin-top: 0; line-height: 16px; font-size: 11px; }
  .over-actions { align-self: end; gap: 8px; }
  .over-actions .btn { height: 42px; font-size: 13px; }
}

#game-error:empty { display: none; }

/* English: the same screens read left to right in a Latin typeface.
   Sun stays on the right of the board, because that's the side its snakes start on. */
:root[lang="en"] body { font-family: Nunito, "Noto Kufi Arabic", system-ui, sans-serif; }
:root[dir="ltr"] .invite-link { text-align: left; }
:root[lang="en"] .rules li::before { content: counter(rule); }
/* Words and letters follow the room's language, whatever language the screen is in. */
#game[data-letters="en"] :is(.word, .letters) { font-family: Nunito, "Noto Kufi Arabic", system-ui, sans-serif; }
#game[data-letters="en"] .word-tile { padding-bottom: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
