:root {
  --font: "Arial Black", "Trebuchet MS", system-ui, sans-serif;
  --ink: #16202e;
  --cream: #fff4dc;
  --cyan: #5ff2ff;
  --brass: #f2b450;
  --panel-img: none;
  --button-img: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; background: #e9b48c; touch-action: none; user-select: none; -webkit-user-select: none; }
body { font-family: var(--font); color: var(--cream); }
#stage { position: fixed; inset: 0; }
#stage canvas { display: block; width: 100%; height: 100%; }
.hidden { display: none !important; }

.ol {
  text-shadow: 2px 0 0 var(--ink), -2px 0 0 var(--ink), 0 2px 0 var(--ink), 0 -2px 0 var(--ink),
    1.5px 1.5px 0 var(--ink), -1.5px 1.5px 0 var(--ink), 1.5px -1.5px 0 var(--ink), -1.5px -1.5px 0 var(--ink), 0 4px 0 rgba(0,0,0,.35);
}

/* panels drawn from ui-panel as a 9-slice */
.panel {
  background: rgba(22, 40, 52, 0.72);
  border: 3px solid #e2a54a;
  border-radius: 14px;
  box-shadow: 0 4px 0 rgba(0,0,0,.3);
}
.npanel {
  border-style: solid; border-color: transparent; border-width: 30px;
  border-image-source: var(--panel-img); border-image-slice: var(--panel-slice, 60) fill; border-image-width: 44px; border-image-repeat: stretch;
  background: transparent;
}
.npanel.noimg { background: rgba(22, 40, 52, 0.95); border: 4px solid #e2a54a; border-radius: 18px; }

.gbtn {
  font-family: var(--font); font-weight: 900; font-size: 18px; color: var(--cream);
  min-height: 52px; min-width: 120px; padding: 6px 26px; cursor: pointer; outline: none;
  border-style: solid; border-color: transparent; border-width: 6px;
  border-image-source: var(--button-img); border-image-slice: var(--button-slice, 40) fill; border-image-width: 22px; border-image-repeat: stretch;
  background: transparent;
  text-shadow: 2px 0 0 var(--ink), -2px 0 0 var(--ink), 0 2px 0 var(--ink), 0 -2px 0 var(--ink), 0 3px 0 rgba(0,0,0,.4);
  transition: transform .09s ease-out, filter .12s;
  -webkit-tap-highlight-color: transparent;
}
.gbtn.noimg { background: linear-gradient(#f4c66b, #c98a2e); border: 3px solid #6b4316; border-radius: 14px; }
.gbtn:hover, .gbtn.focus { filter: brightness(1.15) drop-shadow(0 0 6px var(--cyan)); transform: scale(1.05); }
.gbtn:active { transform: scale(0.94); }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#xpTop { position: absolute; left: 0; right: 0; top: 0; height: 8px; background: rgba(10, 20, 30, .55); border-bottom: 2px solid var(--ink); }
#xpFill { height: 100%; width: 0%; background: linear-gradient(90deg, #7ff6ff, #b48cff); box-shadow: 0 0 8px #7ff6ff; transition: width .15s; }
#lvNum { position: absolute; left: 50%; top: 2px; transform: translateX(-50%); font-size: 14px; font-weight: 900; color: #d9f9ff; line-height: 1; padding: 2px 10px; }
#hudLeft { position: absolute; left: calc(12px + env(safe-area-inset-left, 0px)); top: 16px; padding: 8px 12px; display: flex; flex-direction: column; gap: 6px; }
.hudRow { display: flex; align-items: center; gap: 8px; }
.bar { width: 170px; height: 18px; border-radius: 9px; background: rgba(0,0,0,.5); border: 2px solid var(--ink); overflow: hidden; }
.bar.small { width: 90px; height: 12px; }
.fill { height: 100%; width: 100%; transition: width .12s; }
.fill.hp { background: linear-gradient(#8ff7a8, #2dbb63); }
.fill.hp.low { background: linear-gradient(#ffb0a0, #e5432f); animation: lowhp .6s ease-in-out infinite alternate; }
@keyframes lowhp { from { filter: brightness(1); } to { filter: brightness(1.5); } }
.fill.pulse { background: linear-gradient(#a9f6ff, #2ab8e8); }
.fill.pulse.ready { background: linear-gradient(#fff, #5ff2ff); box-shadow: 0 0 10px #5ff2ff; }
.fill.bossf { background: linear-gradient(#ffb36b, #d8452c); }
.num { font-weight: 900; font-size: 20px; color: var(--cream); min-width: 36px;
  text-shadow: 2px 0 0 var(--ink), -2px 0 0 var(--ink), 0 2px 0 var(--ink), 0 -2px 0 var(--ink), 0 3px 0 rgba(0,0,0,.35); }
.icon { width: 22px; height: 22px; flex: 0 0 auto; }
.icon.heart { background: #ff5d6c; clip-path: polygon(50% 92%, 6% 46%, 6% 22%, 24% 8%, 50% 26%, 76% 8%, 94% 22%, 94% 46%); filter: drop-shadow(0 2px 0 #000); }
.icon.bolt { background: var(--cyan); clip-path: polygon(58% 0, 14% 58%, 46% 58%, 36% 100%, 86% 38%, 54% 38%); }
.icon.gear { background: var(--brass); border-radius: 50%; box-shadow: inset 0 0 0 6px #b77a26, 0 2px 0 #000; margin-left: 8px; }
.icon.core { background: var(--cyan); transform: rotate(45deg) scale(.8); box-shadow: 0 0 10px var(--cyan), inset 0 0 0 4px #1aa6c2; }
#loadout { display: flex; gap: 4px; flex-wrap: wrap; max-width: 250px; }
#loadout:empty { display: none; }
.slot { position: relative; width: 30px; height: 30px; border-radius: 8px; background: rgba(0,0,0,.35); border: 2px solid rgba(242,180,80,.7); }
.slot.pas { border-color: rgba(95, 242, 255, .8); border-radius: 50%; background: rgba(10, 40, 50, .45); }
.slot img { width: 100%; height: 100%; object-fit: contain; }
.slot b { position: absolute; right: -4px; bottom: -5px; font-size: 12px; color: #fff;
  text-shadow: 1px 0 0 var(--ink), -1px 0 0 var(--ink), 0 1px 0 var(--ink), 0 -1px 0 var(--ink); }

#hudCenter { position: absolute; left: 50%; top: 22px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 4px; }
#topRow { display: flex; align-items: center; gap: 10px; }
#timer { font-size: 22px; }
#fragBox { display: flex; align-items: center; gap: 10px; padding: 4px 16px; }
#objective { font-size: 15px; font-weight: 800; color: #ffe9b8; white-space: nowrap; }
#bossBar { display: flex; flex-direction: column; align-items: center; gap: 2px; margin-top: 2px; }
#bossName { font-size: 16px; font-weight: 900; color: #ffcf9c; }
.bar.boss { width: min(420px, 46vw); height: 16px; }

#beaconArrow { position: absolute; left: 0; top: 0; width: 64px; height: 64px; margin: -32px 0 0 -32px; display: flex; align-items: center; justify-content: center; --ac: var(--cyan); }
#beaconArrow.npc { --ac: #ffd25a; }
#beaconArrow .arrowHead { position: absolute; width: 0; height: 0; border-left: 14px solid transparent; border-right: 14px solid transparent; border-bottom: 26px solid var(--ac); filter: drop-shadow(0 0 6px var(--ac)) drop-shadow(0 2px 0 #000); top: 0; }
#beaconDist { position: absolute; top: 30px; font-size: 14px; font-weight: 900; color: var(--ac); }

#subtitle { position: absolute; left: 50%; top: 24%; transform: translateX(-50%); max-width: min(680px, 70vw); text-align: center; font-size: 19px; font-weight: 800; color: #fff;
  background: rgba(10, 20, 30, .55); padding: 8px 18px; border-radius: 12px; }
#banner { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); font-size: clamp(24px, 4.5vw, 54px); font-weight: 900; color: #ffcf6b; white-space: nowrap; letter-spacing: .04em; }
#banner.show { animation: slam .45s cubic-bezier(.34,1.56,.64,1); }
@keyframes slam { from { transform: translate(-50%, -50%) scale(2.2); opacity: 0; } to { transform: translate(-50%, -50%) scale(1); opacity: 1; } }
#hint { position: absolute; left: 50%; top: 33%; transform: translateX(-50%); font-size: 16px; font-weight: 800; color: #fff; text-align: center; max-width: 72vw; background: rgba(10,20,30,.5); padding: 6px 14px; border-radius: 10px; }

/* Title */
#title { position: fixed; inset: 0; z-index: 20; overflow: hidden; background: #e9b48c; }
#titleBg { position: absolute; inset: -3%; background: url("assets/title-bg.webp") center / cover no-repeat; animation: drift 18s ease-in-out infinite alternate; }
#title::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 36%; background: linear-gradient(rgba(30, 14, 8, 0), rgba(30, 14, 8, .6)); pointer-events: none; z-index: 1; }
@keyframes drift { from { transform: scale(1.02) translate(0, 0); } to { transform: scale(1.07) translate(-1.2%, .6%); } }
#titleLogo { position: absolute; left: 50%; top: 4%; width: min(62vw, 760px); max-height: 32vh; object-fit: contain; transform: translateX(-50%); filter: drop-shadow(0 6px 0 rgba(40,20,10,.35)); z-index: 2; }
#titleLogo.enter { animation: logoIn .6s cubic-bezier(.34,1.56,.64,1) both, float 4s ease-in-out .6s infinite; }
@keyframes logoIn { from { transform: translateX(-50%) translateY(-60px) scale(.6); opacity: 0; } to { transform: translateX(-50%) scale(1); opacity: 1; } }
@keyframes float { 0%,100% { transform: translateX(-50%) translateY(0); } 50% { transform: translateX(-50%) translateY(-6px); } }
#titleBottom { position: absolute; left: 50%; bottom: 6%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 10px; z-index: 3; }
#pressStart { font-size: clamp(18px, 2.6vw, 28px); font-weight: 900; color: #fff; animation: pulse 1.6s ease-in-out infinite; white-space: nowrap; }
@keyframes pulse { 0%,100% { opacity: 1; transform: scale(1); } 50% { opacity: .7; transform: scale(.96); } }
#kbHint { font-size: 14px; font-weight: 800; color: #ffe9c8; white-space: nowrap; }
#lbBtn { display: flex; align-items: center; gap: 8px; font-size: 16px; min-height: 48px; }
.trophy { width: 20px; height: 20px; background: var(--brass); clip-path: polygon(10% 0, 90% 0, 90% 30%, 66% 58%, 60% 72%, 78% 84%, 78% 100%, 22% 100%, 22% 84%, 40% 72%, 34% 58%, 10% 30%); }

/* Intro */
#introWrap { position: fixed; inset: 0; z-index: 40; background: #000 url("assets/title-bg.webp") center / cover no-repeat; }
#introVid { width: 100%; height: 100%; object-fit: cover; background: transparent; }
#skipBtn { position: absolute; right: calc(16px + env(safe-area-inset-right, 0px)); top: 14px; min-width: 96px; }

/* Level up */
#levelUp { position: fixed; inset: 0; z-index: 28; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  background: radial-gradient(ellipse at center, rgba(20, 40, 60, .55), rgba(8, 14, 22, .85)); padding: 10px; }
#luTitle { font-size: clamp(30px, 5vw, 56px); font-weight: 900; color: #ffd27a; animation: slamIn .45s cubic-bezier(.34,1.56,.64,1); letter-spacing: .04em; }
@keyframes slamIn { from { transform: scale(2); opacity: 0; } to { transform: scale(1); opacity: 1; } }
#luSub { font-size: 16px; font-weight: 800; color: #d9f9ff; margin-bottom: 6px; }
#luCards { display: flex; gap: 14px; justify-content: center; align-items: stretch; }
.card { position: relative; width: 230px; min-height: 250px; padding: 4px 6px; display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; cursor: pointer;
  border-width: 26px; transition: transform .12s ease-out, filter .12s; animation: cardIn .35s cubic-bezier(.34,1.56,.64,1) both; }
.card:nth-child(2) { animation-delay: .07s; }
.card:nth-child(3) { animation-delay: .14s; }
@keyframes cardIn { from { transform: translateY(40px) scale(.8); opacity: 0; } to { transform: none; opacity: 1; } }
.card.focus { transform: translateY(-6px) scale(1.05); filter: brightness(1.12) drop-shadow(0 0 10px var(--cyan)); }
.card:active { transform: scale(.95); }
.card img { width: 84px; height: 84px; object-fit: contain; filter: drop-shadow(0 3px 0 rgba(0,0,0,.35)); }
.card .cname { font-size: 18px; font-weight: 900; color: #ffd27a; line-height: 1.15; }
.card .ctag { font-size: 13px; font-weight: 900; color: var(--cyan); }
.card .ctag.new { color: #ff9a6b; }
.card .cdesc { font-family: system-ui, sans-serif; font-size: 14px; font-weight: 700; color: #f4f1e8; line-height: 1.35; }
.card .pips { display: flex; gap: 3px; margin-top: auto; }
.card .pips i { width: 12px; height: 12px; border-radius: 3px; background: rgba(0,0,0,.45); border: 1px solid #b77a26; }
.card .pips i.on { background: var(--brass); }
.card .pips i.next { background: var(--cyan); animation: lowhp .5s ease-in-out infinite alternate; }

/* Survivor dialogue */
#dialog { position: fixed; inset: 0; z-index: 29; display: flex; align-items: center; justify-content: center; background: rgba(10, 16, 24, .6); padding: 10px; }
#dlgPanel { width: min(900px, 96vw); max-height: 96%; display: flex; gap: 14px; align-items: center; animation: pop .28s cubic-bezier(.34,1.56,.64,1); }
#dlgPanel.noart { width: min(620px, 94vw); }
#dlgImg { width: 30%; max-height: 62vh; object-fit: contain; flex: 0 0 auto; filter: drop-shadow(0 6px 0 rgba(0,0,0,.3)); animation: float2 3s ease-in-out infinite; }
@keyframes float2 { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
#dlgMain { flex: 1 1 auto; display: flex; flex-direction: column; gap: 6px; min-width: 0; max-height: 80vh; }
#dlgKicker { font-size: 13px; font-weight: 900; color: #ffd25a; letter-spacing: .1em; }
#dlgName { font-size: clamp(20px, 2.8vw, 28px); font-weight: 900; color: #ffd27a; }
#dlgText { font-family: system-ui, sans-serif; font-size: 16px; line-height: 1.55; font-weight: 600; color: #f4f1e8; overflow-y: auto; white-space: pre-line; padding-right: 4px; }
#dlgChoices { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
#dlgChoices .gbtn { white-space: normal; text-align: left; font-size: 15px; line-height: 1.3; padding: 8px 18px; width: 100%; }
#dlgChoices .gbtn.focus { transform: scale(1.02); }

/* Modal */
#modal { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; background: rgba(10, 16, 24, .55); padding: 12px; }
#modalPanel { width: min(620px, 92vw); max-height: 92%; display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; animation: pop .28s cubic-bezier(.34,1.56,.64,1); overflow: hidden; }
#modalPanel[data-mood="good"] { filter: drop-shadow(0 0 22px rgba(150, 235, 255, .6)); }
#modalPanel[data-mood="bad"] { filter: drop-shadow(0 0 22px rgba(255, 110, 60, .6)); }
@keyframes pop { from { transform: scale(.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
#modalKicker { font-size: 14px; font-weight: 900; color: var(--cyan); letter-spacing: .1em; }
#modalTitle { font-size: clamp(22px, 3.2vw, 32px); font-weight: 900; color: #ffd27a; }
#modalBody { font-family: system-ui, sans-serif; font-size: 17px; line-height: 1.55; color: #f4f1e8; overflow-y: auto; max-height: 50vh; padding: 0 6px; text-align: left; width: 100%; font-weight: 600; }
#modalBody p { margin: 0 0 8px; }
#modalBody .locked { opacity: .5; }
#modalBody b { color: #ffd27a; }
#modalBody .hum { text-align: center; color: #ffd25a; font-weight: 900; }
#modalBody .voice { text-align: center; font-style: italic; color: var(--cyan); font-weight: 800; font-size: 1.05em; margin-bottom: 12px; }
#modalBody .met { border-left: 4px solid #ffd25a; padding-left: 10px; }
#modalBtn { margin-top: 6px; min-width: 160px; }

#fade { position: fixed; inset: 0; z-index: 50; background: #1a1410; opacity: 0; pointer-events: none; transition: opacity .35s; }
#fade.on { opacity: 1; }

@media (max-height: 460px) {
  .bar { width: 120px; height: 14px; }
  .bar.small { width: 64px; height: 10px; }
  .num { font-size: 16px; }
  #timer { font-size: 17px; }
  #hudLeft { padding: 5px 9px; gap: 4px; top: 14px; }
  #loadout { max-width: 190px; }
  .slot { width: 24px; height: 24px; }
  #objective { font-size: 13px; }
  #hudCenter { top: 18px; }
  #modalBody { font-size: 15px; max-height: 46vh; }
  #modalPanel { border-width: 22px; }
  #subtitle { font-size: 16px; }
  .gbtn { font-size: 16px; min-height: 46px; }
  #kbHint { display: none; }
  #luTitle { font-size: 28px; }
  #luSub { font-size: 14px; margin-bottom: 2px; }
  .card { width: 196px; min-height: 0; border-width: 20px; gap: 2px; }
  .card img { width: 52px; height: 52px; }
  .card .cname { font-size: 16px; }
  .card .cdesc { font-size: 13px; }
  #dlgPanel { border-width: 22px; gap: 8px; }
  #dlgImg { width: 24%; max-height: 70vh; }
  #dlgText { font-size: 14px; line-height: 1.45; }
  #dlgChoices .gbtn { font-size: 14px; min-height: 44px; padding: 5px 14px; }
  #dlgMain { max-height: 88vh; }
}
