/* App layout and components. Theme tokens and primitives are in theme.css. */

:root[data-mode="dark"] { color-scheme: dark; }

h1, h2, h3 { font-weight: normal; }

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

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

/* The update bar, when there is one, then the page column. */
body {
  display: flex;
  flex-direction: column;
}

.page {
  flex: 1 0 auto;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 14px;
  padding-top: max(14px, env(safe-area-inset-top));
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px 10px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.brand-icon {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border-radius: 7px;
}
.brand-name {
  font-size: 1.2rem;
  color: var(--brand-ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 28px 20px;
  text-align: center;
}
.card p {
  max-width: 34em;
  line-height: 1.5;
  color: var(--ink);
}
.card-icon {
  display: inline-flex;
  width: 56px;
  height: 56px;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  background: var(--brand-fill);
  color: var(--on-brand);
}
.card-icon svg { width: 30px; height: 30px; }

.foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
}
.foot p { max-width: 40em; line-height: 1.5; }
.made {
  display: flex;
  align-items: center;
  gap: 6px;
}
.footer-heart {
  display: inline-flex;
  width: 15px;
  height: 15px;
  /* Fixed meaning: reads as a heart whatever the brand colour. */
  color: #34c759;
}
.footer-heart svg { width: 100%; height: 100%; }

/* Buttons. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 12px;
  font-size: 0.85rem;
  transition: background 0.15s ease;
}
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.btn-primary {
  background: var(--brand-fill);
  color: var(--on-brand);
}
.btn-primary:hover { background: var(--brand-fill-strong); }
.btn-quiet {
  color: var(--ink);
  border: 1px solid var(--surface-border);
}
.pill { border-radius: 999px; }

/* The game card. Panels swap with a class flip; the entrance is CSS. */
.game { padding: 22px 20px; }
.game .hidden { display: none !important; }

.panel {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  animation: panel-in 0.2s ease;
}
@keyframes panel-in {
  from { opacity: 0; transform: translateY(6px); }
}

.card .notice p { color: var(--muted); }

.round-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 4px;
}
.round-actions .btn { padding: 9px 16px; }

.round-meta {
  display: flex;
  gap: 14px;
  font-size: 0.95rem;
}
.card .round-meta { color: var(--muted); }
.score { color: var(--brand-ink); }

/* The speed bonus draining: full for five seconds, gone at twenty. The
   server's clock decides the points; this only shows them going. */
.bonus-bar {
  width: min(260px, 80%);
  height: 6px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface-strong);
}
.bonus-fill {
  display: block;
  height: 100%;
  background: var(--brand-ink);
  transform-origin: left center;
  animation: bonus-drain 20s linear forwards;
}
.bonus-fill.stopped { animation-play-state: paused; }
@keyframes bonus-drain {
  0%, 25% { transform: scaleX(1); }
  100% { transform: scaleX(0); }
}
@media (prefers-reduced-motion: reduce) {
  .bonus-bar { display: none; }
}

.prompt {
  max-width: 30em;
  font-size: 1.45rem;
  line-height: 1.3;
  color: var(--ink);
}
.prompt:focus { outline: none; }

/* Four options: a two by two grid on a wide screen, a column on a phone. */
.options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 520px;
}
.option {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--surface-strong);
  border: 2px solid var(--surface-border);
  color: var(--ink);
  font-size: 1.05rem;
  text-align: left;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}
.option:not(:disabled):hover {
  background: var(--brand-fill);
  color: var(--on-brand);
}
.option:not(:disabled):active { transform: scale(0.98); }
.option:disabled { cursor: default; opacity: 1; }
.option-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--ink) 30%, transparent);
  font-size: 0.8rem;
  color: var(--muted-strong);
}
.option:not(:disabled):hover .option-key { color: var(--on-brand); }
.option-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.option-mark {
  display: inline-flex;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}
.option-mark svg { width: 100%; height: 100%; stroke-width: 2.4; }

/* Waiting for the server after a tap. */
.option.chosen { border-color: var(--brand-ink); }

/* Right and wrong carry an icon and a border as well as a colour. */
.option.right {
  background: color-mix(in srgb, var(--ok) 14%, var(--surface-strong));
  border-color: var(--ok);
}
.option.right .option-mark { color: var(--ok); }
.option.wrong {
  background: color-mix(in srgb, var(--error) 14%, var(--surface-strong));
  border-color: var(--error);
}
.option.wrong .option-mark { color: var(--error); }
.options:has(.right) .option:not(.right, .wrong) { opacity: 0.7; }

.outcome {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface-strong);
  text-align: left;
  animation: panel-in 0.2s ease;
}
.card .verdict { font-size: 1.05rem; }
.card .verdict.ok { color: var(--ok); }
.card .verdict.miss { color: var(--warn); }
.card .fact { color: var(--ink); }

.card .feedback {
  min-height: 1.2em;
  font-size: 0.9rem;
  color: var(--ink);
}
.card .feedback:empty { display: none; }
.card .feedback.error { color: var(--error); }

.next { padding: 10px 20px; font-size: 0.95rem; }

/* A finished game. */
.result-title {
  font-size: 1.8rem;
  color: var(--brand-ink);
}
.result-title:focus { outline: none; }
.card .result-score { font-size: 1.4rem; }
.card .result-correct { color: var(--muted); }

