:root {
  color-scheme: dark;
  --text: #f6f1e6;
  --muted: #9aa6b0;
  --amber: #ffd479;
  --mint: #8fe0c8;
  --panel: rgba(14, 18, 28, 0.55);
  --line: rgba(255, 255, 255, 0.10);
  font-family: "Inter Tight", Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; width: 100%; height: 100%;
  overflow: hidden; background: #05070d; color: var(--text);
  -webkit-font-smoothing: antialiased;
}
#stage { position: fixed; inset: 0; }
canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: pointer; }

/* ---- Splash ---- */
.splash {
  position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; cursor: pointer;
  background:
    radial-gradient(circle at 50% 38%, rgba(255,224,150,0.16), transparent 38%),
    radial-gradient(circle at 72% 72%, rgba(143,224,200,0.10), transparent 42%),
    linear-gradient(160deg, #070a12 0%, #0c1019 52%, #140f17 100%);
  transition: opacity .6s ease;
}
.splash.gone { opacity: 0; pointer-events: none; }
.splash::after { content:""; position:absolute; inset:0; pointer-events:none;
  background: radial-gradient(circle at 50% 46%, transparent 42%, rgba(2,4,9,0.62) 100%); }
.splash-firefly { position:absolute; top:35%; left:50%; width:40px; height:26px;
  transform: translate(-50%,-50%); animation: sf-fly 3600ms cubic-bezier(.22,.74,.22,1) both; }
.sf-glow { position:absolute; left:50%; top:50%; width:170px; height:170px; transform:translate(-50%,-50%);
  border-radius:50%; background: radial-gradient(circle, rgba(255,244,191,.6), rgba(255,212,121,.22) 32%, transparent 68%);
  animation: sf-breathe 2200ms ease-in-out infinite; }
.sf-body { position:absolute; left:11px; top:8px; width:20px; height:11px; border-radius:999px;
  background: linear-gradient(90deg,#ffe96c 0 26%,#5a7a68 46%,#1e2a2a 100%); box-shadow:0 0 24px rgba(255,233,108,.85); }
.sf-wing { position:absolute; left:16px; width:15px; height:13px; border-radius:80% 20% 80% 20%;
  background: rgba(214,250,242,.5); border:1px solid rgba(255,255,255,.28); transform-origin:14% 80%; }
.sf-wl { top:1px; animation: sf-flutter-l 220ms ease-in-out infinite alternate; }
.sf-wr { top:12px; animation: sf-flutter-r 220ms ease-in-out 60ms infinite alternate; }
.splash-title { position:relative; text-align:center; opacity:0; transform:translateY(60px);
  animation: sf-title 2400ms ease 700ms forwards; text-shadow:0 2px 40px rgba(0,0,0,.6); }
.splash-title p { margin:0; color:var(--amber); font-size:.72rem; font-weight:760; letter-spacing:.24em; text-transform:uppercase; }
.splash-title h2 { margin:10px 0 6px; font-size:clamp(3rem,11vw,6rem); font-weight:820; letter-spacing:-.02em; line-height:.92; }
.splash-title span { display:block; color:var(--muted); font-size:1rem; font-style:italic; }
@keyframes sf-fly {
  0% { transform: translate(calc(-50% - 44vw), calc(-50% - 16vh)) scale(.4); opacity:0; }
  12% { opacity:1; }
  45% { transform: translate(calc(-50% + 22vw), calc(-50% - 4vh)) scale(.78); }
  72% { transform: translate(calc(-50% - 8vw), calc(-50% + 3vh)) scale(.92); }
  100% { transform: translate(-50%,-50%) scale(1); opacity:1; }
}
@keyframes sf-breathe { 0%,100%{transform:translate(-50%,-50%) scale(.92);opacity:.85;} 50%{transform:translate(-50%,-50%) scale(1.06);opacity:1;} }
@keyframes sf-flutter-l { from{transform:rotate(-44deg) scaleX(.85);} to{transform:rotate(-18deg) scaleX(1.05);} }
@keyframes sf-flutter-r { from{transform:rotate(44deg) scaleY(-1) scaleX(.85);} to{transform:rotate(18deg) scaleY(-1) scaleX(1.05);} }
@keyframes sf-title { to{opacity:1;transform:translateY(0);} }
@media (prefers-reduced-motion: reduce){ .splash-firefly,.splash-title,.sf-glow,.sf-wing{animation-duration:1ms;animation-iteration-count:1;} }

/* ---- HUD ---- */
.hud {
  position: absolute; z-index: 5; top: 16px; left: 16px; right: 16px;
  display: flex; gap: 12px; align-items: flex-start; justify-content: space-between;
  pointer-events: none;
}
.panel {
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(20px) saturate(1.1);
  -webkit-backdrop-filter: blur(20px) saturate(1.1);
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.06);
}
.brand { display: flex; gap: 12px; align-items: center; padding: 11px 15px 11px 12px; pointer-events: auto; }
.brand .mark {
  width: 38px; height: 38px; flex: 0 0 auto; border-radius: 50%;
  background:
    radial-gradient(circle at 38% 36%, #fff5cf 0 16%, transparent 18%),
    radial-gradient(circle at 62% 64%, rgba(143,224,200,0.9) 0 22%, transparent 24%),
    conic-gradient(from 210deg, #ffd479, #ff9d7a, #8fe0c8, #8fb6ff, #ffd479);
  box-shadow: 0 0 26px rgba(255,212,121,0.45);
}
.brand h1 { margin: 0; font-size: 1.02rem; font-weight: 760; letter-spacing: -0.01em; }
.brand p { margin: 3px 0 0; font-size: 0.74rem; color: var(--muted); }
.meters { display: flex; gap: 4px; padding: 7px; pointer-events: auto; }
.meters .m {
  min-width: 70px; text-align: center; padding: 7px 10px; border-radius: 9px;
  background: rgba(255,255,255,0.05);
}
.meters .m b { display: block; font-size: 0.98rem; font-weight: 760; line-height: 1.05; }
.meters .m span { font-size: 0.6rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.actions { display: flex; gap: 6px; padding: 7px; pointer-events: auto; }
.btn {
  width: 40px; height: 40px; display: grid; place-items: center; border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.14); background: rgba(255,255,255,0.06);
  color: var(--text); cursor: pointer; font-size: 1.05rem; line-height: 1;
  transition: transform .15s ease, background .15s ease, border-color .15s ease;
}
.btn:hover { transform: translateY(-1px); background: rgba(255,255,255,0.13); border-color: rgba(255,255,255,0.3); }
.btn:active { transform: translateY(0); }
.btn.on { border-color: rgba(143,224,200,0.7); background: rgba(143,224,200,0.18); color: #d6fff2; }
/* hint: the flashlight gently shakes + glows when the player seems lost */
.btn.hint { animation: hintShake 820ms ease-in-out infinite; border-color: rgba(255,212,121,0.9); background: rgba(255,212,121,0.18); color: #ffe9b8; }
@keyframes hintShake {
  0%,100% { transform: translateX(0) rotate(0); box-shadow: 0 0 0 0 rgba(255,212,121,0.5); }
  15% { transform: translateX(-2px) rotate(-6deg); }
  30% { transform: translateX(2px) rotate(6deg); box-shadow: 0 0 0 9px rgba(255,212,121,0.07); }
  45% { transform: translateX(-2px) rotate(-4deg); }
  60% { transform: translateX(1px) rotate(3deg); box-shadow: 0 0 0 0 rgba(255,212,121,0); }
}
/* steady soft glow while the onboarding toast points at the lantern */
.btn.onboard { border-color: rgba(255,212,121,0.8); animation: onboardGlow 1900ms ease-in-out infinite; }
@keyframes onboardGlow { 0%,100%{ box-shadow:0 0 0 0 rgba(255,212,121,0); } 50%{ box-shadow:0 0 0 7px rgba(255,212,121,0.12); } }

/* ---- onboarding toast (points at the flashlight) ---- */
.toast {
  position: absolute; z-index: 8; top: 82px; right: 16px; width: min(296px, calc(100vw - 32px));
  display: grid; grid-template-columns: 34px 1fr; gap: 11px; align-items: center;
  padding: 12px 40px 12px 14px; border-radius: 13px;
  border: 1px solid rgba(255,212,121,0.34); background: rgba(20,16,24,0.88);
  box-shadow: 0 0 0 1px rgba(255,212,121,0.06), 0 16px 42px rgba(0,0,0,0.42);
  backdrop-filter: blur(18px); cursor: pointer; animation: toastIn 440ms ease both;
}
.toast[hidden] { display: none !important; }
.toast.gone { animation: toastOut 300ms ease forwards; }
.toast::before {
  content: ""; position: absolute; top: -7px; left: var(--caret, 50%); width: 12px; height: 12px;
  background: rgba(20,16,24,0.88);
  border-left: 1px solid rgba(255,212,121,0.34); border-top: 1px solid rgba(255,212,121,0.34);
  transform: translateX(-50%) rotate(45deg);
}
.toast svg { width: 26px; height: 26px; justify-self: center; fill: none; stroke: #ffd479; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.toast strong { display: block; color: #ffe9b8; font-size: 0.74rem; font-weight: 760; }
.toast em { display: block; margin-top: 2px; color: var(--muted); font-size: 0.78rem; font-style: normal; line-height: 1.3; }
.toast-close {
  position: absolute; top: 8px; right: 8px; width: 24px; height: 24px;
  display: grid; place-items: center; border: 0; border-radius: 50%;
  background: rgba(255,255,255,0.06); color: rgba(255,255,255,0.82);
  cursor: pointer; font-size: 1.05rem; line-height: 1;
}
.toast-close:hover { background: rgba(255,255,255,0.14); color: var(--text); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-8px) scale(0.98); } }
.btn .ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* charge ring on pulse button */
.btn.charge { position: relative; }
.btn.charge::after {
  content: ""; position: absolute; inset: -3px; border-radius: 12px;
  background: conic-gradient(var(--amber) calc(var(--charge,0) * 360deg), rgba(255,255,255,0.08) 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 2.5px), #000 calc(100% - 2px));
          mask: radial-gradient(farthest-side, transparent calc(100% - 2.5px), #000 calc(100% - 2px));
  opacity: .9; pointer-events: none;
}

/* ---- Level title card ---- */
.card {
  position: absolute; z-index: 6; left: 50%; top: 50%; transform: translate(-50%,-50%);
  text-align: center; pointer-events: none; opacity: 0;
  text-shadow: 0 2px 30px rgba(0,0,0,0.6);
}
.card .ch { font-size: 0.72rem; letter-spacing: 0.42em; text-transform: uppercase; color: var(--amber); }
.card h2 { margin: 10px 0 6px; font-size: clamp(2.6rem, 8vw, 5.4rem); font-weight: 820; letter-spacing: -0.02em; line-height: 0.95; }
.card p { margin: 0; color: var(--muted); font-size: 0.96rem; font-style: italic; }
.card.show { animation: cardIn 3200ms ease forwards; }
@keyframes cardIn {
  0% { opacity: 0; transform: translate(-50%,-46%); letter-spacing: 0; }
  18%,68% { opacity: 1; transform: translate(-50%,-50%); }
  100% { opacity: 0; transform: translate(-50%,-54%); }
}

/* ---- Finish panel ---- */
.finish {
  position: absolute; z-index: 7; left: 50%; bottom: 34px; transform: translateX(-50%) translateY(20px);
  width: min(440px, calc(100vw - 32px)); padding: 18px 20px; border-radius: 16px;
  display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: center;
  background: rgba(12,16,24,0.82); opacity: 0; pointer-events: none;
  transition: opacity .4s ease, transform .4s ease;
}
.finish.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
.finish .k { font-size: 0.68rem; letter-spacing: 0.22em; text-transform: uppercase; color: var(--amber); }
.finish h3 { margin: 5px 0 6px; font-size: 1.2rem; font-weight: 780; }
.finish .s { margin: 0; color: var(--muted); font-size: 0.84rem; line-height: 1.35; }
.primary {
  min-height: 46px; padding: 0 20px; border-radius: 12px; cursor: pointer; font-weight: 740; font-size: 0.92rem;
  color: #1a1206; border: 1px solid rgba(255,212,121,0.5);
  background: linear-gradient(180deg, #ffe49a, #f4ad5a); box-shadow: 0 10px 30px rgba(244,173,90,0.35);
  transition: transform .15s ease, filter .15s ease;
}
.primary:hover { transform: translateY(-1px); filter: brightness(1.05); }

/* ---- touch pad ---- */
.pad { position: absolute; z-index: 5; right: 18px; bottom: 18px; display: grid;
       grid-template-columns: repeat(3, 46px); grid-template-rows: repeat(3, 46px); gap: 5px; }
.pad .btn { width: 46px; height: 46px; background: rgba(12,16,24,0.6); backdrop-filter: blur(12px); }
.pad .u { grid-area: 1/2; } .pad .l { grid-area: 2/1; } .pad .r { grid-area: 2/3; } .pad .d { grid-area: 3/2; }
@media (pointer:fine) and (min-width:900px){ .pad { opacity:.32; transition:opacity .2s; } .pad:hover{opacity:1;} }

@media (max-width: 640px){
  .hud { flex-wrap: wrap; }
  .meters { order: 3; width: 100%; justify-content: space-between; }
  .meters .m { flex: 1; min-width: 0; }
  .toast { top: 166px; }
  .toast::before { display: none; }
}
