:root {
  color-scheme: dark;
  --bg: #151518;
  --card: #222227;
  --card-2: #2b2b31;
  --line: #3a3a42;
  --text: #f3f3f5;
  --muted: #a7a7b2;
  --crimson: #c41224;
  --crimson-hi: #e8283d;
  --crimson-lo: #5a0a13;
  --ok: #2fbf71;
  --bad: #e8283d;
  --blue: #2f4fd8;
  --felt: #0e6a3c;
  --felt-line: #1c8a52;
  --rail: #3a2a1f;
  --radius: 14px;
  --tab-h: 64px;
  --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; background: var(--bg); color: var(--text); }
/* Fast repeat taps on the score buttons must never trigger double-tap zoom. */
html, button, a, input, select, label { touch-action: manipulation; }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  padding-bottom: calc(var(--tab-h) + var(--safe-b) + 8px);
  overflow-x: hidden;
}
a { color: var(--crimson-hi); }
button, input, select, textarea { font: inherit; color: var(--text); }
input, select, textarea {
  background: #111114; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--crimson-hi); outline-offset: 1px; }

/* DJ's bottlecap watermark + crimson shatter */
#watermark {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    url("../img/djs-logo-600.png") no-repeat right -90px bottom 70px / 300px 300px,
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 220'><g fill='%23c41224'><polygon points='0,0 120,0 40,70' opacity='.55'/><polygon points='120,0 210,0 150,45' opacity='.35'/><polygon points='40,70 150,45 90,120' opacity='.25'/><polygon points='0,0 40,70 0,140' opacity='.4'/><polygon points='210,0 300,0 260,30' opacity='.18'/><polygon points='150,45 260,30 200,95' opacity='.12'/><polygon points='0,140 90,120 30,210' opacity='.15'/></g></svg>") no-repeat left top / 420px auto;
  opacity: .16;
}

.topbar {
  position: sticky; top: 0; z-index: 5;
  padding: calc(var(--safe-t) + 8px) 16px 8px;
  background: linear-gradient(180deg, rgba(21,21,24,.97), rgba(21,21,24,.85));
  backdrop-filter: blur(6px);
  border-bottom: 1px solid #26262c;
}
.brand { display: flex; gap: 10px; align-items: center; color: var(--text); text-decoration: none; }
.brand img { border-radius: 50%; }
.brand b { display: block; font-size: 18px; letter-spacing: .3px; }
.brand small { display: block; color: var(--muted); font-size: 12px; margin-top: -2px; }

