:root {
  --bg: #0b0f17;
  --bg-elev: #131a26;
  --card: #161f2e;
  --border: #25303f;
  --text: #e6edf6;
  --muted: #93a1b5;
  --accent: #4f8cff;
  --accent-2: #6ee7b7;
  --danger: #ff5470;
  --live: #ff3b5c;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(1200px 600px at 70% -10%, #1a2436 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
}

a { color: var(--accent); }

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo { font-size: 38px; line-height: 1; }
.brand h1 { font-size: 20px; margin: 0; letter-spacing: .2px; }
.brand .sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.status-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 999px;
  background: var(--bg-elev); border: 1px solid var(--border);
  font-size: 13px; font-weight: 600; color: var(--muted);
}
.status-pill .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.status-pill[data-live="true"] { color: #fff; border-color: var(--live); background: rgba(255,59,92,.12); }
.status-pill[data-live="true"] .dot { background: var(--live); box-shadow: 0 0 0 0 rgba(255,59,92,.6); animation: pulse 1.6s infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255,59,92,.55); }
  70% { box-shadow: 0 0 0 9px rgba(255,59,92,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,59,92,0); }
}

/* Grid + cards */
.grid {
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  gap: 18px;
}
.card {
  background: linear-gradient(180deg, var(--card), #131b29);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.grid > .card:first-child { align-self: start; }
.card-head { margin-bottom: 16px; }
.card-head h2 { margin: 0 0 4px; font-size: 16px; }
.hint { margin: 0; color: var(--muted); font-size: 12.5px; line-height: 1.45; }

/* Source actions */
.source-actions { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.device-picker { display: flex; gap: 8px; }
.device-picker select { flex: 1; }

select, input[type="text"], input[type="password"] {
  width: 100%;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  outline: none;
}
select:focus, input:focus { border-color: var(--accent); }

/* Buttons */
.btn {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .05s ease, background .15s ease, border-color .15s ease;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #3d7bf0; }
.btn.primary.is-live { background: var(--danger); border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.big { width: 100%; padding: 14px; font-size: 15px; margin-top: 4px; }
.btn.tiny { padding: 6px 10px; font-size: 12px; }
.btn.block { display: block; text-align: center; text-decoration: none; margin-top: 14px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Source list */
.source-list { list-style: none; margin: 0 0 16px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.source-list .empty { color: var(--muted); font-size: 13px; padding: 14px; text-align: center; border: 1px dashed var(--border); border-radius: 10px; }
.source-item {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 10px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
.source-item .kind { font-size: 18px; }
.source-item .name { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-item .name small { display: block; color: var(--muted); font-weight: 400; font-size: 11px; }
.source-item input[type="range"] { width: 90px; }
.source-item.muted { opacity: .55; }
.icon-btn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 16px; padding: 4px; }
.icon-btn:hover { color: var(--text); }
.icon-btn.active { color: var(--accent-2); }

/* Meter */
.meter-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.meter-label { font-size: 12px; color: var(--muted); width: 84px; }
.meter { flex: 1; height: 10px; background: var(--bg-elev); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.meter-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent-2), #f6c453 70%, var(--danger)); transition: width .06s linear; }
.meter-db { font-size: 11px; color: var(--muted); width: 52px; text-align: right; font-variant-numeric: tabular-nums; }
.master-vol { display: flex; align-items: center; gap: 12px; }
.master-vol label { font-size: 12px; color: var(--muted); white-space: nowrap; }
.master-vol input { flex: 1; }

input[type="range"] { accent-color: var(--accent); }

/* Fields */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.field .opt { color: #6b7787; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.conn-state { margin: 10px 0 0; font-size: 12.5px; color: var(--muted); text-align: center; }
.warn { margin-top: 14px; font-size: 12px; line-height: 1.5; color: #ffd9a0; background: rgba(255,170,60,.08); border: 1px solid rgba(255,170,60,.25); padding: 10px 12px; border-radius: 10px; }
.warn code { background: rgba(0,0,0,.3); padding: 1px 5px; border-radius: 5px; }

/* Address */
.addr { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.addr-label { font-size: 12px; color: var(--muted); width: 120px; flex-shrink: 0; }
.addr code { flex: 1; background: var(--bg-elev); border: 1px solid var(--border); padding: 8px 10px; border-radius: 8px; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.stats { display: flex; gap: 12px; margin: 16px 0 4px; }
.stat { flex: 1; background: var(--bg-elev); border: 1px solid var(--border); border-radius: 10px; padding: 12px; text-align: center; }
.stat-num { display: block; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-lbl { font-size: 11px; color: var(--muted); }

.foot { margin-top: 26px; text-align: center; color: var(--muted); font-size: 12px; }

/* Toast */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: #1f2937; border: 1px solid var(--border); color: var(--text);
  padding: 12px 18px; border-radius: 10px; box-shadow: var(--shadow);
  font-size: 13.5px; z-index: 50; max-width: 90vw;
}

/* Studio: right column wrapper */
.col { display: flex; flex-direction: column; gap: 18px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }

/* Always-visible listening bar */
.listenbar {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 14px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 16px; margin-bottom: 18px;
}
.lb-stats { display: flex; gap: 10px; }
.lb-stat {
  display: flex; flex-direction: column; align-items: center;
  min-width: 86px; padding: 6px 16px;
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
}
.lb-num { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.15; }
.lb-lbl { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; margin-top: 2px; }
.lb-addrs { display: flex; gap: 14px; flex: 1; min-width: 260px; flex-wrap: wrap; justify-content: flex-end; }
.lb-addr { display: flex; align-items: center; gap: 8px; }
.lb-tag { font-size: 12px; color: var(--muted); white-space: nowrap; }
.lb-addr code {
  background: var(--card); border: 1px solid var(--border);
  padding: 6px 9px; border-radius: 8px; font-size: 12px;
  max-width: 230px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* In the app the listening bar is moved into its own "Infos" tab (frees the top of the screen). */
.inapp #infoHost .listenbar { margin-bottom: 0; }
.inapp #infoHost .lb-addrs { justify-content: flex-start; }

/* Live-broadcast tuning group (Studio) */
.live-tune {
  margin-top: 16px; padding: 14px 14px 4px;
  border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 10px; background: rgba(79,140,255,.05);
}
.lt-title { font-size: 13px; font-weight: 700; color: var(--text); margin-bottom: 10px; }

/* Live button mode picker (toggle vs push-to-talk) */
.live-mode { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.lm-opt { display: flex; align-items: flex-start; gap: 8px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg-elev); cursor: pointer; font-size: 13px; font-weight: 600; }
.lm-opt:hover { border-color: var(--accent); }
.lm-opt input { margin-top: 2px; accent-color: var(--accent); flex-shrink: 0; }
.lm-opt span { display: flex; flex-direction: column; gap: 2px; }
.lm-opt small { font-weight: 400; color: var(--muted); font-size: 11.5px; line-height: 1.3; }
.lm-opt:has(input:checked) { border-color: var(--accent); background: rgba(79,140,255,.08); }

/* Tabs */
.tabs { display: flex; gap: 6px; margin-bottom: 18px; border-bottom: 1px solid var(--border); }
.tab { background: none; border: none; color: var(--muted); font-size: 14px; font-weight: 600; padding: 12px 16px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; display: inline-flex; align-items: center; gap: 8px; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-badge { background: var(--bg-elev); border: 1px solid var(--border); color: var(--muted); border-radius: 999px; font-size: 11px; font-weight: 700; padding: 1px 8px; min-width: 20px; text-align: center; }
.tabpanel[hidden] { display: none; }

/* Library header with search */
.lib-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.lib-search { flex: 1; min-width: 200px; max-width: 360px; }
.lib-search input { width: 100%; }
input[type="search"] { width: 100%; background: var(--bg-elev); border: 1px solid var(--border); color: var(--text); padding: 10px 12px; border-radius: 10px; font-size: 14px; outline: none; }
input[type="search"]:focus { border-color: var(--accent); }
.playlist.tall { max-height: 60vh; }

/* On-air pill modes */
.status-pill[data-mode="music"] { color: #fff; border-color: var(--accent); background: rgba(79,140,255,.12); }
.status-pill[data-mode="music"] .dot { background: var(--accent); }
.status-pill[data-mode="live"] { color: #fff; border-color: var(--live); background: rgba(255,59,92,.12); }
.status-pill[data-mode="live"] .dot { background: var(--live); box-shadow: 0 0 0 0 rgba(255,59,92,.6); animation: pulse 1.6s infinite; }
.status-pill[data-mode="silence"] { color: var(--muted); }

/* Now-air card */
.now-air { background: var(--bg-elev); border: 1px solid var(--border); border-radius: 12px; padding: 16px 16px 12px; }
.na-main { display: flex; align-items: center; gap: 14px; }
.na-cover { width: 64px; height: 64px; border-radius: 8px; object-fit: cover; border: 1px solid var(--border); flex-shrink: 0; background: var(--card); }
.na-info { flex: 1; min-width: 0; }
.na-next { margin-top: 10px; font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history { margin-top: 16px; }
.hist-title { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; margin-bottom: 6px; }
.hist-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.hist-list li { font-size: 12.5px; color: var(--text); opacity: .8; padding: 4px 8px; background: var(--bg-elev); border: 1px solid var(--border); border-radius: 7px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.na-title { font-size: 17px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.na-bar { height: 6px; background: #0e1622; border-radius: 6px; margin: 12px 0 6px; overflow: hidden; }
.na-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 6px; transition: width .25s linear; }
.na-fill.live { background: linear-gradient(90deg, var(--live), #ff8aa0); animation: livebar 1.6s ease-in-out infinite; }
@keyframes livebar { 0%,100% { opacity: .65; } 50% { opacity: 1; } }
.na-time { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

/* Transport */
.transport { display: flex; align-items: center; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.t-btn { width: 46px; height: 46px; border-radius: 50%; border: 1px solid var(--border); background: var(--bg-elev); color: var(--text); font-size: 18px; cursor: pointer; display: grid; place-items: center; transition: background .15s, border-color .15s, transform .05s; }
.t-btn:hover:not(:disabled) { border-color: var(--accent); }
.t-btn:active:not(:disabled) { transform: scale(.95); }
.t-btn:disabled { opacity: .4; cursor: not-allowed; }
.t-btn.play { width: 56px; height: 56px; font-size: 22px; background: var(--accent); border-color: var(--accent); color: #fff; }
.t-btn.play:hover:not(:disabled) { background: #3d7bf0; }
.t-toggles { display: flex; gap: 8px; margin-left: auto; }
.chip { background: var(--bg-elev); border: 1px solid var(--border); color: var(--muted); padding: 8px 12px; border-radius: 999px; font-size: 12.5px; font-weight: 600; cursor: pointer; transition: all .15s; }
.chip:hover { border-color: var(--accent); }
.chip.active { background: rgba(110,231,183,.12); border-color: var(--accent-2); color: var(--accent-2); }

/* Drop zone */
.drop { border: 2px dashed var(--border); border-radius: 12px; padding: 22px; text-align: center; cursor: pointer; transition: border-color .15s, background .15s; margin-bottom: 12px; }
.drop:hover, .drop.hover { border-color: var(--accent); background: rgba(79,140,255,.06); }
.drop-inner { display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.drop-ico { font-size: 30px; }
.drop-inner small { font-size: 12px; }

/* Upload progress rows */
.uploads { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.up-row { display: grid; grid-template-columns: 1fr 120px auto; align-items: center; gap: 10px; font-size: 12.5px; }
.up-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.up-bar { height: 6px; background: var(--bg-elev); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.up-fill { height: 100%; width: 0%; background: var(--accent); transition: width .15s; }
.up-row.done .up-fill { background: var(--accent-2); }
.up-row.err .up-pct { color: var(--danger); }
.up-pct { width: 34px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Playlist */
.playlist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 380px; overflow: auto; }
.playlist .empty { color: var(--muted); font-size: 13px; padding: 18px; text-align: center; border: 1px dashed var(--border); border-radius: 10px; }
.playlist-item { display: grid; grid-template-columns: auto 1fr auto auto auto; align-items: center; gap: 10px; background: var(--bg-elev); border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; cursor: grab; }
.pl-move { display: flex; flex-direction: column; gap: 0; }
.pl-move .icon-btn { font-size: 9px; line-height: 1; padding: 1px 4px; }
.pl-move .icon-btn:disabled { opacity: .25; cursor: default; }
.lib-actions { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.lib-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 4px 0 12px; }
.lib-toolbar-lbl { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.lib-toolbar-hint { font-size: 11.5px; color: var(--muted); margin-left: auto; }
.playlist-item.current { border-color: var(--accent); background: rgba(79, 140, 255, .10); }
.playlist-item.is-jingle { border-left: 3px solid var(--accent-2); }
.playlist-item.dragging { opacity: .4; }
.playlist-item.over { border-color: var(--accent-2); border-style: dashed; }
.pl-idx { width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; text-align: center; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.pl-thumb { width: 34px; height: 34px; border-radius: 6px; object-fit: cover; border: 1px solid var(--border); }
.pl-actions { display: flex; align-items: center; gap: 2px; }
.playlist-item.current .pl-idx { color: var(--accent-2); }
.pl-name { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.pl-dur { color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.pl-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; color: var(--muted); font-size: 12.5px; }

/* PC broadcaster generator */
.check { display: flex; align-items: center; gap: 9px; font-size: 13px; color: var(--muted); margin: 0 0 14px; cursor: pointer; line-height: 1.4; }
.check input[type="checkbox"] { width: auto; flex-shrink: 0; accent-color: var(--accent); }
.check code, .howto code { background: rgba(0,0,0,.3); padding: 1px 5px; border-radius: 5px; }
.cmd-preview { background: #0e1622; border: 1px solid var(--border); border-radius: 10px; padding: 12px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; color: var(--accent-2); white-space: pre-wrap; word-break: break-all; margin: 0; max-height: 150px; overflow: auto; }
.gen-downloads { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.gen-downloads .btn small { font-weight: 400; color: var(--muted); }
.gen-downloads .btn.primary small { color: rgba(255,255,255,.8); }
.howto { margin: 0; padding-left: 20px; color: var(--muted); font-size: 13px; line-height: 1.7; }

/* Now-playing (listener page) */
.now-playing { color: var(--accent-2); font-size: 14px; margin: 4px 0 0; min-height: 18px; font-weight: 600; }

@media (max-width: 820px) {
  .grid { grid-template-columns: 1fr; }
  .card:first-child { grid-row: auto; }
  .t-toggles { margin-left: 0; width: 100%; }
}

/* Phones: stack the header so the title keeps one line, let the tabs scroll. */
@media (max-width: 640px) {
  .topbar { flex-direction: column; align-items: stretch; gap: 12px; }
  .topbar-right { width: 100%; flex-wrap: wrap; }
  .brand { align-items: flex-start; }
  .brand h1 { font-size: 18px; }
  .brand .sub { font-size: 12px; }

  .tabs { gap: 2px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { padding: 11px 12px; font-size: 13px; white-space: nowrap; flex: 0 0 auto; }

  .lb-addr code { max-width: 46vw; }
}
