:root {
  color-scheme: light;
  --paper: #fbf7f0;
  --surface: #ffffff;
  --ink: #221b16;
  --muted: #675d55;
  --line: #dfd4c7;
  --accent: #b23a2f;
  --accent-dark: #7f241d;
  --teal: #176d6a;
  --gold: #bd7b22;
  --green: #2f7d48;
  --focus: #0b63ce;
  --shadow: 0 18px 40px rgba(50, 39, 29, 0.13);
  font-family: Arial, Helvetica, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button,
select,
input {
  min-height: 44px;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  z-index: 20;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 18px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(251, 247, 240, 0.94);
  backdrop-filter: blur(12px);
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.help-button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 8px 12px;
  font-weight: 800;
}

.help-drawer {
  position: fixed;
  top: 82px;
  right: 22px;
  z-index: 30;
  display: grid;
  max-width: 360px;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 16px;
  box-shadow: var(--shadow);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.brand small,
.eyebrow,
.help-text,
.line-meta span,
.simple-status span,
.script-card p,
.form-error {
  color: var(--muted);
}

.brand strong,
.brand small {
  display: block;
}

.main-nav {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.nav-link,
.segmented button {
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  padding: 9px 14px;
}

.nav-link.active,
.segmented button.active {
  background: var(--ink);
  color: #fff;
}

.session-pill {
  border: 1px solid rgba(47, 125, 72, 0.35);
  border-radius: 999px;
  padding: 9px 12px;
  color: var(--green);
  background: #eef8f0;
  font-weight: 700;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.workspace-grid,
.admin-layout {
  display: grid;
  grid-template-columns: minmax(270px, 360px) minmax(0, 1fr);
  gap: 24px;
  padding: 24px;
}

.side-panel,
.login-panel {
  align-self: start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  box-shadow: var(--shadow);
}

.panel-heading h1,
.page-title h1,
.admin-header h2 {
  margin: 6px 0 18px;
  font-size: clamp(1.55rem, 2vw, 2.2rem);
  letter-spacing: 0;
}

.eyebrow {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.field {
  display: grid;
  gap: 8px;
  margin: 16px 0;
  border: 0;
  padding: 0;
}

.compact-field {
  margin: 12px 0;
}

.field span,
.field legend {
  font-weight: 800;
}

.work-picker {
  display: grid;
  gap: 14px;
  margin: 18px 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf3;
}

.work-field,
.work-section {
  margin: 0;
}

.field select,
.field input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f5eee5;
}

.section-choice-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  max-height: 360px;
  overflow-y: auto;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8f1e8;
  scrollbar-color: var(--accent) #eadfd2;
}

.section-choice-meta {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf3;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.section-choice-grid button {
  display: grid;
  gap: 4px;
  min-height: 64px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 12px;
  text-align: left;
  transition: border-color 120ms ease, background 120ms ease, transform 120ms ease;
}

.section-choice-grid button:hover {
  border-color: rgba(178, 58, 47, 0.5);
  background: #fffdf9;
}

.section-choice-grid button strong {
  overflow-wrap: anywhere;
}

.section-choice-grid button span {
  color: var(--muted);
  font-size: 0.9rem;
}

.section-choice-grid button.active {
  border-color: var(--accent);
  background: #fff2f0;
  box-shadow: inset 4px 0 0 var(--accent);
  transform: translateX(1px);
}

.section-choice-grid button.active span {
  color: var(--accent-dark);
}

.work-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.work-summary span {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.work-summary strong,
.work-summary small {
  display: block;
  overflow-wrap: anywhere;
}

.work-summary small {
  margin-top: 3px;
  color: var(--muted);
  font-weight: 700;
}

.simple-status {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  align-items: start;
  margin: 18px 0;
  padding: 14px;
  border-radius: 8px;
  background: #eef8f0;
}

.status-dot {
  width: 12px;
  height: 12px;
  margin-top: 3px;
  border-radius: 50%;
  background: var(--green);
}

.simple-status span:last-child {
  grid-column: 2;
}

.action-stack {
  display: grid;
  gap: 10px;
}

.primary-action,
.secondary-action,
.danger-action,
.icon-button {
  border: 1px solid transparent;
  border-radius: 8px;
  font-weight: 800;
}

.primary-action {
  background: var(--accent);
  color: #fff;
  padding: 13px 16px;
}

.primary-action:hover {
  background: var(--accent-dark);
}

.secondary-action {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
  padding: 13px 16px;
}

.danger-action {
  background: #fff2f0;
  color: var(--accent-dark);
  border-color: rgba(127, 36, 29, 0.35);
  padding: 13px 16px;
}

.compact {
  min-height: 40px;
  padding: 9px 12px;
}

.rehearsal-stage,
.admin-console,
.page-band {
  min-width: 0;
  padding: 24px;
}

.stage-toolbar,
.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.stage-toolbar h2,
.admin-header h2 {
  margin: 4px 0 0;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
}

.icon-button {
  width: 48px;
  height: 48px;
  background: #fff;
  border-color: var(--line);
  font-size: 1.35rem;
}

.icon-button.wide {
  width: auto;
  min-width: 82px;
  padding: 0 14px;
  font-size: 1rem;
}

.speaker-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin: 22px 0;
}

.speaker-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

.speaker-chip.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(178, 58, 47, 0.16);
}

.avatar,
.avatar-large {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 2px solid rgba(255, 255, 255, 0.8);
  border-radius: 50%;
  color: #fff;
  font-weight: 900;
}

.avatar {
  width: 40px;
  height: 40px;
}

.avatar-large {
  width: 76px;
  height: 76px;
  font-size: 2rem;
}

.line-focus {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: clamp(18px, 3vw, 34px);
  box-shadow: var(--shadow);
}

.line-meta {
  display: flex;
  align-items: center;
  gap: 16px;
}

.line-meta p {
  margin: 0 0 4px;
  font-size: 1.35rem;
  font-weight: 900;
}

.karaoke-line {
  margin: 28px 0 0;
  font-size: clamp(2.1rem, 5.2vw, 5.2rem);
  line-height: 1.1;
  font-weight: 900;
  letter-spacing: 0;
}

.karaoke-line.large-text {
  font-size: clamp(2.8rem, 6.4vw, 6.4rem);
}

.karaoke-line.small-text {
  font-size: clamp(1.55rem, 4vw, 4rem);
}

.karaoke-line.masked {
  color: transparent;
  text-shadow: 0 0 16px rgba(34, 27, 22, 0.35);
}

.reading-settings {
  margin-top: 20px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.reading-settings h2 {
  margin: 0 0 12px;
  font-size: 1.05rem;
}

.settings-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.settings-row span {
  font-weight: 800;
}

.range-field {
  display: grid;
  grid-template-columns: 1fr minmax(110px, 1.4fr) auto;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.range-field span {
  font-weight: 800;
}

.range-field input {
  min-height: 30px;
}

.range-field output {
  min-width: 54px;
  text-align: right;
  color: var(--muted);
  font-weight: 800;
}

.audio-panel {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf3;
}

.audio-panel strong,
.audio-panel span {
  display: block;
}

.audio-panel span {
  margin-top: 4px;
  color: var(--muted);
}

.meter {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #eadfd2;
}

.meter span {
  display: block;
  width: 0%;
  height: 100%;
  background: var(--teal);
  transition: width 120ms linear;
}

.listening-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 24px;
  padding: 14px;
  border-radius: 8px;
  background: #fff7df;
  border: 1px solid rgba(189, 123, 34, 0.45);
}

.hidden {
  display: none;
}

.up-next {
  margin-top: 22px;
}

.up-next h3,
.admin-section h3 {
  margin: 0 0 12px;
}

.up-next ol {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 22px;
}

.up-next li {
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.page-band {
  max-width: 1180px;
  margin: 0 auto;
}

.script-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}

.script-card,
.admin-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.script-card h2 {
  margin: 0 0 8px;
}

.script-card p {
  margin: 8px 0;
}

.admin-console.locked {
  opacity: 0.5;
  pointer-events: none;
}

.admin-steps {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(0, 1.4fr);
  gap: 16px;
  margin-top: 18px;
}

.simple-admin .admin-summary,
.simple-admin .admin-section:nth-child(3) {
  grid-column: 1 / -1;
}

.admin-kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.admin-kpis span {
  display: grid;
  gap: 3px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf3;
}

.admin-kpis strong {
  font-size: 1.25rem;
}

.admin-kpis small {
  color: var(--muted);
  font-weight: 800;
}

.drop-zone {
  display: grid;
  gap: 8px;
  padding: 18px;
  border: 2px dashed var(--line);
  border-radius: 8px;
  background: #fffaf3;
}

.drop-zone input {
  width: 100%;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.language-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.api-inline,
.api-vault {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 10px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf3;
}

.api-vault .button-row {
  grid-column: 1 / -1;
}

.import-status {
  min-height: 22px;
  margin: 10px 0 0;
  color: var(--muted);
  font-weight: 800;
}

#apiResult.ai-working,
#importStatus.ai-working {
  color: var(--teal);
}

#apiResult.ai-error,
#importStatus.ai-error {
  color: var(--accent-dark);
}

.quick-editor,
.character-review {
  display: grid;
  gap: 10px;
}

.edit-row,
.character-row {
  display: grid;
  gap: 8px;
  align-items: center;
}

.edit-row {
  grid-template-columns: 1fr 1.5fr auto;
}

.edit-row input,
.character-row input,
.character-row select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}

.character-row {
  grid-template-columns: minmax(120px, 1fr) minmax(90px, 0.8fr) minmax(90px, 0.8fr) minmax(90px, 0.8fr) minmax(110px, 0.9fr) minmax(150px, 1.2fr) minmax(150px, 1.3fr) minmax(130px, 1fr);
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf3;
}

.character-table-head {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(90px, 0.8fr) minmax(90px, 0.8fr) minmax(90px, 0.8fr) minmax(110px, 0.9fr) minmax(150px, 1.2fr) minmax(150px, 1.3fr) minmax(130px, 1fr);
  gap: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

.audio-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.82rem;
  font-weight: 900;
  white-space: nowrap;
}

.audio-status.ready {
  background: #eef8f0;
  color: var(--green);
}

.audio-status.missing,
.audio-status.generating {
  background: #fff7df;
  color: var(--gold);
}

.audio-status.error {
  background: #fff2f0;
  color: var(--accent-dark);
}

.form-error {
  min-height: 22px;
  font-weight: 800;
}

@media (max-width: 860px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .main-nav {
    justify-content: stretch;
  }

  .nav-link {
    flex: 1;
  }

  .workspace-grid,
  .admin-layout {
    grid-template-columns: 1fr;
    padding: 14px;
  }

  .rehearsal-stage,
  .admin-console,
  .page-band {
    padding: 14px;
  }

  .stage-toolbar,
  .admin-header,
  .listening-box {
    align-items: stretch;
    flex-direction: column;
  }

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

  .language-grid,
  .api-inline,
  .api-vault,
  .admin-kpis,
  .work-summary,
  .character-table-head,
  .edit-row,
  .character-row {
    grid-template-columns: 1fr;
  }

  .top-actions {
    justify-content: stretch;
  }

  .help-button,
  .session-pill {
    flex: 1;
    text-align: center;
  }

  .help-drawer {
    left: 14px;
    right: 14px;
    top: 150px;
    max-width: none;
  }
}

body.high-contrast {
  --paper: #000000;
  --surface: #101010;
  --ink: #ffffff;
  --muted: #f4e18a;
  --line: #777777;
  --accent: #ffe66d;
  --accent-dark: #ffd43b;
  --focus: #6bb6ff;
}

body.high-contrast .primary-action,
body.high-contrast .brand-mark,
body.high-contrast .nav-link.active,
body.high-contrast .segmented button.active {
  color: #000;
}

body.high-contrast .karaoke-line {
  color: #ffe66d;
}

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