:root {
  --bg: #eef3ed;
  --panel: rgba(255, 255, 255, 0.9);
  --panel-solid: #ffffff;
  --panel-soft: #f8faf7;
  --text: #17211b;
  --muted: #68766c;
  --border: #dfe7dd;
  --sage: #456b51;
  --sage-deep: #173525;
  --gold: #b8872d;
  --caption-size: 31px;
  --shadow: 0 18px 48px rgba(42, 63, 47, 0.13);
}

body.dark {
  --bg: #101410;
  --panel: rgba(27, 33, 28, 0.92);
  --panel-solid: #1d251f;
  --panel-soft: #252e27;
  --text: #f3f6f2;
  --muted: #b8c3b7;
  --border: #343e35;
  --sage: #a9c5a8;
  --sage-deep: #dfeee0;
  --gold: #d8ad56;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  font-family: "Segoe UI", Arial, Helvetica, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(184, 205, 181, 0.58), transparent 34rem),
    linear-gradient(145deg, rgba(255, 255, 255, 0.72), transparent 42rem),
    var(--bg);
  color: var(--text);
}

body.dark {
  background:
    radial-gradient(circle at top left, rgba(140, 173, 131, 0.16), transparent 34rem),
    linear-gradient(145deg, rgba(197, 154, 69, 0.07), transparent 40rem),
    var(--bg);
}

button,
input {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

.viewer-shell {
  width: min(880px, 100%);
  margin: 0 auto;
  min-height: 100vh;
  padding: max(18px, env(safe-area-inset-top)) clamp(16px, 4vw, 30px) var(--toolbar-clearance, calc(112px + env(safe-area-inset-bottom)));
}

.viewer-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 14px;
  padding: 10px 0 16px;
  backdrop-filter: blur(18px);
}

.viewer-brand {
  display: flex;
  width: 100%;
  min-width: 0;
  align-items: flex-start;
  gap: 12px;
}

.viewer-brand > div {
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

.viewer-brand img {
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  border-radius: 13px;
  box-shadow: 0 12px 28px rgba(28, 55, 36, 0.18);
}

.app-name {
  margin: 0 0 2px;
  color: var(--sage);
  font-size: 13px;
  font-weight: 850;
}

h1 {
  margin: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: normal;
  hyphens: auto;
  color: var(--text);
  font-size: clamp(20px, 6vw, 38px);
  line-height: 1.06;
  letter-spacing: 0;
}

.status-pill {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
  box-shadow: 0 8px 24px rgba(42, 63, 47, 0.08);
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #9aa39b;
}

.status-pill.waiting .status-dot {
  background: #d29b2f;
  animation: pulseDot 1.35s ease-in-out infinite;
}

.status-pill.live .status-dot {
  background: #19a05f;
  animation: pulseDot 1.15s ease-in-out infinite;
}

.status-pill.live {
  color: #0f7a46;
  background: #dff7e9;
}

body.dark .status-pill.live {
  color: #b7f4ce;
  background: #183f29;
}

@keyframes pulseDot {
  0%, 100% { box-shadow: 0 0 0 0 rgba(25, 160, 95, 0.22); transform: scale(1); }
  50% { box-shadow: 0 0 0 8px rgba(25, 160, 95, 0); transform: scale(1.12); }
}

.state-panel {
  display: grid;
  min-height: 45vh;
  place-items: center;
  align-content: center;
  text-align: center;
  padding: clamp(26px, 8vw, 70px) 18px;
  color: var(--muted);
}

.state-panel.hidden {
  display: none;
}

.state-panel h2 {
  margin: 12px 0 8px;
  color: var(--text);
  font-size: clamp(28px, 7vw, 52px);
  line-height: 1.1;
}

.state-panel p {
  max-width: 560px;
  margin: 0;
  font-size: clamp(16px, 3vw, 20px);
  line-height: 1.5;
}

.waiting-dots {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  justify-content: center;
}

.waiting-dots.hidden {
  display: none;
}

.waiting-dots span {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--gold);
  animation: waitingDot 1.2s ease-in-out infinite;
}

