@font-face {
  font-family: "OpenDyslexic";
  src: url("assets/fonts/OpenDyslexic-Regular.otf") format("opentype");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "OpenDyslexic";
  src: url("assets/fonts/OpenDyslexic-Bold.otf") format("opentype");
  font-weight: 700;
  font-display: swap;
}

:root {
  --night: #0d1730;
  --night-2: #1a2a52;
  --hill-far: #16294d;
  --hill-near: #102040;
  --road: #2b344b;
  --light: #ffd36b;
  --vest: #ff7a1a;
  --green: #90be6d;
  --mistake: #ff5d5d;
  --text: #f6f2e7;
  --caption: #ffffff;   /* feature explanations over the story */
  --muted: rgba(246, 242, 231, 0.7);
  --unread: rgba(246, 242, 231, 0.42);
  --panel: rgba(9, 16, 36, 0.72);
  --radius: 18px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--night);
  color: var(--text);
  font-family: "Nunito", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
img { max-width: 100%; display: block; }
h1, h2, .brand { font-family: "Love Ya Like A Sister", "Nunito", cursive; font-weight: 400; }

/* ---------- top bar ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
}
/* Dark blue overlay behind the bar: almost solid where the buttons and the title are,
   then fading out below, so content scrolling underneath doesn't clash with them. */
.topbar::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: calc(100% + 48px); z-index: -1; pointer-events: none;
  background: linear-gradient(to bottom, rgba(6, 11, 26, 0.96) 0%, rgba(6, 11, 26, 0.9) 55%, rgba(6, 11, 26, 0.55) 78%, rgba(6, 11, 26, 0) 100%);
}
.brand { color: var(--text); text-decoration: none; font-size: 1.6rem; }

.sound-toggle {
  font: inherit; font-size: 0.85rem; color: var(--text);
  background: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px; padding: 6px 12px; cursor: pointer;
}
.sound-toggle[aria-pressed="true"] { background: var(--light); color: var(--night); border-color: var(--light); }

.btn {
  display: inline-block; font-weight: 800; text-decoration: none; text-align: center;
  background: var(--vest); color: #fff; border: 0; border-radius: 999px;
  padding: 14px 24px; font-size: 1rem; cursor: pointer;
  box-shadow: 0 6px 24px rgba(255, 122, 26, 0.35);
}
/* Apple's badge: keep its proportions, never smaller than 40px tall (Apple's guideline). */
.appstore-badge { display: inline-block; line-height: 0; border-radius: 9px; }
.appstore-badge img { height: 100%; width: auto; }
.appstore-badge-small { height: 40px; }
.appstore-badge-large { height: 56px; }
.appstore-badge:focus-visible { outline: 2px solid var(--light); outline-offset: 3px; }
.btn-small { padding: 8px 14px; font-size: 0.85rem; box-shadow: none; }
.btn-ghost { background: transparent; border: 2px solid var(--light); color: var(--light); box-shadow: none; font-family: inherit; }


/* ---------- story stage ---------- */
#story { position: relative; height: 900vh; }
.stage {
  position: sticky; top: 0; height: 100vh; height: 100svh; overflow: hidden;
}
.sky { position: absolute; inset: 0; background: linear-gradient(to bottom, var(--night) 0%, var(--night-2) 58%); }

