/* =========================================================
   אחרי הכל את שיר — notebook styles

   Ruled-paper rhythm
   ------------------
   Everything on the ruled sheet is laid out on one grid: --line (L).
   - Every line of text has line-height L, so each text line fills
     exactly one band between two ruled lines.
   - Every margin, padding and box height is a whole multiple of L,
     so the next line of text starts on the grid again.
   - Text is nudged up by --nudge so the letters (from the top of ל
     to the bottom of ק) sit centred between the lines.
   - L is always at least 0.95 × the largest font size + 8px, so the
     letters never reach a line. js/app.js widens L when the lyrics
     are enlarged with A+ (see lineFor()).
   ========================================================= */

:root {
  /* paper & ink */
  --paper: #efe3bf;
  --ink: #111;
  --ink-soft: #3d3730;
  --ink-faint: #6b6153;
  --divider: rgba(70, 50, 25, .3);

  /* notebook ruling */
  --line-base: 38px;                         /* band height on phones (whole px: no drift) */
  --line: var(--line-base);                  /* js/app.js may widen this for large lyrics */
  --rule-color: rgba(84, 110, 148, .2);      /* faded blue-grey */
  --margin-color: rgba(176, 72, 60, .26);    /* faded red margin */
  --margin-x: 14px;                          /* margin line, from the right edge */

  /* type: FtPilKahol for headings, Amatic SC for everything else */
  --font-read: "Amatic SC", "Arial Hebrew", sans-serif;
  --font-hand: "FtPilKahol", "Amatic SC", cursive;
  --title-scale: 1.08;
  --nudge: -0.06em;                          /* centres Amatic's letters in a band */

  --lyrics-size: 28px;
  --pad: max(1.4rem, env(safe-area-inset-right), env(safe-area-inset-left));
}

@font-face {
  font-family: "FtPilKahol";
  src: url("../fonts/FtPilKahol2.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: 1rem;
}
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

/* ---------- Paper ---------- */
/* vertical margin line runs down the whole page */
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--font-read);
  font-size: 1.5rem;
  font-weight: 700;
  line-height: var(--line);
  overflow-x: hidden;
  background-color: var(--paper);
  background-image: linear-gradient(to left,
    transparent var(--margin-x),
    var(--margin-color) var(--margin-x),
    var(--margin-color) calc(var(--margin-x) + 1px),
    transparent calc(var(--margin-x) + 1px));
}

/* horizontal rules: one per band, drawn on the band's bottom pixel */
.sheet, .toolbar {
  background-image: repeating-linear-gradient(to bottom,
    transparent 0,
    transparent calc(var(--line) - 1px),
    var(--rule-color) calc(var(--line) - 1px),
    var(--rule-color) var(--line));
}

/* Aging: fixed grain + soft discoloration + darker edges (above content, no clicks) */
body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
}
body::before {
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .26 0 0 0 0 .12 0 0 0 .5 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='900' height='900'%3E%3Cfilter id='b'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.006' numOctaves='3' seed='7' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .55 0 0 0 0 .38 0 0 0 0 .12 0 0 0 .9 -.34'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23b)'/%3E%3C/svg%3E");
  background-size: 300px 300px, 900px 900px;
  opacity: .34;
}
body::after {
  box-shadow:
    inset 0 0 110px rgba(140, 100, 35, .22),
    inset 0 0 20px rgba(120, 80, 25, .16);
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap;
}

:focus-visible { outline: 2px dashed var(--ink); outline-offset: 3px; }

/* =========================================================
   Header: the unruled top of the notebook page
   ========================================================= */
.hero {
  padding:
    max(3.25rem, calc(env(safe-area-inset-top) + 1.5rem))
    var(--pad)
    1.75rem;
  text-align: center;
}
.title {
  margin: 0;
  font-family: var(--font-hand);
  font-weight: 400;
  font-size: calc(clamp(2.6rem, 12.4vw, 7.25rem) * var(--title-scale, 1));
  line-height: 1.15;
  color: #000;
  text-wrap: balance;
}

/* photo (hidden until images/judy.jpg exists) */
.photo {
  margin: 2rem auto 0;
  width: min(74%, 19rem);
  padding: .55rem .55rem 1.5rem;
  background: #f8f3e6;
  box-shadow: 0 1px 3px rgba(60, 40, 10, .25);
  transform: rotate(1.5deg);
}
.photo[hidden] { display: none; }
.photo img { display: block; width: 100%; height: auto; filter: sepia(.12); }

/* =========================================================
   The ruled sheet
   Only margin-top is used for spacing (bottoms are 0) and containers
   are flow-root, so margins never collapse into odd amounts.
   ========================================================= */
.sheet { display: flow-root; padding-top: var(--line); }

.page,
.intro, .invite, .playlist, .jump, .songbook, .lyrics {
  display: flow-root;
}
.page {
  max-width: 72rem;
  margin: 0 auto;
  padding: 0 var(--pad) calc(var(--line) * 3);
}

