:root {
  --bg: #14161a; --bg2: #1c1f25; --bg3: #262a32; --line: #333842; --fg: #e3e6eb;
  --mut: #8b93a1; --acc: #4fc3f7; --on: #ffd54f; --rec: #ef5350; --ok: #81c784;
  --warn: #ffb74d; --r: 10px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font: 14px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent; }
button, select, input { font: inherit; color: inherit; }
button { background: var(--bg3); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 12px; cursor: pointer; touch-action: manipulation; }
button:active { filter: brightness(1.3); }
select, input[type=search], input[type=text], input[type=password], input[type=number] {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; }
input[type=range] { accent-color: var(--acc); }
input[type=checkbox] { accent-color: var(--acc); width: 20px; height: 20px; }
.muted { color: var(--mut); }
.small { font-size: 12px; }

body { display: flex; flex-direction: column; overflow: hidden; }

/* header */
#top { display: flex; align-items: center; gap: 8px; padding: 6px 10px;
  padding-top: max(6px, env(safe-area-inset-top)); background: var(--bg2);
  border-bottom: 1px solid var(--line); flex: none; min-height: 46px; }
.brand { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.chip { padding: 3px 9px; border-radius: 99px; font-size: 12px; white-space: nowrap; }
.chip.on { border-color: #2e7d32; color: var(--ok); }
.chip.sleep, .chip.off { color: var(--mut); }
.chip.desktop, .chip.starting { border-color: #8d6e00; color: var(--warn); }
.chip.error { border-color: #b71c1c; color: #ff8a80; }
.onair { flex: 1; min-width: 0; color: var(--on); font-weight: 600; font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.listen { font-weight: 600; }
.listen.on { background: #0d47a1; border-color: var(--acc); }

/* waterfall */
#wfwrap { position: relative; flex: none; height: 46vh; min-height: 230px; background: #000;
  touch-action: none; user-select: none; -webkit-user-select: none; }
#spec, #wf, #ov { position: absolute; left: 0; width: 100%; display: block; }
#spec { top: 0; }
#ov { top: 0; height: 100%; cursor: crosshair; }
.wftools { position: absolute; right: 6px; bottom: 6px; display: flex; gap: 6px; }
.wftools button { background: rgba(20,22,26,.8); min-width: 38px; padding: 6px 10px; }
.wfmsg { position: absolute; left: 50%; top: 55%; transform: translate(-50%, -50%);
  background: rgba(20,22,26,.9); border: 1px solid var(--line); border-radius: var(--r);
  padding: 12px 16px; text-align: center; max-width: 90%; }

/* tabs + panels */
#tabs { display: flex; background: var(--bg2); border-bottom: 1px solid var(--line); flex: none; }
#tabs button { flex: 1; border: 0; border-radius: 0; background: none; padding: 10px 4px;
  color: var(--mut); border-bottom: 2px solid transparent; }
#tabs button.on { color: var(--fg); border-bottom-color: var(--acc); }
#tabs span { font-size: 12px; color: var(--mut); }
#panels { flex: 1; min-height: 0; position: relative; }
.panel { display: none; position: absolute; inset: 0; overflow-y: auto;
  padding: 8px 8px calc(16px + var(--safe-b)); -webkit-overflow-scrolling: touch; }
.panel.on { display: block; }
.dh { display: none; }
.ptools { display: flex; gap: 6px; margin-bottom: 6px; flex-wrap: wrap; }
.ptools input[type=search] { flex: 1; min-width: 120px; }
.ptools.bulk button { padding: 5px 9px; font-size: 13px; }

/* channel rows */
.list { display: flex; flex-direction: column; gap: 4px; }
.ch { display: grid; grid-template-columns: 5px 1fr auto; gap: 4px 8px; align-items: center;
  background: var(--bg2); border: 1px solid var(--line); border-radius: var(--r); padding: 6px 8px 6px 0; }
.ch .bar { grid-row: 1 / span 2; align-self: stretch; border-radius: 3px 0 0 3px; }
.ch .nm { min-width: 0; cursor: pointer; }
.ch .nm b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.ch .nm small { color: var(--mut); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.ch .sig { width: 86px; text-align: right; font-size: 12px; color: var(--mut); }
.ch .meter { height: 5px; background: var(--bg3); border-radius: 3px; overflow: hidden; margin-top: 3px; }
.ch .meter i { display: block; height: 100%; width: 0; background: var(--acc); transition: width .3s; }
.ch .tg { grid-column: 2 / span 2; display: flex; gap: 5px; }
.ch .tg button { flex: 1; padding: 5px 0; font-size: 12px; color: var(--mut); }
.ch .tg button.on { color: #fff; }
.ch .tg .b-en.on { background: #1b5e20; border-color: #2e7d32; }
.ch .tg .b-mu.on { background: #4e342e; border-color: #795548; }
.ch .tg .b-so.on { background: #0d47a1; border-color: #1976d2; }
.ch .tg .b-re.on { background: #b71c1c; border-color: var(--rec); }
.ch.active { border-color: var(--on); box-shadow: 0 0 0 1px var(--on) inset; }
.ch.active .sig { color: var(--on); font-weight: 600; }
.ch.active .meter i { background: var(--on); }
.ch.off .nm b { color: var(--mut); }
.ch.nocover .nm small::after { content: " · outside tuners"; color: #f48fb1; }

/* activity */
.act { display: grid; grid-template-columns: auto 1fr auto; gap: 2px 10px; align-items: center;
  background: var(--bg2); border: 1px solid var(--line); border-radius: var(--r); padding: 7px 10px; }
.act .t { color: var(--mut); font-variant-numeric: tabular-nums; font-size: 12px; }
.act .n { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.act .n small { color: var(--mut); }
.act .d { font-size: 12px; color: var(--mut); text-align: right; }
.act button { padding: 4px 10px; }
.act.hasrec { grid-template-columns: auto 1fr auto auto; }
#player { width: 100%; margin-top: 8px; }

/* settings */
.group { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--r);
  padding: 8px 12px 12px; margin-bottom: 8px; }
.group h3 { margin: 4px 0 8px; font-size: 13px; color: var(--mut); text-transform: uppercase; letter-spacing: .04em; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 6px 0; flex-wrap: wrap; }
.row input[type=range] { flex: 1 1 160px; max-width: 260px; }
.row output { color: var(--mut); font-size: 12px; margin-right: auto; }
.tuners { font-size: 12px; color: var(--mut); margin-bottom: 8px; }
.tuners div { padding: 2px 0; }
.tuners .err { color: #ff8a80; }
.danger { border-color: #b71c1c; color: #ff8a80; }

/* bottom sheet */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 10; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 11; background: var(--bg2);
  border-top: 1px solid var(--line); border-radius: 16px 16px 0 0;
  padding: 12px 14px calc(14px + var(--safe-b)); max-height: 85vh; overflow-y: auto;
  box-shadow: 0 -8px 30px rgba(0,0,0,.5); }
.sheet h2 { margin: 0 0 2px; font-size: 18px; }
.sheet .sub { color: var(--mut); margin-bottom: 10px; }
.sheet .tg { display: flex; gap: 6px; margin: 8px 0; }
.sheet .tg button { flex: 1; }
.sheet .tg button.on { color: #fff; background: #0d47a1; border-color: #1976d2; }
.sheet .tg .b-re.on { background: #b71c1c; border-color: var(--rec); }
.sheet .acts { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }
.sheet .acts button { flex: 1; padding: 10px; }
.sheet .acts .primary { background: #0d47a1; border-color: var(--acc); font-weight: 600; }
.sheet label.row input[type=text] { flex: 1; min-width: 0; }

/* desktop: waterfall on top, three columns below */
@media (min-width: 1000px) {
  #wfwrap { height: 56vh; }
  #tabs { display: none; }
  #panels { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) 320px; gap: 0; }
  .panel { display: block; position: static; border-right: 1px solid var(--line); }
  .dh { display: block; font-size: 13px; color: var(--mut); text-transform: uppercase;
    letter-spacing: .04em; margin: 2px 0 8px; }
  .sheet { left: 50%; right: auto; bottom: auto; top: 50%; transform: translate(-50%, -50%);
    width: 440px; border-radius: 16px; border: 1px solid var(--line); }
}

/* login */
body.login { align-items: center; justify-content: center; }
.login-box { display: flex; flex-direction: column; gap: 10px; width: min(320px, 90vw);
  text-align: center; align-items: stretch; }
.login-box img { align-self: center; }
.login-box h1 { margin: 0; font-size: 22px; }
.login-box .sub { margin: 0 0 8px; color: var(--mut); }
.login-box input { padding: 11px; font-size: 16px; }
.login-box button { padding: 11px; font-size: 16px; background: #0d47a1; border-color: var(--acc); }
.msg { color: #ff8a80; margin: 4px 0 0; }
