/* Spooky Boo! — overlay UI. Mobile-portrait first, scales up to widescreen. */

/* Fredoka (SIL OFL, see assets/fonts/OFL.txt), self-hosted so no visitor data goes to a font CDN.
   It's a variable font: one file covers every weight we use. */
@font-face {
  font-family: 'Fredoka';
  font-weight: 300 700;
  font-display: swap;
  src: url(../assets/fonts/fredoka-latin.woff2?v=1e7701b1a9) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Fredoka';
  font-weight: 300 700;
  font-display: swap;
  src: url(../assets/fonts/fredoka-latin-ext.woff2?v=1e7701b1a9) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
:root {
  --ink: #f7f1ff;
  --ink-dim: #c9bde6;
  --night: #1a1030;
  --panel: rgba(30, 18, 54, 0.78);
  --panel-edge: rgba(190, 160, 255, 0.35);
  --purple: #9b6bff;
  --lav: #c9b3ff;
  --pumpkin: #ff9a3c;
  --mint: #6effb5;
  --pink: #ff7eb6;
  --danger: #ff5a6e;
  --gold: #ffd35a;
  --radius: 16px;
  --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);
  --btn: clamp(74px, 22vw, 104px);
  font-family: "Fredoka", ui-rounded, "SF Pro Rounded", "Nunito", system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--night); color: var(--ink); overscroll-behavior: none; }
body { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none; }
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#world-ui { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }

/* ---------- screens ---------- */
.screen {
  position: fixed; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  padding: calc(20px + var(--safe-t)) calc(16px + var(--safe-r)) calc(20px + var(--safe-b)) calc(16px + var(--safe-l));
  text-align: center; z-index: 20;
}
.screen.show { display: flex; animation: fade-in .35s ease both; }
.screen.dim { background: rgba(14, 8, 28, 0.62); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.screen.scroll { overflow-y: auto; justify-content: flex-start; }
#screen-loading, #screen-error { background: radial-gradient(ellipse at 50% 35%, #3a2266 0%, var(--night) 70%); }
#screen-title { background: linear-gradient(to bottom, rgba(26,16,48,.15) 0%, rgba(26,16,48,0) 40%, rgba(26,16,48,.65) 100%); }
#screen-levels { background: rgba(20, 12, 40, 0.55); justify-content: flex-start; overflow-y: auto; padding-top: calc(28px + var(--safe-t)); }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.logo { display: flex; flex-direction: column; align-items: center; }
.logo h1 { margin: 0; font-size: clamp(44px, 13vw, 92px); line-height: .95; letter-spacing: 1px; font-weight: 700;
  text-shadow: 0 4px 0 #4b2a86, 0 10px 30px rgba(155, 107, 255, .7); }
.logo h1 em { font-style: normal; color: var(--pumpkin); }
.logo .tagline { margin: 8px 0 0; color: var(--ink-dim); font-size: clamp(15px, 4vw, 20px); }
.logo-ghost { font-size: clamp(56px, 16vw, 110px); animation: bob 2.4s ease-in-out infinite; filter: drop-shadow(0 8px 18px rgba(200, 170, 255, .6)); }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-12px) rotate(4deg); } }

