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

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

h1, h2 { 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 h2 {
  font-size: 1.4rem;
  color: var(--brand-ink);
}
.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;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}
.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 {
  padding: 8px 14px;
  border-radius: 12px;
  font-size: 0.85rem;
  transition: background 0.15s ease;
}
.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);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.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); }
}

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

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

/* The masked name. A word never breaks across lines; words wrap. Sized so
   the longest word, twelve letters, fits a 320px screen. */
.mask {
  --tile: clamp(18px, calc((100vw - 64px) / 14), 40px);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px calc(var(--tile) * 0.6);
  padding: 6px 0 2px;
}
.word {
  display: inline-flex;
  gap: 4px;
  white-space: nowrap;
}
.tile,
.sep {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: calc(var(--tile) * 1.25);
  font-size: calc(var(--tile) * 0.72);
  color: var(--ink);
}
.tile {
  width: var(--tile);
  border-radius: 8px;
  background: var(--surface-strong);
  border: 1px solid var(--surface-border);
}
.tile.blank { position: relative; }
.tile.blank::after {
  content: "";
  position: absolute;
  left: 22%;
  right: 22%;
  bottom: 18%;
  height: 2px;
  border-radius: 2px;
  background: var(--muted-strong);
}
.tile.fresh {
  background: var(--brand-fill-strong);
  color: var(--on-brand);
  animation: tile-pop 0.22s ease;
}
@keyframes tile-pop {
  from { transform: scale(0.6); opacity: 0; }
}

/* Time to the next letter from the clock. */
.reveal-bar {
  width: min(260px, 80%);
  height: 6px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface-strong);
}
.reveal-fill {
  display: block;
  height: 100%;
  background: var(--brand-ink);
  transform-origin: left center;
  animation: reveal-fill var(--ms, 15s) linear forwards;
}
@keyframes reveal-fill {
  from { transform: scaleX(var(--from, 0)); }
  to { transform: scaleX(1); }
}
@media (prefers-reduced-motion: reduce) {
  .reveal-bar { display: none; }
}
.card .reveal-note {
  font-size: 0.85rem;
  color: var(--muted);
}

/* Text fields: the guess, and the leaderboard name. */
.guess {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 440px;
}
.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; }
.guess .btn {
  padding: 10px 16px;
  font-size: 0.95rem;
}
.field.shake { animation: shake 0.3s ease; }
@keyframes shake {
  25% { transform: translateX(-6px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}

.card .feedback {
  min-height: 1.4em;
  font-size: 0.9rem;
  color: var(--ink);
}
.card .feedback.miss { color: var(--warn); }
.card .feedback.error { color: var(--error); }

/* Hints bought so far. */
.hints {
  display: grid;
  gap: 8px;
  width: 100%;
  max-width: 440px;
}
.hint-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--surface-strong);
  text-align: left;
}
.hint-row dt {
  font-size: 0.85rem;
  color: var(--muted-strong);
  flex-shrink: 0;
}
.hint-row dd {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  color: var(--ink);
  text-align: right;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  font-size: 0.9rem;
  color: var(--ink);
}
.chip.code { letter-spacing: 0.03em; }
.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--dot);
  border: 1px solid color-mix(in srgb, var(--ink) 30%, transparent);
}
.zh { font-size: 1.3rem; }

/* The map hint. Leaflet's own look is kept to the controls, restyled to
   the theme. */
.map-hint {
  width: 100%;
  max-width: 440px;
}
.map {
  height: clamp(220px, 60vw, 320px);
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--surface-border);
}
.map.leaflet-container {
  background: var(--bg);
  font: inherit;
}
.map .leaflet-bar {
  border: 1px solid var(--surface-border);
  box-shadow: none;
}
.map .leaflet-bar a,
.map .leaflet-bar a:hover {
  background: color-mix(in srgb, var(--ink) 8%, var(--bg));
  color: var(--ink);
  border-bottom-color: var(--surface-border);
}
/* Leaflet's stylesheet loads after this one, so these outrank it on
   specificity rather than order. */
.map.leaflet-container .leaflet-control-attribution {
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  color: var(--muted);
  font-size: 0.7rem;
}
.map.leaflet-container .leaflet-control-attribution a { color: var(--brand-ink); }
.map-failed {
  padding: 40px 16px;
  color: var(--muted);
}

