/* ---------------------------------------------------------------------------
   Template 02 — anniversary story.
   Every colour goes through a variable here (template 01 hardcoded most of its
   hex values and re-theming it was the painful part). Per-screen themes are
   just three variables re-pointed: --bg, --fg, --accent.
--------------------------------------------------------------------------- */
@font-face {
  font-family: 'JaoTomato';
  src: url('../assets/fonts/JaoTomato-Thin.ttf') format('truetype');
  font-display: swap;
}

:root {
  --ink: #3d241a;
  --paper: #f4ecda;
  --pink: #f6d8e6;
  --pink-deep: #e3aec9;
  --brown-deep: #472a1c;
  --brown-dark: #2b1810;
  --star-blue: #b9cbe8;
  --white: #fff;
  --shadow: rgba(61, 36, 26, .22);

  --bg: var(--paper);
  --fg: var(--ink);
  --accent: var(--pink-deep);
  --dot: rgba(61, 36, 26, .14);
}

.theme-dark  { --bg: var(--brown-dark);  --fg: var(--paper); --accent: var(--pink); --dot: rgba(244, 236, 218, .10); }
.theme-brown { --bg: var(--brown-deep);  --fg: var(--paper); --accent: var(--pink); --dot: rgba(244, 236, 218, .10); }
.theme-cream { --bg: var(--paper);       --fg: var(--ink);   --accent: var(--pink-deep); }
.theme-pink  { --bg: var(--pink);        --fg: var(--ink);   --accent: var(--brown-deep); }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;          /* the flow is one screen per step, never a scrolling page */
  background: var(--brown-dark);
  font-family: 'Mali', sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

#app {
  position: relative;
  max-width: 540px;
  height: 100%;
  margin: 0 auto;
  overflow: hidden;
}

/* --- step frame --------------------------------------------------------- */
/* the story pages sit slightly higher: their header block is shorter */
.step {
  display: none;
  position: absolute;
  inset: 0;
  padding: 4.5rem 1.5rem 2.5rem;
  background: var(--bg);
  color: var(--fg);
  overflow-y: auto;          /* a long story page scrolls inside its own screen */
  text-align: center;
  /* polka dots, the reference's background — no paper texture here */
  background-image: radial-gradient(var(--dot) .08rem, transparent .09rem);
  background-size: 2.1rem 2.1rem;
}
.step.active { display: flex; flex-direction: column; align-items: center; gap: .9rem; }
.step > * { position: relative; z-index: 1; }
.theme-cream, .theme-pink { background-blend-mode: normal; }

/* the "01" chip at the top of every screen */
.step-no {
  position: absolute;
  top: 1.6rem; left: 50%; transform: translateX(-50%);
  min-width: 3rem;
  padding: .1rem .7rem;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: .85rem;
  letter-spacing: .1em;
  opacity: .85;
}

.script {
  font-family: 'Yellowtail', 'JaoTomato', cursive;
  font-weight: 400;
  line-height: 1.15;
  margin: 0;
  font-size: clamp(2.1rem, 9vw, 2.9rem);
}
.script-hero { font-size: clamp(2.6rem, 12vw, 3.6rem); }
.script i { font-style: italic; font-size: .8em; }

.part-label { margin: -.4rem 0 .2rem; font-size: .95rem; opacity: .8; }

/* torn-paper note: the cream block the reference puts the Thai copy on */
.paper-note {
  margin: 0;
  padding: .9rem 1.2rem;
  max-width: 22rem;
  white-space: pre-line;
  background: var(--paper);
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.85;
  box-shadow: 0 .25rem .6rem var(--shadow);
  /* uneven edges, so it reads as torn rather than as a card */
  clip-path: polygon(0 4%, 4% 0, 97% 2%, 100% 7%, 99% 95%, 95% 100%, 3% 98%, 0 93%);
}
.note-sm { font-size: .95rem; padding: .7rem 1rem; }
.theme-cream .paper-note { background: var(--white); }

/* sticker-style button: white box + hard shadow, no tape */
.sticker-btn {
  margin-top: .4rem;
  padding: .6rem 1.4rem;
  border: none;
  background: var(--pink);
  color: var(--brown-deep);
  font-family: 'Mali', sans-serif;
  font-size: .95rem;
  line-height: 1.4;
  transform: rotate(-2deg);
  box-shadow: .2rem .2rem 0 var(--brown-deep);
  cursor: pointer;
}
.sticker-btn:active { transform: rotate(-2deg) translate(.1rem, .1rem); box-shadow: .1rem .1rem 0 var(--brown-deep); }

