:root {
  color-scheme: dark;
  --ink: #11120f;
  --ink-raised: #181a16;
  --ink-strong: #20221d;
  --line: #383a31;
  --line-soft: #2a2c26;
  --paper: #f4f0e7;
  --paper-muted: #c5c0b5;
  --quiet: #98968c;
  --brass: #d7b06f;
  --brass-bright: #f0cb8a;
  --signal: #99c47a;
  --warning: #e1b66d;
  --danger: #e4897f;
  --focus: #f0cb8a;
  --shadow: rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }

html { background: var(--ink); }

body {
  min-width: 320px;
  margin: 0;
  background: var(--ink);
  color: var(--paper);
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

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

button,
.downloads a,
.hermes-login-panel a {
  appearance: none;
  min-height: 42px;
  border: 1px solid var(--brass);
  border-radius: 8px;
  background: var(--brass);
  color: #19160f;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 15px;
  font-weight: 750;
  letter-spacing: .01em;
  line-height: 1.2;
  text-decoration: none;
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease, transform 140ms ease;
}

button:hover:not(:disabled),
.downloads a:hover,
.hermes-login-panel a:hover {
  background: var(--brass-bright);
  border-color: var(--brass-bright);
  transform: translateY(-1px);
}

button:disabled {
  border-color: var(--line);
  background: var(--line-soft);
  color: var(--quiet);
  cursor: not-allowed;
  opacity: 1;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 70%, transparent);
  outline-offset: 3px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #10110f;
  color: var(--paper);
  padding: 10px 11px;
  transition: border-color 140ms ease, background-color 140ms ease;
}

input:hover,
select:hover,
textarea:hover { border-color: #5b5c51; }
input:focus,
select:focus,
textarea:focus { border-color: var(--brass); }

textarea {
  min-height: 340px;
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
  line-height: 1.6;
  resize: vertical;
}

p { color: var(--paper-muted); }
h1, h2, h3, h4 { color: var(--paper); }
h1, h2, h3 { font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif; }
h1, h2, h3, h4, p { margin-top: 0; }

.shell {
  width: min(1320px, calc(100% - 48px));
  margin: 0 auto;
  padding: 26px 0 72px;
}

.auth-shell {
  display: grid;
  width: min(100% - 32px, 480px);
  min-height: 100vh;
  margin: 0 auto;
  place-items: center;
}

.auth-card {
  width: 100%;
  padding: 30px;
}

.auth-card > p:not(.eyebrow) { margin-bottom: 24px; }
.auth-form { display: grid; gap: 10px; }
.auth-form button { margin-top: 8px; }

.app-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px 32px;
  align-items: start;
  padding: 0 0 24px;
  border-bottom: 1px solid var(--line);
}

.app-header-side {
  display: flex;
  min-width: 0;
  align-items: flex-end;
  flex-direction: column;
  gap: 14px;
}

.app-auth-controls {
  display: flex;
  align-items: center;
  justify-content: end;
  gap: 10px;
}
.app-auth-controls .hint { margin: 0; white-space: nowrap; }
.app-auth-controls button { min-height: 34px; padding: 7px 10px; font-size: 12px; }

.brand-lockup {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 14px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  place-items: center;
  border: 1px solid var(--brass);
  border-radius: 50%;
  color: var(--brass-bright);
  font-family: Georgia, serif;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .08em;
}

.eyebrow,
.step-label {
  margin: 0 0 6px;
  color: var(--brass);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .12em;
  line-height: 1.2;
  text-transform: uppercase;
}

.step-label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.step-label span {
  color: var(--signal);
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 10px;
  letter-spacing: .08em;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(31px, 4vw, 49px);
  font-weight: 500;
  letter-spacing: -.04em;
  line-height: .98;
}

h2 {
  margin-bottom: 7px;
  font-size: clamp(24px, 2.4vw, 33px);
  font-weight: 500;
  letter-spacing: -.025em;
  line-height: 1.04;
}

h3 {
  margin-bottom: 6px;
  font-size: 25px;
  font-weight: 500;
  letter-spacing: -.02em;
}

h4 {
  margin-bottom: 0;
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.app-intro {
  max-width: 390px;
  margin: 0;
  color: var(--quiet);
  font-size: 13px;
  text-align: right;
}

.app-menu {
  display: flex;
  grid-column: 1 / -1;
  gap: 0;
  width: fit-content;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #0e0f0d;
}

.menu-button {
  min-height: 38px;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--quiet);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
}

