:root {
  color-scheme: dark;
  --page: #090b10;
  --surface: #11151d;
  --surface-raised: #171c27;
  --field: #0c1017;
  --line: #2b3342;
  --line-strong: #424d61;
  --text: #f2f4f8;
  --muted: #aab2c2;
  --quiet: #7f899d;
  --violet: #8b7cf6;
  --violet-strong: #7565eb;
  --cyan: #31c6d4;
  --green: #55d39e;
  --amber: #efb35f;
  --red: #ff818d;
  --focus: #b8adff;
  --radius: 14px;
  --shadow: 0 22px 70px rgba(0, 0, 0, .46);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--page); }
body {
  margin: 0;
  min-height: 100vh;
  padding: 24px clamp(16px, 3.5vw, 52px) 36px;
  color: var(--text);
  background:
    radial-gradient(900px 500px at 82% -18%, rgba(103, 82, 214, .2), transparent 64%),
    radial-gradient(700px 480px at -12% 108%, rgba(22, 142, 154, .13), transparent 68%),
    var(--page);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.45;
}
body.auth-open { overflow: hidden; }
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}
a { color: #c8c2ff; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.svg-defs { position: absolute; width: 0; height: 0; overflow: hidden; }
svg { width: 1.1em; height: 1.1em; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.hero {
  max-width: 1240px;
  margin: 0 auto 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.brand { display: flex; align-items: center; gap: 13px; color: inherit; text-decoration: none; }
.logo {
  width: 46px;
  height: 46px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 13px;
  color: #fff;
  background: var(--violet-strong);
  box-shadow: 0 10px 24px rgba(73, 56, 188, .32);
}
.logo svg { width: 25px; height: 25px; stroke-width: 2; }
.brand h1 { margin: 0; font-size: 1.25rem; letter-spacing: -.02em; line-height: 1.2; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: .82rem; }
.account-nav { display: flex; align-items: center; gap: 9px; }
.nav-button {
  min-height: 38px;
  padding: 7px 11px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
}
.nav-button:hover { color: var(--text); background: rgba(255, 255, 255, .055); }
.account-button { display: inline-flex; align-items: center; gap: 7px; }
.credit-meter {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 7px 11px;
  color: #dce1ec;
  background: var(--surface);
  border-radius: 999px;
  font-size: .78rem;
}
.credit-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 3px 10px rgba(85, 211, 158, .36); }

.workspace-bar {
  max-width: 1240px;
  min-height: 56px;
  margin: 0 auto 16px;
  padding: 8px 9px 8px 15px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.project-name-field { flex: 1 1 280px; }
.project-name-field input {
  width: 100%;
  padding: 5px 0;
  color: var(--text);
  background: transparent;
  border: 0;
  font-size: .98rem;
  font-weight: 650;
}
.project-name-field input:focus-visible { outline-offset: 6px; }
.save-state { color: var(--quiet); font-size: .75rem; white-space: nowrap; }
.workspace-actions { display: flex; align-items: center; gap: 7px; }

.layout {
  max-width: 1240px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(340px, 1.15fr) minmax(330px, .85fr);
  grid-template-areas: "script voices" "cast voices" "cast output";
  gap: 16px;
  align-items: start;
}
.script-card { grid-area: script; }
#speakersCard { grid-area: cast; }
.voices-card { grid-area: voices; }
.output-card { grid-area: output; }
.card {
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 13px; }
.card-head h2 { margin: 0; color: #c0c7d5; font-size: .76rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; }
.section-note { color: var(--quiet); font-size: .75rem; }

textarea#script {
  display: block;
  width: 100%;
  min-height: 290px;
  padding: 15px;
  resize: vertical;
  color: #e9edf5;
  caret-color: var(--cyan);
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 11px;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: .87rem;
  line-height: 1.65;
}
textarea#script::placeholder, input::placeholder { color: #6f798c; opacity: 1; }
.meta-row { display: flex; align-items: center; gap: 12px; margin-top: 10px; color: var(--quiet); font-size: .75rem; }
.meta-row #charCount { color: #d4d9e5; }
.meta-row #speakerCount { margin-right: auto; }
select, input[type="text"], input[type="email"], input[type="password"] {
  min-height: 36px;
  padding: 7px 9px;
  color: var(--text);
  background: var(--field);
  border: 1px solid var(--line-strong);
  border-radius: 9px;
}

.ghost-btn, .preview-btn {
  min-height: 34px;
  padding: 6px 11px;
  color: #c5ccda;
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  cursor: pointer;
  text-decoration: none;
  font-size: .78rem;
}
.ghost-btn:hover:not(:disabled), .preview-btn:hover:not(:disabled) { color: #fff; background: rgba(255, 255, 255, .055); border-color: #59657a; }
.ghost-btn:disabled, .preview-btn:disabled { opacity: .45; cursor: not-allowed; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.danger-button, .remove-btn { color: #ffadb5; }

.engine-switch { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.pill {
  min-height: 30px;
  padding: 5px 9px;
  color: var(--quiet);
  background: var(--field);
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  font-size: .7rem;
}
.pill.active { color: #fff; background: var(--violet-strong); }
.pill:disabled { opacity: .38; cursor: not-allowed; }

.speaker-list { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; list-style: none; }
.speaker-row { display: grid; grid-template-columns: 9px minmax(90px, 1fr) minmax(150px, 1.25fr); align-items: center; gap: 10px; padding: 9px 10px; background: var(--field); border-radius: 10px; }
.dot { width: 8px; height: 8px; border-radius: 50%; }
.speaker-name { min-width: 0; overflow: hidden; color: #e4e8f0; font-size: .84rem; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.speaker-row select { width: 100%; min-width: 0; }

.voice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 9px; }
.voice-chip { min-width: 0; padding: 12px; background: var(--field); border-radius: 11px; }
.voice-chip b { display: block; overflow: hidden; font-size: .86rem; text-overflow: ellipsis; white-space: nowrap; }
.voice-chip small { display: block; min-height: 2.8em; margin-top: 3px; color: var(--quiet); font-size: .7rem; line-height: 1.4; }
.voice-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.preview-btn { display: inline-flex; align-items: center; gap: 5px; min-height: 30px; padding: 4px 8px; color: #77d7df; border-color: #315861; font-size: .7rem; }
.preview-btn svg { width: 13px; height: 13px; }

.profile-tools { margin-top: 15px; padding-top: 13px; border-top: 1px solid var(--line); }
.profile-tools summary { width: fit-content; color: #d2d7e2; cursor: pointer; font-size: .8rem; font-weight: 700; }
.profile-tools[open] summary { margin-bottom: 3px; }
.hint { margin: 10px 0 0; color: var(--muted); font-size: .76rem; }
.hint code { padding: 1px 5px; color: #d7d2ff; background: var(--field); border-radius: 5px; }
.profile-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 13px; }
.profile-form label, .auth-form-wrap label { display: grid; gap: 5px; min-width: 0; color: var(--muted); font-size: .73rem; }
.profile-form input, .profile-form select { width: 100%; min-width: 0; }
.file-field input { max-width: 100%; color: var(--muted); font-size: .7rem; }
.consent-check { display: flex; align-items: flex-start; gap: 8px; margin-top: 12px; color: #c7cdd9; font-size: .75rem; }
.consent-check input { width: 16px; height: 16px; flex: none; accent-color: var(--violet); }
.profile-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 11px; }
.record-dot { display: inline-block; width: 7px; height: 7px; margin-right: 4px; border-radius: 50%; background: var(--red); }
.recording-timer { margin-left: auto; color: #8edfe6; font-size: .72rem; font-variant-numeric: tabular-nums; }
.error { color: #ffadb5 !important; }

.tuning-panel { padding-bottom: 14px; }
.tuning-head { display: flex; align-items: center; justify-content: space-between; color: #d1d6e0; font-size: .77rem; font-weight: 700; }
.tuning-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 15px; margin-top: 12px; }
.tuning-field { display: grid; gap: 6px; color: var(--muted); font-size: .72rem; }
.tuning-field > span { display: flex; justify-content: space-between; gap: 8px; }
.tuning-field output { color: #e8ebf1; font-variant-numeric: tabular-nums; }
.tuning-field input { width: 100%; accent-color: var(--violet); }
.tuning-field small { color: var(--quiet); }
.tuning-hint { margin-bottom: 0; }
.render-estimate { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 2px 0 10px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: .77rem; }
.render-estimate strong { color: #e9ecf2; font-size: .8rem; }
.primary-btn {
  min-height: 45px;
  padding: 10px 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #fff;
  background: var(--violet-strong);
  border: 0;
  border-radius: 11px;
  box-shadow: 0 11px 25px rgba(70, 51, 194, .28);
  cursor: pointer;
  font-weight: 750;
}
.output-card > .primary-btn { width: 100%; }
.primary-btn:hover:not(:disabled) { background: var(--violet); transform: translateY(-1px); }
.primary-btn:disabled { opacity: .52; cursor: wait; transform: none; }
#status { min-height: 1em; color: var(--muted); font-size: .73rem; text-align: right; }
#playerWrap { display: grid; gap: 9px; margin-top: 13px; }
#playerWrap audio { width: 100%; }
.ai-disclosure { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: .7rem; }
.ai-disclosure span { padding: 2px 5px; color: #071013; background: var(--cyan); border-radius: 5px; font-size: .62rem; font-weight: 850; }
.download-link { width: 100%; }
.mobile-render-bar { display: none; }

.side-panel {
  position: fixed;
  z-index: 20;
  top: 0;
  right: 0;
  width: min(430px, 100vw);
  height: 100dvh;
  padding: 24px;
  overflow-y: auto;
  background: #121720;
  box-shadow: -18px 0 58px rgba(0, 0, 0, .48);
  animation: panel-in .24s cubic-bezier(.16, 1, .3, 1);
}
@keyframes panel-in { from { transform: translateX(32px); opacity: .5; } to { transform: translateX(0); opacity: 1; } }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.panel-head h2 { margin: 0; font-size: 1.35rem; letter-spacing: -.025em; }
.panel-head p { margin: 5px 0 0; color: var(--muted); font-size: .8rem; }
.history-list { display: grid; gap: 10px; }
.history-item { padding: 13px 0; border-bottom: 1px solid var(--line); }
.history-item > div { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.history-item b { font-size: .82rem; }
.history-item time, .history-item p { color: var(--quiet); font-size: .7rem; }
.history-item p { margin: 5px 0 9px; }
.history-item audio { width: 100%; height: 36px; }
.panel-empty { color: var(--muted); font-size: .82rem; }
.plan-list { display: grid; gap: 0; }
.panel-subheading { margin: 24px 0 0; padding-top: 18px; border-top: 1px solid var(--line); font-size: .85rem; }
.plan-item { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 14px; padding: 16px 0; border-bottom: 1px solid var(--line); }
.plan-item h3 { grid-column: 1; margin: 0; font-size: .95rem; }
.plan-item strong { grid-column: 1; margin-top: 6px; color: #eaeef5; font-size: 1.45rem; letter-spacing: -.03em; }
.plan-item p { grid-column: 1; margin: 0; color: var(--muted); font-size: .7rem; }
.plan-item button { grid-column: 2; grid-row: 1 / 4; }
.legal-note { margin-top: 18px; color: var(--quiet); font-size: .7rem; }
.account-details { margin: 0 0 20px; }
.account-details div { display: grid; grid-template-columns: 100px 1fr; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.account-details dt { color: var(--quiet); font-size: .72rem; }
.account-details dd { margin: 0; overflow-wrap: anywhere; color: #dde2eb; font-size: .8rem; }
#accountPanel > button { width: 100%; margin-top: 8px; }

.auth-gate {
  position: fixed;
  z-index: 50;
  inset: 0;
  padding: clamp(16px, 4vw, 48px);
  display: grid;
  place-items: center;
  overflow-y: auto;
  background: rgba(4, 6, 9, .9);
}
.auth-card {
  width: min(920px, 100%);
  display: grid;
  grid-template-columns: 1.12fr .88fr;
  overflow: hidden;
  background: #121720;
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.auth-intro {
  min-height: 480px;
  padding: clamp(30px, 6vw, 70px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  background:
    radial-gradient(500px 360px at 20% 100%, rgba(35, 174, 186, .16), transparent 68%),
    #0b0e15;
}
.auth-intro .logo { margin-bottom: 28px; }
.auth-intro h2 { max-width: 12ch; margin: 0; font-size: clamp(2rem, 5vw, 3.65rem); line-height: .98; letter-spacing: -.04em; text-wrap: balance; }
.auth-intro > p { max-width: 46ch; margin: 18px 0 25px; color: #b5bdca; font-size: .92rem; }
.auth-intro pre { margin: 0; padding: 14px 16px; overflow-x: auto; color: #c5cbd7; background: #080b10; border-radius: 11px; font: .73rem/1.7 ui-monospace, "Cascadia Code", monospace; }
.auth-intro pre span { color: #8edfe6; }
.auth-form-wrap { padding: clamp(28px, 5vw, 54px); display: flex; flex-direction: column; justify-content: center; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-bottom: 25px; padding: 4px; background: var(--field); border-radius: 10px; }
.auth-tabs button { min-height: 36px; color: var(--muted); background: transparent; border: 0; border-radius: 8px; cursor: pointer; font-size: .78rem; }
.auth-tabs button.active { color: #fff; background: var(--surface-raised); }
#authForm { display: grid; gap: 13px; }
#authForm input { width: 100%; }
#authForm .primary-btn { width: 100%; margin-top: 4px; }
.form-status { min-height: 1.2em; margin: 0; color: #ffadb5; font-size: .75rem; }
.auth-terms { margin: 18px 0 0; color: var(--quiet); font-size: .68rem; text-align: center; }

.oauth-page { padding: 24px; display: grid; place-items: center; }
.oauth-card { width: min(520px, 100%); padding: 36px; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); }
.oauth-card h1 { margin: 22px 0 10px; font-size: 1.7rem; letter-spacing: -.03em; }
.oauth-card p { color: var(--muted); font-size: .84rem; }
.oauth-actions { display: grid; grid-template-columns: 1fr auto; gap: 9px; margin-top: 22px; }
.oauth-field { display: grid; gap: 5px; margin-top: 12px; color: var(--muted); font-size: .74rem; }
.oauth-field input { width: 100%; }
#oauthLogin .primary-btn { width: 100%; margin-top: 8px; }

.legal-page { padding-top: clamp(24px, 6vw, 70px); }
.legal-document { width: min(760px, 100%); margin: 0 auto; padding: clamp(24px, 5vw, 54px); background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); }
.legal-back { display: inline-block; margin-bottom: 24px; color: var(--muted); font-size: .78rem; }
.legal-document h1 { margin: 0; font-size: clamp(2rem, 6vw, 3.6rem); line-height: 1; letter-spacing: -.04em; }
.legal-document h2 { margin: 32px 0 8px; font-size: 1rem; }
.legal-document p { max-width: 72ch; color: #c5ccd8; font-size: .88rem; line-height: 1.72; }
.legal-document .legal-updated { margin-top: 10px; color: var(--quiet); font-size: .74rem; }

footer { max-width: 1240px; margin: 28px auto 0; display: flex; justify-content: center; gap: 18px; color: var(--quiet); font-size: .7rem; }
footer a { color: var(--quiet); }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-areas: "script" "cast" "voices" "output"; }
  .auth-card { grid-template-columns: 1fr; }
  .auth-intro { min-height: auto; padding: 32px; }
  .auth-intro h2 { max-width: 16ch; font-size: clamp(2rem, 8vw, 3rem); }
  .auth-intro pre { display: none; }
  .auth-form-wrap { padding: 30px 32px 34px; }
}

@media (max-width: 620px) {
  body { padding: 16px 12px 28px; }
  .hero { align-items: flex-start; }
  .brand p { display: none; }
  .account-nav { gap: 3px; }
  .credit-meter { padding: 6px 9px; }
  .account-button span { display: none; }
  .nav-button, .ghost-btn, .preview-btn, .pill { min-height: 44px; }
  .workspace-bar { align-items: stretch; flex-wrap: wrap; padding: 10px; }
  .project-name-field { flex-basis: calc(100% - 90px); }
  .save-state { align-self: center; }
  .workspace-actions { width: 100%; }
  .workspace-actions .ghost-btn { flex: 1; }
  .card { padding: 14px; }
  .card-head { align-items: flex-start; flex-direction: column; }
  .engine-switch { justify-content: flex-start; }
  textarea#script { min-height: 250px; }
  .meta-row { flex-wrap: wrap; }
  .meta-row #speakerCount { margin-right: 0; }
  .meta-row label { margin-left: auto; }
  .speaker-row { grid-template-columns: 8px 1fr; }
  .speaker-row select { grid-column: 2; }
  .profile-form, .tuning-grid { grid-template-columns: 1fr; }
  .recording-timer { width: 100%; margin-left: 0; }
  .side-panel { padding: 20px 16px; }
  .mobile-render-bar {
    position: fixed;
    z-index: 15;
    right: 10px;
    bottom: 10px;
    left: 10px;
    min-height: 64px;
    padding: 9px 10px 9px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: #171c27;
    border-radius: 14px;
    box-shadow: 0 14px 36px rgba(0, 0, 0, .52);
  }
  .mobile-render-bar > span { display: grid; gap: 1px; }
  .mobile-render-bar small { color: var(--quiet); font-size: .65rem; }
  .mobile-render-bar strong { font-size: .78rem; }
  .mobile-render-bar .primary-btn { min-height: 44px; padding-inline: 14px; }
  body:has(.mobile-render-bar:not([hidden])) footer { margin-bottom: 84px; }
  .auth-gate { padding: 0; align-items: stretch; }
  .auth-card { min-height: 100dvh; border-radius: 0; }
  .auth-intro { padding: 28px 24px; }
  .auth-intro .logo { margin-bottom: 20px; }
  .auth-intro > p { margin-bottom: 0; }
  .auth-form-wrap { padding: 26px 24px 32px; }
  footer { flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .side-panel { animation: none; }
  .primary-btn { transition: none; }
  .primary-btn:hover:not(:disabled) { transform: none; }
}