.menu { display: flex; flex-direction: column; gap: 12px; align-items: stretch; width: min(320px, 80vw); }
.card .menu { margin: 0 auto; }
.menu.row { flex-direction: row; flex-wrap: wrap; justify-content: center; width: auto; }
.btn {
  border: 0; border-radius: 999px; padding: 14px 26px; font-size: 20px; font-weight: 600; letter-spacing: .3px;
  background: linear-gradient(#5b3a9c, #43277a); box-shadow: 0 4px 0 #2a1650, 0 8px 18px rgba(0,0,0,.35); transition: transform .08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #2a1650; }
.btn.primary { background: linear-gradient(#ffb25c, #ff8a2a); color: #3a1a00; box-shadow: 0 4px 0 #b95a10, 0 8px 22px rgba(255, 140, 50, .45); }
.btn.small { font-size: 16px; padding: 10px 18px; }
.btn:focus-visible { outline: 3px solid var(--mint); outline-offset: 3px; }
.footnote { color: var(--ink-dim); font-size: 13px; opacity: .8; margin: 0; }

.card {
  background: var(--panel); border: 2px solid var(--panel-edge); border-radius: 22px; padding: 22px 22px 20px;
  width: min(560px, 92vw); box-shadow: 0 20px 60px rgba(0,0,0,.45);
}
.card h2, .screen > h2 { margin: 0 0 12px; font-size: clamp(24px, 6vw, 34px); }
.howto ul { text-align: left; padding-left: 4px; list-style: none; margin: 0 0 16px; display: grid; gap: 10px; font-size: clamp(15px, 3.9vw, 18px); line-height: 1.35; }

.meter { position: relative; height: 10px; border-radius: 999px; background: rgba(0,0,0,.4); overflow: hidden; }
.meter > div { position: absolute; inset: 0 auto 0 0; width: 0%; border-radius: inherit; background: linear-gradient(90deg, var(--purple), var(--pink)); transition: width .15s linear; }
.load-meter { width: min(320px, 70vw); height: 14px; }
#load-fill { background: linear-gradient(90deg, var(--pumpkin), var(--gold)); }

/* level cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; width: min(960px, 94vw); }
.level-card { text-align: left; border: 2px solid var(--panel-edge); border-radius: 20px; padding: 16px; background: var(--panel); position: relative; overflow: hidden; }
.level-card h3 { margin: 0; font-size: 24px; }
.level-card .sub { color: var(--pumpkin); font-weight: 600; margin: 2px 0 8px; }
.level-card p { margin: 0 0 10px; color: var(--ink-dim); font-size: 15px; line-height: 1.3; }
.level-card .stars { color: rgba(255,255,255,.2); font-size: 26px; letter-spacing: 3px; }
.level-card .stars .on { color: var(--gold); text-shadow: 0 0 10px rgba(255, 211, 90, .6); }
.level-card .meta { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.level-card.locked { opacity: .55; }
.level-card.locked::after { content: "🔒 Earn a ★ in the previous house"; position: absolute; inset: auto 0 0 0; padding: 8px; background: rgba(0,0,0,.55); font-size: 14px; text-align: center; }
.level-card .house-emoji { position: absolute; right: 12px; top: 10px; font-size: 38px; opacity: .9; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
.hud-top { position: absolute; left: 0; right: 0; top: 0; display: flex; gap: 8px; align-items: stretch; padding: calc(8px + var(--safe-t)) calc(8px + var(--safe-r)) 0 calc(8px + var(--safe-l)); }
.panel { background: var(--panel); border: 1.5px solid var(--panel-edge); border-radius: 14px; padding: 6px 10px; backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.score-panel { flex: 1 1 auto; min-width: 0; }
.score-line { display: flex; align-items: baseline; gap: 6px; font-weight: 700; font-size: clamp(18px, 5vw, 24px); line-height: 1.1; }
.score-line .goal { font-size: .7em; color: var(--ink-dim); font-weight: 600; }
.combo { margin-left: auto; color: var(--mint); font-size: .8em; animation: pop .3s ease; }
.score-meter { margin-top: 5px; height: 9px; overflow: visible; }
.score-meter > div { background: linear-gradient(90deg, var(--pumpkin), var(--gold)); }
.star { position: absolute; top: 50%; transform: translate(-50%, -52%); font-style: normal; font-size: 15px; color: rgba(255,255,255,.35); text-shadow: 0 1px 2px #000; transition: color .3s; }
.star.on { color: var(--gold); text-shadow: 0 0 8px rgba(255, 211, 90, .9); }
.star.s1 { left: 50%; } .star.s2 { left: 75%; } .star.s3 { left: calc(100% - 7px); }
.clock-panel { display: flex; flex-direction: column; justify-content: center; align-items: center; min-width: 88px; font-weight: 600; font-size: 15px; }
.clock-panel .moon { display: none; }
.clock-panel .meter { width: 100%; height: 5px; margin-top: 4px; }
#night-fill { background: linear-gradient(90deg, #6f8bff, var(--gold)); }
.hearts { display: flex; align-items: center; gap: 2px; font-size: 20px; padding: 6px 8px; }
.hearts .lost { opacity: .22; filter: grayscale(1); }
.icon-btn { pointer-events: auto; font-size: 16px; font-weight: 700; min-width: 44px; }

.phase-bar { position: absolute; left: 50%; transform: translateX(-50%); top: calc(74px + var(--safe-t)); width: min(420px, 86vw);
  background: var(--panel); border: 1.5px solid var(--panel-edge); border-radius: 14px; padding: 6px 12px 8px; text-align: center; }
.phase-label { font-weight: 700; font-size: 15px; margin-bottom: 4px; }
.phase-bar.boss { border-color: rgba(255, 90, 110, .6); }
.phase-bar.boss #phase-fill { background: linear-gradient(90deg, #ff5a6e, #ffb25c); }
.phase-bar.busters #phase-fill { background: linear-gradient(90deg, #6fd3ff, #b9f3ff); }
.detect { position: absolute; left: 50%; transform: translateX(-50%); top: calc(128px + var(--safe-t)); display: flex; align-items: center; gap: 6px; font-size: 22px;
  background: rgba(60, 10, 20, .7); border-radius: 999px; padding: 4px 12px; }
.detect .meter { width: 120px; }
#detect-fill { background: linear-gradient(90deg, #ffb25c, var(--danger)); }

.controls { position: absolute; right: calc(14px + var(--safe-r)); bottom: calc(16px + var(--safe-b)); display: flex; flex-direction: column-reverse; gap: 14px; align-items: flex-end; }
.round-btn {
  pointer-events: auto; position: relative; width: var(--btn); height: var(--btn); border-radius: 50%; border: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-weight: 700; box-shadow: 0 5px 0 rgba(0,0,0,.35), 0 10px 24px rgba(0,0,0,.35); touch-action: none; transition: transform .06s, filter .2s, opacity .2s;
}
.round-btn:active, .round-btn.pressed { transform: translateY(3px) scale(.97); }
.round-btn .btn-icon { font-size: calc(var(--btn) * .34); line-height: 1; }
.round-btn .btn-text { font-size: calc(var(--btn) * .17); margin-top: 2px; white-space: nowrap; max-width: 92%; overflow: hidden; text-overflow: ellipsis; }
.round-btn.boo { background: radial-gradient(circle at 35% 30%, #fff 0%, #e6dcff 35%, #b597ff 100%); color: #3b1f73; }
.round-btn.action { background: radial-gradient(circle at 35% 30%, #fff3d6 0%, #ffc070 40%, #ff8a2a 100%); color: #4a1f00; width: calc(var(--btn) * .86); height: calc(var(--btn) * .86); }
.round-btn:disabled { filter: grayscale(.9) brightness(.6); opacity: .7; }
.round-btn.cooling { filter: brightness(.75); }
.round-btn svg.cd { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); pointer-events: none; }
.round-btn svg.cd circle { fill: none; stroke: rgba(40, 20, 80, .55); stroke-width: 7; stroke-dasharray: 0 999; }

.keys-hint { position: absolute; left: 50%; bottom: calc(10px + var(--safe-b)); transform: translateX(-50%); color: var(--ink-dim); font-size: 13px; opacity: .8; white-space: nowrap;
  background: rgba(20, 12, 40, .55); padding: 4px 10px; border-radius: 999px; }
.touch .keys-hint { display: none; }

.stick { position: absolute; width: 130px; height: 130px; margin: -65px 0 0 -65px; border-radius: 50%; background: rgba(200, 180, 255, .12); border: 2px solid rgba(200, 180, 255, .35); }
.stick .knob { position: absolute; left: 50%; top: 50%; width: 58px; height: 58px; margin: -29px 0 0 -29px; border-radius: 50%; background: rgba(230, 220, 255, .55); box-shadow: 0 4px 12px rgba(0,0,0,.3); }

.action-tag { position: absolute; transform: translate(-50%, -100%); padding: 4px 10px; border-radius: 999px; background: rgba(20, 12, 40, .82); border: 1.5px solid var(--panel-edge);
  font-size: 14px; white-space: nowrap; display: flex; gap: 6px; align-items: center; transition: opacity .15s; }
.action-tag b { font-weight: 600; }
.action-tag span { font-size: 12px; font-weight: 700; padding: 1px 7px; border-radius: 999px; }
.fresh-hi { background: var(--mint); color: #083; }
.fresh-mid { background: var(--gold); color: #5a3a00; }
.fresh-lo { background: #ff8a5c; color: #4a1000; }
.fresh-cd { background: rgba(255,255,255,.18); color: var(--ink); }

.hint { position: absolute; left: calc(12px + var(--safe-l)); bottom: calc(16px + var(--safe-b)); width: min(440px, calc(100vw - var(--btn) - 52px));
  display: flex; gap: 10px; align-items: center; background: rgba(35, 20, 66, .92); border: 2px solid var(--lav); border-radius: 16px; padding: 10px 12px;
  font-size: clamp(13px, 3.6vw, 16px); line-height: 1.3; animation: slide-up .3s ease; }
.hint-ghost { font-size: 26px; }
@keyframes slide-up { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

.banner { position: absolute; left: 50%; top: 38%; transform: translate(-50%, -50%); text-align: center; white-space: pre-line;
  font-size: clamp(22px, 6.5vw, 40px); font-weight: 700; line-height: 1.15; text-shadow: 0 3px 0 #2b1650, 0 6px 24px rgba(0,0,0,.6); animation: banner-in .45s cubic-bezier(.2, 1.6, .4, 1); width: 94vw; }
.banner.intro { color: var(--ink); }
.banner.warn { color: #b9f3ff; }
.banner.danger, .banner.boss { color: #ffb0bb; }
.banner.good, .banner.goal { color: var(--gold); }
.banner small { display: block; font-size: .55em; font-weight: 600; color: var(--ink-dim); }
@keyframes banner-in { from { opacity: 0; transform: translate(-50%, -50%) scale(.6); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }
@keyframes pop { from { transform: scale(1.5); } to { transform: scale(1); } }

/* ---------- world-anchored UI ---------- */
.tag { position: absolute; transform: translate(-50%, -100%); display: flex; flex-direction: column; align-items: center; gap: 2px; transition: opacity .2s; }
.tag .name { font-size: 11px; font-weight: 600; color: var(--ink); background: rgba(20, 12, 40, .6); padding: 0 6px; border-radius: 6px; white-space: nowrap; }
.tag .bars { display: flex; flex-direction: column; gap: 2px; width: 52px; }
.tag .bar { height: 5px; border-radius: 3px; background: rgba(0,0,0,.45); overflow: hidden; }
.tag .bar > i { display: block; height: 100%; width: 0%; }
.tag .fear > i { background: linear-gradient(90deg, #b597ff, var(--pink)); }
.tag .stress > i { background: linear-gradient(90deg, #ffb25c, var(--danger)); }
.tag .icon { font-size: 18px; line-height: 1; height: 18px; }
.tag.warn .stress { box-shadow: 0 0 0 1.5px var(--danger); animation: blink .6s infinite alternate; }
@keyframes blink { to { box-shadow: 0 0 0 1.5px transparent; } }

.bubble { position: absolute; transform: translate(-50%, -100%); max-width: 180px; padding: 6px 10px; border-radius: 14px; background: #fff; color: #2a1a40;
  font-size: 13px; font-weight: 600; line-height: 1.2; text-align: center; box-shadow: 0 4px 12px rgba(0,0,0,.35); animation: bubble-in .25s cubic-bezier(.2, 1.6, .4, 1); }
.bubble::after { content: ""; position: absolute; left: 50%; bottom: -6px; margin-left: -6px; border: 6px solid transparent; border-bottom: 0; border-top-color: #fff; }
.bubble.foe { background: #ffe9c2; }
@keyframes bubble-in { from { opacity: 0; transform: translate(-50%, -80%) scale(.6); } to { opacity: 1; transform: translate(-50%, -100%) scale(1); } }

.popup { position: absolute; transform: translate(-50%, -50%); font-weight: 700; font-size: 18px; white-space: nowrap; text-shadow: 0 2px 0 rgba(0,0,0,.6), 0 0 12px rgba(0,0,0,.5);
  animation: popup-rise 1.4s ease-out forwards; }
.popup.good { color: var(--mint); }
.popup.stale { color: #ffbf7a; }
.popup.meh { color: var(--ink-dim); font-size: 15px; }
.popup.big { color: var(--gold); font-size: 24px; }
.popup.bad { color: var(--danger); font-size: 22px; }
.popup.hit { color: #ffd35a; font-size: 26px; }
.popup.info { color: var(--lav); font-size: 15px; }
@keyframes popup-rise { 0% { opacity: 0; transform: translate(-50%, -30%) scale(.7); } 12% { opacity: 1; transform: translate(-50%, -60%) scale(1.1); } 100% { opacity: 0; transform: translate(-50%, -260%) scale(1); } }
.alert-mark { position: absolute; transform: translate(-50%, -100%); font-size: 26px; font-weight: 700; color: var(--danger); text-shadow: 0 2px 0 #000; animation: blink2 .3s infinite alternate; }
@keyframes blink2 { to { opacity: .4; } }

/* results */
.result-stars { font-size: 52px; letter-spacing: 8px; color: rgba(255,255,255,.18); }
.result-stars i { font-style: normal; display: inline-block; }
.result-stars i.on { color: var(--gold); text-shadow: 0 0 18px rgba(255, 211, 90, .8); animation: star-pop .5s cubic-bezier(.2, 1.8, .4, 1) both; }
@keyframes star-pop { from { transform: scale(0) rotate(-90deg); } to { transform: scale(1) rotate(0); } }
.result-score { font-size: 26px; font-weight: 700; margin: 4px 0; }
.result-reason { color: var(--ink-dim); margin: 0 0 10px; }
.stats { list-style: none; padding: 0; margin: 0 0 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; text-align: left; font-size: 15px; }
.stats b { color: var(--gold); }

/* ---------- wider screens ---------- */
@media (min-width: 900px) and (min-aspect-ratio: 1/1) {
  .hud-top { gap: 12px; padding: 12px 16px 0; }
  .score-panel { flex: 0 1 420px; }
  .clock-panel { min-width: 120px; flex-direction: row; gap: 8px; flex-wrap: wrap; }
  .clock-panel .moon { display: inline; }
  .hearts { margin-left: auto; font-size: 24px; }
  .phase-bar { top: 16px; }
  .detect { top: 84px; }
  .tag .name { font-size: 12px; }
  .tag .bars { width: 64px; }
  .bubble { font-size: 14px; max-width: 220px; }
  :root { --btn: 96px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  :root { --btn: 72px; }
  .controls { flex-direction: row-reverse; align-items: flex-end; }
  .banner { top: 45%; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
body:not(.touch) .hint { bottom: calc(46px + var(--safe-b)); }
