:root {
  --bg: #0f1420;
  --panel: #1a2130;
  --panel-header: #232c40;
  --border: #2d3750;
  --text: #e6ebf5;
  --muted: #8a95ad;
  --accent: #4f8cff;
  --final: #e6ebf5;
  --nonfinal: #8a95ad;
  --green: #35c46a;
  --red: #ff5c5c;
  --font-scale: 1;
  --transcript-size: calc(21px * var(--font-scale));
  --translit-size: calc(18px * var(--font-scale));
  /* One visual row; double this for interleaved wrap spacing. */
  --row-height: calc(1.45 * var(--transcript-size));
}

* {
  box-sizing: border-box;
}

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

body {
  display: flex;
  flex-direction: column;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: var(--panel-header);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.toolbar h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 600;
}

.controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

label {
  color: var(--muted);
  font-size: 14px;
}

select {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 14px;
}

select:disabled,
.font-slider:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.font-slider:disabled::-webkit-slider-thumb,
.font-slider:disabled::-moz-range-thumb {
  cursor: not-allowed;
}

.requires-restart.is-locked,
.requires-restart.is-locked label,
.requires-restart.is-locked .slider-value,
.requires-restart.is-locked .tip {
  opacity: 0.55;
  cursor: not-allowed;
}

.requires-restart.is-locked .tip {
  pointer-events: none;
}

.font-slider {
  width: 110px;
  height: 4px;
  appearance: none;
  -webkit-appearance: none;
  background: var(--border);
  border-radius: 2px;
  cursor: pointer;
}

.font-slider::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

.font-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

.control-with-tip {
  display: flex;
  align-items: center;
  gap: 8px;
}

.control-with-tip label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.slider-value {
  color: var(--muted);
  font-size: 13px;
  min-width: 2.6em;
}

.tip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  cursor: help;
}

.tip-bubble {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: 240px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-header);
  color: var(--text);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.45;
  text-align: left;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
  z-index: 20;
}

.tip:hover .tip-bubble,
.tip:focus .tip-bubble,
.tip:focus-within .tip-bubble {
  opacity: 1;
}

.btn {
  border: none;
  border-radius: 6px;
  padding: 8px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: #fff;
}

.btn-start {
  background: var(--accent);
}

.btn-stop {
  background: var(--red);
}

.btn-clear {
  background: var(--panel);
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.status {
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.status-idle {
  color: var(--muted);
}

.status-live {
  color: var(--green);
  border-color: var(--green);
}

.status-error {
  color: var(--red);
  border-color: var(--red);
}

.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  justify-content: center;
  padding: 16px;
}

.scrollview {
  flex: 1;
  max-width: 900px;
  overflow-y: auto;
  padding: 24px 28px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  word-break: break-word;
}

.empty-hint {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
  text-align: center;
  margin-top: 40px;
}

.empty-hint strong {
  color: var(--accent);
}

/* One utterance. Transcript is always double-spaced; translit overlays in the
   gaps (shifted down one row) so wraps interleave. */
.segment {
  position: relative;
  margin-bottom: 18px;
}

.transcript-line {
  font-size: var(--transcript-size);
  line-height: calc(2 * var(--row-height));
}

.transcript-line .final {
  color: var(--final);
}

.transcript-line .nonfinal {
  color: var(--nonfinal);
}

.translit-line {
  position: absolute;
  left: 0;
  right: 0;
  top: var(--row-height);
  margin: 0;
  font-size: var(--translit-size);
  line-height: calc(2 * var(--row-height));
  color: var(--accent);
  font-style: italic;
  pointer-events: none;
}

.translit-line.hidden {
  display: none;
}

/* Blinking caret shown while the transliteration types itself out. */
.translit-line.typing::after {
  content: '';
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 1px;
  vertical-align: text-bottom;
  background: var(--accent);
  animation: blink 1s step-end infinite;
}

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

/* Shimmering placeholder shown where a transliteration will appear. */
.skeleton {
  display: inline-block;
  width: 45%;
  min-width: 120px;
  height: 0.85em;
  border-radius: 4px;
  background: linear-gradient(
    90deg,
    rgba(79, 140, 255, 0.08) 25%,
    rgba(79, 140, 255, 0.24) 37%,
    rgba(79, 140, 255, 0.08) 63%
  );
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}

@keyframes shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: 0 0;
  }
}
