/* Game screen (shown once the words arrive) */

/* Every rule here starts with :where([data-styles~="game-state"]): the game's screens are all on one page (app.html), with
   every screen's stylesheet loaded, and that keeps this one's rules to the screens that name it in their data-styles.
   (:where adds no weight, so the rules count for just what they did before it. A rule for the screen itself has no
   space after it.) */

:where([data-styles~="game-state"]) .game-state {
  position: fixed;
  inset: 0;
  display: none;
}

:where([data-styles~="game-state"]) .game-state.show {
  display: block;
}

/* A room's round is over (game.js roundOver): everything on the screen stops where it is and dims, under what happened,
   until the results come down over it on their curtain (results.js) */
:where([data-styles~="game-state"]) .game-state.frozen { pointer-events: none; }
:where([data-styles~="game-state"]) .game-state.frozen *, :where([data-styles~="game-state"]) .game-state.frozen *::before, :where([data-styles~="game-state"]) .game-state.frozen *::after { animation-play-state: paused !important; }

:where([data-styles~="game-state"]) .game-state::after {
  content: attr(data-frozen);
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(12, 10, 20, 0.55);
  color: #fff;
  font-weight: 900;
  font-size: clamp(34px, 11vw, 56px);
  line-height: 1.1;
  text-align: center;
  text-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

:where([data-styles~="game-state"]) .game-state.frozen::after {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.25s ease;
}

:where([data-styles~="game-state"]) .game-ui {
  position: absolute;
  inset: 0;
  display: grid;
  /* As wide as the screen, never as wide as the word or the buttons would like */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto 1fr;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

:where([data-styles~="game-state"]) .floating-shapes {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: -1;
}

:where([data-styles~="game-state"]) .shape {
  position: absolute;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 50%;
  animation: float 6s ease-in-out infinite;
}

:where([data-styles~="game-state"]) .shape:nth-child(1) {
  width: 80px;
  height: 80px;
  top: 20%;
  left: 10%;
  animation-delay: 0s;
}

:where([data-styles~="game-state"]) .shape:nth-child(2) {
  width: 120px;
  height: 120px;
  top: 60%;
  right: 10%;
  animation-delay: 2s;
}

:where([data-styles~="game-state"]) .shape:nth-child(3) {
  width: 60px;
  height: 60px;
  bottom: 20%;
  left: 20%;
  animation-delay: 4s;
}

@keyframes float {
  0%, 100% { transform: translateY(0px) rotate(0deg); }
  50% { transform: translateY(-20px) rotate(180deg); }
}


/* Header: leader on the left, timer on the right, with room left for the fixed home and mute buttons */

:where([data-styles~="game-state"]) .game-header {
  display: flex;
  align-items: center;
  gap: 12px;
  /* Clear of 🏠 and 🔊, which move in from the edges past a notch when the phone is on its side (game.css) */
  padding: 10px calc(68px + env(safe-area-inset-right, 0px)) 6px calc(68px + env(safe-area-inset-left, 0px));
}

:where([data-styles~="game-state"]) .leader {
  min-width: 0;
  padding: 9px 12px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.22);
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

:where([data-styles~="game-state"]) .timer {
  position: relative;
  width: 48px;
  height: 48px;
  flex: none;
  margin-left: auto;
}

:where([data-styles~="game-state"]) .timer svg {
  position: absolute;
  inset: 0;
  transform: rotate(-90deg);
}

:where([data-styles~="game-state"]) .timer circle {
  fill: none;
  stroke-width: 4;
}

:where([data-styles~="game-state"]) .timer .track { stroke: rgba(255, 255, 255, 0.18); }

:where([data-styles~="game-state"]) .timer .bar {
  stroke: #fff;
  stroke-linecap: round;
  stroke-dasharray: 131.95; /* 2 * pi * 21 */
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 1s linear, stroke 0.3s ease;
}

:where([data-styles~="game-state"]) .timer span {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

/* The last seconds: the ring goes red, and the timer beats once with each tick's sound (timer.js for a room, run.js for
   solo) - an endless pulse of its own here used to swell halfway between the ticks */
:where([data-styles~="game-state"]) .timer.urgent .bar { stroke: var(--bad); }


/* Standings: a chip row on phones, a side panel on wide screens */

:where([data-styles~="game-state"]) .standing {
  min-width: 0;
  padding: 4px 14px 0;
}

:where([data-styles~="game-state"]) .standing h2 {
  margin: 0 0 8px;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--on-dark-muted);
}

:where([data-styles~="game-state"]) .standing-list {
  display: flex;
  gap: 8px;
  margin: 0;
  padding: 0 0 4px;
  list-style: none;
  overflow-x: auto;
  scrollbar-width: none;
}

:where([data-styles~="game-state"]) .standing-list::-webkit-scrollbar { display: none; }

:where([data-styles~="game-state"]) .standing-item {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 4px 4px;
  border-radius: 999px;
  background: var(--glass);
  font-weight: 600;
  font-size: 14px;
}

:where([data-styles~="game-state"]) .standing-item.you { background: rgba(255, 255, 255, 0.24); }
:where([data-styles~="game-state"]) .standing-item .avatar { width: 26px; height: 26px; font-size: 12px; }
:where([data-styles~="game-state"]) .standing-item .rank { font-weight: 800; opacity: 0.7; }
:where([data-styles~="game-state"]) .standing-item .rank:empty { display: none; }
/* Points decide the round; the level only says how close it is to ending */
:where([data-styles~="game-state"]) .standing-item .pts { font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
:where([data-styles~="game-state"]) .standing-item .lv { font-size: 12px; font-variant-numeric: tabular-nums; opacity: 0.65; }

@media (max-width: 899px) {
  :where([data-styles~="game-state"]) .standing h2 { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
}

@media (min-width: 900px) {
  :where([data-styles~="game-state"]) .standing {
    position: absolute;
    top: 84px;
    right: 20px;
    width: 250px;
    padding: 0;
  }

  :where([data-styles~="game-state"]) .standing-list {
    flex-direction: column;
    overflow: visible;
  }

  :where([data-styles~="game-state"]) .standing-item {
    padding: 8px 14px 8px 8px;
    border-radius: 14px;
  }

  :where([data-styles~="game-state"]) .standing-item .pts { margin-left: auto; }
}

/* A phone on its side (in a browser - the app stays upright): too short for the chip row over the word, which spilled up
   into it. So the standings go down the side, as on a wide screen, and the word keeps clear of them - centred in what's
   left, a little tighter, its dots under it. (Rooms only: a .standing comes before the word only there.) */
@media (orientation: landscape) and (max-height: 500px) and (min-width: 560px) and (max-width: 899px) {
  :where([data-styles~="game-state"]) .standing {
    position: absolute;
    top: calc(64px + env(safe-area-inset-top, 0px));
    right: calc(16px + env(safe-area-inset-right, 0px));
    width: 210px;
    padding: 0;
  }

  :where([data-styles~="game-state"]) .standing-list {
    flex-direction: column;
    overflow: visible;
  }

  :where([data-styles~="game-state"]) .standing-item .pts { margin-left: auto; }

  :where([data-styles~="game-state"]) .standing ~ .game-content {
    justify-content: center;
    justify-content: safe center;
    gap: 10px;
    padding-right: calc(226px + env(safe-area-inset-right, 0px));
    padding-bottom: 44px;
  }

  :where([data-styles~="game-state"]) .standing ~ .game-content .levels {
    left: calc(50% - 113px - env(safe-area-inset-right, 0px) / 2);
    bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  }
}

/* A short phone on its side (an SE, or a long Android 330-360px tall): a room's word smaller still, and closer, so it and
   its buttons end above the dots with the '+N' line kept */
@media (orientation: landscape) and (max-height: 360px) and (min-width: 560px) {
  :where([data-styles~="game-state"]) .standing ~ .game-content { --tile-size: 48px; --tile-gap: 8px; gap: 6px; padding-top: 4px; }
}


/* The word */

:where([data-styles~="game-state"]) .game-content {
  /* Always the stretchy last row, even when the standings are taken out of flow on wide screens */
  grid-row: 3;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 8px 16px 72px;
  min-height: 0;
  --tile-size: 52px;
  --tile-gap: 8px;
}

@media (min-width: 600px) {
  :where([data-styles~="game-state"]) .game-content { --tile-size: 60px; --tile-gap: 10px; }
}

/* A room's five letters across a narrow phone - or one set to a bigger display size, which makes the screen narrower.
   (Solo's longer words size themselves to fit from these - fitTiles in solo/js/tiles.js reads them as numbers.) */
@media (max-width: 324px) {
  :where([data-styles~="game-state"]) .game-content { --tile-size: 46px; --tile-gap: 6px; }
}
@media (max-width: 286px) {
  :where([data-styles~="game-state"]) .game-content { --tile-size: 40px; }
}

/* Bigger letters (Settings: html.big-letters, --letter-zoom in theme.css): a room's word about a fifth bigger, but
   never wider than the screen - a room deals words of up to five letters. (Solo, Daily Jam and practice grow theirs in
   fitTiles, solo/js/tiles.js, which fits them to the screen as it always has.) */
html.big-letters :where([data-styles~="game-state"]:not([data-styles~="solo"])) .game-content {
  --tile-size: min(calc(52px * var(--letter-zoom)), calc((100vw - 32px - 4 * var(--tile-gap)) / 5));
}
@media (min-width: 600px) {
  html.big-letters :where([data-styles~="game-state"]:not([data-styles~="solo"])) .game-content { --tile-size: calc(60px * var(--letter-zoom)); }
}
@media (max-width: 324px) {
  html.big-letters :where([data-styles~="game-state"]:not([data-styles~="solo"])) .game-content { --tile-size: min(calc(46px * var(--letter-zoom)), calc((100vw - 32px - 4 * var(--tile-gap)) / 5)); }
}
/* ...except a short phone on its side, where there's no height to spare (as above) */
@media (orientation: landscape) and (max-height: 360px) and (min-width: 560px) {
  html.big-letters :where([data-styles~="game-state"]:not([data-styles~="solo"])) .standing ~ .game-content { --tile-size: 48px; }
}
@media (min-width: 1024px) and (min-height: 760px) {
  html.big-letters :where([data-styles~="game-state"]:not([data-styles~="solo"])) .game-content { --tile-size: calc(72px * var(--letter-zoom)); }
}

:where([data-styles~="game-state"]) .progress {
  margin: 0;
  font-weight: 600;
  font-size: 14px;
  color: var(--on-dark-muted);
  font-variant-numeric: tabular-nums;
}

:where([data-styles~="game-state"]) .answer-slots, :where([data-styles~="game-state"]) .letter-tiles {
  display: flex;
  justify-content: center;
  gap: var(--tile-gap);
  /* No pinch-zoom or scrolling here, so two thumbs landing at once are just two taps */
  touch-action: none;
}

:where([data-styles~="game-state"]) .slot {
  width: var(--tile-size);
  height: calc(var(--tile-size) * 1.15);
  display: grid;
  place-items: center;
  padding: 0;
  border: 2px dashed rgba(255, 255, 255, 0.35);
  border-radius: var(--radius-tile);
  background: transparent;
  color: #fff;
  font-weight: 900;
  font-size: calc(var(--tile-size) * 0.56);
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.25s ease;
}

:where([data-styles~="game-state"]) .slot.filled {
  border-style: solid;
  border-color: rgba(255, 255, 255, 0.85);
  background: rgba(255, 255, 255, 0.1);
}

/* Its tile is still flying in (game.js flyTile) */
:where([data-styles~="game-state"]) .slot.landing { color: transparent; }

:where([data-styles~="game-state"]) .answer-slots.win .slot {
  background: var(--go);
  border-color: var(--go);
  animation: flipIn 0.45s ease both;
}

:where([data-styles~="game-state"]) .answer-slots.win .slot:nth-child(2) { animation-delay: 0.05s; }
:where([data-styles~="game-state"]) .answer-slots.win .slot:nth-child(3) { animation-delay: 0.1s; }
:where([data-styles~="game-state"]) .answer-slots.win .slot:nth-child(4) { animation-delay: 0.15s; }
:where([data-styles~="game-state"]) .answer-slots.win .slot:nth-child(5) { animation-delay: 0.2s; }

@keyframes flipIn {
  0% { transform: rotateX(0); }
  50% { transform: rotateX(90deg); }
  100% { transform: rotateX(0) translateY(-3px); }
}

:where([data-styles~="game-state"]) .answer-slots.wrong { animation: shake 0.4s ease; }

:where([data-styles~="game-state"]) .answer-slots.wrong .slot {
  border-color: var(--bad);
  background: var(--bad-tint);
}

/* The answer shown when time runs out */
:where([data-styles~="game-state"]) .answer-slots.reveal .slot {
  border-style: solid;
  border-color: var(--go-light);
  color: var(--go-light);
  cursor: default;
}

:where([data-styles~="game-state"]) .letter-tiles .tile {
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.2s ease;
}

/* Only with a real pointer - on phones the hover sticks to the last tile tapped */
@media (hover: hover) {
  :where([data-styles~="game-state"]) .letter-tiles .tile:hover { transform: translateY(-2px); }
}
/* Pressed (theme.css): a tile, or a letter in the answer row, shrinks as an icon button does - an empty space, or the
   answer shown when time's up, does nothing */
:where([data-styles~="game-state"]) :is(.letter-tiles .tile, .slot.filled):is(:active, .is-pressed) { scale: 0.92; }
:where([data-styles~="game-state"]) :is(.slot:not(.filled), .answer-slots.reveal .slot):is(:active, .is-pressed) { scale: none; }

:where([data-styles~="game-state"]) .letter-tiles .tile.used {
  opacity: 0.22;
  transform: scale(0.9);
  pointer-events: none;
}
/* A dark tile faded that far is lost on the dark backdrop: a little more of it, so its place still shows */
html[data-theme="dark"] :where([data-styles~="game-state"]) .letter-tiles .tile.used { opacity: 0.45; }

:where([data-styles~="game-state"]) .letter-tiles.nope { animation: shake 0.3s ease; }

/* Its letter is flying back to it from the answer row (solo/js/tiles.js flyBack), and shows once it lands */
:where([data-styles~="game-state"]) .letter-tiles .tile.returning { color: transparent; }

/* A copy of a tapped tile on its way to the answer row (game.js flyTile) */
:where([data-styles~="game-state"]) .tile.flying {
  position: fixed;
  z-index: 20;
  margin: 0;
  pointer-events: none;
}

:where([data-styles~="game-state"]) .feedback {
  height: 28px;
  /* Kept even when the word's column is over-full (a phone on its side): shrunk to nothing, the first '+N' would push
     the word down under the player's fingers */
  flex-shrink: 0;
  margin: -6px 0;
  font-weight: 900;
  font-size: 24px;
  line-height: 28px;
  color: var(--go-light);
  opacity: 0;
}

:where([data-styles~="game-state"]) .feedback.show { animation: floatUp 1s ease-out; }

@keyframes floatUp {
  0% { opacity: 0; transform: translateY(8px) scale(0.8); }
  20% { opacity: 1; transform: translateY(0) scale(1.1); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-14px); }
}

/* With Reduce Motion, theme.css ends every animation at once - and this line is only ever seen through its animation, so
   the points, "Not it · 2 tries left" and the rest never showed. It fades in and out where it is instead, nothing
   moving. (Two classes outweigh theme.css's rule for everything, !important as both are.) */
/* Less motion: the phone's Reduce Motion, or the switch in Settings (html.reduce-motion - /shared/settings.js) */
html.reduce-motion :where([data-styles~="game-state"]) .feedback.show { animation: roundFeedbackStill 1.2s linear both !important; }

@keyframes roundFeedbackStill {
  0% { opacity: 0; }
  12%, 80% { opacity: 1; }
  100% { opacity: 0; }
}

/* Shuffle on the left and delete on the right, like backspace on a phone keyboard. As wide as the
   longest words (5 letters, see words.js) so the buttons don't move from word to word. */
:where([data-styles~="game-state"]) .word-actions {
  display: flex;
  justify-content: space-between;
  width: calc(var(--tile-size) * 5 + var(--tile-gap) * 4);
  max-width: 100%;
}

:where([data-styles~="game-state"]) .hint {
  margin: 0;
  font-size: 13px;
  line-height: 1.4;
  text-align: center;
  text-wrap: balance;
  color: rgba(255, 255, 255, 0.5);
}

@media (max-height: 640px) {
  :where([data-styles~="game-state"]) .hint { display: none; }
}

:where([data-styles~="game-state"]) .levels {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
}

:where([data-styles~="game-state"]) .level-list {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

:where([data-styles~="game-state"]) .level-circle {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--level-dot);
  border: 2px solid var(--level-line);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.12);
}

@media (max-width: 380px) {
  :where([data-styles~="game-state"]) .level-list { gap: 9px; }
}

/* A word column taller than its row (page zoom, or Android's largest text, makes the screen narrow and everything big)
   overflows downward rather than up into the header: "safe" keeps it centred only while it fits. ("center" first, for
   browsers without "safe".) */
:where([data-styles~="game-state"]) .game-content {
  justify-content: center;
  justify-content: safe center;
}

/* That narrow (a phone zoomed to 150% or more): the column scrolls if it has to, and the header and the dots close up -
   the pills beside the timer cut short as they must, so the timer itself is never under 🔊 */
@media (max-width: 300px) {
  :where([data-styles~="game-state"]) .game-content { overflow-y: auto; }
  :where([data-styles~="game-state"]) .game-header { gap: 8px; padding-left: calc(60px + env(safe-area-inset-left, 0px)); padding-right: calc(60px + env(safe-area-inset-right, 0px)); }
  :where([data-styles~="game-state"]) .game-header > :not(.timer) { padding-left: 8px; padding-right: 8px; }
  :where([data-styles~="game-state"]) .level-list { gap: 6px; }
  :where([data-styles~="game-state"]) .level-circle { width: 10px; height: 10px; }
}

/* A computer's big window: bigger tiles (fitTiles in solo/js/tiles.js still fits a long word), and the dots just under
   the word, rather than a long way down at the window's bottom edge */
@media (min-width: 1024px) and (min-height: 760px) {
  :where([data-styles~="game-state"]) .game-content { --tile-size: 72px; --tile-gap: 12px; }
  :where([data-styles~="game-state"]) .levels { position: static; transform: none; margin-top: 4px; }
}

:where([data-styles~="game-state"]) .active {
  background-color: #fbbf24;
}
:where([data-styles~="game-state"]) .completed {
  background-color: var(--go-light);
}
:where([data-styles~="game-state"]) .skipped {
  background-color: var(--bad-light);
}



:where([data-styles~="game-state"]) .powerups {
  display: none;
  position: fixed;
  top: 80px;
  right: 20px;
  /* display: flex; */
  flex-direction: column;
  gap: 12px;
  z-index: 10;
}

:where([data-styles~="game-state"]) .powerup {
  position: relative;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background-color: #ffffff8c;
  border: 2px solid #d1d5db;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(0,0,0,0.12);
}


/* More than 4 in the round, on a phone (leaderboard.js): the player ahead of you, you and the one behind, three chips
   sharing the width - names cut short rather than the strip scrolling - and where you are under them */
:where([data-styles~="game-state"]) .standing-where {
  margin: 2px 0 0;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--on-dark-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
:where([data-styles~="game-state"]) .standing-where[hidden] { display: none; }
@media (max-width: 899px) {
  :where([data-styles~="game-state"]) .standing-list.is-crowded { overflow: visible; gap: 6px; }
  :where([data-styles~="game-state"]) .standing-list.is-crowded > .standing-item:not(.near) { display: none; }
  :where([data-styles~="game-state"]) .standing-list.is-crowded > .standing-item {
    flex: 1 1 0;
    min-width: 0;
    gap: 6px;
    padding: 4px 10px 4px 4px;
    font-size: 13px;
  }
  :where([data-styles~="game-state"]) .standing-list.is-crowded .name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  :where([data-styles~="game-state"]) .standing-list.is-crowded :is(.lv, .rank) { display: none; }
  :where([data-styles~="game-state"]) .standing-list.is-crowded .avatar { width: 24px; height: 24px; font-size: 11px; }
  :where([data-styles~="game-state"]) .standing-list.is-crowded .pts { margin-left: auto; }
}
@media (min-width: 900px) {
  :where([data-styles~="game-state"]) .standing-where { display: none; }
}
