:root {
  --ink: #130f0c;
  --ink-2: #1c1713;
  --ink-3: #2a221c;
  --line: rgba(242, 228, 208, 0.12);
  --paper: #f2e4d0;
  --paper-dim: rgba(242, 228, 208, 0.62);
  --amber: #f2a93b;
  --ember: #d9572b;
  --danger: #e2674b;
  --display: "Fraunces", Georgia, serif;
  --body: "Newsreader", Georgia, serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --radius: 14px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(217, 87, 43, 0.18), transparent 60%),
    radial-gradient(900px 500px at -10% 30%, rgba(242, 169, 59, 0.08), transparent 60%),
    var(--ink);
  color: var(--paper);
  font-family: var(--body);
  font-size: 18px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
.grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 100; opacity: 0.07;
  background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}
.mono { font-family: var(--mono); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; }
a { color: inherit; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 3px; }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 22px clamp(20px, 5vw, 64px);
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(var(--ink) 40%, transparent);
}
.wordmark {
  font-family: var(--display); font-size: 26px; font-weight: 600; text-decoration: none;
  letter-spacing: -0.02em;
}
.wordmark span { font-style: italic; font-weight: 400; color: var(--amber); }
.topbar nav { display: flex; gap: 6px; }
.topbar nav a {
  text-decoration: none; font-family: var(--mono); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase;
  padding: 9px 14px; border-radius: 999px; border: 1px solid transparent; color: var(--paper-dim);
  transition: color .2s, border-color .2s;
}
.topbar nav a:hover { color: var(--paper); }
.topbar nav a.active { color: var(--paper); border-color: var(--line); }

main { padding: 0 clamp(20px, 5vw, 64px) 120px; max-width: 1280px; margin: 0 auto; }

/* Hero */
.hero { padding: clamp(32px, 7vw, 90px) 0 36px; max-width: 900px; }
.kicker { color: var(--amber); margin: 0 0 18px; }
.hero h1, .library-head h1 {
  font-family: var(--display); font-weight: 350; font-size: clamp(44px, 7.4vw, 104px);
  line-height: 0.95; letter-spacing: -0.035em; margin: 0;
  font-variation-settings: "opsz" 144;
}
.hero h1 em { font-style: italic; color: var(--amber); font-weight: 300; }
.lede { font-size: clamp(19px, 1.8vw, 23px); color: var(--paper-dim); max-width: 600px; margin: 26px 0 0; }

.hero > * { animation: rise .9s cubic-bezier(.2,.7,.2,1) both; }
.hero > :nth-child(2) { animation-delay: .08s; }
.hero > :nth-child(3) { animation-delay: .18s; }
@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }

/* Drop zone */
.drop {
  display: block; position: relative; cursor: pointer;
  border: 1.5px dashed rgba(242, 169, 59, 0.45); border-radius: 22px;
  padding: clamp(36px, 6vw, 72px) 24px; text-align: center;
  background: linear-gradient(180deg, rgba(242,169,59,0.05), rgba(242,169,59,0.01));
  transition: border-color .25s, background .25s, transform .25s;
  animation: rise .9s .28s cubic-bezier(.2,.7,.2,1) both;
}
.drop:hover, .drop.over { border-color: var(--amber); background: rgba(242,169,59,0.08); }
.drop.over { transform: scale(1.01); }
.drop-inner { display: grid; justify-items: center; gap: 8px; }
.drop strong { font-family: var(--display); font-weight: 500; font-size: 30px; letter-spacing: -0.01em; }
.drop span { color: var(--paper-dim); }
.drop small { color: var(--paper-dim); opacity: .7; margin-top: 14px; max-width: 460px; line-height: 1.6; text-transform: none; letter-spacing: 0.02em; }
.reel { display: flex; gap: 6px; margin-bottom: 14px; }
.reel span {
  width: 34px; height: 46px; border-radius: 5px; background: var(--ink-3); border: 1px solid var(--line);
  position: relative; animation: flicker 2.4s infinite ease-in-out;
}
.reel span::before, .reel span::after {
  content: ""; position: absolute; left: 5px; right: 5px; height: 3px;
  background: repeating-linear-gradient(90deg, var(--ink) 0 4px, transparent 4px 8px);
}
.reel span::before { top: 3px; } .reel span::after { bottom: 3px; }
.reel span:nth-child(2) { animation-delay: .2s } .reel span:nth-child(3) { animation-delay: .4s; background: var(--amber); }
.reel span:nth-child(4) { animation-delay: .6s } .reel span:nth-child(5) { animation-delay: .8s }
@keyframes flicker { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-6px) } }

.form-error { color: var(--danger); margin: 14px 0 0; font-size: 16px; }

