:root {
  --bg: #14110f;
  --panel: #1e1a17;
  --panel-2: #27221e;
  --line: #3a332d;
  --text: #f1e9df;
  --muted: #b3a597;
  --accent: #e7a04b;
  --accent-ink: #1b1309;
  --danger: #e2735f;
  --ok: #8fc48a;
  --radius: 14px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 17px/1.55 var(--sans);
  background-image: radial-gradient(1200px 500px at 50% -200px, #2b2018 0%, transparent 70%);
  min-height: 100vh;
}
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: clamp(1.7rem, 4vw, 2.3rem); }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; margin-top: 1.2em; }
h4 { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 1em 0 .3em; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: max(14px, env(safe-area-inset-top)) 20px 14px;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5; background: rgba(20,17,15,.92); backdrop-filter: blur(8px);
}
.brand { font-family: var(--serif); font-size: 1.4rem; color: var(--text); text-decoration: none; letter-spacing: .02em; }
.top nav { display: flex; align-items: center; gap: 14px; }
.top nav form { margin: 0; }
main { max-width: 900px; margin: 0 auto; padding: 24px 16px 80px; }
.page-title { margin-top: 4px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.narrow { max-width: 420px; margin: 8vh auto 0; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.hint { color: var(--muted); font-size: .92rem; }
.small { font-size: .8rem; }
.alert { background: #3a1f19; border: 1px solid #6b3428; color: #ffd9cf; padding: 10px 14px; border-radius: 10px; }

label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .95rem; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 12px; width: 100%;
}
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: 600 1rem var(--sans); background: var(--accent); color: var(--accent-ink);
  border: 0; border-radius: 999px; padding: 11px 20px; cursor: pointer; text-decoration: none;
  transition: transform .15s ease, filter .15s ease, opacity .2s ease;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(.97); }
.btn.small { padding: 7px 14px; font-size: .9rem; }
.btn.big { padding: 15px 24px; font-size: 1.1rem; width: 100%; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn.danger { color: var(--danger); border-color: #5a2d24; }
.btn[disabled] { opacity: .55; cursor: progress; }
.link { background: none; border: 0; color: var(--muted); font: inherit; cursor: pointer; padding: 0; }
.link:hover { color: var(--text); }

/* new story form */
.drop {
  position: relative; display: flex; align-items: center; justify-content: center; text-align: center;
  min-height: 120px; border: 2px dashed var(--line); border-radius: var(--radius);
  color: var(--muted); font-weight: 500; cursor: pointer; transition: border-color .2s ease, background .2s ease;
}
.drop:hover, .drop.over { border-color: var(--accent); background: #221c17; }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.previews { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 8px; margin-top: 12px; }
.previews img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; animation: pop .25s ease; }
@keyframes pop { from { opacity: 0; transform: scale(.94); } to { opacity: 1; transform: none; } }

fieldset { border: 0; padding: 0; margin: 0 0 16px; }
legend { font-weight: 600; font-size: .95rem; margin-bottom: 8px; }
.segmented { display: flex; flex-wrap: wrap; gap: 6px; }
.segmented legend { width: 100%; }
.segmented label { flex: 1 1 0; min-width: 52px; }
.segmented input { position: absolute; opacity: 0; width: 0; height: 0; }
.segmented span {
  display: block; text-align: center; padding: 10px 8px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel-2); cursor: pointer; transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.segmented input:checked + span { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.toggle { flex-direction: row; align-items: center; gap: 10px; font-weight: 500; margin: 6px 0 14px; }
.toggle input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
#narrator-voice-wrap { margin-bottom: 14px; transition: opacity .2s ease; }
#narrator-voice-wrap.off { opacity: .4; pointer-events: none; }

/* library */
.grid { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.tile { display: block; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; color: var(--text); text-decoration: none; transition: transform .2s ease, border-color .2s ease; }
.tile:hover { transform: translateY(-2px); border-color: #574a3e; }
.tile img { width: 100%; aspect-ratio: 16/10; object-fit: cover; display: block; background: var(--panel-2); }
.tile-body { padding: 14px 16px 16px; }
.tile h2 { font-size: 1.15rem; margin-bottom: 6px; }
.prompt { color: var(--muted); font-size: .9rem; margin: 6px 0 0; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; color: var(--muted); font-size: .88rem; margin: 0; }
.pill { font-size: .75rem; font-weight: 700; letter-spacing: .03em; padding: 3px 9px; border-radius: 999px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.pill.done { background: #1f2d1e; color: var(--ok); border-color: #355234; }
.pill.review { background: #3a2a14; color: var(--accent); border-color: #6a4a1f; }
.pill.failed { background: #3a1f19; color: var(--danger); border-color: #6b3428; }
.empty { text-align: center; padding: 12vh 10px; }
.empty p { color: var(--muted); max-width: 440px; margin: 0 auto 22px; }

/* story page */
.story-head { display: grid; gap: 18px; margin-bottom: 18px; }
.photos { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; }
.photos a { flex: 0 0 auto; scroll-snap-align: start; }
.photos img { height: 220px; max-width: 80vw; object-fit: cover; border-radius: var(--radius); display: block; }
.logline { font-family: var(--serif); font-style: italic; color: var(--muted); font-size: 1.1rem; margin: 0 0 10px; }
.progress { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 30px 20px; }
.progress p { margin: 6px 0 0; }
#progress-text { font-weight: 600; transition: opacity .3s ease; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.player { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.player audio { width: 100%; }
.cast-row { display: grid; gap: 8px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.cast-row:last-of-type { border-bottom: 0; }
.cast-row .who { display: flex; flex-direction: column; }
.cast-row .pick { display: flex; gap: 8px; }
.cast-row select { flex: 1; min-width: 0; }
.script { font-family: var(--serif); font-size: 1.08rem; line-height: 1.7; max-height: 70vh; overflow-y: auto; padding-right: 6px; }
.script p { margin: 0 0 .8em; }
.script .line { padding-left: 14px; border-left: 2px solid #574a3e; }
.script .line b { font-family: var(--sans); font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); display: block; }
details summary { cursor: pointer; list-style: none; }
details summary::-webkit-details-marker { display: none; }
details summary h2 { display: inline; }
details summary::after { content: " ▾"; color: var(--muted); }
details[open] summary::after { content: " ▴"; }
.facts { padding-left: 18px; margin: 0; }
.facts li { margin-bottom: 4px; font-size: .95rem; }
.danger-zone { margin: 22px 0 10px; }
.danger-zone form { margin: 0; }

@media (min-width: 720px) {
  .cast-row { grid-template-columns: 1fr 1.4fr; align-items: center; }
  main { padding-top: 32px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
