:root {
  --bg: #f3efe7;
  --paper: #fdfbf7;
  --line: #dfd6c8;
  --line-deep: #cdbfa9;
  --text: #26211b;
  --muted: #8d8376;
  --brand: #b8521b;
  --brand-2: #8f3f14;
  --accent: #211b16;
  --accent-soft: #f4eadf;
  --hard: #f5dfbe;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Inter", "PingFang SC", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 50% 0%, rgba(214, 168, 110, 0.14) 0%, transparent 30%),
    linear-gradient(180deg, #efe9de 0%, #f4f0e7 42%, #f7f4ed 100%);
}

.container {
  max-width: 1920px;
  margin: 0 auto;
  padding: 40px 48px 56px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 28px;
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 18px;
}

.brand-mark {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: linear-gradient(140deg, #d77241 0%, #9d4618 100%);
  color: #fff;
  display: grid;
  place-items: center;
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 34px;
  font-weight: 700;
  box-shadow: 0 10px 26px rgba(157, 70, 24, 0.2);
}

.brand-copy {
  min-width: 0;
}

h1 {
  margin: 0;
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 32px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.03em;
}

.hero-sub {
  margin: 6px 0 0;
  color: var(--muted);
  font-family: "JetBrains Mono", monospace;
  font-size: 13px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

h2 {
  margin: 0 0 12px;
  font-size: 20px;
}

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 28px 32px;
  box-shadow: 0 2px 10px rgba(61, 51, 34, 0.05);
}

.controls,
.library-panel {
  margin-bottom: 14px;
}

.processing-panel {
  margin-bottom: 14px;
}

.hidden {
  display: none !important;
}

.field-label {
  display: block;
  margin-bottom: 14px;
  color: var(--muted);
  font-family: "JetBrains Mono", monospace;
  font-size: 14px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

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

.row.small {
  margin-top: 14px;
}

.ingest-row {
  align-items: stretch;
}

input,
select,
button {
  border: 1px solid #d8cebf;
  border-radius: 20px;
  padding: 18px 22px;
  font-size: 16px;
}

input,
select {
  width: 100%;
  background: #fff;
  font-family: "JetBrains Mono", monospace;
}

input:focus,
select:focus {
  outline: none;
  border-color: #8fb4ff;
  box-shadow: 0 0 0 3px rgba(47, 118, 255, 0.15);
}

input[type="checkbox"] {
  width: auto;
}

button {
  cursor: pointer;
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
  letter-spacing: -0.01em;
}

button.secondary,
.link-btn {
  color: var(--text);
  background: #fff;
  border-color: #d9cfbf;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(72, 58, 37, 0.06);
}

.link-btn {
  padding: 14px 18px;
  border-radius: 18px;
  font-size: 15px;
}

#processBtn {
  min-width: 196px;
  border-radius: 20px;
  background: #211b16;
  border-color: #211b16;
}

#clearHistoryBtn {
  padding-left: 18px;
  padding-right: 18px;
}

.hint,
.level-hint,
.status {
  font-size: 13px;
  color: var(--muted);
}

.status {
  margin-top: 18px;
  border-top: 1px dashed #e4d9cb;
  padding-top: 16px;
}

.ingest-sub {
  display: flex;
  gap: 28px;
  margin-top: 24px;
  flex-wrap: wrap;
}

.ingest-sub .sub-item {
  flex: 1 1 240px;
  padding-bottom: 18px;
  border-bottom: 1px solid #e8dece;
  font-size: 14px;
  color: var(--muted);
}

.processing-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}

.processing-message {
  font-size: 13px;
  color: var(--muted);
}

.processing-steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.proc-step {
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 8px;
  align-items: start;
}

.proc-marker {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid #d8cebf;
  display: grid;
  place-items: center;
  background: #fff;
  color: #697182;
  font-size: 12px;
}

.proc-step.active .proc-marker {
  background: #28303a;
  color: #fff;
  border-color: #28303a;
}

.proc-step.done .proc-marker {
  background: #5a7a3e;
  color: #fff;
  border-color: #5a7a3e;
}

.proc-name {
  font-size: 14px;
  font-weight: 600;
}

.proc-meta {
  margin-top: 2px;
  font-size: 11px;
  color: var(--muted);
}

.proc-progress {
  margin-top: 6px;
  height: 3px;
  background: #e8e0d2;
  border-radius: 3px;
  overflow: hidden;
}

.proc-progress > div {
  width: 0%;
  height: 100%;
  background: var(--brand);
  transition: width 180ms;
}

.status-main {
  color: #374151;
  font-size: 14px;
}

.status-meta {
  margin-top: 4px;
}

.library-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 18px;
}

.library-header h2 {
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 22px;
  font-weight: 700;
}

