/* @dailies/shell - shared game skin. Hand-written, mobile-first, dark-mode
 * aware, zero-CLS. No framework. Per-app accent injected via CSS vars in the
 * app's Layout call (see views.tsx `Theme`). */

/* The island toggles visibility via the `hidden` attribute; any author
 * `display` rule (e.g. .streak inline-flex) silently beats the UA's
 * [hidden] { display: none }, so re-assert it with priority. */
[hidden] {
  display: none !important;
}

:root {
  --bg: #f7f7f8;
  --fg: #16181d;
  --muted: #5c6270;
  --card: #ffffff;
  --border: #d7dae1;
  --accent: #2f6df6;
  /* Foreground for filled accent buttons + the active autocomplete option.
   * Split from the hard-coded #fff so dark mode can flip to dark text on the
   * (deliberately brighter) dark-mode accent and still clear WCAG AA. */
  --btn-fg: #ffffff;
  /* Status colours are the colour-blind-critical feedback cells; every one is
   * kept >= 4.5:1 (WCAG AA normal text) against its -fg in BOTH modes - see
   * test/contrast.test.ts, which fails the build if any pair regresses. */
  --exact: #3f7d3c;
  --exact-fg: #ffffff;
  --partial: #c9a227;
  --partial-fg: #16181d;
  --miss: #6d7380;
  --miss-fg: #ffffff;
  --dir: #3b5bb5;
  --dir-fg: #ffffff;
  --row-h: 3rem;
  --maxw: 40rem;
  font-size: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161b;
    --fg: #e8eaef;
    --muted: #9aa0ac;
    --card: #1d2027;
    --border: #2c303a;
    --accent: #5a8bff;
    /* Dark text on the bright dark-mode accent: white would fail AA on these
     * lighter accents (see contrast test). */
    --btn-fg: #16181d;
    --exact: #38793d;
    --partial: #b8931f;
    --miss: #565c68;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* Keyboard focus is visible EVERYWHERE (a11y: keyboard-only playable). Scoped
 * to :focus-visible so mouse clicks don't draw a ring, but every interactive
 * element - buttons, links, the input, autocomplete options - gets one. The
 * endstate heading receives focus on finish (tabindex=-1) and shows it too. */
a:focus-visible,
button:focus-visible,
input:focus-visible,
[tabindex]:focus-visible,
.ac-item:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}
/* The finish heading is a programmatic focus target, not a click target - no
 * ring needed when we move focus there on game end. */
.endstate-heading:focus:not(:focus-visible) { outline: none; }

/* Header ------------------------------------------------------------------ */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  max-width: var(--maxw);
  margin: 0 auto;
}
.brand {
  font-weight: 800;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
  color: var(--fg);
  text-decoration: none;
}
.streak {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Mode toggle (Ships | Warships). The active tab is filled with the current
 * mode's accent; --btn-fg keeps its label >= 4.5:1 in both modes (the warship
 * accent is held to the same AA bar - see apps/shipdle/test/contrast.test.ts). */
.mode-tabs {
  display: inline-flex;
  gap: 0.25rem;
  padding: 0.15rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
}
.mode-tab {
  padding: 0.2rem 0.7rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
}
.mode-tab:hover { color: var(--fg); }
.mode-tab.active {
  background: var(--accent);
  color: var(--btn-fg);
}

/* Main -------------------------------------------------------------------- */
main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 1rem;
}
.puzzle-meta h1 { margin: 0.25rem 0; font-size: 1.5rem; }
.puzzle-no { color: var(--muted); font-weight: 600; }
.tagline { margin: 0 0 1rem; color: var(--muted); }

/* Comparison banner (reserved) */
.banner {
  background: var(--card);
  border: 1px solid var(--accent);
  border-radius: 0.5rem;
  padding: 0.6rem 0.8rem;
  margin: 0 0 1rem;
  font-weight: 600;
}

/* Progressive photo hint (reserved 16:9 box, zero CLS) ------------------- */
.photo-hint {
  margin: 0 0 1rem;
  width: 100%;
  max-width: 560px;
  margin-inline: auto;
}
.photo-hint img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  height: auto;
  object-fit: cover;
  background: #1a1a1c;
  border: 1px solid var(--accent);
  border-radius: 0.5rem;
  transition: opacity 0.2s ease;
}
.photo-credit {
  margin: 0.35rem 0 0;
  font-size: 0.8rem;
  text-align: center;
  opacity: 0.75;
}
.photo-credit a { color: var(--accent); }

