:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: rgba(255, 255, 255, 0.88);
  --surface: #ffffff;
  --text: #111827;
  --muted: #667085;
  --border: #e2e8f0;
  --accent: #147a4b;
  --accent-dark: #0f613c;
  --blue: #2563eb;
  --gold: #b7791f;
  --rose: #c02663;
  --danger: #dc2626;
  --ok: #147a4b;
  --shadow: 0 20px 60px rgba(15, 23, 42, 0.08);
  --soft-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 20% -10%, rgba(37, 99, 235, 0.08), transparent 34%),
    radial-gradient(circle at 90% 10%, rgba(20, 122, 75, 0.10), transparent 28%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  padding-bottom: 112px;
}

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

button,
.file {
  border: 1px solid transparent;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 44px;
  padding: 0 18px;
  font-weight: 800;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease, border-color 120ms ease;
  box-shadow: 0 8px 18px rgba(20, 122, 75, 0.18);
}

button:hover,
.file:hover,
.link-button:hover {
  background: var(--accent-dark);
}

.link-button {
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
  font-weight: 800;
  text-decoration: none;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.ghost {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  box-shadow: none;
}

.ghost:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
}

button:active,
.link-button:active {
  transform: translateY(1px);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.22);
  outline-offset: 2px;
}

.app {
  max-width: 1240px;
  margin: 0 auto;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 38px;
  line-height: 1.05;
  letter-spacing: -0.02em;
}

h2 {
  font-size: 17px;
  margin-bottom: 12px;
}

p {
  color: var(--muted);
  margin-top: 6px;
}

.layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 20px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
  box-shadow: var(--soft-shadow);
  backdrop-filter: blur(16px);
}

.setup {
  position: sticky;
  top: 16px;
}

.setup-flow {
  display: grid;
  gap: 12px;
}

.flow-step {
  border: 1px solid var(--border);
  border-radius: 18px;
  background: linear-gradient(180deg, #ffffff, #f8fafc);
  padding: 16px;
  box-shadow: var(--soft-shadow);
}

.flow-step.hidden {
  display: none;
}

.step-label {
  color: var(--blue);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.flow-step > button {
  width: 100%;
}

.file {
  margin-bottom: 12px;
  width: 100%;
}

.file input {
  display: none;
}

textarea {
  width: 100%;
  min-height: 380px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
  line-height: 1.45;
}

summary {
  cursor: pointer;
  font-weight: 800;
  margin-bottom: 8px;
}

.script-summary {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: linear-gradient(180deg, #ffffff, #f8fafc);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.script-summary strong {
  display: block;
  font-size: 18px;
  margin-bottom: 6px;
}

.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  color: var(--muted);
  font-weight: 700;
}

.stack {
  display: grid;
  gap: 8px;
}

.stack button {
  width: 100%;
}

.ai-json-panel {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fff;
  margin: 12px 0 0;
  padding: 12px;
  overflow: hidden;
}

.ai-json-panel h2 {
  margin-bottom: 8px;
}

.import-why {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
  margin: 0 0 12px;
}

.free-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: #eef7f1;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  margin-bottom: 10px;
}

.ai-json-panel button {
  width: 100%;
}

.simple-steps {
  margin: 0 0 12px;
  padding-left: 22px;
  color: var(--text);
  font-size: 14px;
  line-height: 1.35;
}

.simple-steps li {
  margin-bottom: 6px;
}

.json-input {
  min-height: 120px;
  margin: 10px 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

.prompt-preview {
  margin-top: 10px;
}

.prompt-preview textarea {
  min-height: 190px;
  margin: 8px 0 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

.json-status {
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--border);
  color: var(--muted);
  font-weight: 800;
  padding: 8px 10px;
  margin-bottom: 10px;
}

.json-status.ok {
  border-color: var(--ok);
  color: var(--ok);
  background: #eef7f1;
}

.json-status.bad {
  border-color: var(--danger);
  color: var(--danger);
  background: #fff5f3;
}

.confirm-row {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 8px;
  align-items: start;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.3;
  margin-bottom: 10px;
}

.confirm-row input {
  margin-top: 2px;
}

.hidden {
  display: none;
}

.characters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.role {
  background: #f1f5f9;
  color: var(--text);
  box-shadow: none;
}

.role.selected {
  background: var(--accent);
  color: #fff;
}

.role:nth-child(2).selected {
  background: var(--blue);
}

.role:nth-child(3).selected {
  background: var(--gold);
}

.role:nth-child(4).selected {
  background: var(--rose);
}

.status,
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
}

.primary-controls {
  justify-content: flex-start;
}

.secondary-controls {
  justify-content: flex-start;
  margin-top: 8px;
}

.secondary-controls button:nth-child(1) {
  border-color: var(--blue);
  color: var(--blue);
}

.secondary-controls button:nth-child(2),
.secondary-controls button:nth-child(3) {
  border-color: var(--gold);
  color: var(--gold);
}

.secondary-controls button:nth-child(4) {
  border-color: var(--rose);
  color: var(--rose);
}

.status {
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 12px;
}

.stage.focus-mode {
  padding: 24px;
}

.stage.focus-mode .controls,
.stage.focus-mode .cleanup,
.stage.focus-mode .scene-map {
  display: none;
}

.stage.focus-mode .status {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  padding: 8px 12px;
  margin-bottom: 14px;
}

.stage.focus-mode .current {
  min-height: 300px;
  border-color: rgba(20, 122, 75, 0.28);
  background: linear-gradient(135deg, #ffffff, #effaf4);
  box-shadow: var(--soft-shadow);
}

.stage.focus-mode .current .text {
  font-size: clamp(30px, 4vw, 52px);
  max-width: 900px;
}

.stage.focus-mode .practice-options {
  border: 1px solid var(--border);
  border-radius: 18px;
  background: #fff;
  padding: 12px;
}

.practice-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.practice-options label {
  color: var(--muted);
  display: grid;
  font-size: 12px;
  font-weight: 800;
  gap: 4px;
  text-transform: uppercase;
  min-width: 0;
}

.toggle-option {
  align-content: end;
}

.toggle-option input {
  width: 22px;
  height: 22px;
}

.practice-options select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0 10px;
  background: #fff;
}

.practice-dock {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 20;
  width: min(1120px, calc(100vw - 32px));
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto;
  gap: 16px;
  align-items: center;
  border: 1px solid rgba(20, 122, 75, 0.45);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  padding: 14px;
  backdrop-filter: blur(18px);
}

.practice-dock.needs-action {
  border-color: rgba(183, 121, 31, 0.7);
  box-shadow: 0 0 0 5px rgba(183, 121, 31, 0.12), var(--shadow);
}

.practice-dock.listening {
  border-color: rgba(20, 122, 75, 0.75);
  box-shadow: 0 0 0 5px rgba(20, 122, 75, 0.14), var(--shadow);
}

.practice-dock.paused {
  border-color: rgba(37, 99, 235, 0.55);
}

.practice-dock.hidden {
  display: none;
}

.dock-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.dock-line {
  color: var(--text);
  font-size: 18px;
  font-weight: 800;
  line-height: 1.25;
  max-height: 48px;
  overflow: hidden;
}

.dock-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.dock-actions select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  font-weight: 800;
  padding: 0 10px;
}

