:root {
  --ink: #0b0614;
  --night: #170b29;
  --plum: #2a1347;
  --orange: #ff8a1f;
  --orange2: #ffb347;
  --gold: #ffe27a;
  --green: #7dff6a;
  --purple: #b377ff;
  --red: #ff4d5e;
  --paper: #f6e7c1;
  --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);
  --display: Creepster, "Chalkduster", "Comic Sans MS", Impact, fantasy;
  --body: Nunito, "Trebuchet MS", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  overflow: hidden; background: #05030a; color: #fff;
  font-family: var(--body);
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
  touch-action: none;
}

#app { position: fixed; inset: 0; overflow: hidden; }
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; background: #05030a; }
#touch { position: absolute; inset: 0; touch-action: none; }

button, input, textarea, .layer, .panel { font-family: var(--body); touch-action: manipulation; }
input, textarea { touch-action: auto; }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; transition: opacity .3s; }
#hud.off { opacity: 0; visibility: hidden; }
#hud button { pointer-events: auto; }

#hud-top {
  position: absolute; left: 0; right: 0; top: 0;
  padding: calc(8px + var(--safe-t)) calc(10px + var(--safe-r)) 0 calc(10px + var(--safe-l));
  display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;
}
#hud-left { max-width: 46%; text-shadow: 0 2px 6px #000, 0 0 3px #000; }
#hud-title { font-family: var(--display); font-size: 1.25rem; color: var(--orange2); letter-spacing: .04em; line-height: 1; }
#hud-obj { font-size: .82rem; font-weight: 800; margin-top: 3px; color: #fff; line-height: 1.2; }
#hud-mid { text-align: center; text-shadow: 0 2px 6px #000; }
#hud-timer { font-family: var(--display); font-size: 1.7rem; color: var(--gold); line-height: 1; }
#hud-timer.warn { color: var(--red); animation: pulse .6s infinite alternate; }
#hud-hearts { font-size: 1.15rem; letter-spacing: 2px; margin-top: 2px; }
#hud-right { display: flex; align-items: center; gap: 8px; }
#party {
  position: absolute; left: calc(8px + var(--safe-l)); right: calc(8px + var(--safe-r));
  top: calc(50px + var(--safe-t)); display: none; gap: 6px; flex-wrap: wrap; justify-content: flex-start;
  pointer-events: none; z-index: 4;
}
#party.on { display: flex; }
#party i {
  display: flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 999px;
  background: rgba(10, 6, 20, .72); border: 2px solid var(--c, #ffb347); color: #fff;
  font-size: .72rem; font-weight: 900; font-style: normal;
}
#party i.me { box-shadow: 0 0 10px var(--c); }
#party i.away { opacity: .45; }
#party i b { font-size: .72rem; }

.code-big {
  font-family: var(--display); font-size: 3.2rem; letter-spacing: .28em; color: var(--gold);
  text-shadow: 0 3px 0 #5a2200, 0 0 18px rgba(255, 180, 60, .6); margin: 4px 0 8px; padding-left: .28em;
}
input.join-code {
  width: 100%; height: 64px; border-radius: 16px; border: 3px solid var(--orange2);
  background: #120922; color: var(--gold); font-size: 2rem; font-weight: 900; letter-spacing: .35em;
  text-align: center; text-transform: uppercase; font-family: var(--body); margin: 8px 0;
}

#hud-candy {
  background: rgba(10, 5, 20, .55); border: 2px solid rgba(255, 179, 71, .6); border-radius: 999px;
  padding: 5px 11px; font-weight: 900; font-size: .95rem; color: var(--gold);
}
#btn-pause {
  width: 44px; height: 44px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .5);
  background: rgba(10, 5, 20, .6); color: #fff; font-weight: 900; font-size: 1rem; letter-spacing: -2px;
}

#minimap {
  position: absolute; left: calc(10px + var(--safe-l)); top: calc(86px + var(--safe-t));
  width: 96px; height: 96px; border-radius: 12px; border: 2px solid rgba(255, 179, 71, .6);
  background: rgba(8, 4, 16, .55); display: none;
}
#minimap.on { display: block; }

