:root {
  --ink: #1d1420;
  --cream: #fff4dc;
  --paper: #f7e6c4;
  --paper-2: #efd7a8;
  --gold: #ffd23f;
  --red: #e8453c;
  --green: #4cc26a;
  --blue: #3a8ee6;
  --purple: #7a3aa8;
  --shadow: 0 6px 0 var(--ink);
  --title: "Luckiest Guy", "Arial Black", Impact, sans-serif;
  --body: "Nunito", system-ui, sans-serif;
  --mono: "JetBrains Mono", Consolas, monospace;
}
* { box-sizing: border-box; }
/* html and body both clip, so the 1280px stage never widens a phone's layout viewport */
html { height: 100%; overflow: hidden; }
body { margin: 0; position: fixed; inset: 0; background: #120b16; overflow: hidden; color: var(--ink); font-family: var(--body); }
/* clip (not just hide) overflow: off-stage slide-in UI must never make the stage scrollable */
#stage { position: absolute; left: 50%; top: 50%; width: 1280px; height: 720px; transform-origin: 50% 50%; overflow: hidden; overflow: clip; background: #1a0e16; }
#game { position: absolute; inset: 0; width: 1280px; height: 720px; display: block; }
#ui { position: absolute; inset: 0; pointer-events: none; }
#ui .screen { position: absolute; inset: 0; pointer-events: auto; }
#ui .hidden { display: none !important; }
button { font-family: var(--title); cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 4px solid var(--gold); outline-offset: 2px; }

/* ---------- common pieces ---------- */
.btn {
  pointer-events: auto;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  border: 4px solid var(--ink); border-radius: 16px;
  background: var(--gold); color: var(--ink);
  font-size: 26px; letter-spacing: 1px; padding: 12px 26px 8px;
  box-shadow: 0 6px 0 var(--ink);
  transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.1s;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.5);
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 8px 0 var(--ink); filter: brightness(1.06); }
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--ink); }
.btn.red { background: var(--red); color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,0.3); }
.btn.green { background: var(--green); color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,0.3); }
.btn.blue { background: var(--blue); color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,0.3); }
.btn.ghost { background: var(--cream); }
.btn.small { font-size: 18px; padding: 8px 16px 5px; border-radius: 12px; box-shadow: 0 4px 0 var(--ink); }
.btn[disabled] { filter: grayscale(0.8) brightness(0.8); cursor: not-allowed; transform: none; }
.panel {
  background: var(--cream);
  border: 5px solid var(--ink); border-radius: 22px;
  box-shadow: 0 8px 0 var(--ink);
}
.panel.paper { background: linear-gradient(180deg, var(--cream), var(--paper)); }
.h-title { font-family: var(--title); font-size: 44px; margin: 0; letter-spacing: 1px; color: var(--gold); -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; text-shadow: 0 5px 0 var(--ink); }
.dim { position: absolute; inset: 0; background: rgba(18, 8, 20, 0.55); }
.icon-btn {
  width: 48px; height: 48px; border: 4px solid var(--ink); border-radius: 14px; background: var(--cream);
  box-shadow: 0 4px 0 var(--ink); font-size: 22px; display: grid; place-items: center; padding: 0; pointer-events: auto;
  font-family: var(--body);
}
.icon-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.icon-btn.off { background: #cfc3b0; opacity: 0.85; }
.corner-tools { position: absolute; right: 18px; top: 16px; display: flex; gap: 10px; pointer-events: auto; }

/* ---------- title ---------- */
#title .logo { position: absolute; left: 60px; top: 70px; transform: rotate(-4deg); }
#title .logo .l1, #title .logo .l2 {
  font-family: var(--title); line-height: 0.9; display: block;
  -webkit-text-stroke: 6px var(--ink); paint-order: stroke fill; text-shadow: 0 9px 0 var(--ink);
}
#title .logo .l1 { font-size: 104px; color: var(--gold); }
#title .logo .l2 { font-size: 124px; color: #ff6b4a; margin-left: 40px; }
#title .logo .tag {
  display: inline-block; margin: 18px 0 0 46px; padding: 8px 16px 6px;
  font-weight: 900; font-size: 20px; background: var(--cream); border: 4px solid var(--ink); border-radius: 12px;
  box-shadow: 0 5px 0 var(--ink); transform: rotate(2deg);
}
#title .menu { position: absolute; left: 90px; top: 420px; display: flex; flex-direction: column; gap: 16px; align-items: flex-start; }
#title .menu .btn { min-width: 330px; justify-content: flex-start; font-size: 30px; }
#title .menu .btn .sub { font-family: var(--body); font-weight: 800; font-size: 14px; letter-spacing: 0; opacity: 0.75; margin-left: auto; }
#title .who { position: absolute; left: 90px; bottom: 26px; font-weight: 800; color: var(--cream); font-size: 16px; text-shadow: 0 2px 0 var(--ink); }

