:root {
  --ink: #171b21;
  --paper: #f1f2ee;
  --paper-raised: #ffffff;
  --line: #dcded7;
  --muted: #666b6f;
  --accent: #146e67;
  --accent-strong: #0d514c;
  --accent-soft: #dcefec;
  --highlight: #e2932a;
  --highlight-soft: #fbe6c4;
  --highlight-ink: #3e2803;
  --danger: #a8461f;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #e9eae5;
    --paper: #14171b;
    --paper-raised: #1c2025;
    --line: #2c3137;
    --muted: #9aa0a6;
    --accent: #3fb7ac;
    --accent-strong: #7fd9ce;
    --accent-soft: #1c3532;
    --highlight: #f0ab4c;
    --highlight-soft: #3d2c0c;
    --highlight-ink: #ffe7bb;
    --danger: #e2825b;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ink: #e9eae5;
  --paper: #14171b;
  --paper-raised: #1c2025;
  --line: #2c3137;
  --muted: #9aa0a6;
  --accent: #3fb7ac;
  --accent-strong: #7fd9ce;
  --accent-soft: #1c3532;
  --highlight: #f0ab4c;
  --highlight-soft: #3d2c0c;
  --highlight-ink: #ffe7bb;
  --danger: #e2825b;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: "Source Sans 3", "Noto Sans SC", ui-sans-serif, system-ui, sans-serif;
  padding-inline: 20px;
  padding-block: 28px 48px;
  max-width: 1180px;
  margin-inline: auto;
}
h1, h2, h3 { font-family: "Fraunces", "Noto Sans SC", Georgia, serif; text-wrap: balance; margin: 0; }
p { margin: 0; }

header.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  padding-bottom: 22px;
  margin-bottom: 26px;
  border-bottom: 1px solid var(--line);
}
.wordmark-row { display: flex; align-items: center; gap: 14px; }
.wordmark { font-size: 1.9rem; font-weight: 600; letter-spacing: -0.01em; }
.waveform { display: flex; align-items: flex-end; gap: 3px; height: 28px; }
.waveform i {
  display: block; width: 3px; background: var(--accent); border-radius: 2px;
  animation: bob 1.8s ease-in-out infinite;
}
.waveform i:nth-child(1) { height: 10px; animation-delay: -0.1s; }
.waveform i:nth-child(2) { height: 22px; animation-delay: -0.9s; }
.waveform i:nth-child(3) { height: 14px; animation-delay: -0.4s; }
.waveform i:nth-child(4) { height: 26px; animation-delay: -1.3s; }
.waveform i:nth-child(5) { height: 8px;  animation-delay: -0.6s; }
.waveform i:nth-child(6) { height: 18px; animation-delay: -1.6s; }
@keyframes bob { 0%, 100% { transform: scaleY(0.55); } 50% { transform: scaleY(1); } }
@media (prefers-reduced-motion: reduce) { .waveform i { animation: none; } }
.tagline { color: var(--muted); font-size: 0.95rem; max-width: 36ch; }

.lang-toggle {
  display: flex; flex-wrap: wrap; gap: 2px; flex: none;
  border: 1px solid var(--line); border-radius: 999px; padding: 3px;
  background: var(--paper-raised);
}
.lang-toggle button {
  appearance: none; border: none; cursor: pointer; background: transparent; color: var(--muted);
  font-family: "Source Sans 3", "Noto Sans SC", sans-serif; font-size: 0.82rem; font-weight: 600;
  padding: 6px 13px; border-radius: 999px;
}
.lang-toggle button:hover:not([aria-pressed="true"]) { color: var(--ink); }
.lang-toggle button[aria-pressed="true"] { background: var(--accent); color: #fff; }

.layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 26px;
  align-items: start;
}
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  /* On narrow screens, show the transcribed text (results) above the input
     panel -- the DOM order (input first, for tab order) stays unchanged. */
  aside { order: 2; }
  section.results { order: 1; }
}

aside {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  position: sticky;
  top: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
@media (max-width: 860px) { aside { position: static; } }

aside h2 { font-size: 1.05rem; font-weight: 600; }
.field-label { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }

textarea {
  width: 100%;
  min-height: 150px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 13px;
  font-family: "Source Sans 3", sans-serif;
  font-size: 0.98rem;
  line-height: 1.45;
  background: var(--paper);
  color: var(--ink);
}
.title-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 11px;
  font-family: "Source Sans 3", sans-serif;
  font-size: 0.92rem;
  background: var(--paper);
  color: var(--ink);
}
textarea:focus-visible, button:focus-visible, .chip:focus-visible, .title-input:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

