:root {
  --bg: #0f1115;
  --panel: #1a1d24;
  --line: #2a2f3a;
  --text: #f2f4f7;
  --muted: #9aa3b2;
  --accent: #22c55e;
  --accent-ink: #052e13;
  --warn: #f59e0b;
  --danger: #ef4444;
  --key: #252a34;
  --key-press: #3a4150;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 16px; }
body { display: flex; flex-direction: column; overscroll-behavior: none; }
button { font: inherit; color: inherit; background: var(--key); border: 1px solid var(--line);
  border-radius: 10px; padding: .7em 1em; cursor: pointer; touch-action: manipulation; }
button:active { background: var(--key-press); }
button.small { padding: .45em .8em; font-size: .9rem; }
button.danger { border-color: var(--danger); color: #fecaca; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
input { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: .55em .7em; width: 100%; }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--accent); transform: scale(1.3); margin-right: .5em; }

header#top { display: flex; align-items: center; gap: .75rem; padding: calc(.4rem + var(--safe-t)) .9rem .4rem;
  background: #0b0d11; border-bottom: 1px solid var(--line); }
#clock { font-variant-numeric: tabular-nums; font-size: 1.6rem; font-weight: 700; letter-spacing: .02em; }
#raceinfo { flex: 1; font-size: .85rem; color: var(--muted); line-height: 1.2; font-variant-numeric: tabular-nums; }
#raceinfo b { color: var(--text); }
#raceinfo .over { color: var(--warn); font-weight: 700; }
#status span { margin-left: .4rem; color: var(--line); font-size: 1rem; }
#status span.on { color: var(--accent); }
#status span.bad { color: var(--danger); }

main { flex: 1; overflow: hidden; position: relative; }
.view { display: none; height: 100%; overflow-y: auto; padding: .8rem; -webkit-overflow-scrolling: touch; }
.view.active { display: block; }
#v-entry.active { display: flex; flex-direction: column; overflow: hidden; padding: .6rem; }

#display-wrap { text-align: center; padding: .2rem 0 .5rem; }
#display { font-size: clamp(3.5rem, 18vw, 6rem); font-weight: 800; height: 1.15em; line-height: 1.15em;
  font-variant-numeric: tabular-nums; letter-spacing: .06em; }
#hint { color: var(--muted); font-size: .9rem; min-height: 1.3em; }
#hint.ok { color: var(--accent); font-weight: 600; }
#hint.warn { color: var(--warn); font-weight: 600; }

#keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; flex: 0 0 auto; }
#keypad button { font-size: clamp(1.8rem, 9vw, 2.6rem); font-weight: 700; padding: 0; height: clamp(58px, 11vh, 92px);
  border-radius: 14px; user-select: none; -webkit-user-select: none; }
#keypad .k-ok { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
#keypad .k-ok:active { filter: brightness(.85); }
#keypad .k-del { color: var(--muted); }

#last-head { display: flex; justify-content: space-between; align-items: center; margin: .7rem 0 .3rem; color: var(--muted); font-size: .85rem; }
#last { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; min-height: 0; }
#last li, #list li { display: flex; gap: .8rem; align-items: baseline; padding: .45rem .3rem; border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums; }
.bib { font-weight: 800; font-size: 1.25rem; min-width: 3.2em; }
.t { color: var(--muted); }
.tag { font-size: .72rem; padding: .1em .45em; border-radius: 6px; background: var(--line); color: var(--muted); margin-left: auto; white-space: nowrap; }
.tag.dup { background: #422006; color: #fcd34d; }
.tag.del { background: #450a0a; color: #fca5a5; }
.tag.man { background: #172554; color: #93c5fd; }
.tag.ed { background: #2e1065; color: #c4b5fd; }
li.deleted .bib, li.deleted .t { text-decoration: line-through; opacity: .5; }
#list li { cursor: pointer; }

.bar { display: flex; gap: .6rem; align-items: center; justify-content: space-between; margin-bottom: .6rem; }
.bar h2 { margin: 0; }
.bar input { flex: 1; }
h2 { font-size: 1.1rem; margin: 1.4rem 0 .5rem; }
h2:first-child { margin-top: .2rem; }
label { display: block; margin: .6rem 0; color: var(--muted); font-size: .9rem; }
label > input:not([type=checkbox]):not([type=radio]) { margin-top: .25rem; }
label.chk { display: flex; align-items: center; color: var(--text); }
.row { display: flex; gap: .5rem; margin-top: .25rem; }
.row input { flex: 1; }
.seg { display: flex; gap: .5rem; }
.seg label { flex: 1; margin: 0; padding: .7rem; border: 1px solid var(--line); border-radius: 10px; color: var(--text); display: flex; align-items: center; }
.info { color: var(--muted); font-size: .82rem; line-height: 1.35; }
.btns { display: flex; flex-direction: column; gap: .5rem; }
.range { display: grid; grid-template-columns: 1fr 1fr 1.6fr auto auto; gap: .35rem; align-items: center; margin: .35rem 0; }
.range input { padding: .5em .4em; }
.range-head { display: grid; grid-template-columns: 1fr 1fr 1.6fr auto auto; gap: .35rem; font-size: .75rem; color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: .5rem .35rem; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-size: .78rem; font-weight: 600; position: sticky; top: -1px; background: var(--bg); }
td.num, th.num { text-align: right; }
tr.detail td { color: var(--muted); font-size: .82rem; padding-top: 0; }
tbody tr.main { cursor: pointer; }
#res-note { color: var(--muted); font-size: .85rem; margin-bottom: .5rem; }

nav#tabs { display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--line); background: #0b0d11;
  padding-bottom: var(--safe-b); }
nav#tabs button { border: 0; border-radius: 0; background: transparent; padding: .9rem .2rem; font-size: .88rem; color: var(--muted); }
nav#tabs button.active { color: var(--accent); font-weight: 700; box-shadow: inset 0 3px 0 var(--accent); }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; width: min(92vw, 420px); padding: 1rem; }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h3 { margin: 0 0 .6rem; }
.dlg-btns { display: flex; flex-direction: row-reverse; flex-wrap: wrap; gap: .5rem; justify-content: flex-start; margin-top: 1rem; }
.log { font-size: .78rem; color: var(--muted); max-height: 9em; overflow-y: auto; border-top: 1px solid var(--line); margin-top: .6rem; padding-top: .4rem; }
.log div { padding: .1rem 0; }

#toast { position: fixed; left: 50%; bottom: calc(5rem + var(--safe-b)); transform: translateX(-50%); background: #000; color: #fff;
  padding: .6rem 1rem; border-radius: 10px; font-size: .9rem; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw; text-align: center; }
#toast.show { opacity: .95; }

@media (min-height: 760px) { #keypad button { height: 88px; } }