main { padding: 14px 16px 24px; max-width: 640px; margin: 0 auto; outline: none; }
h1 { font-size: 24px; margin: 6px 0 10px; }
h2 { font-size: 19px; margin: 22px 0 10px; }
h3 { font-size: 16px; margin: 0 0 6px; }
p { margin: 6px 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.stack > * + * { margin-top: 10px; }

.card {
  background: var(--card); border: 1px solid #2f2f36; border-radius: var(--radius);
  padding: 14px; margin: 10px 0;
}
.card.hero {
  background: linear-gradient(150deg, #3a0d14 0%, #25161a 45%, var(--card) 100%);
  border-color: var(--crimson-lo);
}
.card.done { border-color: #1e5c3c; background: linear-gradient(150deg, #12301f, var(--card)); }
.card a.cardlink { color: inherit; text-decoration: none; display: block; }
.pill {
  display: inline-block; font-size: 12px; padding: 2px 9px; border-radius: 99px;
  background: var(--card-2); color: var(--muted); border: 1px solid var(--line);
}
.pill.red { background: var(--crimson-lo); color: #ffd7dc; border-color: var(--crimson); }
.pill.green { background: #123522; color: #bff0d3; border-color: #1e6b43; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px; border-radius: 12px;
  background: var(--card-2); border: 1px solid var(--line); color: var(--text);
  font-weight: 600; text-decoration: none; cursor: pointer; user-select: none;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--crimson); border-color: var(--crimson-hi); color: #fff; }
.btn.big { min-height: 58px; font-size: 18px; width: 100%; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.sm { min-height: 38px; padding: 6px 12px; font-size: 14px; }
.btn[disabled] { opacity: .45; pointer-events: none; }

/* Scoring buttons: huge, chalky-thumb friendly */
.score-pad { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 12px 0; }
.score-pad button {
  min-height: 92px; border-radius: 18px; border: 2px solid; font-size: 22px; font-weight: 800;
  cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.score-pad button small { font-size: 13px; font-weight: 600; opacity: .85; }
.score-pad .yes { background: #123522; border-color: var(--ok); color: #d8ffe9; }
.score-pad .no { background: #3a1016; border-color: var(--bad); color: #ffe0e4; }
.score-pad button:active { filter: brightness(1.3); }

.dots { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.dots i { width: 22px; height: 22px; border-radius: 50%; background: #1a1a1e; border: 1px solid var(--line); display: inline-flex; align-items: center; justify-content: center; font-style: normal; font-size: 11px; color: var(--muted); }
.dots i.y { background: var(--ok); border-color: var(--ok); color: #062; }
.dots i.n { background: var(--bad); border-color: var(--bad); color: #fff; }

.timer { font-variant-numeric: tabular-nums; font-size: 44px; font-weight: 800; letter-spacing: 1px; line-height: 1; }
.timer.over { color: var(--crimson-hi); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .35; } }
.blockbar { display: flex; gap: 4px; margin: 8px 0 4px; }
.blockbar span { flex: 1; height: 6px; border-radius: 3px; background: #2d2d33; }
.blockbar span.done { background: var(--ok); }
.blockbar span.now { background: var(--crimson-hi); }

.bignum { font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: #1b1b20; border: 1px solid #2c2c33; border-radius: 12px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 22px; }
.stat span { font-size: 12px; color: var(--muted); }

/* Table diagram */
.diagram { display: block; width: 100%; max-width: 300px; margin: 6px auto; }
.diagram.compact { width: auto; max-width: 100%; height: 34vh; min-height: 220px; }
.modal .diagram { width: auto; max-width: 100%; height: 50vh; min-height: 260px; }
.diagram-wrap { position: relative; }
.diagram text { font: 700 9px -apple-system, sans-serif; }
.cap { min-height: 66px; background: #1b1b20; border-radius: 12px; padding: 10px 12px; margin: 8px 0; font-size: 15px; }

/* Explainer animation */
svg.explain [data-s] { opacity: 0; transition: opacity .45s ease; }
svg.explain [data-s].on { opacity: 1; }
svg.explain [data-s].on .anim, svg.explain .anim[data-s].on {
  stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 1.3s ease forwards;
}
svg.explain [data-s].on.pulse { animation: pulse 1.4s ease-in-out 2; }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes pulse { 50% { opacity: .35; } }

/* Score sheet */
.sheet-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table.sheet { border-collapse: collapse; width: 100%; min-width: 560px; font-size: 14px; }
.sheet th, .sheet td { border-bottom: 1px solid #2c2c33; padding: 0; text-align: center; white-space: nowrap; }
.sheet th { color: var(--muted); font-weight: 600; font-size: 12px; padding: 8px 4px; position: sticky; top: 0; background: var(--bg); }
.sheet td button.cell {
  width: 100%; min-height: 44px; background: none; border: 0; padding: 6px 6px; cursor: pointer; font-variant-numeric: tabular-nums;
}
.sheet td button.cell:active, .sheet td button.cell:focus { background: #2a2a31; }
.sheet td.date button.cell { text-align: left; font-weight: 600; }
.sheet .y { color: var(--ok); font-weight: 800; }
.sheet .n { color: var(--bad); font-weight: 800; }
.sheet tr.inprog td { background: #24171a; }

.seg { display: flex; background: #1b1b20; border: 1px solid #2c2c33; border-radius: 12px; padding: 3px; gap: 3px; margin: 8px 0; }
.seg button { flex: 1; min-height: 40px; border: 0; background: none; border-radius: 9px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--crimson); color: #fff; }

.list a.item {
  display: flex; gap: 12px; align-items: center; padding: 12px; border-radius: 12px;
  background: var(--card); border: 1px solid #2f2f36; color: var(--text); text-decoration: none; margin: 8px 0;
}
.list .item .ico { font-size: 26px; width: 38px; text-align: center; }
.list .item .chev { color: var(--muted); font-size: 20px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: rgba(17,17,20,.97); border-top: 1px solid #26262c;
}
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 600; }
.tabbar a .ico { font-size: 21px; line-height: 1.1; }
.tabbar a.on { color: var(--text); }
.tabbar a.on .ico { filter: drop-shadow(0 0 6px var(--crimson-hi)); }
body.running .tabbar { display: none; }
body.running { padding-bottom: 20px; }

/* Modal */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.modal {
  background: var(--card); width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + var(--safe-b)); border: 1px solid #34343c;
}
.modal .close { float: right; }
.yt { position: relative; padding-top: 56.25%; border-radius: 12px; overflow: hidden; background: #000; }
.yt iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

#toast {
  position: fixed; left: 50%; top: calc(var(--safe-t) + 64px); transform: translateX(-50%) translateY(-20px);
  background: #2e2e35; border: 1px solid var(--line); color: var(--text); padding: 10px 16px; border-radius: 12px;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 30; max-width: 90vw; text-align: center; font-size: 14px;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.banner { background: #2a1d10; border: 1px solid #6b4a1c; color: #ffe2b8; border-radius: 12px; padding: 10px 12px; font-size: 14px; margin: 8px 0; }
.nudge { background: #2a1418; border: 1px solid var(--crimson-lo); border-radius: 12px; padding: 12px; }
.rungs { display: flex; flex-direction: column-reverse; gap: 4px; margin: 8px 0; }
.rungs div { padding: 6px 10px; border-radius: 8px; background: #1b1b20; border: 1px solid #2c2c33; font-size: 14px; display: flex; justify-content: space-between; }
.rungs div.now { border-color: var(--crimson-hi); background: #3a1016; font-weight: 700; }
.rungs div.passed { color: var(--ok); }
hr { border: 0; border-top: 1px solid #2c2c33; margin: 16px 0; }
.kbd { font-family: ui-monospace, Menlo, monospace; font-size: 13px; }

/* Team tab */
.tabbar a { position: relative; }
.tabbar .badge { position: absolute; top: 6px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--crimson-hi); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }
.tabbar .badge[hidden] { display: none; }
.chat { display: flex; flex-direction: column; gap: 6px; padding: 6px 0 90px; }
.chat .day { align-self: center; font-size: 12px; color: var(--muted); margin: 10px 0 2px; }
.bubble { max-width: 82%; align-self: flex-start; background: var(--card-2); border: 1px solid var(--line); border-radius: 16px 16px 16px 4px; padding: 7px 11px; cursor: pointer; }
.bubble.mine { align-self: flex-end; background: var(--crimson-lo); border-color: var(--crimson); border-radius: 16px 16px 4px 16px; }
.bubble .who { font-size: 12px; font-weight: 700; color: #ffd54a; margin-bottom: 2px; }
.bubble .body { white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.bubble .t { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; }
.composer { position: fixed; left: 0; right: 0; bottom: calc(var(--tab-h) + var(--safe-b)); z-index: 5; display: flex; gap: 8px; align-items: flex-end;
  padding: 8px 16px; background: rgba(21,21,24,.97); border-top: 1px solid #26262c; max-width: 640px; margin: 0 auto; }
.composer textarea { resize: none; min-height: 44px; max-height: 140px; border-radius: 22px; padding: 11px 14px; }
.composer .btn { min-height: 44px; border-radius: 22px; }
.avail .btn { min-height: 40px; }
body.typing .tabbar { display: none; }
body.typing .composer { bottom: 0; padding-bottom: calc(8px + var(--safe-b)); }
.coach { background: #1f1a12; border: 1px solid #5a4515; border-radius: 12px; padding: 9px 12px; font-size: 14px; color: #f3e6c4; margin: 8px 0; }