#crosshair {
  position: absolute; left: 50%; top: 50%; width: 10px; height: 10px; margin: -5px 0 0 -5px;
  border-radius: 50%; background: rgba(255, 255, 255, .55); box-shadow: 0 0 0 2px rgba(0, 0, 0, .35);
  transition: transform .12s, background .12s;
}
#crosshair.hot { transform: scale(1.9); background: var(--gold); box-shadow: 0 0 12px var(--orange); }
#crosshair.hidden { display: none; }

#prompt {
  position: absolute; left: 50%; top: calc(50% + 24px); transform: translateX(-50%);
  font-weight: 900; font-size: 1rem; color: var(--gold); text-shadow: 0 2px 6px #000, 0 0 3px #000;
  white-space: nowrap; opacity: 0; transition: opacity .12s;
}
#prompt.on { opacity: 1; }

#say {
  position: absolute; left: 50%; transform: translate(-50%, 0);
  top: calc(92px + var(--safe-t)); width: min(92vw, 520px);
  background: rgba(14, 7, 28, .86); border: 2px solid var(--orange2); border-radius: 16px;
  padding: 9px 13px; font-weight: 800; font-size: .95rem; line-height: 1.3;
  display: none; box-shadow: 0 6px 22px rgba(0, 0, 0, .55);
}
#say.on { display: block; animation: pop .22s ease-out; }
#say b { color: var(--orange2); margin-right: 6px; font-family: var(--display); font-size: 1.05rem; font-weight: 400; letter-spacing: .04em; }

#inv {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(14px + var(--safe-b)); display: flex; gap: 8px; pointer-events: none;
}
#inv .chip {
  pointer-events: auto; min-width: 54px; height: 54px; border-radius: 14px; padding: 0 8px;
  background: rgba(14, 7, 28, .82); border: 2px solid var(--orange2); display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem;
}
#inv .chip small { font-size: .62rem; font-weight: 900; display: block; color: var(--gold); text-align: center; line-height: 1; }
#inv .chip.note { border-color: var(--paper); }

#hud-extra { position: absolute; inset: 0; pointer-events: none; }
#hud-extra > * { pointer-events: auto; }
#hud-extra .noclick { pointer-events: none; }

#btn-use {
  position: absolute; right: calc(16px + var(--safe-r)); bottom: calc(26px + var(--safe-b));
  width: 86px; height: 86px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffd37a, var(--orange) 70%);
  border: 4px solid #fff3d1; color: #3a1500; font-weight: 900; font-size: 1.05rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .55), 0 0 22px rgba(255, 138, 31, .6);
  display: none; line-height: 1.05;
}
#btn-use.on { display: block; animation: pop .18s ease-out; }
#btn-use:active { transform: scale(.92); }

#joy {
  position: absolute; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, .35); background: rgba(255, 255, 255, .08); display: none;
}
#joy.on { display: block; }
#joy-knob {
  position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px; border-radius: 50%;
  background: rgba(255, 220, 160, .55); border: 3px solid rgba(255, 255, 255, .7);
}

/* ---------- Effects ---------- */
#vignette { position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .35s; box-shadow: inset 0 0 120px 40px rgba(255, 0, 40, .75); }
#flash { position: absolute; inset: 0; pointer-events: none; background: #fff; opacity: 0; }
#fade { position: absolute; inset: 0; pointer-events: none; background: #05030a; opacity: 1; transition: opacity .45s; }
#fade.clear { opacity: 0; }

#toast {
  position: absolute; left: 50%; bottom: calc(120px + var(--safe-b)); transform: translateX(-50%);
  background: rgba(14, 7, 28, .92); border: 2px solid var(--gold); border-radius: 999px; padding: 9px 18px;
  font-weight: 900; font-size: .98rem; color: var(--gold); pointer-events: none; opacity: 0; transition: opacity .2s;
  max-width: 92vw; text-align: center; z-index: 50;
}
#toast.on { opacity: 1; }

#boot { position: absolute; inset: 0; z-index: 99; background: #05030a; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; transition: opacity .5s; }
#boot.gone { opacity: 0; pointer-events: none; }
.boot-pumpkin { font-size: 4.5rem; animation: bob 1.2s ease-in-out infinite; }
.boot-text { font-family: var(--display); font-size: 1.5rem; color: var(--orange2); letter-spacing: .05em; }

