:root {
  --ink: #0e1424; --ink2: #18203a; --paper: #fff4e0; --muted: #a9b2cf;
  --hot: #ff4d6d; --warm: #ffc04d; --good: #58f0b0; --gold: #ffd166; --vermilion: #ff6a3d;
  --safe-top: 0px; --host-top: 0px; --host-side: 0px;
  --r: 18px;
  font-family: "Nunito", ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
}
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; background: var(--ink); color: var(--paper); }
* { box-sizing: border-box; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
button:focus-visible { outline: 3px solid var(--warm); outline-offset: 3px; }

#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#vignette { position: fixed; inset: 0; pointer-events: none; box-shadow: inset 0 0 0 0 rgba(255, 40, 70, 0); transition: box-shadow .25s; }
#vignette.hurt { box-shadow: inset 0 0 90px 30px rgba(255, 40, 70, .55); transition: none; }
#vignette.low { animation: lowhp 1.1s ease-in-out infinite; }
#vignette.alarm { box-shadow: inset 0 0 70px 10px rgba(255, 40, 70, .35); animation: alarm .6s steps(2) infinite; }
@keyframes lowhp { 50% { box-shadow: inset 0 0 70px 20px rgba(255, 40, 70, .35); } }
@keyframes alarm { 50% { box-shadow: inset 0 0 40px 4px rgba(255, 40, 70, .15); } }

/* ---------------- HUD */
#hud { position: fixed; left: 0; right: 0; top: 0; padding: calc(var(--safe-top) + var(--host-top) + 10px) max(12px, env(safe-area-inset-right, 0px)) 0 max(12px, env(safe-area-inset-left, 0px)); display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 8px; pointer-events: none; }
.hud-left { display: flex; min-width: 0; }
.hud-mid { min-width: 0; justify-self: center; max-width: 100%; }
.hud-right { display: flex; justify-content: flex-end; align-items: center; gap: 8px; }
.hpbar { position: relative; width: 150px; max-width: 100%; height: 18px; border-radius: 10px; background: rgba(8, 10, 22, .65); box-shadow: 0 0 0 2px rgba(255, 244, 224, .14); overflow: hidden; }
.hpbar i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 10px; }
.hpbar .lag { background: #fff; opacity: .55; transition: width .5s .25s; z-index: 1; }
.hpbar .fill { background: linear-gradient(180deg, #ff7a5c, #ff3b5c); z-index: 2; transition: width .12s; }
.hpbar .armor { background: linear-gradient(180deg, #d9e2ec, #8d99ae); z-index: 3; height: 5px; top: auto; bottom: 0; }
.hpbar .hpnum { position: absolute; inset: 0; z-index: 4; display: grid; place-items: center; font-size: 11px; font-weight: 900; letter-spacing: .03em; text-shadow: 0 1px 2px rgba(0,0,0,.6); }
.progress { display: flex; align-items: center; gap: 9px; padding: 5px 10px 5px 12px; border-radius: 99px; background: rgba(8, 10, 22, .55); }
.floor-n { flex: none; font-size: 13px; font-weight: 900; letter-spacing: .01em; white-space: nowrap; font-variant-numeric: tabular-nums; }
.floor-n:empty { display: none; }
.nodes { display: flex; flex-wrap: wrap; justify-content: center; gap: 5px; align-items: center; }
.nodes i { flex: none; width: 8px; height: 8px; border-radius: 50%; background: rgba(255, 244, 224, .25); display: block; }
.nodes i.done { background: var(--good); }
.nodes i.now { background: var(--paper); box-shadow: 0 0 0 3px rgba(255, 244, 224, .25); width: 10px; height: 10px; }
.nodes i.shop { border-radius: 2px; transform: rotate(45deg); width: 7px; height: 7px; }
.nodes i.boss { width: 12px; height: 12px; background: var(--hot); clip-path: polygon(50% 0, 100% 38%, 82% 100%, 18% 100%, 0 38%); border-radius: 0; }
.nodes i.boss.done { background: var(--good); }
.nodes i.mini { background: var(--warm); }
.nodes i.mini.done { background: var(--good); }
.coins { display: flex; align-items: center; gap: 5px; padding: 5px 10px 5px 6px; border-radius: 99px; background: rgba(8, 10, 22, .55); font-weight: 900; font-size: 14px; font-variant-numeric: tabular-nums; }
.coins.bump { animation: bump .25s; }
@keyframes bump { 40% { transform: scale(1.12); } }
.coin-ic { flex: none; width: 16px; height: 16px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fff2b8, var(--gold) 55%, #c98a1a); box-shadow: 0 0 0 2px rgba(201, 138, 26, .4); }
.icon-btn { flex: none; pointer-events: auto; width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; background: rgba(8, 10, 22, .55); }
.icon-btn svg { width: 20px; height: 20px; fill: var(--paper); }
.icon-btn:active { transform: scale(.94); }

#bossbar { position: fixed; left: 50%; transform: translateX(-50%); top: calc(var(--safe-top) + var(--host-top) + 66px); pointer-events: none; }
#bossbar .pips { display: flex; gap: 5px; padding: 6px 8px; border-radius: 99px; background: rgba(8, 10, 22, .6); }
#bossbar .pips i { width: 26px; height: 9px; border-radius: 5px; background: var(--hot); box-shadow: 0 0 10px rgba(255, 77, 109, .6); transition: background .2s, box-shadow .2s, transform .2s; }
#bossbar .pips i.gone { background: rgba(255,244,224,.14); box-shadow: none; transform: scaleY(.6); }
#bossbar.mini .pips i { width: 16px; background: var(--warm); box-shadow: 0 0 10px rgba(255, 192, 77, .5); }
#bossbar.mini .pips i.gone { background: rgba(255,244,224,.14); box-shadow: none; }

/* The HUD sits below host controls; only physical safe areas need side gutters.
   Put progress on its own row before its intrinsic width can push Pause offscreen. */
@media (max-width: 600px) {
  #hud { grid-template-columns: minmax(0, 1fr) auto; gap: 6px 12px; }
  .hud-left { grid-column: 1; grid-row: 1; }
  .hud-right { grid-column: 2; grid-row: 1; }
  .hud-mid { grid-column: 1 / -1; grid-row: 2; }
  #bossbar { top: calc(var(--safe-top) + var(--host-top) + 94px); }
}

/* ---------------- joystick */
#stick { position: fixed; left: 0; top: 0; width: 0; height: 0; pointer-events: none; opacity: 0; transition: opacity .12s; }
#stick.on { opacity: 1; }
#stick .base { position: absolute; width: 112px; height: 112px; left: -56px; top: -56px; border-radius: 50%; border: 2px solid rgba(255, 244, 224, .22); background: radial-gradient(circle, rgba(255,244,224,.06), rgba(255,244,224,.02)); }
#stick .knob { position: absolute; left: 0; top: 0; width: 52px; height: 52px; border-radius: 50%; background: rgba(255, 244, 224, .55); box-shadow: 0 4px 14px rgba(0,0,0,.35); transform: translate(-50%, -50%); }

/* ---------------- announcements */
#announce { position: fixed; left: 0; right: 0; top: 30%; display: grid; place-items: center; pointer-events: none; }
#announce .a { font-weight: 1000; font-size: clamp(34px, 11vw, 64px); letter-spacing: .02em; text-shadow: 0 4px 0 rgba(0,0,0,.35); animation: pop .9s cubic-bezier(.2, 1.6, .4, 1) both; white-space: nowrap; }
#announce .a.small { font-size: clamp(18px, 5vw, 26px); font-weight: 900; }
#announce .a.hot { color: var(--hot); } #announce .a.gold { color: var(--gold); } #announce .a.good { color: var(--good); } #announce .a.warm { color: var(--warm); }
#announce .sub { display: block; text-align: center; font-size: .34em; font-weight: 800; color: var(--muted); letter-spacing: .08em; margin-top: 2px; }
@keyframes pop { 0% { transform: scale(.4); opacity: 0; } 18% { transform: scale(1.08); opacity: 1; } 70% { transform: scale(1); opacity: 1; } 100% { transform: scale(1) translateY(-12px); opacity: 0; } }
#toast { position: fixed; left: 50%; bottom: calc(26px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); pointer-events: none; }
#toast .t { padding: 10px 16px; border-radius: 14px; background: rgba(8, 10, 22, .82); font-weight: 800; font-size: 14px; white-space: nowrap; animation: toast 3.2s both; box-shadow: 0 0 0 2px rgba(255,244,224,.08); }
@keyframes toast { 0% { opacity: 0; transform: translateY(10px); } 10%, 85% { opacity: 1; transform: none; } 100% { opacity: 0; } }
#hint { position: fixed; left: 50%; bottom: 22%; transform: translateX(-50%); pointer-events: none; text-align: center; font-weight: 900; font-size: 16px; color: var(--paper); opacity: .9; }
#hint .hand { width: 46px; height: 46px; margin: 0 auto 10px; border-radius: 50%; background: rgba(255,244,224,.85); animation: drag 1.6s ease-in-out infinite; box-shadow: 0 0 0 10px rgba(255,244,224,.12); }
@keyframes drag { 0%, 100% { transform: translateX(-40px); } 50% { transform: translateX(40px); } }

/* ---------------- sheets */
#sheet { position: fixed; inset: 0; display: grid; place-items: end center; background: rgba(6, 8, 18, .55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); animation: fade .2s; padding: calc(var(--safe-top) + var(--host-top) + 12px) 12px calc(12px + env(safe-area-inset-bottom, 0px)); }
#sheet.center { place-items: center; }
@keyframes fade { from { opacity: 0; } }
.card { width: min(100%, 440px); max-height: 100%; overflow: auto; background: linear-gradient(180deg, #1c2443, #141a33); border-radius: 26px; padding: 22px 18px 18px; box-shadow: 0 0 0 2px rgba(255, 244, 224, .08), 0 20px 60px rgba(0,0,0,.5); animation: rise .28s cubic-bezier(.2, 1.3, .4, 1); }
@keyframes rise { from { transform: translateY(30px); opacity: 0; } }
.card h2 { margin: 0 0 4px; font-size: 26px; font-weight: 1000; text-align: center; letter-spacing: .01em; }
.card .sub { margin: 0 0 14px; text-align: center; color: var(--muted); font-weight: 700; font-size: 14px; }
.btn { display: block; width: 100%; padding: 15px; border-radius: 16px; font-weight: 900; font-size: 17px; text-align: center; background: var(--paper); color: var(--ink); box-shadow: 0 4px 0 #c9b48f; margin-top: 10px; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #c9b48f; }
.btn.hot { background: var(--vermilion); color: #fff; box-shadow: 0 4px 0 #b8401f; }
.btn.ghost { background: rgba(255, 244, 224, .08); color: var(--paper); box-shadow: none; font-size: 15px; padding: 12px; }
.btn[disabled] { opacity: .45; }
.btn.gold { background: var(--gold); color: var(--ink); box-shadow: 0 4px 0 #c79a2c; }
.btn.choice { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 12px 14px; }
.btn.choice .ttl { font-size: 17px; font-weight: 900; }
.btn.choice .dtl { font-size: 13px; font-weight: 700; opacity: .82; }

.offers { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.offer { position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 6px 10px; border-radius: 18px; background: rgba(255, 244, 224, .06); box-shadow: 0 0 0 2px rgba(255,244,224,.08); min-height: 168px; }
.offer.r1 { box-shadow: 0 0 0 2px rgba(127, 214, 255, .45); }
.offer.r2 { box-shadow: 0 0 0 2px rgba(255, 192, 77, .7); background: rgba(255, 192, 77, .08); }
.offer .ic { width: 58px; height: 58px; border-radius: 16px; display: grid; place-items: center; background: rgba(255,244,224,.08); }
.offer .ic svg { width: 40px; height: 40px; }
.offer b { font-size: 14px; font-weight: 900; text-align: center; line-height: 1.1; }
.offer small { font-size: 11.5px; color: var(--muted); font-weight: 700; text-align: center; line-height: 1.2; min-height: 2.4em; }
.offer .price { margin-top: auto; display: flex; align-items: center; gap: 4px; padding: 6px 10px; border-radius: 99px; background: var(--paper); color: var(--ink); font-weight: 900; font-size: 14px; }
.offer .price .coin-ic { width: 13px; height: 13px; }
.offer.cant .price { background: rgba(255,244,224,.2); color: var(--muted); }
.offer.sold { opacity: .35; pointer-events: none; }
.offer:active { transform: scale(.97); }
.purse { display: flex; justify-content: center; margin-bottom: 12px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 4px 0 12px; }
.stat { text-align: center; padding: 10px 2px; border-radius: 14px; background: rgba(255,244,224,.06); }
.stat b { display: block; font-size: 20px; font-weight: 1000; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; color: var(--muted); font-weight: 800; }
.reward { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 30px; font-weight: 1000; color: var(--gold); margin: 6px 0 10px; }
.mark-ic { width: 24px; height: 24px; background: var(--gold); clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); }

.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 4px; border-radius: 14px; background: rgba(255,244,224,.06); margin-bottom: 8px; }
.tabs button { padding: 9px; border-radius: 10px; font-weight: 900; font-size: 14px; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--paper); color: var(--ink); }
.board { min-height: 120px; max-height: 210px; overflow: auto; display: flex; flex-direction: column; gap: 4px; }
.row { display: grid; grid-template-columns: 28px 30px 1fr auto; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 12px; background: rgba(255,244,224,.04); text-align: left; width: 100%; font-weight: 800; font-size: 14px; }
.row.me { background: rgba(255, 106, 61, .18); box-shadow: 0 0 0 2px rgba(255, 106, 61, .5); }
.row .rk { color: var(--muted); font-variant-numeric: tabular-nums; text-align: center; }
.row img, .row .av { width: 30px; height: 30px; border-radius: 50%; background: #2a375e; object-fit: cover; }
.row .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sc { font-variant-numeric: tabular-nums; color: var(--gold); }
.board .note { text-align: center; color: var(--muted); font-weight: 700; padding: 24px 0; font-size: 14px; }
.board .note button { color: var(--warm); font-weight: 900; text-decoration: underline; }
.savestate { text-align: center; font-size: 12px; color: var(--muted); font-weight: 800; min-height: 16px; margin-top: 6px; }

.settings { display: flex; flex-direction: column; gap: 6px; margin-bottom: 4px; }
.setting { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-radius: 14px; background: rgba(255,244,224,.06); font-weight: 800; }
.setting .val { padding: 6px 12px; border-radius: 99px; background: rgba(255,244,224,.12); font-size: 13px; font-weight: 900; }
.setting .val.on { background: var(--good); color: var(--ink); }

.heroes { display: flex; flex-direction: column; gap: 8px; }
.hero { display: grid; grid-template-columns: 54px 1fr auto; gap: 10px; align-items: center; padding: 10px; border-radius: 18px; background: rgba(255,244,224,.06); }
.hero.sel { box-shadow: 0 0 0 2px var(--vermilion); }
.hero .face { width: 54px; height: 54px; border-radius: 16px; display: grid; place-items: center; }
.hero .face svg { width: 42px; height: 42px; }
.hero b { font-size: 16px; font-weight: 1000; display: block; }
.hero small { color: var(--muted); font-weight: 700; font-size: 12px; }
.hero .pips { display: flex; gap: 3px; margin-top: 5px; }
.hero .pips i { width: 9px; height: 5px; border-radius: 3px; background: rgba(255,244,224,.15); }
.hero .pips i.on { background: var(--good); }
.hero .act { padding: 9px 12px; border-radius: 12px; background: var(--paper); color: var(--ink); font-weight: 900; font-size: 13px; display: flex; gap: 4px; align-items: center; white-space: nowrap; }
.hero .act.dim { background: rgba(255,244,224,.14); color: var(--muted); }
.hero .act .mark-ic { width: 14px; height: 14px; background: currentColor; }
.marks-top { display: flex; justify-content: center; align-items: center; gap: 6px; font-weight: 1000; font-size: 18px; color: var(--gold); margin-bottom: 10px; }

#boot { position: fixed; inset: 0; display: grid; place-items: center; background: var(--ink); transition: opacity .4s; z-index: 50; }
#boot.gone { opacity: 0; pointer-events: none; }
.boot-mark { width: 54px; height: 54px; border-radius: 50%; border: 4px solid rgba(255,244,224,.15); border-top-color: var(--vermilion); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) { #announce .a, .card, #hint .hand { animation-duration: .01s !important; } }
@media (orientation: landscape) and (max-height: 500px) { .card { max-width: 560px; } .offer { min-height: 140px; } }

.hero .face canvas, .ic canvas { width:100%; height:100%; object-fit:contain; display:block; }