.library-summary {
  color: var(--muted);
  font-family: "JetBrains Mono", monospace;
  font-size: 13px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.library-list {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.library-item {
  display: block;
  border: 1px solid var(--line);
  background: #fffdf9;
  border-radius: 26px;
  padding: 18px 18px 16px;
  box-shadow: 0 2px 10px rgba(61, 51, 34, 0.03);
}

.library-item.current {
  border-color: #cf7442;
  box-shadow: 0 0 0 2px rgba(207, 116, 66, 0.16);
}

.library-thumb {
  height: 128px;
  border-radius: 16px;
  margin-bottom: 16px;
  position: relative;
  overflow: hidden;
}

.library-thumb::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    45deg,
    rgba(255, 255, 255, 0.14) 0 8px,
    transparent 8px 16px
  );
}

.library-duration {
  position: absolute;
  right: 8px;
  bottom: 6px;
  z-index: 2;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.66);
  color: #fff;
  font-size: 10px;
}

.library-cached {
  position: absolute;
  left: 8px;
  top: 8px;
  z-index: 2;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.9);
  color: #364152;
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.library-title {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.35;
  margin-bottom: 10px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 52px;
}

.library-meta {
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 14px;
}

.library-actions {
  display: flex;
  gap: 8px;
  align-items: stretch;
  flex-wrap: wrap;
}

.layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.panel-titlebar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: -28px -32px 22px;
  padding: 22px 32px 18px;
  border-bottom: 1px solid #e7ddce;
}

.panel-titlebar h2 {
  margin: 0;
  font-family: "JetBrains Mono", monospace;
  font-size: 19px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #72685c;
}

.panel-meta {
  color: var(--muted);
  font-family: "JetBrains Mono", monospace;
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.subtitle-head {
  display: grid;
  gap: 6px;
}

.subtitle-summary {
  margin: 0;
  color: var(--muted);
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.audio-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(260px, 0.9fr);
  gap: 18px;
  align-items: center;
}

#audioPlayer {
  display: none;
}

.audio-shell {
  display: grid;
  gap: 26px;
}

.audio-hero {
  display: grid;
  grid-template-columns: 144px minmax(0, 1fr);
  gap: 26px;
  align-items: start;
}

.audio-cover {
  width: 144px;
  height: 144px;
  border-radius: 20px;
  background: linear-gradient(135deg, #d9826b 0%, #b75b1d 45%, #a85a00 100%);
  position: relative;
  overflow: hidden;
}

.audio-cover::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    45deg,
    rgba(92, 38, 7, 0.16) 0 12px,
    transparent 12px 24px
  );
}

.audio-copy {
  min-width: 0;
  padding-top: 6px;
}

.audio-title {
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 32px;
  font-weight: 700;
  line-height: 1.18;
  letter-spacing: -0.03em;
  color: #2a241d;
  margin-bottom: 12px;
}

.audio-channel {
  font-size: 20px;
  line-height: 1.3;
  color: #7f7669;
  margin-bottom: 10px;
}

.audio-url {
  font-family: "JetBrains Mono", monospace;
  font-size: 14px;
  line-height: 1.4;
  color: #a09689;
  word-break: break-all;
}

.waveform {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 140px;
  padding: 2px 4px 0;
  cursor: pointer;
}

.wave-bar {
  width: 3px;
  border-radius: 999px;
  background: #d2c5b0;
  flex: 0 0 auto;
  transition: background 120ms ease, transform 120ms ease;
}

.wave-bar.played {
  background: #c75a17;
}

.wave-bar.current {
  background: #2a241d;
  transform: scaleY(1.08);
}

.wave-bar.real {
  background: #d4c9b7;
}

.wave-time {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: -8px;
  color: #756b60;
  font-family: "JetBrains Mono", monospace;
  font-size: 16px;
}

.audio-controls-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.transport-group {
  display: flex;
  align-items: center;
  gap: 16px;
}

.transport-btn {
  min-width: 112px;
  min-height: 54px;
  padding: 0 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border-radius: 18px;
  font-family: "JetBrains Mono", monospace;
  font-size: 18px;
  letter-spacing: -0.01em;
}

.transport-icon {
  font-size: 14px;
  letter-spacing: -0.18em;
  transform: translateY(-1px);
}

.play-btn {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  border: 1px solid #211b16;
  background: #211b16;
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 34px;
  line-height: 1;
  box-shadow: 0 10px 20px rgba(33, 27, 22, 0.12);
}

.rate-pill {
  display: inline-flex;
  align-items: center;
  gap: 0;
  padding: 0;
  border: 1px solid #d9cebd;
  border-radius: 20px;
  overflow: hidden;
  background: #fff;
}

.rate-pill button {
  border: none;
  border-radius: 0;
  background: transparent;
  color: #746a5f;
  padding: 18px 24px;
  font-family: "JetBrains Mono", monospace;
  font-size: 16px;
  font-weight: 400;
}

