/* First game: the old dijkgraaf's lessons in his candlelit study. body[data-teach] = swipe | meters | dots | death |
   quest | goals | chain. body.handover = the chain taken: the study swings open onto the polder.
   Also the paper narration card (kind "note") used by the tutorial and the story. */

/* ── the study: a warm room behind the table instead of the night polder ── */
.study { display: none; position: fixed; inset: 0; z-index: 1; pointer-events: none; }
.study > div { position: absolute; inset: 0; }
.study svg { display: block; width: 100%; height: 100%; }
.study .flame { transform-box: fill-box; transform-origin: 50% 100%; animation: flicker 2.6s ease-in-out infinite; }
@keyframes flicker { 30% { scale: .92 1.06; } 55% { scale: 1.05 .95; } 80% { scale: .97 1.03; } }
.study-door { display: none; }
body[data-teach] .study { display: block; }
body[data-teach] {
  --bar: #24160c;
  --bar-muted: #c9b08a;
  .column {
    background:
      radial-gradient(90% 70% at 50% 62%, rgb(255 190 90 / .22), transparent 70%),
      radial-gradient(120% 60% at 50% 45%, transparent 55%, rgb(90 50 10 / .3)),
      #e8cf9c;
    box-shadow: 0 0 0 1px rgb(0 0 0 / .5), 0 0 120px rgb(255 160 60 / .18);
  }
  .meters, .ledger { border-color: #140b05; }
  .hud { visibility: hidden; }
  .card-art svg { filter: sepia(.3) saturate(1.1) brightness(.97); }
}

/* lesson cards carry their number */
.card[data-lesson]::before {
  content: attr(data-lesson);
  position: absolute; left: 12px; bottom: 12px; z-index: 2;
  padding: 3px 10px; border-radius: 4px;
  background: #24160c; color: #f3d58a;
  font-size: clamp(.78rem, 1.6vh, .95rem); letter-spacing: .08em; font-variant: small-caps;
  box-shadow: 0 2px 6px rgb(0 0 0 / .4);
}

/* ── the handover: the room splits down the middle and swings away; the polder is outside ── */
body.handover .study { display: block; z-index: 40; }
body.handover .study-room { visibility: hidden; } /* not display:none: the doors use its gradients */
body.handover .study-door { display: block; animation: door-l 1.4s .25s cubic-bezier(.6, 0, .4, 1) forwards; }
.study-door.l { clip-path: inset(0 50% 0 0); }
.study-door.r { clip-path: inset(0 0 0 50%); animation-name: door-r !important; }
@keyframes door-l { to { translate: -52% 0; opacity: .6; } }
@keyframes door-r { to { translate: 52% 0; opacity: .6; } }
body.handover .backdrop { z-index: 35; }
body.handover :is(.column, .hud) { animation: handover-in 2s both; }
@keyframes handover-in { 0%, 72% { opacity: 0; } }

/* tip line, laid over the bottom bar (on phones the study shows through it) */
.teach-tip {
  display: none;
  position: fixed; z-index: 6;
  left: 50%; bottom: 0; translate: -50% 0;
  width: var(--column);
  height: clamp(64px, 11vh, 120px);
  margin: 0; padding: 0 28px;
  place-items: center;
  background: var(--bar);
  border-top: 3px solid #0a0d1f;
  color: #f3d58a;
  font-size: clamp(1rem, 2vh, 1.25rem);
  font-style: italic;
  text-align: center;
  text-wrap: balance;
}
body[data-teach] .teach-tip { display: grid; }

/* the pointing hand that sways over the first card */
.teach-hand {
  display: none;
  position: absolute; z-index: 3;
  left: 50%; bottom: 8%;
  width: clamp(54px, 9vh, 80px);
  translate: -50% 0;
  pointer-events: none;
  filter: drop-shadow(0 6px 8px rgb(0 0 0 / .4));
  animation: teach-sway 2.4s ease-in-out infinite;
  svg { display: block; width: 100%; }
}
body:is([data-teach="swipe"], [data-teach="dots"]) .teach-hand { display: block; }
body[data-teach="dots"] .teach-hand { animation-name: teach-hold; }
@keyframes teach-hold { 0%, 15% { translate: -50% 0; } 45%, 85% { translate: 10% -4px; rotate: 10deg; } }
.deck:has(.card.dragging, .card.flying) .teach-hand { opacity: 0; transition: opacity .15s; }
@keyframes teach-sway {
  0%, 100% { translate: -50% 0; rotate: 0deg; }
  25% { translate: -150% -4px; rotate: -14deg; }
  75% { translate: 50% -4px; rotate: 14deg; }
}

/* lesson 1: the meters are not there yet; lesson 2 lights them and names them */
.meter { transition: opacity .6s, filter .6s; }
body[data-teach="swipe"] .meter { opacity: .12; filter: grayscale(1); }
body:is([data-teach="meters"], [data-teach="death"]) .meter::after {
  content: attr(aria-label);
  position: absolute; left: 50%; top: calc(100% + 4px); translate: -50% 0;
  font-size: .8rem; letter-spacing: .06em; color: #f3d58a; white-space: nowrap;
}
body[data-teach="meters"] .meter-fill { animation: teach-glow 1.6s ease-in-out infinite; }
@keyframes teach-glow { 50% { filter: drop-shadow(0 0 8px #f3d58a); } }
/* lesson 3: the preview dots get a ring so they're impossible to miss */
body[data-teach="dots"] .meter-dot { background: #f3d58a; box-shadow: 0 0 0 4px rgb(243 213 138 / .35), 0 0 14px #f3d58a; }
/* lesson 4: empty or full, both kill: flash the edges of each gauge */
body[data-teach="death"] .meter-track { animation: teach-danger 1.4s ease-in-out infinite; }
@keyframes teach-danger { 50% { color: #6a1f22; } }

/* ── narration card: plain paper, italic hand ── */
.note-art {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  padding: 12%;
  background:
    radial-gradient(circle at 50% 50%, transparent 60%, rgb(150 120 60 / .18)),
    repeating-linear-gradient(0deg, transparent 0 31px, rgb(120 90 40 / .06) 31px 32px),
    #f6ecd2;
  color: var(--ink);
  p {
    margin: 0;
    font-size: clamp(1.05rem, 2.4vh, 1.45rem);
    font-style: italic;
    line-height: 1.45;
    text-align: center;
    text-wrap: balance;
  }
}
body[data-kind="note"] .prompt { opacity: .55; }

@media (max-width: 760px) {
  .teach-tip {
    left: 0; translate: none; width: 100%;
    height: calc(clamp(84px, 13svh, 104px) + var(--safe-bottom));
    padding: 0 20px var(--safe-bottom);
    font-size: clamp(.92rem, 2.6svh, 1rem);
    background: linear-gradient(rgb(20 10 4 / .35), rgb(20 10 4 / .7));
    text-shadow: 0 1px 3px #000;
  }
  /* the study cropped like the polder, so the candles stand in the bottom bar */
  .study-room svg { position: absolute; inset: auto 0 calc(var(--safe-bottom) - 113px); height: 390px; }
  /* the handover fills the screen with the polder */
  body.handover .backdrop { top: 0; bottom: 0; left: 0; width: 100%; height: 100%; translate: none; }
  .meter { --label-gap: 2px; }
  body:is([data-teach="meters"], [data-teach="death"]) .meter::after { font-size: .7rem; }
}

@media (prefers-reduced-motion: reduce) {
  .teach-hand { animation: none; translate: -50% 0; }
  body[data-teach="meters"] .meter-fill,
  body[data-teach="death"] .meter-track,
  .study .flame { animation: none; }
  .meter { transition: none; }
}

@media (max-width: 760px) {
  body[data-teach] .column { background: none; box-shadow: none; }
  body[data-teach] .stage {
    background:
      radial-gradient(90% 70% at 50% 62%, rgb(255 190 90 / .22), transparent 70%),
      radial-gradient(120% 60% at 50% 45%, transparent 55%, rgb(90 50 10 / .3)),
      #e8cf9c;
  }
}
