:root {
  color-scheme: light;
  --wine: #7f1726;
  --wine-dark: #57101b;
  --cream: #fff8ee;
  --paper: #ffffff;
  --ink: #251b1c;
  --muted: #715f61;
  --line: #decfd0;
  --gold: #d6ad5b;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  font-family: ui-rounded, "Avenir Next", Avenir, system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 15% 0%, #f4d9d3 0, transparent 34%), var(--cream);
}

button, input { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 4px solid #2b74d6; outline-offset: 3px; }

.auth-locked > :not(.password-gate):not(script) { visibility: hidden; }
.password-gate {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 10%, rgba(214, 173, 91, .25), transparent 30%),
    linear-gradient(135deg, #3e0811, var(--wine));
}
.password-gate[hidden] { display: none; }
.password-card {
  width: min(480px, 100%);
  padding: clamp(30px, 7vw, 54px);
  border-radius: 26px;
  background: var(--paper);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .38);
}
.book-mark {
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  margin-bottom: 24px;
  border-radius: 20px;
  color: white;
  background: var(--wine);
  font: 700 2.35rem/1 Georgia, serif;
  box-shadow: inset -8px 0 rgba(0, 0, 0, .12), 0 10px 26px rgba(127, 23, 38, .2);
}
.password-card h1 { margin-bottom: 12px; color: var(--wine); font-size: clamp(2.3rem, 7vw, 3.6rem); }
.password-card > p:not(.eyebrow):not(.password-error) { margin-bottom: 24px; color: var(--muted); font-size: 1.08rem; line-height: 1.55; }
.password-card label { display: block; margin-bottom: 8px; font-weight: 800; }
.password-card input {
  width: 100%;
  min-height: 58px;
  margin-bottom: 14px;
  padding: 12px 16px;
  border: 2px solid var(--line);
  border-radius: 14px;
  color: var(--ink);
  background: white;
  font-size: 1.15rem;
}
.password-card input[aria-invalid="true"] { border-color: #b42318; }
.password-card .primary { width: 100%; margin-top: 8px; }
.password-error { margin: -2px 0 12px; color: #9b1c1c; font-weight: 750; }

.app {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  gap: 14px;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
}
.topbar-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.home-link { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-family: Georgia, serif; font-size: clamp(1.65rem, 4vw, 2.45rem); }
h2 { font-family: Georgia, serif; font-size: clamp(1.8rem, 4vw, 2.7rem); }
.eyebrow { margin-bottom: 2px; color: var(--wine); font-size: .9rem; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }

.book-stage {
  min-height: 0;
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr) 76px;
  align-items: center;
  gap: 16px;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
}

.page-frame {
  min-width: 0;
  min-height: 0;
  height: 100%;
  margin: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.page-frame img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
  background: white;
  box-shadow: 0 15px 50px rgba(74, 25, 31, .2);
}

.page-arrow {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: var(--paper);
  color: var(--wine);
  font: 700 3rem/1 Georgia, serif;
  box-shadow: 0 8px 24px rgba(70, 30, 34, .12);
}
.page-arrow:disabled { opacity: .28; cursor: default; }

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.primary, .soft, .voice {
  min-height: 52px;
  border-radius: 16px;
  padding: 12px 20px;
  border: 2px solid transparent;
  font-weight: 800;
  font-size: 1rem;
}
.primary { background: var(--wine); color: white; box-shadow: 0 8px 20px rgba(127, 23, 38, .22); }
.primary:hover { background: var(--wine-dark); }
.primary.large { min-height: 64px; padding-inline: 30px; font-size: 1.2rem; }
.soft { background: white; color: var(--wine); border-color: var(--line); }
.soft.large { min-height: 64px; padding-inline: 30px; font-size: 1.1rem; }
.voice { background: #f0e4ce; color: #5c4017; border-color: #dec58f; }
.voice small { display: block; font-size: .72rem; font-weight: 700; }

.progress-area {
  max-width: 700px;
  width: 100%;
  margin: 0 auto;
  display: grid;
  grid-template-columns: auto minmax(130px, 1fr);
  align-items: center;
  gap: 16px;
  color: var(--muted);
  font-size: 1rem;
}
.progress-area label { white-space: nowrap; }
.progress-area input { width: 100%; accent-color: var(--wine); min-height: 32px; }

.welcome {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, rgba(62, 8, 17, .96), rgba(127, 23, 38, .94));
}
.welcome[hidden] { display: none; }
.welcome-card {
  width: min(880px, 100%);
  max-height: calc(100dvh - 48px);
  display: grid;
  grid-template-columns: minmax(220px, 390px) 1fr;
  overflow: hidden;
  border-radius: 26px;
  background: white;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .35);
}
.welcome-cover { width: 100%; height: 100%; min-height: 0; object-fit: cover; object-position: center top; }
.welcome-copy { align-self: center; padding: clamp(30px, 7vw, 70px); }
.welcome-copy h1 { margin-bottom: 18px; color: var(--wine); font-size: clamp(2.3rem, 6vw, 4.2rem); }
.welcome-copy p:not(.eyebrow) { font-size: 1.2rem; line-height: 1.6; }
.welcome-actions { display: grid; gap: 12px; }
.film-access { display: grid; gap: 10px; }
.film-access[hidden] { display: none; }
.film-heading { margin: 4px 0 0; color: var(--wine); font-weight: 800; }
.film-link {
  display: grid;
  place-items: center;
  text-align: center;
  text-decoration: none;
}
.film-link small { display: block; margin-top: 2px; font-size: .78rem; }
.film-link:hover { border-color: var(--wine); background: var(--cream); }

