/* Trinity Bracket System — shared design tokens & primitives (mobile-first).
   Aesthetic follows the tour's properties (billiardscollective / CenTex /
   UPL SA): near-black green base, white type, one green accent + gold,
   red reserved for urgent, sharp edges, uppercase letterspaced labels. */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0d1110;
  --panel: #141917;
  --panel2: #1b211e;
  --line: #29312c;
  --text: #f2f4f2;
  --muted: #8d978f;
  --alpha: #c9a24b;   /* winners tier — gold */
  --omega: #7d9cb8;   /* one-loss tier — steel */
  --trinity: #a189c2; /* two-loss tier — violet */
  --live: #34a860;    /* brand green — live/positive */
  --danger: #d64545;  /* urgent only */
  --focus: #7fb595;
  --radius: 2px;
  --tap: 44px;
}
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  min-height: 100vh;
}
a { color: var(--focus); text-decoration: none; }
button { font: inherit; color: inherit; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 12px; }
.topbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: rgba(13,17,16,.95); backdrop-filter: blur(6px); z-index: 30;
}
.topbar h1 { font-size: 17px; font-weight: 800; letter-spacing: .02em; text-transform: uppercase; }
.topbar .sub { color: var(--muted); font-size: 13px; }
.spacer { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 8px 16px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--panel2); color: var(--text);
  font-weight: 600; cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.btn:active { transform: translateY(1px); filter: brightness(1.15); }
.btn.primary { background: var(--live); border-color: var(--live); color: #071009; }
.btn.warn { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.big { font-size: 18px; min-height: 56px; width: 100%; }
.btn:disabled { opacity: .4; pointer-events: none; }
.btn.small { min-height: 34px; padding: 4px 10px; font-size: 13px; border-radius: var(--radius); }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  border-radius: var(--radius); padding: 3px 8px; font-size: 10.5px; font-weight: 700;
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  letter-spacing: .12em; text-transform: uppercase;
  /* a chip is one short label: it may move, but it may never break in half.
     Wide system fonts (Segoe UI) used to split "MOVED · TABLE 2" across two
     lines inside the chip, doubling the card's head height. */
  white-space: nowrap;
}
.chip.alpha { color: var(--alpha); border-color: var(--alpha); }
.chip.omega { color: var(--omega); border-color: var(--omega); }
.chip.trinity { color: var(--trinity); border-color: var(--trinity); }
.chip.final { color: var(--alpha); border-color: var(--alpha); }
.chip.live { color: var(--live); border-color: var(--live); }
@keyframes pulse { 50% { opacity: .62; } }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-variant-numeric: tabular-nums; }

/* forms */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input[type="text"], input[type="date"], input[type="number"], input[type="password"], select, textarea {
  width: 100%; min-height: var(--tap); padding: 8px 12px; border-radius: var(--radius);
  background: var(--panel2); color: var(--text); border: 1px solid var(--line); font: inherit;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row > * { flex: 1; }
.row > .fixed { flex: 0 0 auto; }

/* tabs — flat underline nav, uppercase letterspaced */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 6px 0 0; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.tabs .tab {
  border: 0; border-bottom: 2px solid transparent; background: none; color: var(--muted);
  padding: 10px 14px 8px; border-radius: 0; font-weight: 700; white-space: nowrap; cursor: pointer;
  min-height: 40px; text-transform: uppercase; letter-spacing: .12em; font-size: 12.5px;
}
.tabs .tab.on { color: var(--text); border-bottom-color: var(--live); background: none; }
.tabpane { display: none; }
.tabpane.on { display: block; }

/* bottom sheet + modal */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 90; display: none;
}
.sheet-backdrop.on { display: block; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 91; display: none;
  background: var(--panel); border-top: 2px solid var(--live);
  border-radius: 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  max-height: 82vh; overflow-y: auto;
}
.sheet.on { display: block; animation: rise .18s ease-out; }
@keyframes rise { from { transform: translateY(40px); opacity: .4; } }
.sheet h3 { margin-bottom: 10px; font-size: 16px; }
.sheet .opt {
  display: flex; align-items: center; gap: 10px; width: 100%;
  min-height: 52px; padding: 8px 12px; margin-bottom: 8px;
  background: var(--panel2); border: 1px solid var(--line); border-radius: var(--radius);
  cursor: pointer; text-align: left; font-weight: 600;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.opt .grow { flex: 1; }
.sheet .opt.ghostopt { background: transparent; color: var(--muted); min-height: 44px; font-weight: 600; }

/* toast */
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #000; color: #fff; border: 1px solid var(--line);
  padding: 10px 18px; border-radius: var(--radius); font-weight: 600; z-index: 120;
  opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 92vw; text-align: center;
}
#toast.on { opacity: .96; }
#toast.err { background: var(--danger); border-color: var(--danger); }

