:root {
  --cream: #FFF6E9;
  --paper: #FFFDF8;
  --ink: #1D1A1F;
  --muted: #6B6470;
  --line: #E8DCC8;
  --red: #E0402F;
  --red-deep: #9E1426;
  --gold: #F2B33D;
  --sky: #5C9BD6;
  --green: #3E9B6A;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Fredoka", system-ui, -apple-system, "Segoe UI", sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
[hidden] { display: none !important; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--cream); color: var(--ink); font-family: var(--font); }
body { position: fixed; inset: 0; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; -webkit-user-select: text; user-select: text; }

#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* ---------- Screens ---------- */
.screen { position: fixed; inset: 0; display: none; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: calc(16px + var(--safe-t)) calc(16px + var(--safe-r)) calc(16px + var(--safe-b)) calc(16px + var(--safe-l));
  background: var(--cream); z-index: 10; }
.screen-dim { background: rgba(29, 26, 31, .55); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
body[data-screen="title"] #s-title, body[data-screen="levels"] #s-levels, body[data-screen="intro"] #s-intro,
body[data-screen="pause"] #s-pause, body[data-screen="result"] #s-result, body[data-screen="how"] #s-how,
body[data-screen="cast"] #s-cast, body[data-screen="scores"] #s-scores { display: flex; flex-direction: column; align-items: center; }
body[data-screen="pause"] #hud, body[data-screen="result"] #hud { opacity: .35; }

.title-card { margin: auto; width: 100%; max-width: 420px; text-align: center; display: flex; flex-direction: column; align-items: center; }
.eyebrow { margin: 0; font-size: 13px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.logo { margin: 4px 0 0; font-size: clamp(64px, 20vw, 96px); line-height: .95; font-weight: 900; letter-spacing: -.03em;
  color: var(--ink); text-shadow: 4px 4px 0 var(--gold); }
.tagline { margin: 8px 0 0; font-size: 18px; font-weight: 700; }
.hero { width: 170px; height: auto; margin: 10px 0 6px; animation: bob 2.4s ease-in-out infinite; }
.hero-photo { width: 150px; margin: 6px 0 4px; }
@media (max-height: 700px) { .hero-photo { width: 110px; } }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-2deg); } }
.menu { width: 100%; display: flex; flex-direction: column; gap: 10px; }
.menu-row { display: flex; gap: 8px; }
.menu-row .btn { flex: 1; }
.title-foot { margin-top: 18px; display: flex; gap: 8px; justify-content: center; color: var(--muted); font-size: 14px; }

