/* Layout and components. Colours come only from theme.css tokens. Mobile first (360 px). */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 var(--hs);
}

h1,
h2,
h3 {
  margin: 0;
  font-family: var(--head-font);
  font-weight: var(--hw);
  font-stretch: condensed;
  text-transform: var(--ht);
  letter-spacing: 0.02em;
  line-height: 1.1;
}

h1 {
  font-size: 1.9rem;
}

h2 {
  font-size: 1.35rem;
}

h3 {
  font-size: 1rem;
  color: var(--muted);
}

p {
  margin: 0;
}

/* The document is the one scroller (no 100vh shell, no inner scroll box), and nothing in its
   layout follows the browser's toolbars: heights use svh (the viewport with the toolbars shown,
   constant), never dvh, and in a browser tab the top and bottom padding is fixed. On iOS, dvh and
   (with viewport-fit=cover) the top and bottom safe-area insets change while Chrome's or Safari's
   bars collapse and expand, so the page resized or shifted under the scroll gesture and could
   come back up with its top stuck under the address bar. The sides pad by their insets (the
   notch in landscape), which never change mid-scroll; standalone mode adds top and bottom
   (Installed app, at the end). */
main {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left));
}

.screen {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: calc(100vh - 40px); /* before svh (iOS 15.4, Chrome 108) */
  min-height: calc(100svh - 40px);
}

/* Outside a round the footer (About, legal links, disclaimer) shows under the screen: keep
   it above the fold, with room for a two-line disclaimer on a narrow phone. */
main:has(+ .footer:not([hidden])) .screen {
  min-height: calc(100vh - 128px);
  min-height: calc(100svh - 128px);
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.95rem;
}

.bar h1 {
  font-size: 1.4rem;
  color: var(--text);
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: auto; /* primary actions sit in the thumb zone */
}

/* Buttons and inputs: at least 48 px tall, so above the 44 px tap-target minimum. */
button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  min-height: 48px;
  padding: 10px 16px;
  border-radius: var(--r);
  border: 2px solid var(--bd);
  background: var(--surface);
  box-shadow: var(--sh);
  font-family: var(--head-font);
  font-weight: var(--hw);
  font-stretch: condensed;
  text-transform: var(--ht);
  letter-spacing: 0.04em;
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  cursor: default;
  opacity: 0.55;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on);
}

button.secondary {
  background: transparent;
}

button.small {
  min-height: 44px;
  padding: 6px 12px;
  font-size: 0.9rem;
}

button.link,
a.link {
  min-height: 44px;
  border: 0;
  background: none;
  color: var(--muted);
  text-decoration: underline;
  text-transform: none;
  font-family: var(--hs);
  font-weight: 400;
  padding: 6px 4px;
}

a.link {
  display: inline-flex;
  align-items: center;
  font-size: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
}

.field > span {
  color: var(--muted);
  font-size: 0.9rem;
}

input,
select {
  min-height: 48px;
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--r);
  border: 2px solid var(--bd);
  background: var(--surface);
}

.code-input {
  font-family: var(--head-font);
  font-weight: var(--hw);
  font-size: 2rem;
  letter-spacing: 0.35em;
  text-align: center;
  text-transform: uppercase;
}

.counter {
  position: absolute;
  right: 0;
  top: 0;
  color: var(--muted);
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
}

.chips legend {
  width: 100%;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.9rem;
}

.chip {
  position: relative;
}

.chip input {
  position: absolute;
  opacity: 0;
  inset: 0;
  min-height: 0;
  margin: 0;
}

.chip span {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 14px;
  border-radius: var(--r);
  border: 2px solid var(--bd);
  background: var(--surface);
}

.chip input:checked + span {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on);
}

.chip input:checked + span::before {
  content: '✓ '; /* state is never colour alone */
  white-space: pre;
}