.menu-button:last-child { border-right: 0; }
.menu-button:hover:not(:disabled) {
  background: var(--ink-raised);
  border-color: var(--line);
  color: var(--paper);
  transform: none;
}
.menu-button.active {
  background: var(--paper);
  color: #171713;
}
.menu-button.active:hover:not(:disabled) {
  background: var(--paper);
  color: #171713;
}

.app-view { margin-top: 24px; }
.hidden { display: none !important; }

.studio-workbench {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}

.card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--ink-raised);
  box-shadow: 0 16px 34px var(--shadow);
}

.upload-card { padding: 23px; }
.upload-card-content {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, .82fr);
  gap: 30px;
  align-items: end;
}
.upload-card p { max-width: 650px; margin-bottom: 0; }

.upload-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.file-field { display: grid; gap: 6px; }
.file-field > span,
label {
  color: var(--paper-muted);
  font-size: 12px;
  font-weight: 700;
}

input[type="file"] {
  min-height: 42px;
  color: var(--quiet);
  padding: 7px;
}
input[type="file"]::file-selector-button {
  margin-right: 9px;
  border: 0;
  border-radius: 5px;
  background: var(--ink-strong);
  color: var(--paper);
  cursor: pointer;
  padding: 6px 8px;
  font-weight: 700;
}

.workflow-card { padding: 0; overflow: hidden; }
.workflow-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 23px 23px 20px;
  border-bottom: 1px solid var(--line);
}
.workflow-header h2 { margin-bottom: 4px; }
.job-summary { max-width: 700px; margin: 0; }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  flex: 0 0 auto;
  border: 1px solid color-mix(in srgb, var(--signal) 55%, var(--line));
  border-radius: 999px;
  color: var(--signal);
  padding: 5px 10px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .1em;
  line-height: 1;
  text-transform: uppercase;
}

.workflow-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(280px, .7fr);
}

.workflow-main { padding: 23px; }

.controls,
.actions,
.downloads,
.voice-controls,
.script-reuse-panel,
.script-reuse-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
}

.draft-controls {
  gap: 18px;
  align-items: end;
}
.draft-controls > label { width: min(250px, 100%); }
.draft-controls .hint {
  min-width: 220px;
  flex: 1 1 260px;
  margin: 0;
  padding-bottom: 2px;
}

.hint {
  color: var(--quiet);
  font-size: 13px;
  line-height: 1.5;
}

.workflow-actions { margin: 23px 0 0; }
.workflow-actions button:not(:first-child),
.script-reuse-actions button,
#hermes-cancel-login-btn {
  border-color: var(--line);
  background: transparent;
  color: var(--paper-muted);
}
.workflow-actions button:not(:first-child):hover:not(:disabled),
.script-reuse-actions button:hover:not(:disabled),
#hermes-cancel-login-btn:hover:not(:disabled) {
  border-color: var(--paper-muted);
  background: var(--ink-strong);
  color: var(--paper);
}

.control-inspector {
  border-left: 1px solid var(--line);
  background: #141611;
  padding: 23px;
}
.inspector-heading p { margin-bottom: 19px; font-size: 13px; }
.voice-controls {
  display: grid;
  gap: 13px;
  align-items: stretch;
}
.voice-controls label { display: grid; gap: 6px; }
#tts-options-warning,
#omnivoice-upload-status,
#hermes-selection-message,
#hermes-openai-api-key-message { min-height: 1.3em; margin: 0; color: var(--warning); }

.script-reuse-panel {
  justify-content: space-between;
  align-items: center;
  margin-top: 23px;
  padding: 14px;
  border: 1px solid #4d493d;
  border-radius: 9px;
  background: #1d1e18;
}
.script-reuse-panel strong { color: var(--paper); }
.script-reuse-panel p { max-width: 540px; margin: 4px 0 0; }
.script-reuse-actions { justify-content: flex-end; }

.progress-panel {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid #4d493d;
  border-radius: 9px;
  background: #171914;
}
.progress-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 9px;
}
.progress-row span { color: var(--brass); font-family: "Cascadia Mono", Consolas, monospace; font-weight: 800; }
progress { width: 100%; height: 9px; accent-color: var(--brass); }

.script-card,
.outputs-card,
.voice-menu-card,
.hermes-menu-card { padding: 23px; }

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-end;
  margin-bottom: 18px;
}
.section-heading > p { max-width: 360px; margin: 0; font-size: 13px; }
.card-footer { display: flex; justify-content: flex-end; margin-top: 14px; }

