:root {
  --bg: #0a0a0e;
  --bg-elev: #121218;
  --bg-card: #14141c;
  --line: rgba(232, 176, 75, 0.08);
  --line-strong: rgba(232, 176, 75, 0.18);
  --text: #f0e9d8;
  --text-dim: #9c9585;
  --muted: #6e685c;
  --accent: #e8b04b;
  --accent-soft: rgba(232, 176, 75, 0.14);
  --danger: #e06550;
  --live: #7ed491;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

.app {
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  position: relative;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 10px;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  color: var(--accent);
}

.brand-mark {
  width: 18px;
  height: 18px;
  align-self: center;
  opacity: 0.9;
}

.brand-name {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text);
  white-space: nowrap;
}

.brand-sub {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  transition: background 0.3s;
}

.status[data-state="listening"] .status-dot {
  background: var(--live);
  box-shadow: 0 0 8px rgba(126, 212, 145, 0.7);
  animation: pulse 1.6s ease-in-out infinite;
}

.status[data-state="connecting"] .status-dot,
.status[data-state="syncing"] .status-dot {
  background: var(--accent);
  animation: pulse 0.8s ease-in-out infinite;
}

.status[data-state="error"] .status-dot,
.status[data-state="disconnected"] .status-dot {
  background: var(--danger);
}

@keyframes pulse {
  50% { opacity: 0.4; }
}

.status-time {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  padding-left: 4px;
  border-left: 1px solid var(--line-strong);
  margin-left: 2px;
}

/* ---------- controls ---------- */

.movie-row {
  padding: 2px 18px 0;
}

.movie-pick {
  width: 100%;
}

.movie-pick select {
  width: 100%;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 18px 12px;
  flex-wrap: wrap;
}

.lang-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.lang {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.lang-caption {
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  padding-left: 2px;
}

.lang select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg-elev) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%236e685c' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 10px center;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  padding: 8px 28px 8px 12px;
  outline: none;
  min-width: 118px;
}

.lang select:focus-visible {
  border-color: var(--accent);
}

.lang-arrow {
  color: var(--accent);
  font-size: 15px;
  margin-top: 14px;
  opacity: 0.75;
}

.btn-main {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--accent);
  color: #191307;
  border: none;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 650;
  letter-spacing: 0.02em;
  padding: 11px 20px;
  cursor: pointer;
  transition: transform 0.12s, background 0.25s, color 0.25s, box-shadow 0.25s;
  box-shadow: 0 2px 18px rgba(232, 176, 75, 0.25);
}

.btn-main:active { transform: scale(0.96); }

.btn-icon {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #191307;
  transition: border-radius 0.25s, background 0.25s;
}

.btn-main.recording {
  background: rgba(224, 101, 80, 0.14);
  color: var(--danger);
  box-shadow: inset 0 0 0 1px rgba(224, 101, 80, 0.45);
}

.btn-main.recording .btn-icon {
  border-radius: 2.5px;
  background: var(--danger);
}

.spend {
  text-align: center;
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 0 18px 8px;
  font-family: var(--mono);
}

/* ---------- visualizer ---------- */

.visualizer {
  height: 84px;
  padding: 0 18px;
  position: relative;
}

.visualizer::after {
  content: "";
  position: absolute;
  inset: auto 18px 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--line-strong), transparent);
}

#viz {
  width: 100%;
  height: 100%;
  display: block;
}

/* ---------- caption feed ---------- */

.feed {
  flex: 1;
  overflow-y: auto;
  padding: 18px 18px calc(28px + env(safe-area-inset-bottom));
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

/* Once captions exist, anchor them to the bottom like real subtitles. */
.feed.has-content {
  display: flex;
  flex-direction: column;
}

.feed.has-content::before {
  content: "";
  flex: 1 0 auto;
}

.empty-state {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  color: var(--muted);
  padding: 0 24px;
}

.empty-icon {
  width: 34px;
  height: 34px;
  color: var(--accent);
  opacity: 0.5;
  margin-bottom: 4px;
}

.empty-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-dim);
}

.empty-hint {
  font-size: 13.5px;
  line-height: 1.55;
  max-width: 320px;
}

.empty-hint em {
  color: var(--accent);
  font-style: normal;
}

.seg {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  animation: seg-in 0.35s ease;
}

@keyframes seg-in {
  from { opacity: 0; transform: translateY(8px); }
}

.seg time {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--accent);
  opacity: 0.75;
  padding-top: 5px;
  text-align: right;
  letter-spacing: 0.03em;
}

.seg-texts {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.seg .orig {
  font-size: 13.5px;
  line-height: 1.5;
  font-style: italic;
  color: var(--text-dim);
  overflow-wrap: break-word;
}

.seg .trans {
  font-size: clamp(16px, 4.4vw, 19px);
  line-height: 1.45;
  font-weight: 500;
  color: var(--text);
  overflow-wrap: break-word;
}

.seg.live .orig::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 0.95em;
  background: var(--accent);
  margin-left: 3px;
  vertical-align: text-bottom;
  animation: blink 0.9s step-end infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

.trans.pending {
  color: var(--muted);
  font-weight: 400;
}

.trans.pending .dots span {
  animation: dot 1.2s infinite;
  display: inline-block;
}

.trans.pending .dots span:nth-child(2) { animation-delay: 0.2s; }
.trans.pending .dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot {
  0%, 60%, 100% { opacity: 0.25; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-2px); }
}

.trans.failed {
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 400;
}

/* ---------- jump to live ---------- */

.jump-live {
  position: absolute;
  bottom: calc(22px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  color: #191307;
  border: none;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
  box-shadow: 0 4px 22px rgba(0, 0, 0, 0.55);
  animation: seg-in 0.25s ease;
}

.jump-live svg { width: 13px; height: 13px; }

/* ---------- resync ---------- */

.resync {
  position: absolute;
  bottom: calc(22px + env(safe-area-inset-bottom));
  right: 16px;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-elev);
  color: var(--accent);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 22px rgba(0, 0, 0, 0.55);
}

.resync:active { transform: scale(0.95); }

.resync:disabled {
  opacity: 0.45;
  cursor: default;
}

.resync svg { width: 13px; height: 13px; }

.resync.spinning svg {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------- toast ---------- */

.toast {
  position: absolute;
  top: calc(64px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  background: #221512;
  border: 1px solid rgba(224, 101, 80, 0.4);
  color: #f0b9ad;
  font-size: 13px;
  line-height: 1.45;
  padding: 10px 16px;
  border-radius: 12px;
  max-width: min(86vw, 420px);
  z-index: 10;
  box-shadow: 0 6px 30px rgba(0, 0, 0, 0.6);
  animation: seg-in 0.25s ease;
}

@media (max-width: 480px) {
  .controls { justify-content: center; }
  .btn-main { width: 100%; justify-content: center; }
  .brand-sub { display: none; }
}
