* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%; width: 100%;
  background: #07070d;
  color: #e8e8f2;
  font-family: "Courier New", ui-monospace, Menlo, Consolas, monospace;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#app { position: fixed; inset: 0; overflow: hidden; }

.hidden { display: none !important; }

/* ---------- canvas ---------- */
#game {
  position: absolute; left: 0; top: 0;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  background: #0b0b12;
  box-shadow: 0 0 0 2px #23233a, 0 0 30px rgba(80, 110, 255, .16);
}

/* ---------- HUD ---------- */
#hud {
  position: absolute; left: 0; right: 0; top: 0; z-index: 12;
  padding: calc(6px + env(safe-area-inset-top, 0px)) calc(8px + env(safe-area-inset-right, 0px)) 0 calc(8px + env(safe-area-inset-left, 0px));
  pointer-events: none;
}
.hud-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.hud-left { display: flex; gap: 7px; align-items: flex-start; min-width: 0; }
.hud-stats { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.hud-right { display: flex; align-items: center; gap: 6px; }
.hud-sub { display: flex; gap: 5px; margin-top: 3px; flex-wrap: wrap; }
.hud-sub2 { display: flex; gap: 5px; margin-top: 4px; flex-wrap: wrap; padding-left: 2px; }

/* 角色像素头像 */
.portrait-box {
  width: 34px; height: 42px; flex: 0 0 auto;
  background: linear-gradient(#14142a, #0d0d1a);
  border: 2px solid #3d3d63; border-radius: 3px;
  box-shadow: inset 0 0 0 1px #0a0a14, 0 3px 0 rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
#hud-portrait { image-rendering: pixelated; width: 26px; height: 32px; }

/* 层数 + 进度点 */
.hud-mid {
  position: absolute; left: 50%; top: calc(6px + env(safe-area-inset-top, 0px));
  transform: translateX(-50%); text-align: center; pointer-events: none;
}
.floor-chip {
  display: inline-block; background: rgba(14,14,26,.9); border: 2px solid #3d3d63;
  border-radius: 4px; padding: 2px 9px; font-size: 12px; color: #cdd3ff;
  box-shadow: 0 3px 0 rgba(0,0,0,.5);
}
.floor-chip b { color: #ffd447; font-size: 14px; }
.room-tag { color: #9fb0ff; font-size: 10px; margin-left: 4px; }
.dots { display: flex; gap: 3px; justify-content: center; margin-top: 4px; }
.dots i {
  width: 6px; height: 6px; display: block; background: #2b2b46;
  box-shadow: inset 0 0 0 1px #0a0a14;
}
.dots i.on { background: #7ff0ff; box-shadow: 0 0 6px rgba(127,240,255,.7); }
.dots i.boss { background: #ff5a5a; box-shadow: 0 0 6px rgba(255,90,90,.8); }

.floor-badge {
  font-size: 13px; font-weight: bold; color: #ffd447;
  text-shadow: 1px 1px 0 #000; letter-spacing: 1px;
}
.room-tag { color: #9fb0ff; font-size: 11px; letter-spacing: 0; }

.bar {
  position: relative; width: min(46vw, 176px); height: 14px;
  background: #17172a; border: 2px solid #2e2e4a; border-radius: 3px; overflow: hidden;
}
.bar.xp { height: 8px; }
.bar .fill {
  position: absolute; left: 0; top: 0; bottom: 0; width: 100%;
  background: linear-gradient(#ff7a7a, #c0203a);
}
.bar.xp .fill { background: linear-gradient(#7ff0ff, #2a8fd0); }
.bar .txt {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 10px; color: #fff; text-shadow: 1px 1px 0 #000;
}
.bar.xp .txt { font-size: 8px; }

.chip {
  background: rgba(18, 18, 32, .85); border: 2px solid #33334f; border-radius: 4px;
  padding: 3px 8px; font-size: 12px; font-weight: bold; color: #ffd447;
  text-shadow: 1px 1px 0 #000; white-space: nowrap;
}
.chip.small { font-size: 10px; padding: 2px 6px; color: #b9c6ff; border-width: 1px; background: rgba(14, 14, 26, .7); }

.icon-btn {
  pointer-events: auto; width: 38px; height: 32px;
  background: rgba(28, 28, 48, .92); border: 2px solid #3d3d66; border-radius: 5px;
  color: #cdd3ff; font-size: 11px; cursor: pointer; font-family: inherit;
}
.icon-btn:active { background: #3a3a62; }

/* ---------- boss bar ---------- */
#boss-wrap {
  position: absolute; top: calc(74px + env(safe-area-inset-top, 0px)); left: 50%;
  transform: translateX(-50%); width: min(74vw, 430px); z-index: 12;
  pointer-events: none; text-align: center;
}
#boss-wrap:not(.hidden) { animation: bossBarIn .55s cubic-bezier(.2,.9,.3,1.2); }
@keyframes bossBarIn {
  from { transform: translateX(-50%) scaleX(.15); opacity: 0 }
  to { transform: translateX(-50%) scaleX(1); opacity: 1 }
}
.boss-name {
  font-size: 12px; color: #ffb0b0; letter-spacing: 2px; margin-bottom: 3px;
  text-shadow: 1px 1px 0 #000;
}
.boss-bar { height: 12px; background: #191022; border: 2px solid #6b2240; border-radius: 3px; overflow: hidden; }
.boss-fill { height: 100%; width: 100%; background: linear-gradient(#ff5b6e, #8d0f2c); }

/* ---------- banner & toasts ---------- */
#banner {
  position: absolute; left: 0; right: 0; top: 32%; text-align: center;
  z-index: 14; pointer-events: none; opacity: 1; transition: opacity .45s ease;
}
#banner.fade { opacity: 0; }
#banner-main {
  font-size: clamp(20px, 6vw, 34px); font-weight: bold; color: #fff; letter-spacing: 3px;
  text-shadow: 2px 2px 0 #000, 0 0 14px rgba(120, 150, 255, .65);
}
#banner-sub { font-size: clamp(11px, 3vw, 15px); color: #ffd447; margin-top: 6px; text-shadow: 1px 1px 0 #000; }

#toasts {
  position: absolute; top: calc(104px + env(safe-area-inset-top, 0px)); left: 50%;
  transform: translateX(-50%); display: flex; flex-direction: column; gap: 4px;
  align-items: center; z-index: 13; pointer-events: none;
}
.toast {
  background: rgba(10, 10, 20, .88); border-left: 3px solid #ffd447;
  padding: 4px 10px; font-size: 12px; color: #ffe9a8; white-space: nowrap;
  animation: toastIn .18s ease;
}
.toast.warn { border-left-color: #ff6b6b; color: #ffc9c9; }
.toast.good { border-left-color: #7ff0ff; color: #d4f6ff; }
@keyframes toastIn { from { transform: translateY(-6px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- touch controls ---------- */
#touch { position: absolute; inset: 0; z-index: 20; pointer-events: none; }
#pad, #aim-pad {
  position: absolute; border-radius: 50%;
  background: rgba(40, 44, 74, .28); border: 2px solid rgba(130, 145, 220, .38);
  pointer-events: auto; touch-action: none;
}
#aim-pad { background: rgba(78, 40, 74, .26); border-color: rgba(220, 150, 220, .42); }
#aim-knob {
  position: absolute; width: 54px; height: 54px; left: 50%; top: 50%;
  margin: -27px 0 0 -27px; border-radius: 50%;
  background: rgba(255, 170, 230, .38); border: 2px solid rgba(255, 220, 250, .62);
}
#pad {
  background: rgba(40, 44, 74, .28); border: 2px solid rgba(130, 145, 220, .38);
}
.pad-knob, #pad-knob {
  position: absolute; width: 56px; height: 56px; left: 50%; top: 50%;
  margin: -28px 0 0 -28px; border-radius: 50%;
  background: rgba(150, 170, 255, .45); border: 2px solid rgba(220, 230, 255, .65);
}
#btn-attack {
  position: absolute; width: 98px; height: 98px; border-radius: 50%;
  background: rgba(200, 60, 80, .42); border: 3px solid rgba(255, 150, 160, .72);
  color: #fff; font-size: 16px; font-weight: bold; font-family: inherit;
  pointer-events: auto; touch-action: none;
  text-shadow: 1px 1px 0 #000; box-shadow: 0 4px 0 rgba(120, 20, 40, .5);
}
#btn-attack:active { background: rgba(245, 90, 110, .7); transform: translateY(2px); box-shadow: 0 2px 0 rgba(120, 20, 40, .5); }

#btn-dash {
  position: absolute; border-radius: 50%; overflow: hidden;
  background: rgba(50, 120, 180, .42); border: 3px solid rgba(150, 220, 255, .7);
  color: #e9fbff; font-size: 13px; font-weight: bold; font-family: inherit;
  pointer-events: auto; touch-action: none; text-shadow: 1px 1px 0 #000;
  box-shadow: 0 4px 0 rgba(20, 60, 90, .55);
  display: flex; align-items: center; justify-content: center;
}
#btn-dash.ready { border-color: rgba(190, 245, 255, .95); box-shadow: 0 0 12px rgba(120, 220, 255, .55), 0 4px 0 rgba(20, 60, 90, .55); }
#btn-dash.pressed { transform: translateY(2px); box-shadow: 0 2px 0 rgba(20, 60, 90, .55); }
#btn-dash .dash-fill {
  position: absolute; left: 0; right: 0; bottom: 0; height: 0%;
  background: rgba(8, 16, 32, .62); pointer-events: none;
}
#dash-cd-text { position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%); font-size: 13px; color: #cfefff; }

.chip.weapon { color: #ffe9a8; border-color: #5c4a20; }
.chip.char { color: #b6f0a8; border-color: #2f5233; }
.chip.dash.ready { color: #9fe8ff; border-color: #2d5468; }
.chip.dash.cooling { color: #7d8798; border-color: #33405a; }

.card.weapon-card { border-color: #4a4a7a; }
.card.weapon-card:hover { border-color: #9fb0ff; }
.card.char-card { border-color: #3f5a44; }
.card.char-card:hover { border-color: #b6f0a8; }
.card.char-card .portrait {
  image-rendering: pixelated; flex: 0 0 auto;
  background: linear-gradient(#14142a, #0c0c18);
  border: 2px solid #3d3d63; border-radius: 3px; padding: 2px;
  animation: iconBob 2.2s ease-in-out infinite;
}
.cstats { font-size: 10px; color: #7ff0ff; margin-top: 2px; }
.result-hint { font-size: 11px; color: #8d93bb; margin-top: 8px; }
.cdesc.dim { color: #7f86ab; font-size: 10px; }

/* ---------- 商店 ---------- */
.shop-gold { font-size: 14px; color: #ffd447; margin-bottom: 10px; letter-spacing: 1px; }
.shop-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 6px; }
.shop-row {
  display: flex; align-items: center; gap: 10px; text-align: left;
  background: linear-gradient(#1c1c36, #12121f); border: 2px solid #3b3b62; border-radius: 6px;
  padding: 8px 10px; cursor: pointer; box-shadow: 0 3px 0 #0a0a14;
}
.shop-row:hover { border-color: #7a8cff; }
.shop-row .icon { font-size: 22px; }
.shop-row .texts { flex: 1; min-width: 0; }
.shop-row .sname { font-size: 14px; font-weight: bold; color: #ffe9a8; }
.shop-row .sdesc { font-size: 11px; color: #a9b0d8; }
.shop-row .price { font-size: 13px; font-weight: bold; color: #ffd447; white-space: nowrap; }
.shop-row.sold { opacity: .45; cursor: default; box-shadow: none; }
.shop-row.sold .price { color: #8d93bb; }
.shop-row.poor .price { color: #ff6b6b; }

/* ---------- screens ---------- */
.screen {
  position: absolute; inset: 0; z-index: 30;
  display: flex; align-items: center; justify-content: center;
  background: rgba(6, 6, 12, .84); padding: 12px;
  animation: fadeIn .16s ease;
}
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }

.panel {
  width: min(94vw, 430px); max-height: 92vh; overflow: auto;
  background: linear-gradient(#14142a, #0e0e1c);
  border: 3px solid #35355c; border-radius: 8px;
  box-shadow: 0 8px 0 rgba(0, 0, 0, .55), inset 0 0 0 2px #0a0a14;
  padding: 20px 18px; text-align: center;
}

/* ---------- V4 像素化面板 / 按钮 / 卡片 ---------- */
.panel {
  position: relative; border: 3px solid #454570;
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, .022) 0 2px, rgba(0, 0, 0, 0) 2px 4px),
    linear-gradient(#16162c, #0d0d1a);
  box-shadow: 0 0 0 2px #0a0a14, 0 10px 0 rgba(0, 0, 0, .6), inset 0 0 0 2px #0a0a14;
}
.panel::before {
  content: ''; position: absolute; inset: 5px; border-radius: 4px;
  border: 1px dashed rgba(120, 130, 200, .22); pointer-events: none;
}
.btn { border: 3px solid #454570; box-shadow: 0 4px 0 #07070e, inset 0 -6px 0 rgba(0, 0, 0, .22); }
.btn:hover { border-color: #7a8cff; color: #fff; }
.btn.primary { background: linear-gradient(#3a68d0, #26469a); border-color: #6f9dff; }
.btn.danger { background: linear-gradient(#8a2738, #5e1723); border-color: #c03a4e; }

.card {
  position: relative; border-width: 3px; border-color: #454570;
  box-shadow: 0 6px 0 #07070e, inset 0 -8px 0 rgba(0, 0, 0, .25);
  animation: cardIn .3s cubic-bezier(.2, .9, .3, 1.25) backwards;
  animation-delay: var(--d, 0ms);
}
.card:hover { transform: translateY(-6px) scale(1.04); border-color: #ffd447; box-shadow: 0 8px 0 #07070e, 0 0 20px rgba(255, 212, 71, .35); }
.card:active { transform: translateY(-2px) scale(.99); }
.card .icon { animation: iconBob 1.8s ease-in-out infinite; }
.card.picked { animation: cardPick .24s ease forwards; }
@keyframes cardIn { from { transform: translateY(46px) scale(.82); opacity: 0 } to { transform: none; opacity: 1 } }
@keyframes iconBob { 0%, 100% { transform: translateY(0) } 50% { transform: translateY(-3px) } }
@keyframes cardPick { to { transform: scale(1.2) translateY(-14px); opacity: 0 } }

/* HUD 反馈 */
#hud.lowhp .bar.hp { animation: hpWarn .7s ease-in-out infinite; }
@keyframes hpWarn { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 60, 80, 0) } 50% { box-shadow: 0 0 10px 2px rgba(255, 60, 80, .7) } }
.bar.xp.flash .fill { filter: brightness(1.9); }
.chip.gold { color: #ffd447; border-color: #6a5a26; }
.chip.gold.pulse { animation: goldPulse .36s ease; }
@keyframes goldPulse {
  0% { transform: scale(1) } 40% { transform: scale(1.18); box-shadow: 0 0 12px rgba(255, 212, 71, .8) } 100% { transform: scale(1) }
}
.result-build { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 8px 0 4px; }
.result-build span { background: #1c1c36; border: 2px solid #3b3b62; padding: 2px 7px; font-size: 11px; color: #ffe9a8; }
.result-char { font-size: 13px; color: #b6f0a8; margin-bottom: 6px; }
.panel.wide { width: min(96vw, 640px); }

.title {
  font-size: clamp(28px, 9vw, 46px); font-weight: bold; letter-spacing: 5px; color: #ffd447;
  text-shadow: 3px 3px 0 #7a3b0c, 0 0 18px rgba(255, 200, 60, .35);
}
.subtitle { font-size: clamp(14px, 4vw, 18px); color: #9fb0ff; letter-spacing: 4px; margin: 4px 0 18px; }
.subtitle.small { font-size: 13px; letter-spacing: 2px; margin-bottom: 10px; }
.p-title { font-size: clamp(18px, 5vw, 24px); font-weight: bold; letter-spacing: 3px; margin-bottom: 14px; color: #dfe4ff; }
.p-title.danger-text { color: #ff6b6b; }
.p-title.gold-text { color: #ffd447; }

.menu-list { display: flex; flex-direction: column; gap: 10px; }
.menu-list.row { flex-direction: row; justify-content: center; flex-wrap: wrap; }

.btn {
  display: block; width: 100%; padding: 13px 18px;
  background: #20203a; border: 2px solid #3d3d66; border-radius: 5px;
  color: #e8e8f2; font-size: 16px; font-weight: bold; font-family: inherit;
  cursor: pointer; box-shadow: 0 3px 0 #0a0a14; letter-spacing: 1px;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #0a0a14; }
.btn.primary { background: #2f57b0; border-color: #6f9dff; }
.btn.danger { background: #6d1f2c; border-color: #c03a4e; }
.btn.small { width: auto; padding: 7px 14px; font-size: 13px; }
.btn.wide-btn { margin-top: 14px; }
.btn:disabled { opacity: .45; box-shadow: none; }

.record, .hint { font-size: 11px; color: #8d93bb; margin-top: 14px; line-height: 1.6; }
.record.warn { color: #ffb0b0; }
.hint { color: #6f749b; margin-top: 6px; }
.confirm-text { font-size: 13px; color: #c3c8e6; line-height: 1.7; margin-bottom: 16px; }

.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 4px; border-bottom: 1px solid #26263f; font-size: 14px; margin-bottom: 4px;
}

.result { font-size: 13px; color: #ccd2f0; line-height: 2; margin-bottom: 16px; }
.result b { color: #ffd447; }

/* ---------- reward cards ---------- */
.cards { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.card {
  width: min(30vw, 165px); min-height: 150px; padding: 10px 8px;
  background: linear-gradient(#1c1c36, #12121f);
  border: 2px solid #3b3b62; border-radius: 6px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  box-shadow: 0 4px 0 #0a0a14; transition: transform .1s, border-color .1s;
}
.card:hover { border-color: #7a8cff; }
.card:active { transform: translateY(2px); box-shadow: 0 2px 0 #0a0a14; }
.card .icon { font-size: 30px; line-height: 1; }
.card .cname { font-size: 14px; font-weight: bold; color: #ffe9a8; }
.card .cdesc { font-size: 11px; color: #a9b0d8; line-height: 1.5; }
.card .ccount { font-size: 10px; color: #7ff0ff; }

@media (max-aspect-ratio: 1/1) {
  .cards { flex-direction: column; align-items: center; }
  .card { width: min(88vw, 360px); min-height: 0; flex-direction: row; justify-content: flex-start; text-align: left; gap: 12px; padding: 12px; }
  .card .icon { font-size: 26px; }
  .card .texts { display: flex; flex-direction: column; gap: 3px; }
}

@media (max-width: 430px) {
  .bar { width: 42vw; }
  .floor-badge { font-size: 11px; }
  .chip { font-size: 11px; }
}
