:root {
  --bg: #14161c;
  --bg2: #0e1014;
  --card: #1d2029;
  --card2: #262b37;
  --line: #313848;
  --text: #f2f4f8;
  --muted: #9aa4b8;
  --green: #3dd68c;
  --amber: #ffb15a;
  --red: #ff5d73;
  --accent: #ffa26b;
  --accent-soft: #ffd9b8;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(0,0,0,.4);
  --warm-glow: 0 6px 18px rgba(255,162,107,.25);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg2);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  display: flex; justify-content: center;
  min-height: 100vh;
}
#app {
  width: min(1100px, 100%);
  min-height: 100vh;
  background: var(--bg);
  display: flex; flex-direction: column;
  position: relative;
}
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
  background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 16px;
  background: linear-gradient(180deg, #ffc38f, #f07f2e);
  display: grid; place-items: center;
  font-weight: 800; font-size: 14px; color: #3a1c05;
  box-shadow: var(--warm-glow);
}
.brand h1 { font-size: 16px; margin: 0; }
.tagline { margin: 0; font-size: 11px; color: var(--muted); }
.conn { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.conn .dot { width: 10px; height: 10px; border-radius: 50%; background: #666; }
.conn .dot.on { background: var(--green); box-shadow: 0 0 0 4px rgba(61,214,140,.15); }
.conn .dot.warn { background: var(--amber); }

#screens { flex: 1; padding: 14px 14px 120px; }
.screen { display: none; animation: fade .18s ease-in; }
.screen.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
h2 { font-size: 17px; margin: 18px 0 8px; }
h3 { font-size: 14px; margin: 0 0 8px; }
.hint { color: var(--muted); font-size: 12.5px; line-height: 1.45; }
.warn { color: var(--amber); font-size: 13px; line-height: 1.5; }
a { color: var(--accent); }

.searchbar { display: flex; gap: 8px; margin-bottom: 10px; }
.searchbar input { flex: 1; }
input[type="search"], input[type="text"], input[type="url"], input[type="number"], select {
  background: #0f1218; color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 12px; font-size: 14px; width: 100%;
}
input[type="range"] { accent-color: var(--accent); width: 100%; }
.btn {
  border: 0; border-radius: 999px;
  background: var(--card2); color: var(--text);
  font-weight: 700; font-size: 13px;
  padding: 10px 16px; cursor: pointer;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(180deg, #ffb37e, #f08a3c); color: #3a1c05; box-shadow: var(--warm-glow); }
.btn.accent { background: #fff7ef; color: #3a1c05; }
.btn.danger { background: #3a1d24; color: var(--red); border: 1px solid #5c2a35; }
.btn.small { padding: 7px 11px; font-size: 12px; }
.btn:disabled { opacity: .45; cursor: default; }

.quick-actions { display: flex; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.filters { display: flex; gap: 8px; margin-bottom: 10px; }
.filters select { flex: 1; }

.cards { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 700px) { .cards { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1000px) { .cards { grid-template-columns: 1fr 1fr 1fr; } }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px;
  box-shadow: var(--shadow);
}
.card .name { font-weight: 800; font-size: 14.5px; margin: 0 0 2px; }
.card .loc { color: var(--muted); font-size: 12.5px; margin: 0 0 6px; }
.card .meta-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; align-items: center; }
.pill {
  font-size: 11px; font-weight: 700; border-radius: 999px; padding: 3px 9px;
  background: var(--card2); color: var(--text);
}
.pill.live { background: #123a28; color: var(--green); }
.pill.recent { background: #3a2c12; color: var(--amber); }
.pill.offline { background: #2a2d36; color: var(--muted); }
.pill.error { background: #3a1d24; color: var(--red); }
.pill.checking { background: #2a2d36; color: var(--muted); animation: pulse 1.2s infinite; }
.pill.test { background: #3a2c12; color: var(--amber); }
@keyframes pulse { 50% { opacity: .5; } }
.card .actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.card .src { font-size: 11px; color: var(--muted); margin-top: 8px; }

.add-system { margin-bottom: 12px; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; }
.status-line { font-size: 12.5px; color: var(--amber); min-height: 18px; margin: 8px 0 0; }

.mix-header { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.mix-header select { flex: 1; min-width: 140px; }
.modes { display: flex; gap: 8px; margin-bottom: 6px; }
.mode {
  flex: 1; border: 1px solid var(--line); background: var(--card);
  color: var(--muted); border-radius: 16px; padding: 10px 6px;
  font-size: 12.5px; font-weight: 700; cursor: pointer;
}
.mode.on { background: linear-gradient(180deg, #ffb37e, #f08a3c); color: #3a1c05; border-color: transparent; box-shadow: var(--warm-glow); }
.master-row { display: flex; gap: 10px; align-items: center; margin: 8px 0; }
.master-row label { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.master-row input { flex: 1; }
.ducking-row { display: flex; gap: 8px; align-items: center; font-size: 12.5px; color: var(--muted); margin-bottom: 10px; }
.ducking-row input { width: auto; accent-color: var(--accent); }

.mix-item {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px; margin-bottom: 8px;
}
.mix-item.pinned { border-color: var(--amber); }
.mix-item .top { display: flex; align-items: center; gap: 8px; }
.mix-item .nm { font-weight: 800; font-size: 13.5px; flex: 1; }
.mix-item .ctl { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; align-items: center; }
.mix-item .vol { display: flex; gap: 6px; align-items: center; flex: 1; min-width: 120px; }
.mix-item .vol label { font-size: 11px; color: var(--muted); }
.mix-item .prio { display: flex; gap: 4px; align-items: center; }
.mix-item .prio button.on { background: var(--amber); color: #221503; }
.mix-item .err { color: var(--red); font-size: 12px; margin-top: 6px; }
.mix-item .buf { color: var(--amber); font-size: 12px; margin-top: 6px; }

.empty { text-align: center; padding: 30px 10px; color: var(--muted); }

.form label { display: block; font-size: 12.5px; color: var(--muted); margin: 12px 0 4px; }
.danger-zone { border-color: #5c2a35; }

#tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: min(1100px, 100%);
  display: flex; overflow-x: auto;
  background: #171a21; border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  z-index: 30; scrollbar-width: none;
}
#tabbar::-webkit-scrollbar { display: none; }
.tab {
  flex: 1 0 auto; min-width: 64px;
  background: none; border: 0; color: var(--muted);
  font-size: 10.5px; font-weight: 700;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 8px; cursor: pointer;
}
.tab .ico {
  width: 26px; height: 26px; border-radius: 9px;
  background: var(--card2); display: grid; place-items: center;
  font-size: 12px; color: var(--text);
}
.tab.on { color: var(--accent-soft); }
.tab.on .ico { background: linear-gradient(180deg, #ffb37e, #f08a3c); color: #3a1c05; box-shadow: var(--warm-glow); }

#playerBar {
  position: fixed; bottom: 64px; left: 50%; transform: translateX(-50%);
  width: min(1100px, calc(100% - 20px));
  background: var(--card2); border: 1px solid var(--line);
  border-radius: 16px; padding: 10px 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  box-shadow: var(--shadow); z-index: 25;
}
#playerBar[hidden] { display: none; }
.pb-info { display: flex; align-items: center; gap: 8px; font-size: 13px; min-width: 0; }
#pbName { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-pill { font-size: 11px; font-weight: 800; border-radius: 999px; padding: 3px 9px; background: #123a28; color: var(--green); }
.status-pill.paused { background: #3a2c12; color: var(--amber); }
.status-pill.error { background: #3a1d24; color: var(--red); }
.pb-controls { display: flex; gap: 6px; }

#toast {
  position: fixed; bottom: 140px; left: 50%; transform: translateX(-50%);
  background: #0c0e12; border: 1px solid var(--line); color: var(--text);
  padding: 10px 16px; border-radius: 12px; font-size: 13px;
  opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 50;
  max-width: calc(100% - 40px); text-align: center;
}
#toast.show { opacity: 1; }

/* ---- Phase 2 UI: captions, threads, ease-of-use ---- */
.check { display: flex !important; gap: 8px; align-items: center; font-size: 13px; color: var(--text); margin: 10px 0 4px; }
.check input { width: auto; accent-color: var(--accent); }
input[type="time"] {
  background: #0f1218; color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 12px; font-size: 14px;
}
.btn.big { padding: 14px 26px; font-size: 15px; }
.btn.on { background: var(--amber); color: #221503; }

/* Big friendly tap targets */
.btn { min-height: 44px; }
.btn.small { min-height: 40px; }
.tab { min-height: 52px; }

/* Playback status line: the radio never fails silently */
.pb-detail { font-size: 12px; color: var(--muted); margin: 2px 0 0; min-height: 15px; width: 100%; }

/* Caption chatbox: streamer-chat style, newest at the bottom */
.chat-wrap { position: relative; }
#captionLog {
  max-height: 420px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 8px;
  padding: 10px; background: #12151c;
  border: 1px solid var(--line); border-radius: 16px;
}
#transcriptLog {
  max-height: 62vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 8px;
  padding: 10px; background: #12151c;
  border: 1px solid var(--line); border-radius: 16px;
}
.chat-row { display: flex; gap: 8px; align-items: flex-start; }
.chat-avatar {
  flex: none; width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 800; font-size: 14px; color: #141414;
}
.chat-bubble {
  background: var(--card2); border: 1px solid var(--line);
  border-radius: 4px 16px 16px 16px; padding: 8px 10px;
  min-width: 0; flex: 1;
}
.chat-head { margin: 0 0 2px; display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.chat-name { font-size: 12.5px; font-weight: 800; }
.chat-time { font-size: 10.5px; color: var(--muted); }
.chat-text { margin: 2px 0; font-size: 14.5px; line-height: 1.4; }
.cap-size-small .chat-text { font-size: 12.5px; }
.cap-size-large .chat-text { font-size: 17.5px; }
.chat-pins { font-size: 11px; color: var(--accent); font-weight: 700; margin: 2px 0 0; }
.chat-meta { font-size: 10.5px; color: var(--muted); margin: 4px 0 0; }
.chat-acts { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.jump-latest {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  border: 0; border-radius: 999px; padding: 8px 16px; min-height: 40px;
  background: var(--accent); color: #141414; font-weight: 800; font-size: 13px;
  box-shadow: var(--shadow); z-index: 5;
}
.jump-latest[hidden] { display: none; }

/* Caption stage: high-contrast band above the player */
#captionStage {
  position: fixed; bottom: 150px; left: 50%; transform: translateX(-50%);
  width: min(1100px, calc(100% - 20px));
  background: #0a0c10; border: 2px solid var(--amber);
  border-radius: 16px; padding: 10px 12px;
  box-shadow: var(--shadow); z-index: 24;
  max-height: 220px; overflow: auto;
}
#captionStage[hidden] { display: none; }
.cap-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.zone-chip {
  font-size: 11px; font-weight: 800; border-radius: 999px; padding: 3px 10px;
  color: #141414; white-space: nowrap;
}
.cap-now .cap-line { border: 0; padding: 0; }
.cap-line {
  display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: start;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 8px; margin-bottom: 6px;
}
.cap-body { min-width: 0; }
.cap-speaker { font-size: 11.5px; font-weight: 800; margin: 0 0 2px; color: var(--accent-soft); }
.ai-mark {
  font-size: 10px; font-weight: 700; background: #3a2c12; color: var(--amber);
  border-radius: 6px; padding: 1px 6px; margin-left: 4px; white-space: nowrap;
}
.cap-text { margin: 0; font-size: 15px; line-height: 1.4; }
.cap-size-small .cap-text { font-size: 13px; }
.cap-size-large .cap-text { font-size: 18px; }
.cap-pins { font-size: 11px; color: var(--accent); font-weight: 700; }
.cap-meta { font-size: 11px; color: var(--muted); margin: 4px 0 0; }
.cap-acts { display: flex; flex-direction: column; gap: 4px; }
.cap-status { color: var(--amber); font-size: 13px; margin: 6px 0; }
.cap-note { font-size: 11px; color: var(--muted); margin: 8px 0 0; line-height: 1.4; }

/* Thread cards in the caption log */
.thread-card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px; margin-bottom: 10px;
}
.thread-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.thread-title { font-weight: 800; font-size: 13px; flex: 1; }
.thread-times { font-size: 11px; color: var(--muted); }

/* Quiet hours banner */
#quietBanner {
  position: fixed; bottom: 210px; left: 50%; transform: translateX(-50%);
  width: min(1100px, calc(100% - 20px));
  background: #241c10; border: 1px solid var(--amber);
  border-radius: 14px; padding: 8px 12px; z-index: 24;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 13px; color: var(--amber);
}
#quietBanner[hidden] { display: none; }

/* Player bar extras */
#playerBar { flex-wrap: wrap; }
.pb-progress-row { display: flex; align-items: center; gap: 8px; width: 100%; }
.pb-progress-row input[type="range"] { flex: 1; height: 6px; }
.pb-time { font-size: 11px; color: var(--muted); white-space: nowrap; }
.pb-controls { flex-wrap: wrap; }

/* Freshness + why lines */
.fresh-line { font-size: 11px; color: var(--muted); margin: 4px 0 0; }
.why { font-size: 12px; color: var(--accent-soft); font-style: italic; margin: 4px 0 0; }

/* Recent search chips */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.chip {
  border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px;
  background: var(--card2); color: var(--text); font-size: 12.5px; font-weight: 700;
  cursor: pointer; min-height: 40px;
}

/* Overlays: offline + tour */
#offlineOverlay, #tourOverlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(5, 6, 9, .82);
  display: grid; place-items: center; padding: 20px;
}
#offlineOverlay[hidden], #tourOverlay[hidden] { display: none; }
.overlay-card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 20px; padding: 24px; max-width: 420px; width: 100%;
  box-shadow: var(--shadow); text-align: center;
}
.overlay-card h2 { margin-top: 0; }
.overlay-card p { color: var(--muted); line-height: 1.5; }
.tour-count { font-size: 12px; color: var(--accent); font-weight: 800; margin: 0 0 4px; }

/* Long-press context menu */
#ctxMenu {
  position: fixed; z-index: 70; min-width: 200px;
  background: var(--card2); border: 1px solid var(--line);
  border-radius: 14px; padding: 10px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 6px;
}
#ctxMenu[hidden] { display: none; }
.ctx-title { font-weight: 800; font-size: 13px; margin: 0 0 4px; }

/* Battery saver: calm and dim */
body.battery-saver #app { filter: brightness(.82); }
body.battery-saver *, body.reduce-motion * {
  animation: none !important; transition: none !important;
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
  .screen { animation: none; }
}

@media (min-width: 800px) {
  #screens { padding: 20px 24px 40px; }
  #tabbar { position: sticky; bottom: auto; top: 0; order: -1; border-top: 0; border-bottom: 1px solid var(--line); transform: none; left: auto; }
  #app { flex-direction: column; }
  #playerBar { bottom: 20px; }
}

/* ---- Compact Mix layout: chatroom above the fold ---- */
.mode-wrap { flex: 1; display: flex; position: relative; min-width: 0; }
.mode-wrap .mode { flex: 1; }
.info-dot {
  position: absolute; top: 3px; right: 3px;
  width: 22px; height: 22px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--card2);
  color: var(--muted); font-size: 12px; font-weight: 800;
  cursor: pointer; padding: 0; line-height: 1;
}
.mix-item .top { flex-wrap: nowrap; }
.mix-item .top .btn[data-act="play"] { flex: none; }
.mix-detail { margin-top: 8px; }
.mix-detail[hidden] { display: none; }
.compact-h { margin: 12px 0 6px; font-size: 15px; }
.searchbar.slim { margin-bottom: 8px; }
.searchbar.slim .btn { min-height: 40px; }

/* Small phones: all 9 tabs fit without sideways scrolling */
@media (max-width: 520px) {
  #tabbar { overflow-x: hidden; padding-left: 2px; padding-right: 2px; }
  .tab { flex: 1 1 0; min-width: 0; padding: 5px 1px; font-size: 9px; }
  .tab .ico { width: 22px; height: 22px; font-size: 10px; border-radius: 8px; }
  .modes { gap: 6px; }
  .mode { padding: 9px 4px; font-size: 11.5px; }
  .mix-header { gap: 6px; }
  .mix-header .btn { padding: 8px 12px; font-size: 12px; min-height: 40px; }
}