.btn {
  appearance: none; border: none; cursor: pointer;
  font-family: "Source Sans 3", sans-serif; font-weight: 600; font-size: 0.95rem;
  border-radius: 9px; padding: 11px 16px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); }
.btn-ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.btn-ghost:hover { border-color: var(--accent); }

.save-row { display: flex; gap: 8px; }
.save-row .btn { flex: none; }
.save-status { font-size: 0.8rem; color: var(--accent); min-height: 1.1em; }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  appearance: none; cursor: pointer; background: var(--paper);
  border: 1px solid var(--line); color: var(--ink);
  border-radius: 999px; padding: 6px 12px; font-size: 0.84rem; font-family: inherit;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-strong); font-weight: 600; }

.saved-list { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; }
.saved-item {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px;
  cursor: pointer; background: var(--paper); text-align: left;
  font-family: inherit; color: var(--ink);
}
.saved-item:hover { border-color: var(--accent); }
.saved-item .meta { flex: 1; min-width: 0; }
.saved-item .preview { display: block; font-size: 0.86rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.saved-item .sub { font-size: 0.72rem; color: var(--muted); margin-top: 2px; text-transform: uppercase; letter-spacing: 0.04em; }
.saved-item .del-btn {
  appearance: none; border: none; background: transparent; color: var(--muted);
  cursor: pointer; font-size: 1rem; line-height: 1; padding: 4px 6px; border-radius: 6px; flex: none;
}
.saved-item .del-btn:hover { color: var(--danger); background: var(--paper-raised); }
.saved-empty { font-size: 0.82rem; color: var(--muted); font-style: italic; }

section.results { display: flex; flex-direction: column; gap: 16px; }

.results-bar { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.detected {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--paper-raised); border: 1px solid var(--line);
  padding: 6px 12px 6px 6px; border-radius: 999px; font-size: 0.86rem;
}
.detected .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.detected b { font-weight: 700; }

.results-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.speed-label {
  font-size: 0.78rem; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.05em;
}

.speed-toggle {
  display: flex; flex-wrap: wrap; gap: 2px;
  border: 1px solid var(--line); border-radius: 999px; padding: 3px;
  background: var(--paper-raised);
}
.speed-toggle button {
  appearance: none; border: none; cursor: pointer; background: transparent; color: var(--muted);
  font-family: "Source Sans 3", sans-serif; font-size: 0.78rem; font-weight: 600;
  padding: 5px 10px; border-radius: 999px; font-variant-numeric: tabular-nums;
}
.speed-toggle button:hover:not([aria-pressed="true"]) { color: var(--ink); }
.speed-toggle button[aria-pressed="true"] { background: var(--accent); color: #fff; }

.tts-note {
  font-size: 0.84rem; color: var(--danger); background: var(--paper-raised);
  border: 1px solid var(--line); border-radius: 9px; padding: 9px 12px; line-height: 1.4;
}
.draft-note {
  font-size: 0.84rem; color: var(--muted); background: var(--paper-raised);
  border: 1px dashed var(--line); border-radius: 9px; padding: 9px 12px; line-height: 1.4;
}

.lines { display: flex; flex-direction: column; }

.line-row { display: flex; gap: 12px; align-items: flex-start; padding-block: 12px; }
.line-row + .line-row { border-top: 1px solid var(--line); }

.play-btn {
  appearance: none; cursor: pointer; border: 1px solid var(--line); background: var(--paper-raised);
  color: var(--accent); border-radius: 50%; width: 34px; height: 34px; flex: none;
  display: flex; align-items: center; justify-content: center; margin-top: 2px;
}
.play-btn:hover { border-color: var(--accent); }
.line-row.playing .play-btn { background: var(--accent); color: #fff; border-color: var(--accent); }
.play-btn:disabled { opacity: 0.6; }

.line-content { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }

.text-row { font-size: 1.28rem; line-height: 1.6; }
.ipa-row {
  font-family: "Gentium Plus", "Doulos SIL", serif;
  font-style: italic;
  font-size: 1.08rem; color: var(--muted); line-height: 1.6;
}

.syll { padding: 0.05em 0.08em; border-radius: 4px; transition: background 0.12s ease, color 0.12s ease; }
.syll.done { opacity: 0.55; }
.syll.active { background: var(--highlight); color: var(--highlight-ink); font-weight: 600; }
.ipa-row .syll.active { background: var(--highlight-soft); color: var(--highlight-ink); font-weight: 600; }
.dot { color: var(--muted); opacity: 0.6; padding: 0 0.02em; }
.ipa-slash { color: var(--muted); opacity: 0.7; }
