/* A fita: a capa (J-card) e a fita ficam fixas à esquerda no computador enquanto as faixas rolam;
   no celular, a capa vem primeiro e o play fica numa barra embaixo. Um mundo escuro só, de propósito.
   O roxo aparece uma única vez: na flor do final. */
:root {
  color-scheme: dark;
  --shell: #1b1a1c;      /* plástico da fita, fundo */
  --shell-2: #2a282b;
  --card: #efe6d2;       /* papel da capa */
  --pen: #1f3a8a;        /* caneta azul */
  --tape: #5a3a26;       /* fita marrom, rótulos no papel */
  --rec: #d6402b;        /* vermelho de gravar, a cor das ações */
  --rule: #c9bc9f;
  --ink: #f3efe6;        /* texto sobre o plástico */
  --ink-soft: #c9c1b0;
  --purple: #6f3fd0;     /* só a flor */
  --hand: "Caveat", "Nanum Pen Script", "Comic Sans MS", cursive;
  --mono: "DM Mono", "Nanum Gothic Coding", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scrollbar-color: var(--tape) var(--shell); }
body { margin: 0; background: var(--shell); color: var(--ink); font-family: var(--mono); font-size: 15px; overflow-x: clip; }
::selection { background: var(--rec); color: #fff; }
p, h1, h2 { margin: 0; }
button { font: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible, [role="button"]:focus-visible { outline: 2px solid var(--rec); outline-offset: 3px; }
[hidden] { display: none !important; }
.hand { font-family: var(--hand); font-weight: 500; line-height: 1.1; }
.label { font-size: .75rem; letter-spacing: .04em; color: var(--tape); }

.page {
  display: grid; gap: 40px; max-width: 1180px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: calc(24px + env(safe-area-inset-top, 0px)) 120px;
}
.side-col { display: grid; gap: 16px; min-width: 0; }

/* Capa */
.jcard { background: var(--card); color: var(--pen); border-radius: 3px; }
.front { position: relative; padding: 18px 18px 14px; border-bottom: 1px solid var(--rule); }
.front h1 { font-size: clamp(3.2rem, 11vw, 4.4rem); line-height: .95; transform: rotate(-2deg); margin-top: 36px; }
.front .sub { font-size: 1.45rem; margin-top: 8px; }
.ko-inline { font-family: "Nanum Pen Script", var(--hand); font-size: 1.3em; }
.counter { position: absolute; right: 16px; top: 16px; display: flex; align-items: center; gap: 2px; }
.counter b, .cell {
  display: grid; place-items: center; position: relative; border-radius: 2px;
  background: var(--shell-2); color: var(--ink); font-weight: 500; font-variant-numeric: tabular-nums;
  box-shadow: inset 0 0 0 1px #4a464e;
}
.counter b { width: 22px; height: 30px; font-size: 1.05rem; }
.counter .d { background: none; box-shadow: none; color: var(--tape); width: auto; padding-right: 3px; font-size: .95rem; }
.counter + small { position: absolute; right: 16px; top: 50px; font-size: .66rem; color: var(--tape); }
.spine { display: flex; justify-content: space-between; gap: 8px; padding: 9px 18px; background: var(--pen); color: var(--card); font-size: .75rem; }
.tracks { padding: 10px 18px 16px; display: grid; gap: 6px; }
.tracks .side { font-size: .7rem; letter-spacing: .05em; color: var(--tape); margin-top: 6px; }
.tracks a {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  padding-bottom: 5px; border-bottom: 1px dashed var(--rule);
  color: var(--pen); text-decoration: none; font-family: var(--hand); font-weight: 500; font-size: 1.35rem; line-height: 1.1;
}
.tracks a span { font-family: var(--mono); font-size: .7rem; color: var(--tape); flex: none; }
.tracks a:hover, .tracks a.now, .tracks a.now span { color: var(--rec); }

/* Fita desenhada; as rodas giram enquanto toca */
.cassette { background: var(--shell-2); border-radius: 10px; padding: 12px; display: grid; gap: 10px; box-shadow: inset 0 0 0 1px #46424a, 0 10px 24px -12px #000; }
.stick { background: var(--card); color: var(--pen); border-radius: 4px; padding: 6px 10px; display: flex; justify-content: space-between; align-items: baseline; }
.stick .hand { font-size: 1.5rem; }
.window { display: flex; justify-content: space-around; align-items: center; background: #111; border-radius: 30px; padding: 10px; }
.reel { width: 44px; height: 44px; border-radius: 50%; background: repeating-conic-gradient(var(--ink) 0 12deg, #111 12deg 60deg); box-shadow: 0 0 0 7px var(--tape); }
.ribbon { flex: 1; height: 6px; margin: 0 8px; background: var(--tape); border-radius: 3px; }
.playing .reel { animation: spin 2.2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Deck: barra fixa no celular, dentro da coluna no computador */
.deck {
  position: fixed; z-index: 5; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; gap: 12px;
  background: #0e0d0f; border-top: 1px solid #3a373b;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 10px calc(10px + env(safe-area-inset-bottom, 0px));
}
.play { flex: none; width: 52px; height: 52px; border: 0; border-radius: 50%; background: var(--rec); display: grid; place-items: center; }
.play::before { content: ""; width: 17px; height: 20px; margin-left: 5px; background: #fff; clip-path: polygon(0 0, 100% 50%, 0 100%); }
.play[aria-pressed="true"]::before { margin: 0; width: 15px; height: 19px; clip-path: none; background: linear-gradient(90deg, #fff 0 35%, transparent 35% 65%, #fff 65%); }
.deck p { font-size: .8rem; line-height: 1.45; min-width: 0; }
.deck p b { color: var(--card); font-weight: 500; }

/* Faixas */
.story { display: grid; gap: 64px; min-width: 0; }
.track { display: grid; gap: 14px; scroll-margin-top: 24px; }
.track > header { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 12px; }
.track .no { font-size: .75rem; color: var(--ink-soft); }
.track .ko { font-family: "Nanum Pen Script", var(--hand); font-size: 1.6rem; color: var(--ink-soft); }
.track h2 { flex-basis: 100%; font-family: var(--hand); font-weight: 600; font-size: clamp(2.1rem, 6vw, 2.7rem); line-height: 1.05; color: var(--card); text-wrap: balance; }
.note { background: var(--card); color: var(--pen); border-radius: 3px; padding: 16px 18px; display: grid; gap: 8px; max-width: 60ch; }
.note .hand { font-size: 1.6rem; }
.btn { justify-self: start; border: 0; border-radius: 3px; padding: 12px 16px; background: var(--pen); color: var(--card); font-size: .85rem; text-decoration: none; }
.btn:hover { background: #2a4aa6; }
.btn.rec { background: var(--rec); color: #fff; }
.btn.rec:hover { background: #e2513c; }

/* A1: o apelido em casas de painel */
.flaps { display: flex; flex-wrap: wrap; gap: 4px; min-height: 52px; }
.cell { width: min(38px, calc((100vw - 68px) / 10)); height: 52px; font-size: 1.45rem; font-family: var(--mono); }
.cell::after { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: #0009; }
.cell.flip { animation: flap .18s ease-in; }
.cell.cut { color: #8d8692; opacity: .7; text-decoration: line-through 3px var(--rec); }
@keyframes flap { 50% { transform: rotateX(90deg); } }
.stepbar { display: flex; gap: 6px; }
.stepbar i { flex: 1; height: 4px; border-radius: 2px; background: var(--rule); }
.stepbar i.on { background: var(--pen); }

/* Momentos */
.moments { list-style: none; margin: 0; padding: 0 0 0 16px; border-left: 2px dashed var(--rule); display: grid; gap: 14px; }
.moments li { background: var(--card); color: var(--pen); border-radius: 3px; padding: 14px 16px; display: grid; gap: 6px; max-width: 60ch; }
.moments .hand { font-size: 1.6rem; }
.stamp { justify-self: start; border: 2px solid currentColor; padding: 1px 8px; transform: rotate(-4deg); }
.stamp.ko { font-family: "Nanum Pen Script", var(--hand); font-size: 1.6rem; color: var(--rec); }

/* Fotos: cartas viradas. Ao virar, a foto aparece em preto e branco e ganha cor; depois, um toque amplia. */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 18px; }
.photo { margin: 0; border: 0; padding: 0; background: none; color: var(--pen); perspective: 900px; transform: rotate(-1.5deg); }
.photo:nth-child(2) { transform: rotate(1.8deg); }
.photo:nth-child(3) { transform: rotate(-.6deg); }
.photo .inner { display: grid; transform-style: preserve-3d; transition: transform .7s cubic-bezier(.16, 1, .3, 1); }
.photo.flipped .inner { transform: rotateY(180deg); }
.photo .face { grid-area: 1 / 1; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: 3px; box-shadow: 0 10px 22px -12px #000; }
.photo .front { transform: rotateY(180deg); background: var(--card); padding: 9px 9px 6px; display: grid; gap: 6px; text-align: center; }
.photo .back { background: var(--pen); color: var(--card); display: grid; place-content: center; justify-items: center; gap: 6px; padding: 12px; box-shadow: inset 0 0 0 6px var(--card), 0 10px 22px -12px #000; }
.photo .back .count { font-size: .75rem; }
.photo .back .ko-flip { font-family: "Nanum Pen Script", var(--hand); font-size: 2.2rem; line-height: 1; }
.photo .back .hint { font-family: var(--hand); font-size: 1.3rem; }
.photo:hover .back { background: #2a4aa6; }
.photo img { display: block; width: 100%; max-width: 100%; aspect-ratio: 4 / 5; object-fit: cover; filter: grayscale(1) contrast(1.05); transition: filter 2s cubic-bezier(.16, 1, .3, 1); }
.photo.on img { filter: none; }
.photo .front .hand { font-size: 1.2rem; }
.photo.flipped { cursor: zoom-in; }

/* Foto ampliada */
.viewer { border: 0; padding: 12px 12px 14px; background: var(--card); color: var(--pen); border-radius: 3px; max-width: min(92vw, 640px); display: none; gap: 10px; justify-items: center; text-align: center; }
.viewer[open] { display: grid; }
.viewer::backdrop { background: #0e0d0fe6; }
.viewer img { display: block; max-width: 100%; max-height: 74vh; object-fit: contain; }
.viewer .hand { font-size: 1.5rem; }

/* B1: virar a fita */
.flipwrap { perspective: 900px; max-width: 360px; }
.flipcard { display: grid; transform-style: preserve-3d; transition: transform .7s cubic-bezier(.16, 1, .3, 1); }
.flipcard > * { grid-area: 1 / 1; backface-visibility: hidden; }
.flipcard .b { transform: rotateY(180deg); }
.flipped .flipcard { transform: rotateY(180deg); }
.now-text { font-size: .85rem; line-height: 1.5; color: var(--ink-soft); max-width: 60ch; }

/* B2: a conta */
.bill { background: var(--card); color: var(--pen); border-radius: 3px; padding: 18px; display: grid; gap: 12px; max-width: 60ch; }
.bill ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.bill li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding-bottom: 8px; border-bottom: 1px dashed var(--rule); font-size: .85rem; line-height: 1.4; }
.bill li .stamp { flex: none; text-align: center; font-size: 1.15rem; font-family: "Nanum Pen Script", var(--hand); line-height: 1; padding: 2px 6px; }
.bill li .stamp small { display: block; font-family: var(--mono); font-size: .62rem; }
.bill li .stamp.due { color: var(--rec); }
.bill .fine { font-size: .8rem; line-height: 1.5; }
.bill .thanks { justify-self: end; font-family: "Nanum Pen Script", var(--hand); font-size: 1.7rem; }

/* B3: a flor, desenhada a caneta; cada pétala ganha roxo quando tocada */
.flower-card { background: var(--card); color: var(--pen); border-radius: 3px; padding: 16px 18px 20px; display: grid; gap: 10px; max-width: 60ch; justify-items: center; text-align: center; }
.flower-card svg { width: min(100%, 300px); height: auto; overflow: visible; }
.flower-card .stem, .flower-card .leaf { fill: none; stroke: var(--pen); stroke-width: 2.5; stroke-linecap: round; }
.petal path { fill: transparent; stroke: var(--pen); stroke-width: 2.5; transition: fill .6s cubic-bezier(.16, 1, .3, 1); }
.petal { cursor: pointer; }
.petal:hover path { fill: #d9cdf2; }
.petal.on path { fill: var(--purple); }
.petal:focus { outline: none; }
.petal:focus-visible path { stroke: var(--rec); stroke-width: 4; }
.flower-card .center { fill: var(--card); stroke: var(--pen); stroke-width: 2.5; transition: fill .6s ease; }
.bloomed .center { fill: #f2c94c; }
.flower-card .phrase { font-family: var(--hand); font-weight: 500; font-size: 1.6rem; line-height: 1.15; min-height: 2.3em; }

.noscript { padding: 2rem 1rem; }

@media (min-width: 900px) {
  .page { grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); gap: 56px; padding-block: 40px 80px; align-items: start; }
  .side-col { position: sticky; top: calc(24px + env(safe-area-inset-top, 0px)); }
  .deck { position: static; background: none; border: 0; padding: 0; }
  .story { padding-top: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .playing .reel, .cell.flip { animation: none; }
  .flipcard, .photo .inner, .photo img, .petal path, .flower-card .center { transition: none; }
}
