/* Splitpot on the web.
 *
 * The responsive rules are written from the start rather than added as a coat of paint at
 * the end: the layout is fluid, there is no framework and no device detection, and the same
 * markup serves a phone, a tablet either way up, and a desktop.
 *
 * Themes are data-theme on <html>, mirroring ThemePref's five choices. Phase 1 ships the
 * first three; felt and paper arrive with the picker in Phase 8. Money colours are their own
 * variables and are NEVER derived from --primary - that is the whole point of
 * LocalMoneyColors on the phone.
 */

:root,
[data-theme='system'],
[data-theme='midnight'] {
  --bg: #0e0f11;
  --surface: #17181c;
  --line: #26282e;
  --text: #f2f3f5;
  --muted: #9aa0aa;
  --primary: #f2f3f5;
  --on-primary: #0e0f11;
  --up: #46c46b;
  --down: #ef5b5b;
  --flat: #9aa0aa;
  --danger: #ef5b5b;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  [data-theme='system'] {
    --bg: #f6f6f4;
    --surface: #ffffff;
    --line: #e2e2dd;
    --text: #16171a;
    --muted: #6b7079;
    --primary: #16171a;
    --on-primary: #ffffff;
    --up: #1c8c3f;
    --down: #c62828;
    --flat: #6b7079;
    --danger: #c62828;
    color-scheme: light;
  }
}

[data-theme='daylight'] {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --line: #e2e2dd;
  --text: #16171a;
  --muted: #6b7079;
  --primary: #16171a;
  --on-primary: #ffffff;
  --up: #1c8c3f;
  --down: #c62828;
  --flat: #6b7079;
  --danger: #c62828;
  color-scheme: light;
}

* { box-sizing: border-box; }

/* Any class here that sets `display` beats the browser's own [hidden] rule, so .field and
 * .btn silently un-hide themselves. Everything in this app toggles visibility with
 * el.hidden, so this rule is what makes that mean anything. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

body {
  /* dvh, not vh: mobile browsers count the URL bar in 100vh, which leaves anything pinned
     to the bottom sitting below the fold until you scroll. */
  min-height: 100dvh;
}

#app {
  /* One column, capped and centred. A seat row stretched across an iPad - name at one end,
     number at the other - is unreadable, so the column stops growing instead. */
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
}

.loading {
  padding: 48px 16px;
  text-align: center;
  color: var(--muted);
}

/* ---------- banner ---------- */

.banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  font-size: 0.95rem;
}

.banner-error { background: var(--danger); color: #fff; }
.banner-notice { background: var(--surface); color: var(--muted); border-bottom: 1px solid var(--line); }

/* ---------- type ---------- */

.title { font-size: 1.5rem; margin: 0; letter-spacing: -0.02em; }
.wordmark { font-size: 2rem; margin: 0 0 4px; letter-spacing: -0.03em; }
.sub { margin: 0 0 24px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }

.screen-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

/* ---------- controls ---------- */

.btn, .btn-link, .btn-inline {
  font: inherit;
  cursor: pointer;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  /* 44px minimum: this gets used at a real table, at night, one-handed, with people
     waiting. Anything smaller is a mis-tap. */
  min-height: 44px;
  padding: 0 16px;
  /* Without this a fast double-tap zooms the page instead of registering twice. */
  touch-action: manipulation;
}

.btn { display: block; width: 100%; margin-bottom: 12px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--primary); color: var(--on-primary); border-color: var(--primary); font-weight: 600; }

.btn-link {
  background: none;
  border: none;
  color: var(--muted);
  text-decoration: underline;
  padding: 0;
  min-height: 44px;
}

.btn-inline { min-height: 36px; padding: 0 12px; margin-left: auto; }

.field {
  display: block;
  width: 100%;
  margin-bottom: 12px;
  padding: 10px 12px;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  /* 16px minimum, always. iOS Safari zooms the page on focus for anything smaller and does
     not zoom back out. The amount fields are where this bites first. */
  font-size: 16px;
}

/* ---------- cards and rows ---------- */

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 24px; }
.card-signin { margin-top: 12dvh; }

.list { display: flex; flex-direction: column; gap: 8px; }

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.row-main { flex: 1; min-width: 0; }
.row-title { font-size: 1rem; margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.row-sub { margin: 2px 0 0; color: var(--muted); font-size: 0.875rem; }

.tag {
  flex: none;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}

.tag-live { color: var(--up); border-color: var(--up); }

/* ---------- layout blocks ---------- */

.stack { display: flex; flex-direction: column; gap: 12px; }

.section-label {
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 12px 0 0;
  font-weight: 600;
}

.card-title { font-size: 1.125rem; margin: 0 0 4px; }
.card-live { border-color: var(--up); }

/* Cards and rows are often links. They must not look like body links. */
a.card, a.row { text-decoration: none; color: inherit; display: flex; }
a.card:not(.row) { flex-direction: column; gap: 4px; }

.row-right { display: flex; flex-direction: column; align-items: flex-end; flex: none; }
.row-tappable { width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer; }

/* Reflows 1 -> 2 -> 3 columns with no media query. */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }

.tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
}

.tile-label { margin: 4px 0 0; color: var(--muted); font-size: 0.875rem; }
.tile-sub { margin: 0; color: var(--muted); font-size: 0.8125rem; }

.money { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.125rem; }
.money-up { color: var(--up); }
.money-down { color: var(--down); }
.money-flat { color: var(--flat); }

.streak { margin: 0 0 12px; color: var(--muted); }

/* ---------- season chips ---------- */

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }

.chip {
  flex: none;
  width: auto;
  margin: 0;
  min-height: 40px;
  border-radius: 999px;
  padding: 0 14px;
}

.chip-on { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }

/* ---------- sheet ---------- */

.sheet {
  width: min(560px, 100%);
  max-height: 85dvh;
  margin: auto auto 0;
  border: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  background: var(--surface);
  color: var(--text);
  padding: 0;
  overflow: auto;
}

.sheet::backdrop { background: rgb(0 0 0 / 0.5); }
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--surface);
}
.sheet-title { margin: 0; font-size: 1.125rem; }
.sheet-body { padding: 16px calc(16px + env(safe-area-inset-left)) calc(24px + env(safe-area-inset-bottom)); }

/* ---------- tabs ---------- */

.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-around;
  gap: 4px;
  background: var(--surface);
  border-top: 1px solid var(--line);
  /* Or the iPhone home indicator sits on top of the tabs. */
  padding: 4px 8px calc(4px + env(safe-area-inset-bottom));
}

.tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border: none;
  background: none;
  margin: 0;
  border-radius: 10px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9375rem;
  touch-action: manipulation;
}

.tab-on { color: var(--text); font-weight: 600; }
.tab-quiet { flex: 0 1 auto; font-size: 0.875rem; text-decoration: none; }

/* The tab bar is fixed, so the last row of content needs somewhere to end. */
#app { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }

/* Above ~900px the bottom edge is nowhere near anyone's thumb, so the tabs go to the top. */
@media (min-width: 900px) {
  .tabs {
    position: static;
    justify-content: flex-start;
    border-top: none;
    border-bottom: 1px solid var(--line);
    border-radius: 12px;
    margin-bottom: 16px;
    padding: 4px 8px;
  }
  .tab { flex: 0 1 auto; padding: 0 16px; }
  #app { padding-bottom: 24px; display: flex; flex-direction: column; }
  .tabs { order: -1; }
}

/* ---------- live table ---------- */

.stack-tight { display: flex; flex-direction: column; gap: 8px; }

.meter {
  height: 6px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--primary);
  transition: width 150ms ease-out;
}

/* Squared up: the bar turns the win colour rather than staying the control colour. */
.meter-done { background: var(--up); }

.pills { display: flex; gap: 8px; }
.pills .chip { flex: 1; }

.monogram {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--bg);
  border: 1px solid var(--line);
  font-size: 0.875rem;
  font-weight: 700;
}

.tag-settled { color: var(--muted); }

/* ---------- keypad sheet ---------- */

.sheet-sub { margin: 0 0 12px; color: var(--muted); }

.amount-display {
  margin: 16px 0;
  text-align: center;
  font-size: 2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 12px 0 16px;
}

.key {
  width: 100%;
  margin: 0;
  min-height: 56px;
  font-size: 1.25rem;
  font-weight: 600;
  /* A fast double-tap on a quick chip must log two entries, not zoom the page. */
  touch-action: manipulation;
}

.btn-rebuy {
  width: auto;
  margin: 6px 0 0;
  min-height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  touch-action: manipulation;
}

/* ---------- forms ---------- */

.field-wrap { display: block; }
.field-label { display: block; margin-bottom: 4px; color: var(--muted); font-size: 0.875rem; }

.two-up { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }

.checkline { display: flex; align-items: center; gap: 10px; min-height: 44px; margin-bottom: 8px; }
.checkline input { width: 20px; height: 20px; }

/* A link styled as the primary button. Anchors ignore .btn's button-only rules. */
.btn-link-solid { display: flex; align-items: center; justify-content: center; text-decoration: none; }

/* ---------- destructive and toggled ---------- */

/* Stamp red is reserved for money lost and for errors - never for ordinary controls, or a
   loss looks like a button. Destructive actions earn it; that IS the warning. */
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-on { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }

.actions { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); gap: 4px; }
.actions .btn-link { align-self: flex-start; }

/* Historical rows: present for reference, not the thing being acted on. */
.row-quiet { opacity: 0.72; }