.waiting-dots span:nth-child(2) { animation-delay: .12s; }
.waiting-dots span:nth-child(3) { animation-delay: .24s; }

@keyframes waitingDot {
  0%, 100% { opacity: .38; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(-5px); }
}

.captions {
  display: grid;
  gap: 16px;
}

.caption-line {
  max-width: 840px;
  width: 100%;
  font-size: var(--caption-size);
  line-height: 1.42;
  margin: 0 auto;
  padding: clamp(13px, 3vw, 20px) clamp(14px, 4vw, 24px);
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
  transition: opacity 0.2s ease;
}

.caption-line p {
  margin: 0;
}

.caption-line.provisional {
  border: 0;
  opacity: 0.86;
}

.caption-line.new {
  animation: captionIn 0.22s ease both;
}

@keyframes captionIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.jump-latest {
  position: fixed;
  right: 18px;
  bottom: calc(var(--toolbar-clearance, 112px) - 4px);
  z-index: 30;
  width: auto;
  min-height: 42px;
  padding: 10px 16px;
  border: 0;
  border-radius: 999px;
  background: var(--sage);
  color: #fff;
  font-weight: 850;
  box-shadow: 0 16px 36px rgba(30, 57, 35, 0.22);
}

.hidden {
  display: none !important;
}

.bottom-toolbar {
  position: fixed;
  left: 50%;
  bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(var(--toolbar-columns, 3), minmax(0, 1fr));
  gap: 3px;
  width: min(420px, calc(100% - 16px));
  transform: translateX(-50%);
  padding: 6px;
  border-radius: 21px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--panel-solid) 86%, transparent);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
}

.toolbar-button {
  display: grid;
  justify-items: center;
  gap: 3px;
  min-width: 0;
  min-height: 58px;
  padding: 4px 2px;
  border: 0;
  border-radius: 15px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
}

.toolbar-button:active,
.toolbar-button:focus-visible {
  background: var(--panel-soft);
  color: var(--text);
}

.toolbar-icon {
  display: grid;
  width: 31px;
  height: 31px;
  place-items: center;
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--sage-deep);
  font-size: 17px;
  font-weight: 850;
}

.toolbar-icon svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.text-icon {
  font-size: 16px;
}

.flag-icon {
  overflow: hidden;
}

.flag-icon img {
  width: 25px;
  height: 17px;
  object-fit: cover;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1);
}

.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(13, 20, 15, 0.36);
  opacity: 0;
  transition: opacity .18s ease;
}

.sheet-overlay.open {
  opacity: 1;
}

.bottom-sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 60;
  width: min(560px, 100%);
  transform: translate(-50%, 102%);
  padding: 10px 20px calc(22px + env(safe-area-inset-bottom));
  border-radius: 26px 26px 0 0;
  border: 1px solid var(--border);
  background: var(--panel-solid);
  color: var(--text);
  box-shadow: 0 -20px 54px rgba(13, 20, 15, 0.22);
  transition: transform .22s ease;
}

.bottom-sheet.open {
  transform: translate(-50%, 0);
}

.sheet-handle {
  width: 46px;
  height: 5px;
  margin: 2px auto 16px;
  border-radius: 999px;
  background: var(--border);
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.sheet-header h2 {
  margin: 0;
  font-size: 22px;
}

.sheet-close {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--text);
  font-size: 24px;
  line-height: 1;
}

.slider-field {
  display: grid;
  gap: 12px;
  margin: 0 0 20px;
  color: var(--text);
  font-weight: 850;
}

input[type="range"] {
  width: 100%;
  min-height: 42px;
  accent-color: var(--sage);
}

.sheet-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px;
  border-radius: 16px;
  background: var(--panel-soft);
}

.sheet-row p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.switch-button {
  min-width: 72px;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-solid);
  color: var(--muted);
  font-weight: 850;
}