.submit {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin-top: 6px;
}
.submit-label {
  font-size: 0.95rem;
  color: var(--ink);
}
.name-row {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 440px;
}
.name-row .btn {
  padding: 10px 16px;
  font-size: 0.95rem;
}
.field {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--surface-strong);
  /* 3:1 against the card, as a field's edge must be. */
  border: 1px solid color-mix(in srgb, var(--ink) 45%, transparent);
  color: var(--ink);
  font-size: 1rem;
}
.field::placeholder { color: var(--muted-strong); opacity: 1; }
.card .submit-msg {
  min-height: 1.2em;
  font-size: 0.85rem;
  color: var(--error);
}
.card .submit-note {
  font-size: 0.8rem;
  color: var(--muted);
}
.submitted {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 440px;
  padding: 10px 14px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--ok) 14%, transparent);
  text-align: left;
}
.card .submitted p { color: var(--ok); }
.ok-icon {
  display: inline-flex;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--ok);
}
.ok-icon svg { width: 100%; height: 100%; }

/* Settings modal. */
.modal .hidden { display: none !important; }
.saved-name {
  font-size: 0.95rem;
  color: var(--ink);
}
.modal .name-row { max-width: none; }
.clear-name { align-self: flex-start; }

.setting-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  font-size: 0.9rem;
  color: var(--ink);
  text-align: left;
}
.setting-toggle > span:first-child { flex: 1; }
.switch-state {
  font-size: 0.8rem;
  color: var(--muted-strong);
}
.switch {
  position: relative;
  flex-shrink: 0;
  width: 40px;
  height: 24px;
  border-radius: 999px;
  background: var(--surface-strong);
  border: 1px solid color-mix(in srgb, var(--ink) 45%, transparent);
  transition: background 0.18s ease, border-color 0.18s ease;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--muted-strong);
  transition: transform 0.18s ease, background 0.18s ease;
}
.setting-toggle[aria-checked="true"] .switch {
  background: var(--brand-ink);
  border-color: var(--brand-ink);
}
.setting-toggle[aria-checked="true"] .switch::after {
  background: var(--bg);
  transform: translateX(16px);
}

/* Leaderboard modal. */
.board-body {
  min-height: 120px;
  max-height: 50vh;
  overflow-y: auto;
  transition: opacity 0.15s ease;
}
.board-body[aria-busy="true"] { opacity: 0.6; }
.board-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.board-table th {
  padding: 6px 8px;
  text-align: left;
  font-weight: normal;
  font-size: 0.8rem;
  color: var(--muted-strong);
}
.board-table td {
  padding: 7px 8px;
  border-top: 1px solid var(--surface-border);
  color: var(--ink);
  overflow-wrap: anywhere;
}
.board-table th:first-child,
.board-table td:first-child { width: 2.5em; color: var(--muted-strong); }
.board-empty {
  padding: 32px 8px;
  text-align: center;
  color: var(--muted-strong);
}

/* Station list modal. */
.stations-modal { max-width: 520px; }
.stations-modal .field { flex: none; }
.station-list {
  list-style: none;
  max-height: 55vh;
  overflow-y: auto;
}
.station {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 12px;
  padding: 8px 4px;
  border-top: 1px solid var(--surface-border);
}
.station-name { color: var(--ink); }
.station-zh {
  margin-left: 4px;
  color: var(--muted-strong);
}
.station-codes {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  font-size: 0.8rem;
  color: var(--ink);
}
.chip.code { letter-spacing: 0.03em; }
.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  /* A line's own colour: fixed meaning, like the footer heart. */
  background: var(--dot);
  border: 1px solid color-mix(in srgb, var(--ink) 30%, transparent);
}

/* Update bar, per update-bar-spec.md. Quieter than the header, full width,
   tinted enough to read as a notice. */
.update-notice {
  flex: none;
  background: color-mix(in srgb, var(--brand-ink) 12%, var(--bg));
  border-bottom: 1px solid var(--surface-border);
  color: var(--ink);
  font-size: 0.875rem;
}
.update-notice-inner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  max-width: 720px;
  margin: 0 auto;
  padding: 0.5rem 1rem;
  /* Under the notch on a phone, where the bar is the topmost thing on screen. */
  padding-top: max(0.5rem, env(safe-area-inset-top));
}
.update-notice p { flex: 1 1 auto; min-width: 0; }
.update-notice .btn {
  flex: none;
  padding: 6px 12px;
}

/* With the bar showing, it owns the notch and the page does not pad for it. */
.update-notice + .page { padding-top: 14px; }

@media (max-width: 480px) {
  .page {
    padding: 10px;
    padding-top: max(10px, env(safe-area-inset-top));
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }
  .update-notice + .page { padding-top: 10px; }
  .topbar { padding: 8px 8px 8px 12px; }
  /* Five header buttons leave no room for the name on a phone; the icon
     stays, and the heading is still read out. */
  .brand-name {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
  .topbar-actions { gap: 6px; }
  /* Five 42px buttons and the icon fit a 320px screen at 38px. */
  .topbar-actions .icon-btn { width: 38px; height: 38px; }
  .game { padding: 18px 14px; }
  .prompt { font-size: 1.25rem; }
  .options { grid-template-columns: 1fr; }
  .result-title { font-size: 1.5rem; }
  .update-notice-inner { flex-wrap: wrap; }
  .update-notice p { flex-basis: 100%; }
}
