/* styles.css — dark, high-contrast, mobile-first subtitle UI. */

:root {
  --bg: #0b0d12;
  --panel: #141821;
  --panel-2: #1c2230;
  --border: #2a3142;
  --text: #f4f6fb;
  --muted: #8a93a6;
  --dim: #b8c0d0;
  --accent: #3ba0ff;
  --accent-2: #2b7fe0;
  --danger: #ff5a5a;
  --warn: #ffcc55;
  --rec: #ff3b3b;
  --good: #4ade80;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  /* Respect notches / safe areas on phones. */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---- Header ---- */
.app-header {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.app-header h1 {
  margin: 0;
  font-size: clamp(1.1rem, 4vw, 1.6rem);
  font-weight: 700;
  letter-spacing: 0.01em;
}

/* ---- Controls ---- */
.controls {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.8rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.lang-row {
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
}

.lang-select {
  flex: 1 1 0;
  min-width: 0;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  padding: 0.7rem 0.6rem;
  font-size: clamp(0.95rem, 3.6vw, 1.1rem);
  font-weight: 600;
  appearance: none;
  -webkit-appearance: none;
}
.lang-select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.swap-btn {
  flex: 0 0 auto;
  width: 3rem;
  background: var(--panel-2);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}
.swap-btn:active { transform: scale(0.94); }

.toggle-btn {
  width: 100%;
  padding: 0.95rem 1rem;
  font-size: clamp(1.1rem, 4.5vw, 1.4rem);
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #fff;
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-2) 100%);
  border: none;
  border-radius: 0.8rem;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(59, 160, 255, 0.35);
  transition: transform 0.05s ease, box-shadow 0.15s ease;
}
.toggle-btn:active { transform: scale(0.985); }
.toggle-btn.recording {
  background: linear-gradient(180deg, #ff5b5b 0%, var(--rec) 100%);
  box-shadow: 0 4px 18px rgba(255, 59, 59, 0.4);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 4px 18px rgba(255, 59, 59, 0.4); }
  50%      { box-shadow: 0 4px 26px rgba(255, 59, 59, 0.7); }
}

/* ---- Status line ---- */
.status {
  padding: 0.45rem 1rem;
  font-size: clamp(0.8rem, 3vw, 0.95rem);
  color: var(--muted);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  min-height: 1.6rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status[data-kind="warn"]  { color: var(--warn); }
.status[data-kind="error"] { color: var(--danger); font-weight: 700; }

/* ---- Subtitles ---- */
.subtitles {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 1rem 1rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  /* Push first lines toward the bottom so early text isn't lonely at the top. */
  justify-content: flex-end;
}

.utt {
  padding: 0.6rem 0.8rem;
  border-radius: 0.7rem;
  background: var(--panel);
  border: 1px solid var(--border);
}

/* Transcript = source text. Translation = target text, slightly larger emphasis. */
.transcript {
  font-size: clamp(1.25rem, 6vw, 2.1rem);
  line-height: 1.25;
  font-weight: 600;
  word-break: break-word;
}
.translation {
  margin-top: 0.35rem;
  font-size: clamp(1.4rem, 7vw, 2.6rem);
  line-height: 1.25;
  font-weight: 800;
  word-break: break-word;
}

/* Interim (not final) text is muted/gray. Final is bright/solid. */
.transcript.interim,
.translation.interim {
  color: var(--muted);
}
.transcript.final {
  color: var(--text);
}
.translation.final {
  color: var(--accent);
}

/* Within an interim transcript: stable prefix bright, unstable tail dimmer. */
.transcript.interim .stable { color: var(--dim); }
.transcript.interim .tail   { color: var(--muted); opacity: 0.75; }

/* Empty rows (prepared on speech_start) shouldn't look broken. */
.transcript:empty::before,
.translation:empty::before {
  content: "";
}

/* Larger screens: cap width and grow the font for projection. */
@media (min-width: 800px) {
  .controls, .status, .subtitles, .app-header {
    width: 100%;
  }
  .subtitles {
    max-width: 1100px;
    margin: 0 auto;
  }
}