.switch-button.on {
  background: var(--sage);
  color: #fff;
}

.language-list {
  display: grid;
  gap: 10px;
}

.language-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--panel-soft);
  color: var(--text);
  font-size: 17px;
  font-weight: 850;
}

.language-option > span {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.language-option img {
  width: 30px;
  height: 20px;
  object-fit: cover;
  border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1);
}

.language-option strong {
  opacity: 0;
  color: var(--sage);
}

.language-option.selected {
  border-color: color-mix(in srgb, var(--sage) 60%, var(--border));
  background: color-mix(in srgb, var(--sage) 16%, var(--panel-soft));
}

.language-option.selected strong {
  opacity: 1;
}

.listen-copy,
.listen-status {
  color: var(--muted);
  line-height: 1.45;
}

.listen-sheet {
  width: min(440px, 100%);
  padding-top: 8px;
}

.listen-sheet .sheet-handle {
  margin-bottom: 12px;
}

.listen-sheet .sheet-header {
  margin-bottom: 8px;
}

.listen-heading {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
}

.listen-heading-icon {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 999px;
  background: var(--panel-soft);
  font-size: 17px;
}

.listen-heading-icon svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.listen-sheet .sheet-header h2 {
  font-size: 20px;
}

.listen-copy {
  margin: 6px 0 14px;
  font-size: 13px;
}

.listen-status:empty {
  display: none;
}

.listen-status {
  min-height: 20px;
  margin: 9px 2px 0;
  font-size: 12px;
}

.listen-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  width: 100%;
  min-height: 46px;
  border: 0;
  border-radius: 14px;
  background: var(--sage);
  color: #fff;
  font: inherit;
  font-weight: 850;
}

.listen-primary:disabled {
  cursor: wait;
  opacity: .82;
}

.listen-action-icon {
  display: none;
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.listen-action-icon.spinner {
  display: block;
  border: 2px solid rgba(255, 255, 255, .42);
  border-top-color: #fff;
  border-radius: 999px;
  animation: audioSpin .72s linear infinite;
}

.listen-action-icon.waveform {
  display: block;
  background: linear-gradient(90deg, transparent 0 4%, #fff 4% 17%, transparent 17% 26%, #fff 26% 40%, transparent 40% 50%, #fff 50% 65%, transparent 65% 74%, #fff 74% 87%, transparent 87%);
  -webkit-mask: linear-gradient(to bottom, transparent 8%, #000 8% 92%, transparent 92%);
  mask: linear-gradient(to bottom, transparent 8%, #000 8% 92%, transparent 92%);
  animation: audioWave .9s ease-in-out infinite alternate;
}

.listen-action-icon.retry {
  display: block;
  border: 2px solid #fff;
  border-left-color: transparent;
  border-radius: 999px;
}

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

@keyframes audioWave {
  from { transform: scaleY(.58); opacity: .72; }
  to { transform: scaleY(1); opacity: 1; }
}

.toolbar-button.listening .toolbar-icon {
  background: var(--sage);
  color: #fff;
  animation: listenPulse 1.35s ease-in-out infinite;
}

.toolbar-button.connecting .toolbar-icon {
  color: var(--sage);
  animation: audioWave .8s ease-in-out infinite alternate;
}

@keyframes listenPulse {
  50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--sage) 18%, transparent); }
}

@media (max-width: 560px) {
  .viewer-shell {
    padding-left: 14px;
    padding-right: 14px;
  }

  .viewer-brand img {
    width: 42px;
    height: 42px;
  }

  h1 {
    max-width: 100%;
    font-size: clamp(20px, 6vw, 24px);
  }

  .caption-line {
    line-height: 1.48;
  }

  .bottom-toolbar {
    gap: 2px;
    padding: 5px;
  }

  .toolbar-button {
    min-height: 56px;
    font-size: 10px;
  }

  .toolbar-icon {
    width: 29px;
    height: 29px;
  }
}
