:root {
  --bg: #0a0c0f;
  --panel: #13171c;
  --panel-2: #1a1f26;
  --line: #262d36;
  --text: #e8ebee;
  --dim: #7f8994;
  --faint: #4a525c;
  --amber: #ffb020;
  --red: #ff3b30;
  --green: #32d15a;
  --blue: #3d8bff;
  --violet: #bf6bff;
  --teal: #3ccbe0;
  --mono: "Consolas", "Menlo", "DejaVu Sans Mono", monospace;
  --sans: "Segoe UI", "Yu Gothic UI", "Meiryo", "Hiragino Sans", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  overflow: hidden;
}
h2 { margin: 0; font-size: 12px; letter-spacing: .12em; color: var(--dim); font-weight: 600; }
.num, .clock, .countdown, .c-time, .c-state, .np-times, .block-meta, .after, #queue { font-variant-numeric: tabular-nums; }

/* ---------- header */
.top {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  align-items: center;
  gap: 24px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
  background: #0d1014;
}
.station-name { font-weight: 700; font-size: 18px; letter-spacing: .04em; }
.station-date { color: var(--dim); font-family: var(--mono); font-size: 14px; }
.mode {
  display: flex; align-items: baseline; gap: 10px;
  padding: 6px 18px; border-radius: 6px;
  border: 2px solid var(--faint); color: var(--dim);
  min-width: 200px;
}
.mode-label { font-family: var(--mono); font-weight: 700; font-size: 26px; letter-spacing: .08em; }
.mode-sub { font-size: 13px; max-width: 280px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mode[data-mode="live"] { border-color: var(--red); background: var(--red); color: #fff; animation: pulse 2s ease-in-out infinite; }
.mode[data-mode="pgm"] { border-color: var(--blue); color: var(--blue); }
.mode[data-mode="auto"] { border-color: var(--green); color: var(--green); }
.mode[data-mode="manual"] { border-color: var(--amber); color: var(--amber); }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(255, 59, 48, .25); } }

