@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

/* Live Translation — shared design system. Mobile-first; most of the audience
   joins on phones by scanning a QR. */

:root {
  --bg-0: #070b16;
  --bg-1: #0e1626;
  --bg-2: #14203a;
  --card: rgba(255, 255, 255, 0.98);
  --card-line: rgba(148, 163, 184, 0.18);
  --ink: #0f172a;
  --ink-soft: #475569;
  --muted: #94a3b8;
  --muted-ink: #64748b;
  --line: #e8edf4;

  --speaker: #2563eb;
  --speaker-2: #3b82f6;
  --listener: #10b981;
  --listener-2: #34d399;
  --danger: #ef4444;
  --danger-2: #f87171;
  --amber: #f59e0b;

  --radius: 18px;
  --radius-sm: 11px;
  --shadow: 0 24px 60px -28px rgba(2, 6, 23, 0.75);
  --shadow-sm: 0 6px 18px -10px rgba(2, 6, 23, 0.5);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Inter', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg-0);
  background-image:
    radial-gradient(1100px 520px at 15% -10%, #1d2b4d 0%, transparent 55%),
    radial-gradient(900px 480px at 100% 0%, #16304f 0%, transparent 50%),
    linear-gradient(180deg, var(--bg-1) 0%, var(--bg-0) 70%);
  background-attachment: fixed;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 26px 16px 56px;
  -webkit-font-smoothing: antialiased;
}

/* ---- header / brand ---- */
.brand { color: #e8eefb; text-align: center; margin: 6px 0 22px; animation: fade-down 0.5s ease both; }
.brand .logo { font-size: 1.55rem; font-weight: 800; letter-spacing: -0.025em; }
.brand .tag { color: #8da2c0; font-size: 0.9rem; margin-top: 3px; }
.brand .tag strong { color: #cbd9f0; font-weight: 700; letter-spacing: 0.5px; }

.wrap { width: 100%; max-width: 470px; }

/* ---- cards ---- */
.card {
  background: var(--card);
  border: 1px solid var(--card-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin: 0 0 18px;
  animation: fade-up 0.45s ease both;
}
.card h2 { font-size: 1.08rem; margin: 0 0 5px; letter-spacing: -0.01em; }
.card .desc { color: var(--muted-ink); margin: 0 0 16px; font-size: 0.9rem; line-height: 1.45; }

label { display: block; margin: 14px 0 7px; font-weight: 650; font-size: 0.82rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.04em; }

/* ---- inputs / buttons ---- */
select, input, button, .btn {
  font-size: 1rem;
  font-family: inherit;
  width: 100%;
  padding: 14px 15px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--line);
  background: #fff;
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.06s, filter 0.15s;
}
select:focus, input:focus { outline: none; border-color: var(--speaker); box-shadow: 0 0 0 4px rgba(37,99,235,0.13); }
select { appearance: none; cursor: pointer; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 19px) center, calc(100% - 14px) center; background-size: 6px 6px, 6px 6px; background-repeat: no-repeat; padding-right: 38px; }

button, .btn {
  border: 0;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  display: block;
  letter-spacing: 0.01em;
  box-shadow: var(--shadow-sm);
}
button:active, .btn:active { transform: translateY(1px) scale(0.997); }
button:hover, .btn:hover { filter: brightness(1.06); }
button:disabled { background: #cbd5e1 !important; cursor: default; filter: none; box-shadow: none; }

.btn-speaker { background: linear-gradient(135deg, var(--speaker-2), var(--speaker)); }
.btn-listener { background: linear-gradient(135deg, var(--listener-2), var(--listener)); }
.btn-stop, button.live, button.stop { background: linear-gradient(135deg, var(--danger-2), var(--danger)); }
.btn-ghost { background: #f1f5f9; color: var(--ink-soft); border: 1.5px solid var(--line); font-weight: 650; box-shadow: none; }
.btn-ghost:hover { filter: none; background: #e9eef5; }

.mt { margin-top: 18px; }

/* live button gets a soft breathing glow */
button.live { animation: live-glow 2s ease-in-out infinite; }

/* ---- status panel ---- */
.status { margin-top: 20px; padding: 6px 16px; border-radius: var(--radius-sm); background: #f7f9fc; border: 1px solid var(--line); }
.row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; font-size: 0.92rem; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row > span { color: var(--muted-ink); }
.row strong { color: var(--ink); font-weight: 700; display: inline-flex; align-items: center; }

.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #cbd5e1; margin-right: 8px; transition: background 0.2s; }
.dot.on { background: #22c55e; box-shadow: 0 0 0 0 rgba(34,197,94,0.5); animation: pulse-dot 1.8s infinite; }
.dot.warn { background: var(--amber); }

.err { color: var(--danger); font-size: 0.88rem; min-height: 1em; margin: 12px 0 0; font-weight: 600; }
.hint { color: var(--muted-ink); font-size: 0.85rem; margin: 10px 0 0; line-height: 1.45; }

/* ---- latency pill ---- */
.lat { display: inline-flex; align-items: baseline; gap: 7px; padding: 4px 11px; border-radius: 999px; font-weight: 700; font-size: 0.9rem; background: #eef2f7; color: var(--muted-ink); }
.lat .sub { font-weight: 500; font-size: 0.78rem; opacity: 0.85; }
.lat.good { background: #e7f8ef; color: #0f9d58; }
.lat.ok { background: #fef3e2; color: #c77700; }
.lat.bad { background: #fdeaea; color: #d63333; }
.lat.relay { background: #e7f0ff; color: #2563eb; }

/* ---- card topline + status badge (speaker/listener) ---- */
.topline { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.topline h2 { margin: 0; }
.pill { font-size: 0.72rem; padding: 5px 11px; border-radius: 999px; font-weight: 800; display: inline-flex; align-items: center; gap: 6px; letter-spacing: 0.03em; }
.pill .d { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.idle { background: #eef2f7; color: var(--muted-ink); }
.pill.on { background: #e7f8ef; color: #0f9d58; }
.pill.on .d { animation: pulse-dot 1.6s infinite; }
.pill.air { background: #fdeaea; color: #dc2626; }
.pill.air .d { animation: pulse-dot 1.4s infinite; }

/* ---- hero metric (listener latency) ---- */
.metric { margin-top: 18px; padding: 20px 16px; border-radius: 14px; background: #f7f9fc; border: 1px solid var(--line); text-align: center; transition: background 0.25s; }
.metric-big { font-size: 2.5rem; font-weight: 850; letter-spacing: -0.025em; color: var(--ink); line-height: 1; }
.metric-sub { font-size: 0.82rem; color: var(--muted-ink); margin-top: 8px; font-weight: 600; }
.metric.good { background: #e7f8ef; } .metric.good .metric-big { color: #0f9d58; }
.metric.ok { background: #fef3e2; } .metric.ok .metric-big { color: #c77700; }
.metric.bad { background: #fdeaea; } .metric.bad .metric-big { color: #d63333; }
.metric.relay { background: #e7f0ff; } .metric.relay .metric-big { color: #2563eb; }

/* ---- role picker ---- */
.roles { display: grid; gap: 13px; }
.role {
  display: flex; align-items: center; gap: 15px;
  padding: 18px; border-radius: 15px; cursor: pointer;
  border: 2px solid var(--line); background: #fff; color: var(--ink);
  text-align: left; width: 100%; box-shadow: none;
  transition: border-color 0.18s, transform 0.08s, box-shadow 0.18s, background 0.18s;
}
.role:hover { border-color: #c4d0e0; transform: translateY(-1px); box-shadow: var(--shadow-sm); filter: none; }
.role.sel-speaker { border-color: var(--speaker); background: #f3f7ff; box-shadow: 0 0 0 4px rgba(37,99,235,0.1); }
.role.sel-listener { border-color: var(--listener); background: #f0fdf7; box-shadow: 0 0 0 4px rgba(16,185,129,0.1); }
.role .ic { font-size: 1.8rem; line-height: 1; }
.role .t { font-weight: 750; font-size: 1.06rem; }
.role .s { color: var(--muted-ink); font-size: 0.84rem; }

/* ---- QR / share ---- */
.qr-box { text-align: center; }
.qr-frame { display: inline-block; padding: 14px; margin: 14px auto 6px; background: #fff; border-radius: 16px; box-shadow: var(--shadow-sm); border: 1px solid var(--line); }
.qr-frame img { width: 248px; height: 248px; display: block; image-rendering: pixelated; }
.qr-box.big .qr-frame img { width: 300px; height: 300px; }
.roomcode { font-size: 2rem; font-weight: 850; letter-spacing: 4px; margin: 6px 0; color: var(--ink); }
.roomcode.huge { font-size: 2.7rem; }
.roomcode .lbl { font-size: 0.8rem; font-weight: 600; letter-spacing: 1px; color: var(--muted-ink); display: block; text-transform: uppercase; margin-bottom: -2px; }

.join-row { display: flex; gap: 10px; }
.join-row input { flex: 1; text-transform: lowercase; }
.join-row button { width: auto; padding: 14px 22px; }

a.link { color: var(--speaker); text-decoration: none; font-weight: 650; }

/* ---- back link (fixed top-left) ---- */
.backlink {
  position: fixed; top: 14px; left: 14px; z-index: 30;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 14px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(148, 163, 184, 0.28);
  color: #d3deef; text-decoration: none; font-size: 0.85rem; font-weight: 650;
  backdrop-filter: blur(8px); transition: background 0.15s, transform 0.06s;
}
.backlink:hover { background: rgba(255, 255, 255, 0.16); }
.backlink:active { transform: translateY(1px); }

/* ---- mic level meter (speaker) ---- */
.meter { display: flex; align-items: flex-end; gap: 3px; height: 34px; margin-top: 16px; }
.meter .bar { flex: 1; background: #e2e8f0; border-radius: 3px; height: 18%; transition: height 0.08s ease, background 0.12s; }
.meter.active .bar { background: var(--listener); }

/* ---- listener playing indicator ---- */
.eq { display: inline-flex; align-items: flex-end; gap: 3px; height: 16px; margin-left: 8px; opacity: 0; transition: opacity 0.2s; }
.eq.on { opacity: 1; }
.eq i { width: 4px; background: var(--listener); border-radius: 2px; height: 4px; animation: eq 0.7s ease-in-out infinite; }
.eq i:nth-child(2) { animation-delay: 0.15s; }
.eq i:nth-child(3) { animation-delay: 0.3s; }
.eq i:nth-child(4) { animation-delay: 0.45s; }
.eq i:nth-child(5) { animation-delay: 0.2s; }

/* live captions */
.cap-head { display: flex; align-items: center; justify-content: space-between; }
.cap-body { margin-top: 12px; max-height: 168px; overflow-y: auto; display: flex; flex-direction: column; gap: 7px; }
.cap-line { background: #f1f5f9; border-radius: 11px; padding: 10px 13px; font-size: 1rem; line-height: 1.45; color: var(--ink); animation: fade-up 0.25s ease both; }
.cap-line.cap-live { background: #eef2ff; color: #1e293b; }
.cap-empty { color: var(--muted); font-size: 0.88rem; }

/* volume slider */
input[type=range] { -webkit-appearance: none; appearance: none; height: 6px; padding: 0; background: #e2e8f0; border-radius: 999px; border: 0; }
input[type=range]:focus { box-shadow: none; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%; background: var(--listener); cursor: pointer; box-shadow: var(--shadow-sm); }
input[type=range]::-moz-range-thumb { width: 20px; height: 20px; border: 0; border-radius: 50%; background: var(--listener); cursor: pointer; }
.vol-row { display: flex; align-items: center; gap: 12px; margin-top: 6px; }
.vol-row .ic { font-size: 1.1rem; }
.vol-row output { color: var(--muted-ink); font-size: 0.82rem; min-width: 38px; text-align: right; }

/* hero metric pulses briefly while audio plays */
.metric.pulse { box-shadow: 0 0 0 4px rgba(16,185,129,0.18); }

/* skeleton shimmer (dashboard loading) */
.skeleton { position: relative; overflow: hidden; background: rgba(255,255,255,0.06); border: 1px solid rgba(148,163,184,0.16); border-radius: var(--radius); height: 96px; margin: 0 0 12px; }
.skeleton::after { content: ''; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, rgba(255,255,255,0.10), transparent); animation: shimmer 1.3s infinite; }
@keyframes shimmer { 100% { transform: translateX(100%); } }

/* ---- waiting banner ---- */
.waiting { margin-top: 16px; padding: 13px 15px; border-radius: var(--radius-sm); background: #fff7ed; border: 1px solid #fed7aa; color: #b45309; font-size: 0.88rem; font-weight: 600; display: none; align-items: center; gap: 9px; }
.waiting.show { display: flex; }
.waiting .spin { width: 14px; height: 14px; border: 2px solid #fcd9a8; border-top-color: #d97706; border-radius: 50%; animation: spin 0.8s linear infinite; }

/* ---- provider lab ---- */
.lab-langs { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.prov-row { display: flex; gap: 8px; }
.prov-row select:first-child { flex: 1; }
.prov-row .model-sel { flex: 0 0 auto; max-width: 46%; }
.lab-metrics { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 14px 0 4px; }
.lab-metric { background: #f1f5f9; border-radius: 12px; padding: 12px 10px; text-align: center; }
.lab-metric .lbl { display: block; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted-ink); }
.lab-metric strong { font-size: 1.2rem; font-weight: 800; color: var(--ink); }
.lab-metric.hero { grid-column: 1 / -1; background: linear-gradient(135deg, #eef2ff, #e0f2fe); }
.lab-metric.hero strong { font-size: 1.6rem; }

/* ---- history table ---- */
.hist-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.hist-table th { text-align: left; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted-ink); padding: 0 8px 10px 0; border-bottom: 1px solid var(--line); }
.hist-table td { padding: 10px 8px 10px 0; border-bottom: 1px solid var(--line); vertical-align: middle; }
.hist-table tr:last-child td { border-bottom: 0; }
.hist-table strong { font-size: 0.82rem; word-break: break-all; }

/* ---- dark mode ---- */
/* ---- theme toggle button ---- */
#theme-toggle {
  position: fixed; bottom: 20px; right: 20px; z-index: 100;
  width: 44px; height: 44px; border-radius: 50%; padding: 0;
  font-size: 1.2rem; line-height: 1;
  background: rgba(255,255,255,0.12); backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.18); color: #fff;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3); cursor: pointer;
  transition: transform 0.15s, background 0.15s;
}
#theme-toggle:hover { transform: scale(1.1); background: rgba(255,255,255,0.2); filter: none; }

/* ---- dark mode — shared rules (extracted so both triggers can reuse) ---- */
.dark-rules {
  --card: #111827; --card-line: rgba(255,255,255,0.08);
  --ink: #f1f5f9; --ink-soft: #94a3b8; --muted-ink: #64748b;
  --line: rgba(255,255,255,0.09);
}

/* system dark + not manually forced light */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --card: #111827; --card-line: rgba(255,255,255,0.08);
    --ink: #f1f5f9; --ink-soft: #94a3b8; --muted-ink: #64748b;
    --line: rgba(255,255,255,0.09);
  }
  :root:not([data-theme="light"]) body { background: #060a14; }
  :root:not([data-theme="light"]) select,
  :root:not([data-theme="light"]) input { background: #1e2a3e; color: var(--ink); border-color: rgba(255,255,255,0.12); }
  :root:not([data-theme="light"]) .btn-ghost { background: #1e2a3e; color: var(--ink-soft); border-color: rgba(255,255,255,0.1); }
  :root:not([data-theme="light"]) .btn-ghost:hover { background: #263348; }
  :root:not([data-theme="light"]) .status,
  :root:not([data-theme="light"]) .cap-body { background: #0e1626; border-color: rgba(255,255,255,0.08); }
  :root:not([data-theme="light"]) .metric,
  :root:not([data-theme="light"]) .lab-metric { background: #0e1626; }
  :root:not([data-theme="light"]) .lab-metric.hero { background: linear-gradient(135deg,#1e2060,#0e2040); }
  :root:not([data-theme="light"]) .lat.good { background: #0a2e1c; color: #34d399; }
  :root:not([data-theme="light"]) .lat.ok { background: #2a1e06; color: #fbbf24; }
  :root:not([data-theme="light"]) .lat.bad { background: #2a0e0e; color: #f87171; }
  :root:not([data-theme="light"]) .lat.relay { background: #0e1e40; color: #60a5fa; }
  :root:not([data-theme="light"]) .cap-empty { color: var(--muted-ink); }
  :root:not([data-theme="light"]) .waiting { background: #2a1e06; border-color: #92400e; color: #fcd34d; }
  :root:not([data-theme="light"]) .skeleton { background: linear-gradient(90deg,#1e2a3e 25%,#263348 50%,#1e2a3e 75%); }
  :root:not([data-theme="light"]) .chip { background: #1e2a3e; color: var(--ink-soft); }
  :root:not([data-theme="light"]) .chip.eng { background: #1e2040; color: #818cf8; }
  :root:not([data-theme="light"]) .role { background: #1e2a3e; color: var(--ink); border-color: rgba(255,255,255,0.1); }
  :root:not([data-theme="light"]) .role:hover { border-color: rgba(255,255,255,0.22); background: #263348; }
  :root:not([data-theme="light"]) .role .t { color: #f1f5f9; }
  :root:not([data-theme="light"]) .role.sel-speaker { background: #0e1e40; border-color: var(--speaker); }
  :root:not([data-theme="light"]) .role.sel-listener { background: #0a2e1c; border-color: var(--listener); }
  :root:not([data-theme="light"]) .hist-table th,
  :root:not([data-theme="light"]) .hist-table td { border-color: rgba(255,255,255,0.08); }
}

/* manually forced dark (overrides system light) */
:root[data-theme="dark"] {
  --card: #111827; --card-line: rgba(255,255,255,0.08);
  --ink: #f1f5f9; --ink-soft: #94a3b8; --muted-ink: #64748b;
  --line: rgba(255,255,255,0.09);
}
:root[data-theme="dark"] body { background: #060a14; }
:root[data-theme="dark"] select,
:root[data-theme="dark"] input { background: #1e2a3e; color: var(--ink); border-color: rgba(255,255,255,0.12); }
:root[data-theme="dark"] .btn-ghost { background: #1e2a3e; color: var(--ink-soft); border-color: rgba(255,255,255,0.1); }
:root[data-theme="dark"] .btn-ghost:hover { background: #263348; }
:root[data-theme="dark"] .status,
:root[data-theme="dark"] .cap-body { background: #0e1626; border-color: rgba(255,255,255,0.08); }
:root[data-theme="dark"] .metric,
:root[data-theme="dark"] .lab-metric { background: #0e1626; }
:root[data-theme="dark"] .lab-metric.hero { background: linear-gradient(135deg,#1e2060,#0e2040); }
:root[data-theme="dark"] .lat.good { background: #0a2e1c; color: #34d399; }
:root[data-theme="dark"] .lat.ok { background: #2a1e06; color: #fbbf24; }
:root[data-theme="dark"] .lat.bad { background: #2a0e0e; color: #f87171; }
:root[data-theme="dark"] .lat.relay { background: #0e1e40; color: #60a5fa; }
:root[data-theme="dark"] .cap-empty { color: var(--muted-ink); }
:root[data-theme="dark"] .waiting { background: #2a1e06; border-color: #92400e; color: #fcd34d; }
:root[data-theme="dark"] .skeleton { background: linear-gradient(90deg,#1e2a3e 25%,#263348 50%,#1e2a3e 75%); }
:root[data-theme="dark"] .chip { background: #1e2a3e; color: var(--ink-soft); }
:root[data-theme="dark"] .chip.eng { background: #1e2040; color: #818cf8; }
:root[data-theme="dark"] .role { background: #1e2a3e; color: var(--ink); border-color: rgba(255,255,255,0.1); }
:root[data-theme="dark"] .role:hover { border-color: rgba(255,255,255,0.22); background: #263348; }
:root[data-theme="dark"] .role .t { color: #f1f5f9; }
:root[data-theme="dark"] .role.sel-speaker { background: #0e1e40; border-color: var(--speaker); }
:root[data-theme="dark"] .role.sel-listener { background: #0a2e1c; border-color: var(--listener); }
:root[data-theme="dark"] .hist-table th,
:root[data-theme="dark"] .hist-table td { border-color: rgba(255,255,255,0.08); }

/* light mode forced via toggle */
:root[data-theme="light"] { color-scheme: light; }

/* ---- animations ---- */
@keyframes fade-up { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes fade-down { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }
@keyframes pulse-dot { 0% { box-shadow: 0 0 0 0 rgba(34,197,94,0.5); } 70% { box-shadow: 0 0 0 7px rgba(34,197,94,0); } 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); } }
@keyframes live-glow { 0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.4); } 50% { box-shadow: 0 0 0 8px rgba(239,68,68,0); } }
@keyframes eq { 0%,100% { height: 4px; } 50% { height: 16px; } }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
