:root {
  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  --text-sm: clamp(0.875rem, 0.8rem + 0.35vw, 1rem);
  --text-base: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  --text-lg: clamp(1.125rem, 1rem + 0.75vw, 1.5rem);
  --text-xl: clamp(1.5rem, 1.2rem + 1.25vw, 2.25rem);

  --bg: #14120f;
  --surface: #1c1a16;
  --surface-2: #24211c;
  --border: #35312a;
  --text: #ede6da;
  --muted: #a39a8b;
  --accent: #f2a541;
  --accent-ink: #1a1306;
  --danger: #e06c5a;
  --ok: #8cc084;
  --radius: 14px;
  --font: 'General Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f2ea;
    --surface: #fffdf8;
    --surface-2: #f1ebe0;
    --border: #ddd4c4;
    --text: #221d16;
    --muted: #6d6456;
    --accent: #b8650a;
    --accent-ink: #fffaf2;
    --danger: #b3412f;
    --ok: #3f7d38;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: var(--text-base);
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-size: var(--text-lg); font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: var(--text-sm); font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 20px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo { width: 40px; height: 40px; color: var(--text); flex: none; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: var(--text-sm); }

.engine {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 8px 14px; border: 1px solid var(--border); border-radius: 999px;
  font-family: var(--mono); font-size: var(--text-xs); color: var(--muted);
  max-width: 100%;
}
.top-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.quality { display: inline-flex; align-items: center; gap: 8px; font-size: var(--text-xs); color: var(--muted); }
.quality select {
  font: inherit; font-size: var(--text-xs); color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 999px; padding: 7px 12px;
}
.quality select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--border); flex: none; }
.engine[data-state='loading'] .dot { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
.engine[data-state='ready'] .dot { background: var(--ok); }
.engine[data-state='ready'] { color: var(--text); }
.engine[data-state='error'] .dot { background: var(--danger); }
@keyframes pulse { 50% { opacity: 0.3; } }

.layout {
  display: grid; grid-template-columns: minmax(260px, 340px) 1fr; gap: 20px;
  padding: 24px clamp(16px, 4vw, 40px); max-width: 1200px; margin: 0 auto;
}
@media (max-width: 820px) { .layout { grid-template-columns: 1fr; } .script { order: -1; } }

.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; min-width: 0;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.meta { font-family: var(--mono); font-size: var(--text-xs); color: var(--muted); }

.voice-list { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 8px; }
.voice-list .empty { color: var(--muted); font-size: var(--text-sm); padding: 8px 0; }
.voice {
  display: flex; align-items: center; gap: 4px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2);
  transition: border-color 0.15s ease;
}
.voice.selected { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.voice-pick {
  flex: 1; min-width: 0; text-align: left; background: none; border: 0; color: inherit; cursor: pointer;
  padding: 10px 12px; display: grid; gap: 2px; font: inherit;
}
.vname { font-weight: 600; font-size: var(--text-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vdate { font-size: var(--text-xs); color: var(--muted); }
.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center; flex: none;
  background: none; border: 0; border-radius: 8px; color: var(--muted); cursor: pointer;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { color: var(--text); background: var(--border); }
.icon-btn.danger:hover { color: var(--danger); }

.create { border-top: 1px solid var(--border); padding-top: 14px; }
.create summary { cursor: pointer; font-weight: 600; font-size: var(--text-sm); color: var(--accent); list-style: none; }
.create summary::before { content: '+ '; }
.create[open] summary::before { content: '− '; }
.create summary::-webkit-details-marker { display: none; }
.create-body { display: grid; gap: 12px; margin-top: 12px; }
.hint { margin: 0; font-size: var(--text-xs); color: var(--muted); }
.clip-status { margin: 0; font-size: var(--text-xs); color: var(--muted); font-family: var(--mono); }
audio { width: 100%; height: 40px; }

.field { display: grid; gap: 6px; font-size: var(--text-sm); color: var(--muted); }
.field output { font-family: var(--mono); color: var(--text); margin-left: 6px; }
input[type='text'], textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
}
textarea { min-height: 220px; resize: vertical; font-size: var(--text-base); line-height: 1.6; }
input[type='text']:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
input[type='range'] { width: 100%; accent-color: var(--accent); }

.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin: 18px 0; }
@media (max-width: 560px) { .controls { grid-template-columns: 1fr; } }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.actions { display: flex; gap: 10px; align-items: center; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-size: var(--text-sm); font-weight: 600; text-decoration: none;
  padding: 10px 16px; border-radius: 10px; border: 1px solid transparent; cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease, opacity 0.15s ease;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.07); }
.btn.secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn.secondary:hover { border-color: var(--muted); }
.btn.ghost { background: none; color: var(--muted); border-color: var(--border); }
.btn.ghost:hover { color: var(--text); }
.btn.small { padding: 6px 12px; font-size: var(--text-xs); }
.btn.big { padding: 13px 22px; }
.btn.full { width: 100%; }
.btn.recording { color: var(--danger); border-color: var(--danger); }
.btn:focus-visible, .icon-btn:focus-visible, .voice-pick:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.progress { margin-top: 18px; }
.bar { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--border); }
.bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.3s ease; }
.progress .meta { margin: 8px 0 0; }

.result { display: flex; gap: 10px; align-items: center; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.result audio { flex: 1; min-width: 220px; }

.foot { max-width: 1200px; margin: 0 auto; padding: 0 clamp(16px, 4vw, 40px) 40px; }
.foot p { font-size: var(--text-xs); color: var(--muted); margin: 0; max-width: 80ch; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: var(--text-sm);
  max-width: min(90vw, 520px); transition: opacity 0.2s ease, transform 0.2s ease; z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
