:root {
  --ink: #1a1020; --panel: #2b1f3a; --panel2: #3a2a4e; --edge: #6a4f8a; --gold: #ffd23f; --red: #ff5a5a; --green: #7ee36b; --text: #fff4e0;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px); --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1a1020; color: var(--text); font-family: 'Press Start 2P', monospace; font-size: 10px; user-select: none; -webkit-user-select: none; touch-action: none; overscroll-behavior: none; }
#cv { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; image-rendering: pixelated; image-rendering: crisp-edges; display: block; }
.hidden { display: none !important; }
img.ico { width: 16px; height: 16px; image-rendering: pixelated; vertical-align: middle; }
img.ico.big { width: 32px; height: 32px; }
button { font-family: inherit; color: inherit; }

/* ---------- HUD ---------- */
#hud { position: fixed; left: 0; right: 0; top: 0; padding: calc(6px + var(--sat)) calc(6px + var(--sar)) 0 calc(6px + var(--sal)); pointer-events: none; z-index: 5; }
.hrow { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.chip { display: flex; align-items: center; gap: 4px; background: rgba(26, 16, 32, 0.82); border: 2px solid var(--ink); box-shadow: inset 0 0 0 2px #4a3a5e; padding: 4px 6px; font-size: 10px; height: 28px; white-space: nowrap; }
.chip b { color: var(--text); }
.chip.full { box-shadow: inset 0 0 0 2px var(--red); animation: pulse 0.6s infinite alternate; }
.chip.full b { color: #ff9a6a; }
.chip.lvl span { color: var(--gold); }
.bar { width: 40px; height: 6px; background: #120a18; border: 1px solid #000; position: relative; }
.bar.wide { width: 60px; }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--green); display: block; }
.time .bar i { background: linear-gradient(90deg, #ff8a2a, var(--gold)); }
.btnchip { pointer-events: auto; cursor: pointer; margin-left: auto; color: var(--gold); }
#h-day { display: inline-block; margin-top: 4px; padding: 4px 6px; font-size: 9px; color: var(--gold); text-shadow: 1px 1px 0 #000; background: rgba(26, 16, 32, 0.82); border: 2px solid var(--ink); }
#h-day:empty { display: none; }
#h-board { position: absolute; right: calc(6px + var(--sar)); top: calc(42px + var(--sat)); background: rgba(26, 16, 32, 0.82); border: 2px solid var(--ink); box-shadow: inset 0 0 0 2px #4a3a5e; padding: 6px; font-size: 8px; min-width: 150px; }
#h-board div { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; }
#h-board div.me { color: var(--gold); }
body:not([data-mode="comp"]) #h-board, body:not([data-mode="comp"]) #h-ptschip { display: none; }
body[data-mode="comp"] #h-basketchip, body[data-mode="comp"] #b-home { display: none !important; }
body[data-mode="hub"] .time .bar { display: none; }
body[data-mode="cut"] #hud, body[data-mode="cut"] #joy { display: none !important; }

/* ---------- joystick ---------- */
#joy { position: fixed; left: 0; bottom: 0; top: 0; width: 58%; z-index: 3; touch-action: none; }
body[data-mode="hub"] #joy { width: 100%; }
#joybase { position: fixed; width: 92px; height: 92px; margin: -46px 0 0 -46px; border-radius: 50%; background: rgba(255, 255, 255, 0.08); border: 3px solid rgba(255, 255, 255, 0.35); display: none; pointer-events: none; }
#joyknob { position: absolute; left: 50%; top: 50%; width: 40px; height: 40px; border-radius: 50%; background: rgba(255, 255, 255, 0.45); border: 3px solid rgba(26, 16, 32, 0.6); transform: translate(-50%, -50%); }

/* ---------- action buttons ---------- */
#btns { position: fixed; right: calc(10px + var(--sar)); bottom: calc(10px + var(--sab)); width: 230px; height: 250px; z-index: 4; pointer-events: none; display: none; }
body[data-mode="forest"] #btns, body[data-mode="comp"] #btns { display: block; }
.abtn { position: absolute; pointer-events: auto; border-radius: 50%; border: 3px solid var(--ink); background: radial-gradient(circle at 35% 30%, #6a5a8a, #3a2a4e); box-shadow: 0 4px 0 #0d0812, inset 0 0 0 2px rgba(255, 255, 255, 0.15); color: var(--text); font-size: 8px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; overflow: hidden; touch-action: none; cursor: pointer; padding: 0; }
.abtn.down { transform: translateY(3px); box-shadow: 0 1px 0 #0d0812; }
.abtn .lbl { position: relative; z-index: 2; text-shadow: 1px 1px 0 #000; }
.abtn img { position: relative; z-index: 2; }
.abtn .cd { position: absolute; left: 0; right: 0; bottom: 0; height: 0; background: rgba(0, 0, 0, 0.6); z-index: 3; pointer-events: none; }
.abtn.big { right: 0; bottom: 0; width: 86px; height: 86px; background: radial-gradient(circle at 35% 30%, #ff6a7a, #b0182e); font-size: 10px; }
.abtn.big img { width: 24px; height: 24px; }
.abtn.mid { right: 96px; bottom: 4px; width: 62px; height: 62px; background: radial-gradient(circle at 35% 30%, #6ab8ff, #2a5ea8); }
.abtn.small { width: 52px; height: 52px; background: radial-gradient(circle at 35% 30%, #b88aff, #5a3a9a); }
.abtn.small img { width: 24px; height: 24px; }
#b-t1 { right: 92px; bottom: 74px; }
#b-t2 { right: 22px; bottom: 96px; }
.abtn.rush { right: 150px; bottom: 76px; width: 60px; height: 60px; background: #2a2236; }
.abtn.rush .fill { position: absolute; left: 0; right: 0; bottom: 0; height: 0; background: linear-gradient(0deg, #ff8a2a, #ffe23b); z-index: 1; }
.abtn.rush.ready { animation: glow 0.5s infinite alternate; }
.abtn.rush.ready .fill { background: linear-gradient(0deg, #ff3b9a, #ffe23b, #3bf0ff); }
.abtn.rush.active .fill { background: linear-gradient(0deg, #ff3b3b, #ff9a2e, #ffe23b, #4cdb5a, #3bb0ff, #9b5cff); }
.abtn.tiny { width: 40px; height: 40px; border-radius: 8px; }
.abtn.tiny em { font-style: normal; font-size: 8px; position: absolute; right: 3px; bottom: 2px; z-index: 2; text-shadow: 1px 1px 0 #000; }
#b-drink { right: 34px; bottom: 160px; }
#b-decoy { right: 82px; bottom: 136px; }
.abtn.home { right: 0; bottom: 210px; width: 84px; height: 32px; border-radius: 6px; flex-direction: row; background: #5a3a28; font-size: 8px; }
@keyframes glow { from { box-shadow: 0 0 6px 2px #ffe23b, 0 4px 0 #0d0812; } to { box-shadow: 0 0 18px 6px #ff3bd0, 0 4px 0 #0d0812; } }
@keyframes pulse { from { opacity: 1; } to { opacity: 0.6; } }

/* ---------- toasts ---------- */
#toasts { position: fixed; left: 50%; top: calc(58px + var(--sat)); transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 4px; z-index: 8; pointer-events: none; width: 92vw; }
.toast { background: rgba(26, 16, 32, 0.9); border: 2px solid var(--ink); box-shadow: inset 0 0 0 2px #4a3a5e; padding: 7px 10px; font-size: 9px; text-align: center; line-height: 1.5; text-shadow: 1px 1px 0 #000; animation: tin 0.25s ease-out; transition: opacity 0.5s, transform 0.5s; max-width: 100%; }
.toast.out { opacity: 0; transform: translateY(-8px); }
@keyframes tin { from { transform: scale(0.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- dialog ---------- */
#dialog { position: fixed; left: 50%; bottom: calc(12px + var(--sab)); transform: translateX(-50%); width: min(640px, 94vw); background: var(--panel); border: 3px solid var(--ink); box-shadow: inset 0 0 0 3px var(--edge), 0 6px 0 rgba(0, 0, 0, 0.5); padding: 12px; display: flex; gap: 12px; align-items: flex-start; z-index: 20; cursor: pointer; }
#d-port img.portrait { width: 72px; height: 72px; image-rendering: pixelated; background: #1a1020; border: 2px solid var(--edge); }
.dbody { flex: 1; min-height: 72px; position: relative; }
#d-name { color: var(--gold); margin-bottom: 8px; font-size: 10px; }
#d-text { font-size: 10px; line-height: 1.7; }
.dnext { position: absolute; right: 0; bottom: -4px; color: var(--gold); animation: pulse 0.5s infinite alternate; }
#dialog.narr #d-name { display: none; }

/* ---------- panels ---------- */
#panel { position: fixed; inset: 0; background: rgba(10, 6, 16, 0.6); display: flex; align-items: center; justify-content: center; z-index: 15; padding: calc(10px + var(--sat)) 10px calc(10px + var(--sab)); }
.card { position: relative; width: min(560px, 100%); max-height: 100%; overflow-y: auto; background: var(--panel); border: 4px solid var(--ink); box-shadow: inset 0 0 0 3px var(--edge), 0 8px 0 rgba(0, 0, 0, 0.5); padding: 16px 14px; touch-action: pan-y; animation: tin 0.18s ease-out; }
.card.still { animation: none; }
.card h2 { margin: 0 30px 12px 0; font-size: 13px; color: var(--gold); text-shadow: 2px 2px 0 #000; line-height: 1.5; }
.card h3 { font-size: 10px; color: var(--gold); margin: 14px 0 8px; }
.card .x { position: absolute; right: 8px; top: 8px; width: 32px; height: 32px; background: #5a2a3a; border: 2px solid var(--ink); cursor: pointer; font-size: 12px; }
.phead { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.phead img.portrait { width: 64px; height: 64px; image-rendering: pixelated; background: #1a1020; border: 2px solid var(--edge); flex: none; }
.phead h2 { margin-bottom: 6px; }
.quote { margin: 0; font-size: 9px; line-height: 1.6; color: #e8d8ff; }
.box { background: var(--panel2); border: 2px solid var(--ink); padding: 8px 10px; margin: 8px 0; line-height: 1.7; font-size: 9px; }
.box.hl { box-shadow: inset 0 0 0 2px var(--gold); }
.box.dim { opacity: 0.8; }
.box.small, .small { font-size: 8px; }
.box.center, .center { text-align: center; }
.box .big, .big { font-size: 11px; color: var(--gold); }
.red { color: var(--red); }
.gold { color: var(--gold); }
.ok { color: var(--green); }
.crave { color: var(--gold); }
.btn { display: block; width: 100%; margin: 8px 0 0; padding: 11px 10px; background: #4a3a6a; border: 3px solid var(--ink); box-shadow: 0 4px 0 #0d0812, inset 0 0 0 2px rgba(255, 255, 255, 0.12); font-size: 10px; cursor: pointer; text-shadow: 1px 1px 0 #000; }
.btn:active:not([disabled]) { transform: translateY(3px); box-shadow: 0 1px 0 #0d0812; }
.btn.big { font-size: 12px; padding: 14px; }
.btn.gold { background: #c48a18; color: #fff; }
.btn.red { background: #9a2030; }
.btn.on { background: #2f7a3a; }
.btn[disabled] { opacity: 0.45; cursor: default; }
.item { display: flex; align-items: center; gap: 10px; background: var(--panel2); border: 2px solid var(--ink); padding: 8px; margin: 6px 0; }
.item .info { flex: 1; min-width: 0; line-height: 1.6; }
.item .info small { display: block; font-size: 8px; color: #d8c8ee; }
.item .lv { font-size: 8px; color: var(--gold); white-space: nowrap; }
.item .btn { width: auto; min-width: 84px; margin: 0; flex: none; padding: 9px 8px; font-size: 9px; }
.item.locked { opacity: 0.55; }
.item img.ico.big { flex: none; }
.tag { font-size: 8px; color: var(--green); }
.tabs { display: flex; gap: 4px; margin: 6px 0; }
.tab { flex: 1; padding: 9px 2px; font-size: 8px; background: #2a1d36; border: 2px solid var(--ink); cursor: pointer; }
.tab.on { background: var(--edge); color: var(--gold); }
.wallet { font-size: 10px; margin: 4px 0; }
table.sell { width: 100%; border-collapse: collapse; font-size: 9px; margin: 8px 0; }
table.sell td { padding: 6px 4px; border-bottom: 2px solid #22182e; }
table.sell td.r { text-align: right; white-space: nowrap; }
table.sell tr.tot td { color: var(--gold); border-bottom: none; }
table.sell tr.me td { color: var(--gold); }
.bd { display: inline-block; width: 10px; height: 10px; border: 2px solid var(--ink); vertical-align: middle; margin-right: 2px; }
.dots { margin-top: 4px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px; }
.cell { background: var(--panel2); border: 2px solid var(--ink); padding: 8px; text-align: center; line-height: 1.6; font-size: 8px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.cell .bdot { width: 24px; height: 24px; border: 3px solid var(--ink); background: #111; margin-bottom: 4px; }
.cell.unk { opacity: 0.6; }
.order.done { opacity: 0.7; }

/* ---------- title ---------- */
#title { position: fixed; inset: 0; z-index: 12; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; padding: 20px; background: radial-gradient(ellipse at center, rgba(10, 6, 16, 0.15), rgba(10, 6, 16, 0.65)); }
.logo { text-align: center; text-shadow: 3px 3px 0 #1a1020, -2px -2px 0 #1a1020, 2px -2px 0 #1a1020, -2px 2px 0 #1a1020; line-height: 1.5; }
.logo .l1 { font-size: clamp(12px, 3.2vw, 20px); color: #fff4e0; }
.logo .l2 { font-size: clamp(16px, 5vw, 34px); color: #7ee36b; }
.logo .l3 { font-size: clamp(18px, 6vw, 44px); color: #ff3b5c; display: flex; align-items: center; justify-content: center; gap: 10px; }
.tbtns { width: min(320px, 86vw); }
#title .foot { font-size: 8px; color: #e8d8ff; opacity: 0.85; text-align: center; text-shadow: 2px 2px 0 #000; }

@media (max-width: 520px) {
  .chip { font-size: 8px; padding: 3px 4px; height: 24px; gap: 3px; }
  .bar { width: 28px; } .bar.wide { width: 36px; }
  img.ico { width: 12px; height: 12px; }
  #btns { transform: scale(0.88); transform-origin: bottom right; }
  #h-board { top: calc(66px + var(--sat)); min-width: 120px; }
  #toasts { top: calc(70px + var(--sat)); }
  body[data-mode="comp"] #toasts { top: calc(140px + var(--sat)); }
}
@media (max-height: 420px) {
  #btns { transform: scale(0.8); transform-origin: bottom right; }
  #dialog { padding: 8px; } #d-port img.portrait { width: 52px; height: 52px; } .dbody { min-height: 52px; }
}
