/* Puck web UI. Built for phones at the race field: bright sunlight (light theme, dark text, strong
   colours, nothing below 4.5:1), one hand (44 px targets, actions at the bottom), 360 px wide screens. */
:root {
  --ink: #0b0d10;
  --ink-2: #3a4048;
  --paper: #ffffff;
  --paper-2: #f1f3f5;
  --line: #a9b0b8;
  --line-soft: #d5dade;
  --blue: #0047b3;
  --blue-ink: #ffffff;
  --green: #0b6b3f;        /* After pass */
  --green-bright: #3ee08f;
  --amber: #8a5300;        /* Always */
  --amber-bright: #ffc145;
  --red: #b3171d;
  --red-bg: #fde8e8;
  --good-bg: #e2f5ea;
  --info-bg: #eef3fb;
  --goggle: #101317;
  --focus: #ff9d00;
  --radius: 10px;
  --gutter: 16px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}
main { max-width: 36rem; margin: 0 auto; padding: var(--gutter) var(--gutter) calc(var(--gutter) + env(safe-area-inset-bottom)); }
body.admin main { max-width: 56rem; }
h1 { font-size: 1.6rem; line-height: 1.2; margin: .2rem 0 .6rem; overflow-wrap: anywhere; }
h1:focus { outline: none; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .5rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
p { margin: .5rem 0; }
a { color: var(--blue); text-underline-offset: 2px; }
a.inline { font-weight: 600; }
code, .mono { font-family: ui-monospace, Menlo, Consolas, "DejaVu Sans Mono", monospace; }
.small, small { font-size: .88rem; }
.hint { color: var(--ink-2); font-size: .94rem; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------- buttons, fields */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 48px; padding: .6rem 1.1rem; border-radius: var(--radius); border: 2px solid var(--blue);
  font: inherit; font-weight: 700; text-decoration: none; cursor: pointer; touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  background: var(--paper); color: var(--blue);
}
.btn.main { background: var(--blue); color: var(--blue-ink); }
.btn.alt { background: var(--paper); color: var(--blue); }
.btn.ghost { border-color: transparent; background: none; color: var(--blue); text-decoration: underline; }
.btn.danger { border-color: var(--red); color: var(--red); background: var(--paper); }
.btn.small { min-height: 44px; padding: .4rem .8rem; font-size: .94rem; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.nudge { min-width: 48px; padding: 0; font-size: 1.3rem; }
.field {
  display: block; width: 100%; min-height: 48px; padding: .6rem .75rem; border: 2px solid var(--line); border-radius: var(--radius);
  font: inherit; color: var(--ink); background: var(--paper);
}
.field:focus { border-color: var(--blue); }
textarea.field { min-height: 6rem; font-size: 16px; } /* under 16 px iOS zooms on focus */
select.field.small { min-height: 44px; width: auto; }
label { font-weight: 600; }
.stack { display: flex; flex-direction: column; gap: .45rem; margin: .6rem 0; }
.stack > .btn { align-self: flex-start; }
.stack > .btn.wide { align-self: stretch; }
.with-btn { display: flex; gap: .5rem; align-items: stretch; }
.with-btn .field { flex: 1; min-width: 0; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.row-btns { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }

/* ---------- messages */
.result { min-height: 1.4em; margin: .5rem 0; font-weight: 600; }
.result:empty { margin: 0; min-height: 0; }
.result.good, .result.bad, .result.info { padding: .55rem .75rem; border-radius: var(--radius); border-left: 5px solid; }
.result.good { background: var(--good-bg); border-color: var(--green); color: #063d24; }
.result.bad { background: var(--red-bg); border-color: var(--red); color: #6e0b0f; }
.result.info { background: var(--info-bg); border-color: var(--blue); color: #0a2a5c; }
.warn { margin: .4rem 0; padding: .45rem .7rem; border-radius: var(--radius); background: #fff4d6; color: #5a3600; border-left: 5px solid var(--amber); font-weight: 600; font-size: .94rem; }
.warn:empty { display: none; }

/* ---------- pills */
.pill { display: inline-flex; align-items: center; gap: .35rem; padding: .15rem .6rem; border-radius: 999px; font-size: .88rem; font-weight: 700; border: 2px solid currentColor; vertical-align: middle; }
.pill .dot { width: .6rem; height: .6rem; border-radius: 50%; background: currentColor; }
.feed-live { color: var(--green); }
.feed-stale { color: var(--amber); }
.feed-down { color: var(--red); }
.feed-connecting { color: var(--amber); }
.feed-off { color: var(--ink-2); }
.race-running { color: var(--green); }
.race-staging { color: var(--amber); }
.pill[class*="race-"]:not(.race-running):not(.race-staging) { color: var(--ink-2); }
.status-line { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; }

/* ---------- lists of names / items */
.list { list-style: none; margin: .5rem 0; padding: 0; border: 2px solid var(--line-soft); border-radius: var(--radius); overflow: hidden; }
.list > li { border-top: 1px solid var(--line-soft); }
.list > li:first-child { border-top: 0; }
.list .row { display: flex; align-items: center; gap: .6rem; min-height: 56px; padding: .5rem .9rem; color: var(--ink); text-decoration: none; }
.list .row:active { background: var(--paper-2); }
.list .name { flex: 1; min-width: 0; font-weight: 700; overflow-wrap: anywhere; white-space: pre-wrap; }
.count { margin: .3rem 0 0; }
.list .tag { color: var(--blue); font-weight: 700; font-size: .9rem; white-space: nowrap; }
.list .claimed .tag { color: var(--ink-2); }
.list .go { color: var(--ink-2); font-size: 1.5rem; line-height: 1; }
.list .none { padding: .9rem; color: var(--ink-2); }
.list .item { display: flex; align-items: center; gap: .7rem; padding: .6rem .9rem; flex-wrap: wrap; }
.list .item.revoked { color: var(--ink-2); background: var(--paper-2); }
.item-main { flex: 1; min-width: 12rem; overflow-wrap: anywhere; }
.item-main p { margin: .15rem 0 0; color: var(--ink-2); }
.item input[type=checkbox] { width: 24px; height: 24px; }
details.more { margin: 1rem 0; }
details.more summary { cursor: pointer; color: var(--blue); font-weight: 700; min-height: 44px; display: flex; align-items: center; }
.card { border: 2px solid var(--line-soft); border-radius: var(--radius); padding: .4rem .9rem .7rem; margin: .8rem 0; }
.card.you { border-color: var(--blue); background: var(--info-bg); }
.card.token { border-color: var(--amber); background: #fff8e6; }
.cards { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); }
.cards .card { margin: 0; }
dl { display: grid; grid-template-columns: auto 1fr; gap: .1rem .8rem; margin: .5rem 0 0; font-size: .94rem; }
dt { color: var(--ink-2); }
dd { margin: 0; font-weight: 600; }

/* ---------- the goggles grid */
.gridwrap { margin: .4rem 0 0; }
.grid {
  --cell: 7px;
  position: relative; width: 100%; aspect-ratio: 50 / 18; background-color: var(--goggle); border-radius: 6px;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
  background-image:
    linear-gradient(rgba(255,255,255,.09) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.09) 1px, transparent 1px);
  background-size: calc(100% / 50) calc(100% / 18);
  outline: 2px solid var(--ink); cursor: crosshair;
}
@supports not (aspect-ratio: 1) {
  /* iOS 14: the chips are positioned against the padding box, so this gives the same 50:18 box */
  .grid { height: 0; padding-top: 36%; }
}
.chip {
  position: absolute; height: calc(100% / 18); margin: 0; padding: 0; border: 0; border-radius: 0;
  font-family: ui-monospace, Menlo, Consolas, "DejaVu Sans Mono", monospace; font-weight: 700;
  font-size: calc(var(--cell) * 1.3); letter-spacing: calc(var(--cell) * .22); line-height: var(--cell);
  color: #fff; white-space: pre; text-align: left; overflow: visible; pointer-events: none;
  background: var(--green); outline: 2px solid var(--green-bright); outline-offset: 0;
}
.chip.always { background: var(--amber); outline-color: var(--amber-bright); }
.chip.sel { outline: 3px solid #fff; box-shadow: 0 0 0 5px var(--focus); z-index: 2; }
.chip.drag { z-index: 3; }
.chip:focus-visible { outline: 3px solid #fff; box-shadow: 0 0 0 6px var(--focus); }
.under-grid { display: flex; align-items: center; justify-content: space-between; gap: .5rem; flex-wrap: wrap; margin-top: .4rem; }
.where { margin: 0; font-weight: 600; font-size: .94rem; flex: 1; min-width: 10rem; }
.nudges { display: flex; gap: .3rem; }
.legend { margin-top: .3rem; }
.key { display: inline-block; padding: 0 .4rem; border-radius: 4px; color: #fff; font-weight: 700; }
.key-always { background: var(--amber); }
.key-pass { background: var(--green); }
@media (max-width: 599px) {
  /* edge to edge on phones: every pixel makes the cells bigger */
  .gridwrap { margin-left: calc(-1 * var(--gutter)); margin-right: calc(-1 * var(--gutter)); }
  .grid { border-radius: 0; outline: 0; }
}

/* ---------- element modes */
.els { border-top: 1px solid var(--line-soft); }
.el { display: flex; align-items: center; justify-content: space-between; gap: .5rem; min-height: 56px; border-bottom: 1px solid var(--line-soft); flex-wrap: wrap; padding: .3rem 0; }
.el-name { font-weight: 700; }
.el.na .el-name { color: var(--ink-2); }
.seg { display: inline-flex; border: 2px solid var(--ink); border-radius: var(--radius); overflow: hidden; flex: none; }
.seg label { position: relative; display: flex; align-items: center; min-height: 44px; padding: 0 .65rem; font-size: .9rem; font-weight: 700; cursor: pointer; border-left: 2px solid var(--ink); background: var(--paper); color: var(--ink); white-space: nowrap; }
.seg label:first-child { border-left: 0; }
.seg input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.seg label.on.seg-off { background: var(--ink); color: #fff; }
.seg label.on.seg-pass { background: var(--green); color: #fff; }
.seg label.on.seg-always { background: var(--amber); color: #fff; }
.seg label:focus-within { outline: 3px solid var(--focus); outline-offset: -3px; z-index: 1; }
.el.na .seg { opacity: .45; }
.el.na .seg label { cursor: default; }

/* ---------- hold + switch */
.hold { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.hold input[type=range] { flex: 1 1 10rem; min-width: 0; height: 44px; accent-color: var(--blue); }
.hold output { font-weight: 700; min-width: 7.5rem; }
.switch-row { display: flex; align-items: center; gap: .7rem; min-height: 56px; margin: .6rem 0; }
.switch-row label { font-weight: 400; }
input.switch {
  appearance: none; -webkit-appearance: none; flex: none; position: relative; width: 56px; height: 32px; margin: 0;
  border-radius: 999px; background: #7d858e; border: 2px solid var(--ink); cursor: pointer;
}
input.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: left .15s; }
input.switch:checked { background: var(--green); }
input.switch:checked::after { left: 26px; }

/* ---------- editor actions: in reach of the thumb */
.actions {
  position: sticky; bottom: 0; z-index: 5; margin: 1rem calc(-1 * var(--gutter)) 0; padding: .6rem var(--gutter) calc(.6rem + env(safe-area-inset-bottom));
  background: var(--paper); border-top: 2px solid var(--line-soft); box-shadow: 0 -4px 12px rgba(0,0,0,.08);
}
.action-row { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.action-msg { display: flex; flex-direction: column; }
.action-msg .result { margin: .4rem 0 0; }
.dirty { color: var(--amber); font-weight: 700; font-size: .9rem; margin-top: .3rem; }
.dirty:empty { display: none; }
.foot { margin-top: 1.5rem; padding-top: .5rem; border-top: 2px solid var(--line-soft); }

/* ---------- live tables */
table.live { width: 100%; border-collapse: collapse; margin: .5rem 0; font-size: 1rem; }
table.live th, table.live td { padding: .55rem .4rem; border-bottom: 1px solid var(--line-soft); text-align: left; }
table.live thead th { font-size: .85rem; color: var(--ink-2); border-bottom: 2px solid var(--line); }
table.live tbody th { font-weight: 700; overflow-wrap: anywhere; }
table.live .num { text-align: right; font-variant-numeric: tabular-nums; }
table.live tr.me { background: var(--info-bg); }
table.live .tag { color: var(--blue); font-size: .85rem; }
.event { font-weight: 700; color: var(--ink-2); margin: 0; }

/* ---------- admin */
.admin-head { display: flex; justify-content: space-between; align-items: center; gap: .6rem; flex-wrap: wrap; }
.admin-head h1 { margin: 0; }
.tabs { display: flex; gap: .25rem; overflow-x: auto; border-bottom: 2px solid var(--ink); margin: 1rem calc(-1 * var(--gutter)) 0; padding: 0 var(--gutter); scrollbar-width: none; }
.tab { flex: none; min-height: 48px; padding: .5rem .55rem; border: 2px solid transparent; border-bottom: 0; border-radius: var(--radius) var(--radius) 0 0; background: none; font: inherit; font-size: .95rem; font-weight: 700; color: var(--blue); cursor: pointer; margin-bottom: -2px; }
.tab[aria-selected="true"] { border-color: var(--ink); background: var(--paper); color: var(--ink); box-shadow: inset 0 -2px 0 var(--paper); }
.panel { padding-top: .5rem; }
.panel:focus { outline: none; }
.log { list-style: none; padding: 0; margin: .4rem 0; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .82rem; max-height: 22rem; overflow: auto; border: 2px solid var(--line-soft); border-radius: var(--radius); }
.log li { padding: .25rem .6rem; border-top: 1px solid var(--line-soft); overflow-wrap: anywhere; }
.log li:first-child { border-top: 0; }
.log .lvl { font-weight: 700; }
.log .lvl-warn .lvl { color: var(--amber); }
.log .lvl-error { background: var(--red-bg); }
.log .lvl-error .lvl { color: var(--red); }
