:root {
  --fire: #ff8a1f;
  --fire-hot: #ffcf3f;
  --ember: #c4320a;
  --night: #1a0904;
  --panel: rgba(26, 9, 4, 0.82);
  --water: #3fb8ff;
  --ink: #fff4e0;
  --muted: #d9b99a;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--night); color: var(--ink); overflow: hidden; overscroll-behavior: none;
  font-family: "Nunito", system-ui, sans-serif; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none; }
button { touch-action: manipulation; }
#app { position: fixed; inset: 0; }
canvas#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; }
.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; }
#hud-top { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); text-align: center; max-width: calc(100% - 24px); }
#stage-name { font-family: "Bangers", cursive; font-size: 22px; letter-spacing: 1.5px; color: var(--fire-hot);
  text-shadow: 0 2px 0 var(--ember), 0 0 12px rgba(255,120,0,.6); }
#objective { margin-top: 4px; background: var(--panel); border: 2px solid var(--fire); border-radius: 12px;
  padding: 6px 14px; font-weight: 800; font-size: 14px; line-height: 1.35; }
#objective .done { color: #8dff8a; text-decoration: line-through; opacity: .8; }

#hud-stats { position: absolute; top: 10px; left: 12px; background: var(--panel); border-radius: 12px; padding: 8px 10px;
  border: 2px solid rgba(255,138,31,.5); min-width: 170px; }
#hearts { font-size: 18px; letter-spacing: 2px; }
.bar { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.bar-label { font-weight: 900; font-size: 11px; color: var(--water); width: 26px; }
.bar-track { flex: 1; height: 12px; border-radius: 6px; background: #0b2433; overflow: hidden; border: 1px solid #1d5a7d; }
#water-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #1b8fd6, var(--water), #b8ecff); transition: width .1s; }
#water-fill.low { background: linear-gradient(90deg, #d63a1b, #ff8a3f); animation: blink .5s infinite alternate; }
#carry { font-size: 12px; font-weight: 800; color: var(--muted); margin-top: 4px; min-height: 16px; }

/* crew cards stack on the right above the skill button, like a MOBA skill bar; the move pad owns the bottom-left */
#team { position: absolute; right: 16px; bottom: 136px; display: flex; flex-direction: column; gap: 8px; pointer-events: auto; }
.member { position: relative; width: 66px; height: 82px; border-radius: 12px; background: var(--panel); border: 2px solid #5a3420;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end; padding-bottom: 4px; cursor: pointer;
  font-weight: 900; font-size: 11px; color: var(--muted); transition: transform .15s, border-color .15s; }
.member canvas { width: 52px; height: 52px; }
.member.active { border-color: var(--fire-hot); color: var(--ink); transform: translateX(-6px); box-shadow: 0 0 14px rgba(255,180,40,.55); }
.member .key { position: absolute; top: 3px; left: 6px; font-size: 10px; opacity: .7; }
.member .cd { position: absolute; inset: 0; border-radius: 10px; background: rgba(0,0,0,.55); transform-origin: bottom; pointer-events: none; }

#skill-btn { position: absolute; right: 16px; bottom: 16px; width: 104px; height: 104px; border-radius: 50%;
  border: 4px solid var(--fire-hot); background: radial-gradient(circle at 40% 35%, #ff9d2e, #c4320a);
  color: #fff; font-family: "Bangers", cursive; font-size: 17px; letter-spacing: 1px; pointer-events: auto; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.05; overflow: hidden;
  text-shadow: 0 2px 0 rgba(0,0,0,.4); box-shadow: 0 6px 18px rgba(0,0,0,.5); padding: 6px; }
#skill-btn small { font-family: "Nunito"; font-size: 10px; opacity: .8; margin-top: 2px; }
#skill-btn #skill-cd { position: absolute; inset: 0; background: rgba(0,0,0,.6); transform-origin: bottom; transform: scaleY(0); }
#skill-btn.ready { animation: pulse 1.2s infinite; }
#pull-btn { position: absolute; right: 136px; bottom: 22px; width: 92px; height: 92px; border-radius: 50%; pointer-events: auto;
  border: 4px solid #b8ff6a; background: radial-gradient(circle at 40% 35%, #5fe07a, #1f8a3a); color: #fff; cursor: pointer;
  font-family: "Bangers", cursive; font-size: 24px; letter-spacing: 1px; display: flex; flex-direction: column; align-items: center;
  justify-content: center; box-shadow: 0 6px 18px rgba(0,0,0,.5); }
#pull-btn small { font-family: "Nunito"; font-size: 10px; opacity: .85; }
#mute { position: absolute; top: 10px; right: 60px; pointer-events: auto; background: var(--panel); color: var(--ink);
  border: 2px solid rgba(255,138,31,.5); border-radius: 10px; font-size: 18px; width: 40px; height: 40px; cursor: pointer; }