.swipe-hint {
  margin: auto 0 .2rem;      /* pinned to the bottom of the screen whatever is above it */
  font-size: .9rem;
  letter-spacing: .12em;
  opacity: .75;
  cursor: pointer;
}

/* --- decorations: all CSS, no image assets ------------------------------- */
.deco { position: absolute; z-index: 0; opacity: .85; }
.deco-star {
  width: 1.1rem; height: 1.1rem;
  background: currentColor;
  clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}
.deco-star.blue { background: var(--star-blue); }
.deco-heart {
  width: 1.2rem; height: 1.2rem;
  background: currentColor;
  clip-path: polygon(50% 100%, 15% 68%, 0 38%, 8% 12%, 30% 4%, 50% 20%, 70% 4%, 92% 12%, 100% 38%, 85% 68%);
}
.s1 { top: 13%; left: 7%; }
.s2 { top: 25%; right: 10%; transform: scale(.8); }
.s3 { bottom: 18%; left: 12%; }
.h1 { top: 30%; right: 9%; opacity: .5; }

/* the big hand-drawn heart on the cover */
.heart-doodle {
  position: relative;
  width: 9.5rem; height: 8.5rem;
  margin: 1.2rem 0 1.8rem;
  background: var(--fg);
  clip-path: polygon(50% 100%, 15% 68%, 0 38%, 8% 12%, 30% 4%, 50% 20%, 70% 4%, 92% 12%, 100% 38%, 85% 68%);
}
.heart-doodle::before {
  content: '';
  position: absolute; inset: .5rem;
  background: var(--bg);
  clip-path: polygon(50% 100%, 15% 68%, 0 38%, 8% 12%, 30% 4%, 50% 20%, 70% 4%, 92% 12%, 100% 38%, 85% 68%);
}

/* --- step 2: PIN -------------------------------------------------------- */
.pin-card {
  width: min(19rem, 88%);
  padding: 1.4rem 1rem 1.1rem;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 .3rem .8rem var(--shadow);
  clip-path: polygon(0 3%, 3% 0, 98% 2%, 100% 6%, 99% 96%, 96% 100%, 2% 98%, 0 94%);
}
.pin-question { margin: 0 0 1rem; font-size: 1rem; }
.pin-inputs { display: flex; justify-content: center; gap: .35rem; }
.pin-slot { position: relative; width: 2.1rem; height: 2.5rem; }
.pin-digit {
  width: 100%; height: 100%;
  border: 1.5px solid var(--ink);
  background: transparent;
  color: transparent;        /* the typed char is hidden; the digit image is the visible one */
  caret-color: var(--ink);
  text-align: center;
  font-size: 1.2rem;
}
.pin-digit:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.pin-digit-img {
  display: none;
  position: absolute; inset: 12%;
  width: 76%; height: 76%;
  object-fit: contain;
  pointer-events: none;
}
.pin-slot-tip { margin: .9rem 0 0; font-size: .85rem; opacity: .75; }
.unlock-hint {
  margin: auto 0 .4rem;
  padding: .35rem 1.5rem;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: .95rem;
  letter-spacing: .1em;
}

.toast {
  margin: .2rem 0 0;
  padding: .3rem .9rem;
  background: var(--paper);
  color: var(--ink);
  font-size: .9rem;
  box-shadow: .15rem .15rem 0 var(--brown-deep);
}
.toast-success { background: var(--pink); }
.icon-heart {
  display: inline-block; width: .7rem; height: .7rem;
  background: var(--brown-deep);
  clip-path: polygon(50% 100%, 15% 68%, 0 38%, 8% 12%, 30% 4%, 50% 20%, 70% 4%, 92% 12%, 100% 38%, 85% 68%);
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}
#app.shake { animation: shake .45s; }

/* --- story pages -------------------------------------------------------- */
.polaroids { display: flex; flex-direction: column; gap: .7rem; width: 100%; align-items: center; }
.polaroid {
  position: relative;
  /* sized so three of them fit one phone screen without scrolling */
  width: min(11.5rem, 56%);
  margin: 0;
  padding: .4rem .4rem .1rem;
  background: var(--white);
  color: var(--ink);
  box-shadow: 0 .3rem .7rem var(--shadow);
}
.polaroid img { width: 100%; aspect-ratio: 5 / 4; object-fit: cover; display: block; background: var(--paper); }
.polaroid figcaption { padding: .35rem .2rem .45rem; font-size: .72rem; line-height: 1.45; }
.polaroid .pl-date { display: block; font-weight: 600; }
.tilt-left  { transform: rotate(-2deg); }
.tilt-right { transform: rotate(2deg); align-self: flex-end; }
.tilt-right .label-sticker { left: auto; right: -1.4rem; }

