* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
}

html:has(.play-scroll),
html:has(.play-scroll) body {
  height: auto;
  min-height: 100%;
}

button, input { font: inherit; color: inherit; }

button, a, .key { touch-action: manipulation; }

a { color: var(--cyan); }

.app {
  max-width: 32rem;
  margin: 0 auto;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  padding: 0.35rem 0.45rem 0.3rem;
  padding-bottom: max(0.3rem, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.app:has(.play-scroll) {
  height: auto;
  min-height: 100dvh;
  max-height: none;
  overflow: visible;
}

.top {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.2rem 0.6rem;
  padding-bottom: 0.15rem;
  margin-bottom: 0.3rem;
}

.help-open {
  position: fixed;
  z-index: 25;
  top: max(0.35rem, env(safe-area-inset-top));
  right: max(0.4rem, env(safe-area-inset-right));
  width: 2rem;
  height: 2rem;
  border: 2px solid var(--cga-cyan);
  border-radius: 999px;
  background: #000;
  color: var(--cga-ltcyan);
  font-weight: 800;
  font-size: 1rem;
  line-height: 1;
}

.app:has(.help-open) .top {
  padding-right: 2.4rem;
}

.crumb { color: var(--cyan); text-decoration: none; font-size: 0.78rem; }

.title-block { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; }

h1 { margin: 0; font-size: 1.05rem; }

.app > .legal-foot { flex: none; }

.app:has(.wizard) {
  justify-content: center;
}

.app:has(#word-step) {
  justify-content: flex-start;
  height: 100dvh;
  min-height: 0;
  max-height: 100dvh;
  overflow: hidden;
}

html:has(#word-step),
html:has(#word-step) body {
  height: 100%;
  overflow: hidden;
}

#word-step.wizard {
  margin-top: 0;
  overflow: hidden;
}

.tagline {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.mascot {
  display: block;
  width: 72px;
  height: 93px;
  margin: 0 auto 0.35rem;
  object-fit: contain;
  transform-origin: 50% 90%;
  pointer-events: none;
}

.mascot-welcome {
  animation: mascot-hop 0.55s ease-out both, mascot-idle 5s ease-in-out 1.1s infinite;
}

.mascot-wait {
  animation: mascot-bob 3.2s ease-in-out infinite;
}

.mascot-reveal {
  animation: mascot-peek 2.1s ease-in-out both;
}

.mascot-win {
  animation: mascot-cheer 0.9s ease-out both;
}

.mascot-reveal.mascot-win {
  animation: mascot-peek 2.1s ease-in-out both, mascot-cheer 0.9s ease-out 2.1s both;
}

.mascot-droop {
  animation: mascot-droop 1.15s ease-out both;
}

.mascot-reveal.mascot-droop {
  animation: mascot-peek 2.1s ease-in-out both, mascot-droop 1.15s ease-out 2.1s both;
}

@keyframes mascot-hop {
  0% { transform: translateY(14px) scale(0.92, 0.9); opacity: 0; }
  55% { transform: translateY(-7px) scale(1.03, 1.04); opacity: 1; }
  100% { transform: none; }
}

@keyframes mascot-idle {
  0%, 72%, 100% { transform: translateY(0) scaleY(1); }
  80% { transform: translateY(-3px) scaleY(1.02); }
  88% { transform: translateY(0) scaleY(0.96); }
}

@keyframes mascot-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

@keyframes mascot-peek {
  0%, 100% { transform: none; }
  35%, 68% { transform: translateY(2px) rotate(-7deg); }
}

@keyframes mascot-cheer {
  0% { transform: none; }
  28% { transform: translateY(-10px) rotate(-10deg) scale(1.08); }
  52% { transform: translateY(-3px) rotate(7deg) scale(1.04); }
  100% { transform: none; }
}

@keyframes mascot-droop {
  0%, 100% { transform: none; }
  42% { transform: translateY(5px) rotate(8deg) scale(0.96); }
}

html.scene-paused .mascot { animation-play-state: paused; }

.fine-print {
  margin: 0.7rem 0 0;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.3;
}

.status {
  flex-basis: 100%;
  margin: 0;
  color: var(--cga-ltcyan);
  font-size: 0.78rem;
  line-height: 1.2;
}

.panel { padding: 0.55rem 0.6rem 0.7rem; }

.wizard {
  flex: 0 1 auto;
  width: 100%;
  height: auto;
  max-height: 100%;
  margin: auto 0;
  overflow: auto;
  text-align: center;
}

#invite-step .challenge { margin-bottom: 0.9rem; }

#invite-step .lede { margin-bottom: 1.05rem; }

#invite-step .actions { margin-top: 0.95rem; }

.wizard .btn,
.sheet-card .btn {
  border-radius: 999px;
  min-width: 9.5rem;
}

.callout {
  display: inline-block;
  margin: 0 0 0.55rem;
  padding: 0.2rem 0.7rem;
  border-radius: 999px;
  background: var(--tile-present);
  color: var(--tile-present-ink);
  font-weight: 800;
  font-size: 0.85rem;
}

.sample-key {
  margin: 0.35rem 0 0;
  color: var(--cga-gray);
  font-size: 0.72rem;
  font-weight: 700;
}

.sheet-card {
  position: relative;
  display: grid;
  gap: 0.55rem;
  justify-items: center;
  width: min(22rem, 100%);
  height: auto;
  max-height: min(92dvh, 100%);
  overflow: auto;
  text-align: center;
}

.sheet-card .lede { margin: 0; font-size: 0.92rem; }

.sheet-card .challenge { font-size: clamp(1.2rem, 5.4vw, 1.5rem); }

.sheet-next { margin-top: 0.35rem; }

.sheet-x {
  position: absolute;
  top: 0.45rem;
  right: 0.45rem;
  width: 2rem;
  height: 2rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--cga-ltcyan);
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1;
}

@media (prefers-reduced-motion: reduce) {
  .help-sheet, .help-sheet * { animation: none; transition: none; }
}

.lede, .hint { color: var(--ink); line-height: 1.35; }

.lede { margin: 0 0 0.65rem; font-size: 0.95rem; }

.challenge {
  margin: 0.1rem 0 0.45rem;
  font-size: clamp(1.35rem, 6.4vw, 1.7rem);
  line-height: 1.15;
  font-weight: 800;
}

.sample { margin: 0.35rem 0 0.7rem; }

.sample.sample-tiles { margin-bottom: 0; }

.sample .cell {
  width: 2.4rem;
  height: 2.4rem;
  aspect-ratio: 1;
  font-size: 1.15rem;
  animation: sample-in 0.28s ease both;
  animation-delay: calc(var(--i) * 70ms);
}

@media (prefers-reduced-motion: reduce) {
  .sample .cell { animation: none; }
}

@keyframes sample-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.hint { margin: 0.4rem 0 0; font-size: 0.82rem; color: var(--cga-gray); }

.field { display: grid; gap: 0.3rem; margin: 0 0 0.8rem; font-size: 0.85rem; }

.name-field {
  position: relative;
  margin: 0.85rem 0.85rem 1rem;
}

.name-field .text {
  width: 100%;
  min-height: 3.5rem;
  padding: 0.9rem 3.2rem 0.9rem 1.15rem;
  border-radius: 16px;
  border: 2px solid #64b5f6;
  background: #050510;
  color: #64b5f6;
  font-size: 1.35rem;
  font-weight: 800;
  text-align: center;
  letter-spacing: -0.02em;
}

.name-field .text.ghost { color: #8a8a9a; }

.name-pencil {
  position: absolute;
  top: 50%;
  right: 0.35rem;
  width: 2.75rem;
  height: 2.75rem;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: #64b5f6;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
}

.text, .letter {
  border: 2px solid var(--cga-cyan);
  background: #000;
  color: var(--cga-white);
  font-family: var(--font-tile);
  font-size: 16px;
  font-weight: 700;
}

.text {
  min-height: 2.8rem;
  padding: 0.45rem 0.7rem;
}

.letter-row {
  position: relative;
  display: grid;
  grid-template-columns: repeat(5, 2.75rem);
  gap: 0.35rem;
  margin: 0.6rem 0;
  justify-content: center;
}

.letter-cover {
  position: absolute;
  inset: 0;
  z-index: 2;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
}

.letter-row.picked .letter {
  caret-color: transparent;
  outline: none;
}

.letter-row.picked .letter:focus {
  outline: none;
  box-shadow: none;
}

.letter {
  border-color: var(--tile-correct, #1e88e5);
  color: var(--tile-correct, #1e88e5);
  width: 2.75rem;
  height: 2.75rem;
  aspect-ratio: 1;
  min-height: 0;
  text-align: center;
  text-transform: uppercase;
  font-size: 1.35rem;
}

.idea {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  margin: 0.1rem 0 0.45rem;
}

.idea-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--cga-gray);
}

.chip {
  min-height: 32px;
  padding: 0 0.65rem;
  border: 1px solid rgba(170, 170, 170, 0.45);
  border-radius: 999px;
  background: transparent;
  color: var(--cga-gray);
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 700;
}

.error {
  min-height: 1.1rem;
  margin: 0.3rem 0;
  color: var(--cga-ltred);
  font-weight: 700;
  text-align: center;
}

.play {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.wait-overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.6rem;
  background: rgba(5, 5, 16, 0.42);
  pointer-events: none;
}

.wait-plate {
  margin: 0;
  max-width: 16rem;
  padding: 0.65rem 0.8rem;
  border: 2px solid #fff;
  background: #050510;
  color: #fff;
  font-size: 0.95rem;
  font-weight: 800;
  line-height: 1.3;
  text-align: center;
}

.play-scroll {
  flex: none;
  min-height: auto;
}

.play-scroll .board h2 {
  height: 1rem;
  line-height: 1rem;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  max-width: calc(5 * 2.4rem + 4 * 0.18rem);
}

.play-scroll .row,
.play-scroll .board.yours .row {
  grid-template-columns: repeat(5, 2.4rem);
  gap: 0.18rem;
}

.play-scroll .cell {
  width: 2.4rem;
  height: 2.4rem;
  aspect-ratio: 1;
  font-size: 1.15rem;
}

.board h2 {
  margin: 0 0 0.2rem;
  font-family: var(--font-body);
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--cga-gray);
  font-weight: 700;
}

.rows { display: grid; gap: 0.2rem; justify-content: center; }

.row {
  display: grid;
  grid-template-columns: repeat(5, 2.55rem);
  gap: 0.2rem;
  justify-content: center;
}

.play .board.yours .row,
.play .board .row {
  grid-template-columns: repeat(5, 2.55rem);
}

.cell {
  position: relative;
  width: 2.55rem;
  height: 2.55rem;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  box-shadow: inset 0 0 0 2px #0000aa, 3px 3px 0 #000040;
  background: transparent;
  color: var(--cga-white);
  font-family: var(--font-tile);
  font-weight: 700;
  font-size: clamp(1.35rem, 6.2vw, 1.75rem);
  line-height: 1;
  text-transform: uppercase;
}

.row.live .cell { box-shadow: inset 0 0 0 2px #64b5f6, 3px 3px 0 #0000aa; }

.cell.filled { box-shadow: inset 0 0 0 2px #1565c0, 3px 3px 0 #000055; }

.cell.g, .cell.y, .cell.x {
  animation: none;
  backface-visibility: visible;
  transform: none;
}

.row.revealing { perspective: 700px; }

.cell.turning {
  transform-style: preserve-3d;
  backface-visibility: hidden;
}

.cell.filled .glyph {
  color: transparent;
  -webkit-text-stroke: 1.5px currentColor;
}

.cell.g .glyph,
.cell.y .glyph,
.cell.x .glyph {
  color: inherit;
  -webkit-text-fill-color: currentColor;
  -webkit-text-stroke: 0;
}

.cell.g {
  background-color: #1e88e5;
  background-color: var(--tile-correct, #1e88e5);
  color: #ffffff;
  color: var(--tile-correct-ink, #ffffff);
  box-shadow: 3px 3px 0 #0b3d73;
}

.cell.g .glyph {
  color: #ffffff;
  -webkit-text-fill-color: #ffffff;
}

.cell.y {
  background-color: #e8941a;
  background-color: var(--tile-present, #e8941a);
  color: #1a1000;
  color: var(--tile-present-ink, #1a1000);
  box-shadow: 3px 3px 0 #7a4a08;
}

.cell.x {
  background-color: #3e4c5c;
  background-color: var(--tile-absent, #3e4c5c);
  color: #fff;
  box-shadow: 3px 3px 0 #1a222c;
}

.theirs-scroll {
  flex: 1;
  min-height: 4.2rem;
  overflow: auto;
  margin-top: 0.25rem;
  border-top: 2px solid var(--cga-blue);
  padding-top: 0.3rem;
}

.their-board {
  flex: none;
  overflow: visible;
  margin-top: 0.45rem;
  border-top: 2px solid var(--cga-blue);
  padding-top: 0.45rem;
}

.keys {
  flex: none;
  display: grid;
  gap: 0.32rem;
  margin: 0.35rem 0 0.15rem;
}

.key-row { display: flex; gap: 0.28rem; }

.key {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  min-height: 58px;
  border: 0;
  border-radius: 4px;
  background: var(--key);
  color: var(--key-ink);
  font-family: var(--font-tile);
  font-weight: 700;
  font-size: 1.25rem;
  line-height: 1;
  text-transform: uppercase;
  padding: 0;
}

.key.wide {
  flex: 1.5 1 0;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
}

.key-spacer { flex: 0.5 1 0; }

.key.x { background: var(--tile-absent); color: #fff; }

.key.g {
  background-color: #1e88e5;
  background-color: var(--tile-correct, #1e88e5);
  color: #ffffff;
  color: var(--tile-correct-ink, #ffffff);
}

.key.y {
  background: var(--tile-present);
  color: var(--tile-present-ink);
}

.actions { display: flex; flex-wrap: wrap; gap: 0.45rem; justify-content: center; margin-top: 0.6rem; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 0.9rem;
  border: 0;
  background: var(--cga-blue);
  text-decoration: none;
  color: #fff;
  font-weight: 800;
  font-family: var(--font-body);
}

.btn.primary { background: var(--cga-cyan); color: #fff; }

.install-app { width: min(22rem, 100%); }

.install-btn {
  width: 100%;
  min-height: 44px;
}

.install-steps {
  margin: 0;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.65rem 0.9rem;
  border-radius: 999px;
  background: var(--cga-blue);
  color: #fff;
  font-weight: 800;
  text-align: center;
}

.install-app[hidden],
.install-btn[hidden],
.install-steps[hidden] { display: none; }

.qr { width: min(200px, 64vw); height: auto; background: #fff; padding: 0.35rem; }

.result-title { margin: 0 0 0.35rem; font-size: 1.15rem; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(0, 0, 0, 0.72);
  display: grid;
  place-items: center;
  padding: 1rem;
}

.modal-card {
  width: min(22rem, 100%);
  padding: 0.8rem 0.75rem 0.9rem;
  text-align: center;
}

.modal-card h2 { margin: 0 0 0.4rem; font-size: 0.95rem; }

.burst-layer {
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  overflow: hidden;
}

.burst-bit {
  position: fixed;
  left: 0;
  top: 0;
  line-height: 1;
  transform: translate(-50%, -50%) scale(var(--s, 1));
  animation: burst-fly 1.35s cubic-bezier(0.12, 0.7, 0.2, 1) 40ms both;
  will-change: transform, opacity;
}

@keyframes burst-fly {
  0% { transform: translate(-50%, -50%) scale(0.4); opacity: 0; }
  8% { opacity: 1; }
  20% {
    transform: translate(calc(-50% + var(--dx) * 0.22), calc(-50% + var(--dy) * 0.22)) rotate(calc(var(--rot) * 0.2)) scale(var(--s, 1));
    opacity: 1;
  }
  78% { opacity: 1; }
  to {
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) rotate(var(--rot)) scale(var(--s-end, 0.9));
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cell.turning { backface-visibility: visible; transform: none; }
  .mascot { animation: none !important; transform: none; }
}

@media (max-width: 420px) {
  .key { min-height: 58px; font-size: 1.25rem; }
}
