:root {
  --ink: #0b0b14;
  --paper: #fff8e7;
  --orange: #ff7a1a;
  --magenta: #ff2e88;
  --cyan: #19e3ff;
  --yellow: #ffd60a;
  --purple: #7b2ff7;
  --green: #2ee59d;
  --red: #e63946;
  --shadow: 5px 5px 0 var(--ink);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--ink); color: var(--paper); font-family: Nunito, system-ui, sans-serif; overscroll-behavior: none; }
body { touch-action: none; user-select: none; -webkit-user-select: none; }
button { font-family: inherit; }

/* comic background: halftone + speed rays */
#bg {
  position: fixed; inset: 0; z-index: 0;
  background:
    radial-gradient(circle at 50% 40%, rgba(123,47,247,.45), transparent 60%),
    radial-gradient(rgba(25,227,255,.16) 1.6px, transparent 1.8px) 0 0 / 14px 14px,
    repeating-conic-gradient(from 0deg at 50% 45%, rgba(255,46,136,.10) 0 6deg, transparent 6deg 15deg),
    linear-gradient(160deg, #1a1033, #0b0b14 60%, #10203a);
}
#game, #fx { position: fixed; inset: 0; z-index: 1; display: block; }
#fx { z-index: 30; pointer-events: none; }

/* ------------- screens ------------- */
.screen { position: fixed; inset: 0; z-index: 20; display: none; overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y;
  padding: calc(14px + var(--safe-t)) calc(14px + var(--safe-r)) calc(18px + var(--safe-b)) calc(14px + var(--safe-l)); }
.screen.show { display: block; animation: fadeIn .25s ease; }
.screen.s-pause { background: rgba(11,11,20,.6); backdrop-filter: blur(3px); }
.screen.s-calmRun { pointer-events: none; background: none; }
.screen.s-calmRun .btn { pointer-events: auto; }
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }

.logo { margin: 0; text-align: center; line-height: .85; font-weight: normal; transform: rotate(-3deg); }
.logo .l1 { display: block; position: relative; font-family: Bangers, Impact, sans-serif; font-size: clamp(64px, 17vw, 150px); color: var(--yellow); letter-spacing: 2px;
  -webkit-text-stroke: 4px var(--ink); paint-order: stroke fill;
  text-shadow: -6px 0 0 var(--cyan), 6px 0 0 var(--magenta), 10px 10px 0 var(--ink); animation: glitch 4s infinite steps(1); }
.logo .l2 { display: inline-block; margin-top: 6px; font-family: Bangers, Impact, sans-serif; font-size: clamp(22px, 5.5vw, 44px); color: var(--paper); background: var(--magenta);
  padding: 2px 14px; border: 4px solid var(--ink); box-shadow: var(--shadow); transform: rotate(2deg); letter-spacing: 1px; }
.logo.small .l1 { font-size: clamp(52px, 11vw, 96px); }
.logo.small .l2 { font-size: clamp(18px, 3.6vw, 30px); }
@keyframes glitch { 0%, 92%, 100% { transform: none; } 93% { transform: translate(-3px, 1px) skewX(-6deg); } 95% { transform: translate(3px, -1px); } 97% { transform: translate(-1px, 0) skewX(4deg); } }

.comic-title { font-family: Bangers, Impact, sans-serif; font-weight: normal; margin: 6px 0 10px; font-size: clamp(34px, 7vw, 58px); color: var(--yellow); line-height: 1; letter-spacing: 1px;
  -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; text-shadow: -3px 0 var(--cyan), 3px 0 var(--magenta), 5px 5px 0 var(--ink); text-align: center; }
.comic-title.sm { font-size: clamp(28px, 6vw, 44px); margin: 0; }
.comic-title span { color: var(--orange); font-size: 1.3em; }

.btn { font-family: Bangers, Impact, sans-serif; font-size: 24px; letter-spacing: 1px; color: var(--ink); background: var(--paper); border: 4px solid var(--ink); border-radius: 14px;
  padding: 10px 20px; box-shadow: var(--shadow); cursor: pointer; transition: transform .08s, box-shadow .08s; min-height: 52px; }
.btn:hover { transform: translate(-2px, -2px) rotate(-1deg); box-shadow: 7px 7px 0 var(--ink); }
.btn:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }
.btn.primary { background: var(--orange); color: var(--paper); -webkit-text-stroke: 1.5px var(--ink); paint-order: stroke fill; }
.btn.big { font-size: 32px; padding: 12px 34px; }
.btn.small { font-size: 18px; padding: 6px 12px; min-height: 40px; box-shadow: 3px 3px 0 var(--ink); }
.btn.ghost { background: rgba(255,248,231,.12); color: var(--paper); border-color: var(--paper); box-shadow: 4px 4px 0 rgba(0,0,0,.6); }
.intro-panel .btn.ghost, .panel .btn.ghost { background: #fff; color: var(--ink); border-color: var(--ink); box-shadow: 4px 4px 0 var(--ink); }
.btn.calm { background: var(--cyan); }
.btn.love { background: var(--magenta); color: var(--paper); }
.btn.share { background: var(--green); }
.pulse { animation: pulse 1.4s infinite ease-in-out; }
@keyframes pulse { 50% { transform: scale(1.06) rotate(-1deg); } }
.bob { animation: bob 1.6s infinite steps(4); }
@keyframes bob { 0%, 100% { transform: translateY(0) } 50% { transform: translateY(-8px) } }
.wobble { animation: wobble 2.2s infinite steps(6); }
@keyframes wobble { 0%, 100% { transform: rotate(-6deg) } 50% { transform: rotate(6deg) } }
.pop-in { animation: popIn .45s cubic-bezier(.2, 1.6, .4, 1) both; }
.pop-in.d2 { animation-delay: .5s; } .pop-in.d3 { animation-delay: 1s; }
@keyframes popIn { from { transform: scale(.6) rotate(-4deg); opacity: 0 } to { transform: none; opacity: 1 } }

.chip { font-family: Nunito, sans-serif; font-weight: 900; font-size: 15px; color: var(--paper); background: transparent; border: 3px solid var(--paper); border-radius: 999px; padding: 6px 14px; margin: 3px; cursor: pointer; }
.chip.on { background: var(--paper); color: var(--ink); }
.row { display: flex; gap: 12px; justify-content: center; align-items: center; margin-top: 14px; }
.row.wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 12px; align-items: stretch; margin-top: 10px; }
.foot { margin-top: 18px; text-align: center; opacity: .7; font-size: 13px; font-weight: 700; }

