:root {
  --paper: #FBF6E9;
  --rule: rgba(90, 130, 200, .22);
  --margin: rgba(220, 80, 80, .35);
  --ink: #233A7A;
  --ink2: #3F5FB8;
  --hi: #FFE45C;
  --red: #E0443A;
  --hand: "Gochi Hand", "Patrick Hand", cursive;
  --body: "Patrick Hand", system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  color: var(--ink); font-family: var(--body); font-size: 18px; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
  background-color: var(--paper);
  background-image: linear-gradient(90deg, transparent 54px, var(--margin) 54px, var(--margin) 56px, transparent 56px), repeating-linear-gradient(var(--paper) 0 31px, var(--rule) 31px 32px);
}
body[data-chapter="1"] { --paper: #FFF3E8; }
body[data-chapter="2"] { --paper: #F1F6FB; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
svg { width: 1em; height: 1em; }
button { font: inherit; color: inherit; cursor: pointer; }
#stage { position: fixed; inset: 0; cursor: crosshair; }
#stage canvas { display: block; }

/* HUD */
.hud { position: fixed; top: 0; left: 0; right: 0; z-index: 5; display: flex; align-items: center; gap: 12px; padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left)); pointer-events: none; }
.hud .lvl { display: flex; align-items: center; gap: 8px; min-width: 0; }
.hud .lvl b { font-family: var(--hand); font-weight: 400; font-size: 26px; width: 44px; height: 44px; display: grid; place-items: center; border: 2.5px solid var(--ink); border-radius: 50% 46% 52% 48%; background: var(--hi); }
.hud .lvl span { font-family: var(--hand); font-size: 22px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ink { position: relative; width: 150px; height: 26px; margin-left: auto; border: 2.5px solid var(--ink); border-radius: 13px; background: #fff; overflow: hidden; }
.ink i { position: absolute; left: 0; top: 0; bottom: 0; width: 100%; background: repeating-linear-gradient(-45deg, var(--ink2) 0 6px, var(--ink) 6px 12px); transform-origin: left; transition: transform .08s; }
.ink svg { position: absolute; right: -2px; top: -2px; width: 44px; height: 26px; display: none; }
.ink.low i { background: repeating-linear-gradient(-45deg, var(--red) 0 6px, #B8322A 6px 12px); }
.timer { width: 48px; height: 48px; display: grid; place-items: center; font-family: var(--hand); font-size: 28px; border: 3px solid var(--ink); border-radius: 50%; background: #fff; }
.timer.run { background: var(--hi); animation: wob 1s ease-in-out infinite; }
.timer.low { color: #fff; background: var(--red); }
@keyframes wob { 50% { transform: rotate(-6deg) scale(1.05); } }
.btns { display: flex; gap: 8px; pointer-events: auto; }
.ib { width: 44px; height: 44px; display: grid; place-items: center; border: 2.5px solid var(--ink); border-radius: 12px 14px 11px 15px; background: #fff; color: var(--ink); box-shadow: 3px 3px 0 var(--ink); }
.ib svg { width: 22px; height: 22px; }
.ib:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.ib.small { width: 38px; height: 38px; }
.mute .offi { display: none; }
.mute.off .on { display: none; }
.mute.off .offi { display: block; }
.tip { position: fixed; left: 50%; top: calc(max(10px, env(safe-area-inset-top)) + 62px); transform: translateX(-50%) rotate(-1deg); z-index: 5; margin: 0; padding: 10px 18px; max-width: min(92vw, 460px); text-align: center; font-size: 20px;
  background: var(--hi); border: 2.5px solid var(--ink); border-radius: 6px; box-shadow: 4px 4px 0 rgba(35,58,122,.25); pointer-events: none; }

/* panels: notebook cards */
.panel { position: fixed; z-index: 10; left: 50%; top: 50%; transform: translate(-50%, -50%) rotate(-.6deg); width: min(92vw, 400px); max-height: 94vh; overflow: auto; padding: 24px 22px 18px; text-align: center;
  background: #fff; border: 3px solid var(--ink); border-radius: 18px 22px 16px 20px; box-shadow: 7px 7px 0 rgba(35,58,122,.28); }
.panel h2 { font-family: var(--hand); font-weight: 400; font-size: 40px; margin: 0 0 6px; }
.panel p { margin: 0 0 16px; line-height: 1.35; }
.stamp { position: absolute; top: 14px; right: 16px; margin: 0 !important; padding: 2px 10px; font-family: var(--hand); font-size: 22px; letter-spacing: .08em; text-transform: uppercase; border: 3px solid; border-radius: 8px; transform: rotate(12deg); animation: stamp .45s cubic-bezier(.3,1.6,.5,1) both; }
.stamp.good { color: #2E9A4E; } .stamp.bad { color: var(--red); }
@keyframes stamp { from { transform: rotate(12deg) scale(2.2); opacity: 0; } }
.btn { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; margin: 0 0 10px; padding: 12px 18px; font-family: var(--hand); font-size: 26px; color: #fff;
  background: var(--ink2); border: 3px solid var(--ink); border-radius: 14px 18px 13px 17px; box-shadow: 4px 4px 0 var(--ink); }
.btn svg { width: 22px; height: 22px; }
.btn:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }
.btn.ghost { background: #fff; color: var(--ink); }
.row { display: flex; gap: 10px; }
.row .btn { font-size: 21px; }
.btn:focus-visible, .ib:focus-visible, .lvl:focus-visible { outline: 3px dashed var(--red); outline-offset: 3px; }
.stars { display: flex; justify-content: center; gap: 10px; margin: 4px 0 12px; }
.stars i, .star, .st i { display: inline-block; width: 46px; height: 46px; clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); background: #D9DCE8; }
.stars i.on { background: var(--hi); animation: pop .5s cubic-bezier(.3,1.6,.5,1) both; animation-delay: var(--d); filter: drop-shadow(0 0 0 var(--ink)); }
@keyframes pop { from { transform: scale(0) rotate(-60deg); } }

/* map */
.panel.map { width: min(94vw, 540px); transform: translate(-50%, -50%); }
.logo { font-family: var(--hand); font-weight: 400; font-size: clamp(54px, 13vw, 76px); line-height: 1; margin: 0; color: var(--ink); transform: rotate(-2deg); }
.logo span { background: linear-gradient(transparent 55%, var(--hi) 55% 88%, transparent 88%); padding: 0 6px; }
.tag { margin: 8px 0 14px !important; font-size: 20px; }
.maprow { display: flex; align-items: center; gap: 14px; }
.maprow .btn { width: auto; flex: 1; margin: 0; }
.total { display: flex; align-items: center; gap: 6px; margin: 0 !important; font-size: 20px; }
.total .star { width: 24px; height: 24px; background: var(--hi); }
.chapter { text-align: left; margin-top: 16px; }
.chapter h3 { font-family: var(--hand); font-weight: 400; font-size: 28px; margin: 0; }
.chapter p { margin: 0 0 8px !important; font-size: 17px; opacity: .8; }
.lgrid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.lvl { aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 2px; border: 2.5px solid var(--ink); border-radius: 12px 15px 11px 14px; background: #fff; box-shadow: 3px 3px 0 var(--ink); color: var(--ink); }
.lvl.c0 { background: #E8F6D8; } .lvl.c1 { background: #FFE6D0; } .lvl.c2 { background: #DDEEFA; }
.lvl b { font-family: var(--hand); font-weight: 400; font-size: 26px; line-height: 1; }
.lvl svg { width: 22px; height: 22px; opacity: .5; }
.lvl:disabled { opacity: .45; box-shadow: none; cursor: default; }
.lvl.next { background: var(--hi); animation: wob 1.6s ease-in-out infinite; }
.st { display: flex; gap: 1px; }
.st i { width: 12px; height: 12px; background: #C8CCD8; }
.st i.on { background: #F2B134; }
.foot { display: flex; align-items: center; justify-content: space-between; margin: 16px 0 0 !important; }
.foot a { color: var(--ink); font-size: 20px; }

/* share image */
.ogmark { display: none; }
body.og .ogmark { display: block; position: fixed; left: 5%; top: 50%; transform: translateY(-50%); z-index: 8; }
body.og .ogmark .logo { font-size: 110px; }
body.og .ogmark p { font-family: var(--hand); font-size: 40px; margin: 14px 0 0 6px; }
body.demo .panel, body.demo .hud, body.demo .tip { display: none !important; }
@media (max-width: 520px) {
  .hud { flex-wrap: wrap; row-gap: 8px; }
  .hud .lvl span { font-size: 18px; max-width: 30vw; }
  .ink { width: 110px; }
}
@media (prefers-reduced-motion: reduce) { .timer.run, .lvl.next, .stamp, .stars i.on { animation: none; } }
