/* ============================================================================
   CROSSWORD — the daily 5×5 mini. NYT-mini-style engine on the Daily Games
   Lab dark design system. All styling rides base.css tokens.
   ============================================================================ */

body.crossword {
  --accent: #ffb347;          /* warm amber — paper-and-ink crossword feel */
  --accent-ink: #2a1600;
  /* lock the page: no scroll / pinch while solving */
  overscroll-behavior: none;
  touch-action: manipulation;
}

.topbar-right { display: inline-flex; align-items: center; gap: 10px; }
.timer-chip {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 6px 12px;
  border-radius: var(--r-pill);
  min-width: 58px;
  text-align: center;
}
.timer-chip[hidden] { display: none; }

/* ---------------- intro card ---------------- */
.intro.card { padding: 24px 22px 22px; }
.intro h2 { font-size: 1.7rem; margin-top: 4px; }
.intro .lead { margin-top: 8px; }
.intro .howto { margin-top: 18px; display: grid; gap: 12px; }
.intro .step { display: flex; gap: 12px; align-items: flex-start; }
.intro .step .n {
  flex: none;
  width: 26px; height: 26px;
  display: grid; place-items: center;
  font-family: var(--font-mono); font-weight: 700; font-size: 0.82rem;
  border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  border: 1px solid var(--accent-soft);
}
.intro .step b { color: var(--ink); }
.intro .step div { color: var(--ink-dim); font-size: 0.95rem; }
.intro .start { margin-top: 22px; }
.intro .subnav {
  margin-top: 14px; display: flex; align-items: center; justify-content: space-between;
  font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.06em;
  color: var(--ink-faint);
}

/* ---------------- play layout ---------------- */
.play {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

/* theme banner */
.theme-banner {
  width: 100%;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.theme-banner .eyebrow { color: var(--accent); }
.theme-banner .theme-name { font-family: var(--font-display); font-weight: 800; font-size: 1.05rem; letter-spacing: -0.01em; }

/* ---------------- grid ---------------- */
.grid-wrap {
  --cell: min(17.6vw, 72px);     /* 5 cells + 4 gaps fit a phone & cap on desktop */
  width: calc(var(--cell) * 5 + 8px);
  max-width: 100%;
  background: var(--line);
  border: 2px solid var(--ink-faint);
  border-radius: var(--r-sm);
  padding: 2px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 1px;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.cell {
  position: relative;
  aspect-ratio: 1 / 1;
  background: var(--surface);
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: calc(var(--cell) * 0.5);
  line-height: 1;
  color: var(--ink);
  text-transform: uppercase;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s var(--ease), color 0.12s;
}
.cell.block {
  background: var(--bg);
  cursor: default;
  box-shadow: inset 0 0 0 1px var(--line-soft);
}
.cell .num {
  position: absolute;
  top: 2px; left: 3px;
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: calc(var(--cell) * 0.22);
  line-height: 1;
  color: var(--ink-faint);
  pointer-events: none;
}
.cell .ltr { pointer-events: none; }

/* highlight states */
.cell.in-entry { background: var(--accent-soft); }
.cell.selected { background: var(--accent); color: var(--accent-ink); }
.cell.selected .num { color: color-mix(in oklab, var(--accent-ink) 70%, transparent); }

/* feedback */
.cell.wrong { animation: cellShake 0.3s var(--ease) both; box-shadow: inset 0 0 0 2px var(--bad); }
.cell.wrong .ltr { color: var(--bad); }
.cell.selected.wrong .ltr { color: var(--bad); }
@keyframes cellShake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-2px); }
  75% { transform: translateX(2px); }
}
.cell.revealed-flash { animation: pop 0.4s var(--ease-snap) both; }

