:root {
  --paper: #f4f1ea;
  --paper-raised: #ffffff;
  --ink: #1d1f22;
  --muted: #64676d;
  --line: #dcd7cc;
  --course: #b4520f;          /* runway-light amber, darkened to read on paper */
  --course-soft: #b4520f1a;
  --on-course: #ffffff;
  --found: #2c7a4b;
  --missed: #a53b2a;
  --near: #b98a00;
  --mid: #c8601a;
  --far: #b23a2e;
  --focus: #1f6fa8;
  /* The board: printed-timetable light here, amber on black in dark mode. */
  --board: #ffffff;
  --board-row: #f8f5ef;
  --board-line: #e7e2d7;
  --board-edge: #dcd7cc;
  --board-accent: #b4520f;
  --flap: #1d1f22;
  --flap-dim: #6b6e74;
  --flap-blank: #ece7dc;
  --landed: #2c7a4b;
  --late: #b23a2e;
  --font: "Familjen Grotesk", ui-sans-serif, system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #111315;
    --paper-raised: #1a1d20;
    --ink: #e7e5e0;
    --muted: #9a9ea5;
    --line: #2c3035;
    --course: #ffb347;
    --course-soft: #ffb34721;
    --on-course: #16181b;
    --found: #5fbf85;
    --missed: #e07b67;
    --near: #e8c547;
    --mid: #f08d4f;
    --far: #e5655a;
    --focus: #6cb4e6;
    --board: #0b0c0e;
    --board-row: #16181b;
    --board-line: #25282c;
    --board-edge: #0b0c0e;
    --board-accent: #ffc23d;
    --flap: #ffc23d;
    --flap-dim: #8a8f97;
    --flap-blank: #292d32;
    --landed: #6fd39a;
    --late: #ff7b5c;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #111315;
  --paper-raised: #1a1d20;
  --ink: #e7e5e0;
  --muted: #9a9ea5;
  --line: #2c3035;
  --course: #ffb347;
  --course-soft: #ffb34721;
  --on-course: #16181b;
  --found: #5fbf85;
  --missed: #e07b67;
  --near: #e8c547;
  --mid: #f08d4f;
  --far: #e5655a;
  --focus: #6cb4e6;
  --board: #0b0c0e;
  --board-row: #16181b;
  --board-line: #25282c;
  --board-edge: #0b0c0e;
  --board-accent: #ffc23d;
  --flap: #ffc23d;
  --flap-dim: #8a8f97;
  --flap-blank: #292d32;
  --landed: #6fd39a;
  --late: #ff7b5c;
  color-scheme: dark;
}

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

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
}

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

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.shell {
  max-width: 520px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

/* Header */
.top { display: flex; align-items: center; gap: 12px; padding: 4px 0 8px; }
.wordmark { margin: 0 auto 0 0; font-size: 1.375rem; font-weight: 700; letter-spacing: -0.01em; }
.modes { display: flex; border: 1px solid var(--line); border-radius: 999px; padding: 2px; }
.mode {
  border: 0; background: none; padding: 4px 12px; border-radius: 999px;
  font-size: 0.875rem; font-weight: 500; color: var(--muted); cursor: pointer;
}
.mode[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.icon-btn {
  flex-shrink: 0; display: grid; place-items: center;
  width: 32px; height: 32px; padding: 0;
  border-radius: 50%; border: 1px solid var(--line); background: none;
  font-weight: 600; cursor: pointer;
}
.icon-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.status { display: flex; align-items: center; gap: 12px; }
.puzzle-title { margin: 0 auto 0 0; color: var(--muted); font-size: 0.9375rem; }
.tries { display: flex; gap: 4px; margin: 0; }
.pip { width: 10px; height: 10px; border-radius: 50%; background: var(--course); border: 1.5px solid var(--course); }
.pip.spent { background: none; border-color: var(--muted); opacity: 0.6; }

.task { margin: 14px 0 10px; font-size: 1.375rem; line-height: 1.2; letter-spacing: -0.01em; }

/* Board */
.board {
  background: var(--board);
  border-radius: 12px;
  padding: 10px 10px 6px;
  font-family: var(--mono);
  color: var(--flap);
  border: 1px solid var(--board-edge);
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.08);
}
.board-head {
  display: flex; align-items: center; gap: 10px;
  padding: 2px 4px 8px;
  border-bottom: 1px solid var(--board-line);
}
.board-title {
  display: flex; align-items: center; gap: 8px; margin-right: auto;
  color: var(--board-accent); font-weight: 700; text-transform: uppercase; letter-spacing: 0.12em; font-size: 0.875rem;
}
.board-title svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; }
.board-clock { color: var(--flap-dim); font-size: 0.8125rem; }
.board-code {
  min-width: 3.4em; padding: 2px 6px; border-radius: 4px; text-align: center;
  background: var(--flap-blank); color: var(--flap-dim); font-weight: 700; letter-spacing: 0.08em;
}
.board-code.solved { color: var(--board); background: var(--board-accent); animation: flip 0.45s ease-out; }

