:root {
  font-family: "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  color: #fff4d2;
  background: #111e2d;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }

body {
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 42%, #27394c 0, #111e2d 72%);
}

.account-screen {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: clamp(24px, 5vh, 48px);
  padding: 20px;
  overflow: auto;
  background: radial-gradient(circle at 50% 35%, #354e65 0, #111e2d 72%);
}
.account-screen[hidden] { display: none; }
.account-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; width: min(920px, 100%); }
.account-card { display: grid; gap: 16px; align-content: start; border: 5px solid #0a1522; padding: clamp(16px, 3vw, 30px); background: #26394b; box-shadow: 0 10px 0 #09131e, inset 0 4px #597184; }
.account-card h2 { margin: 0; font-size: clamp(22px, 3vw, 38px); }
.account-card input { width: 100%; min-height: 52px; border: 4px solid #0a1522; border-radius: 0; padding: 8px 12px; background: #fff4d2; color: #18212b; font-family: inherit; font-size: 20px; font-weight: 700; }
.account-card button { width: 100%; }
.account-status { min-height: 2.8em; margin: 0; color: #ffb5d1; font-size: 16px; font-weight: 700; }
.save-status { position: absolute; z-index: 5; left: 50%; bottom: 18px; transform: translateX(-50%); padding: 5px 10px; background: #612e3b; color: #fff4d2; font-size: 15px; font-weight: 700; }
.save-status[hidden] { display: none; }
.inventory-use { display: none; margin-top: 14px; }
.inventory-use:disabled { opacity: .5; cursor: default; }

.game-shell {
  width: min(100vw, calc((100dvh - 120px) * 16 / 9));
  height: min(calc(100dvh - 120px), 56.25vw);
  transform: translateY(-60px);
}

.game-stage {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #45647a;
  box-shadow: 0 0 0 6px #0a1522, 0 22px 65px #050b12a6;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.hud {
  position: absolute;
  z-index: 2;
  inset: clamp(9px, 1.7vw, 22px) clamp(10px, 2vw, 26px) auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  color: #fff6d6;
  font-size: clamp(12px, 1.5vw, 21px);
  font-weight: 900;
  text-shadow: 2px 2px #18212b, -2px 2px #18212b, 2px -2px #18212b, -2px -2px #18212b;
  white-space: nowrap;
  pointer-events: none;
}
.hud[hidden] { display: none; }
#score-total { text-align: center; }
#enemy-distance { text-align: right; }
.hud.is-title #time-remaining,
.hud.is-title #enemy-distance { visibility: hidden; }

.screen-shade {
  position: absolute;
  inset: 0;
  background: linear-gradient(#0717247a, #0717240d 56%, #07172455);
  pointer-events: none;
  transition: opacity 150ms ease;
}
.screen-shade.is-hidden { opacity: 0; }

.overlay {
  position: absolute;
  z-index: 3;
  inset: 10% 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(12px, 3vh, 30px);
  text-align: center;
  pointer-events: none;
}
.overlay-buttons button { pointer-events: auto; }
.overlay[hidden], button[hidden] { display: none !important; }

h1 {
  margin: 0;
  padding: 0 16px;
  color: #fff6d6;
  font-size: clamp(36px, 6.2vw, 88px);
  font-weight: 900;
  letter-spacing: .11em;
  line-height: 1.2;
  text-shadow: 0 .08em 0 #19232c, .06em .12em 0 #19232c, -.06em .12em 0 #19232c, 0 .2em 0 #0b1723;
  white-space: nowrap;
}

.overlay-buttons {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: clamp(10px, 1.8vw, 24px);
}
.overlay[data-mode="title"] .overlay-buttons,
.overlay[data-mode="paused"] .overlay-buttons { flex-direction: column; align-items: center; }

button {
  min-width: clamp(120px, 17vw, 220px);
  min-height: clamp(42px, 5vw, 66px);
  padding: 7px 18px;
  border: 4px solid #16212b;
  border-radius: 0;
  background: #f5d38a;
  box-shadow: 0 6px 0 #825c42, inset 0 3px #fff3c3;
  color: #18212b;
  font: 900 clamp(16px, 2.2vw, 30px)/1 "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  cursor: pointer;
  touch-action: manipulation;
}
button:hover { background: #ffe2a1; transform: translateY(-2px); }
button:active { transform: translateY(4px); box-shadow: 0 2px 0 #825c42; }
button:focus-visible { outline: 3px solid white; outline-offset: 5px; }

.shop-entry {
  position: absolute;
  z-index: 3;
  right: clamp(8px, 1.8vw, 18px);
  bottom: clamp(8px, 1.8vw, 18px);
  min-width: 0;
  min-height: 0;
  padding: 6px 12px;
  font-size: clamp(12px, 1.7vw, 22px);
}

.panel-backdrop {
  position: fixed;
  z-index: 10;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  background: #0a1625e8;
}
.panel-backdrop[hidden] { display: none; }
.panel {
  width: min(94vw, 1040px);
  max-height: 100%;
  overflow: auto;
  border: 5px solid #0a1522;
  background: #26394b;
  box-shadow: 0 12px 0 #09131e, inset 0 4px #597184;
  padding: clamp(14px, 2vw, 28px);
}
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.panel h2, .panel h3 { margin: 0; color: #fff4d2; text-shadow: 3px 3px #111c29; }
.panel h2 { font-size: clamp(26px, 4vw, 50px); }
.panel h3 { font-size: clamp(19px, 2.3vw, 30px); margin-bottom: 14px; }
.panel-close { min-width: 48px; min-height: 48px; padding: 0; font-size: 30px; }
.bag-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.bag-column { min-width: 0; border: 3px solid #111e2d; background: #354e5d; padding: clamp(10px, 1.5vw, 18px); }
.item-list { display: grid; gap: 10px; }
.item-card {
  width: 100%;
  min-width: 0;
  min-height: 54px;
  text-align: left;
  font-size: clamp(15px, 1.8vw, 24px);
  white-space: nowrap;
}
.item-card:disabled { opacity: .55; cursor: default; }
.passive-item:disabled { opacity: 1; }
.item-card.is-selected, .shop-card.is-selected { outline: 4px solid #ffb5d1; outline-offset: 2px; background: #ffe2a1; }
.panel-status { min-height: 1.5em; color: #ffdda1; font-size: clamp(15px, 1.7vw, 22px); font-weight: 700; }
.inventory-panel .panel-status { margin-top: 18px; }
.shop-balance { margin: -6px 0 18px; font-size: clamp(18px, 2vw, 27px); font-weight: 900; }
.shop-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.shop-card {
  min-width: 0;
  min-height: 190px;
  padding: 12px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  font-size: clamp(14px, 1.5vw, 20px);
}
.shop-card strong { font-size: clamp(18px, 1.8vw, 26px); white-space: nowrap; }
.shop-card small { font-size: .8em; }
.shop-card:disabled { opacity: .48; cursor: default; }
.shop-icon { color: #9d476a; font-size: clamp(32px, 4vw, 54px); line-height: 1; }
.shop-actions { display: flex; align-items: center; gap: 22px; margin-top: 20px; }
.shop-actions button:disabled { opacity: .55; cursor: default; }

.touch-controls {
  position: fixed;
  z-index: 4;
  right: clamp(18px, 5vw, 64px);
  bottom: max(18px, env(safe-area-inset-bottom));
  left: clamp(18px, 5vw, 64px);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  pointer-events: none;
}
.touch-controls[hidden] { display: none; }
.touch-button {
  width: clamp(64px, 13vw, 88px);
  height: clamp(64px, 13vw, 88px);
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 4px solid #0b1723;
  border-radius: 12px;
  background: #f5d38a;
  box-shadow: 0 7px 0 #825c42, inset 0 3px #fff3c3;
  font-size: clamp(34px, 6vw, 52px);
  line-height: 1;
  pointer-events: auto;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.touch-button.is-active { background: #ffb5d1; box-shadow: 0 7px 0 #a64c76, inset 0 3px #ffe3ed; }
.touch-button:disabled { opacity: .72; cursor: default; }

@media (max-width: 640px) {
  .account-screen { justify-content: flex-start; padding: 28px 16px; }
  .account-options { grid-template-columns: 1fr; gap: 18px; }
  .account-card { gap: 10px; }
  .account-status { min-height: 1.4em; }
  .game-stage { box-shadow: none; }
  .overlay { inset: 7% 0 auto; gap: 8px; }
  h1 { font-size: clamp(26px, 8vw, 48px); }
  button { min-width: 102px; min-height: 34px; padding: 4px 9px; border-width: 3px; font-size: clamp(12px, 3vw, 17px); box-shadow: 0 4px 0 #825c42; }
  .hud { font-size: clamp(9px, 1.9vw, 12px); gap: 5px; }
  .touch-button { width: 68px; height: 68px; min-width: 0; min-height: 0; font-size: 38px; }
  .shop-entry { min-width: 0; min-height: 0; padding: 3px 6px; font-size: 11px; }
  .panel { width: 100%; padding: 12px; }
  .panel-heading { margin-bottom: 12px; }
  .panel-close { min-width: 44px; min-height: 44px; font-size: 27px; }
  .bag-columns { gap: 8px; }
  .bag-column { padding: 8px; }
  .item-card { min-width: 0; min-height: 44px; padding: 5px; font-size: 13px; }
  .shop-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .shop-card { min-width: 0; min-height: 130px; gap: 3px; padding: 5px; }
  .shop-actions { flex-wrap: wrap; gap: 8px; }
}

@media (pointer: coarse) {
  .inventory-use { display: block; width: 100%; }
  .shop-entry { min-width: 68px; min-height: 44px; padding: 4px 8px; font-size: 16px; }
}