/* ---------------- clue bar ---------------- */
.clue-bar {
  width: 100%;
  display: flex; align-items: stretch; gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
  min-height: 58px;
}
.clue-bar .nav {
  flex: none;
  width: 42px;
  border: none;
  background: transparent;
  color: var(--ink-dim);
  font-size: 1.5rem;
  cursor: pointer;
  display: grid; place-items: center;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, color 0.15s;
}
.clue-bar .nav:hover { background: var(--surface); color: var(--ink); }
.clue-bar .nav:active { background: var(--accent-soft); }
.clue-bar .clue-text {
  flex: 1;
  display: flex; flex-direction: column; justify-content: center;
  gap: 2px;
  padding: 8px 4px;
  cursor: pointer;
  text-align: center;
}
.clue-bar .clue-meta {
  font-family: var(--font-mono);
  font-size: 0.66rem; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--accent);
}
.clue-bar .clue-prompt { font-size: 0.98rem; color: var(--ink); line-height: 1.25; }

/* ---------------- tools row (check / reveal) ---------------- */
.tools { width: 100%; display: flex; gap: 8px; }
.tools .tool {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink-dim);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  padding: 9px 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.tools .tool:hover { color: var(--ink); border-color: var(--ink-faint); }
.tools .tool:active { background: var(--accent-soft); }
.tools details { position: relative; flex: 1; }
.tools details > summary {
  list-style: none;
  font-family: var(--font-mono);
  font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink-dim);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  padding: 9px 8px;
  cursor: pointer;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}
.tools details > summary::-webkit-details-marker { display: none; }
.tools details[open] > summary { color: var(--ink); border-color: var(--ink-faint); }
.tools .menu {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0; right: 0;
  z-index: 5;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 6px;
  display: grid; gap: 4px;
}
.tools .menu button {
  width: 100%;
  text-align: left;
  font-family: var(--font-body);
  font-size: 0.86rem;
  color: var(--ink);
  background: transparent;
  border: none;
  border-radius: var(--r-sm);
  padding: 9px 11px;
  cursor: pointer;
}
.tools .menu button:hover { background: var(--surface); }

/* ---------------- on-screen keyboard ---------------- */
.keyboard {
  width: 100%;
  display: flex; flex-direction: column;
  gap: 6px;
  margin-top: 2px;
  touch-action: manipulation;
}
.kb-row { display: flex; justify-content: center; gap: 5px; }
.key {
  flex: 1 1 0;
  min-width: 0;
  max-width: 42px;
  height: 50px;
  display: grid; place-items: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.08s var(--ease-snap), background 0.12s;
}
.key:active { transform: translateY(1px) scale(0.96); background: var(--accent-soft); }
.key.wide { flex: 1.6 1 0; max-width: 66px; font-size: 1.3rem; }

/* ---------------- result sheet ---------------- */
.result-head { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.result-time {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 3.2rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}
.result-time .lbl {
  display: block;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.82rem; letter-spacing: 0;
  color: var(--ink-dim);
  margin-top: 6px;
}
.result-sub { color: var(--ink-dim); font-size: 0.98rem; margin-bottom: 14px; }
.result-sub b { color: var(--ink); }
.sheet-actions { display: grid; gap: 10px; margin-top: 16px; }
.sheet .stats { margin-top: 14px; }

/* ---------------- confetti ---------------- */
.confetti {
  position: fixed; inset: 0; z-index: 50;
  pointer-events: none; overflow: hidden;
}
.confetti i {
  position: absolute;
  top: -12px;
  width: 9px; height: 14px;
  border-radius: 2px;
  will-change: transform, opacity;
  animation: confFall var(--dur, 2.2s) var(--ease) forwards;
}
@keyframes confFall {
  0% { transform: translateY(-10px) rotate(0); opacity: 1; }
  100% { transform: translateY(102vh) rotate(720deg); opacity: 0; }
}

@media (max-width: 360px) {
  .key { height: 46px; font-size: 0.98rem; }
}
@media (prefers-reduced-motion: reduce) {
  .confetti { display: none; }
}