.dock-field {
  display: grid;
  gap: 3px;
  min-width: 104px;
}

.dock-field span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.listen-state {
  color: var(--gold);
  font-size: 13px;
  font-weight: 900;
}

.listen-state.listening {
  color: var(--ok);
}

.listen-state.paused {
  color: var(--blue);
}

.listen-state.needs-action {
  color: var(--gold);
}

.needs-listen {
  animation: pulse-listen 1.2s ease-in-out infinite;
  box-shadow: 0 0 0 5px rgba(20, 122, 75, 0.16), 0 12px 24px rgba(20, 122, 75, 0.22);
}

@keyframes pulse-listen {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-1px);
  }
}

.current {
  border: 1px solid var(--border);
  border-radius: 18px;
  min-height: 170px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin-bottom: 12px;
}

.line-hint {
  align-self: flex-start;
  border-radius: 999px;
  margin-top: 18px;
  padding: 9px 13px;
  font-size: 14px;
  font-weight: 900;
}

.line-hint.needs-action {
  background: #fff7ed;
  color: var(--gold);
}

.line-hint.listening {
  background: #eef7f1;
  color: var(--ok);
}

.line-hint.paused {
  background: #eff6ff;
  color: var(--blue);
}

.current.empty {
  color: var(--muted);
}