/* Composer */
.composer {
  display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: clamp(24px, 4vw, 56px);
  align-items: start; animation: rise .6s cubic-bezier(.2,.7,.2,1) both;
}
.preview { position: sticky; top: 96px; }
.preview video {
  width: 100%; max-height: 70vh; border-radius: var(--radius); background: #000; display: block;
  box-shadow: 0 30px 80px -30px rgba(0,0,0,.8), 0 0 0 1px var(--line);
}
.preview .meta { color: var(--paper-dim); margin-top: 14px; text-transform: none; letter-spacing: .02em; word-break: break-all; }
.link { background: none; border: 0; padding: 0; margin-top: 8px; color: var(--amber); text-decoration: underline; text-underline-offset: 3px; font-size: 16px; }

.controls { display: grid; gap: 30px; }
.label { color: var(--paper-dim); display: block; margin-bottom: 12px; }
.label em { text-transform: none; font-style: normal; opacity: .6; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }

.strip-wrap { min-width: 0; }
.filmstrip {
  list-style: none; margin: 0; padding: 12px 10px; display: flex; gap: 8px; overflow-x: auto;
  background: #0a0806; border-radius: 10px; position: relative; scrollbar-width: thin;
  border-top: 10px solid #0a0806; border-bottom: 10px solid #0a0806;
  background-image:
    repeating-linear-gradient(90deg, transparent 0 6px, rgba(242,228,208,.18) 6px 12px, transparent 12px 18px),
    repeating-linear-gradient(90deg, transparent 0 6px, rgba(242,228,208,.18) 6px 12px, transparent 12px 18px);
  background-size: 18px 5px, 18px 5px; background-repeat: repeat-x; background-position: 0 2px, 0 calc(100% - 2px);
}
.filmstrip li { flex: 0 0 auto; position: relative; animation: pop .45s cubic-bezier(.2,.8,.2,1.2) both; }
.filmstrip img, .filmstrip .ph { height: 84px; width: auto; aspect-ratio: 16/10; object-fit: cover; border-radius: 4px; display: block; background: var(--ink-3); }
.filmstrip .ph { width: 134px; animation: shimmer 1.2s infinite linear; background: linear-gradient(90deg, var(--ink-3), #3a2f26, var(--ink-3)); background-size: 200% 100%; }
.filmstrip time { position: absolute; left: 5px; bottom: 4px; font: 500 10px var(--mono); background: rgba(0,0,0,.6); padding: 1px 5px; border-radius: 3px; }
@keyframes pop { from { opacity: 0; transform: scale(.85) } to { opacity: 1; transform: none } }
@keyframes shimmer { to { background-position: -200% 0 } }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips input, .segmented input { position: absolute; opacity: 0; pointer-events: none; }
.chips span {
  display: inline-block; padding: 9px 16px; border-radius: 999px; border: 1px solid var(--line);
  font-size: 17px; transition: all .18s; cursor: pointer; user-select: none;
}
.chips label:hover span { border-color: rgba(242,169,59,.5); }
.chips input:checked + span { background: var(--amber); color: var(--ink); border-color: var(--amber); }
.chips input:focus-visible + span, .segmented input:focus-visible + span { outline: 2px solid var(--amber); outline-offset: 2px; }

.segmented { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.segmented span { display: grid; padding: 12px 14px; cursor: pointer; transition: background .18s; font-size: 18px; border-right: 1px solid var(--line); }
.segmented label:last-child span { border-right: 0; }
.segmented small { font-family: var(--mono); font-size: 11px; color: var(--paper-dim); letter-spacing: .04em; }
.segmented input:checked + span { background: rgba(242,169,59,.14); box-shadow: inset 0 -2px 0 var(--amber); }

.notes textarea {
  width: 100%; background: var(--ink-2); color: var(--paper); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px; font: inherit; font-size: 17px; resize: vertical;
}
.notes textarea::placeholder { color: rgba(242,228,208,.35); font-style: italic; }
.notes textarea:focus { outline: none; border-color: var(--amber); }

.cta {
  justify-self: start; display: inline-flex; align-items: center; gap: 14px;
  background: var(--amber); color: var(--ink); border: 0; border-radius: 999px;
  padding: 18px 30px; font-family: var(--display); font-size: 22px; font-weight: 600; letter-spacing: -0.01em;
  transition: transform .2s, box-shadow .2s, opacity .2s;
  box-shadow: 0 14px 40px -12px rgba(242,169,59,.6);
}
.cta svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; transition: transform .2s; }
.cta:hover:not(:disabled) { transform: translateY(-2px); }
.cta:hover:not(:disabled) svg { transform: translateX(4px); }
.cta:active:not(:disabled) { transform: translateY(0); }
.cta:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; }

/* Story / book */
.book { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: clamp(24px, 5vw, 72px); padding-top: 28px; }
.book-reel { display: grid; gap: 10px; align-content: start; position: sticky; top: 96px; max-height: calc(100vh - 120px); overflow-y: auto; scrollbar-width: none; }
.book-reel img { width: 100%; border-radius: 6px; display: block; filter: sepia(.25) saturate(.9); opacity: 0; animation: fadeIn .6s forwards; box-shadow: 0 0 0 1px var(--line); }
.book-reel .ph { aspect-ratio: 16/10; border-radius: 6px; background: linear-gradient(90deg, var(--ink-3), #3a2f26, var(--ink-3)); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }
@keyframes fadeIn { to { opacity: 1 } }

.page { max-width: 700px; }
.page h1 {
  font-family: var(--display); font-weight: 400; font-size: clamp(40px, 5.6vw, 76px); line-height: 1; letter-spacing: -0.03em; margin: 0 0 40px;
  font-variation-settings: "opsz" 144; min-height: 1em;
}
.page h1.pending { color: var(--paper-dim); font-style: italic; }
.story-body { font-size: 21px; line-height: 1.72; }
.story-body h2 {
  font-family: var(--display); font-weight: 500; font-style: italic; font-size: 26px; color: var(--amber);
  margin: 2.2em 0 .6em; letter-spacing: -0.01em;
}
.story-body h2:first-child { margin-top: 0; }
.story-body p { margin: 0 0 1.05em; }
.story-body h2 + p::first-letter {
  font-family: var(--display); float: left; font-size: 4.1em; line-height: .82; padding: .06em .1em 0 0; color: var(--amber); font-weight: 500;
}
.story-body.writing > :last-child::after {
  content: ""; display: inline-block; width: .5em; height: 1.05em; background: var(--amber); vertical-align: -0.15em; margin-left: 3px;
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0 } }
.thinking { color: var(--paper-dim); font-style: italic; display: flex; align-items: center; gap: 12px; }
.thinking::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--amber); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { transform: scale(.7); opacity: .5 } 50% { transform: scale(1.2); opacity: 1 } }

