/* =============================================================
   Folded Studio - page styles
   The whole page is a handwritten letter on Filipino pad paper.
   ============================================================= */

/* ---------- Themes ----------
   Each theme is just a set of colors. To add a new theme, copy one
   block, change the name and colors, and add the name to THEMES in
   scripts/build.js. "rose" is the brand look and the default. */
:root,
[data-theme="rose"] {
  --paper: #FDFCF7;     /* the sheet */
  --rule: #C9D7EA;      /* faint blue pad-paper lines */
  --margin: #E8A0A8;    /* red margin line on the left */
  --ink: #B84A62;       /* rose pen ink */
  --envelope: #F6D6D6;  /* envelope and washi tape */
  --desk: #EFE7DC;      /* the table behind the paper */
}
[data-theme="blue"] {
  --paper: #FCFCF8;
  --rule: #C9D7EA;
  --margin: #E8A0A8;
  --ink: #2F4F8A;
  --envelope: #D6E2F3;
  --desk: #E6E9EE;
}
[data-theme="lavender"] {
  --paper: #FDFCFA;
  --rule: #D3D3EC;
  --margin: #E3A6C0;
  --ink: #6B4C9A;
  --envelope: #E5DCF3;
  --desk: #ECE7EF;
}
[data-theme="sage"] {
  --paper: #FCFCF6;
  --rule: #CCDCD3;
  --margin: #E3A69C;
  --ink: #4F6B52;
  --envelope: #DCE8D6;
  --desk: #E8E9E0;
}

/* ---------- Measurements ----------
   --line is the gap between two ruled lines. Handwriting uses the
   same line-height so every line of text belongs to one rule.
   (app.js reads these same numbers, so change them in both places.) */
:root {
  --line: 34px;
  --hand-size: 28px;                  /* handwriting, at least 26px on phone */
  --margin-x: 46px;                   /* where the red margin line sits */
  --top-space: calc(var(--line) * 3); /* blank header area of pad paper */
}

/* ---------- Base ---------- */
*,
*::before,
*::after { box-sizing: border-box; }

html,
body {
  margin: 0;
  height: 100%;
  background: var(--desk);
  color: var(--ink);
}

body {
  font-family: "Figtree", sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  /* Stop long-press from selecting text or opening menus on phones. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  height: 100vh;
  height: 100dvh; /* phones: the real visible height */
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- The stage (holds all sheets) ----------
   Fills the phone screen. On desktop it becomes a phone-sized
   sheet lying on the desk. */
.stage {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  visibility: hidden; /* shown after the envelope opens */
}
.stage.is-open { visibility: visible; }

@media (min-width: 520px) {
  .stage {
    width: 390px;
    height: min(844px, 100% - 48px);
    box-shadow: 0 1px 2px rgba(60, 40, 30, 0.14), 0 5px 10px -6px rgba(60, 40, 30, 0.22);
  }
}

/* ---------- One sheet of pad paper ---------- */
.sheet {
  position: absolute;
  inset: 0;
  background-color: var(--paper);
  /* Ruled lines: one continuous repeating pattern of hard 1px
     lines, starting below the blank header area. */
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent calc(var(--line) - 1px),
    var(--rule) calc(var(--line) - 1px),
    var(--rule) var(--line)
  );
  background-position: 0 var(--top-space);
  background-size: 100% calc(100% - var(--top-space));
  background-repeat: no-repeat;
  overflow: hidden;
  visibility: hidden; /* only the current sheet is shown */
}
.sheet.is-current { visibility: visible; }

/* The red margin line. */
.sheet::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--margin-x);
  width: 1.5px;
  background: var(--margin);
}

/* The fold crease: a very soft shadow line, slightly diagonal so
   it crosses the ruled lines instead of doubling one of them. */
.sheet::after {
  content: "";
  position: absolute;
  left: -10px;
  right: -10px;
  top: 47%;
  height: 1px;
  background: rgba(90, 70, 50, 0.05);
  box-shadow: 0 1px 3px rgba(90, 70, 50, 0.07);
  transform: rotate(-0.8deg);
  pointer-events: none;
}

