:root {
  color-scheme: light;
  --bg: #f3efe7;
  --ink: #211914;
  --muted: #75695d;
  --line: rgba(55, 42, 32, 0.14);
  --card: rgba(255, 252, 246, 0.86);
  --card-strong: #fffaf1;
  --accent: #9a531f;
  --accent-2: #2563eb;
  --shadow: 0 24px 70px rgba(74, 52, 28, 0.14);
  --radius: 26px;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --font-display: "Songti SC", "STSong", "SimSun", serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--font-ui);
  background:
    linear-gradient(120deg, rgba(37, 99, 235, 0.09), transparent 36%),
    radial-gradient(circle at 88% 8%, rgba(154, 83, 31, 0.13), transparent 28%),
    var(--bg);
}

button,
textarea,
select,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 11px 15px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.62);
  cursor: pointer;
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(72, 52, 38, 0.1);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
  transform: none;
  box-shadow: none;
}

.primary {
  border-color: transparent;
  color: #fff;
  background: linear-gradient(135deg, #a45c24, #743812);
}

.primary.is-stop {
  background: linear-gradient(135deg, #3f6572, #1f3b45);
}

.secondary {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.72);
}

.app {
  width: min(1420px, calc(100vw - 48px));
  margin: 0 auto;
  padding: 46px 0 60px;
}

.hero {
  display: grid;
  grid-template-columns: 1fr minmax(260px, 360px);
  gap: 24px;
  align-items: end;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 14px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(52px, 8vw, 108px);
  line-height: 0.96;
  letter-spacing: 0;
}

.lede {
  max-width: 760px;
  margin: 20px 0 0;
  color: var(--muted);
  font-size: 21px;
  line-height: 1.7;
}

.status-card,
.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.status-card {
  padding: 22px;
}

.status-stack {
  display: grid;
  gap: 12px;
}

.config-toggle {
  justify-self: end;
  min-width: 96px;
}

.status-title {
  margin-bottom: 12px;
  font-size: 18px;
  font-weight: 800;
}

.status-line {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.status-line strong {
  color: var(--ink);
}

.status-control {
  margin-top: 16px;
}

.status-control select {
  background: rgba(255, 255, 255, 0.72);
}

.config-panel {
  margin-bottom: 24px;
}

.config-panel[hidden] {
  display: none;
}

.config-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px 26px;
  align-items: stretch;
}

.config-section {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding-top: 18px;
  border-top: 1px solid rgba(55, 42, 32, 0.1);
}

.config-section h3 {
  margin: 0 0 14px;
  color: var(--ink);
  font-size: 18px;
  line-height: 25px;
}

.config-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  margin-top: 24px;
}

.config-actions .notice {
  margin: 0;
}

.workspace {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px;
  align-items: start;
}

.panel {
  padding: 28px;
}

.top-panel {
  height: 560px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.input-panel textarea {
  flex: 1;
}

.result-panel .markdown {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.script-panel {
  grid-column: 1 / -1;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 18px;
}

h2 {
  margin: 0;
  font-size: 28px;
  line-height: 1.2;
}

.panel-head p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.65;
}

.script-head-actions {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.compact-control {
  width: min(360px, 42vw);
}

.icon-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 22px;
}

textarea {
  width: 100%;
  min-height: 180px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.62);
  outline: none;
  line-height: 1.7;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

textarea::placeholder {
  color: rgba(117, 105, 93, 0.56);
}

textarea:focus,
select:focus,
input[type="text"]:focus,
input[type="password"]:focus,
input[type="number"]:focus {
  border-color: rgba(154, 83, 31, 0.42);
  box-shadow: 0 0 0 4px rgba(154, 83, 31, 0.1);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 16px 0;
}

.single-control {
  grid-template-columns: 1fr;
}

.form-row.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

select,
input[type="text"],
input[type="password"],
input[type="number"] {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.68);
  outline: none;
}

input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.68;
}

.range-row {
  margin: 10px 0 18px;
}

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

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

.script-panel > .actions {
  margin-top: 18px;
}

.markdown {
  padding: 8px 2px 0;
  font-size: 17px;
  line-height: 1.85;
}

.markdown h3 {
  margin: 26px 0 8px;
  font-size: 22px;
}

.markdown p {
  margin: 12px 0;
}

.markdown ul {
  margin: 12px 0;
  padding-left: 1.4em;
}

.markdown code {
  padding: 2px 6px;
  border-radius: 7px;
  color: #0f3f8f;
  background: rgba(37, 99, 235, 0.09);
  font-family: var(--font-mono);
}

.loader {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(154, 83, 31, 0.18);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

audio {
  width: 100%;
  margin-top: 18px;
}

.subtitle-board {
  height: 360px;
  overflow: auto;
  border: 1px solid rgba(55, 42, 32, 0.08);
  border-radius: 20px;
  background: rgba(244, 237, 226, 0.74);
  scroll-behavior: smooth;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.36);
}

.subtitle-empty {
  padding: 22px;
  color: rgba(117, 105, 93, 0.68);
}

.subtitle-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  padding: 16px 18px;
  border-bottom: 1px solid rgba(55, 42, 32, 0.08);
  line-height: 1.7;
  transition: color 0.16s ease;
}

.subtitle-row:last-child {
  border-bottom: 0;
}

.subtitle-en {
  font-weight: 750;
}

.subtitle-zh {
  color: var(--muted);
}

.subtitle-row.is-active .subtitle-en,
.subtitle-row.is-active .subtitle-zh {
  color: var(--accent);
}

.subtitle-row.is-active .subtitle-en {
  font-weight: 850;
}

.subtitle-row.is-active .subtitle-zh {
  font-weight: 750;
}

.notice {
  min-height: 22px;
  margin: 14px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

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

@media (max-width: 980px) {
  .app {
    width: min(100vw - 28px, 760px);
    padding-top: 28px;
  }

  .hero,
  .workspace,
  .form-row,
  .config-grid,
  .form-row.three {
    grid-template-columns: 1fr;
  }

  .panel {
    padding: 22px;
  }

  .top-panel {
    height: auto;
    min-height: 460px;
  }

  .subtitle-board {
    height: 320px;
  }

  .panel-head,
  .script-head-actions {
    align-items: stretch;
  }

  .panel-head {
    flex-direction: column;
  }

  .script-head-actions {
    width: 100%;
  }

  .compact-control {
    width: 100%;
  }

  .subtitle-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}
