:root {
  --bg: #080e17; --panel: #0e1724; --line: #1f3048; --fg: #e6eef8; --muted: #8ea2bb;
  --accent: #1e9bf0; --onair: #e5484d; --good: #3ccf7a; --warn: #f2b36b;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  --nav-h: 0px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
/* the hidden attribute always wins (a section with its own display stays hidden until signed in) */
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.45 system-ui, "Segoe UI", sans-serif; }
/* nothing shows until the script has decided between the sign-in box and the desk */
body.boot main, body.boot nav { visibility: hidden; }
.top { position: sticky; top: 0; z-index: 5; }
header { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { font-weight: 700; display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand img { flex: none; border-radius: 5px; }
.brand .muted { font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lamp { width: 10px; height: 10px; border-radius: 50%; background: var(--line); flex: none; }
.lamp.on { background: var(--onair); box-shadow: 0 0 8px var(--onair); }

nav { display: flex; gap: 4px; padding: 6px 12px; background: var(--panel); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
nav::-webkit-scrollbar { display: none; }
nav button { display: flex; align-items: center; gap: 6px; background: transparent; border-color: transparent; white-space: nowrap; padding: 6px 12px; }
nav button.on { background: var(--line); border-color: var(--accent); }
nav .ic { font-size: 1rem; line-height: 1; }

main { max-width: 1100px; margin: 0 auto; padding: 16px; padding-bottom: calc(16px + var(--nav-h)); }
.grid2 { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
.view[data-view="studio"] { grid-template-rows: auto 1fr; }
.view[data-view="studio"] .playlist { grid-row: span 2; }
.view:not(.grid2) > .card + .card { margin-top: 16px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; min-width: 0; }
.narrow { max-width: 380px; margin: 40px auto; }
h1, h2 { margin: 0 0 8px; font-size: 1.15rem; }
h1 { font-size: 1.4rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.mono { font-family: var(--mono); }
.center { text-align: center; }
.error { color: var(--onair); min-height: 1.2em; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap, .wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.end { justify-content: flex-end; }
label { display: block; margin: 8px 0; color: var(--muted); }
label.inline { display: flex; margin: 4px 0; color: var(--fg); }
input, select, button, textarea { font: inherit; color: var(--fg); }
input:not([type=range]):not([type=checkbox]):not([type=radio]), select, textarea { width: 100%; padding: 8px 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; }
textarea { min-height: 5em; resize: vertical; font-family: var(--mono); font-size: 0.85rem; }
.row select, .row input:not([type=checkbox]):not([type=radio]) { width: auto; min-width: 0; }
#libSearch { flex: 2 1 220px; width: auto; }
#libFolder { flex: 1 1 160px; max-width: 100%; }
select { max-width: 100%; }
input[type=checkbox], input[type=radio] { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
button { background: var(--line); border: 1px solid var(--line); border-radius: 6px; padding: 8px 14px; cursor: pointer; touch-action: manipulation; }
button:hover { border-color: var(--accent); }
button.primary, #loginform button { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { background: #3a1518; border-color: #5a2328; }
button.ghost { background: transparent; }
button.small, .items button { padding: 4px 10px; font-size: 0.85rem; }
button:disabled { opacity: 0.5; cursor: default; }
.badge { text-transform: uppercase; font-size: 0.75rem; letter-spacing: 0.06em; padding: 2px 8px; border-radius: 4px; background: var(--line); white-space: nowrap; }
.badge.playing { background: var(--onair); color: #fff; }
.badge.paused { background: var(--warn); color: #000; }
.badge.advert { background: #3b2a55; }
.badge.jingle { background: #1d3d4f; }
.badge.off { background: transparent; border: 1px solid var(--line); color: var(--muted); }

.banner { background: #3a2c12; border: 1px solid #6b5220; color: var(--fg); border-radius: 8px; padding: 10px 14px; margin-bottom: 16px; }
.banner a { color: var(--warn); }

.title { font-size: 1.35rem; font-weight: 600; margin: 10px 0; overflow-wrap: anywhere; }
.bar { height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; }
.bar div { height: 100%; width: 0; background: var(--accent); }
.meters { display: grid; gap: 3px; margin: 10px 0; }
.meters div { height: 4px; width: 0; background: var(--good); border-radius: 2px; }
.controls { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 10px; }
.onair .controls button { min-width: 52px; font-size: 1.1rem; flex: 1 0 52px; }
.volume input { flex: 1; }

ol.rows { list-style: none; margin: 0; padding: 0; max-height: 70vh; overflow-y: auto; }
.rows li { display: flex; align-items: center; gap: 8px; padding: 5px 4px; border-bottom: 1px solid var(--line); user-select: none; }
.rows li .n { color: var(--muted); font-family: var(--mono); font-size: 0.8rem; width: 2.6em; flex: none; }
.rows li .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rows li .t small { display: block; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.rows li .d { color: var(--muted); font-family: var(--mono); font-size: 0.85rem; flex: none; }
.rows li button { padding: 3px 9px; font-size: 0.85rem; flex: none; }
.rows li.played .t { color: var(--muted); }
.rows li.current { background: rgba(229, 72, 77, 0.15); }
.rows li.current .t { font-weight: 600; }
.rows li.muted { justify-content: center; }

ul.plain { list-style: none; margin: 0; padding: 0; max-height: 300px; overflow-y: auto; }
ul.plain.tall { max-height: 65vh; }
ul.plain.items { max-height: none; }
ul.plain li { padding: 4px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
ul.plain li.err { color: var(--onair); }
.items li { display: flex; align-items: center; gap: 8px; padding: 8px 0; }
.items li .grow { flex: 1; min-width: 0; }
.items li .grow small { display: block; color: var(--muted); }
#encoders li { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.live { color: var(--good); }

.carts { display: grid; gap: 8px; grid-template-columns: repeat(6, minmax(0, 1fr)); }
.carts button { aspect-ratio: 4 / 3; padding: 6px; display: flex; flex-direction: column; justify-content: space-between; align-items: flex-start; text-align: left; overflow: hidden; background: #13233a; border-color: #23395a; }
.carts button .k { color: var(--muted); font-size: 0.75rem; font-family: var(--mono); }
.carts button .l { font-weight: 600; overflow-wrap: anywhere; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.carts button.empty { background: transparent; border-style: dashed; color: var(--muted); }
.carts button.playing { background: var(--onair); border-color: var(--onair); color: #fff; }
.carts button.playing .k { color: #fff; }
.carts.editing button { border-color: var(--warn); }
#cartEdit[aria-pressed="true"] { background: var(--warn); border-color: var(--warn); color: #000; }

dialog { background: var(--panel); color: var(--fg); border: 1px solid var(--line); border-radius: 12px; padding: 16px; width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); }
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog form { display: flex; flex-direction: column; max-height: calc(100dvh - 60px); }
#dlgBody { overflow-y: auto; flex: 1; min-height: 0; padding-right: 2px; }
dialog .row.end { margin-top: 12px; }
.sub { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 8px 0; }
.sub > .row { margin: 4px 0; }
.sub .row input[type=number] { width: 5.5em; }
.days { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.pick { max-height: 220px; overflow-y: auto; border: 1px solid var(--line); border-radius: 6px; margin-top: 6px; }
.pick div { padding: 6px 8px; border-bottom: 1px solid var(--line); cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick div:hover, .pick div:focus { background: var(--line); outline: none; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }

#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(16px + var(--nav-h)); z-index: 20; background: var(--line); border: 1px solid var(--accent); border-radius: 8px; padding: 10px 16px; max-width: calc(100vw - 32px); box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5); }
#toast.err { border-color: var(--onair); }

@media (max-width: 860px) {
  .carts { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
/* phones: one column, the sections in a bar along the bottom within thumb reach */
@media (max-width: 760px) {
  :root { --nav-h: calc(58px + env(safe-area-inset-bottom)); }
  body { font-size: 16px; }
  header { padding: 8px 12px; }
  main { padding: 12px; padding-bottom: calc(12px + var(--nav-h)); }
  .grid2 { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .view[data-view="studio"] { grid-template-rows: none; }
  .view[data-view="studio"] .playlist { grid-row: auto; }
  .card { padding: 12px; }
  nav { position: fixed; z-index: 5; bottom: 0; left: 0; right: 0; border-top: 1px solid var(--line); border-bottom: 0; padding: 4px 4px env(safe-area-inset-bottom); gap: 0; height: var(--nav-h); }
  nav button { flex: 1 0 54px; flex-direction: column; gap: 2px; padding: 6px 1px; font-size: 0.66rem; border-radius: 8px; }
  nav .ic { font-size: 1.25rem; }
  .rows li { padding: 8px 4px; }
  .rows li button { padding: 6px 11px; }
  ol.rows { max-height: none; }
  .title { font-size: 1.2rem; }
  .carts { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .narrow { margin: 16px auto; }
}
.card > button, .card form > button { margin-top: 8px; }