/* Writing area: starts after the margin, lines up with the rules.
   --baseline-shift nudges the text down a little. Letters sit
   slightly above the lines on purpose (looks hand-written). */
.writing {
  --baseline-shift: 5px;
  position: absolute;
  top: calc(var(--top-space) + var(--baseline-shift));
  left: calc(var(--margin-x) + 12px);
  right: 22px;
  font-family: "Nanum Pen Script", cursive;
  font-size: var(--hand-size);
  line-height: var(--line);
  overflow-wrap: break-word;
}

.writing p { margin: 0; }
.writing .gap { height: var(--line); } /* one empty ruled line */

/* The count-up numbers keep their width steady while counting. */
.count { font-variant-numeric: tabular-nums; }

/* ---------- Progress bars (top of the sheet) ---------- */
.progress {
  position: absolute;
  top: 10px;
  left: 12px;
  right: 12px;
  z-index: 4;
  display: flex;
  gap: 3px;
  pointer-events: none;
}
.progress span {
  flex: 1;
  height: 2px;
  background: color-mix(in srgb, var(--ink) 20%, transparent);
  overflow: hidden;
}
.progress i {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--ink);
  transform-origin: left;
  transform: scaleX(0);
}

/* ---------- Intro sheet ---------- */
.names {
  font-size: 84px;
  line-height: calc(var(--line) * 3); /* big names use three ruled lines */
  position: relative;
  top: 10px; /* big letters need a bigger nudge */
}
.together-note {
  transform: rotate(-1.5deg);
  transform-origin: left center;
}

/* ---------- Memory card sheet ---------- */
.letter-date {
  position: absolute;
  top: 40px;
  right: 22px;
  font-family: "Nanum Pen Script", cursive;
  font-size: var(--hand-size);
  line-height: var(--line);
}

/* A printed photo with a thin white border, taped to the paper. */
.photo {
  position: absolute;
  left: 50%;
  background: #fff;
  padding: 7px;
  box-shadow: 0 1px 2px rgba(60, 40, 30, 0.22);
}
.photo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Washi tape: a semi-transparent strip with torn (zigzag) ends. */
.tape {
  position: absolute;
  top: -14px;
  left: 50%;
  width: 96px;
  height: 26px;
  margin-left: -48px;
  background: var(--envelope);
  opacity: 0.82;
  clip-path: polygon(
    0 0, 4% 16%, 0 33%, 4% 50%, 0 67%, 4% 84%, 0 100%,
    100% 100%, 96% 84%, 100% 67%, 96% 50%, 100% 33%, 96% 16%, 100% 0
  );
}

.card-title { font-size: 32px; }

/* ---------- Reasons sheet: numbered like a student's list ---------- */
/* Number on the left, and wrapped lines line up under the words. */
.reason {
  display: grid;
  grid-template-columns: 1.1em 1fr;
}

/* ---------- Song sheet ---------- */
.song-art {
  position: absolute;
  left: 50%;
  background: #fff;
  padding: 7px;
  box-shadow: 0 1px 2px rgba(60, 40, 30, 0.22);
}
.song-art img { display: block; width: 100%; height: 100%; }
.song-title { font-size: 40px; }

/* ---------- Letter sheets ---------- */
.letter-p { text-indent: 1.5em; }
.letter-p.cont { text-indent: 0; } /* a paragraph continued from the last page */
.sign-off {
  text-align: right;
  white-space: pre-line;
  padding-right: 6px;
}

/* ---------- Share card sheet ---------- */
.share-headline {
  font-size: 56px;
  line-height: calc(var(--line) * 2);
  position: relative;
  top: 4px;
}
/* Big numbers, without making their line taller than one rule. */
.stat-value { font-size: 44px; line-height: 0; }
.stat + .stat { margin-top: var(--line); } /* one empty line between stats */

