:root {
  --bg: #f6f2e9;
  --surface: #fffdf8;
  --surface-2: #eee7db;
  --ink: #20252d;
  --muted: #66707c;
  --nav: #172339;
  --nav-soft: #25354f;
  --accent: #b88a31;
  --accent-strong: #8d651c;
  --line: #d8d0c3;
  --stage: #556274;
  --reader-size: 20px;
  --sidebar-width: 320px;
  --radius: 16px;
  --shadow: 0 18px 45px rgba(23, 35, 57, .12);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 28px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  text-rendering: optimizeLegibility;
}
button, a { font: inherit; }
a { color: inherit; }
button { cursor: pointer; }

.skip-link {
  position: fixed;
  z-index: 9999;
  top: 10px;
  left: 10px;
  transform: translateY(-180%);
  background: #fff;
  color: #000;
  padding: 12px 16px;
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.skip-link:focus { transform: translateY(0); }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-width);
  background: var(--nav);
  color: #f8f6f0;
  display: flex;
  flex-direction: column;
  padding: 28px 22px 24px;
  overflow-y: auto;
  z-index: 50;
}
.sidebar-header { position: relative; padding: 0 8px 20px; }
.sidebar h1 { margin: 4px 0 5px; font-size: 1.6rem; line-height: 1.13; }
.eyebrow { margin: 0; text-transform: uppercase; letter-spacing: .14em; font-size: .78rem; font-weight: 800; color: var(--accent); }
.sidebar-subtitle { margin: 0; color: #c9d0db; }
.close-menu { display: none; }

.act-nav { display: grid; gap: 7px; padding: 12px 0 18px; border-top: 1px solid rgba(255,255,255,.13); border-bottom: 1px solid rgba(255,255,255,.13); }
.nav-link {
  text-decoration: none;
  display: grid;
  gap: 2px;
  padding: 11px 12px;
  border-radius: 10px;
  color: #eef2f7;
  border: 1px solid transparent;
}
.nav-link span { font-weight: 800; }
.nav-link small { color: #aeb8c6; line-height: 1.25; }
.nav-link:hover, .nav-link:focus-visible { background: var(--nav-soft); outline: none; border-color: rgba(255,255,255,.18); }
.nav-link.active { background: #fff; color: var(--nav); }
.nav-link.active small { color: #536074; }

.access-panel { padding: 20px 4px 0; }
.access-title { margin: 0 0 8px; font-weight: 800; font-size: .9rem; text-transform: uppercase; letter-spacing: .08em; color: #cfd6df; }
.font-controls { display: grid; grid-template-columns: 1fr 1.4fr 1fr; gap: 8px; }
.font-btn, .font-reset, .contrast-btn, .secondary-button, .icon-button {
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 10px;
  min-height: 46px;
  background: var(--nav-soft);
  color: #fff;
  font-weight: 800;
}
.font-btn:hover, .font-reset:hover, .contrast-btn:hover { background: #314563; }
.font-reset { font-size: .9rem; }
.contrast-btn { width: 100%; margin-top: 8px; padding-inline: 12px; }
.sidebar-footnote { color: #9aa6b7; font-size: .82rem; line-height: 1.4; padding: 0 4px; margin-top: auto; padding-top: 18px; }

.content { margin-left: var(--sidebar-width); min-height: 100vh; }
.hero {
  padding: 72px clamp(28px, 7vw, 100px) 58px;
  background: linear-gradient(145deg, #fffaf0, #ece2d1);
  border-bottom: 1px solid var(--line);
}
.hero h1 { max-width: 760px; margin: 8px 0 14px; font-family: Georgia, "Times New Roman", serif; font-size: clamp(2.25rem, 5vw, 4.7rem); line-height: .98; letter-spacing: -.035em; color: var(--nav); }
.hero > p:not(.eyebrow) { font-size: 1.08rem; color: var(--muted); }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 25px; }
.primary-link, .secondary-button { min-height: 48px; display: inline-flex; align-items: center; justify-content: center; padding: 0 18px; border-radius: 10px; text-decoration: none; font-weight: 800; }
.primary-link { background: var(--nav); color: #fff; }
.secondary-button { display: none; background: transparent; color: var(--nav); border: 1px solid #9ca5b0; }

.reader { max-width: 940px; margin: 0 auto; padding: 26px clamp(22px, 5vw, 66px) 80px; font-size: var(--reader-size); line-height: 1.72; }
.script-section { scroll-margin-top: 26px; padding: 64px 0 34px; border-bottom: 1px solid var(--line); }
.script-section:last-child { border-bottom: none; }
.act-title { margin: 0 0 28px; font-family: Georgia, "Times New Roman", serif; font-size: 2.08em; line-height: 1.06; letter-spacing: -.025em; color: var(--nav); }
.section-label { margin: 38px 0 14px; font-size: 1.05em; line-height: 1.2; color: var(--accent-strong); text-transform: uppercase; letter-spacing: .055em; }
.part-title { margin: 44px 0 18px; padding-top: 16px; border-top: 2px solid var(--line); font-size: 1.34em; line-height: 1.25; color: var(--nav); }
.source-base { margin: -12px 0 26px; color: var(--muted); font-size: .92em; }
.cast-list { columns: 2; column-gap: 40px; padding-left: 1.4em; margin: 8px 0 28px; }
.cast-list li { break-inside: avoid; margin-bottom: .28em; }
.script-line { margin: .23em 0; }
.speaker { margin: 1.55em 0 .22em; font-weight: 900; letter-spacing: .025em; color: var(--nav); font-size: .94em; }
.stage-direction { margin: .85em 0; padding-left: 1em; border-left: 3px solid #bcc4ce; color: var(--stage); font-style: italic; font-size: .93em; }
.sfx { margin: .8em 0; font-weight: 900; letter-spacing: .12em; color: var(--accent-strong); }
.historical-note { margin: 26px 0; padding: 18px 20px; border: 1px solid #cfbd94; border-left: 5px solid var(--accent); border-radius: 10px; background: #fff9e9; font-size: .93em; color: #3f4650; }
.meta-line { margin: .25em 0; }
.meta-line strong { color: var(--nav); margin-right: .3em; }

.site-footer { max-width: 940px; margin: 0 auto; padding: 30px clamp(22px, 5vw, 66px) 60px; color: var(--muted); border-top: 1px solid var(--line); }
.site-footer a { font-weight: 800; color: var(--nav); }

.mobile-bar { display: none; }
.sidebar-backdrop { display: none; }
.back-to-top {
  position: fixed;
  right: 22px;
  bottom: 22px;
  width: 50px;
  height: 50px;
  border: 0;
  border-radius: 50%;
  background: var(--nav);
  color: #fff;
  box-shadow: var(--shadow);
  font-size: 1.3rem;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: .2s ease;
  z-index: 30;
}
.back-to-top.visible { opacity: 1; pointer-events: auto; transform: translateY(0); }

:focus-visible { outline: 3px solid #e0a83f; outline-offset: 3px; }

body.high-contrast {
  --bg: #000;
  --surface: #000;
  --surface-2: #111;
  --ink: #fff;
  --muted: #e8e8e8;
  --nav: #000;
  --nav-soft: #181818;
  --accent: #ffd400;
  --accent-strong: #ffd400;
  --line: #fff;
  --stage: #fff;
}
body.high-contrast .hero { background: #000; border-color: #fff; }
body.high-contrast .hero h1,
body.high-contrast .act-title,
body.high-contrast .speaker,
body.high-contrast .part-title,
body.high-contrast .meta-line strong,
body.high-contrast .site-footer a { color: #fff; }
body.high-contrast .historical-note { background: #111; color: #fff; border-color: #ffd400; }
body.high-contrast .stage-direction { border-color: #ffd400; }
body.high-contrast .nav-link.active { background: #ffd400; color: #000; }
body.high-contrast .nav-link.active small { color: #000; }

@media (max-width: 900px) {
  html { scroll-padding-top: 76px; }
  body { padding-top: 68px; }
  .mobile-bar {
    position: fixed;
    display: grid;
    grid-template-columns: 48px 1fr auto;
    align-items: center;
    gap: 9px;
    top: 0;
    left: 0;
    right: 0;
    min-height: 68px;
    padding: 8px max(10px, env(safe-area-inset-right)) 8px max(10px, env(safe-area-inset-left));
    background: var(--nav);
    color: #fff;
    z-index: 80;
    box-shadow: 0 5px 18px rgba(0,0,0,.18);
  }
  .mobile-title { min-width: 0; line-height: 1.13; }
  .mobile-title strong, .mobile-title span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-title strong { font-size: .9rem; }
  .mobile-title span { font-size: .76rem; color: #c9d0db; margin-top: 3px; }
  .icon-button { min-width: 46px; font-size: 1.35rem; }
  .mobile-font-controls { display: flex; gap: 5px; }
  .font-btn.compact { min-height: 44px; min-width: 48px; padding: 0 8px; background: var(--nav-soft); }

  .sidebar {
    width: min(88vw, 340px);
    transform: translateX(-103%);
    transition: transform .22s ease;
    z-index: 100;
    padding-top: max(22px, env(safe-area-inset-top));
  }
  body.menu-open { overflow: hidden; }
  body.menu-open .sidebar { transform: translateX(0); }
  .close-menu { display: inline-grid; place-items: center; position: absolute; right: 2px; top: 0; min-width: 46px; }
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.56);
    z-index: 90;
  }
  body.menu-open .sidebar-backdrop { display: block; }
  .content { margin-left: 0; }
  .hero { padding: 44px 22px 42px; }
  .hero h1 { font-size: clamp(2.25rem, 13vw, 4rem); }
  .secondary-button { display: inline-flex; }
  .reader { padding: 6px 20px 72px; }
  .script-section { scroll-margin-top: 82px; padding-top: 54px; }
  .act-title { font-size: 1.78em; }
  .cast-list { columns: 1; }
  .stage-direction { padding-left: .8em; }
  .back-to-top { right: 14px; bottom: max(14px, env(safe-area-inset-bottom)); }
}

@media (max-width: 480px) {
  :root { --reader-size: 19px; }
  .reader { padding-inline: 16px; }
  .hero { padding-inline: 18px; }
  .mobile-title strong { font-size: .82rem; }
  .mobile-font-controls .font-btn { min-width: 44px; }
  .act-title { font-size: 1.62em; }
}

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

@media print {
  .sidebar, .mobile-bar, .back-to-top, .hero-actions { display: none !important; }
  body { background: #fff; color: #000; padding: 0; }
  .content { margin: 0; }
  .hero { background: none; padding: 20px 0; }
  .reader { max-width: none; padding: 0; font-size: 12pt; }
  .script-section { break-before: page; border: 0; }
  .script-section:first-child { break-before: auto; }
}