/* every line of text: exactly one band, letters centred in it */
.sheet p,
.song-title, .song-artist, .song-num,
.btn, .text-link, .wake, .size button {
  line-height: var(--line);
}
.sheet p,
.song-title, .song-artist, .song-num,
.btn-label, .text-link, .wake-label, .size button span {
  position: relative;
  top: var(--nudge);
}
.sheet p { margin: 0; }

/* ---------- 3. Invitation ---------- */
.invite { text-align: center; }
.sheet .invite-text {
  max-width: 30rem;
  margin-inline: auto;
  font-size: 1.85rem;
  text-wrap: pretty;
}
.sheet .details {
  margin: var(--line) auto 0;
  max-width: 24rem;
  font-weight: 700;
  font-size: 1.75rem;
}
.details p { font-size: inherit; }
.sheet .invite-close {
  margin-top: var(--line);
  font-size: 1.85rem;
}

/* ---------- Buttons ----------
   A button is exactly one band tall. Its outline is drawn inside the band
   (::before, 4px clear of each rule) and its tap area is extended to
   ≥ 46px (::after) without changing the layout. */
.btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  height: var(--line);
  margin: var(--line) auto 0;
  padding: 0 1.9rem;
  border: 0;
  background: none;
  color: var(--ink);
  font-family: var(--font-read);
  font-weight: 700;
  font-size: 1.6rem;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.btn::before {
  content: "";
  position: absolute;
  inset: 4px 0;
  border: 1.5px solid var(--ink);
  border-radius: 999px 960px 999px 940px / 80px 70px 90px 75px; /* slightly hand-drawn */
  transition: background-color .15s;
}
.btn::after,
.size button::after,
.wake::after {
  content: "";
  position: absolute;
  inset: min(0px, calc((var(--line) - 46px) / 2)) 0;
}
.btn:hover::before, .btn:active::before { background: rgba(60, 40, 15, .08); }
.btn-label { position: relative; z-index: 1; }
.btn-strong { color: var(--paper); padding-inline: 2.3rem; }
.btn-strong::before { background: var(--ink); }
.btn-strong:hover::before, .btn-strong:active::before { background: #000; }

.text-link {
  display: block;
  width: fit-content;
  margin: 0 auto;
  padding: 0 .25rem;
  color: var(--ink);
  font-weight: 700;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}

/* ---------- 5. Playlist ---------- */
.playlist { margin-top: calc(var(--line) * 2); text-align: center; }
.embed {
  max-width: 34rem;
  height: calc(var(--line) * 10);
  margin: 0 auto;
  border-radius: 12px;
  overflow: hidden;
  background: rgba(60, 40, 15, .06);
}
.embed iframe { display: block; width: 100%; height: 100%; border: 0; }

/* ---------- 6. Jump ---------- */
.jump { margin-top: var(--line); }

/* ---------- 7. Songbook ---------- */
.songbook {
  max-width: 46rem;
  margin: calc(var(--line) * 2) auto 0;
}
.sheet .hint {
  text-align: center;
  color: var(--ink-soft);
  font-size: 1.5rem;
}
.hint:focus { outline: none; }

/* sticky controls: full-bleed strip of the same ruled paper.
   Height = whole bands; its own rules are offset half a band so they
   run between the rows of controls, never through them. */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  width: 100vw;
  margin: var(--line) calc(50% - 50vw) 0;
  padding: calc(var(--line) / 2) 0;
  background-color: var(--paper);
  background-position: 0 calc(var(--line) / 2);
  box-shadow: inset 0 -1px 0 var(--divider);
}
.toolbar::before {           /* margin line continues through the bar */
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(to left,
    transparent var(--margin-x),
    var(--margin-color) var(--margin-x),
    var(--margin-color) calc(var(--margin-x) + 1px),
    transparent calc(var(--margin-x) + 1px));
}
.toolbar-inner {
  position: relative;
  max-width: 46rem;
  margin: 0 auto;
  padding-inline: var(--pad);
}

.search { position: relative; height: var(--line); }
.search input {
  position: absolute;
  inset: 4px 0;
  width: 100%;
  height: calc(var(--line) - 8px);
  padding: 0 1rem 0 2.9rem;
  border: 1.5px solid var(--ink-soft);
  border-radius: 10px;
  background: rgba(255, 251, 236, .7);
  color: var(--ink);
  font-family: var(--font-read);
  font-weight: 700;
  font-size: 1.5rem; /* ≥16px: no iOS zoom */
  line-height: normal;
  -webkit-appearance: none;
  appearance: none;
}
.search input::placeholder { color: var(--ink-faint); opacity: 1; }
.search input::-webkit-search-cancel-button { display: none; }
.search-clear {
  position: absolute;
  inset-inline-end: .1rem;
  top: 50%;
  transform: translateY(-50%);
  width: 2.75rem; height: 2.75rem;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font-size: 1.1rem;
  cursor: pointer;
}
.search-clear[hidden] { display: none; }

