/* ───────────────────────── Design tokens ───────────────────────── */
:root {
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
          "Helvetica Neue", Helvetica, Arial, sans-serif;
  --accent: #007aff;
  --accent-press: #0060df;
  --green: #34c759;
  --red: #ff3b30;
  --amber: #ff9f0a;

  --bg: #f2f2f7;
  --bg-grad-1: #eef1f6;
  --bg-grad-2: #e7ebf3;
  --card: rgba(255, 255, 255, 0.72);
  --card-solid: #ffffff;
  --border: rgba(0, 0, 0, 0.08);
  --text: #1c1c1e;
  --text-2: #3c3c43;
  --text-3: rgba(60, 60, 67, 0.6);
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.10), 0 2px 8px rgba(0, 0, 0, 0.04);
  --radius: 22px;
  --radius-sm: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-grad-1: #0a0a0c;
    --bg-grad-2: #15151a;
    --card: rgba(28, 28, 30, 0.72);
    --card-solid: #1c1c1e;
    --border: rgba(255, 255, 255, 0.10);
    --text: #f5f5f7;
    --text-2: #ebebf0;
    --text-3: rgba(235, 235, 245, 0.6);
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: radial-gradient(140% 120% at 50% 0%, var(--bg-grad-1) 0%, var(--bg-grad-2) 55%, var(--bg) 100%);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.wrap {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 28px 20px 40px;
  flex: 1;
  display: flex;
  flex-direction: column;
}
.wrap.wide { max-width: 900px; }

/* ───────────────────────── Cards / typography ───────────────────────── */
.card {
  background: var(--card);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}
.card + .card { margin-top: 16px; }

h1 { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 2px; }
.subtitle { color: var(--text-3); font-size: 15px; margin: 0; }
.label { font-size: 13px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.04em; margin: 0 0 8px; }

.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.brand .glyph {
  width: 42px; height: 42px; border-radius: 12px;
  background: linear-gradient(160deg, var(--accent), #5e5ce6);
  display: grid; place-items: center; color: #fff; flex: none;
  box-shadow: 0 6px 16px rgba(0, 122, 255, 0.35);
}
.brand .glyph svg { width: 24px; height: 24px; }

/* ───────────────────────── Buttons / controls ───────────────────────── */
button { font-family: var(--font); cursor: pointer; }
.btn {
  width: 100%;
  border: none;
  border-radius: var(--radius-sm);
  padding: 15px 18px;
  font-size: 17px;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  transition: transform 0.12s ease, background 0.2s ease, opacity 0.2s ease;
}
.btn:hover { background: var(--accent-press); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.danger { background: var(--red); }
.btn.danger:hover { background: #e0352b; }
.btn.ghost { background: rgba(120, 120, 128, 0.16); color: var(--text); }
.btn.ghost:hover { background: rgba(120, 120, 128, 0.24); }

.btn-clear {
  border: none;
  background: rgba(120, 120, 128, 0.14);
  color: var(--text-3);
  font-size: 13px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 999px;
  transition: background 0.15s ease, color 0.15s ease;
}
.btn-clear:hover { background: rgba(120, 120, 128, 0.24); color: var(--text); }
.btn-clear:active { transform: scale(0.96); }

select, input[type="password"], input[type="text"] {
  width: 100%;
  font-family: var(--font);
  font-size: 16px;
  color: var(--text);
  background: rgba(120, 120, 128, 0.10);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  appearance: none;
  -webkit-appearance: none;
}
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%238e8e93' d='M6 8 0 2l1.4-1.4L6 5.2 10.6.6 12 2z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }

.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.field + .field { margin-top: 16px; }

/* iOS-style toggle */
.switch { position: relative; display: inline-block; width: 51px; height: 31px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0; border-radius: 999px;
  background: rgba(120, 120, 128, 0.32); transition: background 0.2s ease;
}
.switch .track::before {
  content: ""; position: absolute; height: 27px; width: 27px; left: 2px; top: 2px;
  background: #fff; border-radius: 50%; transition: transform 0.2s ease;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}
.switch input:checked + .track { background: var(--green); }
.switch input:checked + .track::before { transform: translateX(20px); }

/* ───────────────────────── Status chips / dots ───────────────────────── */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 13px; font-weight: 600; color: var(--text-2);
  background: rgba(120, 120, 128, 0.14);
  border-radius: 999px; padding: 7px 12px;
}
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-3); flex: none; }
.dot.green { background: var(--green); box-shadow: 0 0 0 4px rgba(52, 199, 89, 0.18); }
.dot.red { background: var(--red); }
.dot.amber { background: var(--amber); }

