:root {
  --ink: #171613;
  --paper: #f3f0e8;
  --paper-deep: #e8e3d8;
  --cream: #fbf8f1;
  --accent: #e85d2a;
  --accent-dark: #bd3f13;
  --muted: #726f67;
  --line: #d7d1c5;
  --reader-font: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --reader-size: 64px;
}

* { box-sizing: border-box; }

html { color-scheme: light; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 4%, rgba(232, 93, 42, .09), transparent 22rem),
    var(--paper);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.standalone { padding-top: env(safe-area-inset-top); }

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

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

.topbar {
  height: 88px;
  padding: 0 clamp(22px, 5vw, 72px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(23, 22, 19, .12);
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  border: 0;
  padding: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50% 50% 50% 8px;
  color: var(--cream);
  background: var(--ink);
  font-family: Georgia, serif;
  font-size: 24px;
  font-style: italic;
}

.brand strong, .brand small { display: block; }
.brand strong { font-size: 18px; letter-spacing: -.02em; }
.brand small { color: var(--muted); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }

.ghost-button, .text-button {
  border: 0;
  background: transparent;
  cursor: pointer;
}

.top-actions { display: flex; align-items: center; gap: 8px; }
.install-button {
  padding: 11px 16px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  color: white;
  background: var(--ink);
  cursor: pointer;
  font-size: 14px;
  font-weight: 800;
}
.install-button:hover { background: var(--accent); border-color: var(--accent); }

.ghost-button {
  padding: 11px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
}

.ghost-button:hover { border-color: var(--ink); background: rgba(255,255,255,.4); }

.setup-view {
  width: min(1120px, calc(100% - 44px));
  margin: 0 auto;
  padding: clamp(54px, 8vw, 96px) 0 80px;
}

.intro { max-width: 830px; margin-bottom: 48px; }
.eyebrow, .label {
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .16em;
}

.intro h1 {
  margin: 12px 0 22px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(49px, 7vw, 92px);
  line-height: .94;
  letter-spacing: -.055em;
  font-weight: 500;
}

.intro h1 em { color: var(--accent); font-weight: 400; }
.intro-copy { max-width: 640px; margin: 0; color: #5d5a54; font-size: 18px; line-height: 1.6; }

.script-card {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 22px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(251, 248, 241, .72);
  box-shadow: 0 18px 50px rgba(23, 22, 19, .04);
  transition: border-color .2s, transform .2s, background .2s;
}

.script-card.dragging { border-color: var(--accent); background: #fff8f2; transform: translateY(-2px); }
.file-icon { display: grid; place-items: center; width: 62px; height: 72px; border-radius: 8px 8px 14px 8px; background: var(--ink); color: white; font-size: 13px; font-weight: 900; letter-spacing: .1em; }
.script-meta h2 { margin: 4px 0; font-size: 21px; letter-spacing: -.025em; }
.script-meta p { margin: 0; color: var(--muted); font-size: 14px; }
.text-button { padding: 8px; color: var(--accent-dark); font-size: 14px; font-weight: 800; }
.text-button:hover { text-decoration: underline; text-underline-offset: 4px; }
.text-button.muted { color: var(--muted); }

.message { margin-top: 14px; padding: 13px 16px; border-radius: 10px; background: #fff0ea; color: #8a2f0e; font-size: 14px; font-weight: 650; }

.install-banner {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 18px;
  margin-top: 18px;
  padding: 18px 54px 18px 18px;
  border: 1px solid #2a2926;
  border-radius: 16px;
  color: white;
  background: var(--ink);
  box-shadow: 0 16px 42px rgba(23,22,19,.13);
}
.install-banner strong { display: block; margin-bottom: 3px; }
.install-banner p { margin: 0; color: #bcb7ad; font-size: 13px; }
.mini-app-icon, .large-app-icon {
  display: grid;
  place-items: center;
  border-radius: 24% 24% 24% 9%;
  color: white;
  background: var(--accent);
  font-family: Georgia, serif;
  font-style: italic;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.16);
}
.mini-app-icon { width: 54px; height: 54px; font-size: 31px; }
.primary-button.compact { padding: 12px 16px; gap: 0; box-shadow: none; white-space: nowrap; }
.dismiss-button { position: absolute; top: 7px; right: 9px; border: 0; color: #9e9a92; background: transparent; cursor: pointer; font-size: 23px; }

.install-dialog {
  width: min(520px, calc(100% - 28px));
  padding: 34px;
  border: 0;
  border-radius: 22px;
  color: var(--ink);
  background: var(--cream);
  box-shadow: 0 30px 100px rgba(0,0,0,.38);
}
.install-dialog::backdrop { background: rgba(12,12,11,.72); backdrop-filter: blur(5px); }
.dialog-close { position: absolute; top: 16px; right: 18px; width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 50%; background: transparent; cursor: pointer; font-size: 22px; }
.large-app-icon { width: 76px; height: 76px; margin-bottom: 24px; font-size: 45px; }
.install-dialog h2 { margin: 8px 0 26px; font-family: Georgia, serif; font-size: 34px; line-height: 1.05; letter-spacing: -.035em; font-weight: 500; }
.install-dialog ol { display: grid; gap: 12px; margin: 0; padding: 0; list-style: none; }
.install-dialog li { display: grid; grid-template-columns: 44px 1fr; align-items: center; gap: 13px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; }
.instruction-icon { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; color: var(--accent-dark); background: #f7e3da; font-size: 21px; font-weight: 900; }
.dialog-note { margin: 20px 0 0; color: var(--muted); font-size: 13px; text-align: center; }

.selection-section, .settings-section { margin-top: 68px; }
.section-heading { display: flex; justify-content: space-between; align-items: end; gap: 24px; margin-bottom: 24px; }
.section-heading > div:first-child { display: flex; align-items: baseline; gap: 14px; }
.section-heading h2 { margin: 0; font-family: Georgia, serif; font-size: clamp(28px, 3vw, 38px); font-weight: 500; letter-spacing: -.035em; }
.step-number { color: var(--accent); font-size: 12px; font-weight: 900; letter-spacing: .12em; }

.character-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.character-option { position: relative; }
.character-option input { position: absolute; opacity: 0; pointer-events: none; }
.character-option label {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 15px 17px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(251, 248, 241, .55);
  cursor: pointer;
  transition: .18s ease;
}
.character-option label:hover { border-color: #aaa398; transform: translateY(-1px); }
.character-option input:focus-visible + label { outline: 3px solid rgba(232,93,42,.25); outline-offset: 2px; }
.character-option input:checked + label { border-color: var(--ink); background: var(--ink); color: white; box-shadow: 0 8px 24px rgba(23,22,19,.14); }
.character-name { overflow: hidden; text-overflow: ellipsis; font-weight: 760; white-space: nowrap; }
.cue-count { color: var(--muted); font-size: 12px; white-space: nowrap; }
.character-option input:checked + label .cue-count { color: #c9c5bd; }
.checkmark { display: none; color: #ff9a70; font-weight: 900; }
.character-option input:checked + label .checkmark { display: inline; }

.settings-grid { display: grid; grid-template-columns: 1fr 1.2fr 1fr; gap: 12px; }
.setting-card { min-height: 112px; display: flex; flex-direction: column; justify-content: space-between; padding: 18px; border-top: 2px solid var(--ink); background: rgba(251, 248, 241, .44); }
.setting-card > span { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; font-weight: 750; }
.setting-card output { color: var(--ink); }
select { width: 100%; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: 10px 2px; color: var(--ink); background: transparent; font-weight: 700; cursor: pointer; }
input[type="range"] { width: 100%; accent-color: var(--accent); cursor: pointer; }

.start-area { display: flex; align-items: center; justify-content: flex-end; gap: 26px; margin-top: 48px; padding-top: 24px; border-top: 1px solid var(--line); }
.start-area p { color: var(--muted); font-size: 13px; }
.primary-button { display: inline-flex; align-items: center; gap: 44px; padding: 17px 22px; border: 0; border-radius: 7px; color: white; background: var(--accent); font-weight: 850; cursor: pointer; box-shadow: 0 12px 30px rgba(189,63,19,.22); }
.primary-button:hover:not(:disabled) { background: var(--accent-dark); transform: translateY(-1px); }
.primary-button:disabled { opacity: .38; cursor: not-allowed; box-shadow: none; }

.reader-view { position: fixed; inset: 0; z-index: 10; min-height: 100vh; color: #f6f1e8; background: #151513; }
.reader-view::before { content: ""; position: fixed; inset: 0; pointer-events: none; background: radial-gradient(circle at 72% 44%, rgba(232,93,42,.10), transparent 34%), linear-gradient(rgba(255,255,255,.018) 1px, transparent 1px); background-size: auto, 100% 4px; }
.reader-toolbar { position: relative; z-index: 1; min-height: 84px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 14px clamp(18px, 3vw, 42px); border-bottom: 1px solid rgba(255,255,255,.10); }
.reader-icon-button { min-width: 44px; height: 44px; border: 1px solid rgba(255,255,255,.14); border-radius: 50%; color: #f6f1e8; background: transparent; cursor: pointer; font-weight: 800; }
.reader-icon-button:hover { border-color: rgba(255,255,255,.5); background: rgba(255,255,255,.05); }
.reader-toolbar > .reader-icon-button { justify-self: start; }
.reader-progress-copy { text-align: center; }
.reader-progress-copy span { display: block; max-width: 42vw; overflow: hidden; text-overflow: ellipsis; color: #f28b62; font-size: 11px; font-weight: 900; letter-spacing: .13em; white-space: nowrap; }
.reader-progress-copy strong { display: block; margin-top: 3px; font-size: 13px; }
.reader-toolbar-actions { justify-self: end; display: flex; gap: 7px; }
.font-control { width: auto; min-width: 48px; border-radius: 999px; font-size: 12px; }
.progress-track { position: fixed; z-index: 3; top: 83px; left: 0; right: 0; height: 2px; background: rgba(255,255,255,.06); }
.progress-track span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .25s ease; }

.cue-stage { position: relative; z-index: 1; height: calc(100vh - 178px); min-height: 420px; display: grid; grid-template-rows: auto 1fr; width: min(1180px, calc(100% - 48px)); margin: 0 auto; padding: clamp(24px, 5vh, 52px) 0 20px; }
.previous-cue { max-width: 820px; padding-left: 18px; border-left: 2px solid var(--accent); }
.cue-label { color: #8f8b83; font-size: 11px; font-weight: 850; letter-spacing: .13em; }
.cue-label strong { color: #b8b3aa; }
.previous-cue p { margin: 8px 0 0; color: #8f8b83; font-family: Georgia, serif; font-size: clamp(17px, 2vw, 23px); line-height: 1.4; }
.current-cue { align-self: center; padding: 26px 0; }
.speaker-name { display: block; margin-bottom: 16px; color: #f28b62; font-size: 12px; font-weight: 900; letter-spacing: .18em; text-transform: uppercase; }
.current-cue p { max-height: 54vh; overflow: auto; scrollbar-width: none; margin: 0; font-family: var(--reader-font); font-size: clamp(34px, var(--reader-size), 108px); font-weight: 720; line-height: 1.08; letter-spacing: -.035em; text-wrap: balance; }
.current-cue p::-webkit-scrollbar { width: 0; height: 0; }

.reader-controls { position: fixed; z-index: 2; left: 0; right: 0; bottom: 0; height: 94px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px; padding: 14px clamp(18px, 3vw, 42px); border-top: 1px solid rgba(255,255,255,.10); background: rgba(21,21,19,.93); backdrop-filter: blur(16px); }
.reader-controls > p { margin: 0; color: #77736c; font-size: 12px; text-align: center; }
kbd { padding: 3px 6px; border: 1px solid #4e4c47; border-bottom-width: 2px; border-radius: 4px; color: #aaa69e; font-family: inherit; }
.nav-button { min-height: 48px; padding: 0 18px; border-radius: 6px; font-weight: 820; cursor: pointer; }
.nav-button.secondary { justify-self: start; border: 1px solid rgba(255,255,255,.16); color: white; background: transparent; }
.nav-button.primary { justify-self: end; border: 1px solid var(--accent); color: white; background: var(--accent); }
.nav-button:disabled { opacity: .28; cursor: not-allowed; }

[hidden] { display: none !important; }

@media (max-width: 780px) {
  .topbar { height: 72px; }
  .setup-view { width: min(100% - 28px, 1120px); padding-top: 46px; }
  .intro { margin-bottom: 34px; }
  .script-card { grid-template-columns: auto 1fr; padding: 18px; }
  .script-card > .text-button { grid-column: 2; justify-self: start; padding-left: 0; }
  .character-grid { grid-template-columns: 1fr 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
  .install-banner { grid-template-columns: auto 1fr; }
  .install-banner .primary-button { grid-column: 1 / -1; justify-content: center; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .selection-actions { margin-left: 32px; }
  .start-area { align-items: stretch; flex-direction: column; }
  .start-area p { margin: 0; }
  .primary-button { justify-content: space-between; }
  .reader-toolbar { grid-template-columns: auto 1fr auto; gap: 10px; padding-inline: 14px; }
  .reader-toolbar-actions .font-control { display: none; }
  .cue-stage { width: calc(100% - 30px); height: calc(100vh - 166px); padding-top: 25px; }
  .previous-cue p { font-size: 16px; max-height: 72px; overflow: hidden; }
  .current-cue p { font-size: clamp(32px, calc(var(--reader-size) * .72), 76px); max-height: 57vh; }
  .reader-controls { height: 82px; padding: 10px 14px; }
  .reader-controls > p { display: none; }
  .reader-controls { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 500px) {
  .ghost-button { padding: 9px 11px; font-size: 12px; }
  .install-button { width: 42px; height: 42px; padding: 0; overflow: hidden; color: transparent; }
  .install-button span { color: white; font-size: 18px; }
  .character-grid { grid-template-columns: 1fr; }
  .intro h1 { font-size: 49px; }
  .file-icon { width: 48px; height: 58px; font-size: 10px; }
}

@media (display-mode: standalone) {
  .install-button, .install-banner { display: none !important; }
  .topbar { padding-top: env(safe-area-inset-top); height: calc(88px + env(safe-area-inset-top)); }
  .reader-toolbar { padding-top: max(14px, env(safe-area-inset-top)); }
  .reader-controls { padding-bottom: max(14px, env(safe-area-inset-bottom)); height: calc(94px + env(safe-area-inset-bottom)); }
}

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