.btn { display: block; width: 100%; padding: 15px 18px; border: 3px solid var(--ink); border-radius: 16px; background: var(--paper);
  font-size: 18px; font-weight: 800; box-shadow: 0 4px 0 var(--ink); transition: transform .06s, box-shadow .06s; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn-primary { background: var(--gold); }
.btn-small { padding: 10px 8px; font-size: 15px; border-radius: 12px; }
.link { background: none; border: 0; padding: 8px; color: var(--muted); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; font-size: 14px; }
.muted { color: var(--muted); }

.panel { width: 100%; max-width: 480px; margin: 0 auto; }
.panel-center { margin: auto; text-align: center; display: flex; flex-direction: column; gap: 10px; align-items: stretch;
  background: var(--paper); border: 3px solid var(--ink); border-radius: 22px; padding: 22px 18px; box-shadow: 0 6px 0 var(--ink); max-width: 400px; }
.panel-center h2 { margin: 0; font-size: 30px; line-height: 1.1; }
.panel-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.panel-head h2 { margin: 0; font-size: 26px; }
.back { width: 44px; height: 44px; flex: none; border: 3px solid var(--ink); border-radius: 12px; background: var(--paper); font-size: 26px; line-height: 1; font-weight: 900; padding: 0 0 4px; }

/* ---------- Levels ---------- */
.levels { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.lvl { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 12px; border: 3px solid var(--ink);
  border-radius: 16px; background: var(--paper); box-shadow: 0 4px 0 var(--ink); }
.lvl:disabled { opacity: .5; box-shadow: none; cursor: default; }
.lvl-num { flex: none; width: 44px; height: 44px; border-radius: 12px; background: var(--gold); border: 3px solid var(--ink);
  display: grid; place-items: center; font-weight: 900; font-size: 20px; }
.lvl-body { flex: 1; min-width: 0; }
.lvl-name { display: block; font-weight: 800; font-size: 17px; }
.lvl-who { display: block; font-size: 13px; color: var(--muted); margin-top: 2px; }
.lvl-stars { flex: none; font-size: 15px; letter-spacing: 1px; }
.lvl-endless .lvl-num { background: var(--red); color: #fff; }

/* ---------- Intro ---------- */
.intro-cast { display: flex; justify-content: center; gap: 4px; min-height: 84px; }
.intro-cast img { height: 84px; width: auto; }
.intro-text { margin: 0; font-size: 16px; line-height: 1.45; }
.intro-tip { margin: 0; font-size: 14px; font-weight: 700; color: var(--red-deep); background: #FFE9E3; border-radius: 12px; padding: 8px 10px; }

/* ---------- Result ---------- */
.stars { font-size: 40px; letter-spacing: 4px; min-height: 48px; }
.stars .off { filter: grayscale(1); opacity: .3; }
.res-line { margin: 0; font-size: 16px; }
.res-score { margin: 0; display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; text-align: left; font-size: 15px;
  background: var(--cream); border-radius: 12px; padding: 10px 12px; }
.res-score dt { color: var(--muted); }
.res-score dd { margin: 0; font-weight: 800; text-align: right; }
.res-score .total { font-size: 18px; color: var(--ink); border-top: 2px dashed var(--line); padding-top: 6px; }
.submit { text-align: left; display: flex; flex-direction: column; gap: 6px; font-weight: 700; font-size: 14px; }
.submit-row { display: flex; gap: 8px; }
.submit-row input { flex: 1; min-width: 0; padding: 10px 12px; border: 3px solid var(--ink); border-radius: 12px; font-size: 16px; background: #fff; }
.submit-row .btn { width: auto; }
.submit-msg { margin: 0; font-size: 13px; color: var(--muted); min-height: 1em; }

/* ---------- How / cast / board ---------- */
.how { background: var(--paper); border: 3px solid var(--ink); border-radius: 18px; padding: 4px 16px 12px; line-height: 1.5; font-size: 16px; }
.how h3 { margin: 16px 0 4px; font-size: 18px; }
.how p { margin: 6px 0; }
.how-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.how-list li { display: flex; gap: 10px; }
.how-list span { font-size: 24px; line-height: 1.2; }
.cast { display: flex; flex-direction: column; gap: 12px; }
.cast-card { display: flex; gap: 12px; background: var(--paper); border: 3px solid var(--ink); border-radius: 18px; padding: 12px; }
.cast-art { flex: none; width: 84px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.cast-art img { width: 80px; height: auto; }
.cast-forms { display: flex; gap: 2px; }
.cast-forms img { width: 40px; }
.cast-body h3 { margin: 0; font-size: 19px; }
.cast-tag { display: inline-block; margin: 2px 0 4px; font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; padding: 2px 8px; border-radius: 99px; }
.tag-bad { background: #FFE0DA; color: var(--red-deep); }
.tag-good { background: #DDF3E6; color: #1E6B44; }
.tag-you { background: #FFF0C7; color: #7A5200; }
.cast-body p { margin: 4px 0 0; font-size: 15px; line-height: 1.45; }
.cast-body q { display: block; margin-top: 6px; font-style: italic; color: var(--muted); }
.board { list-style: none; margin: 0; padding: 0; background: var(--paper); border: 3px solid var(--ink); border-radius: 18px; overflow: hidden; }
.board li { display: flex; gap: 10px; padding: 12px 14px; border-bottom: 2px solid var(--line); font-size: 16px; }
.board li:last-child { border-bottom: 0; }
.board .rank { width: 28px; font-weight: 900; color: var(--muted); }
.board .who { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .pts { font-weight: 900; }
.board .me { background: #FFF0C7; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; display: none; z-index: 5; }
body[data-screen="game"] #hud, body[data-screen="pause"] #hud, body[data-screen="result"] #hud { display: block; }
.hud-top { position: absolute; top: calc(6px + var(--safe-t)); left: calc(8px + var(--safe-l)); right: calc(8px + var(--safe-r));
  display: flex; align-items: center; gap: 8px; background: var(--paper); border: 3px solid var(--ink); border-radius: 16px;
  padding: 3px 4px 3px 8px; box-shadow: 0 3px 0 var(--ink); }
.hud-hearts { font-size: 22px; letter-spacing: 1px; white-space: nowrap; min-width: 90px; }
.hud-hearts .lost { filter: grayscale(1); opacity: .35; }
.hud-hearts.ouch { animation: ouch .4s; }
@keyframes ouch { 30% { transform: scale(1.25) rotate(-6deg); } }
.hud-mid { flex: 1; text-align: center; min-width: 0; }
.hud-level { font-size: 13px; font-weight: 800; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-goal { font-size: 20px; font-weight: 900; }
.icon-btn { pointer-events: auto; width: 40px; height: 40px; border: 3px solid var(--ink); border-radius: 12px; background: var(--paper); font-size: 14px; font-weight: 900; }
.hud-fluffy { position: absolute; top: calc(64px + var(--safe-t)); left: calc(8px + var(--safe-l)); width: min(250px, 62vw);
  display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 900; background: var(--paper); border: 2.5px solid var(--ink);
  border-radius: 99px; padding: 4px 8px; }
.hud-fluffy[hidden] { display: none; }
.fm-label { white-space: nowrap; min-width: 112px; }
.fm-bar { position: relative; flex: 1; height: 12px; border: 2.5px solid var(--ink); border-radius: 99px; background: #fff; overflow: hidden; }
.fm-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, #F5C04A, #F07A3A 50%, #C8102E); transition: width .2s; }
.fm-tick { position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; background: var(--ink); opacity: .5; }
.hud-fluffy.volcano .fm-label { color: #D2401F; }
.hud-fluffy.devil .fm-label { color: var(--red-deep); animation: shake .25s infinite; }
@keyframes shake { 25% { transform: translateX(-1px); } 75% { transform: translateX(1px); } }
.hud-thought { position: absolute; left: calc(10px + var(--safe-l)); bottom: calc(108px + var(--safe-b)); width: min(340px, calc(100vw - 20px));
  background: var(--paper); border: 3px solid var(--ink); border-radius: 16px; padding: 8px 12px; font-size: 14px; font-weight: 700;
  text-align: center; box-shadow: 0 3px 0 var(--ink); animation: pop .25s; }
.hud-thought[hidden] { display: none; }
@keyframes pop { from { transform: scale(.8); opacity: 0; } }
.hud-abilities { position: absolute; right: calc(12px + var(--safe-r)); bottom: calc(14px + var(--safe-b)); display: flex; align-items: flex-end; gap: 10px; }
.ab { pointer-events: auto; position: relative; width: 64px; height: 64px; border-radius: 50%; border: 3px solid var(--ink); background: var(--paper);
  display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 0; box-shadow: 0 3px 0 var(--ink); touch-action: none; }
.ab-big { width: 82px; height: 82px; background: var(--gold); }
.ab-ico { font-size: 26px; line-height: 1; }
.ab-big .ab-ico { font-size: 32px; }
.ab-name { font-size: 11px; font-weight: 900; margin-top: 2px; white-space: nowrap; }
.ab-key { display: none; position: absolute; top: -8px; right: -6px; font-size: 10px; font-weight: 900; background: var(--ink); color: #fff; border-radius: 6px; padding: 1px 5px; }
@media (hover: hover) and (pointer: fine) { .ab-key { display: block; } }
.ab::after { content: ""; position: absolute; inset: -3px; border-radius: 50%; background: conic-gradient(rgba(29,26,31,.55) calc(var(--cd, 0) * 1turn), transparent 0); pointer-events: none; }
.ab.ready { animation: ready .3s; }
@keyframes ready { 50% { transform: scale(1.12); } }
.ab:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }

body.night { background: #1A1620; }
.intro-emoji { font-size: 64px; line-height: 84px; }
.cast-emoji { font-size: 60px; line-height: 1; }
.tag-mixed { background: #FFF0C7; color: #7A5200; }

.btn-day { background: #9FD0F0; }
.btn-sub { font-size: 13px; font-weight: 700; opacity: .75; margin-left: 4px; }
.btn-extras { text-align: center; text-decoration: none; color: var(--ink); background: #FFE7A8; }