/* Guess input + autocomplete --------------------------------------------- */
.guess-input-wrap {
  position: relative;
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.guess-input {
  flex: 1;
  min-width: 0;
  padding: 0.7rem 0.8rem;
  font-size: 1rem;
  color: var(--fg);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
}
.guess-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.guess-input:disabled { opacity: 0.6; }
.guess-btn {
  padding: 0.7rem 1.1rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--btn-fg);
  background: var(--accent);
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
}
.guess-btn:disabled { opacity: 0.5; cursor: default; }

.autocomplete {
  position: absolute;
  top: calc(100% + 0.25rem);
  left: 0; right: 0;
  z-index: 5;
  margin: 0; padding: 0.25rem;
  list-style: none;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  max-height: 15rem;
  overflow-y: auto;
}
.ac-item {
  padding: 0.55rem 0.6rem;
  border-radius: 0.35rem;
  cursor: pointer;
}
.ac-item.active { background: var(--accent); color: var(--btn-fg); }
.ac-item.loading { color: var(--muted); cursor: default; display: flex; align-items: center; gap: 0.5rem; }
.ac-spinner {
  width: 0.9rem; height: 0.9rem;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  display: inline-block;
  animation: ac-spin 0.7s linear infinite;
}
@keyframes ac-spin { to { transform: rotate(360deg); } }

/* Guess grid - fixed row heights = zero CLS ------------------------------- */
.grid-wrap { overflow-x: auto; }
.guess-grid {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0.25rem;
  table-layout: fixed;
}
.guess-grid th {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  padding: 0.25rem 0.2rem;
  text-align: center;
}
.guess-grid th.col-name { text-align: left; }
.guess-row { height: var(--row-h); }
.guess-grid td {
  height: var(--row-h);
  border: 1px solid var(--border);
  border-radius: 0.35rem;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.15rem;
  vertical-align: middle;
  overflow: hidden;
}
.cell-name, .guess-grid td.cell-name {
  text-align: left;
  font-weight: 700;
  font-size: 0.85rem;
  padding-left: 0.4rem;
}
.guess-row.empty td { background: transparent; border-style: dashed; opacity: 0.5; }
.glyph { display: block; font-size: 0.9rem; line-height: 1; margin-top: 0.1rem; }

.cell.status-exact { background: var(--exact); color: var(--exact-fg); border-color: var(--exact); }
.cell.status-partial { background: var(--partial); color: var(--partial-fg); border-color: var(--partial); }
.cell.status-miss { background: var(--miss); color: var(--miss-fg); border-color: var(--miss); }
.cell.status-higher,
.cell.status-lower { background: var(--dir); color: var(--dir-fg); border-color: var(--dir); }

/* Bonus teaser + ad slot -------------------------------------------------- */
.bonus-teaser {
  margin: 1rem 0;
  padding: 0.7rem 0.8rem;
  border: 1px dashed var(--border);
  border-radius: 0.5rem;
  color: var(--muted);
  font-size: 0.9rem;
}
.ad-slot { min-height: 90px; margin: 1rem 0 0; }

/* End state --------------------------------------------------------------- */
.endstate { margin-top: 1rem; }
.verdict { font-size: 1.15rem; font-weight: 800; margin: 0 0 0.75rem; }
.teach-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  padding: 1rem;
  margin-bottom: 1rem;
}
.reveal-name { margin: 0 0 0.4rem; font-size: 1.4rem; }
.teach-text { margin: 0; color: var(--fg); }
.teach-text + .teach-text, .teach-card .teach-attribution { margin-top: 0.5rem; }
.teach-attribution { margin: 0.5rem 0 0; font-size: 0.8rem; color: var(--muted); }
.teach-attribution a { color: inherit; }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.75rem; }
.btn {
  padding: 0.6rem 1rem;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--btn-fg);
  background: var(--accent);
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
.btn:hover { filter: brightness(1.05); }
.countdown { color: var(--muted); font-variant-numeric: tabular-nums; margin: 0.5rem 0 1rem; }
.toast {
  background: var(--fg);
  color: var(--bg);
  padding: 0.5rem 0.8rem;
  border-radius: 0.4rem;
  font-size: 0.85rem;
  font-weight: 600;
  display: inline-block;
  margin-bottom: 0.5rem;
}