.rate-pill button.active {
  background: #211b16;
  color: #fff;
}

.sync-panel {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: #fcf9f4;
  padding: 24px 28px 26px;
}

.sync-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  color: #807566;
  font-family: "JetBrains Mono", monospace;
  font-size: 16px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.sync-value {
  font-variant-numeric: tabular-nums;
  color: #211b16;
}

input[type="range"] {
  border: none;
  padding: 0;
  background: transparent;
}

#subtitleOffset::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: #d1c5b4;
}

#subtitleOffset::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 28px;
  height: 28px;
  margin-top: -11px;
  border-radius: 50%;
  background: #211b16;
  cursor: pointer;
}

.audio-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
  margin-top: 6px;
  padding-top: 34px;
  border-top: 1px dashed #ddd0bc;
}

.audio-stat {
  display: grid;
  gap: 8px;
}

.audio-stat-value {
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 56px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.04em;
  color: #211b16;
}

.audio-stat.accent .audio-stat-value {
  color: #c75a17;
}

.audio-stat-label {
  color: #7f7569;
  font-family: "JetBrains Mono", monospace;
  font-size: 16px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.subtitle-track {
  margin: 0 0 18px;
  height: 4px;
  border-radius: 999px;
  background: #ece3d6;
  overflow: hidden;
}

.subtitle-read-progress {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #c35a1e 0%, #221c16 100%);
  transition: width 160ms ease;
}

.subtitle-list {
  max-height: 62vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fffdfa;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.subtitle-item {
  display: grid;
  grid-template-columns: 116px minmax(0, 1fr);
  gap: 18px;
  padding: 20px 22px;
  border-bottom: 1px solid #efe7da;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease;
}

.subtitle-item:last-child {
  border-bottom: none;
}

.subtitle-item:hover {
  background: #faf6ef;
}

.subtitle-item.active {
  background: #f8efe5;
  box-shadow: inset 3px 0 0 #211b16;
}

.subtitle-item.hard-sentence {
  background: linear-gradient(180deg, #fff8eb 0%, #fffdf8 100%);
}

.subtitle-empty {
  padding: 14px;
  color: var(--muted);
}

.time {
  color: #95897a;
  font-family: "JetBrains Mono", monospace;
  font-size: 13px;
  margin-bottom: 0;
  padding-top: 4px;
}

.subtitle-text {
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 24px;
  line-height: 1.58;
  color: #2a241d;
  text-wrap: pretty;
}

.subtitle-text.speaker::before {
  content: attr(data-speaker);
  display: inline-block;
  margin-right: 12px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #f2e8da;
  color: #807465;
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  vertical-align: middle;
}

.hard-word {
  background: linear-gradient(to top, var(--hard) 58%, transparent 58%);
  border-radius: 4px;
}

.level-pill-wrap {
  display: flex;
  align-items: center;
  gap: 14px;
}

.level-label {
  color: var(--muted);
  font-family: "JetBrains Mono", monospace;
  font-size: 13px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.level-pill {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  border: 1px solid #d9cebd;
  border-radius: 999px;
  background: #fff;
}

.level-pill button {
  border: none;
  background: transparent;
  color: #6f6559;
  padding: 8px 14px;
  border-radius: 999px;
  font-family: "JetBrains Mono", monospace;
  font-size: 14px;
}

.level-pill button.active {
  background: #211b16;
  color: #fff;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

.review-btn,
.tweaks-btn {
  min-height: 54px;
  padding: 0 22px;
}

.review-btn {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

.tweaks-btn {
  font-weight: 600;
}

.popup {
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: min(430px, calc(100vw - 24px));
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 20px 42px rgba(0, 0, 0, 0.18);
  z-index: 20;
}

.popup h3 {
  margin: 0 0 10px;
}

.popup.hidden {
  display: none;
}

@media (max-width: 960px) {
  .container {
    padding: 20px 16px 40px;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .audio-toolbar {
    grid-template-columns: 1fr;
  }

  .audio-hero {
    grid-template-columns: 1fr;
  }

  .audio-cover {
    width: 112px;
    height: 112px;
  }

  .audio-title {
    font-size: 24px;
  }

  .audio-channel {
    font-size: 16px;
  }

  .audio-controls-row {
    flex-direction: column;
    align-items: stretch;
  }

  .transport-group {
    justify-content: center;
  }

  .rate-pill {
    width: 100%;
    justify-content: stretch;
  }

  .rate-pill button {
    flex: 1 1 0;
    padding-left: 0;
    padding-right: 0;
  }

  .audio-stats {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .subtitle-item {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .processing-steps {
    grid-template-columns: 1fr;
  }

  .library-list {
    grid-template-columns: 1fr;
  }

  .row {
    flex-wrap: wrap;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  h1 {
    font-size: 26px;
  }

  .subtitle-text {
    font-size: 18px;
  }
}
