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

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

/* A QR code is dark on light or it does not scan, whatever the theme: the
   fixed-meaning exception to theme tokens, like the footer heart. */
:root {
  --qr-light: #ffffff;
  --qr-dark: #121815;
}

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: 22px 20px;
  text-align: center;
}
.card p {
  line-height: 1.5;
  color: var(--ink);
}

.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 {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0 6px;
}
.foot .credits {
  display: block;
  font-size: 0.75rem;
}
.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, color 0.15s ease, border-color 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);
  background: var(--surface-strong);
}
.pill { border-radius: 999px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  border-radius: 999px;
  background: var(--surface-strong);
  border: 1px solid var(--surface-border);
  font-size: 0.85rem;
  color: var(--ink);
}
.chip:empty { display: none; }
.chip-btn { cursor: pointer; letter-spacing: 0.03em; }

/* The game card. Panels swap with a class flip; the entrance is CSS. */
.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); }
}
.panel-title {
  font-size: 1.3rem;
  color: var(--brand-ink);
}

/* New game. */
.setup { gap: 14px; }
.field-group {
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
}
.field-label {
  font-size: 0.9rem;
  color: var(--ink);
}
.card .field-note {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.4;
}
.card .field-note.error { color: var(--error); }
.field-note:empty { display: none; }
.mode-toggle.thirds { grid-template-columns: repeat(3, 1fr); }
.mode-btn[aria-checked="true"] {
  background: var(--brand-fill);
  color: var(--on-brand);
}
.mode-btn { color: var(--muted-strong); }
.mode-btn:disabled { opacity: 0.45; }

.level-pick,
.count-pick {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 4px;
  border-radius: 14px;
  background: var(--surface);
}
.count-pick { grid-template-columns: repeat(5, 1fr); }
.level-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 7px 2px;
  border-radius: 10px;
  color: var(--muted-strong);
  transition: background 0.15s ease, color 0.15s ease;
}
.level-btn b {
  font-weight: normal;
  font-size: 1.05rem;
}
.level-btn small { font-size: 0.72rem; }
.level-btn[aria-checked="true"] {
  background: var(--brand-fill);
  color: var(--on-brand);
}

.custom-count {
  display: flex;
  align-items: center;
  gap: 10px;
}
.custom-count .field { flex: 0 0 110px; }
.field-suffix {
  font-size: 0.85rem;
  color: var(--muted);
}

.start-btn {
  padding: 12px 30px;
  font-size: 1rem;
}
.start-btn svg { width: 18px; height: 18px; }

/* Playing with others, under the new game. */
.together {
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--surface-border);
  text-align: left;
}
.together > .btn { align-self: center; }
.join {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}

/* Text fields: the seed, a join code, a typed answer, the leaderboard name. */
.guess {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 460px;
}
.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; }
.seed-field,
.code-field { letter-spacing: 0.06em; text-transform: uppercase; }
.seed-field::placeholder,
.code-field::placeholder { letter-spacing: normal; text-transform: none; }
.field.shake { animation: shake 0.3s ease; }
@keyframes shake {
  25% { transform: translateX(-6px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}
.guess .btn {
  padding: 10px 16px;
  font-size: 0.95rem;
}

/* The game. */
.play { gap: 10px; }
.game-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.progress {
  width: 100%;
  max-width: 520px;
  height: 8px;
  border-radius: 999px;
  background: var(--surface-strong);
  border: 1px solid var(--surface-border);
  overflow: hidden;
}
.progress > span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--brand-ink);
  transition: width 0.25s ease;
}

/* The flag. A fixed box, so the answers below do not jump as flags of
   different shapes come and go. */
.flag-stage {
  --stage-h: clamp(150px, 36vw, 280px);
  position: relative;
  width: 100%;
  max-width: 520px;
  height: var(--stage-h);
  display: grid;
  place-items: center;
  padding: 10px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
}
.flag-img {
  /* In pixels from the stage, since a percentage of a grid cell's height
     does not resolve and a tall flag would spill over the answers. */
  max-width: 100%;
  max-height: calc(var(--stage-h) - 20px);
  width: auto;
  height: auto;
  /* Flags with white edges need an edge to read against a pale card. */
  outline: 1px solid color-mix(in srgb, var(--ink) 25%, transparent);
  border-radius: 6px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: scale(0.98);
  transition: opacity 0.18s ease, transform 0.18s ease;
  -webkit-user-drag: none;
}
.flag-img:not([src]) { visibility: hidden; }
.flag-stage.loaded .flag-img {
  opacity: 1;
  transform: none;
}
.card .flag-note {
  position: absolute;
  inset: auto 10px 10px;
  font-size: 0.85rem;
  color: var(--error);
}
.flag-note:empty { display: none; }