/* ---------- customize ---------- */
#custom .wrap { position: absolute; left: 60px; right: 60px; top: 46px; bottom: 46px; display: flex; gap: 26px; }
#custom .preview { width: 380px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; padding: 14px; position: relative; overflow: hidden; }
#custom .preview canvas { width: 340px; height: 440px; }
#custom .preview .plinth { position: absolute; bottom: 22px; left: 50%; transform: translateX(-50%); width: 240px; height: 40px; border-radius: 50%; background: rgba(29,20,32,0.12); }
#custom .form { flex: 1; padding: 16px 26px; overflow: auto; }
#custom .form .h-title { font-size: 38px; margin-bottom: 4px; }
#custom .row { margin-bottom: 9px; }
#custom .row h3 { font-family: var(--title); font-weight: normal; font-size: 19px; margin: 0 0 5px; letter-spacing: 1px; }
#custom input[type=text] {
  font: 900 22px var(--body); color: var(--ink); width: 100%; padding: 7px 14px; border: 4px solid var(--ink); border-radius: 14px; background: #fff;
}
#custom .chip { padding: 6px 12px; font-size: 16px; }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { width: 40px; height: 40px; border-radius: 50%; border: 4px solid var(--ink); cursor: pointer; box-shadow: 0 3px 0 var(--ink); padding: 0; }
.swatch.on { outline: 4px solid var(--gold); outline-offset: 2px; transform: scale(1.08); }
.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
  font-family: var(--body); font-weight: 900; font-size: 17px; padding: 8px 14px; border: 4px solid var(--ink); border-radius: 12px; background: #fff; box-shadow: 0 3px 0 var(--ink); cursor: pointer; color: var(--ink);
}
.chip.mono { font-family: var(--mono); font-weight: 700; min-width: 58px; }
.chip.on { background: var(--gold); transform: translateY(-2px); }
#custom .actions { display: flex; gap: 14px; margin-top: 8px; }

/* ---------- map ---------- */
#map .top { position: absolute; left: 40px; right: 40px; top: 26px; display: flex; align-items: center; gap: 18px; }
#map .tabs { display: flex; gap: 12px; margin-left: 18px; }
#map .tab { font-family: var(--title); font-size: 24px; padding: 10px 22px 6px; border: 4px solid var(--ink); border-radius: 14px 14px 14px 14px; background: var(--cream); box-shadow: 0 5px 0 var(--ink); cursor: pointer; }
#map .tab.on { transform: translateY(-3px); }
#map .tab .dot { display: inline-block; width: 14px; height: 14px; border-radius: 4px; border: 3px solid var(--ink); margin-right: 8px; vertical-align: 1px; }
#map .blurb { position: absolute; left: 60px; top: 104px; right: 60px; color: var(--cream); font-weight: 800; font-size: 18px; text-shadow: 0 2px 0 var(--ink); }
#map .path { position: absolute; left: 50px; right: 50px; top: 150px; height: 420px; display: flex; gap: 26px; align-items: stretch; }
#map .node { flex: 1; display: flex; flex-direction: column; padding: 14px 16px 16px; position: relative; }
#map .node.final { background: linear-gradient(180deg, #efe1ff, #d9c2f5); }
#map .node canvas.portrait { width: 100%; height: 210px; border-radius: 14px; border: 4px solid var(--ink); background: radial-gradient(circle at 50% 70%, #ffe7b0, #c98a5a); }
#map .node.final canvas.portrait { background: radial-gradient(circle at 50% 70%, #d7b8ff, #5a2a7a); }
#map .node .mod { font-family: var(--title); font-size: 25px; margin: 12px 0 2px; letter-spacing: 0.5px; }
#map .node .boss { font-weight: 900; font-size: 16px; opacity: 0.8; }
#map .node .meta { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-top: 10px; }
#map .node .stars { font-size: 26px; letter-spacing: 2px; color: #cbb68f; -webkit-text-stroke: 1.5px var(--ink); }
#map .node .stars .on { color: var(--gold); }
#map .node.locked { filter: grayscale(0.9) brightness(0.8); }
#map .node .lock { position: absolute; left: 50%; top: 100px; transform: translate(-50%, -50%); font-size: 56px; filter: drop-shadow(0 4px 0 var(--ink)); }
#map .node .tagline { position: absolute; right: 10px; top: -16px; font-family: var(--title); font-size: 16px; background: var(--purple); color: #fff; border: 3px solid var(--ink); border-radius: 10px; padding: 4px 10px 2px; transform: rotate(3deg); }
#map .gallery { position: absolute; left: 50px; right: 50px; bottom: 22px; height: 104px; display: flex; align-items: center; gap: 14px; padding: 8px 18px; }
#map .gallery h4 { font-family: var(--title); font-weight: normal; font-size: 20px; margin: 0; width: 150px; line-height: 1.1; }
#map .gallery .slots { display: flex; gap: 8px; flex: 1; }
#map .gallery canvas { width: 62px; height: 78px; border-radius: 12px; border: 3px solid var(--ink); background: #fff8e8; }
#map .gallery canvas.empty { opacity: 0.35; filter: grayscale(1) brightness(0.3); }
#map .party-note { font-weight: 900; color: var(--cream); text-shadow: 0 2px 0 var(--ink); margin-left: auto; font-size: 17px; }