.story-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 56px; padding-top: 28px; border-top: 1px solid var(--line); }
.ghost {
  background: none; border: 1px solid var(--line); border-radius: 999px; padding: 10px 18px; font-size: 16px; text-decoration: none;
  transition: border-color .2s, background .2s;
}
.ghost:hover { border-color: var(--amber); }
.ghost.danger:hover { border-color: var(--danger); color: var(--danger); }

/* Library */
.library-head { padding: clamp(28px, 5vw, 64px) 0 40px; }
.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 22px; }
.card {
  display: grid; text-decoration: none; background: var(--ink-2); border-radius: var(--radius); overflow: hidden;
  box-shadow: 0 0 0 1px var(--line); transition: transform .25s, box-shadow .25s;
  animation: rise .6s cubic-bezier(.2,.7,.2,1) both;
}
.card:hover { transform: translateY(-4px) rotate(-.3deg); box-shadow: 0 0 0 1px rgba(242,169,59,.5), 0 24px 50px -20px rgba(0,0,0,.8); }
.card .cover { aspect-ratio: 16/9; background: var(--ink-3); overflow: hidden; }
.card .cover img { width: 100%; height: 100%; object-fit: cover; filter: sepia(.2); transition: transform .5s; }
.card:hover .cover img { transform: scale(1.05); }
.card .body { padding: 18px 20px 22px; }
.card .tag { color: var(--amber); }
.card h3 { font-family: var(--display); font-weight: 500; font-size: 25px; line-height: 1.1; margin: 8px 0 10px; letter-spacing: -0.01em; }
.card p { margin: 0; color: var(--paper-dim); font-size: 16px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.card.skeleton { pointer-events: none; }
.card.skeleton .cover, .card.skeleton .line { background: linear-gradient(90deg, var(--ink-3), #3a2f26, var(--ink-3)); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }
.card.skeleton .line { height: 14px; border-radius: 4px; margin-top: 10px; }
.card.skeleton .line.big { height: 24px; width: 70%; }
.empty { grid-column: 1 / -1; text-align: center; padding: 70px 20px; border: 1.5px dashed var(--line); border-radius: 22px; }
.empty h2 { font-family: var(--display); font-weight: 400; font-size: 34px; margin: 0 0 10px; }
.empty p { color: var(--paper-dim); margin: 0 0 24px; }
.empty .cta { justify-self: center; text-decoration: none; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--paper); color: var(--ink); padding: 12px 20px; border-radius: 999px; font-size: 16px; z-index: 50;
  transition: opacity .25s, transform .25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 860px) {
  .composer { grid-template-columns: 1fr; }
  .preview { position: static; }
  .book { grid-template-columns: 1fr; }
  .book-reel { position: static; display: flex; overflow-x: auto; max-height: none; }
  .book-reel img, .book-reel .ph { width: 120px; flex: 0 0 auto; }
  .story-body { font-size: 19px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