/* queue columns (TD live view). The Run pane breaks out of the console's
   1100px reading column like the board does — four queue columns need the
   whole window, and the Done column's header was clipping at the edge. */
#pane-live {
  margin-left: calc(50% - 50vw + 8px);
  margin-right: calc(50% - 50vw + 8px);
  padding: 0 12px;
}
.qwrap { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.qcol { flex: 0 0 270px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.qcol h3 { font-size: 13px; letter-spacing: .08em; color: var(--muted); margin-bottom: 8px; text-transform: uppercase; }
.qcard {
  width: 100%; text-align: left; background: var(--panel2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px; margin-bottom: 8px; cursor: pointer;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
/* when a chip genuinely cannot fit beside the rest, it drops to its own line
   whole rather than being squeezed — the narrow-phone safety net */
.qcard .l1 { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; row-gap: 6px; margin-bottom: 6px; }
.qcard .code { font-weight: 800; font-size: 13px; color: var(--muted); }
.qcard .p { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.qcard .p .sc { color: var(--muted); font-variant-numeric: tabular-nums; }
.qcard .p .ph { color: var(--muted); font-weight: 500; }
.qcard .p.w { color: var(--live); }
/* action-graded card borders: the Run columns are a work list, so emphasis
   follows what needs the TD. A quiet green EDGE marks matches running fine;
   a full amber border marks "needs you" (on a table, clock not started);
   red is urgent. The 3px left rule echoes the tier-head motif. */
.qcard.live { border-color: var(--line); border-left: 3px solid var(--live); }
.qcard.unstarted { border-color: var(--alpha); border-left: 3px solid var(--alpha); }
.qcard .tbl { margin-left: auto; color: var(--live); border-color: var(--live); animation: none; }
.qcard .tbl.call { background: var(--live); color: #08130c; font-size: 13px; }
.qcol.tocall { border-color: var(--live); }
.qhead { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.qhead h3 { margin-bottom: 0; flex: 1; }
.qhead.qsub { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--line); }
.qclock { margin-top: 6px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.qclock .warn { color: var(--alpha); font-weight: 700; }
.qclock .over { color: var(--danger); font-weight: 800; letter-spacing: .06em; }
.pausecue { color: var(--alpha); font-weight: 800; letter-spacing: .08em; }
.tdcue { color: var(--danger); font-weight: 800; letter-spacing: .08em; animation: pulse 1.4s infinite; }
.movecue { color: var(--alpha); font-weight: 800; letter-spacing: .08em; animation: pulse 1.4s infinite; }
.qcard .tbl.mv { background: var(--alpha); color: #131007; border-color: var(--alpha); font-size: 13px; animation: none; }
.racecue { color: var(--alpha); font-weight: 800; letter-spacing: .08em; }
#tcalls { color: var(--danger); border-color: var(--danger); animation: pulse 1.4s infinite; }
.qcard.atrace { border-color: var(--alpha); border-left: 3px solid var(--alpha); }
.qcard.tdcalled { border-color: var(--danger); border-left: 3px solid var(--danger); }
.qstub {
  flex: 0 0 auto; align-self: stretch; display: flex; align-items: flex-start;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 10px; color: var(--muted); font-size: 13px; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase; cursor: pointer; white-space: nowrap;
  writing-mode: vertical-rl;
}

/* round group headers inside the Run columns (A1 / B2 / HOT SEAT…) */
.qgrp {
  display: flex; align-items: center; gap: 8px; width: 100%;
  background: none; border: 0; border-top: 1px solid var(--line);
  padding: 7px 2px 5px; margin: 2px 0 6px; cursor: pointer; color: var(--muted);
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.qgrp:first-child, .qhead + .qgrp { border-top: 0; margin-top: 0; padding-top: 2px; }
.qgrp .qgrp-n { font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums; }
.qgrp .qgrp-ch { margin-left: auto; font-size: 10px; }

/* bracket pace strip: one row per tier, one cell per round */
#pace { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
#pace:empty { display: none; }
.pace-row { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.pace-row .pt {
  flex: 0 0 62px; font-size: 10.5px; font-weight: 800;
  letter-spacing: .14em; text-transform: uppercase;
}
.pc {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 2px 7px;
  font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap;
}
.pc.done { color: #5f6a61; border-color: #212823; }
.pc.live { border-color: var(--live); color: var(--text); }
.pc.late { border-color: var(--danger); }
button.pc.pace-toggle {
  background: none; cursor: pointer; letter-spacing: .12em; font-weight: 700;
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.pc .lv { color: var(--live); font-weight: 700; }
.pc .rdy { color: var(--alpha); font-weight: 700; }
.pc .lateb { color: var(--danger); font-weight: 700; }

/* header chips that summarize the Run queues */
#tfree, #trace, #tcalls { cursor: pointer; }
#tfree.alert { color: var(--alpha); border-color: var(--alpha); animation: pulse 1.4s infinite; }
#trace { color: var(--alpha); border-color: var(--alpha); }

/* result dialog */
.btn.winbtn { min-height: 56px; }
.btn.winbtn.on { border-color: var(--live); background: rgba(53, 194, 107, .18); color: var(--live); }
.checkline { display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 600; cursor: pointer; }
.checkline input { width: 22px; height: 22px; accent-color: var(--live); }

/* tables tab: keep it a readable column even on wide screens */
#pane-links { max-width: 820px; }

/* the board tab wants the whole window, not the console's reading column —
   break out of the centered .wrap; oversized 1:1 boards pan inside the pane.
   Real padding keeps the bracket off the screen edges. */
#pane-board {
  margin-left: calc(50% - 50vw + 8px);
  margin-right: calc(50% - 50vw + 8px);
  padding: 4px 20px 16px;
  overflow-x: auto;
}
.lrow { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 7px 0; border-bottom: 1px solid var(--line); }
.lrow:last-child { border-bottom: 0; }
.lrow .lbl { flex: 0 0 auto; min-width: 74px; }
.lrow .st { flex: 1 1 160px; min-width: 140px; }
.lrow .stbtn {
  background: none; border: 0; padding: 0; text-align: left;
  color: inherit; font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.lrow .stbtn:active { filter: brightness(1.35); }
.lrow .lprog { flex: 1 0 100%; height: 3px; border-radius: 2px; background: var(--panel2); overflow: hidden; }
.lrow .lprog i { display: block; height: 100%; }
.btn.startrow { color: var(--alpha); border-color: var(--alpha); }

.copyline { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.copyline input { flex: 1; font-size: 13px; color: var(--muted); }

.badge-prov { background: transparent; color: var(--alpha); border-color: var(--alpha); }

@media (min-width: 700px) {
  .topbar h1 { font-size: 20px; }
  .sheet { left: 50%; right: auto; transform: translateX(-50%); width: 520px; border-radius: 18px; bottom: 40px; border: 1px solid var(--line); }
}
