:root {
  --panel: rgba(8, 12, 24, 0.94);
  --panel-2: rgba(22, 30, 52, 0.9);
  --line: #2a6a8a;
  --gold: #5ae0ff;
  --text: #e4ecf8;
  --dim: #8a94ae;
  --red: #ff3a6a;
  --hp: #ff3a5a;
  --mp: #2ab8e8;
  --exp: #a060ff;
  --rare: #ffcc55;
  --good: #6affa8;
  --bad: #ff6a6a;
  --ui-font: "Pixelify Sans", "Trebuchet MS", system-ui, sans-serif;
  --title-font: "Press Start 2P", "Courier New", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #07050b; overflow: hidden; }
body { font-family: var(--ui-font); color: var(--text); user-select: none; }

#stage { position: fixed; inset: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px); overflow: hidden; }
/* Fixed 960x540 design space, centered and uniformly scaled to fit the window (see fitStage in ui.js). */
#game { position: absolute; left: 50%; top: 50%; width: 960px; height: 540px; transform-origin: center; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; image-rendering: pixelated; }
img { image-rendering: pixelated; }
#ui { position: absolute; inset: 0; font-size: 12px; pointer-events: none; }
#ui > * { pointer-events: auto; }
#log, #banner { pointer-events: none !important; }
.hidden { display: none !important; }
#ui:not(.playing) > :not(#title):not(#confirm):not(#starter) { display: none !important; }
.dim { color: var(--dim); }
.bad { color: var(--bad); }
.gold { color: var(--gold); }

button {
  font: inherit; color: var(--text); background: linear-gradient(#1e2c48, #121a30);
  border: 1px solid var(--line); border-radius: 4px; padding: 3px 8px; cursor: pointer;
}
button:hover:not(:disabled) { background: linear-gradient(#28406a, #182442); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: linear-gradient(#0a8ab8, #065a80); border-color: #5ae0ff; }
button.primary:hover { background: linear-gradient(#10a0d0, #086a94); }

/* ---------- Minimap ---------- */
#mini { position: absolute; left: 8px; top: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px 6px; }
#mini-name { font-family: var(--title-font); font-weight: 800; color: var(--gold); font-size: 13px; margin-bottom: 3px; }
#mini-map { display: block; background: rgba(0, 0, 0, 0.35); border-radius: 3px; }

/* ---------- Boss bar ---------- */
#bossbar { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); width: 460px; text-align: center; pointer-events: none; }
.bb-name { font-family: var(--title-font); font-weight: 800; font-size: 15px; color: #ffd0f0; text-shadow: 0 2px 4px #000; margin-bottom: 4px; }
.bb-track { height: 12px; background: rgba(0, 0, 0, 0.7); border: 1px solid #ff8ad0; border-radius: 6px; overflow: hidden; }
.bb-fill { height: 100%; background: linear-gradient(90deg, #ff4fa0, #ff9ad8); transition: width 0.15s; }

/* ---------- Banner ---------- */
#banner { position: absolute; left: 0; right: 0; top: 150px; text-align: center; }
#banner.show { animation: banner 2.6s ease forwards; }
.b-title { font-family: var(--title-font); font-weight: 900; font-size: 36px; color: #eafcff; letter-spacing: 4px; text-shadow: 0 0 18px rgba(90, 224, 255, 0.7), 0 3px 0 #000; }
.b-sub { font-size: 14px; color: var(--gold); text-shadow: 0 2px 3px #000; margin-top: 2px; }
@keyframes banner { 0% { opacity: 0; transform: translateY(10px); } 12% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- Chat log ---------- */
/* Log sits under the minimap on every device. */
#log { position: absolute; left: 8px; top: 118px; width: 300px; max-height: 70px; opacity: 0.9; overflow: hidden; display: flex; flex-direction: column; justify-content: flex-end; font-size: 11.5px; }
#log .ln { padding: 1px 6px; background: rgba(0, 0, 0, 0.45); text-shadow: 0 1px 1px #000; border-radius: 2px; margin-top: 1px; }
#log .warn { color: #ffb0a0; }
#log .loot { color: #d8e6ff; }
#log .rare { color: var(--rare); font-weight: bold; }
#log .quest { color: #a8f0c0; }
#log .lvl { color: #ffe27a; font-weight: bold; }
#log .skill { color: #bfe6ff; }
#log .sys { color: #d8c8ff; }

/* ---------- HUD ---------- */
#hud {
  position: absolute; left: 0; right: 0; bottom: 0; height: 80px;
  background: linear-gradient(rgba(10, 16, 32, 0.92), rgba(4, 6, 14, 0.98));
  border-top: 1px solid var(--line);
  display: grid; grid-template-columns: 128px 1fr auto auto auto; grid-template-rows: 1fr 12px; gap: 0 8px; padding: 6px 8px 0;
}
.hud-id { display: flex; align-items: center; gap: 7px; }
.lv { width: 42px; height: 42px; flex: none; border-radius: 50%; border: 2px solid var(--gold); background: radial-gradient(#1a3a5a, #0a1020); display: grid; place-items: center; line-height: 1; }
.lv small { font-size: 9px; color: var(--gold); margin-top: 5px; }
.lv b { font-size: 18px; margin-top: -8px; }
.who #hud-name { font-weight: bold; font-size: 13px; }
.who #hud-gold { color: var(--gold); font-size: 11px; }
.bars { display: flex; flex-direction: column; justify-content: center; gap: 5px; }
.bar { position: relative; height: 16px; background: rgba(0, 0, 0, 0.6); border: 1px solid rgba(255, 255, 255, 0.15); border-radius: 3px; overflow: hidden; }
.bar .fill { position: absolute; left: 0; top: 0; bottom: 0; transition: width 0.12s; }
.bar.hp .fill { background: linear-gradient(#ff6a7a, var(--hp) 50%, #a01c30); }
.bar.mp .fill { background: linear-gradient(#7ab0ff, var(--mp) 50%, #1c4aa0); }
.bar label { position: absolute; left: 5px; top: 0; font-size: 10px; font-weight: bold; line-height: 16px; color: rgba(255, 255, 255, 0.85); }
.bar span { position: absolute; inset: 0; text-align: center; font-size: 11px; line-height: 16px; font-weight: bold; text-shadow: 0 1px 2px #000; }
.bar.exp { grid-column: 1 / -1; height: 8px; margin-top: 2px; border-radius: 0; }
.bar.exp .fill { background: linear-gradient(#d0a8ff, var(--exp)); }
.bar.exp span { font-size: 8px; line-height: 8px; }

.bots { display: flex; gap: 3px; align-items: center; }
.bslot { position: relative; width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 50%; background: #000; overflow: hidden; cursor: pointer; opacity: 0.6; }
.bslot img { width: 100%; height: 100%; display: block; }
.bslot b { position: absolute; left: 50%; bottom: -1px; transform: translateX(-50%); font-size: 9px; text-shadow: 0 0 2px #000, 0 0 2px #000; }
.bslot.on { opacity: 1; border: 2px solid var(--c); box-shadow: 0 0 10px var(--c); }
.bslot.partner { opacity: 0.9; border: 2px dashed var(--c); }
.bslot.empty { cursor: default; opacity: 0.3; display: grid; place-items: center; }
.bslot.empty b { position: static; transform: none; }

.slots { display: flex; gap: 4px; align-items: center; }
.slot { position: relative; width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 4px; background: #000; overflow: hidden; cursor: pointer; }
.slot.sync .fillup { position: absolute; left: 0; right: 0; bottom: 0; background: linear-gradient(rgba(255, 226, 122, 0.55), rgba(255, 160, 40, 0.35)); }
.slot.sync img { position: relative; z-index: 1; opacity: 0.85; }
.slot.sync b, .slot.sync i { z-index: 2; }
.slot.sync.ready { border-color: #ffe27a; animation: syncready 0.8s ease-in-out infinite alternate; }
@keyframes syncready { from { box-shadow: 0 0 4px #ffe27a; } to { box-shadow: 0 0 16px #ffb040; } }
.slot img { width: 100%; height: 100%; display: block; }
.slot .cd { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.65); }
.slot b { position: absolute; left: 2px; top: 0; font-size: 10px; text-shadow: 0 0 2px #000, 0 0 2px #000; }
.slot i { position: absolute; right: 2px; bottom: 0; font-size: 10px; font-style: normal; font-weight: bold; text-shadow: 0 0 2px #000, 0 0 2px #000; }
.slot.locked img { filter: grayscale(1) brightness(0.35); }
.slot.nomp img { filter: saturate(0.3) brightness(0.6); }
.slot[data-kind="pot"] { margin-left: 4px; }
.menu { display: flex; gap: 3px; align-items: center; }
.menu button { width: 36px; height: 38px; padding: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: bold; font-size: 13px; line-height: 1.1; position: relative; }
.menu button small { font-size: 8.5px; font-weight: normal; color: var(--dim); }
.menu button.alert::after { content: ""; position: absolute; top: 3px; right: 3px; width: 7px; height: 7px; background: #ff5a4a; border-radius: 50%; box-shadow: 0 0 6px #ff5a4a; }

/* ---------- Windows ---------- */
/* --wz = UI zoom for windows/dialogs (1.25 on touch). Windows cap their height to the space above the HUD and scroll inside. */
:root { --wz: 1; }
body.touch { --wz: 1.25; }
.win { display: flex; flex-direction: column; max-height: calc(450px / var(--wz)); transform: scale(var(--wz)); transform-origin: 0 0; position: absolute; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6); z-index: 10; }
.win-head { display: flex; justify-content: space-between; align-items: center; padding: 5px 6px 5px 10px; background: linear-gradient(#10284a, #0a1428); border-bottom: 1px solid var(--line); border-radius: 6px 6px 0 0; cursor: move; font-family: var(--title-font); font-weight: 800; color: var(--gold); font-size: 13px; }
.win-head .x { padding: 0 6px; line-height: 16px; font-size: 14px; }
.win-head { flex: none; }
.win-body { padding: 8px 10px 10px; flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.hint { color: var(--dim); font-size: 10.5px; margin-top: 6px; }
.grid { display: grid; grid-template-columns: repeat(6, 34px); gap: 3px; }
.cell { position: relative; width: 34px; height: 34px; background: rgba(0, 0, 0, 0.45); border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 3px; }
.cell[data-slot] { cursor: pointer; }
.cell[data-slot]:hover { border-color: var(--gold); }
.cell.rare { border-color: var(--rare); box-shadow: inset 0 0 8px rgba(255, 204, 85, 0.35); }
.cell img { width: 30px; height: 30px; margin: 1px; display: block; pointer-events: none; }
.cell b { position: absolute; right: 2px; bottom: 0; font-size: 10px; text-shadow: 0 0 2px #000, 0 0 2px #000; pointer-events: none; }
.inv-foot { margin-top: 8px; color: var(--gold); font-weight: bold; display: flex; align-items: center; gap: 6px; }
.coin { width: 10px; height: 10px; transform: rotate(45deg); background: #40e0ff; border: 2px solid #0a6a8a; display: inline-block; }

.char-top { text-align: center; margin-bottom: 8px; }
.char-top .big { font-family: var(--title-font); font-weight: 800; font-size: 17px; color: var(--gold); }
.eqs { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin-bottom: 8px; }
.eq { display: flex; gap: 6px; align-items: center; background: var(--panel-2); padding: 4px; border-radius: 4px; cursor: pointer; font-size: 11px; }
.eq small { color: var(--dim); font-size: 9.5px; }
.stats hr { border: 0; border-top: 1px solid rgba(255, 255, 255, 0.1); margin: 6px 0; }
.stat { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
.stat span { width: 62px; color: var(--dim); }
.stat small { color: var(--good); }
.stat button { margin-left: auto; padding: 0 7px; line-height: 16px; }
.pts { margin-top: 6px; color: var(--dim); }
.pts.on { color: #ffe27a; font-weight: bold; }

.skill { display: flex; gap: 8px; align-items: center; background: var(--panel-2); padding: 6px; border-radius: 4px; margin-top: 6px; }
.skill img { width: 34px; height: 34px; border-radius: 3px; }
.skill.locked { opacity: 0.55; }
.skill .sk-info { flex: 1; line-height: 1.35; }
.skill .key { background: #000; border: 1px solid var(--line); padding: 0 4px; border-radius: 3px; font-size: 10px; }
.skill .eff { color: #bfe6ff; }
.skill button { padding: 2px 9px; }

.quest { background: var(--panel-2); padding: 7px 8px; border-radius: 4px; margin-bottom: 6px; }
.q-name { font-weight: bold; color: var(--gold); margin-bottom: 4px; }
.q-row { display: flex; justify-content: space-between; padding: 1px 0; }
.q-row.ok { color: var(--good); }
.ready { color: var(--good); font-size: 10px; margin-left: 4px; }
.q-done { color: var(--dim); font-size: 11px; margin-top: 6px; }
.q-empty { padding: 8px 0; }

.tabs { display: flex; gap: 4px; align-items: center; margin-bottom: 6px; }
.tabs button.on { border-color: var(--gold); color: var(--gold); }
.tabs .gold { margin-left: auto; font-weight: bold; }
.shop-list .row { display: flex; align-items: center; gap: 6px; padding: 3px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.06); }
.shop-list .grow { flex: 1; line-height: 1.25; }
.shop-list button { padding: 2px 7px; }
button.wide { width: 100%; margin-top: 8px; }

.help .keys { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; margin-bottom: 8px; }
.help p { margin: 6px 0; line-height: 1.45; }
kbd { display: inline-block; min-width: 18px; text-align: center; background: #000; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 3px; padding: 0 4px; margin-right: 2px; font: bold 10.5px var(--ui-font); }

/* ---------- Tooltip ---------- */
#tooltip { position: absolute; z-index: 100; width: 210px; background: rgba(4, 8, 18, 0.97); border: 1px solid var(--line); border-radius: 5px; padding: 7px 9px; pointer-events: none !important; line-height: 1.4; }
.t-name { font-weight: bold; font-size: 13px; }
.t-name.rare { color: var(--rare); }
.t-desc { color: #d8cfe0; font-style: italic; margin: 4px 0; }

/* ---------- Dialog ---------- */
#dialog { display: flex; flex-direction: column; max-height: calc(420px / var(--wz)); transform: translateX(-50%) scale(var(--wz)); transform-origin: 50% 100%; position: absolute; left: 50%; bottom: 96px; width: 520px; background: var(--panel); border: 1px solid var(--gold); border-radius: 8px; padding: 12px 16px; z-index: 50; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7); }
.d-name { font-family: var(--title-font); font-weight: 800; color: var(--gold); font-size: 16px; margin-bottom: 6px; }
.d-name, .d-btns { flex: none; }
.d-text { font-size: 13px; line-height: 1.5; flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; }
.d-text .q-title { color: #9af0ff; }
.d-text .q-row { font-size: 12px; }
.reward { margin-top: 8px; color: #bfe6ff; font-size: 12px; }
.d-btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.d-btns button { padding: 5px 14px; }

/* ---------- Title ---------- */
#title { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 200; background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 30%, rgba(0, 0, 0, 0.55)); }
.t-logo { font-family: var(--title-font); font-weight: 900; font-size: 80px; letter-spacing: 8px; color: #eafcff; text-shadow: 0 0 30px rgba(90, 224, 255, 0.8), 0 4px 0 #04202e; margin-top: -40px; }
.t-logo span { color: #ff3a8a; text-shadow: 0 0 30px rgba(255, 58, 138, 0.9), 0 4px 0 #3a0518; }
.t-sub { font-family: var(--title-font); color: var(--gold); letter-spacing: 6px; font-size: 15px; margin-bottom: 26px; text-shadow: 0 2px 3px #000; }
.t-card { display: flex; flex-direction: column; gap: 8px; width: 240px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
.t-card label { color: var(--dim); font-size: 11px; }
.t-card input { font: 14px var(--ui-font); color: var(--text); background: #000; border: 1px solid var(--line); border-radius: 4px; padding: 6px 8px; outline: none; user-select: text; }
.t-card input:focus { border-color: var(--gold); }
.t-card button { padding: 7px; font-size: 13px; }
/* Title controls panel: keyboard chips on desktop, thumb guide on touch devices. */
.t-controls { margin-top: 16px; width: 520px; background: rgba(8, 12, 24, 0.82); border: 2px solid var(--line); box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.55); padding: 10px 14px 8px; }
.tc-head { font: 9px var(--title-font); color: var(--gold); letter-spacing: 2px; margin-bottom: 8px; }
.tc-keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px 10px; font-size: 13px; }
.tc-keys span { display: flex; align-items: center; gap: 3px; white-space: nowrap; }
.tc-keys kbd { font-size: 11px; padding: 1px 5px; }
.tc-touch { display: none; flex-direction: column; gap: 5px; font-size: 14px; }
.tc-touch b { color: var(--gold); font-weight: 600; }
body.touch .tc-keys { display: none; }
body.touch .tc-touch { display: flex; }
.tc-foot { margin-top: 8px; color: var(--dim); font-size: 11px; }
body.touch .tc-foot { display: none; }

/* ---------- Combo meter ---------- */
#combo { position: absolute; right: 16px; top: 120px; width: 150px; text-align: right; pointer-events: none !important; font-family: var(--title-font); }
.c-num { font-size: 46px; font-weight: 900; line-height: 1; color: #fff; text-shadow: 0 0 12px rgba(90, 224, 255, 0.8), 0 3px 0 #000; }
.c-hits { font-size: 12px; letter-spacing: 4px; color: var(--gold); text-shadow: 0 1px 2px #000; }
.c-rank { font-size: 34px; font-weight: 900; line-height: 1.1; text-shadow: 0 0 14px currentColor, 0 3px 0 #000; }
.c-rank.pop { animation: rankpop 0.35s ease-out; }
@keyframes rankpop { 0% { transform: scale(1.8); } 100% { transform: scale(1); } }
.c-bonus { font-family: var(--ui-font); font-size: 10.5px; color: #d8f4ff; text-shadow: 0 1px 2px #000; min-height: 13px; }
.c-track { height: 4px; margin-top: 4px; background: rgba(0, 0, 0, 0.6); border-radius: 2px; overflow: hidden; }
.c-timer { height: 100%; margin-left: auto; background: linear-gradient(90deg, #ff3a8a, #5ae0ff); }

/* ---------- Nanobots window ---------- */
.stars { color: #ffd24a; letter-spacing: -1px; }
.rar { font-size: 9.5px; padding: 0 4px; border-radius: 3px; border: 1px solid; }
.rar.r1 { color: #b8c4d8; }
.rar.r2 { color: #5ae0ff; }
.rar.r3 { color: #ff7ae0; }
.rar.r4 { color: #ffd24a; background: rgba(255, 210, 74, 0.12); }
.bot-slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 8px; }
.bot-slot { background: var(--panel-2); border: 1px solid rgba(255, 255, 255, 0.1); border-radius: 6px; padding: 5px; text-align: center; min-height: 92px; }
.bot-slot.on { border-color: var(--c); box-shadow: inset 0 0 12px color-mix(in srgb, var(--c) 35%, transparent); }
.bot-slot img { width: 44px; height: 44px; border-radius: 50%; display: block; margin: 2px auto; }
.bot-slot small { color: var(--dim); font-size: 9.5px; }
.bot-slot button { margin-top: 3px; font-size: 10px; padding: 1px 6px; }
.bot-list { display: flex; flex-direction: column; gap: 4px; }
.bot-card { display: flex; align-items: center; gap: 8px; background: var(--panel-2); border-left: 3px solid var(--c); border-radius: 4px; padding: 4px 6px; }
.bot-card img { width: 40px; height: 40px; border-radius: 6px; }
.bot-card .grow { flex: 1; line-height: 1.3; min-width: 0; }
.bexp { height: 3px; background: rgba(0, 0, 0, 0.5); margin-top: 3px; border-radius: 2px; overflow: hidden; }
.bexp div { height: 100%; background: var(--c); }
.bot-actions { display: flex; gap: 3px; align-items: center; flex-wrap: wrap; justify-content: flex-end; max-width: 150px; }
.bot-actions button { padding: 1px 7px; font-size: 11px; }
.tag { font-size: 10px; color: var(--gold); border: 1px solid var(--line); border-radius: 3px; padding: 1px 5px; }
.dex { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.dex-card { display: flex; gap: 6px; align-items: center; background: var(--panel-2); border-left: 3px solid var(--c); border-radius: 4px; padding: 4px; font-size: 11px; line-height: 1.3; }
.dex-card img { width: 38px; height: 38px; border-radius: 6px; }
.dex-card.unseen { border-left-color: #333; opacity: 0.7; }
.eqs.three { grid-template-columns: 1fr 1fr 1fr; }
.eqs.three .eq { flex-direction: column; text-align: center; }
.eq-bot { display: flex; gap: 8px; align-items: center; background: var(--panel-2); border-left: 3px solid var(--c); border-radius: 4px; padding: 5px; margin-bottom: 8px; line-height: 1.3; }
.eq-bot img { width: 40px; height: 40px; border-radius: 6px; }
.eq-bot small { font-size: 9.5px; }

/* ---------- Missions ---------- */
#mtrack { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 4px 14px; font-size: 12px; white-space: nowrap; pointer-events: none !important; }
#mtrack b { color: var(--gold); }
#bossbar:not(.hidden) ~ #mtrack { top: 52px; }
.mission { display: flex; gap: 10px; align-items: center; background: var(--panel-2); border-radius: 5px; padding: 6px 8px; margin-bottom: 5px; line-height: 1.35; }
.mission.locked { opacity: 0.55; }
.mission .grow { flex: 1; display: flex; flex-direction: column; }
.m-grade { width: 34px; font: 900 26px var(--title-font); text-align: center; text-shadow: 0 0 10px currentColor; }
.result { display: flex; gap: 18px; align-items: center; }
.r-grade { font: 900 84px var(--title-font); line-height: 1; text-shadow: 0 0 24px currentColor, 0 4px 0 #000; animation: rankpop 0.5s ease-out; }
.r-stats { line-height: 1.6; }

/* ---------- Settings / pause / ending ---------- */
.set { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.set label { width: 60px; color: var(--dim); }
.set input[type="range"] { flex: 1; accent-color: #40e0ff; }
.set span { width: 38px; text-align: right; }
.set.check { cursor: pointer; }
.set-btns { display: flex; gap: 6px; margin-top: 10px; }
button.danger { border-color: #ff6a6a; color: #ffb0b0; }
#pause { position: absolute; inset: 0; background: rgba(4, 6, 14, 0.6); display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 150; pointer-events: none !important; }
#pause div { font: 900 44px var(--title-font); letter-spacing: 8px; color: #eafcff; text-shadow: 0 0 20px rgba(90, 224, 255, 0.8); }
#pause small { color: var(--dim); margin-top: 6px; }
#ending { position: absolute; inset: 0; z-index: 180; background: radial-gradient(ellipse at center, rgba(40, 8, 30, 0.92), rgba(2, 2, 8, 0.97)); display: flex; align-items: center; justify-content: center; }
.e-card { width: 600px; text-align: center; line-height: 1.55; font-size: 13px; animation: fadein 1.5s ease; }
.e-title { font: 900 34px var(--title-font); letter-spacing: 5px; color: #eafcff; text-shadow: 0 0 24px rgba(255, 58, 138, 0.8); margin-bottom: 10px; }
.e-stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin: 14px 0; }
.e-stats div { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 4px; display: flex; flex-direction: column; }
.e-stats small { color: var(--dim); font-size: 10px; }
.e-credits { color: var(--dim); font-size: 10.5px; margin: 12px 0; }
.e-card button { padding: 7px 22px; font-size: 13px; }
@keyframes fadein { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* ---------- Touch controls ---------- */
html, body { touch-action: none; overscroll-behavior: none; -webkit-user-select: none; -webkit-touch-callout: none; }
#touch { display: none; }
body.touch #touch { display: block; position: absolute; inset: 0 0 80px 0; pointer-events: none !important; z-index: 5; }
#touch > * { pointer-events: auto; }
#stick-zone { position: absolute; left: 0; bottom: 0; width: 360px; height: 300px; touch-action: none; }
#stick { position: absolute; left: 110px; top: 200px; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%; border: 2px solid rgba(160, 230, 255, 0.35); background: rgba(10, 20, 40, 0.25); opacity: 0.55; transition: opacity 0.15s; }
#stick.active { opacity: 1; }
#stick .knob { position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px; border-radius: 50%; background: radial-gradient(rgba(160, 240, 255, 0.7), rgba(40, 120, 180, 0.6)); box-shadow: 0 0 12px rgba(90, 224, 255, 0.6); }
.tb { position: absolute; border-radius: 50%; padding: 0; touch-action: none; background: rgba(12, 24, 48, 0.55); border: 2px solid rgba(90, 224, 255, 0.5); color: #eafcff; font: 900 13px var(--title-font); background-size: 70%; background-position: center; background-repeat: no-repeat; }
.tb.on { background-color: rgba(90, 224, 255, 0.4); transform: scale(0.94); }
.tb span { text-shadow: 0 1px 3px #000; }
.tb.attack { right: 26px; bottom: 16px; width: 96px; height: 96px; font-size: 15px; border-color: rgba(255, 90, 140, 0.7); }
.tb.jump { right: 134px; bottom: 10px; width: 68px; height: 68px; }
.tb.sk { width: 56px; height: 56px; }
.tb.sk span { position: absolute; left: 6px; top: 2px; font-size: 11px; }
.tb.sk1 { right: 136px; bottom: 90px; }
.tb.sk2 { right: 88px; bottom: 132px; }
.tb.sk3 { right: 22px; bottom: 132px; }
.tb.sk4 { right: 196px; bottom: 130px; border-color: rgba(255, 226, 122, 0.7); }
.tb.dodge { right: 208px; bottom: 40px; width: 60px; height: 60px; font-size: 8px; border-color: rgba(190, 255, 230, 0.7); }
.tb.mini { width: 46px; height: 46px; font-size: 10px; border-radius: 12px; }
.tb.swap { left: 526px; bottom: 8px; font-size: 18px; }
.tb.hp { left: 370px; bottom: 8px; }
.tb.mp { left: 422px; bottom: 8px; }
.tb.mount { left: 474px; bottom: 8px; }
.tb.pause { right: 12px; top: 10px; width: 40px; height: 40px; }
/* Keep the log and combo meter clear of the thumbs. */
body.touch #log { width: 260px; max-height: 64px; font-size: 10.5px; }
body.touch #combo { top: 60px; right: 64px; }
/* Windows and dialogs get bigger on touch so text and targets stay readable once the stage is scaled down. */
body.touch .menu button { width: 44px; height: 46px; font-size: 15px; }
body.touch .bslot { width: 44px; height: 44px; }
/* On phones the bottom few pixels can sit under the home-bar area, so the EXP bar rides the HUD's top edge. */
body.touch #hud { grid-template-rows: 1fr; padding-bottom: 12px; }
body.touch .bar.exp { position: absolute; left: 0; right: 0; top: -9px; margin: 0; border-width: 1px 0 0; }
body.touch .win-head .x { padding: 2px 10px; font-size: 16px; }

#rotate { display: none; }
@media (orientation: portrait) {
  body.touch #rotate { display: flex; position: fixed; inset: 0; z-index: 1000; background: #05030c; color: var(--text); flex-direction: column; align-items: center; justify-content: center; gap: 12px; font: 700 16px var(--title-font); text-align: center; padding: 24px; }
  body.touch #rotate div { font-size: 54px; color: var(--gold); animation: spin 2.4s ease-in-out infinite; }
}
@keyframes spin { 0%, 30% { transform: rotate(0); } 60%, 100% { transform: rotate(90deg); } }
.win-body, .shop-list, .bot-list, .d-text { touch-action: pan-y; }
.win-head { touch-action: none; }

/* ---------- Confirm ---------- */
#confirm { position: absolute; inset: 0; z-index: 300; background: rgba(2, 4, 10, 0.6); display: flex; align-items: center; justify-content: center; }
#confirm .c-card { width: 380px; background: var(--panel); border: 1px solid var(--gold); border-radius: 8px; padding: 14px 16px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7); font-size: 13px; line-height: 1.5; }
#confirm p { margin: 0; }
body.touch #confirm .c-card { transform: scale(1.25); }

/* ---------- Pixel-art UI skin ----------
   Square corners, hard drop shadows, and heading sizes tuned for Press Start 2P (a very wide face). */
.win, #dialog, #confirm .c-card, #mini, #mtrack, .t-card, #tooltip, .bot-slot, .bot-card, .dex-card, .mission, .quest,
.skill, .eq, .eq-bot, .e-stats div, .slot, .cell, button:not(.tb), .bar, .bb-track, .c-track, #log .ln, .tag, .rar, kbd,
.t-card input, .lv, .bslot, .win-head, .bexp { border-radius: 0 !important; }
.win, #dialog, .t-card, #confirm .c-card, #mini, #tooltip { border-width: 2px; box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.55); }
button:not(.tb) { box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.5); }
button:not(.tb):active:not(:disabled) { transform: translate(1px, 1px); box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.5); }
.bar .fill, .bb-fill { transition: none; }
.bar { border-width: 2px; border-color: #0a0c16; }
.bar label, .bar span { font-family: var(--ui-font); }
body { font-size: 13px; }
#ui { font-size: 13px; }

#mini-name { font-size: 9px; font-weight: 400; margin-bottom: 5px; }
.bb-name { font-size: 11px; font-weight: 400; }
.b-title { font-size: 24px; font-weight: 400; letter-spacing: 2px; text-shadow: 0 0 14px rgba(90, 224, 255, 0.7), 3px 3px 0 #000; }
.b-sub { font-size: 14px; margin-top: 8px; }
.win-head { font-size: 10px; font-weight: 400; padding: 7px 6px 7px 10px; }
.char-top .big { font-size: 12px; font-weight: 400; line-height: 1.8; }
.d-name { font-size: 11px; font-weight: 400; margin-bottom: 8px; }
.t-logo { font-size: 58px; font-weight: 400; letter-spacing: 4px; text-shadow: 0 0 24px rgba(90, 224, 255, 0.8), 5px 5px 0 #04202e; }
.t-logo span { text-shadow: 0 0 24px rgba(255, 58, 138, 0.9), 5px 5px 0 #3a0518; }
.t-sub { font-size: 10px; letter-spacing: 3px; margin: 12px 0 18px; }
#combo { width: 180px; }
.c-num { font-size: 34px; font-weight: 400; text-shadow: 0 0 10px rgba(90, 224, 255, 0.8), 3px 3px 0 #000; }
.c-hits { font-size: 9px; letter-spacing: 3px; margin-top: 4px; }
.c-rank { font-size: 26px; font-weight: 400; margin-top: 4px; text-shadow: 0 0 12px currentColor, 3px 3px 0 #000; }
.m-grade { font-size: 18px; font-weight: 400; width: 38px; }
.r-grade { font-size: 58px; font-weight: 400; text-shadow: 0 0 20px currentColor, 4px 4px 0 #000; }
#pause div { font-size: 28px; font-weight: 400; letter-spacing: 4px; }
.e-title { font-size: 20px; font-weight: 400; letter-spacing: 2px; line-height: 1.5; }
.lv { border-width: 3px; }
.lv b { font-family: var(--title-font); font-size: 13px; font-weight: 400; margin-top: -4px; }
.tb { font-family: var(--title-font); font-size: 9px; }
.tb.attack { font-size: 11px; }

/* ---------- Nanobot choice (starter + requisition rewards) ---------- */
#starter { position: absolute; inset: 0; z-index: 250; background: rgba(4, 3, 12, 0.88); display: flex; align-items: center; justify-content: center; }
.st-card { width: 760px; text-align: center; }
.st-title { font: 14px var(--title-font); color: #eafcff; letter-spacing: 2px; text-shadow: 0 0 12px rgba(90, 224, 255, 0.7), 3px 3px 0 #000; }
.st-card p { color: var(--dim); margin: 12px 0 16px; }
.st-back { margin-top: 16px; }
.pick { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-top: 10px; }
.pick-card { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 8px; background: var(--panel-2); border: 2px solid var(--c); text-align: center; line-height: 1.3; }
.pick-card:hover { background: color-mix(in srgb, var(--c) 18%, #121a30); }
.pick-card img { width: 64px; height: 64px; border: 2px solid #0a0c16; }
.pick-card b { font: 11px var(--title-font); color: var(--c); margin-top: 4px; }
.pick-card .pc-type { font-size: 12px; }
.pick-card small { font-size: 11px; }
#dialog .pick { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }
#dialog .pick-card img { width: 48px; height: 48px; }
.q-head { font: 9px var(--title-font); color: var(--gold); margin: 6px 0; }
.q-head ~ .q-head { margin-top: 14px; }
body.touch .st-card { transform: scale(1.15); }
.tb.attack.talk { border-color: rgba(120, 255, 180, 0.9); background-color: rgba(20, 70, 50, 0.6); font-size: 12px; }
.tb.attack.talk { animation: tb-swap 0.35s ease-out; }
@keyframes tb-swap { 0% { transform: scale(1.18); box-shadow: 0 0 18px rgba(120, 255, 180, 0.9); } 100% { transform: scale(1); } }

/* ---------- Workshop / Wardrobe ---------- */
.tune-row { gap: 10px; }
.tune-lv { width: 44px; font: 12px var(--title-font); color: var(--gold); text-align: center; }
.tuned { color: var(--gold); }
.wd { display: flex; gap: 12px; align-items: flex-start; }
#wd-preview { flex: none; background: radial-gradient(#1a2a4a, #070a14); border: 2px solid var(--line); image-rendering: pixelated; }
.wd-parts { flex: 1; min-width: 0; }
.wd-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.wd-item { display: flex; flex-direction: column; gap: 3px; align-items: flex-start; padding: 5px 6px; background: var(--panel-2); border: 1px solid rgba(255, 255, 255, 0.08); }
.wd-item.on { border-color: var(--gold); }
.wd-item.locked b { color: var(--dim); }
.wd-item button { padding: 1px 7px; font-size: 11px; }
.wd-item small { font-size: 10px; line-height: 1.25; }
.sw { display: inline-block; width: 14px; height: 14px; border: 2px solid #0a0c16; }
.branch-card { min-height: 100px; }
.branch-card small { font-size: 11px; }
button.wide + .stats, .eqs + button.wide { margin: 0 0 8px; }

/* ---------- Cutscenes ---------- */
#cutscene { position: absolute; inset: 0; z-index: 220; cursor: pointer; }
.cs-bar { position: absolute; left: 0; right: 0; height: 56px; background: #000; }
.cs-bar.top { top: 0; }
.cs-bar.bottom { bottom: 0; }
.cs-box { position: absolute; left: 50%; bottom: 66px; transform: translateX(-50%) scale(var(--wz)); transform-origin: 50% 100%; width: 640px; display: flex; gap: 14px; align-items: flex-start; background: var(--panel); border: 2px solid var(--gold); box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.55); padding: 12px; }
.cs-portrait { flex: none; width: 112px; height: 112px; background: radial-gradient(#1e2a48, #070a14); border: 2px solid var(--line); image-rendering: pixelated; }
.cs-body { flex: 1; min-width: 0; }
.cs-name { font: 11px var(--title-font); color: var(--gold); margin: 4px 0 10px; }
.cs-text { font-size: 16px; line-height: 1.5; min-height: 72px; }
.cs-more { color: var(--dim); font-size: 11px; text-align: right; animation: blink 0.9s steps(2, start) infinite; }
@keyframes blink { to { opacity: 0.25; } }
.cs-skip { position: absolute; right: 14px; top: 14px; z-index: 1; }

/* ---------- How to Play ---------- */
.help .menus { margin: 2px 0 10px; font-size: 12px; line-height: 1.9; }
.help .touch-keys { display: none; grid-template-columns: 1fr 1fr; gap: 6px 12px; margin-bottom: 8px; }
.help .touch-keys b { color: var(--gold); font-weight: 600; }
body.touch .help .keys, body.touch .help .menus { display: none; }
body.touch .help .touch-keys { display: grid; }
.help .tips { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 5px; line-height: 1.4; }