/* title */
.title-wrap { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; }
.hero { display: flex; align-items: center; justify-content: center; gap: 6px; }
.hero-karla { width: clamp(150px, 34vw, 240px); filter: drop-shadow(6px 6px 0 var(--ink)); }
.hero-villain { width: clamp(90px, 20vw, 150px); filter: drop-shadow(5px 5px 0 var(--ink)); }
.hero-vs { font-family: Bangers, Impact, sans-serif; font-size: clamp(36px, 8vw, 64px); color: var(--magenta); -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; transform: rotate(-10deg); }
svg { display: block; width: 100%; height: auto; }

/* menu */
.menu-wrap { min-height: 100%; display: flex; align-items: center; justify-content: center; gap: clamp(16px, 5vw, 60px); flex-wrap: wrap; }
.menu-left { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.menu-karla { width: clamp(130px, 26vw, 220px); filter: drop-shadow(6px 6px 0 var(--ink)); }
.menu-right { display: flex; flex-direction: column; gap: 12px; width: min(340px, 90vw); }
.hello { font-weight: 800; background: rgba(0,0,0,.35); border: 2px solid rgba(255,255,255,.2); padding: 6px 12px; border-radius: 10px; font-size: 14px; }
.quick { display: flex; justify-content: center; flex-wrap: wrap; }

/* pages */
.page { max-width: 980px; margin: 0 auto; }
.page.center { min-height: 100%; display: flex; align-items: center; justify-content: center; }
.page-head { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; margin-bottom: 14px; }
.total-pill { font-family: Bangers, Impact, sans-serif; font-size: 20px; background: var(--yellow); color: var(--ink); border: 3px solid var(--ink); padding: 4px 10px; border-radius: 10px; box-shadow: 3px 3px 0 var(--ink); }

.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.level-card { position: relative; text-align: center; color: var(--ink); background: var(--paper); border: 4px solid var(--ink); border-radius: 16px; box-shadow: 6px 6px 0 var(--ink); padding: 12px 8px 10px; cursor: pointer; font-family: Nunito, sans-serif; transition: transform .1s; overflow: hidden; }
.level-card::before { content: ''; position: absolute; inset: 0; background: radial-gradient(rgba(0,0,0,.08) 1.4px, transparent 1.6px) 0 0 / 9px 9px; pointer-events: none; }
.level-card:hover { transform: translate(-2px, -3px) rotate(-1deg); }
.level-card.locked { filter: grayscale(1); opacity: .6; }
.lc-num { font-family: Bangers, Impact, sans-serif; font-size: 16px; background: var(--ink); color: var(--yellow); display: inline-block; padding: 1px 10px; border-radius: 6px; }
.lc-icon { font-size: 46px; margin: 6px 0 2px; }
.lc-name { font-weight: 900; font-size: 16px; line-height: 1.1; min-height: 36px; display: flex; align-items: center; justify-content: center; }
.lc-stars { font-size: 22px; margin-top: 4px; }
.lc-best { font-size: 13px; font-weight: 800; opacity: .75; }
.lv-1 { background: #ffe6cf; } .lv-2 { background: #d8f6ff; } .lv-3 { background: #cfefff; } .lv-4 { background: #e3ffe9; } .lv-5 { background: #f1e2ff; } .lv-6 { background: #ffd9dd; }
.star { color: rgba(0,0,0,.2); -webkit-text-stroke: 1.5px var(--ink); }
.star.on { color: var(--yellow); }
.medal { margin-left: 4px; }

.intro-panel { position: relative; width: min(680px, 100%); background: var(--paper); color: var(--ink); border: 5px solid var(--ink); border-radius: 20px; box-shadow: 9px 9px 0 var(--ink); padding: 20px clamp(14px, 4vw, 28px); }
.intro-panel.narrow { width: min(460px, 100%); }
.intro-panel .comic-title { margin-top: 4px; }
.intro-badge { position: absolute; top: -18px; left: 50%; transform: translateX(-50%) rotate(-2deg); font-family: Bangers, Impact, sans-serif; font-size: 20px; background: var(--magenta); color: var(--paper); border: 3px solid var(--ink); padding: 2px 14px; border-radius: 8px; white-space: nowrap; box-shadow: 3px 3px 0 var(--ink); }
.intro-desc { text-align: center; font-weight: 800; font-size: 17px; margin: 0 0 12px; }
.villain-row { display: flex; align-items: center; gap: 10px; margin: 8px 0 12px; }
.v-svg { width: 70px; flex: none; }
.bubble { position: relative; background: #fff; border: 3px solid var(--ink); border-radius: 16px; padding: 8px 12px; font-weight: 900; font-style: italic; }
.bubble::before { content: ''; position: absolute; left: -14px; top: 50%; border: 8px solid transparent; border-right: 12px solid var(--ink); transform: translateY(-50%); }
.news { display: grid; gap: 8px; }
.news-card { display: flex; gap: 10px; align-items: center; background: #fff; border: 3px solid var(--ink); border-radius: 12px; padding: 8px 10px; box-shadow: 3px 3px 0 var(--ink); }
.news-card b { font-size: 15px; } .news-card p { margin: 2px 0 0; font-size: 14px; font-weight: 700; }
.nc-ic { font-size: 30px; flex: none; width: 44px; text-align: center; }
.controls-hint { margin-top: 12px; font-size: 13px; font-weight: 800; background: var(--ink); color: var(--paper); padding: 8px 10px; border-radius: 10px; }
.goal { margin-top: 8px; text-align: center; font-weight: 900; }
.tip { margin-top: 10px; font-size: 14px; font-weight: 700; background: #e6fbff; border: 3px dashed var(--ink); border-radius: 12px; padding: 8px 10px; }
.rotate { margin-top: 8px; text-align: center; font-weight: 800; font-size: 13px; }
.hint { text-align: center; font-weight: 800; color: var(--red); }

/* results */
.results { text-align: center; }
.grade { margin-top: 10px; }
.grade.g0 { color: #b0b0b0; } .grade.g3 { color: var(--green); } .grade.g4 { color: var(--orange); font-size: clamp(34px, 8vw, 60px); }
.res-stars { font-size: 56px; line-height: 1; }
.res-stars .star.boom { animation: boom .5s cubic-bezier(.2, 2, .4, 1); display: inline-block; }
@keyframes boom { from { transform: scale(2.4) rotate(30deg); } to { transform: none; } }
.res-score { font-family: Bangers, Impact, sans-serif; font-size: clamp(56px, 14vw, 92px); color: var(--orange); -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; text-shadow: 5px 5px 0 var(--ink); line-height: 1.05; }
.record { display: inline-block; font-family: Bangers, Impact, sans-serif; font-size: 24px; background: var(--yellow); border: 3px solid var(--ink); padding: 2px 12px; border-radius: 8px; transform: rotate(-3deg); animation: pulse 1s infinite; }
.res-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 12px 0 6px; font-weight: 800; font-size: 14px; }
.res-stats div { background: #fff; border: 2px solid var(--ink); border-radius: 10px; padding: 6px; }
.res-stats span { margin-right: 4px; }
.rank-box { min-height: 24px; margin-top: 6px; }
.ranks { display: flex; gap: 10px; justify-content: center; }
.ranks > div { background: var(--ink); color: var(--paper); border-radius: 12px; padding: 6px 14px; font-weight: 800; }
.ranks b { color: var(--yellow); font-size: 22px; } .ranks small { display: block; opacity: .7; font-size: 11px; }
.semester { font-family: Bangers, Impact, sans-serif; font-size: 30px; color: var(--paper); background: linear-gradient(90deg, var(--purple), var(--magenta)); border: 4px solid var(--ink); border-radius: 14px; padding: 8px; margin: 8px 0 18px; }
.semester small { display: block; font-family: Nunito, sans-serif; font-size: 14px; font-weight: 800; margin-top: 2px; }
.name-entry { margin: 12px 0; text-align: center; }
.name-entry label { font-weight: 900; display: block; margin-bottom: 4px; }
.name-entry .row { margin-top: 4px; }
.name-entry input { font-family: Bangers, Impact, sans-serif; font-size: 26px; letter-spacing: 2px; width: min(220px, 55vw); padding: 8px 12px; border: 4px solid var(--ink); border-radius: 12px; text-transform: uppercase; background: #fff; color: var(--ink); user-select: text; -webkit-user-select: text; }
.name-entry small { display: block; opacity: .7; margin-top: 4px; font-weight: 700; }
.page > .name-entry { background: var(--paper); color: var(--ink); border: 4px solid var(--ink); border-radius: 14px; padding: 12px; margin-top: 16px; }

/* leaderboard */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin-bottom: 10px; }
.tab { font-family: Bangers, Impact, sans-serif; font-size: 18px; padding: 6px 12px; border: 3px solid var(--paper); background: transparent; color: var(--paper); border-radius: 10px; cursor: pointer; }
.tab.on { background: var(--yellow); color: var(--ink); border-color: var(--ink); box-shadow: 3px 3px 0 var(--ink); }
.board-title { text-align: center; font-weight: 900; font-size: 18px; margin-bottom: 8px; }
.board-list { max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 6px; }
.b-row { display: grid; grid-template-columns: 56px 1fr auto; align-items: center; gap: 8px; background: var(--paper); color: var(--ink); border: 3px solid var(--ink); border-radius: 12px; padding: 8px 12px; box-shadow: 4px 4px 0 var(--ink); font-weight: 900; }
.b-row.top1 { background: #fff1a8; } .b-row.top2 { background: #eef1f5; } .b-row.top3 { background: #ffd9b8; }
.b-row.mine { outline: 4px solid var(--cyan); }
.b-rank { font-family: Bangers, Impact, sans-serif; font-size: 24px; text-align: center; }
.b-name { font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-transform: uppercase; }
.b-score { font-family: Bangers, Impact, sans-serif; font-size: 26px; color: var(--orange); -webkit-text-stroke: 1px var(--ink); }
.empty, .loading { text-align: center; padding: 20px; font-weight: 800; opacity: .8; }

/* how to */
.howto { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.ht-card { background: var(--paper); color: var(--ink); border: 4px solid var(--ink); border-radius: 14px; box-shadow: 5px 5px 0 var(--ink); padding: 12px 14px; }
.ht-card h3 { margin: 0 0 6px; font-family: Bangers, Impact, sans-serif; font-weight: normal; font-size: 24px; letter-spacing: .5px; }
.ht-card p { margin: 0; font-weight: 700; font-size: 14px; line-height: 1.45; }

/* settings */
.set-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 2px dashed rgba(0,0,0,.2); font-weight: 900; }
.set-row .chip { color: var(--ink); border-color: var(--ink); }
.set-row .chip.on { background: var(--ink); color: var(--paper); }
.calm-panel { background: linear-gradient(160deg, #e6fbff, #f1e2ff); text-align: center; }
.calm-run { position: fixed; top: calc(12px + var(--safe-t)); right: calc(12px + var(--safe-r)); }

/* birthday */
.bday { max-width: 700px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; padding-bottom: 30px; }
.panel { background: var(--paper); color: var(--ink); border: 5px solid var(--ink); border-radius: 18px; box-shadow: 9px 9px 0 var(--ink); padding: 18px; }
.p-21 { position: relative; overflow: hidden; text-align: center; background: radial-gradient(circle at 50% 40%, #fff3b0, #ffb36b 70%); }
.p-21::before { content: ''; position: absolute; inset: 0; background: repeating-conic-gradient(from 0deg at 50% 45%, rgba(255,46,136,.18) 0 8deg, transparent 8deg 18deg); }
.big21 { position: absolute; top: -10px; left: 50%; transform: translateX(-50%); font-family: Bangers, Impact, sans-serif; font-size: 240px; line-height: 1; color: var(--magenta); opacity: .9;
  -webkit-text-stroke: 6px var(--ink); paint-order: stroke fill; text-shadow: -8px 0 var(--cyan), 12px 12px 0 var(--ink); }
.bday-karla { position: relative; width: 200px; margin: 70px auto 0; filter: drop-shadow(6px 6px 0 var(--ink)); }
.p-21 .comic-title { position: relative; }
.letter { background: #fffdf5 repeating-linear-gradient(transparent 0 31px, rgba(25,120,255,.12) 31px 33px); font-size: 18px; line-height: 33px; font-weight: 700; }
.letter-text { min-height: 120px; white-space: normal; }
.letter-sign { text-align: right; font-family: Bangers, Impact, sans-serif; font-size: 30px; color: var(--magenta); margin-top: 8px; }
.caret { animation: blink .6s infinite steps(1); }
@keyframes blink { 50% { opacity: 0 } }
.gift { text-align: center; font-weight: 900; font-size: 18px; }

/* ------------- HUD ------------- */
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#hud.hidden, #touch.hidden { display: none; }
#hudStats { position: absolute; top: calc(6px + var(--safe-t)); left: calc(8px + var(--safe-l)); right: calc(8px + var(--safe-r)); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pill { display: flex; align-items: center; gap: 6px; background: var(--paper); color: var(--ink); border: 3px solid var(--ink); border-radius: 12px; padding: 3px 10px; box-shadow: 3px 3px 0 var(--ink); font-family: Bangers, Impact, sans-serif; font-size: 26px; line-height: 1.1; }
.pill small { font-size: 16px; }
.score-pill { color: var(--orange); -webkit-text-stroke: 1px var(--ink); min-width: 100px; }
#timer.danger { color: var(--red); animation: pulse .5s infinite; display: inline-block; }
#stressWrap .bar { width: clamp(70px, 14vw, 150px); height: 14px; background: #ddd; border: 2px solid var(--ink); border-radius: 8px; overflow: hidden; }
#stressWrap .bar i { display: block; height: 100%; width: 0; background: var(--green); transition: width .2s, background .3s; }
#stressWrap.hot { animation: shake .3s infinite; background: #ffd4d7; }
@keyframes shake { 25% { transform: translateX(-2px) } 75% { transform: translateX(2px) } }
.badge { display: none; font-family: Bangers, Impact, sans-serif; font-size: 20px; padding: 3px 10px; border: 3px solid var(--ink); border-radius: 10px; box-shadow: 3px 3px 0 var(--ink); }
.badge.show { display: block; animation: popIn .3s; }
.combo { background: var(--yellow); color: var(--ink); transform: rotate(-3deg); }
.zen { background: var(--cyan); color: var(--ink); }
.icon-btn { pointer-events: auto; margin-left: auto; font-size: 18px; font-weight: 900; width: 44px; height: 44px; border: 3px solid var(--ink); border-radius: 12px; background: var(--paper); color: var(--ink); box-shadow: 3px 3px 0 var(--ink); cursor: pointer; }
body.mode-swim #hudStats .pill, body.mode-swim #hudStats .badge, body.mode-swim #orders { display: none !important; }

#orders { position: absolute; top: calc(62px + var(--safe-t)); left: calc(8px + var(--safe-l)); right: calc(8px + var(--safe-r)); display: flex; gap: 8px; flex-wrap: wrap; }
.ticket { position: relative; display: flex; align-items: center; gap: 6px; width: 150px; background: var(--paper); color: var(--ink); border: 3px solid var(--ink); border-radius: 12px; padding: 5px 8px 13px; box-shadow: 3px 3px 0 var(--ink); animation: dropIn .35s cubic-bezier(.2, 1.6, .4, 1); transform-origin: top; }
@keyframes dropIn { from { transform: translateY(-30px) rotate(-6deg); opacity: 0 } to { transform: none; opacity: 1 } }
.ticket.danger { animation: shake .25s infinite; background: #ffe0e2; }
.t-emoji { font-size: 28px; line-height: 1; }
.t-body { display: flex; flex-direction: column; min-width: 0; }
.t-body b { font-size: 14px; font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.t-steps { font-size: 13px; white-space: nowrap; }
.t-steps i { font-style: normal; opacity: .5; margin: 0 1px; }
.t-bar { position: absolute; left: 6px; right: 6px; bottom: 4px; height: 6px; background: rgba(0,0,0,.15); border-radius: 4px; overflow: hidden; }
.t-bar i { display: block; height: 100%; width: 100%; background: var(--green); }
.t-pset { border-color: #1d4ed8; } .t-essay { border-color: var(--ink); } .t-swim { background: #dff6ff; } .t-proto { background: #fff1e5; }

/* side HUD on short landscape screens (phones) */
body.side-hud .pill { font-size: 20px; padding: 1px 8px; }
body.side-hud .icon-btn { width: 36px; height: 36px; }
body.side-hud #orders { top: calc(48px + var(--safe-t)); right: auto; flex-direction: column; width: 132px; gap: 5px; }
body.side-hud .ticket { width: 132px; padding: 3px 6px 11px; }
body.side-hud .t-emoji { font-size: 22px; }
body.side-hud .t-body b { font-size: 12px; } body.side-hud .t-steps { font-size: 11px; }

.banner { position: absolute; top: 34%; left: 50%; transform: translate(-50%, -50%) scale(.5) rotate(-4deg); opacity: 0; display: flex; align-items: center; gap: 10px; max-width: 92vw;
  background: var(--paper); color: var(--ink); border: 5px solid var(--ink); border-radius: 16px; padding: 10px 18px; box-shadow: 8px 8px 0 var(--ink); transition: transform .3s cubic-bezier(.2, 1.6, .4, 1), opacity .2s; }
.banner.show { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(-2deg); }
.banner.bad { background: #ffe0e2; } .banner.good { background: #e3ffe9; }
.b-villain { width: 64px; flex: none; } .b-icon { font-size: 40px; }
.b-title { font-family: Bangers, Impact, sans-serif; font-size: 32px; line-height: 1; }
.b-sub { font-weight: 800; font-size: 14px; }

/* ------------- touch controls ------------- */
#touch { position: fixed; inset: 0; z-index: 12; pointer-events: none; }
#joyZone { position: absolute; left: 0; bottom: 0; width: 50%; height: 62%; pointer-events: auto; touch-action: none; }
.joy-hint { position: absolute; left: calc(40px + var(--safe-l)); bottom: calc(40px + var(--safe-b)); font-size: 34px; opacity: .35; }
#joyBase { position: absolute; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%; background: rgba(255,248,231,.12); border: 4px solid rgba(255,248,231,.5); display: none; }
#joyBase.on { display: block; }
#joyKnob { position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; border-radius: 50%; background: var(--yellow); border: 4px solid var(--ink); transform: translate(-50%, -50%); box-shadow: 3px 3px 0 var(--ink); }
.tbtn { pointer-events: auto; touch-action: none; font-family: Bangers, Impact, sans-serif; color: var(--ink); border: 4px solid var(--ink); border-radius: 50%; box-shadow: 4px 4px 0 var(--ink); opacity: .92; }
.tbtn.on { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); filter: brightness(1.15); }
#campusBtns, #swimBtns { position: absolute; display: none; }
body.mode-campus #campusBtns { display: block; right: calc(18px + var(--safe-r)); bottom: calc(18px + var(--safe-b)); width: 190px; height: 170px; }
.tbtn.action { position: absolute; right: 0; bottom: 0; width: 104px; height: 104px; font-size: 44px; background: var(--orange); }
.tbtn.dash { position: absolute; left: 0; top: 0; width: 72px; height: 72px; font-size: 20px; background: var(--cyan); }
body.mode-swim #joyZone { display: none; }
body.mode-swim #swimBtns { display: flex; left: 0; right: 0; bottom: calc(16px + var(--safe-b)); justify-content: space-between; align-items: flex-end; padding: 0 calc(16px + var(--safe-r)) 0 calc(16px + var(--safe-l)); }
.tbtn.arm { width: 100px; height: 100px; font-size: 40px; background: var(--yellow); }
.tbtn.breathe { width: 92px; height: 92px; font-size: 40px; background: var(--cyan); }
body:not(.touch) #touch { display: none !important; }

#toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translate(-50%, 140%); z-index: 40; background: var(--yellow); color: var(--ink); font-weight: 900; border: 3px solid var(--ink); border-radius: 12px; padding: 10px 16px; box-shadow: 4px 4px 0 var(--ink); transition: transform .25s, opacity .25s; max-width: 90vw; text-align: center; opacity: 0; pointer-events: none; }
#toast.show { transform: translate(-50%, 0); opacity: 1; }
body.calm-on #bg { filter: hue-rotate(20deg) brightness(.6); }

@media (max-width: 560px) {
  .btn { font-size: 21px; }
  .btn.big { font-size: 28px; padding: 10px 24px; }
  .ticket { width: calc(50% - 4px); }
  .pill { font-size: 22px; }
  .score-pill { min-width: 80px; }
  .big21 { font-size: 180px; }
  .letter { font-size: 16px; line-height: 29px; background-size: auto; }
}
@media (prefers-reduced-motion: reduce) {
  .logo .l1, .bob, .wobble, .pulse { animation: none; }
}

/* =================== ESCAPE ROOM =================== */
#escape { position: fixed; inset: 0; z-index: 6; display: flex; flex-direction: column; background: #0b0b14; }
.esc-top { display: flex; align-items: center; gap: 8px; padding: calc(6px + var(--safe-t)) calc(10px + var(--safe-r)) 6px calc(10px + var(--safe-l)); background: linear-gradient(#0b0b14, rgba(11,11,20,.85)); z-index: 2; flex-wrap: nowrap; }
.esc-pill { background: var(--paper); color: var(--ink); border: 3px solid var(--ink); border-radius: 12px; padding: 3px 10px; font-weight: 900; box-shadow: 3px 3px 0 var(--magenta); white-space: nowrap; font-size: 15px; }
.esc-pill.code span { opacity: .3; filter: grayscale(1); margin: 0 1px; transition: .3s; }
.esc-pill.code span.got { opacity: 1; filter: none; }
.esc-sp { flex: 1; }
.esc-btn { font-family: Bangers, Impact, sans-serif; font-size: 20px; background: var(--yellow); color: var(--ink); border: 3px solid var(--ink); border-radius: 12px; padding: 4px 12px; box-shadow: 3px 3px 0 var(--ink); cursor: pointer; }
.esc-btn small { font-family: Nunito; font-size: 11px; font-weight: 900; }
.esc-view { flex: 1; position: relative; overflow: hidden; display: flex; align-items: center; justify-content: center; scrollbar-width: none; min-height: 0; }
.esc-view.scroll { overflow-x: auto; justify-content: flex-start; touch-action: pan-x; }
.esc-view.scroll::before { content: '◀ ▶'; position: fixed; bottom: calc(86px + var(--safe-b)); left: 50%; transform: translateX(-50%); z-index: 2; font-weight: 900; color: var(--yellow); background: rgba(0,0,0,.6); padding: 2px 10px; border-radius: 10px; pointer-events: none; animation: pulse 1.5s infinite; }
.esc-view::-webkit-scrollbar { display: none; }
.esc-scene { flex: none; }
.esc-svg { width: 100%; height: 100%; display: block; border-radius: 6px; }
.esc-svg .hs { cursor: pointer; transition: filter .15s; }
.esc-svg .hs:hover { filter: drop-shadow(0 0 6px #ffd60a) drop-shadow(0 0 2px #ffd60a); }
.esc-svg.uv-on, .esc-svg.uv-on .hs { cursor: crosshair; }
.esc-svg.uv-on .hs:hover { filter: none; }
.esc-ecg { stroke-dasharray: 1400; stroke-dashoffset: 1400; animation: ecgDraw 3s linear infinite; }
@keyframes ecgDraw { to { stroke-dashoffset: 0; } }
.esc-beat, .esc-beat-big { animation: beat 1s ease-out infinite; transform-box: fill-box; transform-origin: center; display: inline-block; }
@keyframes beat { 0% { transform: scale(1.5); } 30% { transform: scale(1); } 100% { transform: scale(1); } }
.blink { animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
#doorLeaf { transition: transform 1.6s cubic-bezier(.6,0,.3,1); transform-box: fill-box; transform-origin: left center; }
#doorLeaf.open { transform: perspective(600px) rotateY(-75deg); }
#escape.won .esc-view::after { content: ''; position: absolute; inset: 0; background: radial-gradient(circle at 50% 45%, #fff 0, rgba(255,255,255,.0) 60%); animation: flash 2s ease-out forwards; pointer-events: none; }
@keyframes flash { 0% { opacity: 0; } 60% { opacity: 1; } 100% { opacity: 1; } }

.esc-inv { display: flex; align-items: center; gap: 8px; padding: 6px calc(10px + var(--safe-r)) calc(8px + var(--safe-b)) calc(10px + var(--safe-l)); background: linear-gradient(rgba(11,11,20,.85), #0b0b14); flex-wrap: wrap; }
.inv-label { font-size: 22px; }
.inv-slot { width: 74px; height: 58px; border-radius: 12px; border: 3px solid var(--ink); background: var(--paper); box-shadow: 3px 3px 0 var(--cyan); display: flex; flex-direction: column; align-items: center; justify-content: center; cursor: pointer; padding: 2px; }
.inv-slot span { font-size: 24px; line-height: 1; }
.inv-slot small { font-size: 9px; font-weight: 900; color: var(--ink); line-height: 1.05; text-align: center; }
.inv-slot.empty { background: rgba(255,255,255,.06); border: 3px dashed rgba(255,255,255,.2); box-shadow: none; cursor: default; }
.inv-slot.sel { background: var(--yellow); transform: translateY(-4px); box-shadow: 3px 3px 0 var(--magenta), 0 0 18px var(--yellow); }
.inv-help { font-weight: 900; color: var(--yellow); font-size: 14px; animation: pulse 1.2s infinite; }

.esc-msg { position: absolute; left: 50%; top: calc(58px + var(--safe-t)); transform: translate(-50%, -20px); opacity: 0; transition: .25s; z-index: 4; max-width: min(92vw, 620px);
  background: var(--paper); color: var(--ink); border: 4px solid var(--ink); border-radius: 14px; padding: 10px 14px; font-weight: 800; box-shadow: 5px 5px 0 var(--ink); pointer-events: none; font-size: 15px; }
.esc-msg.show { opacity: 1; transform: translate(-50%, 0); }
.esc-msg.good { background: #d8ffe9; } .esc-msg.bad { background: #ffd9dc; } .esc-msg.hint { background: #fff3b0; }

.esc-modal { position: absolute; inset: 0; z-index: 3; display: none; align-items: center; justify-content: center; background: rgba(5,5,12,.72); backdrop-filter: blur(2px); padding: 12px; }
.esc-modal.show { display: flex; animation: fadeIn .18s; }
.esc-card { background: #1a1730; border: 4px solid var(--ink); outline: 3px solid var(--cyan); border-radius: 18px; width: min(640px, 100%); max-height: 100%; overflow: auto; box-shadow: 8px 8px 0 var(--magenta); animation: popIn .25s; }
.esc-card-h { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; background: var(--yellow); color: var(--ink); border-bottom: 4px solid var(--ink); position: sticky; top: 0; z-index: 1; }
.esc-card-h b { font-family: Bangers, Impact, sans-serif; font-size: 24px; letter-spacing: 1px; font-weight: normal; }
.esc-x { background: var(--ink); color: var(--paper); border: 0; border-radius: 10px; width: 40px; height: 40px; font-size: 20px; cursor: pointer; }
.esc-card-b { padding: 14px; }
.cu { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.cu p { margin: 0; font-weight: 700; }
.cu .muted, .muted { opacity: .75; font-size: 14px; }
.cu-big { font-size: 64px; }
.take { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 2px; background: var(--paper); color: var(--ink); border: 4px solid var(--ink); border-radius: 14px; padding: 10px; box-shadow: 4px 4px 0 var(--green); font-size: 28px; cursor: pointer; animation: pulse 1.6s infinite; }
.take b { font-size: 17px; } .take small { font-size: 13px; font-weight: 800; opacity: .7; }
.flyer { background: #ff7a1a; color: var(--ink); font-weight: 900; padding: 8px 12px; border: 3px solid var(--ink); transform: rotate(-2deg); }
.postit { background: #ffd60a; color: var(--ink); font-weight: 800; padding: 14px 16px; border: 3px solid var(--ink); transform: rotate(-2deg); box-shadow: 4px 4px 0 rgba(0,0,0,.4); text-align: left; line-height: 1.4; font-size: 16px; }
.dad-note { background: var(--paper); color: var(--ink); border: 4px solid var(--ink); border-radius: 12px; padding: 18px; font-size: 18px; font-weight: 800; line-height: 1.45; box-shadow: 5px 5px 0 var(--magenta); }
.dad-note .sig { text-align: right; margin-top: 8px; font-family: Bangers; font-size: 22px; color: var(--magenta); }
.dad-note small { display: block; text-align: center; color: #1a7f4b; }
.wb-svg, .ecg-svg { width: 100%; display: block; border-radius: 10px; }
.ecg-readout { margin-top: 10px; font-weight: 900; font-size: 20px; text-align: center; }
.ecg-readout span { color: var(--red); font-size: 28px; }
.ecg-readout small { opacity: .6; font-size: 13px; }
.term { background: #041a10; color: #39ff88; font-family: ui-monospace, Menlo, monospace; border: 4px solid var(--ink); border-radius: 12px; padding: 12px 14px; text-align: left; font-size: 15px; }
.term p { margin: 0 0 6px; }
.term-in { font-size: 34px; letter-spacing: 6px; margin-top: 6px; }
.kpad { display: grid; grid-template-columns: repeat(3, 64px); gap: 8px; justify-content: center; margin: 12px auto 4px; }
.kpad button { height: 54px; font-family: Bangers, Impact; font-size: 26px; background: var(--paper); color: var(--ink); border: 3px solid var(--ink); border-radius: 12px; box-shadow: 3px 3px 0 var(--ink); cursor: pointer; }
.kpad button:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.kpad .ok { background: var(--green); }
.wheels { display: flex; gap: 10px; justify-content: center; }
.wheel { display: flex; flex-direction: column; gap: 4px; }
.wheel button { width: 60px; height: 42px; font-size: 20px; background: #3a4157; color: var(--paper); border: 3px solid var(--ink); border-radius: 10px; cursor: pointer; }
.wl { width: 60px; height: 64px; display: grid; place-items: center; font-family: Bangers; font-size: 44px; color: var(--ink); background: var(--yellow); border: 4px solid var(--ink); border-radius: 10px; }
.wl.b-A { background: #ff8fa3; } .wl.b-T { background: #8fd3ff; } .wl.b-G { background: #9dffb8; } .wl.b-C { background: #ffe27a; }
.scope { width: min(300px, 70vw); filter: drop-shadow(0 0 20px rgba(25,227,255,.3)); }
.scope svg { width: 100%; display: block; }
.focus { display: flex; align-items: center; gap: 10px; font-weight: 900; width: min(320px, 90%); }
.focus input { flex: 1; accent-color: var(--magenta); height: 34px; }
.spine-svg { width: min(220px, 60vw); max-height: 52vh; border: 4px solid var(--ink); border-radius: 8px; }
.hand-svg { width: min(210px, 50vw); }
.hand-svg.alive rect.fanim { animation: fingerPop .5s ease-out; transform-box: fill-box; transform-origin: bottom; }
@keyframes fingerPop { from { transform: scaleY(.4); } to { transform: scaleY(1); } }
.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.wires, .ports { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.wire, .port { display: flex; align-items: center; gap: 6px; padding: 7px 10px; border-radius: 10px; border: 3px solid var(--ink); background: var(--paper); color: var(--ink); font-weight: 900; cursor: pointer; font-size: 14px; }
.wire i, .port i { width: 18px; height: 18px; border-radius: 50%; background: var(--c); border: 2px solid var(--ink); }
.port i { border-style: dashed; }
.wire.sel { background: var(--yellow); transform: translateY(-3px); box-shadow: 0 0 12px var(--yellow); }
.door-code { background: #1d2133; border: 4px solid var(--ink); border-radius: 14px; padding: 10px 16px; }
.dc-icons, .dc-digits { display: grid; grid-template-columns: repeat(4, 54px); gap: 8px; justify-content: center; text-align: center; }
.dc-icons span { font-size: 30px; }
.dc-digits b { font-family: ui-monospace, monospace; font-size: 36px; color: #39ff88; background: #041a10; border-radius: 8px; padding: 4px 0; }
.fridge-in { gap: 14px; }

.esc-story { position: absolute; inset: 0; z-index: 5; display: none; align-items: center; justify-content: center; background: rgba(5,5,12,.8); padding: 16px; }
.esc-story.show { display: flex; }
.esc-story-card { max-width: 560px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.esc-villain { width: 130px; }
.esc-story .bubble { font-size: 18px; }
.esc-tip { font-weight: 800; color: var(--cyan); margin: 0; }

/* generic pause button for canvas modes */
#gPause { position: fixed; z-index: 7; top: calc(8px + var(--safe-t)); right: calc(10px + var(--safe-r)); display: none; }
body.mode-canvas #gPause { display: block; }
.esc-story .bubble { color: var(--ink); } .esc-story .bubble::before { display: none; }

/* =================== CLOCK TOWER =================== */
.tower-page { max-width: 720px; margin: 0 auto; }
.tower-sub { text-align: center; font-weight: 800; opacity: .9; margin: 4px 0 14px; }
.tower { position: relative; display: flex; flex-direction: column; gap: 0; border: 5px solid var(--ink); border-radius: 26px 26px 8px 8px; overflow: hidden;
  background: repeating-linear-gradient(0deg, #2b2152 0 22px, #261d49 22px 44px); box-shadow: 8px 8px 0 var(--magenta); }
.tower::before { content: '🕰️'; position: absolute; right: 12px; top: -2px; font-size: 26px; opacity: .5; }
.floor { position: relative; display: flex; align-items: center; gap: 12px; text-align: left; padding: 14px 14px; border: 0; border-bottom: 4px solid var(--ink); background: transparent; color: var(--paper); cursor: pointer; font-family: inherit; transition: background .15s; }
.floor:hover:not(.locked) { background: rgba(255,214,10,.12); }
.floor .fl-num { position: absolute; left: 10px; top: 4px; font-family: Bangers; font-size: 13px; letter-spacing: 1px; opacity: .6; }
.floor .fl-ic { width: 64px; height: 64px; flex: none; display: grid; place-items: center; font-size: 34px; background: var(--paper); border: 4px solid var(--ink); border-radius: 16px; box-shadow: 3px 3px 0 var(--cyan); margin-top: 8px; }
.floor .fl-body { flex: 1; min-width: 0; }
.floor .fl-body b { font-family: Bangers, Impact; font-weight: normal; font-size: 24px; letter-spacing: .5px; display: block; color: var(--yellow); -webkit-text-stroke: 1px var(--ink); }
.floor .fl-body small { opacity: .8; font-weight: 800; }
.floor .fl-digit { width: 46px; height: 56px; flex: none; display: grid; place-items: center; font-family: ui-monospace, monospace; font-weight: 900; font-size: 30px; border-radius: 10px; background: #041a10; color: #1f5f3a; border: 3px solid var(--ink); }
.floor .fl-digit.on { color: #39ff88; text-shadow: 0 0 10px #39ff88; }
.floor.locked { cursor: not-allowed; }
.floor.locked .fl-ic, .floor.locked .fl-body { opacity: .45; filter: grayscale(.8); }
.floor.k-escape .fl-ic { box-shadow: 3px 3px 0 var(--green); }
.floor.k-swing .fl-ic { box-shadow: 3px 3px 0 var(--magenta); }
.floor.k-lantern .fl-ic { box-shadow: 3px 3px 0 var(--orange); }
.floor.secret { background: linear-gradient(90deg, #4a137a, #7b2ff7); }
.floor.secret.open { background: linear-gradient(90deg, #ff2e88, #ff7a1a); animation: pulse 1.6s infinite; }
.floor .fl-notes { font-weight: 900; background: var(--paper); color: var(--ink); border: 3px solid var(--ink); border-radius: 10px; padding: 4px 8px; white-space: nowrap; }
.code-slots { display: flex; gap: 6px; margin-top: 4px; }
.code-slots span { width: 30px; height: 38px; display: grid; place-items: center; background: #041a10; color: #1f5f3a; font-family: ui-monospace, monospace; font-weight: 900; font-size: 22px; border: 3px solid var(--ink); border-radius: 6px; }
.code-slots span.on { color: #39ff88; text-shadow: 0 0 8px #39ff88; }
.extras-h { margin: 22px 0 8px; font-family: Bangers; font-weight: normal; font-size: 22px; letter-spacing: 1px; opacity: .85; }
.level-grid.extras .level-card { padding: 8px; min-height: 0; }
.digit-won { font-weight: 900; font-size: 18px; margin-bottom: 6px; }
.digit-won b { font-family: ui-monospace, monospace; background: #041a10; color: #39ff88; padding: 2px 10px; border-radius: 6px; border: 3px solid var(--ink); text-shadow: 0 0 8px #39ff88; }
.secret-room { text-align: center; }
.vault { display: flex; gap: 8px; justify-content: center; align-items: center; font-size: 30px; }
.vault b { font-family: ui-monospace, monospace; background: #041a10; color: #39ff88; padding: 4px 12px; border-radius: 8px; border: 3px solid var(--ink); text-shadow: 0 0 10px #39ff88; }
.vault-sub { font-weight: 900; margin: 6px 0; }
.notes-list { display: flex; flex-direction: column; gap: 8px; margin: 14px 0; text-align: left; }
.note-chip { background: rgba(0,0,0,.08); border: 3px dashed rgba(0,0,0,.3); border-radius: 12px; padding: 8px 12px; font-weight: 800; font-size: 14px; }
.note-chip.on { background: #ffe1ef; border: 3px solid var(--magenta); }
.karlis-svg { width: 100%; height: auto; display: block; }
@media (max-width: 480px) {
  .esc-top { gap: 5px; }
  .esc-pill { font-size: 13px; padding: 3px 7px; }
  .esc-pill.code { display: none; }
  .esc-btn { font-size: 17px; padding: 3px 8px; }
  .inv-slot { width: 64px; height: 54px; }
  .floor { padding: 12px 10px; gap: 8px; }
  .floor .fl-ic { width: 52px; height: 52px; font-size: 28px; }
  .floor .fl-body b { font-size: 20px; }
  .floor .fl-digit { width: 38px; height: 48px; font-size: 24px; }
}
