:root {
  font-family: Consolas, "Microsoft YaHei", monospace;
  color: #fff0ca;
  background: #0b1b2c;
  font-synthesis: none;
}
* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
button { font: inherit; cursor: pointer; touch-action: manipulation; }
button:focus-visible { outline: 3px solid #fff1aa; outline-offset: 2px; }
[hidden] { display: none !important; }
.game-frame { position: fixed; inset: 0; overflow: hidden; background: #8bd3dc; isolation: isolate; }
canvas { display: block; width: 100%; height: 100%; object-fit: fill; image-rendering: pixelated; touch-action: none; }

.top-hud {
  position: absolute; z-index: 3; pointer-events: none;
  inset: max(8px, env(safe-area-inset-top)) max(9px, env(safe-area-inset-right)) auto max(9px, env(safe-area-inset-left));
  display: flex; gap: 10px; align-items: flex-start;
}
.vitals, .battle-meta {
  background: #172d47ed; border: 2px solid #b7dee0; padding: 8px 10px;
  box-shadow: 4px 4px #0e2136a8; min-width: 170px;
}
.vitals { width: 228px; }
.vitals > b, .battle-meta > b { display: block; font-size: 14px; white-space: nowrap; }
.vitals > b span { color: #a8e6c2; font-size: 10px; }
.vitals small, .battle-meta small { display: block; font-size: 10px; line-height: 1.55; white-space: nowrap; color: #c8e0e0; }
.vitals strong { color: #ffda79; }
.health, .token-track { position: relative; width: 100%; height: 13px; background: #294058; border: 1px solid #6c9aa4; margin: 5px 0; overflow: hidden; }
.health i, .token-track i { display: block; height: 100%; width: 0; background: #7fd79f; }
.health span { position: absolute; inset: 0; text-align: center; color: #102638; font-size: 9px; font-weight: 900; line-height: 11px; }
.token-track { height: 5px; margin: 3px 0 0; }
.token-track i { background: #ffcc73; }
.battle-meta { min-width: 185px; }
.battle-meta b { color: #ffdb8c; }
.top-buttons { display: flex; margin-left: auto; gap: 5px; pointer-events: auto; }
.top-buttons button {
  border: 2px solid #9ac6c8; background: #203d59e8; color: #fff0c9;
  padding: 7px 9px; font-size: 11px; font-weight: 900; white-space: nowrap; box-shadow: 3px 3px #0d2034;
}
.top-buttons .support-button { border-color: #ffe2a1; color: #ffe6a1; }
.top-buttons button:active, .skill-slot:active, .attack-button:active { transform: translateY(2px); box-shadow: 1px 1px #0d2034; }
.boss-hud {
  position: absolute; z-index: 3; pointer-events: none; top: 86px; left: 50%; transform: translateX(-50%);
  width: min(340px, 38vw); padding: 5px 10px; background: #1b3049ed;
  border: 2px solid #f4c97d; box-shadow: 4px 4px #102239aa; text-align: center;
}
.boss-hud b, .boss-hud small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.boss-hud b { font-size: 12px; color: #ffdc91; }
.boss-hud small { font-size: 10px; color: #d9e6d8; }
.boss-health { height: 11px; border: 1px solid #f7d59a; background: #314154; margin: 4px 0; }
.boss-health i { display: block; height: 100%; width: 0; background: #f08c67; transition: width .15s; }
.event-toast {
  position: absolute; z-index: 4; top: 23%; left: 50%; transform: translateX(-50%);
  max-width: 60%; padding: 8px 14px; background: #ffedb5; color: #173c52;
  border: 3px solid #244b61; font-size: 15px; font-weight: 900; text-align: center;
  opacity: 0; pointer-events: none; transition: opacity .18s;
}
.event-toast.show { opacity: 1; }
.event-ticker {
  position: absolute; bottom: max(8px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  max-width: 44%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  padding: 4px 8px; background: #16364bbd; color: #f5e8b7; font-size: 10px; text-align: center; pointer-events: none;
}

.controls {
  position: absolute; z-index: 3; pointer-events: none;
  inset: auto max(14px, env(safe-area-inset-right)) max(15px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  display: flex; align-items: end; justify-content: space-between;
}
.left-pad, .right-pad { pointer-events: auto; }
.left-pad { text-align: center; }
.left-pad small { display: block; color: #fff0bb; text-shadow: 2px 2px #17354b; font-weight: 900; font-size: 10px; margin-top: 5px; }
.joystick {
  position: relative; width: 122px; height: 122px; border: 3px solid #e6f8e1b9;
  background: #183c5694; box-shadow: 4px 4px #10263e8f; touch-action: none; user-select: none;
}
.joystick::before { content: ""; position: absolute; inset: 21px; border: 2px dashed #d4eee6a1; }
.joystick i {
  position: absolute; width: 44px; height: 44px; left: 36px; top: 36px;
  border: 3px solid #fff7d0; background: #a9e0d0d9; box-shadow: 3px 3px #10263e8f; pointer-events: none;
}
.right-pad { display: flex; align-items: end; gap: 9px; }
.skill-stack { width: 154px; }
.passive-list { width: 100%; max-height: 36px; overflow: auto; margin-bottom: 5px; padding: 3px 5px; border: 1px solid #a6deb9; background: #173d4ccf; color: #d8f7c8; font-size: 9px; line-height: 1.25; }
.skill-slots { display: grid; grid-template-columns: repeat(2, 74px); gap: 6px; }
.skill-slot {
  width: 74px; height: 60px; position: relative; overflow: hidden; text-align: left;
  border: 2px solid #a8d2d5; background: #1b405eea; color: #fff2c7;
  padding: 5px; box-shadow: 3px 3px #0f2439; touch-action: none; user-select: none;
}
.skill-slot.empty { border-style: dashed; background: #193a52ae; color: #9ec3c3; text-align: center; font-size: 19px; }
.skill-slot.passive { border-color: #a6deb9; background: #224f54e8; }
.skill-slot:disabled { opacity: .57; }
.skill-slot.passive:disabled { opacity: 1; }
.skill-slot b { display: block; font-size: 10px; line-height: 1.2; }
.skill-slot small { display: block; font-size: 9px; color: #a9d9e0; margin-top: 4px; }
.skill-slot em { position: absolute; right: 4px; top: 3px; font-size: 9px; font-style: normal; color: #ffcd73; }
.skill-slot .cooldown { position: absolute; inset: 0; display: grid; place-items: center; background: #0a2035c9; color: #fff4b6; font-size: 18px; font-weight: 900; }
.attack-button {
  width: 88px; height: 88px; border: 3px solid #fff1b8; background: #eaa856df;
  color: #183a50; font-size: 21px; font-weight: 1000; box-shadow: 4px 4px #0f2439;
}
.attack-button span { display: block; font-size: 9px; }

.overlay { position: absolute; inset: 0; z-index: 10; display: grid; place-items: center; padding: 12px; background: #0a2037d9; }
.draft-panel, .ending-panel {
  width: min(860px, 94vw); max-height: 94vh; overflow: auto; padding: 16px;
  background: #173650; border: 4px solid #a8d9d5; box-shadow: 7px 7px #061b2e; text-align: center;
}
.draft-head small { color: #86cfd1; font-size: 10px; letter-spacing: 2px; }
.draft-head h1, .ending-panel h1 { margin: 4px 0; font-size: 25px; color: #ffdd87; }
.draft-head p, .ending-panel p { font-size: 12px; margin: 5px 0 12px; color: #d2e9dc; }
.draft-choices { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.draft-choice {
  min-height: 150px; border: 2px solid var(--rarity, #b6c6cd); background: #23485f;
  color: #fff2d8; padding: 11px; text-align: left; box-shadow: 4px 4px #0a2339;
}
.draft-choice:hover { background: #2c6071; }
.draft-choice small { display: block; font-size: 10px; color: var(--rarity, #b6c6cd); font-weight: 900; }
.draft-choice b { display: block; font-size: 17px; margin: 6px 0; }
.draft-choice p { font-size: 11px; line-height: 1.45; color: #d0e2df; margin: 5px 0; }
.draft-choice strong { display: block; color: #ffdc90; font-size: 11px; margin-top: 8px; }
.replace-picker { margin-top: 10px; padding: 9px; background: #0d2a42; }
.replace-picker p { margin: 0 0 7px; font-size: 12px; }
.replace-picker > div { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.replace-picker button, .ending-panel button { background: #f3c979; color: #17334c; border: 2px solid #fff0bd; padding: 8px 12px; font-weight: 900; font-size: 11px; }
.replace-picker #cancelReplace { margin-top: 8px; background: #24485e; color: #e9f2dc; }
.draft-panel > small { display: block; margin-top: 11px; color: #98bfc6; font-size: 10px; }
.ending-panel { width: min(490px, 90vw); }
#endingStats { font-size: 13px; line-height: 1.9; margin: 10px 0; }
.panel-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.panel-actions button { background: #f3c979; color: #17334c; border: 2px solid #fff0bd; padding: 8px 12px; font-weight: 900; font-size: 11px; }
#supportStatus, #reviveStatus, #rankStatus, #scoreSubmitStatus, #myRank { color: #b9ebd3; min-height: 1.4em; }
#savedRunStatus { padding: 8px; border: 2px solid #ffdb8c; background: #244b5d; color: #ffe1a0; }
#supportGameStatus { color: #b9ebd3; min-height: 1.4em; }
.support-rewards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 10px 0; text-align: left; }
.support-rewards p { padding: 10px; margin: 0; border: 2px solid #80c8c6; background: #224962; line-height: 1.55; }
.support-rewards b, .support-rewards strong { color: #ffdf93; }
.video-action { display: inline-block; margin: 2px 0 10px; padding: 8px 12px; border: 2px solid #ffefb5; background: #f3c979; color: #17334c; font-size: 11px; font-weight: 900; text-decoration: none; touch-action: manipulation; }
.video-action:active { transform: translateY(2px); }
.rank-panel { width: min(590px, 94vw); max-height: 94vh; overflow: auto; }
.rank-rows { display: grid; gap: 4px; max-height: 44vh; overflow: auto; margin: 8px 0; }
.rank-row { display: grid; grid-template-columns: 28px 30px minmax(0, 1fr) auto; align-items: center; gap: 8px; padding: 5px; background: #254b5e; text-align: left; font-size: 11px; }
.rank-row img, .rank-avatar { width: 28px; height: 28px; border: 1px solid #a6deb9; background: #3b6771; object-fit: cover; }
.rank-row span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.rank-row b { color: #ffda82; }
.portrait-gate { display: none; }

@media (max-width: 760px), (max-height: 460px) {
  .top-hud { gap: 5px; }
  .vitals, .battle-meta { padding: 4px 6px; min-width: 0; }
  .vitals { width: 148px; }
  .vitals > b, .battle-meta > b { font-size: 11px; }
  .vitals > b span { font-size: 8px; }
  .vitals small, .battle-meta small { font-size: 8px; }
  .battle-meta { min-width: 129px; }
  .top-buttons button { font-size: 9px; padding: 5px; }
  .boss-hud { top: 64px; width: min(245px, 40vw); padding: 3px 6px; }
  .boss-hud b { font-size: 9px; }
  .boss-hud small { font-size: 8px; }
  .boss-health { height: 6px; margin: 2px 0; }
  .event-toast { top: 35%; font-size: 10px; padding: 5px; }
  .event-ticker { font-size: 8px; max-width: 40%; }
  .joystick { width: 90px; height: 90px; }
  .joystick::before { inset: 15px; }
  .joystick i { width: 34px; height: 34px; left: 25px; top: 25px; }
  .skill-slots { grid-template-columns: repeat(2, 58px); gap: 4px; }
  .skill-stack { width: 120px; }
  .passive-list { max-height: 25px; font-size: 7px; margin-bottom: 3px; }
  .skill-slot { width: 58px; height: 48px; padding: 3px; }
  .skill-slot b { font-size: 8px; }
  .skill-slot small, .skill-slot em { font-size: 7px; }
  .attack-button { width: 66px; height: 66px; font-size: 15px; }
  .attack-button span { font-size: 7px; }
  .right-pad { gap: 5px; }
  .draft-panel { padding: 8px; }
  .draft-head h1 { font-size: 17px; }
  .draft-head p { font-size: 9px; margin-bottom: 6px; }
  .draft-choices { gap: 5px; }
  .draft-choice { min-height: 110px; padding: 6px; }
  .draft-choice b { font-size: 12px; margin: 3px 0; }
  .draft-choice p, .draft-choice strong, .draft-choice small { font-size: 8px; }
  .support-rewards p { padding: 6px; font-size: 9px; }
  .video-action { padding: 6px 8px; font-size: 9px; }
}
@media (max-width: 620px) and (orientation: landscape) {
  .battle-meta small:last-child { display: none; }
  .battle-meta { min-width: 100px; }
  .vitals { width: 132px; }
  .top-buttons button { font-size: 8px; padding: 4px; }
  .boss-hud { top: 58px; width: 205px; }
  .controls { inset: auto 7px 8px 7px; }
  .joystick { width: 76px; height: 76px; }
  .joystick::before { inset: 12px; }
  .joystick i { width: 30px; height: 30px; left: 20px; top: 20px; }
  .left-pad small { font-size: 8px; }
  .skill-slots { grid-template-columns: repeat(2, 56px); }
  .skill-stack { width: 116px; }
  .skill-slot { width: 56px; height: 48px; }
  .attack-button { width: 59px; height: 59px; }
}
@media (orientation: portrait) and (pointer: coarse) {
  .portrait-gate {
    position: absolute; inset: 0; z-index: 30; display: flex; flex-direction: column;
    justify-content: center; align-items: center; text-align: center;
    background: #112d43; color: #ffdf91; padding: 24px;
  }
  .portrait-gate b { font-size: 28px; }
  .portrait-gate p { font-size: 14px; color: #c7e8dc; }
}