/* ───────────────────────── VU meter ───────────────────────── */
.vu { height: 14px; border-radius: 8px; background: rgba(120, 120, 128, 0.18); overflow: hidden; position: relative; }
.vu .fill {
  position: absolute; left: 0; top: 0; bottom: 0; width: 0%;
  background: linear-gradient(90deg, var(--green), #a3e635 70%, var(--amber));
  border-radius: 8px; transition: width 0.06s linear;
}

/* ───────────────────────── Captions ───────────────────────── */
.captions { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 6px; }
@media (max-width: 480px) { .captions { grid-template-columns: 1fr; } }
.captions-vertical { display: flex !important; flex-direction: column; gap: 14px; }
.cap-col { min-height: 120px; max-height: 220px; overflow-y: auto; }
.cap-col p { margin: 0; font-size: 16px; line-height: 1.5; color: var(--text); white-space: pre-wrap; }
.cap-col.muted p { color: var(--text-3); }

/* ───────────────────────── Admin two-column layout ───────────────────────── */
.admin-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}
@media (max-width: 640px) {
  .admin-grid { grid-template-columns: 1fr; }
}
.admin-col-left { display: flex; flex-direction: column; gap: 16px; }
.admin-col-right { display: flex; flex-direction: column; height: 100%; }
.admin-captions-card {
  flex: 1;
  display: flex;
  flex-direction: column;
}
.admin-captions-card .captions-vertical { flex: 1; }
.admin-captions-card .cap-col {
  min-height: 140px;
  max-height: none;        /* let the card height drive it */
  height: 200px;           /* fixed height per column so both are readable */
}

/* ───────────────────────── Listener page ───────────────────────── */
.listener { align-items: center; justify-content: center; text-align: center; gap: 0; }
.listener .hero { display: flex; flex-direction: column; align-items: center; gap: 26px; margin: auto 0; }
.orb {
  position: relative; width: 200px; height: 200px; border-radius: 50%;
  display: grid; place-items: center;
  background: radial-gradient(circle at 50% 38%, #5ea0ff, var(--accent) 62%, #0a63d6);
  color: #fff; box-shadow: 0 20px 60px rgba(0, 122, 255, 0.4);
  border: none; transition: transform 0.15s ease;
}
.orb:active { transform: scale(0.96); }
.orb .ring { position: absolute; inset: 0; border-radius: 50%; border: 2px solid rgba(0, 122, 255, 0.35); opacity: 0; }
.orb.live .ring { animation: pulse 2.6s ease-out infinite; }
.orb.live .ring:nth-child(2) { animation-delay: 0.9s; }
.orb.live .ring:nth-child(3) { animation-delay: 1.8s; }
@keyframes pulse { 0% { transform: scale(1); opacity: 0.55; } 100% { transform: scale(1.7); opacity: 0; } }
.orb .icon { width: 64px; height: 64px; }
.orb .eq { display: none; gap: 5px; height: 56px; align-items: center; }
.orb.live .icon { display: none; }
.orb.live .eq { display: flex; }
.orb .eq span { width: 6px; background: #fff; border-radius: 3px; animation: eq 1s ease-in-out infinite; }
.orb .eq span:nth-child(1){ animation-delay:0s } .orb .eq span:nth-child(2){ animation-delay:.2s }
.orb .eq span:nth-child(3){ animation-delay:.4s } .orb .eq span:nth-child(4){ animation-delay:.1s }
.orb .eq span:nth-child(5){ animation-delay:.3s }
@keyframes eq { 0%,100% { height: 16px; } 50% { height: 48px; } }

.listener h1 { font-size: 30px; }
.hint { color: var(--text-3); font-size: 15px; max-width: 320px; }
.vol-row { display: flex; align-items: center; gap: 14px; width: 280px; max-width: 80vw; }
.wakelock-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; width: 280px; max-width: 80vw; }
input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 6px; border-radius: 3px;
  background: rgba(120,120,128,0.3); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 26px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,0.25); cursor: pointer; }
.statusline { display: inline-flex; align-items: center; gap: 8px; color: var(--text-3); font-size: 14px; font-weight: 500; }

.footer { text-align: center; color: var(--text-3); font-size: 12px; padding: 16px 0 4px; }
.hidden { display: none !important; }
.spacer { flex: 1; }

/* ───────────────────────── Listener transcript ───────────────────────── */
.transcript-card {
  position: relative;
  width: 100%;
  max-width: 560px;
  margin: 20px auto 0;
  background: var(--card);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
  animation: fadeSlideIn 0.3s ease;
}

.scroll-down-btn {
  position: absolute;
  bottom: 14px;
  right: 14px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 4px 14px rgba(0, 122, 255, 0.45);
  transition: transform 0.12s ease, opacity 0.2s ease;
  cursor: pointer;
}
.scroll-down-btn:hover { transform: scale(1.08); }
.scroll-down-btn:active { transform: scale(0.94); }
.scroll-down-btn.hidden { opacity: 0; pointer-events: none; }
@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.transcript-text {
  font-size: 17px;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  text-align: left;
  max-height: 260px;
  overflow-y: auto;
  /* Fade out top edge to hint at scrollability */
  mask-image: linear-gradient(to bottom, transparent 0%, black 18%);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, black 18%);
}

.transcript-sep {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-3);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin: 16px 0 12px;
  white-space: nowrap;
}
.transcript-sep::before,
.transcript-sep::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