/* ---------- party lobby ---------- */
#party .box { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 900px; padding: 28px 34px; }
#party .code { font-family: var(--title); font-size: 64px; letter-spacing: 12px; background: #fff; border: 5px solid var(--ink); border-radius: 18px; padding: 10px 26px 2px; display: inline-block; box-shadow: 0 6px 0 var(--ink); }
#party .members { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin: 22px 0; }
#party .member { border: 4px solid var(--ink); border-radius: 16px; background: #fff; text-align: center; padding: 8px 6px 10px; position: relative; min-height: 190px; }
#party .member canvas { width: 130px; height: 140px; }
#party .member .nm { font-weight: 900; font-size: 18px; }
#party .member.empty { background: repeating-linear-gradient(45deg, #f4e7cc, #f4e7cc 10px, #ecdcbc 10px, #ecdcbc 20px); display: grid; place-items: center; font-weight: 900; opacity: 0.8; }
#party .member .crown { position: absolute; left: 8px; top: 6px; font-size: 24px; }
#party .row { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
#party input { font: 900 30px var(--title); letter-spacing: 8px; text-transform: uppercase; width: 190px; padding: 10px 14px 4px; border: 4px solid var(--ink); border-radius: 14px; }
#party .msg { font-weight: 900; margin-top: 12px; min-height: 24px; }
#party .msg.err { color: var(--red); }
#party p { font-weight: 800; font-size: 17px; margin: 6px 0 14px; }

