/* Guess the Word: the board on the school's navy, in school colours.
   Tokens come from /assets/site.css. Square corners; surfaces separate by tone, not lines. */
.game-page { overscroll-behavior: none; }

.app {
  display: flex; flex-direction: column; min-height: 100dvh;
  max-width: 520px; margin: 0 auto; padding: 0 16px;
}

/* ---- top bar ---- */
.topbar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 0 4px;
}
.back {
  justify-self: start; display: inline-flex; align-items: center; gap: 2px; min-height: 44px; padding-right: 8px;
  font-weight: 600; font-size: var(--step-small); text-decoration: none; color: var(--paper);
}
.back svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: square; }
.back:hover { color: var(--orange); }
.title { margin: 0; font-weight: 800; font-size: 1.375rem; letter-spacing: -0.04em; white-space: nowrap; }
.topbar-actions { justify-self: end; display: flex; }
.icon-btn {
  width: 40px; height: 44px; display: grid; place-items: center; border: 0; background: transparent;
  color: var(--paper); cursor: pointer; transition: color 0.15s, transform 0.15s var(--ease);
}
.icon-btn:hover { color: var(--orange); }
.icon-btn:active { transform: scale(0.9); }
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg .fill { fill: currentColor; stroke: none; }
@media (max-width: 420px) {
  .topbar { gap: 4px; }
  .title { font-size: 1.125rem; }
  .icon-btn { width: 36px; }
  .back { padding-right: 0; }
}
@media (max-width: 340px) { .title { font-size: 1rem; } .icon-btn { width: 32px; } .back { font-size: 0; } }

/* ---- length picker ---- */
.lengths { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 8px 0 4px; }
.lengths button {
  min-height: 44px; border: 0; border-radius: 0; background: var(--navy-2); color: var(--paper);
  font-weight: 800; font-size: 1rem; cursor: pointer;
  transition: background-color 0.2s, color 0.2s, transform 0.12s var(--ease);
}
.lengths button:hover { background: var(--navy-3); }
.lengths button:active { transform: scale(0.97); }
.lengths button[aria-pressed="true"] { background: var(--paper); color: var(--navy); }

/* ---- board ---- */
.play { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 4px 0; }
.streak { margin: 0; min-height: 1.5rem; font-weight: 800; font-size: var(--step-small); color: var(--orange); }

.board {
  --gap: 6px;
  --tile: min(62px,
    calc((100vw - 2rem - (var(--len) - 1) * var(--gap)) / var(--len)),
    calc((100dvh - 440px) / 6.4));
  display: grid; grid-template-rows: repeat(6, var(--tile)); gap: var(--gap);
}
.row { display: grid; grid-template-columns: repeat(var(--len), var(--tile)); gap: var(--gap); }

.tile {
  position: relative; display: grid; place-items: center; background: var(--navy-2);
  font-weight: 800; font-size: calc(var(--tile) * 0.52); line-height: 1; text-transform: uppercase;
  color: var(--paper); user-select: none;
}
.tile.filled { background: var(--navy-3); animation: pop 0.12s ease-out; }
.tile[data-state="correct"] { background: var(--orange); color: var(--navy); }
.tile[data-state="present"] { background: var(--sky); color: var(--navy); }
.tile[data-state="absent"] { background: var(--grey); color: #fff; }
.tile.flip { animation: flip 0.5s ease-in-out both; }
.row.shake { animation: shake 0.45s ease-in-out; }
.tile.bounce { animation: bounce 0.6s ease-in-out both; }

@keyframes pop { 0% { transform: scale(0.85); } 60% { transform: scale(1.08); } 100% { transform: scale(1); } }
@keyframes flip { 0% { transform: rotateX(0); } 50% { transform: rotateX(90deg); } 100% { transform: rotateX(0); } }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); } 20%, 80% { transform: translateX(5px); }
  30%, 50%, 70% { transform: translateX(-8px); } 40%, 60% { transform: translateX(8px); }
}
@keyframes bounce {
  0%, 20% { transform: translateY(0); } 40% { transform: translateY(-28%); }
  50% { transform: translateY(4%); } 60% { transform: translateY(-12%); } 80%, 100% { transform: translateY(0); }
}

/* Colour-blind help: a shape as well as a colour */
.symbols [data-state="correct"]::after,
.symbols [data-state="present"]::after {
  position: absolute; top: 4px; right: 5px; font-size: 0.6rem; line-height: 1;
}
.symbols [data-state="correct"]::after { content: "●"; }
.symbols [data-state="present"]::after { content: "○"; }