.chip input:focus-visible + span {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.hint {
  color: var(--muted);
  font-size: 0.95rem;
}

.hint.warn,
.error {
  color: var(--wrong);
}

.chips > .hint {
  flex-basis: 100%;
  margin: 0;
}

.center {
  text-align: center;
}

.tag {
  display: inline-block;
  margin-left: 8px;
  padding: 0 6px;
  border-radius: var(--r);
  border: 1px solid var(--bd);
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  vertical-align: middle;
}

/* Home */
.brand {
  margin-top: 18vh;
  margin-top: 18svh;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.brand h1 {
  font-size: 2.6rem;
}

.brand p {
  color: var(--muted);
}

/* Add to Home Screen hint: shown once per device, dismissible */
.install {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 6px 10px 12px;
  background: var(--surface);
  border: 1px solid var(--bd);
  border-left: 4px solid var(--accent);
  border-radius: var(--r);
  font-size: 0.95rem;
}

.install p {
  flex: 1;
}

.install .close {
  min-width: 44px;
  text-decoration: none;
}

.share-icon {
  width: 1.2em;
  height: 1.2em;
  vertical-align: -0.2em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Lobby */
.room-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.room-head .label {
  color: var(--muted);
}

.room-head .code {
  font-family: var(--head-font);
  font-weight: var(--hw);
  font-size: 3rem;
  letter-spacing: 0.18em;
}

.share {
  display: grid;
  grid-template-columns: 132px 1fr;
  gap: 14px;
  align-items: center;
}

.share .link {
  word-break: break-all;
  font-size: 0.9rem;
  margin-bottom: 8px;
}

.qr {
  width: 132px;
  height: 132px;
  display: block;
}

.qr-bg {
  fill: var(--qr-bg);
}

.qr-fg {
  fill: var(--qr-fg);
}

.roster {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.roster li {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--bd);
  border-radius: var(--r);
}

.away {
  opacity: 0.55;
}

/* Question */
.seconds {
  display: inline-flex;
  font-family: var(--head-font);
  font-weight: var(--hw);
  font-size: 1.3rem;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* The heading font has no tabular figures: each digit gets a cell one zero wide (wider glyphs
   overflow it evenly), so 10 -> 9 or 1 -> 0 never moves a digit. */
.seconds .digit {
  display: inline-block;
  width: 1ch;
  text-align: center;
}

.timer {
  height: 8px;
  background: var(--surface);
  border: 1px solid var(--bd);
  border-radius: var(--r);
  overflow: hidden;
}

.timer i {
  display: block;
  height: 100%;
  background: var(--accent);
  transform-origin: left center;
}

.card {
  background: var(--surface);
  border: 1px solid var(--bd);
  border-radius: var(--r);
  box-shadow: var(--sh);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.career {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.career th {
  text-align: left;
  color: var(--muted);
  font-weight: 400;
  font-size: 0.8rem;
  padding: 0 4px 4px;
}

.career td {
  padding: 6px 4px;
  border-top: 1px solid var(--bd);
  vertical-align: top;
}

.career .years {
  white-space: nowrap;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.career .club {
  font-weight: 700;
  /* --club: the club's own colour when the data has one, set per row by question.js */
  border-left: 4px solid var(--club, var(--accent));
  padding-left: 8px;
}

.career .num,
.career th:nth-child(n + 3) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.footnote {
  color: var(--muted);
  font-size: 0.8rem;
}

.options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: auto;
}

.option {
  min-height: 72px;
  font-size: 1rem;
  overflow-wrap: anywhere;
}

.option.picked {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on);
  opacity: 1;
}

.option.picked::after {
  content: ' ✓';
}

.status {
  min-height: 1.5em;
  text-align: center;
  color: var(--muted);
}

/* Club Connection */
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.rule-toggle {
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 50%;
}

.club-chips {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.club-chips li {
  padding: 10px 14px;
  border: 1px solid var(--bd);
  border-left: 6px solid var(--accent);
  border-radius: var(--r);
  background: var(--bg);
  font-family: var(--head-font);
  font-weight: var(--hw);
  text-transform: var(--ht);
  font-size: 1.05rem;
}

.attempts {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}

.marks {
  display: inline-flex;
  gap: 6px;
  font-size: 1.2rem;
  color: var(--muted);
}

.marks .good,
.tried .good .mark {
  color: var(--correct);
}

.marks .bad,
.tried .bad .mark {
  color: var(--wrong);
}

.tried {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  color: var(--muted);
}

.tried .mark {
  margin-right: 4px;
}

.guess {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: auto; /* the field and Submit sit in the thumb zone */
}

.combo {
  position: relative;
}

/* Suggestions open upwards: the field sits low and the phone keyboard covers what is below. */
.suggestions {
  list-style: none;
  margin: 0;
  padding: 0;
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 4px);
  z-index: 2;
  background: var(--surface);
  border: 2px solid var(--bd);
  border-radius: var(--r);
  box-shadow: var(--sh);
}

.suggestions li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  min-height: 48px;
  padding: 12px;
  cursor: pointer;
  border-top: 1px solid var(--bd);
}

.suggestions li:first-child {
  border-top: 0;
}

.suggestions li.active {
  background: var(--accent);
  color: var(--on);
}

.suggestions small {
  color: var(--muted);
  white-space: nowrap;
}

.suggestions li.active small {
  color: var(--on);
}

/* Reveal and scoreboard */
.answer .label {
  color: var(--muted);
  font-size: 0.85rem;
}

.answer h2 {
  font-size: 1.8rem;
  color: var(--correct);
}

.answer .sample,
.answer .why {
  color: var(--muted);
}

.report {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.reasons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.about p {
  color: var(--text);
}

.about .privacy {
  margin: 0;
  padding-left: 1.2em;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.about .attribution,
.about .disclaimer {
  color: var(--muted);
  font-size: 0.9rem;
}

.verdict {
  font-size: 1.2rem;
  font-weight: 700;
}

.verdict.good .mark,
.picks .good .mark {
  color: var(--correct);
}

.verdict.bad .mark,
.picks .bad .mark {
  color: var(--wrong);
}

.picks,
.standings,
.steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.picks li,
.standings li {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--bd);
  border-radius: var(--r);
}

.picks .pick {
  flex: 1;
  color: var(--muted);
  text-align: right;
  font-size: 0.9rem;
}

.standings .rank {
  width: 1.6em;
  font-family: var(--head-font);
  font-weight: var(--hw);
}

.standings .nick {
  flex: 1;
}

.standings .nick small {
  color: var(--muted);
}

.standings .me {
  border-color: var(--accent);
  border-width: 2px;
}

.standings .move,
.standings .delta,
.picks .delta {
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.standings .score {
  font-family: var(--head-font);
  font-weight: var(--hw);
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.countdown {
  margin-top: auto;
  text-align: center;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* Disclosures: "More settings" on the set-up forms, "Round trivia" once a game is over */
button.disclosure {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  background: transparent;
  text-align: left;
}

button.disclosure::after {
  content: '+'; /* the state is never colour alone */
  font-size: 1.3rem;
  line-height: 1;
}

button.disclosure[aria-expanded='true']::after {
  content: '−';
}

.disclosure-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.trivia-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.trivia {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.trivia li {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--bd);
  border-radius: var(--r);
  overflow-wrap: anywhere;
}

.trivia .label {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.trivia .path {
  font-size: 0.95rem;
}

.trivia strong {
  color: var(--correct);
}

.trivia .why,
.trivia .players {
  color: var(--muted);
  font-size: 0.9rem;
}

/* Solo summary */
.result {
  align-items: center;
  text-align: center;
  padding: 20px 12px;
}

.result .label,
.result .tally {
  color: var(--muted);
}

.result .total {
  font-family: var(--head-font);
  font-weight: var(--hw);
  font-size: 3.2rem;
  line-height: 1;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.result .best {
  font-weight: 700;
}

.result .best.new::before {
  content: '★ '; /* not colour alone */
  color: var(--accent);
}

/* Podium */
.steps {
  flex-direction: row;
  align-items: flex-end;
  justify-content: center;
  gap: 8px;
}

.step {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 6px;
  background: var(--surface);
  border: 1px solid var(--bd);
  border-radius: var(--r);
  text-align: center;
  overflow-wrap: anywhere;
}

.step .place {
  font-family: var(--head-font);
  font-weight: var(--hw);
  color: var(--accent);
}

.step.place-1 {
  min-height: 150px;
  border-color: var(--accent);
}

.step.place-2 {
  min-height: 120px;
}

.step.place-3 {
  min-height: 100px;
}

/* Daily puzzle */
.badge {
  display: inline-block;
  margin-left: 10px;
  padding: 1px 8px;
  border-radius: var(--r);
  background: var(--accent);
  color: var(--on);
  font-size: 0.8rem;
  vertical-align: middle;
}

.puzzle .verdict {
  font-size: 1.05rem;
  overflow-wrap: anywhere;
}

.puzzle button {
  align-self: flex-start;
}

.streak .big {
  font-family: var(--head-font);
  font-weight: var(--hw);
  font-size: 2rem;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.daily .countdown {
  margin-top: 0;
  font-variant-numeric: tabular-nums;
}

.daily-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: auto; /* the field, Submit and Reveal sit in the thumb zone */
}

.daily-controls .guess {
  margin-top: 0;
}

.tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.tools .secondary {
  flex: 1;
}

/* A club the daily career just revealed */
.career tr.new td {
  animation: reveal 0.6s ease-out;
}

@keyframes reveal {
  from {
    background: var(--accent);
    color: var(--on);
  }
}

/* Shell */
.banner {
  position: sticky;
  top: 0;
  z-index: 3;
  padding: 8px 16px;
  text-align: center;
  background: var(--wrong);
  color: var(--text);
  font-weight: 700;
}

.banner.notice {
  background: var(--accent);
  color: var(--on);
}

.footer {
  max-width: 480px;
  margin: -16px auto 0;
  padding: 0 16px 16px;
  text-align: center;
}

.footer nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  column-gap: 12px;
}

.footer .disclaimer {
  color: var(--muted);
  font-size: 0.8rem;
}

.about a {
  color: var(--text);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--bd);
  border-radius: var(--r);
  z-index: 3;
}

.offscreen {
  position: fixed;
  left: -9999px;
}

[hidden] {
  display: none !important;
}

/* Installed app: viewport-fit=cover and a translucent status bar put the page under the status
   bar and home indicator, so the top and bottom pad by their insets too. No browser bars come
   and go there, so the insets stay put. */
@media (display-mode: standalone) {
  main {
    padding-top: max(16px, env(safe-area-inset-top));
    padding-bottom: max(24px, env(safe-area-inset-bottom));
  }

  .banner {
    padding-top: calc(8px + env(safe-area-inset-top));
  }

  .footer {
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
}

@media (min-width: 720px) {
  main {
    padding-top: 40px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}
