:root {
  --panel: rgba(12, 14, 24, 0.82);
  --panel-edge: rgba(255, 255, 255, 0.12);
  --text: #f3f1ea;
  --muted: #a9adbd;
  --accent: #ffcf4a;
  --hp: #e84a5f;
  --xp: #4ab8ff;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0b0d14; color: var(--text);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif; user-select: none; }
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
canvas#overlay { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.hidden { display: none !important; }

#vignette { position: fixed; inset: 0; pointer-events: none; opacity: 0; transition: opacity 0.25s;
  box-shadow: inset 0 0 160px 40px rgba(255, 0, 30, 0.7); }

/* ─── HUD ─── */
#hud { position: fixed; inset: 0; pointer-events: none; text-shadow: 0 2px 0 rgba(0,0,0,0.6); }
#xpbar { position: absolute; top: 0; left: 0; right: 0; height: 14px; background: rgba(0,0,0,0.55); }
#xpfill { height: 100%; width: 0; background: linear-gradient(90deg, #2a7fff, #6ad8ff); transition: width 0.15s; }
#lvl { position: absolute; left: 50%; top: -1px; transform: translateX(-50%); font-size: 12px; font-weight: bold; }
#topleft { position: absolute; top: 24px; left: 16px; width: 300px; }
.bar { position: relative; height: 22px; background: rgba(0,0,0,0.6); border: 2px solid rgba(255,255,255,0.25); border-radius: 6px; overflow: hidden; }
.bar.hp div { height: 100%; background: linear-gradient(180deg, #ff6a7a, #c42a3f); width: 100%; transition: width 0.1s; }
.bar span { position: absolute; inset: 0; text-align: center; font-size: 13px; line-height: 18px; font-weight: bold; }
.stats-row { display: flex; gap: 14px; margin-top: 6px; font-size: 17px; font-weight: bold; }
#slots { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.slotrow { display: flex; gap: 4px; }
.slot { width: 40px; height: 40px; border-radius: 7px; background: var(--panel); border: 2px solid var(--panel-edge);
  display: flex; align-items: center; justify-content: center; font-size: 22px; position: relative; }
.slot.empty { opacity: 0.35; }
.slot .lv { position: absolute; bottom: -3px; right: 1px; font-size: 11px; font-weight: bold; color: var(--accent); }
.slot.tome { border-color: rgba(120, 180, 255, 0.4); }
#itemrow { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 3px; max-width: 300px; }
#itemrow .it { font-size: 16px; background: var(--panel); border-radius: 5px; padding: 1px 4px; border: 1px solid var(--panel-edge); }
#itemrow .it b { font-size: 10px; color: var(--accent); }

#topcenter { position: absolute; top: 20px; left: 50%; transform: translateX(-50%); text-align: center; width: 520px; }
#stagename { font-size: 15px; color: var(--muted); letter-spacing: 1px; text-transform: uppercase; }
#timer { font-size: 38px; font-weight: bold; letter-spacing: 2px; }
#timer.swarm { color: #ff4a4a; animation: pulse 0.8s infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }
#bossbar { margin-top: 6px; }
#bossname { font-size: 18px; font-weight: bold; margin-bottom: 3px; }
.bar.boss { height: 18px; }
.bar.boss div { height: 100%; width: 100%; background: linear-gradient(180deg, #ff5a3a, #a01a10); transition: width 0.1s; }

#topright { position: absolute; top: 24px; right: 16px; text-align: right; }
#minimap { border-radius: 10px; border: 2px solid rgba(255,255,255,0.3); background: rgba(0,0,0,0.5); display: block; }
#objective { margin-top: 6px; font-size: 13px; max-width: 180px; margin-left: auto; color: #ffe8a0; }

#prompt { position: absolute; left: 50%; bottom: 22%; transform: translateX(-50%); background: var(--panel);
  border: 2px solid var(--panel-edge); padding: 8px 16px; border-radius: 10px; font-size: 17px; white-space: nowrap; }
#prompt kbd, .kbd { background: #fff; color: #111; border-radius: 4px; padding: 0 6px; font-weight: bold; text-shadow: none; margin-right: 6px; }
#toasts { position: absolute; right: 16px; top: 250px; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.toast { background: var(--panel); border-left: 4px solid var(--accent); padding: 7px 12px; border-radius: 6px; font-size: 14px;
  animation: toastin 0.25s ease-out; max-width: 340px; }
@keyframes toastin { from { transform: translateX(40px); opacity: 0; } }
#lockhint { position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); font-size: 13px; color: var(--muted); }

/* ─── Screens / modals ─── */
#screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(6, 8, 14, 0.72); backdrop-filter: blur(3px); overflow-y: auto; padding: 16px; }
.panel { background: var(--panel); border: 2px solid var(--panel-edge); border-radius: 16px; padding: 24px 28px; max-width: 1060px; width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6); max-height: 100%; overflow-y: auto; }
.panel h1 { margin: 0 0 4px; font-size: 44px; letter-spacing: 2px; text-align: center; }
.panel h2 { margin: 0 0 14px; text-align: center; font-size: 28px; }
.panel .sub { text-align: center; color: var(--muted); margin-bottom: 18px; }
.title-logo { font-size: 64px !important; background: linear-gradient(180deg, #ffe07a, #ff8a2a); -webkit-background-clip: text; background-clip: text;
  color: transparent; text-shadow: none; filter: drop-shadow(0 4px 0 #6a2a0a); }
.chars { display: grid; grid-template-columns: repeat(auto-fill, minmax(122px, 1fr)); gap: 8px; margin-bottom: 16px; }
.char { background: rgba(255,255,255,0.05); border: 2px solid var(--panel-edge); border-radius: 12px; padding: 10px; cursor: pointer; text-align: center; }
.char:hover { border-color: rgba(255,255,255,0.4); }
.char.sel { border-color: var(--accent); background: rgba(255, 207, 74, 0.1); }
.char .ic { font-size: 34px; }
.char .nm { font-weight: bold; font-size: 14px; margin-top: 4px; }
.char .pk { font-size: 11px; color: var(--muted); margin-top: 4px; }
.char .best { font-size: 10px; color: var(--accent); margin-top: 4px; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; align-items: center; margin: 10px 0; }
button { font: inherit; font-weight: bold; font-size: 17px; padding: 10px 22px; border-radius: 10px; border: 2px solid rgba(255,255,255,0.2);
  background: #2a2f45; color: var(--text); cursor: pointer; }
button:hover { background: #3a4060; }
button.primary { background: linear-gradient(180deg, #ffcf4a, #e89a1a); color: #2a1a00; border-color: #ffe39a; }
button.primary:hover { filter: brightness(1.1); }
button.sm { font-size: 14px; padding: 6px 14px; }
button.toggle.on { border-color: var(--accent); background: rgba(255, 207, 74, 0.2); }
.cards { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.card { width: 250px; min-height: 200px; background: rgba(255,255,255,0.05); border: 3px solid; border-radius: 14px; padding: 14px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; text-align: center; transition: transform 0.1s; position: relative; }
.card:hover { transform: translateY(-4px) scale(1.02); }
.card .ic { font-size: 44px; margin: 4px 0; }
.card .ttl { font-weight: bold; font-size: 18px; }
.card .tag { font-size: 12px; color: var(--muted); margin-top: 2px; }
.card .rar { font-size: 12px; font-weight: bold; text-transform: uppercase; letter-spacing: 1px; margin-top: 6px; }
.card ul { list-style: none; padding: 0; margin: 10px 0 0; font-size: 14px; }
.card li { margin: 3px 0; }
.card .key { position: absolute; top: 6px; left: 8px; font-size: 12px; color: var(--muted); }
.statgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 4px 18px; font-size: 14px; margin: 12px 0; }
.statgrid div { display: flex; justify-content: space-between; border-bottom: 1px solid rgba(255,255,255,0.06); padding: 2px 0; }
.statgrid b { color: var(--accent); }
.help { font-size: 14px; color: var(--muted); line-height: 1.6; text-align: center; }
.stage-preview { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 8px 0 14px; }
.stage-chip { font-size: 12px; padding: 4px 10px; border-radius: 20px; background: rgba(255,255,255,0.07); border: 1px solid var(--panel-edge); }
.stage-chip.cur { border-color: var(--accent); color: var(--accent); }
.boss-intro { text-align: center; }
.boss-intro .bn { font-size: 40px; font-weight: bold; }
.boss-intro .bt { color: var(--muted); font-size: 16px; }

@media (max-width: 700px) {
  #topleft { width: 200px; }
  #topcenter { width: 60vw; }
  #timer { font-size: 26px; }
  #minimap { width: 110px; height: 110px; }
  .card { width: 100%; min-height: 0; }
  .panel h1 { font-size: 32px; }
}

/* ─── Polish pass ─── */
body.lowhp #vignette { opacity: 0.55 !important; animation: heartbeat 0.9s infinite; }
@keyframes heartbeat { 0%, 100% { opacity: 0.35; } 15% { opacity: 0.8; } 30% { opacity: 0.45; } 45% { opacity: 0.7; } }
.bar.boss { position: relative; }
.bar.boss::after { content: ''; position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; background: rgba(255,255,255,0.6); }

button.big { font-size: 22px; padding: 14px 44px; }
.pill { background: rgba(255,255,255,0.15); border-radius: 20px; padding: 1px 8px; margin-left: 4px; font-size: 14px; }
.muted { color: var(--muted); font-size: 14px; }
.shard { color: #7fe0ff !important; }

.card { animation: cardin 0.28s ease-out both; border-color: var(--rc); }
.card.rar-rare, .card.rar-epic { box-shadow: 0 0 18px -4px var(--rc); }
.card.rar-legendary { box-shadow: 0 0 28px -2px var(--rc); background: linear-gradient(180deg, rgba(255,180,42,0.14), rgba(255,255,255,0.04)); }
@keyframes cardin { from { transform: translateY(24px) scale(0.95); opacity: 0; } }
.card .banish { position: absolute; top: 4px; right: 4px; padding: 0 7px; font-size: 13px; line-height: 22px; border-radius: 6px;
  background: rgba(255, 60, 60, 0.15); border: 1px solid rgba(255, 90, 90, 0.4); color: #ff8a8a; }
.card .banish:hover { background: rgba(255, 60, 60, 0.4); }

.build { display: flex; flex-direction: column; gap: 6px; align-items: center; margin: 10px 0; }
.build > div { display: flex; flex-wrap: wrap; gap: 5px; justify-content: center; }
.bchip { background: rgba(255,255,255,0.06); border: 2px solid var(--panel-edge); border-radius: 8px; padding: 2px 7px; font-size: 20px; }
.bchip b { font-size: 11px; color: var(--accent); margin-left: 2px; }
.bchip.tome { border-color: rgba(120, 180, 255, 0.4); }
.bchip.item { font-size: 17px; }

.shop { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; margin: 10px 0; }
.shopitem { display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,0.05); border: 1px solid var(--panel-edge); border-radius: 10px; padding: 8px 10px; }
.shopitem.maxed { opacity: 0.6; }
.shopitem .ic { font-size: 26px; }
.shopitem .info { flex: 1; display: flex; flex-direction: column; font-size: 13px; }
.shopitem .info span { color: var(--muted); }
.pips { display: flex; gap: 3px; margin-top: 4px; }
.pips i { width: 12px; height: 5px; border-radius: 3px; background: rgba(255,255,255,0.15); }
.pips i.on { background: #7fe0ff; }
button[disabled] { opacity: 0.5; cursor: default; }

.setrow { display: flex; align-items: center; gap: 12px; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid rgba(255,255,255,0.06); }
.setrow input[type=range] { flex: 1; accent-color: var(--accent); }
.setrow b { width: 48px; text-align: right; color: var(--accent); }

/* ─── Touch controls ─── */
#touch { position: fixed; inset: 0; pointer-events: none; z-index: 5; touch-action: none; }
#tz-left, #tz-right { position: absolute; top: 0; bottom: 0; pointer-events: auto; touch-action: none; }
#tz-left { left: 0; width: 45%; }
#tz-right { right: 0; width: 55%; }
#joy { position: absolute; width: 120px; height: 120px; border-radius: 50%; border: 3px solid rgba(255,255,255,0.35);
  background: rgba(0,0,0,0.2); opacity: 0; pointer-events: none; transition: opacity 0.15s; }
#joy.on { opacity: 1; }
#knob { position: absolute; left: 35px; top: 35px; width: 50px; height: 50px; border-radius: 50%; background: rgba(255,255,255,0.55); }
.tbtn { position: absolute; pointer-events: auto; width: 74px; height: 74px; border-radius: 50%; padding: 0; font-size: 26px;
  background: rgba(20, 24, 40, 0.55); border: 2px solid rgba(255,255,255,0.35); display: flex; flex-direction: column; align-items: center; justify-content: center; touch-action: none; }
.tbtn small { font-size: 9px; letter-spacing: 1px; }
.tbtn.down { background: rgba(255, 207, 74, 0.45); }
#tb-jump { right: calc(24px + env(safe-area-inset-right)); bottom: calc(30px + env(safe-area-inset-bottom)); width: 88px; height: 88px; }
#tb-slide { right: calc(120px + env(safe-area-inset-right)); bottom: calc(110px + env(safe-area-inset-bottom)); }
#tb-act { right: calc(210px + env(safe-area-inset-right)); bottom: calc(24px + env(safe-area-inset-bottom)); }
#tb-pause { left: 50%; transform: translateX(-50%); bottom: calc(10px + env(safe-area-inset-bottom)); width: 46px; height: 46px; font-size: 16px; }
#tb-pause.down { transform: translateX(-50%); }
@media (pointer: coarse) {
  #lockhint { display: none !important; }
  #topleft { left: calc(12px + env(safe-area-inset-left)); }
  #topright { right: calc(12px + env(safe-area-inset-right)); }
  #prompt { bottom: 40%; }
  #objective { display: none; }
  #toasts { top: auto; bottom: 45%; }
}
@media (max-height: 500px) {
  #topleft { transform: scale(0.8); transform-origin: top left; }
  #topright { transform: scale(0.75); transform-origin: top right; }
  #topcenter { transform: translateX(-50%) scale(0.8); transform-origin: top center; }
  .panel { padding: 14px 16px; }
  .panel h1 { font-size: 30px; }
  .title-logo { font-size: 40px !important; }
}

/* ─── Live content: modes, events, patch notes ─── */
.newbadge { display: inline-block; background: linear-gradient(180deg, #ff6ad8, #b04aff); color: #fff; font-size: 10px; font-weight: bold;
  padding: 1px 6px; border-radius: 6px; letter-spacing: 1px; vertical-align: middle; }
.char { position: relative; }
.char .newbadge { position: absolute; top: 6px; right: 6px; }
.char.locked { opacity: 0.35; cursor: default; }
.modes button { min-width: 150px; }
.modeinfo { text-align: center; background: rgba(200, 154, 255, 0.08); border: 1px solid rgba(200, 154, 255, 0.35); border-radius: 12px;
  padding: 10px 14px; margin: 6px auto 12px; max-width: 760px; font-size: 14px; }
.muts { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 8px 0 4px; }
.muts.center { margin: 4px 0 8px; }
.mut { background: rgba(0,0,0,0.35); border: 1px solid rgba(255,255,255,0.18); border-radius: 20px; padding: 3px 10px; font-size: 13px; }
#hudmuts { font-size: 18px; letter-spacing: 4px; min-height: 4px; }
.version { text-align: center; color: var(--muted); font-size: 12px; margin-top: 8px; }
.patch { background: rgba(255,255,255,0.04); border: 1px solid var(--panel-edge); border-radius: 10px; padding: 10px 14px; margin: 8px 0; }
.patch.latest { border-color: rgba(200, 154, 255, 0.5); }
.patch .ph { display: flex; justify-content: space-between; gap: 10px; }
.patch ul { margin: 6px 0 0; padding-left: 20px; font-size: 14px; line-height: 1.55; }
.heat { gap: 8px; }
.heatnum { display: inline-block; min-width: 34px; text-align: center; font-size: 22px; color: #ff8a3a; text-shadow: 0 0 10px rgba(255,120,40,0.6); }
.heatlist { columns: 2; max-width: 640px; margin: 0 auto 8px; font-size: 12px; color: #ffb48a; list-style: none; padding: 0; text-align: left; }
.achs { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 8px; margin: 10px 0; }
.ach { display: flex; gap: 10px; align-items: center; background: rgba(255,255,255,0.04); border: 1px solid var(--panel-edge); border-radius: 10px; padding: 8px 10px; opacity: 0.6; }
.ach.done { opacity: 1; border-color: rgba(255, 210, 74, 0.55); background: rgba(255, 210, 74, 0.07); }
.ach .ic { font-size: 26px; }
.ach .info { display: flex; flex-direction: column; font-size: 13px; }
.ach .info span { color: var(--muted); }
.ach .info em { color: #7fe0ff; font-style: normal; font-size: 12px; }
.ach .info small { color: var(--accent); font-size: 11px; }
table.board { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 14px; }
table.board th, table.board td { padding: 5px 8px; text-align: left; border-bottom: 1px solid rgba(255,255,255,0.07); }
table.board th { color: var(--muted); font-weight: normal; }
table.board tr.me td { color: var(--accent); font-weight: bold; }
#pname { font: inherit; padding: 6px 10px; border-radius: 8px; border: 2px solid rgba(255,255,255,0.2); background: #1a1d2e; color: var(--text); width: 180px; user-select: text; }