#toast { position: absolute; top: 34%; left: 50%; transform: translate(-50%, -50%); font-family: "Bangers", cursive;
  font-size: 34px; letter-spacing: 1.5px; color: var(--fire-hot); text-align: center; white-space: pre-line; pointer-events: none;
  text-shadow: 0 3px 0 var(--ember), 0 0 18px rgba(0,0,0,.9); opacity: 0; transition: opacity .25s; width: 92%; }
#toast.show { opacity: 1; }
/* ---------- MOBA move pad ---------- */
#joy { position: absolute; left: 30px; bottom: 30px; width: 144px; height: 144px; border-radius: 50%; z-index: 3; touch-action: none; cursor: grab;
  background: radial-gradient(circle, rgba(255,160,60,.14) 0 38%, rgba(0,0,0,.38) 72%); border: 3px solid rgba(255,200,120,.45);
  box-shadow: 0 0 0 6px rgba(0,0,0,.18), inset 0 0 18px rgba(0,0,0,.5); opacity: .85; transition: border-color .15s, opacity .15s; }
#joy.active { border-color: var(--fire-hot); opacity: 1; cursor: grabbing; }
#joy-ring { position: absolute; inset: 16px; border-radius: 50%; border: 2px dashed rgba(255,255,255,.2); pointer-events: none; }
#joy-knob { position: absolute; left: 50%; top: 50%; width: 62px; height: 62px; margin: -31px 0 0 -31px; border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle at 40% 35%, #ffb35a, #c4320a); border: 3px solid var(--fire-hot); box-shadow: 0 4px 12px rgba(0,0,0,.5); transition: transform .12s ease-out; }
#joy.active #joy-knob { transition: none; }

#help { position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%); font-size: 11px; color: var(--muted); opacity: .75; white-space: nowrap; }

/* ---------- Touch stick ---------- */
#stick2 { position: absolute; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.35); background: rgba(0,0,0,.25); pointer-events: none; }
#stick2-knob { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%;
  background: rgba(255,170,60,.75); }
#stick2 { border-color: rgba(120,200,255,.5); }
#stick2-knob { background: rgba(80,180,255,.75); }
#stick2 span { position: absolute; left: 50%; top: -26px; transform: translateX(-50%); font-size: 18px; }

/* ---------- Dialog ---------- */
#dialog { position: absolute; left: 50%; bottom: 128px; transform: translateX(-50%); width: min(720px, calc(100% - 24px));
  display: flex; gap: 12px; align-items: flex-start; background: var(--panel); border: 3px solid var(--fire); border-radius: 16px;
  padding: 12px; cursor: pointer; box-shadow: 0 10px 30px rgba(0,0,0,.6); animation: pop-dialog .2s ease-out; }
#dialog-face { flex: 0 0 72px; height: 72px; border-radius: 12px; background: #2b140a; overflow: hidden; }
#dialog-face canvas { width: 72px; height: 72px; }
#dialog-name { font-family: "Bangers", cursive; font-size: 20px; letter-spacing: 1px; color: var(--fire-hot); }
#dialog-text { font-size: 16px; font-weight: 700; line-height: 1.4; min-height: 44px; }
#dialog-next { text-align: right; font-size: 11px; color: var(--muted); animation: blink .8s infinite alternate; }

