/* Built for a phone in a ziplock bag, in sun or rain, operated with a wet thumb. */
:root {
  --bg: #f4f1ea; --surface: #ffffff; --ink: #14140f; --muted: #5d5a50; --line: #d6d0c2;
  --brand: #1d3b2a; --brand-ink: #ffffff; --accent: #c8a24a;
  --ok: #1f7a3a; --dnf: #b4521c; --dns: #6b6b6b; --warn: #b3261e; --pending: #c8a24a;
  --tap: 64px; --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11140f; --surface: #1b1f19; --ink: #f1efe8; --muted: #a9a596; --line: #343a30;
    --brand: #2f5c41; --accent: #d9b55a; --ok: #3fae63; --dnf: #e07a43; --dns: #8f8f8f; --warn: #ff6b5e;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font-size: 18px; line-height: 1.35; -webkit-tap-highlight-color: transparent; }
main { max-width: 760px; margin: 0 auto; padding: 0 16px 120px; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 19px; margin: 20px 0 8px; }
p { margin: 8px 0; }
.muted { color: var(--muted); font-size: 15px; }
.warn { color: var(--warn); font-weight: 600; }

header.bar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  margin: 0 -16px 12px; padding: 10px 12px; background: var(--brand); color: var(--brand-ink);
  padding-top: max(10px, env(safe-area-inset-top));
}
header.bar .title { flex: 1; min-width: 0; }
header.bar .title small { display: block; opacity: .8; font-size: 13px; }
header.bar .title h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
header.bar button { background: transparent; color: inherit; border: 1px solid rgba(255,255,255,.4); min-height: 44px; padding: 0 12px; }

button, .btn {
  font: inherit; font-weight: 600; min-height: var(--tap); padding: 0 16px; border-radius: var(--radius);
  border: 2px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none;
  touch-action: manipulation; user-select: none;
}
button:active { transform: scale(.97); }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
button.danger { color: var(--warn); border-color: var(--warn); }
button.wide { width: 100%; }
button:disabled { opacity: .45; }
.stack > * + * { margin-top: 10px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row > button { flex: 1; }

/* Stage and car pickers */
.grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }
.grid.wide { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.tile {
  min-height: 76px; flex-direction: column; font-size: 26px; padding: 6px; position: relative;
}
.tile small { font-size: 12px; font-weight: 500; color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile.OK { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, var(--surface)); }
.tile.DNF { border-color: var(--dnf); background: color-mix(in srgb, var(--dnf) 14%, var(--surface)); }
.tile.DNS { border-color: var(--dns); background: color-mix(in srgb, var(--dns) 18%, var(--surface)); }
.tile .dot { position: absolute; top: 6px; right: 6px; width: 12px; height: 12px; border-radius: 50%; background: var(--pending); }
.tile.big { font-size: 20px; }

/* Entry screen */
.timebox {
  font-variant-numeric: tabular-nums; font-size: 56px; font-weight: 700; text-align: center;
  background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius); padding: 6px;
}
.timebox.off { opacity: .35; }
.timebox.bad { border-color: var(--warn); color: var(--warn); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.keypad button { font-size: 28px; min-height: 60px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.seg button[aria-pressed="true"].OK { background: var(--ok); color: #fff; border-color: var(--ok); }
.seg button[aria-pressed="true"].DNF { background: var(--dnf); color: #fff; border-color: var(--dnf); }
.seg button[aria-pressed="true"].DNS { background: var(--dns); color: #fff; border-color: var(--dns); }
.pens { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.pen { display: grid; grid-template-columns: 1fr 52px; border: 2px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.pen.on { border-color: var(--warn); }
.pen .add { border: 0; border-radius: 0; min-height: 68px; justify-content: flex-start; text-align: left; padding: 6px 10px; flex-direction: column; align-items: flex-start; gap: 2px; font-size: 15px; }
.pen .add b { font-size: 13px; color: var(--muted); }
.pen .add .n { font-size: 22px; color: var(--warn); }
.pen .sub { border: 0; border-left: 1px solid var(--line); border-radius: 0; min-height: 68px; font-size: 26px; padding: 0; }
.savebar { position: fixed; left: 0; right: 0; bottom: 0; padding: 10px 16px max(10px, env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); }
.savebar .inner { max-width: 760px; margin: 0 auto; display: flex; gap: 10px; }
.savebar button.primary { flex: 1; font-size: 22px; min-height: 68px; }

/* Base */
.tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; }
.tabs button { min-height: 48px; flex: 1; white-space: nowrap; }
.tabs button[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 15px; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th { position: sticky; top: 0; background: var(--surface); font-size: 13px; color: var(--muted); }
td.l, th.l { text-align: left; }
td.wrap { white-space: normal; font-size: 13px; }
tr.tap { cursor: pointer; }
.flag { color: var(--warn); font-weight: 700; }
.st-DNF { color: var(--dnf); font-weight: 600; } .st-DNS { color: var(--dns); font-weight: 600; }
textarea, input, select {
  font: inherit; width: 100%; padding: 12px; border-radius: var(--radius); border: 2px solid var(--line);
  background: var(--surface); color: var(--ink);
}
textarea { min-height: 160px; font-family: ui-monospace, Menlo, monospace; font-size: 14px; }
label { display: block; font-weight: 600; margin: 12px 0 6px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
pre { white-space: pre-wrap; word-break: break-all; font-size: 13px; margin: 0; }
.banner { background: color-mix(in srgb, var(--pending) 25%, var(--surface)); border: 2px solid var(--pending); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 12px; font-weight: 600; }

#toast {
  position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 12px 20px; border-radius: 999px; font-weight: 600; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 20;
}
#toast.show { opacity: 1; }