/* ---------- Screens & panels ---------- */
#screens { position: absolute; inset: 0; pointer-events: none; z-index: 20; }
.layer {
  position: absolute; inset: 0; pointer-events: auto; overflow-y: auto; -webkit-overflow-scrolling: touch;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(14px + var(--safe-t)) calc(14px + var(--safe-r)) calc(14px + var(--safe-b)) calc(14px + var(--safe-l));
  background: rgba(6, 3, 14, .72); touch-action: pan-y;
  animation: fadein .25s ease-out;
}
.layer.solid { background: radial-gradient(ellipse at 50% 0%, #3a1a5e 0%, #170b29 55%, #07030f 100%); }
.layer.clear { background: transparent; pointer-events: none; justify-content: flex-end; }
.layer.clear > * { pointer-events: auto; }
.layer.top { justify-content: flex-start; }

.panel {
  width: min(94vw, 460px); background: linear-gradient(180deg, #2a1347 0%, #1a0c30 100%);
  border: 3px solid var(--orange2); border-radius: 22px; padding: 18px 16px 16px; text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .65), 0 0 40px rgba(255, 138, 31, .18);
  animation: pop .25s ease-out; margin: auto;
}
.panel h2 { font-family: var(--display); font-weight: 400; font-size: 2rem; margin: 0 0 6px; color: var(--orange2); letter-spacing: .04em; line-height: 1.05; }
.panel h3 { margin: 12px 0 6px; font-size: 1.05rem; color: var(--gold); font-weight: 900; }
.panel p { margin: 6px 0; font-size: 1rem; line-height: 1.4; font-weight: 700; color: #f1e6ff; }
.panel .big-emoji { font-size: 3.4rem; line-height: 1; margin-bottom: 4px; }
.panel .small { font-size: .82rem; opacity: .8; font-weight: 700; }
.panel.paper { background: linear-gradient(180deg, #f7e9c6, #e8d3a0); border-color: #7a4a18; color: #3a2108; }
.panel.paper h2 { color: #6a2a08; }
.panel.paper p { color: #3a2108; font-family: "Georgia", serif; font-style: italic; font-size: 1.15rem; }

.btn {
  display: block; width: 100%; min-height: 54px; margin: 10px 0 0; padding: 12px 16px; border-radius: 16px;
  border: 3px solid #fff3d1; background: linear-gradient(180deg, #ffb347, #ff7a12);
  color: #3a1500; font-weight: 900; font-size: 1.1rem; letter-spacing: .01em;
  box-shadow: 0 5px 0 #a84a00, 0 8px 18px rgba(0, 0, 0, .45); cursor: pointer;
}
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #a84a00; }
.btn.alt { background: linear-gradient(180deg, #8a5cff, #5b2fd0); color: #fff; border-color: #d9c7ff; box-shadow: 0 5px 0 #34188c, 0 8px 18px rgba(0, 0, 0, .45); }
.btn.alt:active { box-shadow: 0 2px 0 #34188c; }
.btn.dim { background: #3a2a55; color: #d9c7ff; border-color: #6a4aa0; box-shadow: 0 5px 0 #20113a; }
.btn.small { min-height: 44px; font-size: .95rem; padding: 8px 12px; }
.btn[disabled] { opacity: .45; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

/* Title */
.title-wrap { width: min(94vw, 480px); text-align: center; margin: auto; }
.title-pre { font-family: var(--display); font-size: 1.5rem; color: var(--gold); letter-spacing: .12em; text-shadow: 0 3px 0 #5a2200, 0 0 18px rgba(255, 138, 31, .8); }
.title-main {
  font-family: var(--display); font-size: clamp(3rem, 15vw, 5.2rem); line-height: .9; color: var(--orange);
  text-shadow: 0 4px 0 #7a2c00, 0 7px 0 #3a1200, 0 0 36px rgba(255, 138, 31, .75);
  margin: 4px 0 6px; animation: flicker 4s infinite;
}
.title-main span { display: block; }
.title-sub { font-weight: 800; font-size: 1rem; color: #e9d7ff; margin-bottom: 14px; text-shadow: 0 2px 6px #000; }
.title-foot { margin-top: 14px; font-size: .8rem; opacity: .7; font-weight: 700; }

/* Family */
.fam-row { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.fam-row .emo { flex: none; width: 52px; height: 52px; border-radius: 14px; border: 3px solid var(--orange2); background: #3a1d5e; font-size: 1.7rem; }
.fam-row input {
  flex: 1; min-width: 0; height: 52px; border-radius: 14px; border: 3px solid #6a4aa0; background: #120922; color: #fff;
  font-size: 1.1rem; font-weight: 800; padding: 0 12px; font-family: var(--body); -webkit-user-select: text; user-select: text;
}
.fam-row .del { flex: none; width: 44px; height: 52px; border-radius: 12px; border: 0; background: #4a1c3a; color: #ffb0c0; font-size: 1.2rem; font-weight: 900; }
textarea.msg {
  width: 100%; border-radius: 14px; border: 3px solid #6a4aa0; background: #120922; color: #fff; padding: 10px 12px; margin-top: 4px;
  font-size: 1rem; font-weight: 700; font-family: var(--body); resize: none; height: 72px; -webkit-user-select: text; user-select: text;
}

/* Scoreboards */
.score-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; margin: 6px 0; border-radius: 14px; background: rgba(255, 255, 255, .07); text-align: left; font-weight: 800; }
.score-row .who { flex: 1; font-size: 1.05rem; }
.score-row .pts { font-family: var(--display); font-size: 1.5rem; color: var(--gold); }
.score-row.first { background: rgba(255, 200, 80, .22); border: 2px solid var(--gold); }
.stars { font-size: 2.2rem; letter-spacing: 6px; margin: 4px 0; }
.stars .off { filter: grayscale(1) brightness(.4); }

/* Turn card */
.turn-emoji { font-size: 4.5rem; animation: bob 1.2s ease-in-out infinite; }
.turn-name { font-family: var(--display); font-size: 2.6rem; color: var(--gold); line-height: 1; margin: 4px 0; text-shadow: 0 3px 0 #5a2200; }

/* Trivia */
#hud.quiz-up #btn-use { display: none !important; }
#hud.quiz-up #party { opacity: .85; }
.qcard {
  position: absolute; left: 50%; transform: translateX(-50%); top: calc(78px + var(--safe-t)); width: min(94vw, 520px);
  background: rgba(14, 7, 28, .9); border: 3px solid var(--orange2); border-radius: 18px; padding: 10px 14px 12px; text-align: center;
  box-shadow: 0 8px 26px rgba(0, 0, 0, .6); pointer-events: none;
}
.qcard .qmeta { font-size: .78rem; font-weight: 900; color: var(--purple); letter-spacing: .06em; text-transform: uppercase; }
.qcard .qtext { font-size: 1.12rem; font-weight: 900; line-height: 1.25; margin-top: 3px; }
.qbar { height: 8px; background: #2a1347; border-radius: 99px; margin-top: 8px; overflow: hidden; }
.qbar > i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #7dff6a, #ffe27a, #ff4d5e); transform-origin: left; }
.answers { position: absolute; left: 0; right: 0; bottom: calc(10px + var(--safe-b)); padding: 0 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.ans {
  min-height: 62px; border-radius: 16px; border: 3px solid #fff; padding: 6px 8px; font-weight: 900; font-size: .98rem; line-height: 1.15; color: #fff;
  display: flex; align-items: center; gap: 8px; text-align: left; box-shadow: 0 4px 0 rgba(0, 0, 0, .5);
}
.ans b { flex: none; width: 30px; height: 30px; border-radius: 50%; background: rgba(0, 0, 0, .35); display: grid; place-items: center; font-family: var(--display); font-weight: 400; font-size: 1.15rem; }
.ans.a { background: #d6402e; } .ans.b { background: #2a7be0; } .ans.c { background: #2fa84f; } .ans.d { background: #9a4de0; }
.ans:active { transform: translateY(2px); }
.ans.good { background: #1fd35a; border-color: #eaffd0; animation: pulse .4s 3 alternate; }
.ans.bad { background: #444; opacity: .55; }
.ans.chosen-bad { background: #c0172b; opacity: 1; }
.ans[disabled] { pointer-events: none; }

/* Scoreboard overlay in HUD */
.hud-score { position: absolute; left: 50%; transform: translateX(-50%); top: calc(48px + var(--safe-t)); text-align: center; pointer-events: none; text-shadow: 0 2px 8px #000; }
.hud-score .big { font-family: var(--display); font-size: 2.4rem; color: var(--gold); line-height: 1; }
.hud-score .sm { font-weight: 900; font-size: .9rem; }
.streak { color: var(--green); font-weight: 900; font-size: 1.1rem; }

/* Keypad */
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.keypad button { height: 56px; border-radius: 14px; border: 3px solid #6a4aa0; background: #2a1d44; color: #fff; font-size: 1.5rem; font-weight: 900; }
.keypad button:active { background: #4a2d78; }
.lcd { font-family: "Courier New", monospace; font-size: 2.6rem; letter-spacing: .4em; background: #07120a; color: #6dff7a; border: 3px solid #1f5a2a; border-radius: 12px; padding: 6px 0 6px .4em; text-shadow: 0 0 10px #3aff5a; min-height: 64px; }
.lcd.bad { color: #ff5a5a; text-shadow: 0 0 10px #f00; animation: shake .3s; }

/* Potion / gallery HUD */
.pot-hint { position: absolute; left: 0; right: 0; bottom: calc(18px + var(--safe-b)); text-align: center; font-weight: 900; font-size: 1.1rem; text-shadow: 0 2px 8px #000, 0 0 3px #000; pointer-events: none; }
.pot-hint big { display: block; font-family: var(--display); font-weight: 400; font-size: 1.8rem; color: var(--gold); }
.fire-hint { position: absolute; left: 0; right: 0; bottom: calc(18px + var(--safe-b)); text-align: center; font-weight: 900; text-shadow: 0 2px 8px #000; pointer-events: none; opacity: .85; }

.award { display: flex; gap: 12px; align-items: center; text-align: left; padding: 10px 12px; margin: 8px 0; border-radius: 16px; background: rgba(255, 255, 255, .08); border: 2px solid rgba(255, 226, 122, .5); }
.award .e { font-size: 2.2rem; }
.award b { display: block; color: var(--gold); font-size: 1.08rem; }
.award span { font-size: .88rem; font-weight: 700; color: #e9d7ff; }

.banner-final {
  font-family: var(--display); font-size: clamp(2.2rem, 11vw, 3.6rem); line-height: .95; color: var(--orange); text-align: center;
  text-shadow: 0 4px 0 #7a2c00, 0 0 30px rgba(255, 138, 31, .8); margin-bottom: 6px;
}

.ctrl-demo { display: flex; gap: 10px; margin: 8px 0; text-align: left; align-items: center; }
.ctrl-demo .ic { flex: none; width: 52px; height: 52px; border-radius: 14px; background: #3a1d5e; border: 2px solid var(--purple); display: grid; place-items: center; font-size: 1.7rem; }
.ctrl-demo div:last-child { font-weight: 800; font-size: .95rem; line-height: 1.25; }

.seg { display: flex; gap: 6px; margin: 6px 0; }
.seg button { flex: 1; min-height: 46px; border-radius: 12px; border: 2px solid #6a4aa0; background: #241338; color: #cbb8f0; font-weight: 900; font-size: .9rem; }
.seg button.on { background: var(--orange); color: #3a1500; border-color: #fff3d1; }
.set-label { text-align: left; font-weight: 900; color: var(--gold); margin-top: 10px; font-size: .95rem; }

@keyframes pop { from { transform: scale(.88); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.08); } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
@keyframes flicker { 0%, 100% { opacity: 1; } 92% { opacity: 1; } 93% { opacity: .75; } 94% { opacity: 1; } 96% { opacity: .85; } 97% { opacity: 1; } }

@media (orientation: landscape) and (max-height: 520px) {
  .panel { padding: 10px 14px; }
  .panel h2 { font-size: 1.5rem; }
  .btn { min-height: 44px; margin-top: 6px; padding: 8px 12px; }
  .qcard { top: calc(56px + var(--safe-t)); }
  .answers { grid-template-columns: repeat(4, 1fr); }
  .ans { min-height: 52px; font-size: .85rem; }
  #say { top: calc(78px + var(--safe-t)); }
  .title-main { font-size: 3rem; }
}
