/* ─── tokens ─────────────────────────────────────────── */
:root {
  /* Sweet Action Labs tokens (site handoff 2026-10). The lab owns paper, ink,
     Archivo and the logo; each app gets one pale hue. Said What?! is apricot
     (hue 60). Red is reserved for the lab logo dot, so warnings use burnt orange. */
  --paper:   #f7f7f4;
  --ink:     #0b2350;
  --muted:   #4b5d80;
  --rule:    #c3cde0;
  --tint:    #f6cfb0;
  --tint:    oklch(0.88 0.06 60);
  --soft:    #fcebde;
  --soft:    oklch(0.95 0.025 60);
  --font-frame: 'Archivo', system-ui, sans-serif;
  --font-mono:  'JetBrains Mono', ui-monospace, monospace;
  --sheet:   #ffffff;
  --hair:    #d5dbe7;
  --radius-ui: 4px;

  --page:    var(--paper);
  --surface: #ffffff;
  --border:  var(--rule);
  --border-strong: #8d9bb8;
  --text:    var(--ink);
  --text-2:  var(--muted);
  --text-3:  #7a88a6;
  --accent:  var(--ink);
  --dark:    var(--ink);
  --radius:  6px;
  --max-w:   620px;

  --q0: var(--ink);

  /* feedback */
  --ok:   #1d7348;
  --err:  #a8500a;
  --warn: #a8500a;
  --info: var(--ink);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--page);
  color: var(--text);
  font-family: var(--font-frame);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* ─── layout ─────────────────────────────────────────── */
.page {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 16px 24px;
}

/* ─── header: title, rule, status — same frame as the prompt game ─── */
.header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 0 0;
}

.logo {
  font-family: var(--font-frame);
  font-stretch: 125%;
  font-weight: 800;
  font-size: clamp(30px, 6vw, 44px);
  line-height: 0.98;
  letter-spacing: -0.035em;
  color: var(--ink);
}
.logo em {
  font-style: normal;
  background: var(--tint);
  padding: 0 0.1em;
  border-radius: 4px;
}

/* Lab frame: logo above the game, mono footer — matches the other SAL games */
.sal-bar { padding: 16px 0 10px; }
.sal-bar .sal-logo { display: inline-block; }
.sal-bar .sal-logo:hover { opacity: 0.7; }
.sal-bar img { display: block; height: 22px; width: auto; }

.btn-how-to-play {
  flex: none;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: var(--radius-ui);
  background: none;
  color: var(--ink);
  font-family: var(--font-frame);
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
}
.btn-how-to-play:hover { background: var(--soft); }

.rule-short { display: none; }
@media (max-width: 480px) {
  .rule-short { display: inline; }
}
.game-rule {
  margin: 12px 0 0;
  max-width: 60ch;
  font-size: 15px;
  line-height: 1.5;
  color: var(--muted);
}

.game-status {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1.5px solid var(--ink);
  font-size: 15px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.game-status strong { color: var(--ink); font-weight: 800; font-size: 20px; margin-right: 2px; }

/* Five squares, one per quote — same language as the share result */
.found-tracker { display: flex; gap: 6px; margin-left: auto; }
.found-slot {
  width: 20px;
  height: 20px;
  border: 1.5px solid var(--ink);
  border-radius: 2px;
}
.found-slot.filled { background: var(--ink); }
.found-slot.current { box-shadow: 0 0 0 2px var(--tint); }

/* theme strip */
.theme-strip {
  display: none;
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 8px;
}
.theme-strip .theme-label { font-weight: 600; color: var(--ink); }

/* ─── clue: who is talking, about what — always on screen ─── */
.round-clue {
  margin-top: 14px;
  padding: 10px 14px;
  background: var(--soft);
  border-left: 3px solid var(--ink);
  border-radius: var(--radius-ui);
  font-size: 16px;
  line-height: 1.4;
  color: var(--ink);
}
.round-clue .clue-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--muted);
  margin-right: 6px;
}

