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

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

/* Fixed-meaning exceptions to theme tokens, like the footer heart: a QR code
   is dark on light or it does not scan. */
: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;
  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 {
  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; }

/* 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;
}
.field-note:empty { display: none; }
.mode-btn[aria-checked="true"] {
  background: var(--brand-fill);
  color: var(--on-brand);
}
.mode-btn { color: var(--muted-strong); }

.best-pick {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 4px;
  border-radius: 14px;
  background: var(--surface);
}
.best-pick .mode-btn { font-size: 1rem; }
.custom-best {
  display: flex;
  align-items: center;
  gap: 10px;
}
.custom-best .field { flex: 0 0 110px; }
.field-suffix {
  font-size: 0.85rem;
  color: var(--muted);
}

.start-btn {
  padding: 12px 26px;
  font-size: 1rem;
}
.start-btn svg { width: 18px; height: 18px; }
.join {
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 12px;
  border-top: 1px solid var(--surface-border);
  text-align: left;
}

/* Text fields: a custom best-of, a join code, and 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; }
.code-field { letter-spacing: 0.06em; text-transform: uppercase; }
.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;
}

/* Rounds won, which is also the score. */
.scoreboard {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  width: 100%;
  max-width: 460px;
}
.score-side {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
}
.score-side:first-child { justify-content: flex-end; }
.score-name {
  font-size: 0.95rem;
  color: var(--muted);
}
.score-num {
  min-width: 1.4em;
  font-size: 2.4rem;
  line-height: 1;
  color: var(--brand-ink);
  font-variant-numeric: tabular-nums;
}
.score-sep {
  font-size: 2rem;
  color: var(--muted);
}

/* The two hands, mine on the left. */
.arena {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 460px;
}
.hand-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px 8px 12px;
  border-radius: 20px;
  background: var(--surface-strong);
  border: 2px solid var(--surface-border);
  transition: border-color 0.18s ease, background 0.18s ease;
}
.hand-art {
  display: grid;
  place-items: center;
  width: clamp(64px, 20vw, 96px);
  height: clamp(64px, 20vw, 96px);
  color: var(--ink);
}
.hand-art svg { width: 100%; height: 100%; }
.hand-label {
  min-height: 1.4em;
  font-size: 0.95rem;
  color: var(--ink);
}
.hand-slot[data-state="empty"] .hand-art,
.hand-slot[data-state="thinking"] .hand-art { color: var(--muted-strong); }
.hand-slot[data-state="empty"] .hand-label,
.hand-slot[data-state="thinking"] .hand-label { color: var(--muted-strong); }
.hand-slot[data-state="thinking"] .hand-art { animation: think 0.5s ease-in-out infinite alternate; }
@keyframes think {
  from { transform: translateY(-4px) rotate(-6deg); }
  to { transform: translateY(4px) rotate(6deg); }
}
.hand-slot[data-state="locked"] {
  background: var(--brand-fill);
}
.hand-slot[data-state="locked"] .hand-art,
.hand-slot[data-state="locked"] .hand-label,
.hand-slot[data-state="picked"] .hand-art { color: var(--on-brand); }
.hand-slot[data-state="picked"] { background: var(--brand-fill); }
.hand-slot[data-state="picked"] .hand-label { color: var(--on-brand); }
.hand-slot[data-tone="win"] {
  border-color: var(--ok);
  background: color-mix(in srgb, var(--ok) 14%, var(--surface-strong));
}
.hand-slot[data-tone="loss"] {
  border-color: color-mix(in srgb, var(--error) 60%, transparent);
}
.hand-slot.land .hand-art { animation: land 0.22s cubic-bezier(0.2, 0.8, 0.2, 1); }
@keyframes land {
  from { opacity: 0; transform: scale(0.7); }
}

.round-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
  color: var(--muted-strong);
  white-space: nowrap;
}
.round-badge:empty { display: none; }
.round-badge[data-tone="win"] {
  background: color-mix(in srgb, var(--ok) 14%, transparent);
  color: var(--ok);
}
.round-badge[data-tone="loss"] {
  background: color-mix(in srgb, var(--error) 14%, transparent);
  color: var(--error);
}
.round-badge[data-tone="draw"] {
  background: var(--surface-strong);
  color: var(--ink);
}
.card .round-how {
  min-height: 1.5em;
  font-size: 0.9rem;
  color: var(--muted);
}

.card .status {
  min-height: 1.5em;
  font-size: 0.95rem;
  color: var(--ink);
}

/* The three picks. */
.picks {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 460px;
}
.pick-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 6px 12px;
  border-radius: 18px;
  background: var(--brand-fill);
  color: var(--on-brand);
  font-size: 1rem;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, background 0.15s ease;
}
.pick-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  background: var(--brand-fill-strong);
}
.pick-btn:active:not(:disabled) { transform: translateY(0) scale(0.97); }
.pick-art {
  display: grid;
  width: 44px;
  height: 44px;
}
.pick-art svg { width: 100%; height: 100%; }
.pick-btn[aria-pressed="true"] {
  background: var(--brand-fill-strong);
  box-shadow: 0 0 0 3px var(--brand-ink);
}
.pick-btn:disabled[aria-pressed="true"] { opacity: 1; }

.throw-fail {
  display: flex;
  justify-content: center;
}

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

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

.takeback {
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--warn) 14%, transparent);
  animation: panel-in 0.2s ease;
}
.card .takeback p { color: var(--warn); }

.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;
}
.card .net-status { min-height: 1.5em; color: var(--ink); }
.card .net-status.error { color: var(--error); }

/* The replay. */
.replay {
  width: 100%;
  max-width: 460px;
  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);
}
.round-list {
  list-style: none;
  width: 100%;
  max-height: 170px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px;
  border-radius: 12px;
  background: var(--surface);
  text-align: left;
}
.round-btn {
  display: grid;
  grid-template-columns: 2em 1fr auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 4px 8px;
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--ink);
  text-align: left;
}
.round-num { color: var(--muted); }
.round-btn.current {
  background: var(--brand-fill);
  color: var(--on-brand);
}
.round-btn.current .round-num { color: var(--on-brand); }
.round-tag {
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
}
.round-tag[data-tone="win"] {
  background: color-mix(in srgb, var(--ok) 14%, transparent);
  color: var(--ok);
}
.round-tag[data-tone="loss"] {
  background: color-mix(in srgb, var(--error) 14%, transparent);
  color: var(--error);
}
.round-tag[data-tone="draw"] { color: var(--muted-strong); }
.round-btn.current .round-tag {
  background: var(--surface-strong);
  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; }
.card .result-score:empty { display: none; }
.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; }

@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: 16px 10px; }
  .arena { gap: 6px; }
  .round-badge { font-size: 0.78rem; padding: 3px 8px; }
  .score-num { font-size: 2rem; }
  .pick-btn { padding: 12px 4px 10px; font-size: 0.9rem; }
  .pick-art { width: 36px; height: 36px; }
  .result-title { font-size: 1.45rem; }
  .code-big { font-size: 2rem; }
  .update-notice-inner { flex-wrap: wrap; }
  .update-notice p { flex-basis: 100%; }
}