/* ---- keyboard ---- */
.keyboard { display: grid; gap: 6px; padding: 8px 0 4px; user-select: none; }
.keyboard[hidden] { display: none; }
.kb-row { display: flex; gap: 5px; justify-content: center; }
.key {
  position: relative; flex: 1 1 0; max-width: 46px; height: min(56px, 7.2dvh); min-height: 44px;
  border: 0; border-radius: 0; background: var(--navy-3); color: var(--paper);
  font-weight: 800; font-size: 1.0625rem; text-transform: uppercase; cursor: pointer;
  transition: background-color 0.25s, transform 0.06s; touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.key:hover { background: #2d40a0; }
.key:active { transform: translateY(2px); }
.key.wide { flex-grow: 1.6; max-width: 72px; font-size: 0.875rem; }
.key.wide svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: square; stroke-linejoin: miter; }
.key.enter { background: var(--orange); color: var(--navy); }
.key[data-state="correct"] { background: var(--orange); color: var(--navy); }
.key[data-state="present"] { background: var(--sky); color: var(--navy); }
.key[data-state="absent"] { background: var(--navy-2); color: #8b93bd; }

/* Shown in place of the keyboard once a round is over, at the same height so nothing jumps. */
.round-actions {
  display: grid; align-content: center; justify-items: center; gap: 10px;
  min-height: calc(3 * max(44px, min(56px, 7.2dvh)) + 2 * 6px + 12px); padding: 8px 0 4px;
}
.round-actions[hidden] { display: none; }
.round-msg { margin: 0; font-weight: 600; }
.button.big { min-width: 240px; min-height: 56px; font-size: 1.25rem; }
.button.dim { background: var(--navy-2); color: var(--paper); }
.button.dim:hover { background: var(--navy-3); }

.game-page .credit {
  text-align: center; font-size: var(--step-small); color: #b9c0e3;
  padding: 8px 0 calc(10px + env(safe-area-inset-bottom));
}
.game-page .credit strong { color: var(--paper); }

/* ---- toasts ---- */
.toasts {
  position: fixed; top: calc(112px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  display: grid; gap: 6px; z-index: 30; pointer-events: none;
}
.toast {
  background: var(--paper); color: var(--navy); padding: 10px 18px; font-weight: 800;
  animation: toast-in 0.2s ease-out; text-align: center; white-space: nowrap;
}
.toast.out { opacity: 0; transition: opacity 0.3s; }
@keyframes toast-in { from { transform: translateY(-8px); opacity: 0; } }

/* ---- dialogs: paper sheets over the navy ---- */
dialog.sheet {
  width: min(440px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: auto;
  border: 0; border-radius: 0; padding: 28px 24px 24px;
  background: var(--paper); color: var(--ink);
}
dialog.sheet[open] { animation: rise 0.25s var(--ease); }
dialog.sheet::backdrop { background: rgb(5 12 55 / 0.7); }
@keyframes rise { from { transform: translateY(16px); opacity: 0; } }
dialog h2 { font-weight: 800; font-size: 1.75rem; letter-spacing: -0.04em; line-height: 1.1; margin: 0 48px 16px 0; }
dialog h3 { font-size: 1rem; font-weight: 800; margin: 24px 0 10px; }
dialog p { margin: 0 0 12px; }
dialog .small { font-size: var(--step-small); color: var(--ink-soft); }
.close {
  position: absolute; top: 12px; right: 12px; width: 44px; height: 44px; border: 0; border-radius: 0;
  background: var(--paper-2); color: var(--ink); font-size: 1.5rem; line-height: 1; cursor: pointer;
}
.close:hover { background: var(--paper-3); }

.example { margin: 0 0 14px; }
.example p { margin: 6px 0 0; }
.mini-row { display: flex; gap: 4px; }
.mini {
  position: relative; width: 40px; height: 40px; display: grid; place-items: center;
  background: var(--paper-2); color: var(--navy); font-weight: 800; font-size: 1.125rem;
}
.mini[data-state="correct"] { background: var(--orange); }
.mini[data-state="present"] { background: var(--sky); }
.mini[data-state="absent"] { background: var(--grey); color: #fff; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; }
.stat-grid div { background: var(--paper-2); padding: 10px 4px; }
.stat-grid span { display: block; font-weight: 800; font-size: 1.75rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-grid div:nth-child(3) span { color: var(--orange-2); }
.stat-grid small { font-size: var(--step-small); color: var(--ink-soft); }

.dist { display: grid; gap: 5px; }
.dist-row { display: grid; grid-template-columns: 1rem 1fr; align-items: center; gap: 8px; font-weight: 800; }
.dist-bar {
  min-width: 2rem; padding: 2px 8px; text-align: right; color: #fff; background: var(--grey);
  font-size: var(--step-small); font-variant-numeric: tabular-nums;
}
.dist-bar.last { background: var(--orange); color: var(--navy); }

.toggle {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 0; cursor: pointer;
}
.toggle + .toggle { padding-top: 6px; }
.toggle > span { display: grid; gap: 2px; }
.toggle small { color: var(--ink-soft); font-size: var(--step-small); }
.toggle input {
  appearance: none; flex: none; width: 52px; height: 30px; margin: 0; background: var(--paper-3);
  position: relative; cursor: pointer; transition: background-color 0.2s;
}
.toggle input::after {
  content: ""; position: absolute; top: 4px; left: 4px; width: 22px; height: 22px;
  background: #fff; transition: transform 0.2s var(--ease);
}
.toggle input:checked { background: var(--orange); }
.toggle input:checked::after { transform: translateX(22px); }

.result { text-align: center; }
.result h2 { margin: 8px 40px 8px; font-size: 2.25rem; }
.result-word { color: var(--ink-soft); margin-bottom: 8px; }
.result-tiles { justify-content: center; margin: 0 0 20px; font-size: 1.25rem; }
.result-tiles > span { background: var(--orange); color: var(--navy); animation: pop 0.3s var(--ease) both; }
.result-tiles > span:nth-child(2) { animation-delay: 0.05s; }
.result-tiles > span:nth-child(3) { animation-delay: 0.1s; }
.result-tiles > span:nth-child(4) { animation-delay: 0.15s; }
.result-tiles > span:nth-child(5) { animation-delay: 0.2s; }
.result-tiles > span:nth-child(6) { animation-delay: 0.25s; }
.result-actions { display: grid; gap: 8px; margin-top: 20px; }

.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 40; }
.noscript { text-align: center; padding: 32px; }

@media (prefers-reduced-motion: reduce) {
  .tile.flip, .tile.bounce, .row.shake, .tile.filled { animation: none; }
}