/* ─── controls: one solid action, quiet text actions; pinned while scrolling ─── */
.action-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 10px;
  padding: 10px 0;
  background: var(--paper);
}
.btn-check {
  flex: none;
  min-height: 44px;
  padding: 0 22px;
  margin-right: 8px;
  background: var(--ink);
  color: var(--paper);
  border: 0;
  border-radius: var(--radius-ui);
  font-family: var(--font-frame);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.btn-check:hover { background: #162f63; }
.btn-check:disabled { opacity: 0.4; cursor: default; }
.btn-check kbd {
  margin-left: 8px;
  padding: 1px 6px;
  border: 1px solid rgba(247, 247, 244, 0.45);
  border-radius: 3px;
  font-family: var(--font-frame);
  font-size: 12px;
  font-weight: 500;
  opacity: 0.85;
}
.btn-link {
  flex: none;
  min-height: 44px;
  padding: 0 12px;
  background: none;
  border: 0;
  border-radius: var(--radius-ui);
  color: var(--ink);
  font-family: var(--font-frame);
  font-size: 15px;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-thickness: 1.5px;
  cursor: pointer;
}
@media (hover: hover) {
  .btn-link:hover { background: var(--soft); }
}
.btn-link:disabled { opacity: 0.35; cursor: default; background: none; }
.btn-link.btn-hint { margin-left: auto; }

/* ─── your trace so far, as text ───
   Fixed at two lines so the grid never moves under the player's finger as the
   trace grows. Bottom-aligned: on a long quote the newest words stay visible
   and the earliest scroll out of view. */
.selection-preview {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  height: calc(15px * 1.45 * 2);
  overflow: hidden;
  margin-bottom: 8px;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
}
.selection-preview .placeholder { color: var(--muted); }
.word-slots .trace-text { font-weight: 600; }
.word-slots .trace-count { color: var(--muted); margin-left: 6px; font-size: 13px; white-space: nowrap; }

/* ─── the sheet: words in a hairline table, not cards ─── */
.grid-wrapper {
  position: relative;
  min-height: 160px;
  background: var(--sheet);
  border: 1.5px solid var(--ink);
}

.grid-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.95);
  z-index: 10;
  gap: 10px;
  color: var(--muted);
  font-size: 0.88rem;
}
.grid-loading.hidden { display: none; }

.spinner {
  width: 28px;
  height: 28px;
  border: 2.5px solid var(--hair);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#grid {
  display: grid;
  gap: 1px;
  background: var(--hair);
}
#grid.layout-sequential-4  { grid-template-columns: repeat(4, minmax(0, 1fr)); }
#grid.layout-sequential-5  { grid-template-columns: repeat(5, minmax(0, 1fr)); }

.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 58px;
  padding: 8px 6px;
  background: var(--sheet);
  border: 0;
  border-radius: 0;
  color: var(--ink);
  font-family: var(--font-frame);
  font-stretch: 82%;
  font-size: 17px;
  font-weight: 500;
  line-height: 1.15;
  text-align: center;
  /* Long words hyphenate at a syllable, as in the prompt game, instead of shrinking */
  overflow-wrap: break-word;
  hyphens: auto;
  touch-action: manipulation;
  cursor: pointer;
  user-select: none;
  transition: background 0.12s ease, color 0.12s ease;
}
/* Hover only where there's a real pointer: on a phone the tint sticks to the last tapped word */
@media (hover: hover) {
  .cell:hover:not(.found-quote):not(.selected):not(.cell-right) { background: var(--soft); }
}
/* Keyboard focus needs its own look: a navy outline already means "you can tap this next" */
.cell:focus-visible {
  outline: 3px solid #e08a4a;
  outline-offset: -3px;
  z-index: 1;
}

/* Cell states follow the prompt game: navy path with order numbers, navy
   outline on the words you can tap next, green for words a check confirmed. */
.cell.valid-next:not(.found-quote) { box-shadow: inset 0 0 0 1.5px var(--ink); }

.cell.selected,
.cell.cell-right {
  background: var(--ink);
  color: var(--paper);
  font-weight: 600;
}
.cell.cell-right { background: var(--ok); }
.cell.selected::after,
.cell.cell-right::after {
  content: attr(data-order);
  position: absolute;
  top: 3px;
  right: 5px;
  font-stretch: 100%;
  font-size: 10px;
  font-weight: 600;
  color: rgba(247, 247, 244, 0.7);
}

/* The word already shown wrong as the next one: a burnt-orange ring */
.cell.tried-next:not(.found-quote) { box-shadow: inset 0 0 0 2px rgba(168, 80, 10, 0.75); }
/* A hint crossed this word out: it isn't in the quote */
.cell.ruled-out {
  color: var(--muted);
  background: var(--paper);
  text-decoration: line-through;
  text-decoration-thickness: 1.5px;
  opacity: 0.55;
  cursor: default;
}

/* A tap on a word that doesn't touch the last one */
.cell.invalid {
  background: #fbeee0;
  box-shadow: inset 0 0 0 1.5px var(--err);
  animation: cell-shake 0.3s;
}
@keyframes cell-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* Where the quote begins */
.start-tag {
  position: absolute;
  top: 3px;
  left: 5px;
  font-family: var(--font-mono);
  font-stretch: 100%;
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--muted);
  pointer-events: none;
}
.cell.quote-start:not(.selected):not(.cell-right) { background: var(--soft); }
.cell.quote-start.selected .start-tag,
.cell.quote-start.cell-right .start-tag { color: rgba(247, 247, 244, 0.7); }

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