/* ---------- HUD ---------- */
#hud { pointer-events: none; }
#hud .party { position: absolute; left: 14px; top: 12px; display: flex; flex-direction: column; gap: 6px; }
.pslot {
  width: 236px; height: 50px; display: flex; align-items: center; gap: 8px; padding: 3px 8px 3px 3px;
  background: var(--cream); border: 4px solid var(--ink); border-radius: 14px; box-shadow: 0 4px 0 var(--ink);
  transition: transform 0.2s, opacity 0.3s;
}
.pslot.me { background: #fff8d0; }
.pslot.ko { opacity: 0.6; filter: grayscale(0.7); }
.pslot canvas { width: 38px; height: 38px; border-radius: 10px; background: #e9d7b4; border: 3px solid var(--ink); flex: none; }
.pslot .info { flex: 1; min-width: 0; }
.pslot .nm { font-weight: 900; font-size: 14px; line-height: 1; display: flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; }
.pslot .nm .tag { margin-left: auto; font-size: 12px; font-weight: 900; }
.pslot .nm .tag.ok { color: var(--green); }
.pslot .nm .tag.fire { color: #e8651a; }
.hpbar { height: 14px; border: 3px solid var(--ink); border-radius: 8px; background: #3a2a2e; margin-top: 4px; overflow: hidden; position: relative; }
.hpbar .fill { position: absolute; left: 0; top: 0; bottom: 0; background: linear-gradient(180deg, #7de37f, #3faa4a); transition: width 0.35s ease; }
.hpbar .ghost { position: absolute; left: 0; top: 0; bottom: 0; background: #fff2a8; transition: width 0.9s ease 0.25s; }
.hpbar.low .fill { background: linear-gradient(180deg, #ff8a6a, #d9402f); }
#hud .bossbar { position: absolute; left: 50%; top: 14px; transform: translateX(-50%); width: 520px; text-align: center; }
#hud .bossbar .plate {
  display: inline-block; font-family: var(--title); font-size: 24px; letter-spacing: 1px; color: #fff; background: #6b2a3a;
  border: 4px solid var(--ink); border-radius: 12px; padding: 5px 18px 1px; box-shadow: 0 4px 0 var(--ink); position: relative; z-index: 1;
  -webkit-text-stroke: 1px var(--ink); paint-order: stroke fill;
}
#hud .bossbar .hpbar { height: 26px; border-width: 4px; border-radius: 12px; margin-top: -8px; box-shadow: 0 4px 0 var(--ink); }
#hud .bossbar .hpbar .fill { background: linear-gradient(180deg, #ff7a5a, #c93a2a); }
#hud .bossbar .num { position: absolute; right: 12px; top: 1px; font-family: var(--title); color: #fff; font-size: 16px; -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; }
#hud .bossbar .mod { font-weight: 900; font-size: 13px; color: var(--cream); text-shadow: 0 2px 0 var(--ink); margin-top: 6px; letter-spacing: 0.5px; }
#hud .tools { pointer-events: auto; }

/* question card */
#qcard {
  position: absolute; left: 36px; right: 36px; bottom: 12px; padding: 14px 18px 16px;
  transition: transform 0.35s cubic-bezier(.3,1.4,.5,1), opacity 0.25s;
  pointer-events: auto;
}
#qcard.away { transform: translateY(125%); opacity: 0; pointer-events: none; }
#qcard .timer { position: absolute; left: 18px; right: 18px; top: -12px; height: 14px; border: 3px solid var(--ink); border-radius: 8px; background: #3a2a2e; overflow: hidden; }
#qcard .timer .fill { height: 100%; background: linear-gradient(90deg, var(--gold), #ff8a3a); width: 100%; }
#qcard .qhead { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
#qcard .qnum { font-family: var(--title); font-size: 18px; background: var(--ink); color: var(--gold); padding: 3px 10px 0; border-radius: 8px; }
#qcard .qmod { font-weight: 900; font-size: 14px; opacity: 0.7; }
#qcard .qwait { margin-left: auto; font-weight: 900; font-size: 14px; color: #8a5a2a; }
#qcard .qbody { display: flex; gap: 16px; align-items: stretch; }
#qcard .qtext { flex: 1.05; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
#qcard .prompt { font-weight: 900; font-size: 21px; line-height: 1.2; }
#qcard pre { margin: 0; font: 600 15px/1.35 var(--mono); background: #221a2a; color: #f4ecd8; border: 3px solid var(--ink); border-radius: 12px; padding: 8px 12px; overflow: hidden; white-space: pre; }
#qcard pre .k { color: #ff9ad0; } #qcard pre .s { color: #b5f07a; } #qcard pre .n { color: #ffcf5a; } #qcard pre .c { color: #8a8398; font-style: italic; } #qcard pre .f { color: #7ad0ff; }
#qcard .answers { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-content: center; }
.ans {
  position: relative; text-align: left; font: 800 17px/1.2 var(--body); color: var(--ink);
  border: 4px solid var(--ink); border-radius: 14px; background: #fff; padding: 10px 12px 10px 46px; min-height: 56px;
  box-shadow: 0 4px 0 var(--ink); cursor: pointer; transition: transform 0.08s, background 0.15s;
}
.ans .key { position: absolute; left: 8px; top: 50%; transform: translateY(-50%); width: 28px; height: 28px; border-radius: 8px; border: 3px solid var(--ink); background: var(--gold); font: 16px/22px var(--title); text-align: center; }
.ans code { font-family: var(--mono); font-weight: 700; font-size: 15px; }
.ans:hover { transform: translateY(-2px); background: #fffbe8; }
.ans:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.ans.picked { background: #ffe9a8; }
.ans.right { background: #a8f0a0; }
.ans.wrong { background: #ffb3a8; }
.ans.dim { opacity: 0.55; }
#qcard.locked .ans { cursor: default; }
#qcard .why { font-weight: 800; font-size: 16px; padding: 8px 12px; border-radius: 10px; border: 3px solid var(--ink); background: #fff; display: none; }
#qcard .why.show { display: block; }
#qcard .why.good { background: #d8f7cf; }
#qcard .why.bad { background: #ffe0d6; }

/* callouts */
#callout {
  position: absolute; left: 50%; top: 120px; transform: translate(-50%, 0) rotate(-3deg) scale(0);
  font-family: var(--title); font-size: 46px; color: #fff; background: var(--red); border: 5px solid var(--ink); border-radius: 16px;
  padding: 8px 26px 2px; box-shadow: 0 6px 0 var(--ink); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill; white-space: nowrap;
  transition: transform 0.25s cubic-bezier(.3,1.6,.5,1);
}
#callout.show { transform: translate(-50%, 0) rotate(-3deg) scale(1); }
#callout.good { background: var(--green); }

/* boss name card */
#namecard { position: absolute; left: 0; right: 0; top: 230px; height: 190px; pointer-events: none; }
#namecard .band { position: absolute; left: -40px; right: -40px; top: 30px; height: 130px; background: var(--ink); transform: rotate(-3deg) scaleX(0); transform-origin: left; transition: transform 0.35s cubic-bezier(.2,.9,.3,1); }
#namecard .nm { position: absolute; left: 90px; top: 34px; font-family: var(--title); font-size: 78px; color: var(--gold); -webkit-text-stroke: 4px var(--ink); paint-order: stroke fill; transform: translateX(-120%) rotate(-3deg); transition: transform 0.4s cubic-bezier(.2,1.2,.3,1) 0.1s; text-shadow: 0 6px 0 #000; }
#namecard .tt { position: absolute; left: 110px; top: 118px; font-family: var(--title); font-size: 28px; color: #fff; transform: translateX(-160%) rotate(-3deg); transition: transform 0.4s cubic-bezier(.2,1.2,.3,1) 0.2s; }
#namecard .md { position: absolute; right: 110px; top: 128px; font-weight: 900; font-size: 17px; color: var(--ink); background: var(--gold); border: 3px solid var(--ink); border-radius: 10px; padding: 3px 10px; transform: translateX(200%) rotate(-3deg); transition: transform 0.4s ease 0.3s; }
#namecard.show .band { transform: rotate(-3deg) scaleX(1); }
#namecard.show .nm, #namecard.show .tt { transform: translateX(0) rotate(-3deg); }
#namecard.show .md { transform: translateX(0) rotate(-3deg); }

/* results */
#results .card { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%) scale(0.8); opacity: 0; width: 620px; padding: 26px 30px 24px; text-align: center; transition: transform 0.4s cubic-bezier(.3,1.5,.5,1), opacity 0.3s; }
#results.show .card { transform: translate(-50%, -50%) scale(1); opacity: 1; }
#results .big { font-family: var(--title); font-size: 76px; line-height: 1; color: var(--gold); -webkit-text-stroke: 5px var(--ink); paint-order: stroke fill; text-shadow: 0 7px 0 var(--ink); margin: -70px 0 6px; transform: rotate(-3deg); }
#results .big.lose { color: #ff8a7a; }
#results .stars { font-size: 56px; letter-spacing: 6px; color: #d8c7a4; -webkit-text-stroke: 3px var(--ink); margin: 4px 0; }
#results .stars .on { color: var(--gold); }
#results .stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 12px 0 14px; }
#results .stat { border: 4px solid var(--ink); border-radius: 14px; background: #fff; padding: 8px 4px 6px; }
#results .stat b { display: block; font-family: var(--title); font-size: 30px; font-weight: normal; }
#results .stat span { font-weight: 900; font-size: 13px; opacity: 0.7; }
#results .note { font-weight: 900; font-size: 18px; margin: 4px 0 16px; }
#results .actions { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }

/* toast */
#toast { position: absolute; left: 50%; bottom: 30px; transform: translateX(-50%); background: var(--ink); color: var(--cream); font-weight: 900; padding: 10px 18px; border-radius: 12px; opacity: 0; transition: opacity 0.3s; pointer-events: none; font-size: 16px; }
#toast.show { opacity: 1; }
#qcard .prompt code, #qcard .why code { font-family: var(--mono); font-weight: 700; font-size: 0.92em; background: #efe2c6; border: 2px solid rgba(29,20,32,0.25); border-radius: 6px; padding: 0 5px; }

/* portrait phones: the 16:9 battle letterboxes small, so suggest landscape in the empty space above it */
#rotatehint { display: none; position: fixed; left: 50%; top: max(12px, env(safe-area-inset-top)); transform: translateX(-50%); z-index: 5; pointer-events: none; font: 800 14px/1.2 var(--body); color: #f4e8d0; background: rgba(255,255,255,0.08); border: 2px solid rgba(255,255,255,0.18); border-radius: 999px; padding: 8px 14px; white-space: nowrap; }
#rotatehint .ph { display: inline-block; animation: rotatehint 2.4s ease-in-out infinite; }
@keyframes rotatehint { 0%, 30% { transform: rotate(0); } 50%, 80% { transform: rotate(-90deg); } 100% { transform: rotate(0); } }
@media (orientation: portrait) and (max-width: 700px) and (min-height: 520px) { #rotatehint { display: block; } }