/* ---------- Screens ---------- */
#screen { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: radial-gradient(ellipse at center, rgba(60,18,4,.88), rgba(10,3,1,.97)); overflow-y: auto; z-index: 5;
  touch-action: pan-y; -webkit-overflow-scrolling: touch; }
#screen > * { margin: auto; }
.card { width: min(760px, 100%); text-align: center; animation: pop .3s ease-out; }
.card h1, .card h2 { font-family: "Bangers", cursive; letter-spacing: 2px; margin: 6px 0; color: var(--fire-hot);
  text-shadow: 0 3px 0 var(--ember), 0 0 20px rgba(255,120,0,.5); }
.card h1 { font-size: clamp(36px, 8vw, 64px); }
.card h2 { font-size: clamp(28px, 6vw, 44px); }
.card p { font-size: 16px; line-height: 1.5; font-weight: 700; color: var(--ink); margin: 8px auto; max-width: 600px; }
.card .sub { color: var(--muted); font-size: 14px; }
.logo { width: min(420px, 80%); filter: drop-shadow(0 0 30px rgba(255,120,0,.45)); animation: float 3s ease-in-out infinite; border-radius: 18px; }
.still { width: 100%; max-height: 38vh; object-fit: cover; border-radius: 14px; border: 3px solid var(--fire); margin: 6px 0;
  box-shadow: 0 10px 30px rgba(0,0,0,.6); }
