/* ===== Fonts (OTF only) ===== */
@font-face{
  font-family: "Flapstick";
  src: url("fonts/FlapstickDEMO.otf") format("opentype");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face{
  font-family: "Pencilant Script";
  src: url("fonts/Pencilant Script.otf") format("opentype");
  font-weight: 400; font-style: normal; font-display: swap;
}

/* ===== Theme ===== */
:root{
  --pencil-ink: #3b3b3b;
  --pencil-mid: #555;      /* progress fill */
  --pencil-light: #bdbdbd; /* progress track */
  --note-fill: rgba(204, 229, 255, 0.92); /* default; randomized per prompt */
  --note-border: rgba(0,0,0,.06);
  --radius-bottom: 20px;
}

*{ box-sizing:border-box }
html,body{ height:100% }
body{
  margin:0; background:#000; color:var(--pencil-ink);
  font-family:"Flapstick", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial;
  -webkit-font-smoothing:antialiased; -moz-osx-font-smoothing:grayscale;
}

/* ===== Background video + overlay ===== */
.bg{ position:fixed; inset:0; z-index:-3; overflow:hidden }
.bg video{ position:absolute; inset:0; width:100%; height:100%; object-fit:cover }
.doodles{ position:fixed; inset:0; background:center/cover no-repeat url("images/PencilSketches.png"); pointer-events:none; opacity:.9; z-index:-2 }
.paperTint{ position:fixed; inset:0; background:linear-gradient(180deg, rgba(255,255,255,.06), rgba(255,255,255,.12)); z-index:-1 }

/* ===== Layout ===== */
.app{
  min-height:100%;
  display:grid;
  place-items:center; /* center the whole block */
}

.block{
  display:grid;
  row-gap: 6px; /* tight gap between title and note */
}

/* Page heading */
.title{
  width: 100%;
  text-align: center;
  color: var(--pencil-ink);
  font-size: clamp(20px, 4.8vw, 36px);
  letter-spacing: .02em;
  text-shadow: 0 1px 0 rgba(255,255,255,.4);
}

/* ===== Sticky note ===== */
.card{
  width: clamp(320px, 60vw, 560px);
  min-height: clamp(300px, 45vh, 420px);
  background: var(--note-fill);
  border: 1px solid var(--note-border);
  border-radius: 0 0 var(--radius-bottom) var(--radius-bottom);
  box-shadow: 0 14px 40px rgba(0,0,0,.25), 0 6px 18px rgba(0,0,0,.18);
  padding: clamp(18px, 3vw, 28px);
  transform-origin: 50% 6%;
  animation: bob 4.5s ease-in-out infinite;
  position: relative;
}
.card::before{ /* tape */
  content:""; position:absolute; left:50%; top:-14px; transform:translateX(-50%) rotate(-1deg);
  width:180px; height:26px; background:linear-gradient(180deg, rgba(230,230,230,.86), rgba(230,230,230,.5));
  border-radius:4px; box-shadow:0 6px 16px rgba(0,0,0,.22); opacity:.85;
}

@keyframes bob{
  0%,100%{ transform: translateY(0) rotate(0) }
  50%    { transform: translateY(-6px) rotate(-.3deg) }
}

/* Peel/slide transitions */
.peel-exit   { animation: peelExit .28s cubic-bezier(.3,.7,.2,1) both }
.peel-enter  { animation: peelEnter .42s cubic-bezier(.2,.7,.2,1) both }
@keyframes peelExit{ to{ opacity:0; transform: translateX(-14px) rotate(-2deg) } }
@keyframes peelEnter{ from{ opacity:0; transform: translateX(18px) rotate(.8deg) } to{ opacity:1; transform: translateX(0) rotate(0) } }

.noteContent{
  display:grid; gap: clamp(12px,2.2vw,18px);
  height:100%;
  grid-template-rows: auto 1fr auto; /* input, quip, submit */
}

/* Input (extra top spacing) */
.input{
  appearance:none; border:none; outline:none; background:transparent;
  color:var(--pencil-ink);
  font-size: clamp(22px, 4.5vw, 34px);
  line-height:1.2;
  padding: 30px 4px 10px;           /* push down from the top */
  border-bottom: 3px solid var(--pencil-ink);
  font-family: "Flapstick", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial;
}
.input::placeholder,
.input::-webkit-input-placeholder,
.input:-ms-input-placeholder,
.input::-ms-input-placeholder,
.input::-moz-placeholder{
  font-family: "Flapstick", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial;
  font-weight: 400;
  letter-spacing: .01em;
  color: rgba(59,59,59,.65);
}

/* Quip in Pencilant Script */
.quip{
  font-family: "Pencilant Script", "Flapstick", ui-sans-serif, system-ui;
  font-size: clamp(16px, 3vw, 22px);
  color: rgba(0,0,0,.85);
  line-height:1.35;
  align-self: start;
}

/* Submit */
.actions{ display:grid; justify-items:center; align-items:end; margin-top:6px }
.btn{
  appearance:none; cursor:pointer; font:inherit;
  border:2px solid var(--pencil-ink); background:transparent; color:var(--pencil-ink);
  padding:10px 18px; border-radius:999px; box-shadow:0 3px 0 var(--pencil-ink);
  transform:translateY(0); transition:transform .1s ease, box-shadow .1s ease, filter .2s ease;
}
.btn:hover{ filter:brightness(1.02) }
.btn:active{ transform:translateY(3px); box-shadow:0 0 0 var(--pencil-ink) }

/* Progress bar only */
.progress{ display:grid; justify-items:center; margin-top:10px }
.progressBar{ width:clamp(320px, 60vw, 560px); height:8px; background:var(--pencil-light); border-radius:999px; overflow:hidden }
.progressBar span{ display:block; height:100%; width:0%; background:var(--pencil-mid); transition:width .35s ease }

/* Page visibility */
.page{ display:none; opacity:0; transform:translateY(8px); transition:opacity .35s ease, transform .35s ease }
.page.active{ display:block; opacity:1; transform:translateY(0) }

/* ===== STORY OVERLAY ===== */
.overlay{
  position: fixed; inset: 0;
  display: none;               /* shown when story starts */
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
  background: rgba(0,0,0,.2);  /* slight dim */
  z-index: 100;
}
.overlay.show{ display:flex; }

/* Story page: full height, limited width, scrollable text */
.storyPage{
  height: 100vh;
  width: clamp(360px, 70vw, 820px);
  background: rgba(255,255,255,0.92);
  border: 1px solid rgba(0,0,0,.06);
  border-radius: 12px;
  box-shadow: 0 14px 40px rgba(0,0,0,.35), 0 6px 18px rgba(0,0,0,.22);
  display: grid;
  grid-template-rows: 1fr auto;
  overflow: hidden;
}

/* Scroll container with comfy pencil script */
.storyScroll{
  overflow-y: auto;
  padding: clamp(18px, 3.2vw, 32px);
  font-family: "Pencilant Script", "Flapstick", ui-sans-serif, system-ui;
  font-size: clamp(18px, 2.6vw, 26px);
  line-height: 1.9;
  color: #2f2f2f;
}

/* Next Chapter bar */
.storyBar{
  padding: 14px;
  display: none;
  justify-items: center;
  border-top: 1px solid rgba(0,0,0,.08);
  background: rgba(255,255,255,.95);
}
.storyBar.show { display:grid; }  /* revealed when at bottom */

@keyframes slideUp {
  from { transform: translateY(100%); opacity:0; }
  to   { transform: translateY(0); opacity:1; }
}
.storyPage {
  animation: slideUp 0.6s cubic-bezier(.25,.8,.25,1) forwards;
}

.nextBtn{
  appearance:none; cursor:pointer;
  font-family:"Flapstick", ui-sans-serif, system-ui;
  border:2px solid #2f2f2f; background:transparent; color:#2f2f2f;
  padding:10px 18px; border-radius:999px; box-shadow:0 3px 0 #2f2f2f;
  transform:translateY(0); transition:transform .1s ease, box-shadow .1s ease;
}
.nextBtn:active{ transform:translateY(3px); box-shadow:0 0 0 #2f2f2f }