/* ---------- Rubber-stamp buttons (mute, share) ----------
   Ink-colored outline with a thin inner line, slightly crooked,
   like a stamp pressed by hand. */
.stamp {
  appearance: none;
  -webkit-appearance: none;
  font-family: "Figtree", sans-serif;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 3px;
  box-shadow: inset 0 0 0 2px var(--paper), inset 0 0 0 3px color-mix(in srgb, var(--ink) 55%, transparent);
  padding: 7px 13px;
  cursor: pointer;
  transform: rotate(-2deg);
}
.stamp:active { transform: rotate(-2deg) scale(0.96); }
.stamp:focus-visible { outline: 2px dashed var(--ink); outline-offset: 3px; }

.mute {
  position: absolute;
  top: 26px;
  left: 10px;
  z-index: 6;
  padding: 5px 10px;
}

/* Share button and the small notes under it. */
.share-area {
  margin-top: var(--line);
  font-family: "Figtree", sans-serif;
  font-size: 14px;
  line-height: 20px;
}
.share-area .stamp { margin-left: 2px; }
.share-note {
  margin: 14px 0 0;
  max-width: 260px;
}
.share-note[hidden] { display: none; }

/* ---------- Sample sticky note (only when isSample is true) ---------- */
.sticky-note {
  position: absolute;
  bottom: 18px;
  left: 10px;
  width: 128px;
  padding: 9px 10px 11px;
  background: #FBEFA8;
  color: #5B4A2A;
  font-family: "Nanum Pen Script", cursive;
  font-size: 21px;
  line-height: 20px;
  transform: rotate(-3deg);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.12);
  z-index: 5;
  pointer-events: none;
}
.start .sticky-note { position: fixed; }

/* ---------- Small watermark ---------- */
.watermark {
  position: absolute;
  bottom: 16px;
  right: 18px;
  z-index: 4;
  font-size: 14px;
  opacity: 0.7;
  pointer-events: none;
}

/* ---------- Start screen: the closed envelope ---------- */
.start {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: var(--desk);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  outline: none;
}

.envelope {
  position: relative;
  width: 290px;
  height: 190px;
  background: var(--envelope);
  box-shadow: 0 1px 2px rgba(60, 40, 30, 0.16);
  transform: rotate(-2deg);
  perspective: 700px;
}

/* The darker inside, only seen once the flap opens. */
.env-inside {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--envelope) 82%, var(--ink));
  clip-path: polygon(0 0, 100% 0, 50% 58%);
}

.env-folds {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  fill: none;
  stroke: color-mix(in srgb, var(--envelope) 70%, var(--ink));
  stroke-width: 1;
}

.env-flap {
  position: absolute;
  inset: 0 0 auto 0;
  height: 58%;
  background: color-mix(in srgb, var(--envelope) 94%, var(--ink));
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top center;
}

.env-seal {
  position: absolute;
  left: 50%;
  top: calc(58% - 24px);
  width: 40px;
  height: 36px;
  margin-left: -20px;
  fill: var(--ink);
  transform: rotate(-6deg);
}

.tap-to-open {
  margin: 36px 0 0;
  font-family: "Nanum Pen Script", cursive;
  font-size: 32px;
  transform: rotate(-1.5deg);
}

/* ---------- The unfolding letter (only during the opening) ---------- */
.unfold {
  position: fixed;
  z-index: 20;
  perspective: 1400px;
  pointer-events: none;
}
.unfold .sheet { visibility: visible; }
.unfold .half-top { clip-path: inset(0 0 50% 0); }
.unfold .flap {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transform-origin: 50% 50%;
}
.unfold .flap .sheet {
  clip-path: inset(50% 0 0 0);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}
/* The back of the paper (seen while the bottom half is folded up). */
.unfold .flap .back {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--paper) 96%, #8a7a66);
  clip-path: inset(50% 0 0 0);
  transform: rotateX(180deg);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}