.lamps { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.lamp {
  font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 4px;
  border: 1px solid var(--line); color: var(--faint); background: var(--panel);
}
.lamp.on { color: #07210f; background: var(--green); border-color: var(--green); }
.lamp.err { color: #fff; background: var(--red); border-color: var(--red); }
.clock { font-family: var(--mono); font-size: 52px; font-weight: 700; line-height: 1; letter-spacing: .02em; }

.top { grid-row: 1; }
.alert { grid-row: 2; }
.grid { grid-row: 3; }
.timeline { grid-row: 4; }
.alert { background: #3a0f0c; color: #ffb4ad; padding: 6px 20px; font-size: 13px; border-bottom: 1px solid #5a1a15; }

/* ---------- main grid */
.grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(360px, 1fr);
  gap: 12px;
  padding: 12px;
  min-height: 0;
}
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; min-height: 0; }
.panel-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.side { display: grid; grid-template-rows: auto auto auto minmax(0, 1fr); gap: 12px; min-height: 0; }
.grid > *, .side > * { min-width: 0; }

/* ---------- rundown */
.rundown { display: flex; flex-direction: column; }
.rundown-date { font-family: var(--mono); font-size: 16px; font-weight: 700; }
.rundown-date.other { color: var(--amber); }
.nav { margin-left: auto; display: flex; gap: 4px; }
.nav button {
  white-space: nowrap;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 4px; padding: 4px 12px; font: inherit; font-size: 13px; cursor: pointer;
}
.nav button:hover { border-color: var(--dim); }
.table-wrap { overflow-y: auto; flex: 1; min-height: 0; scrollbar-color: var(--faint) transparent; }
table { width: 100%; border-collapse: collapse; }
thead th, thead th.c-time {
  position: sticky; top: 0; z-index: 1; background: var(--panel);
  text-align: left; font-size: 11px; color: var(--dim); font-weight: 600;
  padding: 6px 8px; border-bottom: 1px solid var(--line);
}
td { padding: 9px 8px; border-bottom: 1px solid #1c2229; vertical-align: top; }
.c-time { font-family: var(--mono); font-size: 18px; font-weight: 700; white-space: nowrap; width: 1%; }
.c-kind { width: 1%; }
.c-state { font-family: var(--mono); text-align: right; white-space: nowrap; width: 1%; color: var(--dim); }
td.c-state { font-size: 15px; }
.ev-name { font-weight: 600; font-size: 16px; }
.ev-rec { color: var(--dim); font-size: 12px; margin-top: 2px; }
.acts { display: flex; flex-wrap: wrap; gap: 4px; }
.act { font-size: 11px; padding: 2px 6px; border-radius: 3px; background: var(--panel-2); color: #b9c1c9; border: 1px solid var(--line); white-space: nowrap; }

tr.past td { opacity: .38; }
tr.past .c-state { color: var(--dim); }
tr.next { background: rgba(255, 176, 32, .10); }
tr.next td:first-child { box-shadow: inset 4px 0 0 var(--amber); }
tr.next .c-time, tr.next .c-state { color: var(--amber); }
tr.next td.c-state { font-size: 20px; font-weight: 700; }
tr.in-live td:nth-child(2) { box-shadow: inset 3px 0 0 rgba(255, 59, 48, .55); }
tr.day-sep td {
  padding: 6px 8px; font-family: var(--mono); font-size: 13px; font-weight: 700;
  color: var(--dim); background: var(--panel-2); border-bottom: 1px solid var(--line);
}
tr.now-line td { padding: 0; border: 0; }
tr.now-line .line {
  display: flex; align-items: center; gap: 8px;
  color: var(--red); font-family: var(--mono); font-size: 12px; font-weight: 700;
  padding: 3px 0;
}
tr.now-line .line::after { content: ""; flex: 1; height: 2px; background: var(--red); }
.empty { color: var(--dim); text-align: center; padding: 40px 0; }

.kind-chip {
  display: inline-block; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 3px;
  white-space: nowrap; color: #0a0c0f; background: var(--dim);
}
.kind-chip:empty { display: none; }
.k-LIVE_IN, .k-LIVE_OUT { background: var(--red); color: #fff; }
.k-LIVE_OUT { background: transparent; color: var(--red); box-shadow: inset 0 0 0 1.5px var(--red); }
.k-PGM { background: var(--blue); color: #fff; }
.k-CM { background: var(--violet); color: #fff; }
.k-INSERT { background: var(--teal); }
.k-TALLY_ON, .k-TALLY_OFF { background: transparent; color: var(--amber); box-shadow: inset 0 0 0 1.5px var(--amber); }

/* ---------- next */
.countdown { font-family: var(--mono); font-size: 72px; font-weight: 700; line-height: 1; color: var(--amber); letter-spacing: .02em; }
.countdown.soon { color: var(--red); }
.next-name { margin-top: 8px; font-size: 20px; font-weight: 700; display: flex; gap: 12px; align-items: baseline; }
.next-at { font-family: var(--mono); color: var(--dim); font-size: 16px; }
.after { list-style: none; margin: 10px 0 0; padding: 8px 0 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: auto auto minmax(0, 1fr) auto; gap: 4px 12px; }
.after li { grid-column: 1 / -1; display: grid; grid-template-columns: subgrid; align-items: center; font-size: 13px; }
.after .kind-chip { justify-self: start; }
.after .t { font-family: var(--mono); color: var(--dim); }
.after .r { font-family: var(--mono); color: var(--dim); }
.after .n { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- block */
.block-name { font-size: 22px; font-weight: 700; }
.block.live { border-color: rgba(255, 59, 48, .6); background: #2a1416; }
.block.live .block-name { color: var(--red); }
.block.running .bar-fill { background: #f2f2f2; }
.block.running .block-left { color: #fff; }
.block.soon .bar-fill { background: #ff453a; }
.block.soon .block-left { color: #ff6961; }
.block-meta { display: flex; justify-content: space-between; font-family: var(--mono); color: var(--dim); font-size: 13px; }
.block-left { font-size: 22px; font-weight: 700; color: var(--text); }

/* ---------- now playing */
.bar { height: 6px; background: var(--panel-2); border-radius: 3px; margin: 10px 0 6px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--green); transition: width .2s linear; }
.np-title { font-size: 24px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np-artist { color: var(--dim); font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 1.3em; }
.np-times { display: flex; justify-content: space-between; align-items: baseline; font-family: var(--mono); color: var(--dim); }
.np-remain { font-size: 34px; font-weight: 700; color: var(--text); }
.type-chip { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 3px; background: var(--panel-2); color: var(--dim); border: 1px solid var(--line); }
.type-chip:empty { display: none; }

/* ---------- queue */
.queue { overflow: hidden; display: flex; flex-direction: column; }
#queue { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
#queue li { display: grid; grid-template-columns: 5.2em 1fr auto; gap: 10px; padding: 6px 0; border-bottom: 1px solid #1c2229; align-items: baseline; }
#queue .t { font-family: var(--mono); color: var(--dim); }
#queue .n { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#queue .a { color: var(--dim); }
#queue .d { font-family: var(--mono); color: var(--dim); font-size: 13px; }
#queue .empty-q { color: var(--faint); display: block; }

/* ---------- timeline */
.timeline { padding: 0 12px 10px; }
.tl-track { position: relative; height: 26px; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.tl-block { position: absolute; top: 3px; bottom: 3px; border-radius: 3px; font-size: 11px; font-weight: 700; color: #fff; padding: 2px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tl-block.LIVE { background: rgba(255, 59, 48, .75); }
.tl-block.PGM { background: rgba(61, 139, 255, .75); }
.tl-mark { position: absolute; top: 0; bottom: 0; width: 2px; opacity: .8; }
.tl-mark.CM { background: var(--violet); }
.tl-mark.INSERT { background: var(--teal); }
.tl-mark.TALLY_ON, .tl-mark.TALLY_OFF { background: var(--amber); }
.tl-mark.OTHER { background: var(--dim); }
.tl-now { position: absolute; top: -2px; bottom: -2px; width: 2px; background: #fff; box-shadow: 0 0 6px #fff; z-index: 2; }
.tl-hours { position: relative; height: 14px; font-family: var(--mono); font-size: 10px; color: var(--faint); }
.tl-hours span { position: absolute; transform: translateX(-50%); }
.tl-hours span.midnight { color: var(--dim); font-weight: 700; }

/* ---------- narrow screens */
@media (max-width: 1000px) {
  body { overflow-x: hidden; overflow-y: auto; display: block; }
  .top { grid-template-columns: 1fr auto; gap: 10px; padding: 10px 16px; }
  .station { grid-column: 1; grid-row: 1; }
  .clock { grid-column: 2; grid-row: 1; font-size: 34px; }
  .mode { grid-column: 1 / -1; grid-row: 2; min-width: 0; }
  .lamps { grid-column: 1 / -1; grid-row: 3; justify-content: flex-start; }
  .grid { grid-template-columns: minmax(0, 1fr); padding: 12px 16px; }
  .table-wrap { max-height: 60vh; }
  th:nth-child(4), td:nth-child(4) { display: none; }
  .c-time { font-size: 15px; }
  .ev-name { font-size: 14px; }
  td { padding: 8px 4px; }
  td.c-state { font-size: 13px; }
  tr.next td.c-state { font-size: 15px; }
  .panel-head { flex-wrap: wrap; }
  .countdown { font-size: 52px; }
  .block-meta { flex-wrap: wrap; gap: 4px 12px; }
  .after { grid-template-columns: auto auto minmax(0, 1fr); }
  .after .r { display: none; }
  .timeline { padding: 0 16px 12px; }
}