.session-messages {
  display: grid;
  gap: 7px;
  margin-bottom: 16px;
}
#messages p { margin: 0; color: var(--paper-muted); font-size: 13px; }
.downloads a { border-color: var(--line); background: var(--ink-strong); color: var(--paper); }
.downloads a:hover { border-color: var(--brass); background: #29291f; }

.voice-menu-card { max-width: 920px; }
.voice-upload-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  align-items: end;
}
.voice-upload-form label { display: grid; gap: 6px; }
.voice-profile-promise {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid #4d493d;
  border-radius: 9px;
  background: #171914;
}
.voice-profile-promise strong {
  flex: 0 0 auto;
  color: var(--brass);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.voice-profile-promise p { margin: 0; color: var(--paper-muted); font-size: 13px; }
.full-width { grid-column: 1 / -1; }
.voice-samples { display: grid; gap: 12px; }
.voice-samples-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}
.voice-samples-heading h3 { margin: 0 0 4px; font-size: 17px; }
.voice-samples-heading p { margin: 0; }
.voice-samples-heading button { flex: 0 0 auto; white-space: nowrap; }
.voice-sample-list { display: grid; gap: 10px; }
.voice-sample-card {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  min-width: 0;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--line-soft);
  border-radius: 9px;
  background: #141510;
}
.voice-sample-card legend { padding: 0 5px; color: var(--paper); font-size: 13px; font-weight: 800; }
.voice-sample-card .full-width { grid-column: 1 / -1; }
.voice-sample-default { border-color: #74633e; }
.voice-sample-default-badge {
  display: inline-block;
  margin-left: 7px;
  padding: 2px 6px;
  border: 1px solid #74633e;
  border-radius: 99px;
  color: var(--brass);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.voice-sample-remove { grid-column: 1 / -1; justify-self: end; min-height: 34px; }
.voice-reference-text { min-height: 110px; }
.voice-permission {
  display: flex !important;
  align-items: center;
  gap: 9px;
  color: var(--paper-muted);
  font-size: 13px;
}
.voice-permission input { width: auto; accent-color: var(--brass); }

.voice-reference-library { margin-top: 26px; }
.voice-reference-library > h3 { margin-bottom: 4px; font-size: 19px; }
.speaker-profile-card {
  display: grid;
  gap: 8px;
  margin-top: 11px;
  padding: 13px;
  border: 1px solid var(--line-soft);
  border-radius: 9px;
  background: #141510;
}
.speaker-profile-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}
.speaker-profile-heading > .hint { margin: 0; font-size: 12px; }
.speaker-profile-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-left: auto; }
.speaker-profile-actions button,
.speaker-profile-card > div > button { min-height: 34px; padding: 7px 10px; font-size: 12px; }
.danger-button {
  border-color: color-mix(in srgb, var(--danger) 66%, var(--line));
  background: transparent;
  color: var(--danger);
}
.danger-button:hover:not(:disabled) {
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 16%, var(--ink-strong));
  color: var(--paper);
}
.voice-profile-delete-dialog {
  width: min(480px, calc(100% - 32px));
  border: 1px solid #6b4a45;
  border-radius: 11px;
  background: var(--ink-raised);
  color: var(--paper);
  box-shadow: 0 20px 48px var(--shadow);
  padding: 0;
}
.voice-profile-delete-dialog::backdrop { background: rgba(0, 0, 0, .7); }
.voice-profile-delete-dialog form { display: grid; gap: 14px; padding: 20px; }
.voice-profile-delete-dialog h3 { margin: 0; font-size: 23px; }
.voice-profile-delete-dialog p { margin: 0; }
.voice-profile-delete-dialog label { display: grid; gap: 6px; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 9px; }

.hermes-heading { align-items: center; }
.hermes-status-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 20px 0;
}
.hermes-status-grid div {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #141510;
}
.hermes-status-grid dt,
.hermes-provider-credentials h4 {
  color: var(--quiet);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.hermes-status-grid dd {
  margin: 6px 0 0;
  color: var(--paper);
  font-size: 14px;
  font-weight: 750;
  overflow-wrap: anywhere;
}

.hermes-routing-card {
  margin-top: 22px;
  padding: 18px;
  border: 1px solid #4d493d;
  border-radius: 10px;
  background: #151710;
}
.hermes-routing-card h3 { font-size: 23px; }
.hermes-routing-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  gap: 12px;
  align-items: end;
}
.hermes-routing-form label { display: grid; gap: 6px; min-width: 0; }
.hermes-routing-form button { white-space: nowrap; }
#hermes-selection-message { grid-column: 1 / -1; }