.turn-timer {
  width: 100%;
  max-width: 520px;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-strong);
  overflow: hidden;
}
.turn-timer > span {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--warn);
  transition: width 0.1s linear;
}

.card .prompt {
  font-size: 1.05rem;
  color: var(--ink);
}

/* The names to pick from. */
.options {
  width: 100%;
  max-width: 520px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.options.six { grid-template-columns: repeat(3, 1fr); }
.answer {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--surface-strong);
  border: 2px solid var(--surface-border);
  color: var(--ink);
  font-size: 0.95rem;
  text-align: left;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.answer:not(:disabled):hover {
  transform: translateY(-1px);
  background: var(--brand-fill);
  color: var(--on-brand);
}
/* An answer that is over shows at full strength, not greyed. */
.answer:disabled { cursor: default; opacity: 1; }
.answer-key {
  display: none;
  flex-shrink: 0;
  width: 1.5em;
  height: 1.5em;
  place-items: center;
  border-radius: 6px;
  border: 1px solid color-mix(in srgb, var(--ink) 35%, transparent);
  font-size: 0.75rem;
  color: var(--muted-strong);
}
.options.show-keys .answer-key { display: inline-grid; }
.answer-name { overflow-wrap: anywhere; }
.answer.picked { border-color: var(--brand-ink); }
.answer.right {
  background: color-mix(in srgb, var(--ok) 16%, var(--surface-strong));
  border-color: var(--ok);
  color: var(--ink);
}
.answer.wrong {
  background: color-mix(in srgb, var(--error) 14%, var(--surface-strong));
  border-color: var(--error);
  color: var(--ink);
  text-decoration: line-through;
  text-decoration-color: var(--error);
}
.answer.right,
.answer.wrong { animation: mark-in 0.18s ease; }
@keyframes mark-in {
  from { transform: scale(0.97); }
}

.typed { max-width: 520px; }
.typed .field.right { border-color: var(--ok); }
.typed .field.wrong { border-color: var(--error); }

.card .feedback {
  min-height: 1.5em;
  font-size: 0.95rem;
  color: var(--ink);
}
.card .feedback[data-tone="ok"] { color: var(--ok); }
.card .feedback[data-tone="bad"] { color: var(--error); }

.game-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}
.game-actions .btn { padding: 9px 15px; }
#quitBtn.armed {
  color: var(--error);
  border-color: var(--error);
}
.keys-note { max-width: 460px; }

/* Players in a game together. */
.mp-strip {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}
.mp-strip li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-strong);
  border: 1px solid var(--surface-border);
  font-size: 0.85rem;
  color: var(--ink);
  transition: background 0.15s ease, border-color 0.15s ease;
}
.mp-strip li.you { border-color: var(--brand-ink); }
.mp-strip li.active {
  background: var(--brand-fill);
  color: var(--on-brand);
}
.mp-strip li.gone { opacity: 0.55; }
.mp-score { color: var(--muted-strong); font-variant-numeric: tabular-nums; }
.mp-strip li.active .mp-score { color: var(--on-brand); }
.mp-dot {
  width: 9px;
  height: 9px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--surface-border);
  border: 1px solid color-mix(in srgb, var(--ink) 30%, transparent);
}
.mp-strip li.answered .mp-dot { background: var(--busy); }
.mp-strip li.right .mp-dot { background: var(--ok); }
.mp-strip li.wrong .mp-dot { background: var(--error); }

.net-bar {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--surface-strong);
  font-size: 0.85rem;
  color: var(--ink);
}
.net-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--busy);
}
.net-bar[data-tone="ok"] .net-dot { background: var(--ok); }
.net-bar[data-tone="warn"] .net-dot { background: var(--warn); }
.net-bar[data-tone="error"] .net-dot { background: var(--error); }