/* Two rings and a dot, as telegram-bot/mapimage.py draws them. */
.leaflet-div-icon.station-ring {
  background: none;
  border: none;
}
.station-ring span,
.station-ring span::before,
.station-ring span::after {
  position: absolute;
  top: 50%;
  left: 50%;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}
.station-ring span {
  width: 40px;
  height: 40px;
  border: 3px solid var(--ink);
}
.station-ring span::before {
  content: "";
  width: 20px;
  height: 20px;
  border: 3.5px solid var(--ink);
}
.station-ring span::after {
  content: "";
  width: 7px;
  height: 7px;
  background: var(--ink);
}

.round-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 4px;
}
.round-actions .btn { padding: 9px 16px; }
#giveUpBtn.armed {
  color: var(--error);
  border-color: var(--error);
}

/* A finished round. */
.result-title {
  font-size: 1.8rem;
  font-weight: normal;
  color: var(--brand-ink);
}
.result-title:focus { outline: none; }
.card .result-alt { font-size: 1.1rem; }
.result-codes {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}
.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);
}
.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%; }

/* Map hint colours pinned by the setting rather than following the page:
   theme.css's own light and dark mode tokens, redefined on the map alone. */
.map[data-map-style="light"] {
  --bg: #eef2f0;
  --ink: #121815;
  --muted: #5b665f;
  --surface-border: rgba(255, 255, 255, 0.65);
  --brand-ink: #1f6b3d;
}
.map[data-map-style="dark"] {
  --bg: #0c100e;
  --ink: #eef2ef;
  --muted: #9aa7a0;
  --surface-border: rgba(255, 255, 255, 0.14);
  --brand-ink: #bff5cf;
}

/* Settings modal. */
.modal .hidden { display: none !important; }
.saved-name {
  font-size: 0.95rem;
  color: var(--ink);
}
.modal .guess { max-width: none; }
.clear-name { align-self: flex-start; }
.mode-toggle.thirds { grid-template-columns: repeat(3, 1fr); }

.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);
}

#hintBtn.armed {
  color: var(--warn);
  border-color: var(--warn);
}

/* 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);
}

/* Three cards share the page: the solo round, a party game and a replay.
   Only one shows; js/ui.js showView() sets `hidden` on the others. */
.card[hidden] { display: none; }

#partyBtn[aria-pressed="true"] {
  background: var(--brand-fill);
  color: var(--on-brand);
}

/* The time limit, solo and party: drains left to right. */
.time-bar {
  width: min(260px, 80%);
  height: 6px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface-strong);
}
.time-bar > span {
  display: block;
  height: 100%;
  background: var(--ok);
  transform-origin: left center;
  transition: transform 0.25s linear;
}
.time-bar.low > span { background: var(--error); }
.time-left { font-variant-numeric: tabular-nums; }
.card .round-meta { flex-wrap: wrap; justify-content: center; }

/* The party's next-letter bar is drawn from snapshots, not a CSS timer. */
.reveal-bar.meter .reveal-fill {
  animation: none;
  transform: scaleX(0);
  transition: transform 0.1s linear;
}

.card .result-breakdown {
  font-size: 0.85rem;
  color: var(--muted);
}
.card .share-msg {
  min-height: 1.2em;
  font-size: 0.85rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}

/* Party games. */
.party-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 6px 6px 12px;
  border-radius: 14px;
  background: var(--surface-strong);
  font-size: 0.85rem;
  text-align: left;
}
.party-bar-text { flex: 1; min-width: 0; color: var(--ink); }
.party-bar .btn { padding: 6px 12px; flex-shrink: 0; }

.status-dot {
  width: 10px;
  height: 10px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--busy);
}
.status-dot.ok { background: var(--ok); }
.status-dot.warn { background: var(--warn); }
.status-dot.error { background: var(--error); }

.panel-title {
  font-size: 1.3rem;
  font-weight: normal;
  color: var(--brand-ink);
}
.name-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  width: 100%;
  max-width: 280px;
  text-align: left;
}
.card .party-or { color: var(--muted); font-size: 0.9rem; }
.code-field {
  text-transform: uppercase;
  letter-spacing: 0.2em;
  text-align: center;
}
.code-field::placeholder { letter-spacing: normal; }
.card .party-note {
  font-size: 0.8rem;
  color: var(--muted);
}