.film-dialog {
  width: min(1040px, calc(100% - 28px));
  max-height: calc(100dvh - 28px);
  padding: clamp(18px, 3vw, 32px);
  overflow: auto;
}
.film-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}
.film-dialog-head h2 { margin: 0; color: var(--wine); }
.video-keepsake {
  position: relative;
  padding: clamp(20px, 4.5vw, 46px);
  border: 5px solid var(--gold);
  border-radius: 28px;
  background:
    radial-gradient(circle at 15% 15%, rgba(214, 173, 91, .32), transparent 24%),
    radial-gradient(circle at 85% 85%, rgba(214, 173, 91, .28), transparent 24%),
    var(--wine);
  box-shadow: inset 0 0 0 5px white, 0 16px 44px rgba(74, 25, 31, .24);
}
.video-frame {
  position: relative;
  z-index: 1;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 5px solid white;
  border-radius: 18px;
  background: #171113;
  box-shadow: 0 12px 34px rgba(0, 0, 0, .34);
}
.video-frame iframe { display: block; width: 100%; height: 100%; border: 0; }
.oma-face {
  position: absolute;
  z-index: 2;
  width: clamp(52px, 8vw, 78px);
  aspect-ratio: 1;
  border: 4px solid white;
  border-radius: 50%;
  object-fit: cover;
  background: var(--cream);
  box-shadow: 0 5px 16px rgba(0, 0, 0, .28);
}
.face-top-left { top: 5px; left: 5px; transform: rotate(-8deg); }
.face-top-right { top: 5px; right: 5px; transform: rotate(8deg); }
.face-bottom-left { bottom: 5px; left: 5px; transform: rotate(8deg); }
.face-bottom-right { right: 5px; bottom: 5px; transform: rotate(-8deg); }

