:root {
  color-scheme: light;
  --ink: #17333e;
  --muted: #61727a;
  --navy: #123f52;
  --navy-deep: #0b2d3a;
  --eucalyptus: #39775e;
  --leaf: #6f9c72;
  --sun: #f4c955;
  --coral: #dc755e;
  --paper: #fffdf5;
  --canvas: #edf4ee;
  --line: #d2dfd4;
  --shadow: 0 24px 60px rgba(17, 57, 66, 0.16);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 8% 2%, rgba(244, 201, 85, 0.22), transparent 24rem),
    linear-gradient(180deg, #f6faf6 0%, var(--canvas) 100%);
  color: var(--ink);
  font-family: Inter, ui-rounded, "Segoe UI", system-ui, -apple-system, sans-serif;
  line-height: 1.55;
}

button, select { font: inherit; }

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.8rem clamp(1rem, 4vw, 3rem);
  color: white;
  background: rgba(11, 45, 58, 0.96);
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(12px);
}

.brand { display: flex; align-items: center; gap: 0.7rem; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 2.65rem;
  height: 2.65rem;
  border-radius: 50% 50% 44% 56%;
  background: var(--sun);
  color: var(--navy-deep);
  font-weight: 900;
  letter-spacing: -0.08em;
  transform: rotate(-5deg);
}
.brand span:last-child { display: grid; line-height: 1.18; }
.brand small { color: #c8ddd5; font-size: 0.76rem; margin-top: 0.2rem; }

.view-switch {
  display: flex;
  padding: 0.2rem;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 999px;
}
.view-button {
  min-height: 2.35rem;
  padding: 0.42rem 0.9rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #d8e6e1;
  cursor: pointer;
}
.view-button.active { color: var(--navy-deep); background: white; font-weight: 800; }

.workspace { width: min(1280px, calc(100% - 2rem)); margin: 0 auto; padding: 2.2rem 0 4rem; }
.book-heading { display: flex; justify-content: space-between; align-items: end; gap: 2rem; margin-bottom: 1.25rem; }
.eyebrow { margin: 0 0 0.25rem; color: var(--eucalyptus); font-size: 0.78rem; font-weight: 900; letter-spacing: 0.14em; text-transform: uppercase; }
h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(2rem, 5vw, 4.4rem); line-height: 0.98; letter-spacing: -0.04em; }
h1 span { color: var(--eucalyptus); }
.revision { margin: 0; color: var(--muted); font-size: 0.85rem; text-align: right; }