/* ---------- title screen (normal scroll) ---------- */
.hero {
  position: relative; height: 75vh; height: 75svh; overflow: hidden;
  display: grid; place-items: center; text-align: center; padding: 10vh 16px 0; padding-top: 10svh;
  background: linear-gradient(to bottom, #050a19 0%, var(--night) 100%);
}
.hero .stars { inset: 0; }
.hero-content { position: relative; }
/* The visible title is a fixed layer (hero.js); the real h1 keeps its place, invisible. */
.hero-title-pin h1.is-placeholder { visibility: hidden; }
.floating-title {
  position: fixed; left: 50%; top: 0; z-index: 60; pointer-events: none; white-space: nowrap;
  font-family: "Love Ya Like A Sister", "Nunito", cursive; font-size: clamp(3.5rem, 15vw, 8rem); line-height: 1.15;
  color: var(--light); text-shadow: 0 0 40px rgba(255, 211, 107, 0.35); transform-origin: 50% 50%; will-change: transform;
}
/* Reduced motion: no shrinking title, so show a small one in the top bar instead. */
.topbar-title { position: absolute; left: 50%; transform: translateX(-50%); color: var(--light); font-family: "Love Ya Like A Sister", cursive; font-size: 1.6rem; }
.hero h1 { font-size: clamp(3.5rem, 15vw, 8rem); margin: 0; color: var(--light); text-shadow: 0 0 40px rgba(255, 211, 107, 0.35); line-height: 1.15; }
.hero .tagline { margin: 18px auto 0; max-width: 34ch; text-wrap: balance; font-size: clamp(1.15rem, 4vw, 1.6rem); }
.hero .scroll-hint { position: absolute; bottom: 28px; left: 0; right: 0; margin: 0; }
.stars { position: absolute; inset: 0 0 45% 0; }
.stars i {
  position: absolute; width: 2px; height: 2px; border-radius: 50%; background: #fff;
  animation: twinkle 3s ease-in-out infinite;
}
@keyframes twinkle { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }

/* The camera: landscape and actors move together when the camera zooms or pans. */
.world { position: absolute; inset: 0; will-change: transform; }
.land { position: absolute; inset: 0; width: 100%; height: 100%; }
.hill-far { fill: var(--hill-far); }
.hill-near { fill: var(--hill-near); }
.road { fill: var(--road); }
.road-line { fill: rgba(255, 255, 255, 0.55); }

.actor { position: absolute; left: 50%; top: 56.5%; transform-origin: 50% 100%; will-change: transform, opacity; }
.car { width: min(60vw, 420px); margin-left: calc(min(60vw, 420px) / -2); margin-top: calc(min(60vw, 420px) * -1); }
.car img { position: relative; }
.car-glow {
  position: absolute; left: -40%; right: -40%; top: 20%; bottom: -10%;
  background:
    radial-gradient(closest-side at 28% 55%, rgba(255, 220, 120, 0.85), rgba(255, 220, 120, 0) 70%),
    radial-gradient(closest-side at 72% 55%, rgba(255, 220, 120, 0.85), rgba(255, 220, 120, 0) 70%);
  mix-blend-mode: screen; opacity: 0;
}
.cat, .dog { width: min(26vw, 180px); margin-left: calc(min(26vw, 180px) / -2); margin-top: calc(min(26vw, 180px) * -1); opacity: 0; }
/* The light and Clemente sit on the grass at the right edge of the road. */
.actor-img, .car img, .hedgehog-img { width: 100%; transform-origin: 50% 50%; }
.glimmer { left: 64%; top: 66%; width: 14px; height: 14px; margin-left: -7px; margin-top: -14px; opacity: 0; }
.glimmer span {
  display: block; width: 100%; height: 100%; border-radius: 50%;
  background: var(--vest); box-shadow: 0 0 18px 6px rgba(255, 122, 26, 0.8);
  animation: tremble 0.35s steps(2) infinite;
}
@keyframes tremble { 0% { transform: translate(0, 0); } 50% { transform: translate(1px, -1px); } 100% { transform: translate(-1px, 1px); } }
.hedgehog { left: 64%; top: 66%; width: min(30vw, 190px); margin-left: calc(min(30vw, 190px) / -2); margin-top: calc(min(30vw, 190px) * -0.8); opacity: 0; }
.hedgehog-img { filter: drop-shadow(0 0 24px rgba(255, 122, 26, 0.55)); }
.vest-img { position: absolute; width: 34%; left: -34%; top: 10%; transform: rotate(-10deg); opacity: 0; filter: drop-shadow(0 0 16px rgba(255, 122, 26, 0.9)); }

/* title card */
.title-card {
  position: absolute; left: 50%; top: 18%; transform: translateX(-50%);
  width: min(92vw, 640px); text-align: center; padding: 0 16px;
}
.title-card h1 { font-size: clamp(3rem, 12vw, 6rem); margin: 0; color: var(--light); text-shadow: 0 0 30px rgba(255, 211, 107, 0.35); }
.tagline { font-size: clamp(1.05rem, 3.6vw, 1.4rem); color: var(--text); margin: 8px 0 22px; }
.scroll-hint { margin-top: 26px; color: var(--muted); font-size: 0.9rem; animation: bob 1.8s ease-in-out infinite; }
.scroll-hint::after { content: " ↓"; }
@keyframes bob { 50% { transform: translateY(6px); } }

/* captions (feature explanations) */
.captions { position: absolute; left: 50%; top: 80px; transform: translateX(-50%); width: min(calc(100vw - 32px), 900px); height: 5em; }
.caption {
  position: absolute; inset: 0; text-align: center; opacity: 0; visibility: hidden;
  font-size: clamp(1.5rem, 5.6vw, 2.6rem); line-height: 1.2; font-weight: 800; color: var(--caption);
  text-wrap: balance; text-shadow: 0 2px 18px rgba(6, 12, 29, 0.8);
}

/* tale text at the bottom, like a page of the app */
.reader {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  width: min(calc(100vw - 32px), 760px); min-height: 8.5em;
}
.sentence {
  position: absolute; inset: auto 0 0 0; opacity: 0; visibility: hidden;
  background: var(--panel); border-radius: var(--radius); padding: 16px 20px;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.tale-text { font-family: "OpenDyslexic", "Nunito", sans-serif; font-size: clamp(1rem, 3.3vw, 1.35rem); line-height: 1.75; margin: 0; }
.w { color: var(--unread); transition: none; }
.caption .sound-word { cursor: pointer; text-decoration: underline wavy currentColor; text-underline-offset: 8px; text-decoration-thickness: 2px; }
.w.sound-word { cursor: pointer; text-decoration: underline wavy rgba(255, 211, 107, 0.7); text-underline-offset: 6px; pointer-events: auto; }
.w.hard { display: inline-block; }
.reader, .reader * { pointer-events: none; }
.reader .sound-word { pointer-events: auto; }

/* syllables overlay */
.syllables {
  position: absolute; left: 50%; top: 46%; transform: translate(-50%, -50%);
  display: flex; gap: 0.08em; opacity: 0; pointer-events: none; white-space: nowrap; max-width: calc(100vw - 32px);
  font-family: "OpenDyslexic", sans-serif; font-weight: 700; font-size: clamp(1.3rem, 5.8vw, 4.5rem);
  background: rgba(255, 255, 255, 0.95); color: var(--night); padding: 0.2em 0.5em; border-radius: 22px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}
.syllables span:nth-child(odd) { color: #1d6fd8; }
.syllables span:nth-child(even) { color: #d8431d; }

/* ---------- demo ---------- */
/* The last screen is at least one screen tall, content centred below the top bar, so at the end
   of the page "Ora leggi tu" is never under the bar. */
.finale { min-height: 100vh; min-height: 100svh; display: flex; flex-direction: column; justify-content: center; padding: 104px 0 32px; }
.demo { padding: 0 16px; width: 100%; max-width: 760px; margin: 0 auto; text-align: center; }
.demo h2 { font-size: clamp(2.2rem, 8vw, 3.5rem); color: var(--light); margin: 0; }
.demo-intro { color: var(--muted); margin: 8px 0 88px; }
.demo-card { background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(255, 255, 255, 0.12); border-radius: var(--radius); padding: 24px 20px; position: relative; }
.demo-hedgehog { width: 120px; margin: -84px auto 8px; filter: drop-shadow(0 0 18px rgba(255, 122, 26, 0.5)); }
.demo-sentence { font-size: clamp(1.15rem, 4.2vw, 1.6rem); }
.demo-sentence .w { cursor: pointer; transition: color 0.2s, transform 0.2s; display: inline-block; }
.demo-sentence .w.read { color: var(--light); }
.demo-sentence .w.next { color: var(--text); }
.demo-sentence .w.hint { color: var(--text); transform: scale(1.25); }
.demo-sentence .w.wrong { color: var(--mistake); }
.demo-syllables[hidden] { display: none; }
.demo-syllables { margin: 18px auto 0; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.demo-syllables-word { font-family: "OpenDyslexic", sans-serif; font-weight: 700; font-size: clamp(1.8rem, 8vw, 3rem); background: #fff; border-radius: 16px; padding: 0.1em 0.5em; }
.demo-syllables-word span:nth-child(odd) { color: #1d6fd8; }
.demo-syllables-word span:nth-child(even) { color: #d8431d; }
.demo-controls { margin-top: 22px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.mic {
  display: inline-flex; align-items: center; gap: 10px; font: inherit; font-weight: 800; font-size: 1.05rem;
  background: var(--vest); color: #fff; border: 0; border-radius: 999px; padding: 14px 26px; cursor: pointer;
}
.mic svg { width: 24px; height: 24px; fill: currentColor; }
.mic[aria-pressed="true"] { background: var(--mistake); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 12px rgba(255, 93, 93, 0.2); } }
.demo-status { min-height: 1.5em; color: var(--muted); margin: 0; }
.demo-debug { font-family: ui-monospace, Menlo, monospace; font-size: 0.85rem; color: var(--light); margin: 0; word-break: break-word; }
.demo-privacy { color: var(--muted); font-size: 0.85rem; margin-top: 16px; }
.end { text-align: center; padding: 36px 16px 0; }

/* ---------- reduced motion: a static page, no scroll animation ---------- */
body.reduced #story { height: auto; }
body.reduced .stage { display: none; }
.static-story { display: none; }
body.reduced .static-story { display: block; padding: 96px 16px 0; max-width: 760px; margin: 0 auto; }
.static-scene { background: var(--panel); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
.static-scene img { width: 96px; margin-bottom: 8px; }
.static-scene .w { color: var(--text); }
.static-scene .caption-static { color: var(--light); font-weight: 800; margin: 12px 0 0; }