.cell.found-quote { cursor: default; }
.cell.found-q0 { background: var(--ink); color: var(--paper); }

.word-order {
  position: absolute;
  top: 3px;
  right: 5px;
  font-stretch: 100%;
  font-size: 10px;
  font-weight: 600;
  color: rgba(247, 247, 244, 0.7);
}

/* ─── quote reveal ──────────────────────────────────── */
.quote-reveal {
  display: none;
  position: relative;
  margin-top: 20px;
  padding: 18px 20px;
  background: var(--sheet);
  border: 1.5px solid var(--ink);
  border-radius: var(--radius-ui);
  animation: fadeUp 0.2s ease-out;
}
.quote-reveal.visible { display: block; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.quote-reveal .quote-text {
  font-size: 1rem;
  font-weight: 600;
  font-style: italic;
  color: var(--text);
  line-height: 1.5;
  margin-bottom: 6px;
}
.quote-reveal .speaker {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent);
}
.quote-reveal .context {
  font-size: 0.78rem;
  color: var(--text-2);
  margin-top: 5px;
  line-height: 1.5;
}
.quote-reveal .source {
  font-size: 0.72rem;
  color: var(--text-3);
  margin-top: 4px;
}

.reveal-next {
  display: inline-block;
  margin-top: 12px;
  min-height: 44px;
  padding: 0 22px;
  background: var(--ink);
  color: var(--paper);
  border: none;
  border-radius: var(--radius-ui);
  font-family: var(--font-frame);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s;
}
.reveal-next:hover { opacity: 0.85; }

/* ─── found list ─────────────────────────────────────── */
#found-quotes {
  margin-top: 28px;
}

#found-quotes h3 {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text-3);
  margin-bottom: 12px;
}

.found-quote-item {
  display: flex;
  gap: 10px;
  padding: 11px 14px;
  background: var(--sheet);
  border: 1px solid var(--hair);
  border-radius: 0;
  margin-bottom: -1px;
  align-items: flex-start;
}

.q-num {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.68rem;
  font-weight: 800;
  color: #fff;
  background: var(--accent);
  flex-shrink: 0;
  margin-top: 1px;
}

.q-text {
  font-size: 0.82rem;
  font-style: italic;
  color: var(--text);
  line-height: 1.45;
}
.q-speaker {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-2);
  margin-top: 2px;
}