dialog {
  border: 0;
  border-radius: 24px;
  color: var(--ink);
  background: var(--cream);
  box-shadow: 0 20px 80px rgba(0,0,0,.36);
}
dialog::backdrop { background: rgba(36, 17, 20, .78); backdrop-filter: blur(5px); }
.pages-dialog { width: min(1050px, calc(100% - 28px)); height: min(820px, calc(100dvh - 28px)); padding: 22px; }
.dialog-head { position: sticky; top: -22px; z-index: 2; display: flex; align-items: center; justify-content: space-between; padding: 18px 0 14px; background: var(--cream); }
.dialog-head h2 { margin: 0; }
.page-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 16px; }
.thumb { border: 3px solid transparent; border-radius: 14px; padding: 8px; background: white; color: var(--ink); font-weight: 800; }
.thumb:hover, .thumb.current { border-color: var(--wine); }
.thumb img { display: block; width: 100%; aspect-ratio: 595 / 842; object-fit: cover; margin-bottom: 8px; border-radius: 7px; background: #eee; }

.song-card {
  width: min(700px, 100%);
  margin: 10px auto 0;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border: 2px solid var(--line);
  border-radius: 20px;
  background: white;
  box-shadow: 0 8px 24px rgba(70, 30, 34, .08);
}
.song-card h2 { margin: 0; font-size: clamp(1.35rem, 3vw, 1.8rem); }
.song-button { flex: 0 0 auto; }

.search-dialog { width: min(760px, calc(100% - 28px)); max-height: min(820px, calc(100dvh - 28px)); padding: clamp(26px, 5vw, 44px); }
.search-dialog > p:not(.eyebrow):not(.search-help) { color: var(--muted); font-size: 1.08rem; line-height: 1.55; }
.search-dialog h2 { margin-bottom: 8px; }
.search-form label { display: block; margin-bottom: 8px; font-weight: 800; }
.search-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; }
.search-row input {
  width: 100%;
  min-height: 56px;
  padding: 12px 16px;
  border: 2px solid var(--line);
  border-radius: 14px;
  color: var(--ink);
  background: white;
  font-size: 1.08rem;
}
.search-help { margin: 10px 0 16px; color: var(--muted); font-size: .95rem; }
.search-status { min-height: 26px; margin-bottom: 8px; color: var(--wine); font-weight: 800; }
.search-results { display: grid; gap: 10px; }
.search-result {
  width: 100%;
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  padding: 10px;
  border: 2px solid var(--line);
  border-radius: 15px;
  color: var(--ink);
  background: white;
  text-align: left;
}
.search-result:hover { border-color: var(--wine); }
.search-result img { display: block; width: 82px; aspect-ratio: 595 / 842; object-fit: cover; border-radius: 7px; }
.search-result strong, .search-result span span { display: block; }
.search-result strong { margin-bottom: 5px; color: var(--wine); font-size: 1.05rem; }
.search-result span span { color: var(--muted); line-height: 1.4; }
.dialog-close { position: absolute; top: 12px; right: 14px; width: 46px; height: 46px; border: 0; border-radius: 50%; background: white; color: var(--wine); font-size: 2rem; }

@media (max-width: 720px) {
  .app { gap: 10px; padding: 12px; }
  .topbar h1 { font-size: 1.45rem; }
  .topbar .eyebrow { font-size: .72rem; }
  .topbar { align-items: flex-start; }
  .topbar-actions { width: min(58vw, 250px); display: grid; grid-template-columns: 1fr; }
  .topbar-actions .soft { min-height: 44px; padding: 7px 10px; font-size: .86rem; line-height: 1.15; }
  .book-stage { grid-template-columns: 54px minmax(0, 1fr) 54px; gap: 6px; }
  .page-arrow { width: 50px; height: 50px; font-size: 2.25rem; }
  .controls { display: grid; grid-template-columns: 1fr 1fr; }
  .primary, .soft, .voice { min-height: 56px; padding: 10px; }
  #read-page { grid-column: 1 / -1; }
  .progress-area { grid-template-columns: 1fr; gap: 2px; text-align: center; }
  .welcome-card { grid-template-columns: 1fr; max-width: 430px; overflow-y: auto; }
  .welcome-cover { max-height: 48dvh; object-fit: cover; object-position: center 15%; }
  .welcome-copy { padding: 24px; text-align: center; }
  .welcome-copy h1 { margin-bottom: 8px; }
  .welcome-copy p:not(.eyebrow) { font-size: 1.05rem; }
  .film-dialog-head { align-items: stretch; flex-direction: column; text-align: center; }
  .film-dialog-head .soft { width: 100%; }
  .video-keepsake { padding: 28px 14px; }
  .oma-face { width: 48px; border-width: 3px; }
  .page-grid { grid-template-columns: repeat(2, 1fr); }
  .song-card { align-items: stretch; flex-direction: column; text-align: center; }
  .song-button { width: 100%; }
  .search-row { grid-template-columns: 1fr; }
  .search-result { grid-template-columns: 66px minmax(0, 1fr); }
  .search-result img { width: 66px; }
  .password-gate { padding: 16px; }
  .password-card { padding: 28px 24px; }
}

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