.studio-note {
  margin-bottom: 1rem;
  padding: 1.1rem 1.25rem;
  border: 1px solid #c5d7c8;
  border-left: 5px solid var(--eucalyptus);
  border-radius: 1rem;
  background: rgba(255, 255, 255, 0.74);
  box-shadow: 0 10px 30px rgba(25, 76, 66, 0.07);
}
.studio-note-heading { display: flex; justify-content: space-between; gap: 1rem; align-items: start; }
.note-kicker { color: var(--coral); font-size: 0.74rem; font-weight: 900; letter-spacing: 0.12em; text-transform: uppercase; }
.studio-note h2 { margin: 0.12rem 0 0; font-size: 1.08rem; }
.studio-note > p, .studio-note details p { margin: 0.65rem 0 0; color: #405a61; }
.studio-note details { margin-top: 0.65rem; }
.studio-note summary { color: var(--eucalyptus); font-weight: 800; cursor: pointer; }
.draft-pill { flex: 0 0 auto; padding: 0.3rem 0.58rem; border-radius: 999px; background: #deece2; color: #285f4a; font-size: 0.74rem; font-weight: 800; }

.booklet {
  display: grid;
  grid-template-columns: minmax(0, 1.13fr) minmax(340px, 0.87fr);
  min-height: 660px;
  overflow: hidden;
  border: 1px solid rgba(24, 56, 63, 0.12);
  border-radius: 1.5rem;
  background: var(--paper);
  box-shadow: var(--shadow);
}
.art-panel { position: relative; min-height: 620px; background: #153d42; overflow: hidden; }
.art-panel::after { content: ""; position: absolute; inset: 0; box-shadow: inset -30px 0 44px rgba(7, 35, 43, 0.16); pointer-events: none; }
.art-panel img { width: 100%; height: 100%; display: block; object-fit: cover; object-position: center; }
.story-page {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: clamp(2rem, 4vw, 4.4rem);
  background:
    linear-gradient(90deg, rgba(16, 61, 74, 0.055), transparent 1.4rem),
    radial-gradient(circle at 100% 0, rgba(244, 201, 85, 0.15), transparent 16rem),
    var(--paper);
}
.page-rule { width: 3.5rem; height: 0.45rem; margin-bottom: 1.15rem; border-radius: 999px; background: linear-gradient(90deg, var(--coral), var(--sun)); }
.page-label { margin: 0 0 0.35rem; color: var(--eucalyptus); font-size: 0.78rem; font-weight: 900; letter-spacing: 0.14em; text-transform: uppercase; }
.story-page h2 { margin: 0 0 1.4rem; font-family: Georgia, "Times New Roman", serif; font-size: clamp(1.85rem, 3vw, 3rem); line-height: 1.03; letter-spacing: -0.025em; }
.script { display: grid; gap: 0.78rem; }
.line { margin: 0; font-size: 1rem; line-height: 1.55; }
.line.narrator { padding-left: 1rem; border-left: 3px solid var(--sun); color: #344e55; font-family: Georgia, "Times New Roman", serif; font-size: 1.06rem; font-style: italic; }
.speaker { color: var(--navy); font-weight: 900; }
.line.dialogue .speaker { display: inline; margin-right: 0.28rem; }
.line.sfx { justify-self: start; padding: 0.25rem 0.7rem; border-radius: 999px; background: #e7f0eb; color: var(--eucalyptus); font-weight: 900; letter-spacing: 0.08em; }
.line.card { padding: 0.9rem 1rem; border: 1px dashed #9db6aa; border-radius: 0.8rem; background: #f4f8f2; font-size: 0.9rem; }
.line.card .speaker { display: block; margin-bottom: 0.25rem; color: var(--coral); font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; }
.page-number { position: absolute; display: grid; place-items: center; width: 2.75rem; height: 2.75rem; border-radius: 50%; font-weight: 900; }
.art-number { top: 1rem; left: 1rem; background: rgba(255, 253, 245, 0.93); color: var(--navy); box-shadow: 0 6px 20px rgba(0,0,0,.16); }
.paper-number { right: 1.25rem; bottom: 1.25rem; border: 1px solid #d7e1d4; color: var(--eucalyptus); }

.page-controls { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 1rem; margin: 1.15rem 0 2.2rem; }
.nav-button, .page-select-label { min-height: 2.85rem; border: 1px solid #b9ccc1; border-radius: 999px; background: white; color: var(--navy); font-weight: 800; }
.nav-button { padding: 0.65rem 1.05rem; cursor: pointer; }
.nav-button:last-child { justify-self: end; }
.nav-button.primary { border-color: var(--navy); background: var(--navy); color: white; }
.nav-button:disabled { opacity: 0.42; cursor: not-allowed; }
.page-select-label { display: flex; align-items: center; gap: 0.5rem; padding: 0.15rem 0.5rem 0.15rem 0.9rem; }
.page-select-label select { max-width: 18rem; min-height: 2.3rem; border: 0; background: transparent; color: var(--navy); }

.filmstrip { border-top: 1px solid var(--line); padding-top: 1.25rem; }
.filmstrip-heading { display: flex; align-items: baseline; gap: 0.8rem; }
.filmstrip h2 { margin: 0; font-size: 1.05rem; }
.filmstrip p { margin: 0; color: var(--muted); font-size: 0.85rem; }
.thumbnails { display: grid; grid-template-columns: repeat(10, minmax(84px, 1fr)); gap: 0.65rem; margin-top: 0.9rem; }
.thumbnail { position: relative; aspect-ratio: 4 / 3; padding: 0; overflow: hidden; border: 3px solid transparent; border-radius: 0.72rem; background: #dce7de; cursor: pointer; }
.thumbnail img { width: 100%; height: 100%; display: block; object-fit: cover; }
.thumbnail span { position: absolute; left: 0.3rem; bottom: 0.3rem; display: grid; place-items: center; width: 1.6rem; height: 1.6rem; border-radius: 50%; background: rgba(10,45,58,.88); color: white; font-size: 0.75rem; font-weight: 900; }
.thumbnail.active { border-color: var(--sun); box-shadow: 0 0 0 2px var(--navy); }

body.reader-mode .studio-note { display: none; }
body.reader-mode .workspace { padding-top: 1.6rem; }
body.reader-mode .revision { display: none; }

@media (max-width: 980px) {
  .booklet { grid-template-columns: 1fr; }
  .art-panel { min-height: 52vw; max-height: 580px; }
  .story-page { min-height: 520px; }
  .thumbnails { grid-template-columns: repeat(5, minmax(84px, 1fr)); }
}

@media (max-width: 640px) {
  .topbar { align-items: stretch; flex-direction: column; }
  .view-switch { align-self: stretch; }
  .view-button { flex: 1; }
  .workspace { width: min(100% - 1rem, 1280px); padding-top: 1.25rem; }
  .book-heading { align-items: start; flex-direction: column; gap: 0.45rem; }
  .revision { text-align: left; }
  .studio-note { padding: 1rem; }
  .draft-pill { display: none; }
  .booklet { border-radius: 1rem; }
  .art-panel { min-height: 72vw; }
  .story-page { min-height: 500px; padding: 1.5rem 1.25rem 4rem; }
  .line, .line.narrator { font-size: 1rem; }
  .page-controls { grid-template-columns: 1fr 1fr; }
  .page-select-label { grid-column: 1 / -1; grid-row: 1; justify-content: center; }
  .page-select-label select { width: 100%; }
  .nav-button { grid-row: 2; }
  .thumbnails { display: flex; overflow-x: auto; padding: 0.2rem 0.15rem 0.8rem; scroll-snap-type: x mandatory; }
  .thumbnail { flex: 0 0 7rem; scroll-snap-align: start; }
  .filmstrip-heading { align-items: start; flex-direction: column; gap: 0.2rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}