.btn { font-family: "Bangers", cursive; font-size: 26px; letter-spacing: 1.5px; color: #fff; cursor: pointer; margin: 10px 6px 0;
  border: 3px solid var(--fire-hot); border-radius: 14px; padding: 10px 28px; background: linear-gradient(#ff8a1f, #c4320a);
  text-shadow: 0 2px 0 rgba(0,0,0,.35); box-shadow: 0 5px 0 #6e1b04, 0 10px 24px rgba(0,0,0,.5); transition: transform .1s; }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #6e1b04; }
.btn.ghost { background: transparent; border-color: var(--muted); color: var(--muted); box-shadow: none; font-size: 20px; }


.trivia { background: rgba(255,138,31,.12); border: 2px dashed var(--fire); border-radius: 12px; padding: 10px 14px;
  margin: 10px auto; max-width: 560px; font-weight: 800; font-size: 14px; }
.trivia b { color: var(--fire-hot); }
.stars { font-size: 28px; letter-spacing: 4px; }

/* ---------- Ending popup ---------- */
.poster { position: relative; width: min(560px, 100%); border-radius: 20px; padding: 18px 18px 22px; text-align: center;
  background: linear-gradient(160deg, #2a0d03, #120402); border: 4px solid var(--fire-hot);
  box-shadow: 0 0 60px rgba(255,110,0,.55); animation: pop .5s cubic-bezier(.2,1.6,.4,1); }
.poster .tonton { font-family: "Bangers", cursive; font-size: clamp(26px, 6vw, 36px); letter-spacing: 2px; color: #fff; margin: 0; }
.poster .tanggal { font-family: "Bangers", cursive; font-size: clamp(22px, 5vw, 30px); letter-spacing: 1.5px; color: var(--fire-hot);
  text-shadow: 0 2px 0 var(--ember); margin: 4px 0 2px; }
.poster .logo { width: 82%; animation: none; }
.card .cliff { font-family: "Bangers", cursive; font-size: clamp(30px, 7vw, 54px); letter-spacing: 2px; color: #fff; animation: shake .4s infinite; }

/* ---------- Cutscene ---------- */
#cutscene { position: absolute; inset: 0; z-index: 5; background: #000; overflow: hidden; animation: pop-dialog .6s ease-out; transition: opacity .45s; }
#cutscene.out { opacity: 0; }
#cutscene img { position: absolute; inset: 0; width: 100%; height: 100%; }
#cutscene .bg { object-fit: cover; filter: blur(16px) brightness(.4); transform: scale(1.15); }
#cutscene .fg { object-fit: contain; animation: kenburns 14s ease-out forwards; }
#cutscene::before, #cutscene::after { content: ''; position: absolute; left: 0; right: 0; height: 9vh; background: #000; z-index: 2; }
#cutscene::before { top: 0; }
#cutscene::after { bottom: 0; }
.cs-text { position: absolute; z-index: 3; top: calc(9vh + 12px); left: 0; right: 0; padding: 0 16px; text-align: center; animation: pop-dialog 1s .3s both; }
.cs-title { font-family: "Bangers", cursive; font-size: clamp(24px, 5vw, 40px); letter-spacing: 2px; color: var(--fire-hot);
  text-shadow: 0 3px 0 var(--ember), 0 0 18px rgba(0,0,0,.9); }
.cs-caption { font-weight: 800; font-size: clamp(14px, 2.6vw, 18px); max-width: 640px; margin: 2px auto 0; text-shadow: 0 2px 6px #000, 0 0 12px #000; }
#dialog { z-index: 6; }
@keyframes kenburns { from { transform: scale(1); } to { transform: scale(1.1) translate(1.5%, -1%); } }

/* Cliffhanger: the rescue photo shakes and fades to dark */
.cliff-still { animation: cliff-shake .12s infinite, cliff-dark 4.8s ease-in forwards; }
@keyframes cliff-shake { 0%, 100% { transform: translate(0, 0); } 25% { transform: translate(-3px, 2px); } 75% { transform: translate(3px, -2px); } }
@keyframes cliff-dark { 0% { filter: brightness(1.1) saturate(1.2); } 55% { filter: brightness(.8) sepia(.35); } 100% { filter: brightness(.12) grayscale(.6); } }

/* ---------- Loading screen ---------- */
.load-bar { width: min(420px, 80vw); height: 16px; margin: 20px auto 8px; border-radius: 8px; overflow: hidden;
  background: rgba(0,0,0,.5); border: 2px solid var(--fire); }
#load-fill { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #ff5a0a, #ffcf3f); box-shadow: 0 0 12px rgba(255,160,40,.8); transition: width .2s; }
.card .load-pct { font-family: "Bangers", cursive; font-size: 24px; letter-spacing: 1px; color: var(--fire-hot); margin: 0 auto; text-align: center; }

/* ---------- Title buttons + Mode Tantangan result ---------- */
.title-actions { display: flex; flex-direction: column; align-items: center; }
.title-actions .best { margin: 10px auto 0; }
.btn.btn-challenge { background: linear-gradient(#7a1c10, #3a0a05); border-color: #ff8a1f; box-shadow: 0 5px 0 #2a0704, 0 0 18px rgba(255,120,30,.45); }
.card.result { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.share-card { width: auto; max-width: 100%; max-height: min(62vh, 640px); border-radius: 16px; box-shadow: 0 12px 40px rgba(0,0,0,.6), 0 0 30px rgba(255,120,30,.35); }
.result-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 10px; }
.result-actions .btn { margin-top: 6px; }

/* ---------- Title credit ---------- */
.credit { position: absolute; left: 0; right: 0; bottom: 14px; text-align: center; padding: 0 16px; font-size: 13px; font-weight: 800; color: var(--muted); }
.credit a { color: var(--fire-hot); text-decoration: none; border-bottom: 1px dashed currentColor; }
.credit a:hover { color: #fff; }

/* ---------- BGM switch + tap-to-start ---------- */
#bgm-btn { position: absolute; top: 10px; right: 12px; z-index: 8; width: 40px; height: 40px; border-radius: 10px; cursor: pointer;
  font-size: 18px; color: var(--ink); background: var(--panel); border: 2px solid var(--fire); display: flex; align-items: center; justify-content: center; }
#bgm-btn.off { border-color: rgba(255,138,31,.35); opacity: .7; }
#bgm-btn.off::after { content: ''; position: absolute; left: 6px; right: 6px; top: 50%; height: 3px; background: #ff5a3c; border-radius: 2px; rotate: -45deg; }
/* invisible layer that catches the first tap anywhere; the pill itself sits in the title column */
.tap-gate { position: fixed; inset: 0; z-index: 6; cursor: pointer; }
.tap-pill { display: inline-block; margin: 14px auto 6px; font-family: "Bangers", cursive; font-size: clamp(22px, 5vw, 32px); letter-spacing: 1.5px;
  color: #fff; padding: 12px 26px; border-radius: 40px; border: 3px solid var(--fire-hot); background: linear-gradient(#ff8a1f, #c4320a);
  box-shadow: 0 0 30px rgba(255,120,30,.7); animation: pulse 1.2s infinite; }
.tap-sub { font-weight: 800; font-size: 13px; color: var(--muted); }
.btn.pop-in { animation: pop .35s cubic-bezier(.2,1.6,.4,1); }

#flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; transition: opacity .6s; z-index: 6; }

@keyframes pop { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes blink { from { opacity: 1; } to { opacity: .35; } }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(255,200,60,.6); } 50% { box-shadow: 0 0 0 12px rgba(255,200,60,0); } }
@keyframes float { 0%, 100% { transform: translateY(0) rotate(-1deg); } 50% { transform: translateY(-8px) rotate(1deg); } }
@keyframes shake { 0%, 100% { transform: translate(0,0); } 25% { transform: translate(-2px,1px); } 75% { transform: translate(2px,-1px); } }
@keyframes pop-dialog { from { opacity: 0; } to { opacity: 1; } }

@media (max-width: 640px) {
  #help { display: none; }
  #hud-stats { min-width: 130px; padding: 6px 8px; }
  #hud-top { top: 86px; width: calc(100% - 24px); }
  #stage-name { display: none; }
  #objective { font-size: 12px; }
  #skill-btn { width: 88px; height: 88px; font-size: 15px; }
  .member { width: 56px; height: 72px; }
  #team { bottom: 116px; }
  #joy { left: 18px; bottom: 22px; width: 124px; height: 124px; }
  #joy-knob { width: 54px; height: 54px; margin: -27px 0 0 -27px; }
  .member canvas { width: 44px; height: 44px; }
  #dialog { bottom: 110px; }
  #dialog-text { font-size: 14px; }
}

/* Landscape phones: short screens need a compact HUD */
@media (max-height: 500px) {
  #hud-stats { padding: 4px 8px; min-width: 130px; }
  #hearts { font-size: 14px; }
  #hud-top { top: 6px; }
  #stage-name { font-size: 15px; }
  #objective { font-size: 11px; padding: 3px 10px; }
  #team { right: 10px; bottom: 94px; gap: 6px; }
  #joy { left: 14px; bottom: 14px; width: 112px; height: 112px; }
  #joy-knob { width: 50px; height: 50px; margin: -25px 0 0 -25px; }
  .member { width: 48px; height: 60px; font-size: 9px; }
  .member canvas { width: 38px; height: 38px; }
  #skill-btn { width: 76px; height: 76px; font-size: 14px; right: 10px; bottom: 10px; }
  #pull-btn { width: 70px; height: 70px; right: 96px; bottom: 14px; font-size: 18px; }
  #dialog { bottom: 74px; padding: 8px; width: min(640px, calc(100% - 24px)); }
  #dialog-face { flex-basis: 50px; height: 50px; }
  #dialog-face canvas { width: 50px; height: 50px; }
  #dialog-name { font-size: 16px; }
  #dialog-text { font-size: 13px; min-height: 0; }
  #screen { align-items: flex-start; padding: 10px 16px; }
  .card h1 { font-size: 34px; }
  .card h2 { font-size: 26px; margin: 2px 0; }
  .card p { font-size: 13px; margin: 4px auto; }
  .logo { width: min(240px, 45%); }
  .still { max-height: 34vh; margin: 2px 0; }
  .btn { font-size: 20px; padding: 6px 22px; margin-top: 6px; }
  .trivia { font-size: 12px; padding: 6px 10px; margin: 6px auto; }
  .poster { padding: 10px 14px 14px; }
  .poster .logo { width: 46%; }
}