/* the "first met" / "first date" tag stuck to the side of a polaroid */
.label-sticker {
  position: absolute;
  top: 1.2rem; left: -1.4rem;
  padding: .18rem .5rem;
  background: var(--paper);
  font-size: .7rem;
  letter-spacing: .04em;
  transform: rotate(-4deg);
  box-shadow: .12rem .12rem 0 var(--shadow);
}
.label-sticker:empty { display: none; }

/* --- our song ----------------------------------------------------------- */
.polaroid-wide { width: min(18rem, 84%); }
.player {
  width: min(18rem, 84%);
  padding: .75rem .85rem .6rem;
  border-radius: .7rem;
  background: var(--brown-dark);
  color: var(--paper);
  text-align: left;
}
.player-head { display: flex; align-items: center; gap: .6rem; }
.player-art { width: 2.5rem; height: 2.5rem; border-radius: .3rem; object-fit: cover; background: var(--brown-deep); }
.player-meta { min-width: 0; }
.player-title { margin: 0; font-size: .9rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-artist { margin: 0; font-size: .75rem; opacity: .7; }
.player-bar { margin: .7rem 0 .25rem; height: .25rem; border-radius: 999px; background: rgba(255,255,255,.25); cursor: pointer; }
.player-bar span { display: block; width: 0; height: 100%; border-radius: 999px; background: var(--paper); }
.player-times { display: flex; justify-content: space-between; font-size: .68rem; opacity: .7; }
.player-ctrl { display: flex; align-items: center; justify-content: space-between; padding: .35rem .2rem .1rem; }
.pc-icon { width: .9rem; height: .9rem; background: var(--paper); opacity: .55; clip-path: polygon(0 0, 100% 50%, 0 100%); }
.pc-shuffle, .pc-repeat { clip-path: none; border: 1.5px solid var(--paper); background: none; border-radius: .2rem; }
.pc-prev { transform: rotate(180deg); }
.pc-play {
  width: 2.4rem; height: 2.4rem;
  border: none; border-radius: 50%;
  background: var(--paper);
  cursor: pointer;
  /* play triangle; .playing swaps it for a pause bar via border-left */
  clip-path: circle(50%);
  position: relative;
}
.pc-play::before {
  content: ''; position: absolute; inset: 0; margin: auto;
  width: .8rem; height: .9rem;
  background: var(--brown-dark);
  clip-path: polygon(12% 0, 100% 50%, 12% 100%);
}
.pc-play.playing::before {
  clip-path: none;
  background: linear-gradient(to right, var(--brown-dark) 0 34%, transparent 34% 66%, var(--brown-dark) 66% 100%);
}

/* --- ending ------------------------------------------------------------- */
.lined-note {
  width: min(19rem, 88%);
  padding: .95rem 1.1rem 1.1rem;
  background: var(--paper);
  color: var(--ink);
  /* ruled paper: one repeating line, not 12 hand-placed borders */
  background-image: repeating-linear-gradient(var(--paper) 0 1.8rem, rgba(61,36,26,.16) 1.8rem 1.85rem);
  box-shadow: 0 .3rem .8rem var(--shadow);
}
.lined-note p { margin: 0; white-space: pre-line; line-height: 1.85rem; font-family: 'JaoTomato', 'Mali', sans-serif; font-size: 1.05rem; }
.polaroid-end { width: min(12rem, 56%); transform: rotate(3deg); align-self: flex-end; margin-right: 1rem; }
.heart-sticker {
  position: absolute; bottom: 5.5rem; left: 2.2rem;
  display: grid; place-items: center;
  width: 5.2rem; height: 4.8rem;
  padding: .4rem;
  background: var(--pink-deep);
  color: var(--brown-deep);
  font-size: .75rem;
  text-align: center;
  clip-path: polygon(50% 100%, 15% 68%, 0 38%, 8% 12%, 30% 4%, 50% 20%, 70% 4%, 92% 12%, 100% 38%, 85% 68%);
}

/* --- progress dots: dev-only, like template 01 --------------------------- */
.progress-dots { display: none; }
.dev-mode .progress-dots {
  display: flex; gap: .3rem;
  position: absolute; top: .6rem; left: 50%; transform: translateX(-50%);
  z-index: 50;
}
.progress-dots span { width: .4rem; height: .4rem; border-radius: 50%; background: rgba(255,255,255,.35); }
.progress-dots .done { background: rgba(255,255,255,.7); }
.progress-dots .current { background: var(--pink-deep); }
