:root {
  --ink: #1E150C;
  --parch: #F4E6C4;
  --parch2: #E4CE9C;
  --gold: #F2C14E;
  --gold2: #B8801E;
  --jade: #2E8C6E;
  --jade2: #1E5E4A;
  --text: #FFF6E2;
  --display: "Cinzel", Georgia, serif;
  --body: "Outfit", system-ui, sans-serif;
  --sky1: #10302A; --sky2: #1F5A45; --sky3: #86B77A;
}
body[data-chapter="1"] { --sky1: #3A1E2E; --sky2: #B0583A; --sky3: #F2B36A; }
body[data-chapter="2"] { --sky1: #0B1428; --sky2: #1E3A64; --sky3: #6A8EC4; }
body[data-chapter="3"] { --sky1: #12070A; --sky2: #4A1414; --sky3: #B8401E; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--sky1); color: var(--text); font-family: var(--body); overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
svg { width: 1em; height: 1em; }
button { font: inherit; color: inherit; cursor: pointer; }

/* scenery behind the tower */
.sky { position: fixed; inset: 0; background: linear-gradient(var(--sky1), var(--sky2) 55%, var(--sky3)); transition: background .6s; }
.sky .sun { position: absolute; width: 38vmin; height: 38vmin; left: 62%; top: 12%; border-radius: 50%; background: radial-gradient(circle, rgba(255,236,190,.55), rgba(255,200,120,0) 68%); }
.sky .ridge { position: absolute; left: -10%; right: -10%; bottom: 0; border-radius: 50% 50% 0 0 / 100% 100% 0 0; }
.sky .r1 { height: 34vh; background: rgba(0,0,0,.22); transform: translateX(-12%); }
.sky .r2 { height: 22vh; background: rgba(0,0,0,.35); transform: translateX(14%); }
#stage { position: fixed; inset: 0; }
#stage canvas { display: block; }

/* HUD */
.hud { position: fixed; top: 0; left: 0; right: 0; z-index: 5; display: flex; align-items: center; gap: 10px; padding: max(12px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left)); pointer-events: none; }
.hud .lvl { display: flex; align-items: center; gap: 10px; pointer-events: auto; min-width: 0; }
.hud .lvl b { font-family: var(--display); font-weight: 900; font-size: 22px; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; color: var(--ink);
  background: radial-gradient(circle at 35% 30%, #FFF1B8, var(--gold) 45%, var(--gold2)); box-shadow: 0 3px 0 #6A4410, inset 0 -3px 0 rgba(0,0,0,.2); }
.hud .lvl span { font-family: var(--display); font-weight: 700; font-size: 17px; text-shadow: 0 2px 4px rgba(0,0,0,.5); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.goals { display: flex; gap: 8px; margin-left: auto; }
.chip { display: flex; align-items: center; gap: 6px; height: 38px; padding: 0 12px 0 8px; border-radius: 20px; background: rgba(20,14,8,.62); border: 1.5px solid rgba(242,193,78,.45); backdrop-filter: blur(4px); font-weight: 700; }
.chip svg { width: 24px; height: 24px; }
.chip small { font-weight: 600; opacity: .8; font-size: 13px; }
.chip.ok { border-color: #9BE274; background: rgba(30,70,30,.7); }
.btns { display: flex; gap: 8px; pointer-events: auto; }
.ib { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 14px; border: 0; background: var(--parch); color: var(--ink); box-shadow: 0 3px 0 #8E6A36, 0 6px 14px rgba(0,0,0,.3); }
.ib svg { width: 22px; height: 22px; }
.ib:active { transform: translateY(2px); box-shadow: 0 1px 0 #8E6A36; }
.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%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 5; margin: 0; padding: 12px 18px; border-radius: 16px; max-width: min(92vw, 520px); text-align: center;
  background: rgba(20,14,8,.78); border: 1.5px solid rgba(242,193,78,.5); font-size: 16px; line-height: 1.4; pointer-events: none; animation: rise .4s ease-out; }
@keyframes rise { from { transform: translate(-50%, 16px); opacity: 0; } }

/* panels */
.panel { position: fixed; z-index: 10; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(92vw, 400px); max-height: 94vh; overflow: auto; padding: 26px 22px 20px; text-align: center; color: var(--ink);
  background: linear-gradient(#FBF1D8, var(--parch) 40%, var(--parch2)); border-radius: 24px; border: 3px solid #8E6A36;
  box-shadow: 0 0 0 6px rgba(242,193,78,.25), 0 24px 60px rgba(0,0,0,.5), inset 0 2px 0 #fff; }
.panel h2 { font-family: var(--display); font-weight: 900; font-size: 36px; margin: 0 0 8px; color: #6A3A10; letter-spacing: .02em; }
.panel p { font-size: 16px; line-height: 1.45; margin: 0 0 18px; color: #4A3620; }
.btn { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; margin: 0 0 10px; padding: 14px 18px; border: 0; border-radius: 16px;
  font-family: var(--display); font-weight: 900; font-size: 20px; letter-spacing: .03em; color: #FFF8E4;
  background: linear-gradient(#3FB08A, var(--jade) 55%, var(--jade2)); box-shadow: 0 4px 0 #11382C, 0 8px 18px rgba(0,0,0,.25); text-shadow: 0 2px 0 rgba(0,0,0,.25); }
.btn svg { width: 22px; height: 22px; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #11382C; }
.btn.ghost { background: linear-gradient(#FFF6DE, #EED9A8); color: #5A3A14; box-shadow: 0 4px 0 #A8844A; text-shadow: none; }
.row { display: flex; gap: 10px; }
.row .btn { font-size: 17px; }
.btn:focus-visible, .ib:focus-visible, .lvl:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.stars { display: flex; justify-content: center; gap: 10px; margin: 6px 0 14px; }
.stars i, .star, .st i { display: inline-block; width: 44px; height: 44px; clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); background: #CDB88A; }
.stars i.on { background: linear-gradient(#FFF1B8, var(--gold) 50%, #D8901E); animation: pop .5s cubic-bezier(.3,1.6,.5,1) both; animation-delay: var(--d); }
@keyframes pop { from { transform: scale(0) rotate(-40deg); } }

/* map */
.panel.map { width: min(94vw, 560px); padding-top: 18px; }
.logo { font-family: var(--display); font-weight: 900; font-size: clamp(54px, 13vw, 76px); margin: 0; letter-spacing: .04em; line-height: 1.05;
  background: linear-gradient(#FFF1B8, var(--gold) 45%, #A8680E); -webkit-background-clip: text; background-clip: text; color: transparent; filter: drop-shadow(0 3px 0 #5A3208); }
.tag { margin: 2px 0 14px !important; }
.maprow { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
.maprow .btn { width: auto; flex: 1; margin: 0; }
.total { display: flex; align-items: center; gap: 6px; margin: 0 !important; font-weight: 700; }
.total .star { width: 22px; height: 22px; background: linear-gradient(#FFF1B8, var(--gold) 50%, #D8901E); }
.chapter { text-align: left; margin-top: 16px; padding: 14px; border-radius: 18px; background: rgba(120,80,30,.1); border: 1.5px solid rgba(120,80,30,.18); }
.chapter h3 { font-family: var(--display); font-weight: 900; font-size: 20px; margin: 0; color: #5A3210; }
.chapter p { font-size: 14px; margin: 2px 0 10px; }
.lgrid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.lvl { aspect-ratio: 1; border: 0; border-radius: 14px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 4px;
  background: linear-gradient(#5AB88E, var(--jade)); color: #FFF8E4; box-shadow: 0 3px 0 #11382C; }
.chapter.c1 .lvl { background: linear-gradient(#E8A860, #B8703A); box-shadow: 0 3px 0 #6A3A18; }
.chapter.c2 .lvl { background: linear-gradient(#7FB0E0, #4A7AB8); box-shadow: 0 3px 0 #22406A; }
.chapter.c3 .lvl { background: linear-gradient(#D86A4A, #9A3A24); box-shadow: 0 3px 0 #4A1A10; }
.lvl b { font-family: var(--display); font-weight: 900; font-size: 20px; }
.lvl svg { width: 22px; height: 22px; opacity: .7; }
.lvl:disabled { filter: grayscale(.8) brightness(.8); opacity: .55; cursor: default; }
.lvl.next { outline: 3px solid var(--gold); outline-offset: 2px; animation: glow 1.6s ease-in-out infinite; }
@keyframes glow { 50% { outline-color: #FFF1B8; } }
.st { display: flex; gap: 1px; }
.st i { width: 12px; height: 12px; background: rgba(0,0,0,.25); }
.st i.on { background: #FFE07A; }
.foot { display: flex; align-items: center; justify-content: space-between; margin: 16px 0 0 !important; }
.foot a { color: #6A3A10; font-weight: 700; }

body.demo .panel, body.demo .hud, body.demo .tip { display: none !important; }
.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: 104px; }
body.og .ogmark p { font-family: var(--display); font-weight: 700; font-size: 30px; margin: 8px 0 0 4px; text-shadow: 0 2px 8px rgba(0,0,0,.6); }
@media (max-width: 520px) {
  .hud { flex-wrap: wrap; row-gap: 8px; }
  .goals { order: 3; margin-left: 0; width: 100%; justify-content: center; }
  .hud .lvl span { font-size: 15px; max-width: 34vw; }
}
@media (prefers-reduced-motion: reduce) { .stars i.on, .lvl.next { animation: none; } }