.board-cols, .row {
  display: grid;
  grid-template-columns: 6.6ch 7.6ch minmax(0, 1fr);
  column-gap: 10px;
}
.board-cols {
  padding: 6px 4px 4px;
  color: var(--flap-dim); font-size: 0.6875rem; text-transform: uppercase; letter-spacing: 0.1em;
}
.rows { list-style: none; margin: 0; padding: 0; }
.row {
  align-items: start;
  padding: 7px 4px;
  border-top: 1px solid var(--board-line);
  font-size: 0.875rem;
  line-height: 1.3;
}
.row:nth-child(odd) { background: var(--board-row); }
.r-time { display: flex; flex-direction: column; font-weight: 700; }
.r-status { font-size: 0.6875rem; font-weight: 500; letter-spacing: 0.02em; white-space: nowrap; }
.r-status.landed { color: var(--landed); }
.r-status.ontime { color: var(--flap-dim); }
.r-status.late { color: var(--late); }
.r-flight { font-weight: 700; white-space: nowrap; }
.r-from { display: flex; flex-direction: column; min-width: 0; }
.r-city { font-weight: 700; text-transform: uppercase; overflow-wrap: anywhere; }
.r-airline { color: var(--flap-dim); font-size: 0.75rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.hidden .r-time { color: var(--flap-dim); }
.flap { display: block; height: 1.05em; margin-top: 0.15em; border-radius: 3px; background: var(--flap-blank); width: 6ch; }
.flap.wide { width: 70%; }
.row.fresh > span { animation: flip 0.5s ease-out both; }
.row.fresh > span:nth-child(2) { animation-delay: 0.08s; }
.row.fresh > span:nth-child(3) { animation-delay: 0.16s; }
@keyframes flip {
  0% { transform: perspective(300px) rotateX(-90deg); opacity: 0.2; }
  60% { transform: perspective(300px) rotateX(12deg); opacity: 1; }
  100% { transform: none; }
}

/* Guessing */
.play { margin-top: 14px; }
.guess-form { display: flex; gap: 8px; }
.combo { position: relative; flex: 1; min-width: 0; }
.combo input {
  width: 100%; height: 48px; padding: 0 14px;
  border: 1.5px solid var(--line); border-radius: 10px;
  background: var(--paper-raised);
}
.combo input:focus { border-color: var(--course); outline: none; }
.suggest {
  position: absolute; z-index: 5; left: 0; right: 0; top: calc(100% + 4px);
  list-style: none; margin: 0; padding: 4px;
  background: var(--paper-raised); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 10px 28px rgb(0 0 0 / 0.16);
}
.suggest li {
  display: flex; align-items: baseline; gap: 8px;
  padding: 8px 10px; border-radius: 7px; cursor: pointer;
}
.suggest li[aria-selected="true"] { background: var(--course-soft); }
.suggest li.used { opacity: 0.45; }
.opt-city { font-weight: 600; white-space: nowrap; flex-shrink: 0; }
.opt-country { min-width: 0; color: var(--muted); font-size: 0.875rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.opt-codes { margin-left: auto; font-family: var(--mono); font-size: 0.75rem; color: var(--muted); }

.check-btn {
  height: 48px; padding: 0 20px;
  border: 0; border-radius: 10px;
  background: var(--course); color: var(--on-course);
  font-weight: 700; cursor: pointer;
}
.skip-btn {
  display: block; margin: 0 auto; padding: 6px 10px;
  border: 0; background: none; color: var(--muted);
  font-size: 0.875rem; text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
}
.skip-btn:hover { color: var(--course); }
.skip-btn[hidden] { display: none; }
.form-msg { min-height: 1.4em; margin: 6px 0 0; font-size: 0.875rem; color: var(--muted); text-align: center; }

.guesses { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.guess {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-left: 4px solid var(--far);
}
.guess.near { border-left-color: var(--near); }
.guess.mid { border-left-color: var(--mid); }
.guess.right { border-left-color: var(--found); }
.g-city { font-weight: 600; margin-right: auto; }
.g-info { display: flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; color: var(--muted); }
.guess.right .g-info { color: var(--found); font-weight: 600; }
.g-arrow { width: 18px; height: 18px; fill: none; stroke: var(--ink); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Result */
.result {
  margin-top: 16px; padding: 16px;
  border-radius: 12px; background: var(--paper-raised); border: 1px solid var(--line);
}
.result .verdict { margin: 0 0 2px; font-weight: 600; }
.result.won .verdict { color: var(--found); }
.result.lost .verdict { color: var(--missed); }
.result h2 { margin: 0; font-size: 1.5rem; line-height: 1.2; }
.answer { margin: 10px 0 0; font-weight: 600; }
.answer-code {
  display: inline-block; margin-right: 4px; padding: 1px 6px; border-radius: 4px;
  font-family: var(--mono); font-size: 0.875rem;
  background: var(--board-accent); color: var(--board);
}
.result .note { margin: 8px 0 0; }
.grid { margin: 12px 0 0; font-size: 1.125rem; letter-spacing: 0.05em; }
.stats { display: flex; flex-wrap: wrap; gap: 8px 24px; margin: 16px 0 0; padding: 0; }
.stats div { display: flex; flex-direction: column; }
.stats dt { order: 2; font-size: 0.8125rem; color: var(--muted); }
.stats dd { margin: 0; font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.next-daily { margin: 12px 0 0; color: var(--muted); font-size: 0.9375rem; }
.result-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.secondary-btn {
  height: 48px; padding: 0 18px;
  border-radius: 10px; border: 1.5px solid var(--ink); background: none;
  font-weight: 600; cursor: pointer;
}

.credit { margin-top: 32px; font-size: 0.75rem; color: var(--muted); text-align: center; }
.credit a { color: inherit; }

/* Help */
.help {
  max-width: min(400px, calc(100vw - 32px));
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--paper-raised); color: var(--ink);
  padding: 20px;
}
.help::backdrop { background: rgb(10 12 14 / 0.5); }
.help h2 { margin: 0 0 8px; font-size: 1.25rem; }
.help p { margin: 0 0 10px; }
.help-small { color: var(--muted); font-size: 0.875rem; }
.help form { margin-top: 16px; }

@media (max-width: 380px) {
  .top { gap: 8px; }
  .wordmark { font-size: 1.25rem; }
  .mode { padding: 4px 9px; }
  .row, .board-cols { grid-template-columns: 5.6ch 7.2ch minmax(0, 1fr); column-gap: 8px; }
  .row { font-size: 0.8125rem; }
}

@media (prefers-reduced-motion: reduce) {
  .row.fresh > span, .board-code.solved { animation: none; }
}