.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  height: var(--line);
}
.size { display: flex; gap: .4rem; height: var(--line); }
.size button {
  position: relative;
  min-width: 3.1rem;
  height: var(--line);
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  font-family: var(--font-read);
  font-weight: 700;
  font-size: 1.45rem;
  cursor: pointer;
}
.size button::before {
  content: "";
  position: absolute;
  inset: 4px 0;
  border: 1.5px solid var(--ink-soft);
  border-radius: 8px;
  background: rgba(255, 251, 236, .45);
}
.size button span { position: relative; }
.size button:disabled { opacity: .35; cursor: default; }

.wake {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  height: var(--line);
  font-weight: 700;
  font-size: 1.45rem;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
.wake input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.wake-box {
  flex: none;
  width: 1.5rem; height: 1.5rem;
  border: 1.5px solid var(--ink-soft);
  border-radius: 5px;
  background: rgba(255, 251, 236, .45);
  display: grid;
  place-items: center;
  line-height: 1;
}
.wake input:checked + .wake-box::after {
  content: "✓";
  font-size: 1.05rem;
  line-height: 1;
  font-weight: 700;
}
.wake input:focus-visible + .wake-box { outline: 2px dashed var(--ink); outline-offset: 3px; }
.wake.is-disabled { opacity: .5; cursor: default; }
.sheet .wake-status {
  font-size: 1.3rem;
  color: var(--ink-soft);
  text-align: center;
}
.wake-status:empty { display: none; }

/* song list: each song = title band + artist band; the divider is drawn
   exactly on the ruled line below it */
.songs { list-style: none; margin: 0; padding: 0; }
.song { box-shadow: inset 0 -1px 0 var(--divider); }
.song[hidden] { display: none; }

.song-head { margin: 0; font-size: inherit; font-weight: inherit; }
.song-toggle {
  display: flex;
  align-items: center;
  gap: .9rem;
  width: 100%;
  min-height: calc(var(--line) * 2);
  padding: 0 .1rem;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  text-align: start;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.song-num {
  flex: none;
  align-self: flex-start;     /* sits in the title's band */
  min-width: 1.8rem;
  font-size: 1.35rem;
  color: var(--ink-faint);
  text-align: center;
}
.song-meta { flex: 1; min-width: 0; }
.song-title {
  display: block;
  font-weight: 700;
  font-size: 1.85rem;
  overflow-wrap: anywhere;
}
.song-artist {
  display: block;
  font-size: 1.35rem;
  color: var(--ink-soft);
  overflow-wrap: anywhere;
}
.song-icon {
  flex: none;
  align-self: flex-start;     /* centred in the title's band */
  width: .65rem; height: .65rem;
  margin-top: calc(var(--line) / 2 - .325rem);
  margin-inline-start: .3rem;
  border-right: 1.5px solid var(--ink-soft);
  border-bottom: 1.5px solid var(--ink-soft);
  transform: translateY(-3px) rotate(45deg);   /* points down */
  transition: transform .15s;
}
.song-toggle[aria-expanded="true"] .song-icon { transform: translateY(2px) rotate(-135deg); } /* points up */

.lyrics {
  padding: 0 .1rem var(--line);
  padding-inline-start: 2.7rem;
}
.lyrics[hidden] { display: none; }
.lyrics-text {
  font-size: var(--lyrics-size);
  white-space: pre-line;
  overflow-wrap: anywhere;
}
.sheet .lyrics-text p { font-size: inherit; }
.sheet .lyrics-text p + p { margin-top: var(--line); }   /* one empty band between verses */
.sheet .lyrics-empty { color: var(--ink-faint); font-size: 1.4rem; }
.sheet .lyrics-source { margin-top: var(--line); font-size: 1.25rem; }
.lyrics-source a { color: var(--ink-soft); }

.sheet .empty {
  margin-top: var(--line);
  text-align: center;
  font-size: 1.6rem;
  color: var(--ink-soft);
}

/* =========================================================
   Responsive
   ========================================================= */

/* small iPhones (375 / 390 / 402): tighter lyrics indent */
@media (max-width: 419px) {
  .lyrics { padding-inline-start: 2.2rem; }
  .song-toggle { gap: .7rem; }
}

/* large phones & tablets: controls on one row */
@media (min-width: 600px) {
  :root { --margin-x: 4vw; --line-base: 40px; }
  .toolbar-inner { display: flex; align-items: center; gap: 1rem; }
  .search { flex: 1; }
  .controls { flex: none; }
  .sheet .invite-text, .sheet .invite-close { font-size: 2rem; }
}

/* desktop: same single column, larger type and spacing */
@media (min-width: 960px) {
  :root { --line-base: 42px; --margin-x: 7vw; --pad: 3rem; }
  .hero { padding-top: 5rem; padding-bottom: 2.25rem; }
  .photo { margin-top: 3rem; }
  .sheet { padding-top: calc(var(--line) * 2); }
  .sheet .invite-text { font-size: 2.2rem; max-width: 27rem; }
  .sheet .details { font-size: 2rem; }
  .sheet .invite-close { font-size: 2.2rem; }
  .song-title { font-size: 2rem; }
  .song-artist { font-size: 1.45rem; }
  .lyrics { padding-inline-start: 3.3rem; }
}

@media (min-width: 1400px) {
  :root { --margin-x: 10vw; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
