:root {
  color-scheme: dark;
  --bg: #050b16;
  --surface: #0a1428;
  --panel: #111d33;
  --border: #23324f;
  --text: #f0e6d2;
  --muted: #7d8aa6;
  --gold: #c89b3c;
  --teal: #0ac8b9;
  --live: #00ff88;
  --scrub: #ffcc00;
  --pf-twitch: #a970ff;
  --pf-youtube: #ff4d4d;
  --row-bg: rgba(255, 255, 255, 0.02);
  --label-w: 210px;
  --axis-h: 46px;
  --row-h: 48px;
  --ghead-h: 26px;
  font-family: "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", sans-serif;
}
body.light {
  color-scheme: light;
  --bg: #f6f1e7;
  --surface: #ffffff;
  --panel: #ece4d4;
  --border: #d8ccb6;
  --text: #1e2328;
  --muted: #7a7266;
  --live: #00a352;
  --scrub: #d68a00;
  --row-bg: rgba(0, 0, 0, 0.025);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--bg); color: var(--text);
  background-image: radial-gradient(1200px 500px at 50% -10%, rgba(10, 200, 185, 0.12), transparent 70%);
}
button, select {
  font: inherit; font-size: 12px; color: var(--text); background: var(--panel);
  border: 1px solid var(--border); border-radius: 6px; padding: 5px 10px; cursor: pointer;
}
button:hover, select:hover { border-color: var(--gold); }
button.on { background: var(--gold); color: #111; border-color: var(--gold); }
button.primary { background: linear-gradient(90deg, var(--gold), #f0c35a); color: #111; font-weight: 700; border: none; }
button.primary:disabled { opacity: .4; cursor: default; }
button.x { background: none; border: none; font-size: 20px; line-height: 1; padding: 0 6px; color: var(--muted); }
.hint { color: var(--muted); font-size: 11px; }

/* ---------- header ---------- */
header {
  padding: 10px 16px 8px; border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center; justify-content: space-between;
}
.brand { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.brand-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.brand h1 { margin: 0; font-size: 20px; letter-spacing: .04em; color: var(--gold); }
.badge-unofficial {
  font-size: 13px; font-weight: 800; letter-spacing: .1em; color: #fff; background: #d6336c;
  border-radius: 5px; padding: 3px 9px; box-shadow: 0 0 0 2px color-mix(in srgb, #d6336c 35%, transparent);
}
.unofficial-note { margin: 0; font-size: 12px; color: var(--text); opacity: .85; }
.unofficial-note b { color: #ff6b9a; }
body.light .unofficial-note b { color: #c2255c; }
.scope-note { margin: 0; font-size: 12px; color: var(--muted); }
.scope-note b { color: var(--teal); }
button.link { background: none; border: none; padding: 0 2px; color: var(--gold); text-decoration: underline; font-size: inherit; }
.doc { max-width: 720px; max-height: 85vh; display: flex; flex-direction: column; }
.doc-body { overflow: auto; padding: 4px 20px 20px; font-size: 13px; line-height: 1.8; }
.doc-body h3 { font-size: 14px; color: var(--gold); margin: 18px 0 4px; }
.doc-body p, .doc-body ul { margin: 0; }
.doc-body ul { padding-left: 1.3em; }
.doc-body .riot { font-size: 12px; color: var(--muted); }
.tools { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.presets, .chips { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.chips label { font-size: 12px; display: inline-flex; align-items: center; gap: 4px; padding: 4px 8px; border: 1px solid var(--border); border-radius: 999px; cursor: pointer; user-select: none; }
.chips input { margin: 0; accent-color: var(--gold); }

/* ---------- board ---------- */
main#board { flex: 1; overflow: auto; position: relative; cursor: grab; }
main#board.dragging { cursor: grabbing; user-select: none; }
#loader { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }
#grid { position: relative; min-width: 100%; }
#axis {
  position: sticky; top: 0; z-index: 8; display: flex; height: var(--axis-h);
  background: color-mix(in srgb, var(--surface) 94%, transparent); border-bottom: 1px solid var(--border);
}
.corner {
  position: sticky; left: 0; z-index: 9; flex: none; width: var(--label-w); padding: 6px 12px;
  background: var(--surface); border-right: 1px solid var(--border); font-size: 12px; font-weight: 700;
  display: flex; flex-direction: column; justify-content: center;
}
.corner small { color: var(--muted); font-weight: 400; font-size: 10px; }
#axisTrack { position: relative; flex: none; cursor: col-resize; }
.tick { position: absolute; top: 0; bottom: 0; border-left: 1px solid var(--border); font-size: 11px; color: var(--muted); padding: 22px 0 0 4px; white-space: nowrap; }
.tick.day { border-left: 2px solid var(--gold); color: var(--gold); font-weight: 700; padding-top: 4px; }
.tick.day::after { content: attr(data-hm); display: block; color: var(--muted); font-weight: 400; margin-top: 2px; }

#bands { position: absolute; top: 0; bottom: 0; left: var(--label-w); pointer-events: none; z-index: 0; }
.band { position: absolute; top: 0; bottom: 0; background: rgba(200, 155, 60, 0.07); border-left: 1px dashed rgba(200, 155, 60, .5); border-right: 1px dashed rgba(200, 155, 60, .5); }
.band span, .evline span {
  position: sticky; top: calc(var(--axis-h) + 2px); display: inline-block; font-size: 10px; font-weight: 700;
  padding: 1px 6px; border-radius: 3px; white-space: nowrap; margin-top: calc(var(--axis-h) + 2px);
}
.band.ltk { background: rgba(139, 92, 246, 0.10); border-color: rgba(139, 92, 246, .6); }
.band.ltk span { background: #7c4dff; color: #fff; }
.evline { position: absolute; top: 0; bottom: 0; width: 0; border-left: 2px dotted #14b8a6; }
.evline span { background: #0f766e; color: #fff; margin-top: calc(var(--axis-h) + 20px); top: calc(var(--axis-h) + 20px); }
.gridline { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--border); opacity: .35; }
.gridline.day { background: var(--gold); opacity: .35; }

.ghead { display: flex; height: var(--ghead-h); }
.ghead .glabel {
  position: sticky; left: 0; z-index: 7; padding: 4px 12px; font-size: 12px; font-weight: 700; letter-spacing: .08em;
  color: var(--gold); white-space: nowrap; background: linear-gradient(90deg, var(--surface) 70%, transparent);
}
.ghead .glabel small { color: var(--muted); font-weight: 400; margin-left: 8px; letter-spacing: 0; }
.row { display: flex; height: var(--row-h); border-bottom: 1px solid color-mix(in srgb, var(--border) 50%, transparent); background: var(--row-bg); }
.label {
  position: sticky; left: 0; z-index: 7; flex: none; width: var(--label-w); padding: 4px 8px 4px 10px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--lane) 22%, var(--surface)) 0%, var(--surface) 75%);
  border-left: 4px solid var(--lane); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; justify-content: center; gap: 3px; cursor: default;
}
.label .top { display: flex; align-items: center; gap: 6px; min-width: 0; }
.label .role { font-size: 10px; font-weight: 700; color: var(--lane); min-width: 30px; }
.label .name { font-size: 13px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.label .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--live); box-shadow: 0 0 8px var(--live); flex: none; animation: pulse 1.4s infinite; }
.label .links { display: flex; gap: 4px; align-items: center; }
.label .links a { font-size: 10px; text-decoration: none; padding: 0 5px; border-radius: 3px; border: 1px solid var(--border); color: var(--muted); }
.label .links a.tw:hover { color: var(--pf-twitch); border-color: var(--pf-twitch); }
.label .links a.yt:hover { color: var(--pf-youtube); border-color: var(--pf-youtube); }
.label .links a.xx:hover { color: var(--text); border-color: var(--text); }
.label .coach { font-size: 9px; color: #111; background: var(--teal); border-radius: 3px; padding: 0 4px; }
.track { position: relative; flex: none; }

.seg {
  position: absolute; top: 5px; bottom: 5px; border-radius: 6px; overflow: hidden; cursor: pointer;
  background: linear-gradient(90deg, color-mix(in srgb, var(--lane) 45%, var(--panel)), color-mix(in srgb, var(--lane) 18%, var(--panel)));
  border: 1px solid color-mix(in srgb, var(--lane) 70%, transparent);
  display: flex; flex-direction: column; justify-content: center; padding: 0 6px 0 8px; min-width: 3px;
  font-size: 11px; line-height: 1.25; color: var(--text);
  transition: opacity .15s, box-shadow .15s;
}
body.light .seg { color: #111; }
.seg:hover { box-shadow: 0 0 0 2px var(--gold); z-index: 3; }
.seg::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--pf-twitch); }
.seg.yt::before { background: var(--pf-youtube); }
.seg.sim::before { background: linear-gradient(var(--pf-twitch) 50%, var(--pf-youtube) 50%); width: 4px; }
.pf-switch { display: inline-flex; gap: 4px; }
.pf-switch button { padding: 2px 8px; font-size: 11px; }
.seg .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.seg .m { white-space: nowrap; overflow: hidden; color: var(--muted); font-size: 10px; }
body.light .seg .m { color: #555; }
.seg.live { border-color: var(--live); box-shadow: 0 0 10px color-mix(in srgb, var(--live) 50%, transparent); }
.seg.live .t::before { content: "● LIVE "; color: var(--live); font-weight: 800; }
.seg.nonlol.dim { opacity: .3; filter: grayscale(.7); }
.seg.nonlol.hide { display: none; }
.seg.hit { box-shadow: 0 0 0 2px var(--scrub); }

.vline { position: absolute; top: 0; bottom: 0; width: 0; z-index: 5; pointer-events: none; }
.vline.now { border-left: 2px solid var(--live); }
.vline.scrub { border-left: 2px dashed var(--scrub); }
.axmark {
  position: absolute; bottom: 2px; transform: translateX(-50%); z-index: 2; pointer-events: none;
  font-size: 10px; font-weight: 800; padding: 1px 6px; border-radius: 4px; white-space: nowrap; color: #000;
}
.axmark.now { background: var(--live); }
.axmark.scrub { background: var(--scrub); bottom: auto; top: 2px; }

@keyframes pulse { 50% { opacity: .35; } }

/* ---------- tray ---------- */
#tray {
  position: fixed; right: 16px; bottom: 44px; width: 320px; max-height: 60vh; z-index: 20;
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--scrub);
  border-radius: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
}
#tray[hidden] { display: none; }
.tray-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 13px; }
.tray-head .x { margin-left: auto; }
#trayClock { color: var(--scrub); font-weight: 700; }
#trayList { overflow: auto; padding: 4px 6px; }
#trayList label { display: flex; gap: 8px; align-items: center; padding: 5px 4px; font-size: 12px; border-radius: 6px; cursor: pointer; }
#trayList label:hover { background: var(--panel); }
#trayList .sw { width: 6px; height: 22px; border-radius: 2px; flex: none; }
#trayList .tt { overflow: hidden; }
#trayList .tt b, #trayList .tt span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#trayList .tt span { color: var(--muted); font-size: 10px; }
#trayList .empty { color: var(--muted); font-size: 12px; padding: 10px; }
.tray-tip { font-size: 10px; color: var(--muted); padding: 2px 12px 0; }
.tray-actions { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border-top: 1px solid var(--border); }

/* ---------- footer ---------- */
footer { display: flex; gap: 16px; flex-wrap: wrap; padding: 6px 16px; border-top: 1px solid var(--border); font-size: 11px; background: var(--surface); }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .75); display: grid; place-items: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-box { width: min(1100px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.modal-head, .mv-head { display: flex; align-items: center; gap: 10px; padding: 8px 12px; font-size: 13px; }
.modal-head .x, .mv-head .x { margin-left: auto; }
.frame-wrap { aspect-ratio: 16 / 9; background: #000; position: relative; }
.frame-wrap iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.placeholder { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; color: #aaa; font-size: 13px; padding: 16px; line-height: 1.7; }
.modal-foot { display: flex; gap: 8px; padding: 8px 12px; flex-wrap: wrap; }
.modal-foot a { font-size: 12px; color: var(--gold); }
.mv { display: flex; flex-direction: column; padding: 0; place-items: stretch; background: #000; }
.mv-head { background: var(--surface); }
.mv-grid { flex: 1; display: grid; gap: 4px; padding: 4px; min-height: 0; }
.mv-cell { position: relative; background: #000; display: flex; flex-direction: column; min-height: 0; }
.mv-cell .cap { font-size: 11px; padding: 2px 6px; color: #fff; background: color-mix(in srgb, var(--lane) 50%, #000); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mv-cell .fw { position: relative; flex: 1; }
.mv-cell iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

@media (max-width: 700px) {
  :root { --label-w: 120px; --row-h: 44px; }
  .label .links { display: none; }
  #tray { left: 16px; right: 16px; width: auto; }
  footer .hint { display: none; }
}