.card .block-label {
  font-size: 0.85rem;
  color: var(--muted-strong);
}
.invite,
.lobby-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 440px;
}
.lobby-block .mode-toggle { width: 100%; }
.mode-toggle.quarters { grid-template-columns: repeat(4, 1fr); }

/* The code in large type, read across a room. */
.party-code {
  font-size: clamp(2rem, 11vw, 3rem);
  letter-spacing: 0.18em;
  padding: 2px 6px 2px 14px;
  border-radius: 14px;
  color: var(--brand-ink);
  font-variant-numeric: tabular-nums;
}
/* Centred, black on white whatever the theme, with its quiet zone, so a
   phone pointed at the middle of the screen finds it. */
.qr {
  display: flex;
  justify-content: center;
  width: 100%;
}
.qr svg {
  width: min(220px, 60vw);
  height: auto;
  border-radius: 10px;
}
.qr .qr-bg { fill: #ffffff; }
.qr .qr-fg { fill: #000000; }
.card .party-link {
  font-size: 0.8rem;
  color: var(--muted);
  overflow-wrap: anywhere;
  user-select: text;
}

.custom-length {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--ink);
}
.custom-length .field { width: 6em; flex: none; text-align: center; }
.card .settings-text { color: var(--ink); }
.card .scoring-note { max-width: 440px; margin-top: 0; }

.player-list {
  display: grid;
  gap: 6px;
  width: 100%;
  max-width: 440px;
  list-style: none;
}
.player-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 6px 8px 6px 12px;
  border-radius: 12px;
  background: var(--surface-strong);
  color: var(--ink);
  text-align: left;
}
.player-list li.away { opacity: 0.6; }
.player-name {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}
.tag {
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--surface-border);
  font-size: 0.75rem;
  color: var(--muted-strong);
}
.player-list.compact li { min-height: 0; padding: 6px 12px; font-size: 0.9rem; }
.player-list .state { font-size: 0.8rem; color: var(--muted-strong); }
.player-list .state.solved { color: var(--ok); }
.player-list .state.gave_up,
.player-list .state.out { color: var(--warn); }
.player-list .total {
  min-width: 3.5em;
  text-align: right;
  color: var(--brand-ink);
  font-variant-numeric: tabular-nums;
}

.ready-title { font-size: 1.2rem; color: var(--brand-ink); }
.ready-count {
  font-size: 4rem;
  line-height: 1;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.standings { max-width: 440px; }
.standings tr.me td { color: var(--brand-ink); }
.standings td:last-child,
.standings th:last-child { text-align: right; }

/* Replays. */
.replay-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.card .replay-meta { font-size: 0.9rem; color: var(--ink); }
.card .replay-trust { font-size: 0.8rem; color: var(--muted); }
.turn-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
}
.replay-answer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.replay-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 440px;
}
.scrub {
  flex: 1;
  min-width: 0;
  accent-color: var(--brand-ink);
}
#rvSpeed { width: 100%; max-width: 440px; }
.player-list.picks li { padding: 0; background: none; }
.player-pick {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: var(--surface-strong);
  color: var(--ink);
  text-align: left;
}
.player-pick.active { border-color: var(--brand-ink); }
.player-state { font-size: 0.8rem; color: var(--muted-strong); text-align: right; }
.replay-log {
  width: 100%;
  max-width: 440px;
  max-height: 220px;
  overflow-y: auto;
  list-style: none;
  display: grid;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--ink);
  text-align: left;
}
.replay-log li { display: flex; gap: 10px; }
.log-time {
  flex-shrink: 0;
  min-width: 2.6em;
  color: var(--muted-strong);
  font-variant-numeric: tabular-nums;
}
.log-empty { color: var(--muted); }

/* 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; }
  /* Four 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 header buttons at 320px. */
  .topbar-actions .icon-btn { width: 38px; height: 38px; }
  .game { padding: 18px 14px; }
  .result-title { font-size: 1.5rem; }
  .update-notice-inner { flex-wrap: wrap; }
  .update-notice p { flex-basis: 100%; }
}