/* ─── toast ─────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  /* Hidden fully below the screen, however many lines the message wraps to */
  transform: translateX(-50%) translateY(calc(100% + 40px));
  width: max-content;
  max-width: calc(100vw - 32px);
  text-align: center;
  line-height: 1.35;
  padding: 10px 20px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 0.85rem;
  z-index: 9999;
  transition: transform 0.22s ease-out;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  pointer-events: none;
}
.toast.visible { transform: translateX(-50%) translateY(0); }
.toast.success { background: var(--ok);   color: #fff; }
.toast.error   { background: var(--err);  color: #fff; }
.toast.warning { background: var(--warn); color: #fff; }
.toast.info    { background: var(--info); color: #fff; }

/* ─── overlays ───────────────────────────────────────── */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(11, 35, 80, 0.45);
  backdrop-filter: blur(2px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.overlay.visible { display: flex; }

.modal {
  /* Same panel as the prompt game's dialogs: paper with a navy outline */
  background: var(--paper);
  border: 1.5px solid var(--ink);
  border-radius: 8px;
  padding: 28px;
  max-width: 400px;
  width: 100%;
  animation: popIn 0.22s ease-out;
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.95); }
  to   { opacity: 1; transform: scale(1); }
}

/* completion */
.completion-modal .modal-title {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 4px;
}
.completion-modal .modal-sub {
  font-size: 0.88rem;
  color: var(--text-2);
  margin-bottom: 22px;
}

.comp-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}

.comp-stat {
  background: var(--sheet);
  border: 1px solid var(--hair);
  border-radius: 0;
  padding: 12px 8px;
  text-align: center;
}
.comp-stat .value {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.comp-stat .label {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-3);
  margin-top: 4px;
}

.round-perf {
  text-align: center;
  margin-bottom: 18px;
}
.round-perf-squares {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 8px;
}
.round-perf-square {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: #fff;
}
.round-perf-square.perf-green  { background: #1d7348; }
.round-perf-square.perf-yellow { background: #c99a2e; }
.round-perf-square.perf-orange { background: #a8500a; }
.round-perf-legend {
  display: flex;
  justify-content: center;
  gap: 14px;
  font-size: 0.68rem;
  color: var(--text-3);
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
}
.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  display: inline-block;
}
.legend-dot.dot-green  { background: #1d7348; }
.legend-dot.dot-yellow { background: #c99a2e; }
.legend-dot.dot-orange { background: #a8500a; }

.btn-share {
  width: 100%;
  min-height: 44px;
  background: var(--paper);
  border: 1.5px solid var(--ink);
  border-radius: var(--radius-ui);
  color: var(--ink);
  font-family: var(--font-frame);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  margin-bottom: 8px;
  transition: border-color 0.15s, background 0.15s;
}
.btn-share:hover {
  border-color: var(--border-strong);
  background: var(--page);
}

.btn-full {
  width: 100%;
  min-height: 46px;
  background: var(--ink);
  color: var(--paper);
  border: none;
  border-radius: var(--radius-ui);
  font-family: var(--font-frame);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-full:hover { background: #1f3866; }

/* welcome */
.welcome-modal .modal-title,
.completion-modal .modal-title {
  font-stretch: 125%;
  letter-spacing: -0.03em;
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 4px;
}
.welcome-modal .modal-title em {
  font-style: normal;
  background: var(--tint);
  padding: 0 0.14em;
  border-radius: 4px;
}
.welcome-modal .modal-intro {
  font-size: 0.88rem;
  color: var(--text-2);
  margin-bottom: 20px;
  line-height: 1.5;
}

.steps {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
}
.step {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.step-num {
  width: 24px;
  height: 24px;
  background: var(--dark);
  color: #fff;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 800;
  flex-shrink: 0;
}
.step-text {
  font-size: 0.85rem;
  color: var(--text-2);
  line-height: 1.5;
  padding-top: 2px;
}
.step-text strong { color: var(--text); }

/* ─── hint panel ─────────────────────────────────────── */
.hint-panel {
  margin-top: 12px;
  padding: 12px 16px;
  background: var(--soft);
  border: 1.5px solid var(--ink);
  border-radius: var(--radius-ui);
  animation: fadeUp 0.2s ease-out;
}
.hint-panel .hint-label {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 4px;
}
.hint-panel .hint-summary {
  font-size: 0.9rem;
  color: var(--ink);
  line-height: 1.5;
}
.hint-panel.is-wrong {
  border-left-color: var(--err);
}
.hint-panel.is-wrong .hint-label {
  color: var(--err);
}

/* ─── footer ─────────────────────────────────────────── */
footer {
  text-align: center;
  padding: 16px 0 8px;
  font-size: 0.75rem;
  color: var(--text-3);
}
footer a { color: var(--text-2); text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* ─── touch tooltip ──────────────────────────────────── */
.touch-tooltip {
  position: fixed;
  background: var(--ink);
  color: #fff;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 700;
  pointer-events: none;
  z-index: 999;
  transform: translate(-50%, -100%);
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  display: none;
}
.touch-tooltip.visible { display: block; }

/* ─── sequential mode: round dots ────────────────────── */
.round-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.3s;
}
.round-dot.active {
  background: var(--ink);
  box-shadow: 0 0 0 2px rgba(11, 35, 80, 0.2);
}
.round-dot.complete {
  background: var(--ok);
}

/* ─── sequential mode: grid transition ───────────────── */
.grid-wrapper.grid-transitioning #grid {
  opacity: 0;
  transform: scale(0.95);
  transition: opacity 0.3s, transform 0.3s;
}
#grid {
  transition: opacity 0.3s, transform 0.3s;
}


/* ─── responsive ─────────────────────────────────────── */
@media (max-width: 480px) {
  .cell { min-height: 54px; font-size: 16px; padding: 6px 3px; }
  .modal { padding: 24px; }
  .btn-check { padding: 0 16px; margin-right: 2px; }
  .btn-link { padding: 0 9px; }
  .game-rule { font-size: 14px; margin-top: 8px; }
  .rule-long { display: none; }
}

/* ─── results modal: rank, player stats, countdown ───── */
.comp-rank {
  font-size: 0.85rem;
  color: var(--text-2);
  margin-bottom: 14px;
  text-align: center;
  min-height: 1.2em;
}
.player-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 16px;
  text-align: center;
}
.player-stat .value {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
}
.player-stat .label {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text-3);
}
.next-puzzle-countdown {
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-3);
  margin-top: 10px;
}
.quote-reveal .source a {
  color: inherit;
  text-decoration: underline;
}

/* ─── grid message (already played / load error) ────── */
.grid-message {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px 20px;
}
.grid-message-icon { font-size: 2rem; margin-bottom: 12px; }
.grid-message h3 { margin-bottom: 8px; }
.grid-message p { color: var(--text-2); margin-bottom: 14px; }
.action-bar.hidden,
.selection-preview.hidden { display: none; }
.btn-primary {
  padding: 11px 22px;
  background: var(--dark);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}
.btn-primary:hover { background: #1f3866; }

footer {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  line-height: 1.8;
}
footer a { color: inherit; }