.hermes-connection-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 22px;
}
.hermes-provider-card {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 15px;
  padding: 16px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: #141510;
}
.row { display: flex; justify-content: space-between; gap: 12px; }
.compact-row { align-items: flex-start; }
.hermes-provider-card h3 { margin-bottom: 3px; font-size: 23px; }
.hermes-provider-card p { margin-bottom: 0; }
.hermes-provider-credentials {
  display: grid;
  gap: 8px;
  margin-top: auto;
  padding-top: 13px;
  border-top: 1px solid var(--line-soft);
}
.hermes-provider-credentials h4 { margin: 0; }
.hermes-provider-credentials > .hint { margin: 0; color: var(--quiet); font-size: 12px; }
.hermes-credential-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 9px;
  align-items: center;
  padding: 9px;
  border: 1px solid var(--line-soft);
  border-radius: 7px;
  background: #10110f;
}
.hermes-credential-label { min-width: 0; color: var(--paper); font-size: 13px; font-weight: 750; overflow-wrap: anywhere; }
.hermes-credential-status { margin-top: 2px; color: var(--quiet); font-size: 11px; overflow-wrap: anywhere; }
.hermes-credential-remove {
  min-height: 32px;
  border-color: color-mix(in srgb, var(--danger) 75%, var(--line));
  background: transparent;
  color: #efb1aa;
  padding: 6px 9px;
  font-size: 11px;
}
.hermes-credential-remove:hover:not(:disabled) { border-color: var(--danger); background: #2a1715; color: #ffd4cf; }
.hermes-secret-form { display: grid; gap: 10px; width: 100%; }
.hermes-secret-form label { display: grid; gap: 6px; }

.hermes-login-panel {
  margin-top: 20px;
  padding: 16px;
  border: 1px solid #4d493d;
  border-radius: 9px;
  background: #171914;
}
.hermes-login-panel p { margin-bottom: 12px; }
.hermes-code-row { display: flex; align-items: center; gap: 12px; margin: 14px 0; color: var(--quiet); }
.hermes-code-row code {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0d0e0c;
  color: var(--brass-bright);
  padding: 8px 10px;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: .08em;
}

@media (max-width: 1000px) {
  .workflow-layout { grid-template-columns: 1fr; }
  .control-inspector { border-top: 1px solid var(--line); border-left: 0; }
  .hermes-connection-grid { grid-template-columns: 1fr; }
  .hermes-routing-form { grid-template-columns: 1fr 1fr; }
  .hermes-routing-form button,
  #hermes-selection-message { grid-column: 1 / -1; }
}

@media (max-width: 760px) {
  .shell { width: min(100% - 28px, 1320px); padding-top: 18px; }
  .app-header { grid-template-columns: 1fr; gap: 14px; padding-bottom: 18px; }
  .app-header-side { align-items: flex-start; }
  .app-intro { max-width: 540px; text-align: left; }
  .app-menu { width: 100%; }
  .menu-button { flex: 1 1 0; padding-inline: 8px; }
  .app-view { margin-top: 16px; }
  .upload-card,
  .workflow-header,
  .workflow-main,
  .control-inspector,
  .script-card,
  .outputs-card,
  .voice-menu-card,
  .hermes-menu-card { padding: 17px; }
  .upload-card-content,
  .upload-form,
  .section-heading,
  .hermes-status-grid,
  .hermes-routing-form,
  .voice-upload-form { grid-template-columns: 1fr; }
  .upload-form button { width: 100%; }
  .workflow-header,
  .section-heading { align-items: flex-start; flex-direction: column; }
  .workflow-header .badge { order: -1; }
  .workflow-actions,
  .workflow-actions button,
  .script-reuse-actions,
  .script-reuse-actions button { width: 100%; }
  .script-reuse-panel { align-items: stretch; }
  .script-reuse-actions { justify-content: stretch; }
  .hermes-routing-form button,
  #hermes-selection-message { grid-column: auto; }
  .voice-samples-heading { flex-direction: column; }
  .voice-samples-heading button { width: 100%; }
  .voice-sample-card { grid-template-columns: 1fr; }
  .voice-sample-card .full-width,
  .voice-sample-remove { grid-column: auto; }
  .voice-sample-remove { justify-self: start; }
  .speaker-profile-heading { align-items: flex-start; flex-direction: column; }
  .speaker-profile-actions { width: 100%; margin-left: 0; }
  .speaker-profile-actions button { flex: 1 1 150px; }
  .dialog-actions button { flex: 1 1 150px; }
  .voice-upload-form > button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}