/* Hosting and joining. */
.card .lobby-summary { color: var(--ink); }
.net .net-lead { color: var(--muted); max-width: 30em; }
.code-big {
  font-size: 2.4rem;
  letter-spacing: 0.22em;
  color: var(--brand-ink);
  user-select: text;
}
.qr svg {
  width: 180px;
  height: 180px;
  display: block;
  margin: 0 auto;
  border-radius: 12px;
}
.qr .qr-bg { fill: var(--qr-light); }
.qr .qr-fg { fill: var(--qr-dark); }
.host-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.lobby-players {
  list-style: none;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.lobby-players:empty { display: none; }
.lobby-players li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  color: var(--ink);
  text-align: left;
}
.lobby-players .mp-dot { background: var(--ok); }
.lobby-players li.gone { opacity: 0.55; }
.lobby-players li.gone .mp-dot { background: var(--surface-border); }
.card .net-status { min-height: 1.5em; color: var(--ink); }
.card .net-status.error { color: var(--error); }

/* The replay. */
.replay {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  animation: panel-in 0.2s ease;
}
.replay-controls {
  display: flex;
  gap: 8px;
}
.replay-controls .play-btn {
  background: var(--brand-fill);
  color: var(--on-brand);
}
.speed-pick {
  grid-template-columns: repeat(4, 1fr);
  width: min(100%, 280px);
}
.scrub {
  width: 100%;
  accent-color: var(--brand-ink);
}
.card .replay-label {
  font-size: 0.85rem;
  color: var(--muted);
}
.turn-list {
  list-style: none;
  width: 100%;
  max-height: 170px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 2px 8px;
  padding: 6px;
  border-radius: 12px;
  background: var(--surface);
  text-align: left;
}
.turn-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 6px;
  border-radius: 8px;
  color: var(--ink);
  font-size: 0.85rem;
  text-align: left;
}
.turn-btn.current {
  background: var(--brand-fill);
  color: var(--on-brand);
}
.turn-num {
  min-width: 1.6em;
  color: var(--muted-strong);
  font-variant-numeric: tabular-nums;
}
.turn-btn.current .turn-num { color: var(--on-brand); }
.turn-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.turn-mark {
  display: inline-flex;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}
.turn-mark svg { width: 100%; height: 100%; }
.turn-mark.ok { color: var(--ok); }
.turn-mark.bad { color: var(--error); }
.turn-mark.skip,
.turn-mark.none { color: var(--muted-strong); }
.turn-btn.current .turn-mark { color: var(--on-brand); }

/* A finished game. */
.result {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  padding-top: 14px;
  border-top: 1px solid var(--surface-border);
  animation: panel-in 0.2s ease;
}
.result-title {
  font-size: 1.7rem;
  color: var(--brand-ink);
}
.result-title:focus { outline: none; }
.card .result-reason { color: var(--muted); }
.card .result-score { font-size: 1.05rem; max-width: 32em; }
.standings {
  list-style: none;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.standings li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
}
.standings li.you {
  background: var(--brand-fill);
  color: var(--on-brand);
}
.standing-rank { min-width: 1.2em; color: inherit; opacity: 0.8; }
.standing-name { flex: 1; overflow-wrap: anywhere; }
.standing-score { font-variant-numeric: tabular-nums; }
.seed-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.seed-text {
  letter-spacing: 0.06em;
  color: var(--ink);
  user-select: text;
}
.submit {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin-top: 4px;
}
.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,
.card .not-scored {
  font-size: 0.8rem;
  color: var(--muted);
  max-width: 30em;
}
.submitted {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 460px;
  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%; }

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

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

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

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

/* Key hints mean nothing to a finger. */
@media (pointer: coarse) {
  .options.show-keys .answer-key,
  .keys-note { display: none; }
}

@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; }
  .game { padding: 14px 10px; }
  .level-btn small { font-size: 0.62rem; }
  .mode-toggle.thirds .mode-btn { font-size: 0.78rem; padding: 8px 4px; }
  .mode-toggle.thirds .mode-btn svg { display: none; }
  .options.six { grid-template-columns: repeat(2, 1fr); }
  .answer { min-height: 46px; font-size: 0.88rem; }
  .result-title { font-size: 1.45rem; }
  .code-big { font-size: 2rem; }
  .update-notice-inner { flex-wrap: wrap; }
  .update-notice p { flex-basis: 100%; }
}
