/* cutschedule — single stylesheet: tokens first, then components.
   Event colors are runtime tokens: settings writes hex values onto :root,
   so nothing below may hardcode a kind color. Dark-only by design — rink
   crew phones, and the board is meant to sit propped in the Zamboni room. */

:root {
  /* surfaces */
  --bg: #0b0e12;
  --surface: #151a21;
  --raised: #1c232d;
  --line: rgba(255, 255, 255, 0.08);
  --text: #e8edf2;
  --dim: #8b95a3;
  --faint: #5b6572;

  /* event kinds — defaults; settings overrides these per device */
  --c-cut: #22d3ee;
  --c-internal: #a78bfa;
  --c-external: #fb923c;
  --c-gap: #34d399;

  /* fixed chrome */
  --c-booking: #64748b;   /* kind fallback the parser shouldn't normally emit */
  --drained: #2a3038;     /* consumed portion of an in-progress bar */
  --needle: #f43f5e;
  --danger: #f43f5e;

  --radius: 14px;
  --radius-sm: 7px;
  --dock-h: 64px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "JetBrains Mono", monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100dvh;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input {
  font: inherit; color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  width: 100%;
}
input:focus { outline: 2px solid var(--c-cut); outline-offset: -1px; }

/* ── app shell ─────────────────────────────────────────────────────── */

/* one sticky block: title row + the per-lane pills, no separate offsets */
.shell-header {
  position: sticky; top: 0; z-index: 30;
  padding: calc(6px + env(safe-area-inset-top)) 12px 8px;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  max-width: 640px; margin: 0 auto;
}
.shell-row { display: flex; align-items: center; gap: 10px; }
.shell-header h1 { font-size: 15px; font-weight: 700; letter-spacing: 0.2px; }
.shell-header .spacer { flex: 1; }

.freshness { font-size: 11px; color: var(--dim); }
.freshness.stale { color: var(--danger); font-weight: 600; }

.icon-btn {
  min-width: 44px; min-height: 44px;
  display: grid; place-items: center;
  border-radius: 50%;
  font-size: 18px;
  color: var(--dim);
}
.icon-btn.on { color: var(--c-cut); }

main {
  padding: 12px 12px calc(var(--dock-h) + 24px + env(safe-area-inset-bottom));
  max-width: 640px; margin: 0 auto;
}

/* floating dock */
.dock {
  position: fixed; z-index: 40;
  left: 50%; transform: translateX(-50%);
  bottom: calc(10px + env(safe-area-inset-bottom));
  display: flex; gap: 4px;
  padding: 5px;
  background: color-mix(in srgb, var(--raised) 88%, transparent);
  backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}
.dock button {
  min-width: 72px; min-height: 44px;
  border-radius: 999px;
  font-size: 12px; font-weight: 600;
  color: var(--dim);
  display: grid; place-items: center; gap: 0;
}
.dock button .ico { font-size: 16px; line-height: 1.1; }
.dock button.active { background: var(--surface); color: var(--text); }

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

/* ── per-lane countdown pills (in the top bar) ─────────────────────────
   Outline = rink identity (--rk), fill = what's on the ice right now
   (set inline: current event / gap color tinted into the surface). */

.hpills { display: flex; gap: 6px; margin-top: 7px; }
.pill {
  flex: 1; min-width: 0;
  border: 1.5px solid var(--rk);
  border-radius: 12px;
  padding: 5px 9px 6px;
  background: var(--surface);
}
.pill .r1 { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.pill .l1 {
  font-size: 9px; font-weight: 800; letter-spacing: 1.1px;
  text-transform: uppercase; color: var(--rk);
}
.pill .big {
  font-family: var(--mono);
  font-size: 15px; font-weight: 700; line-height: 1.2;
  font-variant-numeric: tabular-nums;
}
.pill.hot .big { color: var(--c-cut); }
.pill .now {
  display: flex; align-items: center; gap: 4px;
  margin-top: 2px; font-size: 10px; font-weight: 600;
  white-space: nowrap; overflow: hidden;
}
.pill .now .ndot { width: 6px; height: 6px; border-radius: 50%; flex: none; }
.pill .now .ntext { overflow: hidden; text-overflow: ellipsis; }
.pill .then {
  margin-top: 1px; font-size: 10px; color: var(--dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* date nav */
.datenav {
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 12px;
}
.datenav .label { flex: 1; text-align: center; font-weight: 700; font-size: 15px; }
.datenav .label .today-tag { color: var(--c-cut); }
.datenav button {
  min-width: 44px; min-height: 44px;
  border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--line);
  font-size: 16px; color: var(--dim);
}
.datenav button.snap { font-size: 12px; font-weight: 700; color: var(--c-cut); }

/* notes adrift — anchors that no longer match a bar after a re-pull */
.adrift { border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); }
.adrift .t { font-size: 11px; font-weight: 700; color: var(--danger); margin-bottom: 6px; }
.adrift .n { font-size: 12px; color: var(--dim); padding: 3px 0; }

/* ── timeboard component ───────────────────────────────────────────── */

.tb { position: relative; display: flex; }
/* 32px: wide enough for "12p", narrow enough that the left margin reads
   the same as the right one */
.tb-gutter { width: 32px; flex: none; position: relative; }
.tb-hour {
  position: absolute; right: 6px; transform: translateY(-50%);
  font-size: 10px; font-family: var(--mono); color: var(--faint);
}
.tb-lanes { flex: 1; display: flex; gap: 6px; position: relative; }
.tb-lane { flex: 1; position: relative; }
.tb-lane-head {
  position: sticky; top: 0;
  font-size: 11px; font-weight: 700; letter-spacing: 1px;
  text-transform: uppercase; color: var(--dim);
  text-align: center; padding-bottom: 6px;
}
.tb-rule {
  position: absolute; left: 0; right: 0; height: 1px;
  background: var(--line); pointer-events: none;
}

.tb-bar {
  position: absolute;
  border-radius: var(--radius-sm);
  color: #0b0e12;
  /* --k: event color, --p: consumed fraction (%). Drain = hard gradient stop;
     consumed time is the TOP of the bar because time flows down.
     --rk: rink identity — an edge stripe, so event color keeps the fill. */
  background: linear-gradient(to bottom, var(--drained) var(--p, 0%), var(--k) var(--p, 0%));
  border-left: 3px solid var(--rk, transparent);
}
/* text clips inside; the outer bar must stay overflow-visible so the
   expanded tap hitbox and the note badge aren't clipped with it */
.tb-bar .in {
  position: absolute; inset: 0;
  overflow: hidden;
  padding: 3px 7px;
  border-radius: inherit;
}
.tb-bar.past { opacity: 0.5; }
.tb-bar .t1 {
  font-size: 11px; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tb-bar .t2 { font-size: 10px; opacity: 0.75; font-family: var(--mono); }
.tb-bar.cut { box-shadow: 0 0 0 1px color-mix(in srgb, var(--k) 60%, transparent); }
.tb-bar.cut .t1 { letter-spacing: 0.3px; }
/* consumed portion is dark — flip label color so it stays readable */
.tb-bar.draining .t1, .tb-bar.draining .t2, .tb-bar.past .t1, .tb-bar.past .t2 { color: var(--text); }

/* a 10-minute cut is ~20px tall; the visible bar stays honest to scale
   while the hitbox grows to the 44px floor. No position here — the bars
   are already absolute, and a later `relative` would win the cascade and
   knock every bar back into document flow. */
.tb-tap::before {
  content: ""; position: absolute; left: 0; right: 0;
  top: min(0px, calc((100% - 44px) / 2));
  bottom: min(0px, calc((100% - 44px) / 2));
}

.tb-gap {
  position: absolute; left: 4px; right: 4px;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.tb-gap .chip {
  pointer-events: auto;
  font-size: 10px; font-family: var(--mono); font-weight: 600;
  color: var(--c-gap);
  border: 1px dashed color-mix(in srgb, var(--c-gap) 45%, transparent);
  border-radius: 999px;
  padding: 2px 8px;
  background: var(--bg);
  white-space: nowrap;
}
.tb-gap.now .chip {
  color: var(--bg);
  background: var(--c-gap);
  border-style: solid;
  font-size: 11px;
}

.tb-needle {
  position: absolute; left: 0; right: 0; z-index: 5;
  height: 2px; background: var(--needle);
  pointer-events: none;
}
.tb-needle::before {
  content: attr(data-t);
  position: absolute; left: 0; top: -8px;
  transform: translateY(-100%);
  font-size: 10px; font-family: var(--mono); font-weight: 700;
  color: var(--bg); background: var(--needle);
  padding: 1px 5px; border-radius: 4px;
}

.tb-notecount {
  position: absolute; top: -5px; right: -4px; z-index: 2;
  min-width: 16px; height: 16px;
  border-radius: 999px;
  background: var(--text); color: var(--bg);
  font-size: 10px; font-weight: 800;
  display: grid; place-items: center;
  padding: 0 4px;
}

/* ── outlook ───────────────────────────────────────────────────────── */

.ol-day { margin-bottom: 12px; }
.ol-day .head {
  width: 100%;
  display: flex; align-items: baseline; gap: 8px;
  padding: 10px 2px; text-align: left;
  border-bottom: 1px solid var(--line);
}
.ol-day .head .d { font-weight: 700; font-size: 14px; flex: 1; }
.ol-day .head .c { font-size: 12px; color: var(--dim); font-family: var(--mono); }
.ol-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 2px; font-size: 13px;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 50%, transparent);
}
.ol-row .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.ol-row .time { font-family: var(--mono); font-weight: 600; min-width: 64px; }
.ol-row .rink { font-size: 11px; font-weight: 700; color: var(--dim); min-width: 18px; }
.ol-row .ctx { color: var(--dim); font-size: 12px; flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ol-toggle { display: flex; gap: 8px; margin-bottom: 12px; }
.ol-toggle button {
  flex: 1; min-height: 44px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--dim); font-weight: 600; font-size: 13px;
}
.ol-toggle button.active { color: var(--text); border-color: var(--c-cut); }

/* ── settings ──────────────────────────────────────────────────────── */

.set-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.set-row label { flex: 1; font-size: 14px; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.set-row label .count { color: var(--faint); font-size: 11px; font-family: var(--mono); }
.set-row .swatch {
  width: 34px; height: 34px; flex: none;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
}
.set-row input.hex { width: 110px; font-family: var(--mono); text-transform: lowercase; }
.set-row input.hex.bad { border-color: var(--danger); }
.set-note { font-size: 12px; color: var(--faint); margin-top: 8px; }
.set-h { font-size: 12px; font-weight: 700; letter-spacing: 1px;
  text-transform: uppercase; color: var(--dim); margin-bottom: 4px; }
.btn {
  min-height: 44px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--raised); font-weight: 600; font-size: 13px;
}
.btn.danger { color: var(--danger); }

/* ── bottom sheet (slot / gap detail + notes) ──────────────────────── */

.sheet-veil {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0; transition: opacity 0.18s;
}
.sheet-veil.in { opacity: 1; }
.sheet {
  position: fixed; z-index: 51;
  left: 0; right: 0; bottom: 0;
  max-width: 640px; margin: 0 auto;
  background: var(--raised);
  border: 1px solid var(--line); border-bottom: none;
  border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
  max-height: 82dvh; overflow-y: auto;
  transform: translateY(100%); transition: transform 0.22s cubic-bezier(0.3, 0.9, 0.4, 1);
}
.sheet.in { transform: translateY(0); }
.sheet .grab {
  width: 36px; height: 4px; border-radius: 2px;
  background: var(--line); margin: 4px auto 12px;
}
.sheet h2 { font-size: 17px; margin-bottom: 2px; }
.sheet .when { font-size: 13px; color: var(--dim); font-family: var(--mono); }
.sheet .flank { font-size: 13px; color: var(--dim); margin: 10px 0;
  display: grid; gap: 4px; }
.sheet .flank b { color: var(--text); font-weight: 600; }

.note {
  border-top: 1px solid var(--line);
  padding: 10px 0; font-size: 14px;
  display: flex; gap: 10px; align-items: baseline;
}
.note .body { flex: 1; white-space: pre-wrap; overflow-wrap: anywhere; }
.note .meta { font-size: 11px; color: var(--faint); white-space: nowrap; }
.note .del { color: var(--faint); font-size: 15px; min-width: 44px; min-height: 24px; }
.note-form { display: flex; gap: 8px; margin-top: 12px; }
.note-form input { flex: 1; }
.note-form .btn { flex: none; border-color: var(--c-cut); color: var(--c-cut); }

.empty { text-align: center; color: var(--faint); font-size: 13px; padding: 28px 0; }
.err { text-align: center; color: var(--danger); font-size: 13px; padding: 20px 0; }