/* Bonus rounds ------------------------------------------------------------ */
.bonus { border-top: 1px solid var(--border); padding-top: 1rem; }
.bonus-title { font-size: 1.1rem; margin: 0 0 0.75rem; }
.bonus-round {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.8rem;
  margin-bottom: 0.75rem;
}
.bonus-round.locked { opacity: 0.65; }
.bonus-prompt { margin: 0 0 0.6rem; font-weight: 600; }
.bonus-opts { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.bonus-choice { background: var(--card); color: var(--fg); border: 1px solid var(--border); }
.bonus-choice:hover { border-color: var(--accent); }
.bonus-outcome { display: flex; flex-direction: column; gap: 0.15rem; }
.bonus-mark { font-weight: 700; }
.bonus-detail { color: var(--muted); font-size: 0.9rem; }
.bonus-lock { color: var(--muted); margin: 0; }

/* Static pages ------------------------------------------------------------ */
.static-page { padding: 0.5rem 0; }
.static-page h1 { margin-top: 0; }
.answer-reveal { font-size: 1.15rem; }
.teach { color: var(--fg); }
.challenge-line { font-size: 1.1rem; }
.cta { margin-top: 1.25rem; }

/* Footer ------------------------------------------------------------------ */
.site-footer {
  max-width: var(--maxw);
  margin: 2rem auto 0;
  padding: 1rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}
.family { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.family-label { font-weight: 600; }
.family-item {
  padding: 0.15rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
}
a.family-item { color: inherit; text-decoration: none; }
a.family-item:hover { border-color: var(--accent); color: var(--accent); }
.family-item[aria-current="page"] { font-weight: 600; border-color: var(--accent); }
.footer-links a { color: var(--accent); }

/* ---- Legal pages (privacy / cookies) ------------------------------------ */
.legal-page h2 { margin: 1.25rem 0 0.35rem; font-size: 1.05rem; }
.cookie-table { width: 100%; border-collapse: collapse; margin: 0.75rem 0; }
.cookie-table th,
.cookie-table td {
  border: 1px solid var(--border);
  padding: 0.4rem 0.6rem;
  text-align: left;
  font-size: 0.9rem;
}

/* ---- Quiz (METAR Daily) ------------------------------------------------- */
/* The raw report: monospace, wrap-safe on mobile (long METARs must not force a
 * horizontal body scroll), zero-CLS. */
.metar-raw {
  font-family: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  font-size: 0.95rem;
  line-height: 1.5;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.75rem 0.9rem;
  margin: 0 0 1rem;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.quiz-progress {
  list-style: none;
  display: flex;
  gap: 0.5rem;
  padding: 0;
  margin: 0 0 1rem;
}
.quiz-dot {
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: transparent;
}
.quiz-dot.current { border-color: var(--accent); }
.quiz-dot.correct { background: var(--exact); border-color: var(--exact); }
.quiz-dot.wrong { background: var(--miss); border-color: var(--miss); }
/* Reserve height so filling the card in shifts nothing. */
.quiz-card { min-height: 16rem; margin-bottom: 1rem; }
.quiz-prompt { font-size: 1.15rem; font-weight: 700; margin: 0 0 0.9rem; }
.quiz-options { display: flex; flex-direction: column; gap: 0.5rem; }
.quiz-option {
  text-align: left;
  background: var(--card);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.7rem 0.9rem;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  gap: 0.6rem;
  align-items: baseline;
}
.quiz-option:hover:not(:disabled) { border-color: var(--accent); }
.quiz-option:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.quiz-option:disabled { cursor: default; }
.quiz-option .quiz-key {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}
.quiz-option.picked-correct { background: var(--exact); color: var(--exact-fg); border-color: var(--exact); }
.quiz-option.picked-correct .quiz-key { color: var(--exact-fg); }
.quiz-option.picked-wrong { background: var(--miss); color: var(--miss-fg); border-color: var(--miss); }
.quiz-option.picked-wrong .quiz-key { color: var(--miss-fg); }
.quiz-option.reveal-correct { border-color: var(--exact); box-shadow: inset 0 0 0 2px var(--exact); }
.quiz-feedback { margin: 0.9rem 0 0; }
.quiz-verdict { font-weight: 700; margin: 0 0 0.4rem; }
.quiz-explain {
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--card);
  padding: 0.6rem 0.8rem;
  margin: 0.4rem 0 0;
}
.quiz-explain > summary { cursor: pointer; font-weight: 600; }
.quiz-explain[open] > summary { margin-bottom: 0.5rem; }
.quiz-explain ul { margin: 0; padding-left: 1.1rem; }
.quiz-explain li { margin: 0.15rem 0; }
.quiz-explain .trace-token {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-weight: 700;
}
.quiz-next { margin-top: 0.9rem; }
/* End-state decoded report table (token -> meaning). */
.decoded { border-top: 1px solid var(--border); padding-top: 0.75rem; margin-top: 0.75rem; }
.decoded-title { font-size: 1.05rem; margin: 0 0 0.5rem; }
.decoded-row { display: flex; gap: 0.7rem; padding: 0.2rem 0; }
.decoded-row .trace-token {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-weight: 700;
  min-width: 6.5rem;
}
.station-line { margin: 0 0 0.5rem; }
.station-line a { color: var(--accent); }

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