.current.complete {
  border-color: rgba(20, 122, 75, 0.35);
  background: linear-gradient(135deg, #f0fff7, #ffffff);
}

.performance-summary {
  margin-top: 18px;
}

.performance-summary span {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  padding: 8px 12px;
}

.restart-practice {
  margin-top: 18px;
  align-self: flex-start;
}

.speaker {
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.text {
  font-size: 28px;
  line-height: 1.25;
}

.feedback {
  min-height: 54px;
  margin: 12px 0;
  color: var(--muted);
}

.feedback-card {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  background: var(--surface);
}

.feedback-card.ok {
  border-color: var(--ok);
  background: #eef7f1;
}

.feedback-card.bad {
  border-color: var(--danger);
  background: #fff5f3;
}

.feedback-card .expected {
  color: var(--text);
  margin-top: 6px;
}

.feedback-card .label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.feedback strong.ok {
  color: var(--ok);
}

.feedback strong.bad {
  color: var(--danger);
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}

.section-head h2 {
  margin-bottom: 0;
}

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

.mini-actions button {
  min-height: 36px;
  padding: 0 12px;
}

.cleanup {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  margin: 12px 0 16px;
  background: #fafaf8;
}

.cleanup-body.hidden {
  display: none;
}

.cleanup-head,
.cleanup-row {
  display: grid;
  grid-template-columns: 150px 1fr 44px;
  gap: 8px;
  align-items: start;
}

.cleanup-head {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 6px;
  text-transform: uppercase;
}

.cleanup-rows {
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
}

.cleanup-row input,
.cleanup-row textarea {
  min-height: 38px;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 10px;
  background: #fff;
}

.cleanup-row textarea {
  margin: 0;
  resize: vertical;
}

.delete-line {
  min-height: 38px;
  padding: 0;
}

.scene-tools {
  display: grid;
  grid-template-columns: 1fr 160px 96px 170px;
  gap: 8px;
  margin-bottom: 10px;
}

.scene-tools input,
.scene-tools select {
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0 10px;
  background: #fff;
}

.support-note {
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 16px;
  display: grid;
  gap: 4px;
  margin-top: 12px;
  background: rgba(255, 255, 255, 0.72);
  padding: 12px;
}

.support-note strong {
  color: var(--text);
  font-size: 14px;
}

.support-note span {
  font-size: 13px;
}

.lines {
  display: grid;
  gap: 8px;
  max-height: 430px;
  overflow: auto;
  scroll-behavior: smooth;
}

.line {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  cursor: pointer;
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 10px;
}

.line.active {
  border-color: var(--accent);
  background: #eef7f1;
  position: sticky;
  top: 0;
  box-shadow: inset 0 0 0 1px var(--accent);
}

.line.mine {
  border-left: 5px solid var(--accent);
}

.line.hidden-line {
  display: none;
}

.scene-map.collapsed #sceneBody {
  display: none;
}

.docs {
  max-width: 1040px;
}

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

.doc-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
  box-shadow: var(--soft-shadow);
}

.doc-card p {
  line-height: 1.45;
}

.consent-banner {
  position: fixed;
  left: 50%;
  top: 16px;
  transform: translateX(-50%);
  z-index: 50;
  width: min(760px, calc(100vw - 28px));
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: center;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  padding: 16px;
  backdrop-filter: blur(18px);
}

.consent-banner strong {
  display: block;
  margin-bottom: 4px;
}

.consent-banner p {
  margin: 0;
  line-height: 1.35;
}

.consent-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

@media (max-width: 820px) {
  body {
    padding-bottom: 116px;
  }

  .app {
    padding: 10px;
    max-width: 100%;
  }

  .topbar {
    display: grid;
    gap: 12px;
  }

  .top-actions {
    flex-wrap: wrap;
  }

  h1 {
    font-size: 28px;
  }

  .panel {
    border-radius: 16px;
    padding: 12px;
  }

  .layout {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .setup {
    position: static;
  }

  .status {
    font-size: 12px;
    gap: 6px;
  }

  .current {
    min-height: 150px;
    padding: 16px;
    border-radius: 18px;
  }

  .text {
    font-size: 25px;
  }

  .stage.focus-mode {
    padding: 10px;
  }

  .stage.focus-mode .current {
    min-height: 190px;
  }

  .stage.focus-mode .current .text {
    font-size: clamp(30px, 11vw, 46px);
    line-height: 1.12;
  }

  .stage.focus-mode .practice-options {
    display: none;
  }

  .line-hint {
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.25;
    padding: 9px 11px;
  }

  .scene-tools {
    grid-template-columns: 1fr;
  }

  .practice-options {
    grid-template-columns: 1fr;
  }

  .cleanup-head,
  .cleanup-row,
  .line {
    grid-template-columns: 1fr;
  }

  .practice-dock {
    grid-template-columns: 1fr;
    bottom: 8px;
    width: calc(100vw - 16px);
    gap: 8px;
    border-radius: 18px;
    padding: 10px;
    max-height: none;
    overflow: visible;
  }

  .dock-title {
    font-size: 11px;
  }

  .dock-line {
    font-size: 16px;
    max-height: 22px;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .listen-state {
    font-size: 12px;
  }

  .dock-actions {
    display: grid;
    grid-template-columns: 0.9fr 1fr 1fr 1fr;
    gap: 7px;
  }

  .dock-field {
    min-width: 0;
  }

  .dock-field span {
    display: none;
  }

  .dock-actions button,
  .dock-actions select {
    min-height: 44px;
    padding: 0 10px;
    border-radius: 14px;
    font-size: 15px;
  }

  #dockCueBtn {
    display: none;
  }

  #dockRetryBtn {
    grid-column: span 1;
  }

  #dockPauseBtn,
  #dockAcceptBtn,
  #dockNextBtn {
    background: #fff;
  }

  #dockAcceptBtn {
    display: none;
  }

  .consent-banner {
    grid-template-columns: 1fr;
    top: 8px;
    width: calc(100vw - 16px);
    padding: 12px;
  }

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

  .consent-actions button {
    flex: 1;
  }
}
