:root {
  color-scheme: light;
  --ink: #17201e;
  --paper: #f4f0e8;
  --green: #087f63;
  --mint: #6ee7bd;
  --red: #ed4d44;
  --yellow: #f8c94c;
  --line: rgba(23, 32, 30, .18);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  overflow-x: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  letter-spacing: 0;
}

button { font: inherit; }

body {
  min-height: 100vh;
  background-image: linear-gradient(rgba(23,32,30,.035) 1px, transparent 1px), linear-gradient(90deg, rgba(23,32,30,.035) 1px, transparent 1px);
  background-size: 24px 24px;
}

.game-shell {
  width: min(1480px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px clamp(14px, 3vw, 42px) 12px;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 58px;
  display: flex;
  align-items: center;
  gap: 24px;
  border-bottom: 2px solid var(--ink);
  margin-bottom: 14px;
}

.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.brand-mark {
  width: 39px; height: 39px; display: grid; place-items: center;
  color: #fff; background: var(--green); border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink); font: 900 15px/1 monospace;
}
.brand div { display: grid; }
.brand strong { font-size: 16px; }
.brand span:last-child { font: 700 9px/1.4 monospace; color: #5c6864; }

.topbar-stats { display: flex; gap: clamp(14px, 3vw, 36px); }
.topbar-stats div { display: grid; text-align: right; }
.topbar-stats span { font-size: 9px; font-weight: 800; color: #68736f; }
.topbar-stats strong { font: 800 15px/1.3 monospace; }

.icon-button {
  width: 36px; height: 36px; border: 1px solid var(--ink); background: transparent;
  cursor: pointer; font-size: 18px; transition: .15s;
}
.icon-button:hover { background: var(--yellow); transform: translateY(-1px); }

.stage-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: calc(100vh - 118px);
  min-height: 440px;
  overflow: hidden;
  border: 2px solid var(--ink);
  background: #101817;
  box-shadow: 8px 8px 0 rgba(23,32,30,.18);
  isolation: isolate;
}

#gameCanvas { width: 100%; height: 100%; display: block; }

.screen {
  position: absolute; inset: 0; z-index: 5;
  display: none;
}
.screen.active { display: flex; }

#storeScreen {
  align-items: flex-end;
  justify-content: space-between;
  padding: clamp(26px, 4vw, 68px);
  background: linear-gradient(90deg, rgba(8,16,15,.94) 0%, rgba(8,16,15,.68) 45%, rgba(8,16,15,.08) 72%);
  color: white;
}

.store-copy { max-width: 510px; margin-bottom: 8px; }
.kicker { font: 800 11px/1 monospace; color: var(--mint); margin: 0 0 12px; }
.store-copy h1 { font-size: clamp(42px, 6vw, 86px); line-height: .95; margin: 0 0 22px; letter-spacing: 0; }
.store-copy > p:not(.kicker) { max-width: 460px; font-size: clamp(13px, 1.3vw, 18px); line-height: 1.7; color: #d4ddda; }

.primary-button {
  min-width: 220px; height: 50px; margin-top: 18px; padding: 0 18px 0 22px;
  display: inline-flex; align-items: center; justify-content: space-between; gap: 24px;
  border: 2px solid var(--ink); background: var(--yellow); color: var(--ink);
  box-shadow: 5px 5px 0 var(--ink); font-weight: 900; cursor: pointer; transition: .15s;
}
.primary-button:hover { transform: translate(2px,2px); box-shadow: 3px 3px 0 var(--ink); }
.primary-button b { font-size: 21px; }
.primary-button.dark { background: var(--ink); color: #fff; box-shadow: 4px 4px 0 var(--green); border-color: var(--ink); }

.control-hint { display: flex; gap: 15px; margin-top: 22px; flex-wrap: wrap; color: #aebbb7; font-size: 10px; font-weight: 700; }
kbd { border: 1px solid #84928e; padding: 2px 5px; color: #fff; font: 700 10px monospace; }

.upgrade-panel {
  width: min(335px, 29vw); min-width: 280px;
  background: rgba(244,240,232,.96); color: var(--ink); border: 2px solid var(--ink);
  box-shadow: 7px 7px 0 rgba(110,231,189,.75); padding: 18px;
}
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; border-bottom: 2px solid var(--ink); padding-bottom: 12px; }
.panel-heading span:first-child { font: 800 9px monospace; color: #69736f; }
.panel-heading h2 { margin: 3px 0 0; font-size: 19px; }
.open-tag { color: var(--green); border: 1px solid var(--green); padding: 3px 6px; font: 900 9px monospace; }
.upgrade-list { display: grid; gap: 8px; margin-top: 12px; }
.upgrade {
  width: 100%; min-height: 63px; border: 1px solid var(--line); background: transparent;
  display: grid; grid-template-columns: 36px 1fr auto; align-items: center; gap: 10px;
  padding: 8px; text-align: left; color: var(--ink); cursor: pointer;
}
.upgrade:hover:not(:disabled) { border-color: var(--green); background: rgba(110,231,189,.15); }
.upgrade:disabled { opacity: .48; cursor: not-allowed; }
.upgrade-icon { width: 34px; height: 34px; display: grid; place-items: center; background: var(--ink); color: var(--yellow); font-size: 18px; }
.upgrade-copy { display: grid; gap: 2px; }
.upgrade-copy strong { font-size: 12px; }
.upgrade-copy small { color: #69736f; font-size: 9px; line-height: 1.3; }
.upgrade-price { font: 900 11px monospace; white-space: nowrap; }

.hud { position: absolute; inset: 18px 20px auto; z-index: 3; display: flex; align-items: flex-start; justify-content: space-between; color: #fff; pointer-events: none; text-shadow: 0 2px 4px #000; }
.hud-left { width: 230px; }
.health-row { display: grid; grid-template-columns: 26px 1fr 28px; gap: 7px; align-items: center; font: 800 10px monospace; }
.bar { height: 9px; background: #3e4744; border: 1px solid rgba(255,255,255,.3); }
.bar i { display: block; width: 100%; height: 100%; background: var(--mint); transition: width .2s; }
.loot-row { margin-top: 9px; display: flex; align-items: baseline; gap: 8px; font-size: 9px; }
.loot-row strong { color: var(--yellow); font: 900 16px monospace; }
.loot-row span:last-child { color: #adb8b4; }
.weapon-row { display: flex; align-items: center; gap: 6px; margin-top: 7px; color: #dce6e2; font-size: 9px; }
.weapon-row span { width: 18px; height: 18px; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.45); color: var(--yellow); font: 900 11px monospace; }
.weapon-row strong { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.timer { display: grid; text-align: center; }
.timer span, .danger-meter > span { font-size: 9px; font-weight: 800; text-transform: uppercase; }
.timer strong { font: 900 29px/1.2 monospace; }
.timer.urgent strong { color: var(--red); animation: pulse .55s infinite alternate; }
.danger-meter { display: grid; gap: 5px; text-align: right; }
.pips { display: flex; gap: 3px; }
.pips i { width: 22px; height: 7px; background: rgba(255,255,255,.2); border: 1px solid rgba(255,255,255,.35); }
.pips i.active { background: var(--red); border-color: #ff968e; }

.inventory { position: absolute; z-index: 3; left: 50%; bottom: 17px; transform: translateX(-50%); display: flex; gap: 5px; pointer-events: none; }
.slot { width: 53px; height: 53px; position: relative; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.38); background: rgba(9,16,15,.78); color: white; }
.slot.empty { opacity: .46; }
.slot .item-emoji { font-size: 23px; filter: drop-shadow(0 2px 1px #000); }
.slot small { position: absolute; bottom: 2px; left: 4px; right: 4px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 7px; text-align: center; }
.slot.rare { border-color: var(--yellow); box-shadow: inset 0 0 12px rgba(248,201,76,.28); }

.objective { position: absolute; left: 20px; bottom: 22px; z-index: 3; width: 210px; color: #fff; font-size: 10px; line-height: 1.4; pointer-events: none; }
.objective strong { display: block; color: var(--mint); font-size: 11px; margin-bottom: 3px; }

.boss-hud { position: absolute; z-index: 4; top: 72px; left: 50%; width: min(330px, 40vw); transform: translateX(-50%); color: #fff; pointer-events: none; text-shadow: 0 2px 3px #000; }
.boss-hud > div:first-child { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.boss-hud span { color: #ffaaa4; font: 800 8px monospace; }
.boss-hud strong { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 11px; }
.boss-bar { height: 8px; padding: 1px; border: 1px solid rgba(255,255,255,.7); background: rgba(8,14,13,.8); }
.boss-bar i { display: block; width: 100%; height: 100%; background: var(--red); transition: width .12s; }

.toast { position: absolute; z-index: 10; top: 82px; left: 50%; transform: translate(-50%, -10px); padding: 8px 13px; background: var(--ink); color: #fff; border-left: 3px solid var(--yellow); font-size: 11px; font-weight: 800; opacity: 0; transition: .2s; pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%,0); }

.action-button {
  position: absolute; z-index: 4; left: 50%; bottom: 84px; transform: translateX(-50%);
  height: 42px; min-width: 130px; padding: 0 14px; overflow: hidden;
  border: 1px solid rgba(255,255,255,.7); background: rgba(9,16,15,.9); color: #fff; cursor: pointer;
}
.action-button span { display: inline-grid; place-items: center; width: 23px; height: 23px; margin-right: 8px; border: 1px solid #fff; font: 900 10px monospace; }
.action-button strong { font-size: 11px; }
.action-button i { position: absolute; inset: auto 0 0; height: 3px; width: 0; background: var(--yellow); }

.result-screen { align-items: center; justify-content: center; background: rgba(6,13,12,.75); backdrop-filter: blur(5px); }
.receipt { width: min(360px, calc(100% - 40px)); background: #f6f0df; color: var(--ink); padding: 25px 28px; box-shadow: 9px 9px 0 var(--green); transform: rotate(-.7deg); }
.receipt-head { display: grid; text-align: center; border-bottom: 2px dashed #92968c; padding-bottom: 15px; }
.receipt-head span { font: 900 12px monospace; }
.receipt-head strong { font-size: 27px; margin: 4px 0; }
.receipt-head small { font: 10px monospace; color: #777d76; }
.receipt-items { min-height: 90px; display: grid; gap: 7px; padding: 14px 0; border-bottom: 2px dashed #92968c; }
.receipt-line { display: flex; justify-content: space-between; gap: 12px; font: 11px monospace; }
.receipt-total { display: flex; justify-content: space-between; align-items: baseline; margin-top: 14px; }
.receipt-total span { font-size: 12px; font-weight: 800; }
.receipt-total strong { font: 900 28px monospace; }
.receipt > p { color: #666e68; font-size: 10px; line-height: 1.5; }
.receipt .primary-button { width: 100%; min-width: 0; }

.pause-overlay { position: absolute; inset: 0; z-index: 20; background: rgba(5,10,9,.85); color: white; display: grid; place-content: center; justify-items: center; }
.pause-overlay span { color: var(--mint); font: 800 10px monospace; }
.pause-overlay strong { font-size: 32px; margin-top: 5px; }

.mobile-controls { position: absolute; z-index: 5; inset: auto 18px 18px; display: flex; justify-content: space-between; align-items: flex-end; pointer-events: none; }
.joystick { position: relative; width: 104px; height: 104px; border: 1px solid rgba(255,255,255,.35); border-radius: 50%; background: rgba(0,0,0,.25); pointer-events: auto; touch-action: none; }
.joystick i { position: absolute; left: 30px; top: 30px; width: 42px; height: 42px; border-radius: 50%; background: rgba(255,255,255,.7); }
.mobile-controls button { width: 62px; height: 62px; border-radius: 50%; border: 2px solid #fff; color: #fff; background: rgba(237,77,68,.75); font-weight: 900; pointer-events: auto; touch-action: none; }

footer { height: 34px; display: flex; align-items: flex-end; justify-content: space-between; font: 700 9px monospace; color: #65706c; }
footer button { border: 0; background: none; color: inherit; font: inherit; cursor: pointer; text-decoration: underline; }

@keyframes pulse { to { transform: scale(1.08); } }

@media (max-width: 800px) {
  .game-shell { padding: 8px; }
  .topbar { height: 48px; margin-bottom: 8px; }
  .brand-mark { width: 32px; height: 32px; }
  .brand strong { font-size: 13px; }
  .topbar-stats div:last-child { display: none; }
  .stage-wrap { min-height: 0; max-height: none; height: calc(100vh - 76px); aspect-ratio: auto; }
  #storeScreen { padding: 26px 20px; align-items: flex-end; background: linear-gradient(0deg, rgba(8,16,15,.95) 0%, rgba(8,16,15,.72) 52%, rgba(8,16,15,.1) 100%); }
  .store-copy { width: 100%; }
  .store-copy h1 { font-size: 45px; }
  .store-copy > p:not(.kicker) { max-width: 350px; }
  .upgrade-panel { display: none; }
  .control-hint { display: none; }
  .hud { inset: 12px 12px auto; }
  .hud-left { width: 155px; }
  .timer { position: absolute; left: 50%; transform: translateX(-50%); }
  .timer strong { font-size: 22px; }
  .danger-meter { display: none; }
  .inventory { bottom: 13px; gap: 3px; }
  .slot { width: 39px; height: 39px; }
  .slot .item-emoji { font-size: 18px; }
  .slot small { display: none; }
  .objective { left: 12px; bottom: 125px; }
  .boss-hud { top: 67px; width: 220px; }
  .action-button { display: none !important; }
  footer { display: none; }
}

@media (pointer: coarse) { .mobile-controls:not([hidden]) { display: flex; } }
@media (pointer: fine) { .mobile-controls { display: none !important; } }
