:root {
  --ink: #090a0a;
  --coal: #111312;
  --panel: #181a18;
  --panel-2: #22231f;
  --panel-3: #2b2a24;
  --line: #4d3b29;
  --line-hot: #a86f2f;
  --amber: #e4a849;
  --amber-bright: #ffd37a;
  --teal: #55c2bd;
  --teal-dark: #174745;
  --cream: #f2e7d2;
  --muted: #a79d8d;
  --dim: #736d63;
  --danger: #e2674f;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #080909;
  color: var(--cream);
  font-family: "Avenir Next", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-feature-settings: "tnum" 1;
}

button { font: inherit; }

#app {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 12px;
  height: 100vh;
  height: 100dvh;
  padding: 10px;
  background-color: #0b0c0c;
}

#stage {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #14110e;
  border: 1px solid #5a432c;
  border-radius: 5px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.48), inset 0 0 0 2px #171310;
}

#stage::after {
  position: absolute;
  inset: 5px;
  z-index: 2;
  border: 1px solid rgba(226, 168, 73, 0.22);
  pointer-events: none;
  content: "";
}

#game {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  cursor: crosshair;
  background: #211b15;
}

/* ---------- Command rail ---------- */

#sidebar {
  display: flex;
  flex: 0 0 clamp(288px, 22vw, 318px);
  flex-direction: column;
  gap: 6px;
  height: 100%;
  overflow-y: auto;
  padding: 11px;
  border: 1px solid #5b452e;
  border-radius: 5px;
  background: var(--panel);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.52), inset 0 0 0 2px #101110;
  scrollbar-color: #6d4d2c #111312;
  scrollbar-width: thin;
  user-select: none;
}

.brand {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  position: relative;
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  color: #17120b;
  background: var(--amber);
  border: 1px solid var(--amber-bright);
  clip-path: polygon(20% 0, 80% 0, 100% 20%, 100% 80%, 80% 100%, 20% 100%, 0 80%, 0 20%);
}

.brand-mark::after {
  position: absolute;
  inset: 4px;
  border: 1px solid rgba(43, 29, 13, 0.45);
  content: "";
  clip-path: inherit;
}

.brand-mark span { position: relative; z-index: 1; font-size: 19px; transform: rotate(-8deg); }
.brand-copy { min-width: 0; }

.eyebrow {
  overflow: hidden;
  color: var(--teal);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 7px;
  font-weight: 800;
  letter-spacing: 1.35px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand h1 {
  margin-top: 2px;
  color: var(--cream);
  font-size: 17px;
  font-weight: 850;
  letter-spacing: 0.6px;
  line-height: 1.05;
}

.brand-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.best { max-width: 70px; color: var(--dim); font-size: 8px; line-height: 1.15; text-align: right; }

.reset-run {
  width: 23px;
  min-height: 20px;
  padding: 0 !important;
  color: var(--dim) !important;
  font-size: 15px !important;
  line-height: 1;
  background: transparent !important;
  border-color: transparent !important;
}

#hud {
  display: grid;
  grid-template-columns: 1.3fr 0.85fr 0.85fr;
  gap: 4px;
}

.stat {
  display: flex;
  min-width: 0;
  min-height: 42px;
  flex-direction: column;
  justify-content: center;
  padding: 5px 7px;
  background: var(--panel-2);
  border: 1px solid #35332c;
  border-top-color: #5a4732;
}

.stat .label {
  overflow: hidden;
  color: var(--dim);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stat > span:last-child {
  margin-top: 1px;
  color: var(--cream);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 15px;
  font-weight: 850;
  line-height: 1;
}

.stat-gold > span:last-child { color: var(--amber-bright); }
.stat.combo {
  grid-column: 1 / -1;
  min-height: 0;
  height: 4px;
  padding: 0;
  color: var(--amber-bright);
  background: #342516;
  border: 0;
  text-align: center;
}
.stat.combo:has(#combo:not(:empty)) { height: 22px; padding: 3px 8px; }
.stat.combo #combo { margin: 0; font-size: 11px; }

.core-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 7px;
  min-height: 19px;
}

.core-row .label,
#coreText { color: var(--muted); font-size: 9px; font-weight: 700; }
#coreText { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.core-track {
  height: 7px;
  overflow: hidden;
  background: #090a09;
  border: 1px solid #454038;
}

#coreBar {
  width: 100%;
  height: 100%;
  background: var(--teal);
  box-shadow: 0 0 12px rgba(85, 194, 189, 0.38);
  transition: width 0.2s ease;
}

#controls,
#speeds,
.btn-row,
.resume-actions,
.qp-btns { display: flex; gap: 4px; }
#speeds { flex: 1; }
#speeds button,
.btn-row button { flex: 1; }

button {
  min-height: 28px;
  padding: 4px 8px;
  color: var(--cream);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.1;
  background: #252620;
  border: 1px solid #554430;
  border-radius: 3px;
  cursor: pointer;
  transition: transform 90ms ease, background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}

button:hover:not(:disabled) {
  color: #fff5e2;
  background: #343027;
  border-color: #9e6b33;
}

button:active:not(:disabled) { transform: translateY(1px); }
button:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
button:disabled { color: #746f66; background: #1a1b19; border-color: #302f2a; cursor: not-allowed; }
button.active { color: #cafffb; background: var(--teal-dark); border-color: var(--teal); }

button.primary {
  min-height: 34px;
  color: #21160b;
  background: var(--amber);
  border-color: var(--amber-bright);
  box-shadow: inset 0 -3px 0 rgba(85, 48, 16, 0.34);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0.2px;
}

button.primary:hover:not(:disabled) { color: #160f08; background: #f1b95c; border-color: #ffe0a0; }

.header-action {
  min-height: 24px;
  padding: 3px 6px;
  color: var(--muted);
  background: transparent;
  border-color: #42382c;
  font-size: 9px;
}

.mode-badge {
  padding: 3px 5px;
  color: var(--amber-bright);
  background: #2b2116;
  border: 1px solid #654826;
  border-radius: 2px;
  font-size: 8px;
  font-weight: 800;
  white-space: nowrap;
}

#startWave { width: 100%; }
#autoBtn.active { color: #caffd8; background: #25432e; border-color: #62b977; }

#wavePreview {
  display: flex;
  max-height: 34px;
  flex-wrap: wrap;
  gap: 2px 8px;
  overflow: hidden;
  padding: 5px 7px;
  color: var(--muted);
  background: #141614;
  border: 1px solid #34322c;
  font-size: 9px;
}

#wavePreview .pv { display: inline-flex; align-items: center; gap: 4px; }
#wavePreview .pv.event { color: #f3cd7b; font-weight: 800; }
.dot { display: inline-block; width: 7px; height: 7px; border: 1px solid rgba(255,255,255,0.28); border-radius: 50%; }

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 14px;
  color: var(--amber);
  font-size: 9px;
  font-weight: 850;
  letter-spacing: 1.1px;
  text-transform: uppercase;
}

.section-title small { color: var(--dim); font-size: 8px; font-weight: 650; letter-spacing: 0; }
.lv-row { display: flex; align-items: center; gap: 8px; }
.lv-row > .section-title { flex: 0 0 auto; }
.lv-row .lv-sel { flex: 1; }
.lv-sel { display: flex; gap: 3px; }
.lv-sel button { min-height: 25px; flex: 1; padding: 3px 1px; font-size: 9px; }

#palette {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
}

.tool {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 50px;
  grid-template-columns: 30px minmax(0, 1fr);
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: 4px;
  padding: 5px 5px;
  overflow: hidden;
  text-align: left;
  background: #20221f;
  border-color: #413b30;
}

.tool::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 2px;
  background: var(--tool-color, #76532f);
  content: "";
}

.tool.active {
  background: #233533;
  border-color: var(--teal);
  box-shadow: inset 0 0 0 1px rgba(85, 194, 189, 0.16);
}

.tool-icon {
  display: grid;
  grid-row: span 2;
  width: 30px;
  height: 30px;
  place-items: center;
  background: transparent;
  border: 0;
  border-radius: 0;
  font-size: 14px;
}

.tool-icon img {
  display: block;
  width: 34px;
  height: 34px;
  object-fit: contain;
  filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.34));
}

.lock-mark {
  position: absolute;
  right: -2px;
  bottom: -2px;
  padding: 2px 3px;
  color: #e8ddc8;
  background: #24221d;
  border: 1px solid #75634d;
  border-radius: 2px;
  font: 700 5px/1 ui-monospace, monospace;
  letter-spacing: .4px;
}

.asset-fallback { line-height: 1; }
.inline-asset { width: 30px; height: 30px; object-fit: contain; filter: drop-shadow(0 3px 2px rgba(0,0,0,.34)); }
.sel-title { display: flex; align-items: center; gap: 6px; }

.tool-name {
  overflow: hidden;
  color: #e8ddc8;
  font-size: 9px;
  font-weight: 800;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tool-cost {
  color: var(--amber-bright);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 8px;
  line-height: 1;
}

.tool-key { position: absolute; top: 2px; right: 3px; color: #6f695f; font: 7px ui-monospace, monospace; }
.tool.cant .tool-cost { color: var(--danger); }
.tool.locked { opacity: 0.46; }
.tool-lock { color: var(--dim) !important; white-space: nowrap; }

#selected {
  min-height: 45px;
  padding: 6px 8px;
  background: #141614;
  border: 1px solid #3b382f;
  border-left: 2px solid var(--teal);
  font-size: 10px;
}

.sel-empty { padding-top: 7px; color: #777166; font-size: 9px; text-align: center; }
.sel-title { margin-bottom: 2px; color: var(--cream); font-weight: 800; }
.sel-title .lv { color: var(--amber-bright); font-size: 9px; }
.sel-stats { color: var(--muted); line-height: 1.35; }
.sel-stats b { color: var(--cream); }
.oc { color: #81ded9; font-size: 10px; }

#buffs { display: flex; min-height: 23px; flex-wrap: wrap; align-items: center; gap: 3px; }
.buff { padding: 1px 4px; background: #20221f; border: 1px solid #514331; border-radius: 2px; font-size: 14px; cursor: help; }
.buff-empty { color: #706b63; font-size: 9px; }

.hint {
  padding: 6px 7px;
  color: #7d776e;
  background: #121412;
  border-left: 2px solid #5f472d;
  font-size: 8px;
  line-height: 1.45;
}

.hint b { color: #a9967b; }
.mobile-only,
.hint-mobile { display: none; }

/* ---------- Overlays ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 5, 5, 0.82);
  backdrop-filter: blur(5px);
}

.modal.hidden,
.build-confirm.hidden,
.tutorial-coach.hidden,
#toast.hidden,
#quickPop.hidden { display: none; }

.modal-box {
  width: min(720px, calc(100vw - 32px));
  max-width: 720px;
  padding: 24px 28px;
  color: var(--cream);
  background: #171917;
  border: 1px solid #8f6536;
  border-radius: 4px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.7), inset 0 0 0 3px #0f100f;
  text-align: center;
}

.modal-box h2 { margin-bottom: 16px; color: var(--amber-bright); font-size: 22px; letter-spacing: 1px; }
#draftCards { display: flex; justify-content: center; gap: 10px; }

.card {
  display: flex;
  width: 180px;
  min-height: 180px;
  flex-direction: column;
  align-items: center;
  gap: 9px;
  padding: 18px 14px;
  border-color: #564630;
  border-radius: 3px;
}

.card:hover { transform: translateY(-3px); background: #302a21; border-color: var(--amber); }
.card-icon { font-size: 34px; }
.card-name { color: var(--cream); font-size: 15px; font-weight: 850; }
.card-desc { color: var(--muted); font-size: 11px; line-height: 1.5; }

#overStats,
.resume-info { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; color: var(--muted); font-size: 14px; }
#overStats b { color: var(--amber-bright); }
.resume-actions { justify-content: center; }

.modal-kicker {
  display: block;
  margin-bottom: 5px;
  color: var(--teal);
  font: 800 9px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 1.2px;
}

.mode-box { max-width: 860px; }
.mode-cards,
.stage-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }

.mode-card,
.stage-card {
  display: flex;
  min-height: 190px;
  flex-direction: column;
  align-items: flex-start;
  gap: 9px;
  padding: 18px;
  text-align: left;
  background: #20221f;
  border-color: #544631;
}

.mode-card:hover:not(:disabled),
.stage-card:hover:not(:disabled) { transform: translateY(-2px); }
.mode-icon { font-size: 31px; line-height: 1; }
.mode-card strong,
.stage-card strong { color: var(--cream); font-size: 16px; }
.mode-card small,
.stage-card small { min-height: 42px; color: var(--muted); font-size: 11px; line-height: 1.45; }
.mode-card b,
.stage-card b { margin-top: auto; color: var(--amber-bright); font-size: 10px; }
.stage-card.locked { opacity: .48; }
.stage-no { color: var(--teal); font: 800 9px/1 ui-monospace, monospace; letter-spacing: 1px; }
.stage-box #stageBack { margin-top: 14px; }
#winStats { margin-bottom: 18px; color: var(--muted); font-size: 13px; line-height: 1.7; }

#toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  z-index: 200;
  padding: 9px 18px;
  color: #fff2dc;
  background: #713324;
  border: 1px solid #d97859;
  border-radius: 3px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.45);
  font-size: 12px;
  transform: translateX(-50%);
  animation: toast-in 150ms ease-out;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

#quickPop {
  position: absolute;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 7px;
  color: var(--cream);
  background: rgba(19, 21, 19, 0.96);
  border: 1px solid #83603a;
  border-radius: 3px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.55);
  white-space: nowrap;
}

#qpTitle { color: var(--amber-bright); font-size: 10px; font-weight: 800; }
.qp-btns button { min-height: 25px; flex: 1; padding: 3px 6px; font-size: 10px; }

.build-confirm {
  position: absolute;
  bottom: 12px;
  left: 50%;
  z-index: 60;
  display: flex;
  width: min(500px, calc(100% - 24px));
  align-items: center;
  gap: 7px;
  padding: 8px;
  color: var(--cream);
  background: rgba(19, 21, 19, 0.96);
  border: 1px solid #83603a;
  border-radius: 4px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.62);
  transform: translateX(-50%);
  backdrop-filter: blur(8px);
}

.build-confirm-copy { display: grid; min-width: 0; flex: 1; gap: 2px; }
.build-confirm-copy span { color: var(--amber-bright); font-size: 9px; font-weight: 800; }
.build-confirm-copy strong { overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.build-confirm button { min-width: 76px; min-height: 42px; }

.tutorial-coach {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 55;
  display: flex;
  width: min(360px, calc(100% - 24px));
  align-items: center;
  gap: 10px;
  padding: 10px 11px;
  color: var(--cream);
  background: rgba(19, 21, 19, .96);
  border: 1px solid #8f6536;
  border-left: 3px solid var(--amber);
  border-radius: 4px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .58);
  backdrop-filter: blur(8px);
}

.tutorial-copy { display: grid; min-width: 0; flex: 1; gap: 3px; }
.tutorial-copy span { color: var(--teal); font: 800 8px/1 ui-monospace, monospace; letter-spacing: .6px; }
.tutorial-copy strong { color: var(--amber-bright); font-size: 12px; }
.tutorial-copy p { color: var(--muted); font-size: 10px; line-height: 1.35; }
.tutorial-coach button { min-height: 36px; padding-inline: 8px; font-size: 9px; }
.tutorial-focus { border-color: var(--amber-bright) !important; box-shadow: 0 0 0 2px rgba(228, 168, 73, .24) !important; animation: tutorial-focus 1.15s ease-in-out infinite; }

@keyframes tutorial-focus {
  50% { box-shadow: 0 0 0 5px rgba(228, 168, 73, .08) !important; }
}

@media (max-width: 1040px) {
  #app { gap: 8px; padding: 8px; }
  #sidebar { flex-basis: 280px; }
  .tool { grid-template-columns: 27px minmax(0, 1fr); padding-inline: 4px; }
  .tool-icon { width: 27px; height: 27px; font-size: 12px; }
  .tool-icon img { width: 30px; height: 30px; }
}

@media (max-width: 820px) {
  html,
  body {
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    background: #0b0c0c;
  }

  body { -webkit-tap-highlight-color: transparent; }

  #app {
    display: flex;
    min-height: 100dvh;
    height: auto;
    flex-direction: column;
    gap: 7px;
    padding: max(6px, env(safe-area-inset-top)) 6px max(10px, env(safe-area-inset-bottom));
  }

  #stage {
    position: sticky;
    top: 0;
    z-index: 30;
    width: 100%;
    height: auto;
    aspect-ratio: 8 / 5;
    flex: none;
    border-radius: 4px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.66), 0 2px 0 #0b0c0c;
  }

  #game {
    width: 100%;
    height: auto;
    touch-action: manipulation;
  }

  #sidebar {
    width: 100%;
    height: auto;
    flex-basis: auto;
    gap: 8px;
    overflow: visible;
    padding: 10px 9px 14px;
    border-radius: 4px;
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.4), inset 0 0 0 2px #101110;
  }

  #sidebar > header {
    display: flex;
    min-height: 42px;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding-bottom: 7px;
    border-bottom: 1px solid var(--line);
  }

  #sidebar > header h1 {
    overflow: hidden;
    font-size: 17px;
    font-weight: 850;
    letter-spacing: -0.2px;
    line-height: 1.1;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #sidebar > header > div { min-width: 0; flex: 0 1 auto; }
  #sidebar > header .best { max-width: 88px; }
  #modeBadge { display: none; }
  #modeMenu { min-width: 44px; min-height: 42px; }
  #resetRun { min-width: 42px; min-height: 42px; padding: 0 !important; }

  .brand {
    grid-template-columns: 34px minmax(0, 1fr) auto;
    min-height: 38px;
    gap: 8px;
    padding-bottom: 7px;
  }

  .brand-mark { width: 32px; height: 32px; }
  .brand-mark span { font-size: 16px; }
  .brand h1 { font-size: 16px; }
  .eyebrow { font-size: 6px; letter-spacing: 1.1px; }
  .best { max-width: 96px; font-size: 8px; }

  #hud { gap: 5px; }
  .stat { min-height: 48px; padding: 7px 8px; }
  .stat .label { font-size: 9px; }
  .stat > span:last-child { font-size: 18px; }

  .core-row { min-height: 26px; gap: 8px; }
  .core-row .label,
  #coreText { font-size: 10px; }
  .core-track { height: 9px; }

  #controls {
    display: grid;
    grid-template-columns: minmax(0, 3fr) minmax(74px, 1.35fr) 44px 44px;
    gap: 5px;
  }

  #speeds { min-width: 0; gap: 4px; }
  #controls button,
  #speeds button {
    min-width: 0;
    min-height: 44px;
    padding: 6px 4px;
    font-size: 11px;
  }

  #autoBtn { white-space: nowrap; }
  #pause,
  #mute { padding-inline: 0 !important; font-size: 14px !important; }

  #startWave { min-height: 48px; font-size: 13px; }
  #wavePreview { max-height: 38px; padding: 7px 8px; font-size: 10px; }
  #repair { min-height: 42px; }
  #repair:disabled { display: none; }

  #skills {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
  }

  #skills .skill {
    position: relative;
    min-width: 0;
    min-height: 44px;
    padding: 6px 4px;
    overflow: hidden;
    font-size: 10px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #skills .tool-key { display: none; }
  #skills .ready { color: #fff3d7; border-color: var(--amber); }

  .section-title { min-height: 18px; font-size: 10px; }
  .section-title small { font-size: 9px; }
  .desktop-only { display: none; }
  .mobile-only { display: inline; }

  .lv-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 7px; }
  .lv-sel { gap: 4px; }
  .lv-sel button { min-height: 42px; font-size: 10px; }
  #blueprintBtn { min-height: 42px; padding-inline: 9px; white-space: nowrap; }

  #palette {
    display: grid;
    grid-auto-columns: minmax(112px, 31vw);
    grid-auto-flow: column;
    grid-template-columns: none;
    grid-template-rows: repeat(2, 64px);
    gap: 6px;
    width: 100%;
    padding: 1px 1px 7px;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity;
    scrollbar-color: #6d4d2c #111312;
    scrollbar-width: thin;
  }

  .tool {
    min-height: 64px;
    grid-template-columns: 38px minmax(0, 1fr);
    column-gap: 7px;
    padding: 7px 8px;
    scroll-snap-align: start;
  }

  .tool-icon { width: 38px; height: 38px; }
  .tool-icon img { width: 42px; height: 42px; }
  .tool-name { font-size: 10px; }
  .tool-cost { font-size: 9px; }
  .tool-key { display: none; }

  #selected { min-height: 56px; padding: 8px 10px; font-size: 11px; }
  .sel-empty { padding-top: 10px; font-size: 10px; }
  .sel-stats { line-height: 1.45; }

  .btn-row { gap: 6px; }
  .btn-row button,
  #cycleMode { min-height: 44px; }

  #buffs { min-height: 32px; }

  .hint { padding: 9px 10px; font-size: 10px; line-height: 1.5; }
  .hint-desktop { display: none; }
  .hint-mobile { display: inline; }

  #quickPop {
    top: auto !important;
    right: 8px;
    bottom: 8px;
    left: 8px !important;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding: 7px;
    background: rgba(15, 17, 15, 0.94);
    backdrop-filter: blur(8px);
  }

  #qpTitle {
    max-width: 112px;
    overflow: hidden;
    font-size: 10px;
    text-overflow: ellipsis;
  }

  .qp-btns { min-width: 0; flex: 1; gap: 5px; }
  .qp-btns button { min-height: 42px; padding: 4px 8px; font-size: 11px; }

  .modal {
    align-items: flex-end;
    padding: 12px 8px max(8px, env(safe-area-inset-bottom));
  }

  .modal-box {
    width: 100%;
    max-height: calc(100dvh - 20px);
    padding: 20px 16px 18px;
    overflow-y: auto;
    border-radius: 8px 8px 4px 4px;
  }

  .modal-box h2 { margin-bottom: 13px; font-size: 19px; }

  #draftCards {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .card {
    display: grid;
    width: 100%;
    min-height: 86px;
    grid-template-columns: 46px minmax(0, 1fr);
    grid-template-rows: auto auto;
    gap: 3px 10px;
    padding: 12px 14px;
    text-align: left;
  }

  .card-icon { grid-row: span 2; font-size: 30px; text-align: center; }
  .card-name { font-size: 14px; }
  .card-desc { font-size: 11px; line-height: 1.35; }

  #bpCards {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .bp-card {
    display: flex;
    width: 100%;
    min-height: 0;
    align-items: stretch;
    gap: 7px;
    padding: 12px;
    text-align: left;
  }

  .bp-grid {
    display: grid;
    width: 100%;
    aspect-ratio: 8 / 5;
    grid-template-columns: repeat(24, minmax(0, 1fr));
    overflow: hidden;
    background: #0c0e0d;
    border: 1px solid #433a2e;
  }

  .bp-cell { min-width: 0; background: #151816; border: 1px solid rgba(255, 255, 255, 0.015); }
  .bp-wall { background: #8a755b; }
  .bp-rock { background: #3e4542; }
  .bp-mine { background: #a7782f; }
  .bp-hl { background: #244442; }
  .bp-spawn { background: #7652a2; }
  .bp-core { background: #d79236; }
  #bpClose { width: 100%; min-height: 44px; }

  .resume-actions { flex-direction: column; gap: 7px; }
  .resume-actions button,
  #restart { width: 100%; min-height: 46px; }

  #toast {
    right: 12px;
    bottom: max(18px, env(safe-area-inset-bottom));
    left: 12px;
    padding: 10px 14px;
    text-align: center;
    transform: none;
  }

  .build-confirm {
    right: 8px;
    bottom: 8px;
    left: 8px;
    width: auto;
    transform: none;
  }

  .tutorial-coach {
    top: 8px;
    left: 8px;
    width: min(380px, calc(100% - 16px));
  }

  .mode-cards,
  .stage-cards { grid-template-columns: 1fr; gap: 7px; }

  .mode-card,
  .stage-card {
    display: grid;
    min-height: 92px;
    grid-template-columns: 42px minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    align-items: center;
    gap: 3px 10px;
    padding: 12px 13px;
  }

  .mode-icon,
  .stage-no { grid-row: span 2; }
  .mode-card strong,
  .stage-card strong { font-size: 14px; }
  .mode-card small,
  .stage-card small { min-height: 0; font-size: 10px; }
  .mode-card b,
  .stage-card b { grid-column: 3; grid-row: 1 / span 2; margin-top: 0; text-align: right; }
  .stage-box #stageBack { width: 100%; min-height: 44px; }

  @keyframes toast-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
  }
}

/* ============================================================
   2026 surface pass — carved stone, warm brass and touch clarity
   ============================================================ */

:root {
  --ink: #100e0c;
  --coal: #181512;
  --panel: #211d18;
  --panel-2: #2a251e;
  --panel-3: #342c22;
  --line: #5b4934;
  --line-soft: rgba(242, 211, 156, 0.12);
  --line-strong: rgba(242, 211, 156, 0.28);
  --amber: #dca754;
  --amber-bright: #f5d28b;
  --amber-deep: #9a672e;
  --teal: #68c2b4;
  --teal-soft: #a7e0d5;
  --teal-deep: #224b46;
  --cream: #f4ead9;
  --muted: #b7aa97;
  --dim: #847a6d;
  --danger: #e5745c;
  --surface-shadow:
    0 0 0 1px rgba(255, 240, 210, 0.07),
    0 18px 36px rgba(0, 0, 0, 0.34),
    inset 0 1px rgba(255, 244, 219, 0.05);
  --control-shadow:
    0 0 0 1px rgba(255, 236, 202, 0.07),
    0 2px 2px rgba(0, 0, 0, 0.2),
    inset 0 1px rgba(255, 255, 255, 0.035);
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  color: var(--cream);
  background:
    radial-gradient(circle at 12% 8%, rgba(120, 77, 34, 0.23), transparent 30%),
    radial-gradient(circle at 80% 96%, rgba(40, 94, 86, 0.13), transparent 34%),
    #100e0c;
}

button,
input,
select,
textarea { font: inherit; }

button,
.tool,
.skill,
.card,
.mode-card,
.stage-card {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

h1,
h2,
h3,
.modal-kicker,
.mode-card strong,
.stage-card strong { text-wrap: balance; }

p,
.card-desc,
.mode-card small,
.stage-card small,
.resume-info { text-wrap: pretty; }

#wave,
#kills,
#coreText,
#combo,
#resumeInfo,
#overStats,
#winStats,
.tool-cost,
.skill-state { font-variant-numeric: tabular-nums; }

#app {
  gap: 14px;
  padding: 12px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.012), rgba(255, 255, 255, 0.012)),
    radial-gradient(circle at 42% 18%, #201a14 0, #100e0c 48%, #0b0a09 100%);
}

#stage {
  border: 1px solid #766044;
  border-radius: 15px;
  background: #17120e;
  box-shadow:
    0 0 0 4px #272019,
    0 0 0 5px rgba(245, 210, 139, 0.16),
    0 24px 60px rgba(0, 0, 0, 0.52),
    inset 0 1px rgba(255, 241, 213, 0.08);
}

#stage::before {
  position: absolute;
  inset: 0;
  z-index: 3;
  border-radius: inherit;
  box-shadow:
    inset 0 0 34px rgba(0, 0, 0, 0.34),
    inset 0 1px rgba(255, 235, 198, 0.13);
  content: "";
  pointer-events: none;
}

#stage::after {
  inset: 6px;
  z-index: 4;
  border-color: rgba(245, 210, 139, 0.15);
  border-radius: 10px;
}

#game { background: #251d15; }

#sidebar {
  flex-basis: clamp(300px, 23vw, 330px);
  gap: 8px;
  padding: 14px;
  border: 1px solid #68543c;
  border-radius: 16px;
  background:
    linear-gradient(145deg, rgba(255, 237, 207, 0.035), transparent 24%),
    linear-gradient(180deg, #242019, #1b1814 62%, #181512);
  box-shadow: var(--surface-shadow);
}

#sidebar > header {
  display: flex;
  min-height: 46px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 1px 1px 10px;
  border-bottom: 1px solid rgba(224, 184, 118, 0.2);
}

#sidebar > header h1 {
  color: #fff0d2;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.35px;
  line-height: 1.08;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.48);
}

#sidebar > header > div {
  display: flex !important;
  min-width: 0;
  align-items: center;
  justify-content: flex-end;
  gap: 7px !important;
}

#sidebar .best {
  color: #938777;
  font-size: 9px;
  line-height: 1.2;
}

.mode-badge {
  min-height: 23px;
  padding: 5px 8px 4px;
  color: #f7d996;
  border: 0;
  border-radius: 7px;
  background: linear-gradient(180deg, #3a2b1c, #2b2117);
  box-shadow:
    0 0 0 1px rgba(224, 168, 84, 0.32),
    inset 0 1px rgba(255, 232, 184, 0.08);
  font-size: 9px;
  letter-spacing: 0.15px;
}

.header-action,
#resetRun {
  min-width: 36px;
  min-height: 32px;
  padding: 6px 8px;
  color: #c3b7a5;
  border: 0;
  border-radius: 8px;
  background: #2c2720;
  box-shadow: var(--control-shadow);
  font-size: 10px;
}

#resetRun { padding: 0 !important; font-size: 14px !important; }

#hud { gap: 7px; }

.stat {
  min-height: 48px;
  padding: 7px 9px;
  border: 0;
  border-radius: 10px;
  background: linear-gradient(160deg, #302a22, #25211b 66%);
  box-shadow: var(--control-shadow);
}

.stat .label {
  color: #9e9282;
  font-size: 8px;
  font-weight: 650;
  letter-spacing: 0.65px;
}

.stat > span:last-child { margin-top: 3px; font-size: 16px; }

.stat.combo {
  height: 3px;
  min-height: 3px;
  border-radius: 999px;
  background: #38281a;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.55);
}

.stat.combo:has(#combo:not(:empty)) {
  height: 24px;
  padding: 5px 9px;
  border-radius: 7px;
  background: linear-gradient(90deg, #442d18, #322218);
  box-shadow: var(--control-shadow);
}

.core-track {
  height: 9px;
  border: 0;
  border-radius: 999px;
  background: #0e0d0b;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(244, 231, 209, 0.08);
}

#coreBar {
  border-radius: inherit;
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.23), 0 0 12px rgba(104, 194, 180, 0.18);
  transition: width 200ms ease-out, background-color 200ms ease-out;
}

button {
  min-height: 34px;
  padding: 7px 10px;
  color: #eadfce;
  border: 0;
  border-radius: 9px;
  background: linear-gradient(180deg, #332e26, #29251f);
  box-shadow: var(--control-shadow);
  font-size: 11px;
  font-weight: 700;
  transition-property: transform, color, background-color, box-shadow, filter;
  transition-duration: 130ms;
  transition-timing-function: ease-out;
}

button:hover:not(:disabled) {
  color: #fff4df;
  background: linear-gradient(180deg, #40382d, #322c24);
  box-shadow:
    0 0 0 1px rgba(245, 210, 139, 0.24),
    0 4px 8px rgba(0, 0, 0, 0.24),
    inset 0 1px rgba(255, 255, 255, 0.06);
}

button:active:not(:disabled) { transform: translateY(1px) scale(0.96); }

button:focus-visible {
  outline: 3px solid var(--teal-soft);
  outline-offset: 2px;
}

button:disabled {
  color: #746d63;
  background: #211e1a;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.035);
  opacity: 0.72;
}

button.active {
  color: #d7fff7;
  background: linear-gradient(180deg, #315953, #25423e);
  box-shadow:
    0 0 0 1px rgba(104, 194, 180, 0.62),
    inset 0 1px rgba(215, 255, 247, 0.12),
    0 4px 12px rgba(22, 63, 58, 0.22);
}

button.primary {
  min-height: 42px;
  color: #281b0d;
  border: 0;
  border-radius: 11px;
  background: linear-gradient(180deg, #f2c773, #d99e47 72%, #c98838);
  box-shadow:
    0 0 0 1px rgba(255, 226, 165, 0.4),
    0 5px 12px rgba(80, 48, 16, 0.36),
    inset 0 1px rgba(255, 249, 221, 0.42),
    inset 0 -2px rgba(110, 64, 20, 0.2);
  font-size: 12px;
  letter-spacing: 0.1px;
}

button.primary:hover:not(:disabled) {
  color: #1d1309;
  background: linear-gradient(180deg, #f8d58d, #e6ac55 72%, #d4913d);
  box-shadow:
    0 0 0 1px rgba(255, 231, 180, 0.52),
    0 7px 16px rgba(80, 48, 16, 0.4),
    inset 0 1px rgba(255, 255, 255, 0.46);
}

#controls,
#speeds,
.btn-row,
.resume-actions,
.qp-btns { gap: 7px; }

#wavePreview {
  max-height: 38px;
  padding: 7px 9px;
  border: 0;
  border-radius: 8px;
  background: rgba(13, 14, 12, 0.66);
  box-shadow: inset 0 0 0 1px rgba(244, 231, 209, 0.06);
  font-size: 9px;
}

.section-title {
  min-height: 18px;
  color: #dcb772;
  font-size: 9px;
  letter-spacing: 1.25px;
}

.lv-sel { gap: 5px; }
.lv-sel button { min-height: 31px; border-radius: 8px; }

#palette { gap: 7px; }

.tool {
  min-height: 57px;
  padding: 7px;
  border: 0;
  border-radius: 11px;
  background: linear-gradient(150deg, #302c25, #25221d 72%);
  box-shadow: var(--control-shadow);
}

.tool::before {
  width: 3px;
  border-radius: 0 3px 3px 0;
  opacity: 0.72;
}

.tool:hover:not(:disabled) { background: linear-gradient(150deg, #393229, #2c2821 72%); }

.tool.active {
  border: 0;
  background: linear-gradient(145deg, #32544e, #253a37 72%);
  box-shadow:
    0 0 0 2px rgba(104, 194, 180, 0.62),
    0 7px 16px rgba(0, 0, 0, 0.25),
    inset 0 1px rgba(213, 255, 246, 0.11);
}

.tool-icon img,
.skill-icon,
.inline-asset {
  outline: 1px solid rgba(255, 255, 255, 0.08);
  outline-offset: -1px;
  border-radius: 8px;
}

.tool-name { color: #eee2d0; font-size: 9px; }
.tool-cost { color: #e7c37e; }

#skills { gap: 7px; }

.skill {
  min-height: 47px;
  padding: 5px 7px 5px 4px;
  border: 0;
  border-radius: 11px;
  background: linear-gradient(150deg, #2d2923, #24211c 72%);
  box-shadow: var(--control-shadow);
}

.skill.ready {
  border: 0;
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--skill-color) 62%, transparent),
    0 0 14px color-mix(in srgb, var(--skill-color) 20%, transparent),
    inset 0 1px rgba(255, 255, 255, 0.08);
}

.skill-name { color: #e9ddcb; }
.skill-state { font-size: 8px; }

#selected {
  min-height: 52px;
  padding: 8px 10px;
  border: 0;
  border-radius: 10px;
  background: #191815;
  box-shadow:
    inset 3px 0 var(--teal),
    inset 0 0 0 1px rgba(244, 231, 209, 0.06);
}

.buff {
  padding: 3px 6px;
  border: 0;
  border-radius: 7px;
  background: #2a2721;
  box-shadow: var(--control-shadow);
}

.hint {
  padding: 8px 9px;
  color: #8f8578;
  border: 0;
  border-radius: 8px;
  background: rgba(13, 14, 12, 0.5);
  box-shadow: inset 3px 0 rgba(220, 167, 84, 0.38);
  line-height: 1.5;
}

.modal {
  padding: 24px;
  background:
    radial-gradient(circle at 50% 38%, rgba(119, 79, 39, 0.2), transparent 42%),
    rgba(8, 7, 6, 0.84);
  backdrop-filter: blur(10px) saturate(0.76);
  -webkit-backdrop-filter: blur(10px) saturate(0.76);
}

.modal:not(.hidden) .modal-box {
  animation: modal-arrive 260ms cubic-bezier(0.2, 0, 0, 1) both;
}

.modal-box {
  padding: 28px 30px 32px;
  border: 0;
  border-radius: 22px;
  background:
    linear-gradient(145deg, rgba(255, 241, 214, 0.045), transparent 22%),
    linear-gradient(180deg, #25211b, #1c1915);
  box-shadow:
    0 0 0 1px rgba(245, 210, 139, 0.27),
    0 30px 90px rgba(0, 0, 0, 0.72),
    inset 0 1px rgba(255, 248, 229, 0.08);
}

.modal-kicker {
  margin-bottom: 8px;
  color: #8cd0c3;
  font-size: 9px;
  letter-spacing: 1.8px;
  text-transform: uppercase;
}

.modal-box h2 {
  margin-bottom: 20px;
  color: #f8d997;
  font-size: clamp(20px, 3vw, 28px);
  font-weight: 800;
  letter-spacing: -0.55px;
  line-height: 1.08;
}

#draftCards,
.mode-cards,
.stage-cards { gap: 14px; }

.card,
.mode-card,
.stage-card {
  border: 0;
  border-radius: 15px;
  background:
    linear-gradient(145deg, rgba(255, 238, 205, 0.035), transparent 28%),
    linear-gradient(180deg, #302a22, #27221c);
  box-shadow: var(--control-shadow);
}

.card:hover:not(:disabled),
.mode-card:hover:not(:disabled),
.stage-card:hover:not(:disabled) {
  transform: translateY(-3px);
  background:
    linear-gradient(145deg, rgba(255, 238, 205, 0.06), transparent 28%),
    linear-gradient(180deg, #3a3025, #2d271f);
  box-shadow:
    0 0 0 1px rgba(245, 210, 139, 0.34),
    0 12px 24px rgba(0, 0, 0, 0.3),
    inset 0 1px rgba(255, 255, 255, 0.06);
}

.mode-card,
.stage-card {
  min-height: 210px;
  gap: 11px;
  padding: 21px;
}

.mode-icon {
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  border-radius: 15px;
  background: #1e1b17;
  box-shadow: inset 0 0 0 1px rgba(244, 231, 209, 0.08);
  font-size: 29px;
}

.mode-card strong,
.stage-card strong { color: #f3e5cf; font-size: 17px; letter-spacing: -0.15px; }

.mode-card small,
.stage-card small { color: #b2a693; font-size: 11px; line-height: 1.55; }

.mode-card b,
.stage-card b { color: #efd08f; font-size: 10px; letter-spacing: 0.2px; }

.stage-card:disabled {
  filter: saturate(0.34);
  opacity: 0.54;
}

.resume-actions { justify-content: center; }
.resume-actions button { min-width: 132px; }

.tutorial-coach {
  top: 16px;
  left: 16px;
  width: min(390px, calc(100% - 32px));
  gap: 13px;
  padding: 13px 14px 14px 17px;
  border: 0;
  border-radius: 15px;
  background:
    linear-gradient(135deg, rgba(255, 238, 205, 0.06), transparent 35%),
    rgba(27, 25, 21, 0.94);
  box-shadow:
    0 0 0 1px rgba(245, 210, 139, 0.29),
    inset 4px 0 var(--amber),
    0 16px 38px rgba(0, 0, 0, 0.54);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.tutorial-copy { gap: 5px; }
.tutorial-copy span { color: #8fd5c8; font-size: 8px; letter-spacing: 0.9px; }
.tutorial-copy strong { color: #f7d894; font-size: 13px; letter-spacing: -0.1px; }
.tutorial-copy p { color: #b9ad9b; font-size: 10px; line-height: 1.5; }
.tutorial-coach button { min-height: 42px; border-radius: 10px; }

.build-confirm,
#qpTitle + .qp-btns,
#qpTitle {
  font-variant-numeric: tabular-nums;
}

.build-confirm,
#quickPanel,
#quickActions,
#quick {
  border: 0;
  border-radius: 14px;
  background: rgba(28, 25, 21, 0.96);
  box-shadow:
    0 0 0 1px rgba(245, 210, 139, 0.28),
    0 16px 42px rgba(0, 0, 0, 0.58),
    inset 0 1px rgba(255, 255, 255, 0.05);
}

#quickPanel,
#quickActions,
#quick { backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }

#toast {
  border: 0;
  border-radius: 11px;
  background: linear-gradient(180deg, #8a4431, #6e3428);
  box-shadow:
    0 0 0 1px rgba(255, 196, 165, 0.34),
    0 12px 32px rgba(0, 0, 0, 0.44);
}

@keyframes modal-arrive {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 1180px) and (min-width: 821px) {
  #app { gap: 10px; padding: 9px; }
  #sidebar { flex-basis: 305px; padding: 11px; }
  #sidebar > header h1 { font-size: 15px; }
  #sidebar .best { display: none; }
  .mode-badge { padding-inline: 6px; }
  .tool { min-height: 53px; padding: 6px; }
  .tool-icon img { width: 32px; height: 32px; }
}

@media (pointer: coarse) {
  button,
  .header-action,
  #resetRun,
  .lv-sel button,
  .skill,
  .tool { min-height: 44px; }
}

@media (max-width: 820px) {
  #app {
    gap: 9px;
    padding: max(7px, env(safe-area-inset-top)) 7px max(12px, env(safe-area-inset-bottom));
    background:
      radial-gradient(circle at 50% 0, #241b13, #100e0c 58%),
      #100e0c;
  }

  #stage {
    border-radius: 13px;
    box-shadow:
      0 0 0 2px #282019,
      0 0 0 3px rgba(245, 210, 139, 0.14),
      0 14px 34px rgba(0, 0, 0, 0.56);
  }

  #sidebar {
    gap: 9px;
    padding: 12px 11px calc(16px + env(safe-area-inset-bottom));
    border-radius: 14px;
  }

  #sidebar > header { min-height: 52px; padding-bottom: 9px; }
  #sidebar > header h1 { font-size: 17px; }
  #sidebar > header > div { gap: 6px !important; }
  #modeMenu,
  #resetRun { min-width: 44px; min-height: 44px; }

  #hud { gap: 6px; }
  .stat { min-height: 54px; padding: 8px 10px; }
  .stat > span:last-child { font-size: 19px; }
  .stat .label { font-size: 9px; }

  #controls { gap: 6px; }
  #startWave { min-height: 52px; font-size: 14px; }

  .section-title { min-height: 22px; font-size: 10px; }

  #palette { gap: 8px; padding-bottom: 10px; }
  .tool {
    min-height: 68px;
    border-radius: 12px;
    grid-template-columns: 40px minmax(0, 1fr);
  }
  .tool-name { font-size: 11px; }
  .tool-cost { font-size: 10px; }

  #skills { gap: 7px; }
  #skills .skill { min-height: 52px; border-radius: 12px; }
  .skill-name { font-size: 10px; }
  .skill-state { font-size: 8px; }

  #selected { min-height: 61px; padding: 10px 12px; }
  .hint { font-size: 10px; }

  .modal {
    align-items: flex-end;
    padding: 12px 8px max(8px, env(safe-area-inset-bottom));
  }

  .modal-box {
    max-height: calc(100dvh - max(20px, env(safe-area-inset-top)));
    padding: 23px 17px 20px;
    border-radius: 20px 20px 9px 9px;
  }

  .modal-box h2 { margin-bottom: 16px; font-size: 22px; }

  .mode-cards,
  .stage-cards { gap: 9px; }

  .mode-card,
  .stage-card {
    min-height: 104px;
    padding: 13px 14px;
    border-radius: 14px;
    grid-template-columns: 46px minmax(0, 1fr) auto;
    gap: 4px 11px;
  }

  .mode-icon { width: 46px; height: 46px; border-radius: 13px; font-size: 25px; }
  .mode-card strong,
  .stage-card strong { font-size: 15px; }
  .mode-card small,
  .stage-card small { font-size: 11px; line-height: 1.4; }
  .mode-card b,
  .stage-card b { font-size: 10px; }

  .card { border-radius: 13px; }
  .resume-actions button,
  #restart { min-height: 48px; }

  .tutorial-coach {
    top: 10px;
    left: 10px;
    width: min(420px, calc(100% - 20px));
    padding: 12px 13px 12px 16px;
    border-radius: 13px;
  }
  .tutorial-copy strong { font-size: 13px; }
  .tutorial-copy p { font-size: 10px; }
  .tutorial-coach button { min-width: 64px; min-height: 44px; }
}

@media (max-width: 560px) {
  .mode-card,
  .stage-card {
    grid-template-columns: 44px minmax(0, 1fr);
  }

  .mode-card b,
  .stage-card b {
    grid-column: 2;
    grid-row: 3;
    justify-self: start;
    margin-top: 4px;
  }

  .mode-icon,
  .stage-no { grid-row: 1 / span 3; }
}

@media (prefers-reduced-motion: reduce) {
  .modal:not(.hidden) .modal-box { animation: none; }
  button { transition-duration: 0.01ms; }
}

@media (max-width: 820px) and (orientation: landscape) and (max-height: 500px) {
  html,
  body { overflow: hidden; }

  #app {
    display: grid;
    height: 100dvh;
    min-height: 0;
    grid-template-columns: minmax(0, 1.6fr) minmax(280px, 0.85fr);
    grid-template-rows: 1fr;
  }

  #stage {
    position: relative;
    top: auto;
    height: 100%;
    aspect-ratio: auto;
  }

  #game { width: auto; height: auto; max-width: 100%; max-height: 100%; }

  #sidebar {
    height: 100%;
    overflow-y: auto;
    overscroll-behavior-y: contain;
  }
}

@media (pointer: coarse) and (min-width: 700px) and (max-width: 1180px) {
  #game { touch-action: manipulation; }
  #sidebar { flex-basis: 310px; }
  #controls button,
  #speeds button,
  .lv-sel button,
  #blueprintBtn,
  .btn-row button,
  #cycleMode,
  #repair { min-height: 42px; }
  .tool { min-height: 58px; }
  .qp-btns button { min-height: 44px; }
}

@media (max-height: 700px) and (min-width: 821px) {
  #sidebar { gap: 4px; padding-block: 8px; }
  #wavePreview,
  .hint { display: none !important; }
  .tool { min-height: 44px; }
  .stat { min-height: 36px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ============================================================
   新功能组件样式（追加于既有皮肤之后，不覆盖原主题）
   ============================================================ */

/* ---------- 技能栏 ---------- */

#skills {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
}

.skill {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 42px;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 3px;
  padding: 3px 5px 3px 3px;
  overflow: hidden;
  text-align: left;
  border-color: color-mix(in srgb, var(--skill-color) 34%, #413b30);
}

.skill::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 2px;
  background: var(--skill-color);
  content: "";
  opacity: .65;
}

.skill-icon {
  display: block;
  width: 34px;
  height: 34px;
  object-fit: contain;
  filter: saturate(.55) brightness(.72) drop-shadow(0 3px 2px rgba(0,0,0,.35));
}

.skill-copy { display: grid; min-width: 0; gap: 2px; }
.skill-name { overflow: hidden; font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.skill-state { color: var(--dim); font: 7px/1 ui-monospace, monospace; }

.skill:disabled { opacity: .72; }
.skill.ready .skill-icon { filter: saturate(1.05) brightness(1.06) drop-shadow(0 0 5px color-mix(in srgb, var(--skill-color) 55%, transparent)); }
.skill.ready .skill-state { color: var(--skill-color); }
.skill.ready::before { opacity: 1; }

#blueprintBtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

#upgradeAll {
  min-height: 31px;
  padding-inline: 8px;
  white-space: nowrap;
  color: #fff2c9;
  background: linear-gradient(180deg, #6f4d20, #493115);
  border-color: #c58a38;
  box-shadow: inset 0 1px rgba(255, 240, 189, 0.14);
}

#upgradeAll:hover:not(:disabled) {
  color: #fff8e6;
  background: linear-gradient(180deg, #8b6128, #5a3b18);
  border-color: #efb65b;
}

@media (pointer: coarse) {
  #upgradeAll { min-height: 42px; }
}

@media (max-width: 820px) {
  .lv-row {
    grid-template-columns: minmax(0, 1fr) auto auto;
  }

  .lv-row > .section-title { display: none; }
  #upgradeAll,
  #blueprintBtn { min-height: 42px; padding-inline: 7px; font-size: 9px; }
}

.skill.ready {
  border-color: var(--amber-bright, #fbbf24);
  box-shadow: 0 0 6px rgba(251, 191, 36, 0.35);
}

/* 提前开波按钮（战斗中 startWave 变为提前开波） */
#startWave.early {
  background: #7c2d12;
  border-color: #f97316;
}

#startWave.early:hover:not(:disabled) { background: #9a3412; }

/* ---------- 迷宫蓝图 ---------- */

#bpCards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.bp-card {
  display: flex;
  width: 100%;
  min-height: 0;
  align-items: stretch;
  gap: 8px;
  padding: 14px 12px;
  text-align: left;
}

.bp-grid {
  display: grid;
  width: 100%;
  aspect-ratio: 8 / 5;
  grid-template-columns: repeat(24, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  background: #0b1020;
  border: 1px solid #1e293b;
  border-radius: 6px;
  padding: 4px;
  margin: 0 auto;
}

.bp-cell { min-width: 0; border-radius: 1px; background: rgba(148, 163, 184, 0.08); }
.bp-cell.bp-wall { background: #60a5fa; }
.bp-cell.bp-rock { background: #475569; }
.bp-cell.bp-mine { background: #fbbf24; }
.bp-cell.bp-spawn { background: #a78bfa; }
.bp-cell.bp-core { background: #22d3ee; }
.bp-cell.bp-hl { background: #31456b; }

/* ---------- 传说增益卡 ---------- */

.card.epic {
  border-color: #f59e0b;
  background: linear-gradient(160deg, #292012 0%, #1a2540 70%);
  box-shadow: 0 0 14px rgba(245, 158, 11, 0.25);
}

.epic-tag {
  font-size: 9px;
  color: #0f172a;
  background: #f59e0b;
  border-radius: 4px;
  padding: 1px 4px;
  vertical-align: middle;
  margin-left: 4px;
}

.buff.epic {
  border-color: #f59e0b;
  box-shadow: 0 0 5px rgba(245, 158, 11, 0.4);
}

/* 克制提示 / 伤害统计 */
.counter { color: #7dd3fc; font-size: 10px; }

/* 组件块位于响应式规则之后，手机端在这里重新收口，避免桌面值反向覆盖。 */
@media (max-width: 820px) {
  #skills {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
  }

  #skills .skill {
    min-height: 48px;
    grid-template-columns: 36px minmax(0, 1fr);
    gap: 4px;
    padding: 4px 5px 4px 3px;
  }

  .skill-icon { width: 36px; height: 36px; }
  .skill-name { font-size: 9px; }
  .skill-state { font-size: 7px; }
  #skills .tool-key { display: none; }

  #blueprintBtn { min-height: 42px; padding-inline: 8px; white-space: nowrap; }
  #bpCards {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .bp-card {
    display: flex;
    width: 100%;
    min-height: 0;
    gap: 7px;
    padding: 12px;
  }

  .bp-grid {
    width: 100%;
    aspect-ratio: 8 / 5;
    grid-template-columns: repeat(24, minmax(0, 1fr));
    gap: 0;
    padding: 0;
    background: #0c0e0d;
    border-color: #433a2e;
    border-radius: 3px;
  }

  .bp-cell { min-width: 0; width: auto; height: auto; border: 1px solid rgba(255,255,255,.015); }
}

/* iPad 横屏：地图优先，指令区改为横向控制台，格子从约 28px 放大到约 35px。 */
@media (min-width: 821px) and (max-width: 1180px) and (max-height: 900px) {
  #app {
    flex-direction: column;
    gap: 9px;
    padding: 9px;
  }

  #stage {
    width: 100%;
    min-height: 0;
    flex: 1 1 auto;
  }

  #sidebar {
    display: grid;
    width: 100%;
    height: 224px;
    min-height: 224px;
    flex: 0 0 224px;
    grid-template-columns: 228px 228px minmax(470px, 1fr);
    grid-template-rows: 44px 52px 36px 52px;
    gap: 6px 10px;
    overflow: hidden;
    padding: 10px 12px;
  }

  #sidebar > header { grid-column: 1; grid-row: 1; min-height: 0; padding-bottom: 6px; }
  #sidebar > header h1 { font-size: 14px; }
  #sidebar > header > div { gap: 4px !important; }
  #modeBadge { display: none; }
  #modeMenu,
  #resetRun { min-width: 36px; min-height: 36px; }

  #hud { grid-column: 1; grid-row: 2; }
  .stat { min-height: 50px; }
  .stat.combo { display: none; }
  .core-row { grid-column: 1; grid-row: 3; }
  #controls { grid-column: 1; grid-row: 4; }

  #skills { grid-column: 2; grid-row: 1; }
  #skills .skill { min-height: 42px; }
  #startWave { grid-column: 2; grid-row: 2; min-height: 50px; }
  #wavePreview { grid-column: 2; grid-row: 3; min-height: 34px; }
  #repair { grid-column: 2; grid-row: 4; min-height: 50px; }

  .lv-row { grid-column: 3; grid-row: 1; }
  #palette {
    grid-column: 3;
    grid-row: 2 / span 3;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 5px;
    padding: 0;
  }
  .tool {
    min-height: 75px;
    grid-template-columns: 34px minmax(0, 1fr);
    padding: 6px;
  }
  .tool-icon img { width: 34px; height: 34px; }
  .tool-name { font-size: 9px; }
  .tool-cost { font-size: 8px; }

  #sidebar > .section-title,
  #selected,
  #sidebar > .btn-row,
  #cycleMode,
  #buffs,
  #sidebar > .hint { display: none; }

  #quickPop { min-width: 220px; }
  .qp-btns button { min-width: 52px; min-height: 48px; }
}

/* WebGL 主战场：Canvas 随舞台真实缩放，2D 仅保留伤害数字与波次文字叠层。 */
html.webgl3d #game {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  cursor: grab;
  touch-action: none;
}

html.webgl3d #game.camera-dragging { cursor: grabbing; }

.camera-reset {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 5;
  min-width: 72px;
  min-height: 38px;
  padding: 7px 11px;
  border: 1px solid rgba(109, 201, 195, 0.38);
  border-radius: 9px;
  background: rgba(10, 22, 25, 0.78);
  box-shadow: inset 0 1px rgba(255,255,255,.07), 0 7px 18px rgba(0,0,0,.24);
  color: #cceae6;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.camera-reset:hover,
.camera-reset.moved { border-color: rgba(244, 186, 98, 0.72); color: #ffe1a8; }
.camera-reset:active { transform: translateY(1px) scale(.98); }
.camera-reset.hidden { display: none; }

@media (pointer: coarse) {
  .camera-reset { min-width: 82px; min-height: 44px; font-size: 12px; }
}

#fxCanvas {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

html.webgl3d #stage::before,
html.webgl3d #stage::after { z-index: 2; }

html.webgl3d .build-confirm,
html.webgl3d .tutorial-coach,
html.webgl3d #quickPop { z-index: 6; }

/* ============================================================
   移动战斗框架：地图始终完整居中，常用操作停靠在画面四周。
   ============================================================ */

@media (max-width: 820px) {
  html,
  body { width: 100%; height: 100%; overflow: hidden; }

  #app {
    position: relative;
    display: block;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    padding: 6px;
  }

  #stage {
    position: absolute;
    inset: 6px;
    z-index: auto;
    width: auto;
    height: auto;
    aspect-ratio: auto;
  }

  #sidebar {
    position: absolute;
    inset: 6px;
    z-index: 8;
    display: grid;
    width: auto;
    height: auto;
    min-height: 0;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    grid-template-rows: 46px 52px 28px 44px minmax(0, 1fr) 50px 48px 46px 132px;
    gap: 6px;
    padding: 0;
    overflow: visible;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    pointer-events: none;
  }

  #sidebar > * { min-width: 0; pointer-events: auto; }

  #sidebar > header {
    grid-column: 1 / -1;
    grid-row: 1;
    min-height: 0;
    padding: 5px 7px;
    border: 0;
    border-radius: 11px;
    background: rgba(24, 22, 18, 0.9);
    box-shadow: 0 0 0 1px rgba(245, 210, 139, 0.18), 0 8px 22px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }

  #sidebar > header h1 { font-size: 14px; }
  #sidebar .best,
  #modeBadge { display: none; }
  #modeMenu,
  #resetRun { min-width: 42px; min-height: 36px; }

  #hud { grid-column: 1 / -1; grid-row: 2; gap: 5px; }
  #hud .stat { min-height: 52px; background: rgba(39, 35, 29, 0.9); backdrop-filter: blur(8px); }
  #hud .stat.combo { display: none; }

  .core-row {
    grid-column: 1 / -1;
    grid-row: 3;
    min-height: 28px;
    padding: 4px 8px;
    border-radius: 8px;
    background: rgba(19, 18, 15, 0.86);
  }

  #controls {
    grid-column: 1 / -1;
    grid-row: 4;
    min-height: 44px;
    padding: 0;
  }

  #controls button,
  #speeds button { min-height: 44px; background: rgba(42, 38, 32, 0.92); }

  #skills { grid-column: 1 / -1; grid-row: 6; }
  #skills .skill { min-height: 50px; background: rgba(43, 38, 32, 0.92); }

  #startWave { grid-column: 1 / 5; grid-row: 7; min-height: 48px; }
  #repair { grid-column: 5 / -1; grid-row: 7; min-height: 48px; }
  #repair:disabled { display: block; }

  .lv-row {
    grid-column: 1 / -1;
    grid-row: 8;
    min-height: 46px;
    padding: 3px 5px;
    border-radius: 10px;
    background: rgba(24, 22, 18, 0.9);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }

  .lv-row .section-title { display: none; }

  #palette {
    grid-column: 1 / -1;
    grid-row: 9;
    display: grid;
    width: 100%;
    height: 132px;
    grid-auto-columns: minmax(96px, 26vw);
    grid-auto-flow: column;
    grid-template-columns: none;
    grid-template-rows: repeat(2, 63px);
    gap: 6px;
    padding: 1px 2px 3px;
    overflow-x: auto;
    overflow-y: hidden;
    border-radius: 11px;
    background: rgba(19, 18, 15, 0.9);
    box-shadow: 0 0 0 1px rgba(245, 210, 139, 0.12);
    scrollbar-width: none;
    backdrop-filter: blur(9px);
    -webkit-backdrop-filter: blur(9px);
  }

  #palette::-webkit-scrollbar { display: none; }
  #palette .tool { min-height: 63px; padding: 5px; border-radius: 9px; }

  #wavePreview,
  #sidebar > .section-title,
  #selected,
  #sidebar > .btn-row,
  #cycleMode,
  #buffs,
  #sidebar > .hint { display: none !important; }

  .camera-reset { top: 202px; right: 10px; z-index: 10; }
  .build-confirm { bottom: 190px; z-index: 12 !important; }
  #quickPop { bottom: 190px !important; z-index: 12 !important; }
  .tutorial-coach { top: 182px; z-index: 12 !important; }
}

@media (max-width: 820px) and (max-height: 700px) and (orientation: portrait) {
  #sidebar {
    grid-template-rows: 42px 46px 24px 40px minmax(0, 1fr) 44px 44px 40px 72px;
    gap: 4px;
  }
  #sidebar > header { padding-block: 3px; }
  #hud .stat { min-height: 46px; padding-block: 5px; }
  #controls,
  #controls button,
  #speeds button { min-height: 40px; }
  #skills,
  #skills .skill { min-height: 44px; }
  #startWave,
  #repair { min-height: 44px; }
  .lv-row { min-height: 40px; }
  #palette {
    height: 72px;
    grid-auto-columns: minmax(90px, 25vw);
    grid-template-rows: 68px;
  }
  #palette .tool { min-height: 68px; }
  .camera-reset { top: 164px; }
  .build-confirm,
  #quickPop { bottom: 116px !important; }
  .tutorial-coach { top: 154px; }
}

@media (max-width: 820px) and (orientation: landscape) and (max-height: 500px) {
  #app { display: block; padding: 5px; }
  #stage { inset: 5px; width: auto; height: auto; }

  #sidebar {
    inset: 5px;
    display: grid;
    grid-template-columns: minmax(178px, 0.78fr) minmax(250px, 1.8fr) minmax(190px, 0.86fr);
    grid-template-rows: 46px minmax(0, 1fr) 42px 70px;
    gap: 5px 7px;
  }

  #sidebar > header {
    grid-column: 1;
    grid-row: 1;
    padding: 4px 6px;
  }
  #sidebar > header h1 { font-size: 12px; }
  #modeMenu,
  #resetRun { min-width: 36px; min-height: 36px; }

  #hud { grid-column: 2; grid-row: 1; }
  #hud .stat { min-height: 46px; padding: 5px 7px; }
  #hud .stat > span:last-child { font-size: 15px; }

  .core-row { grid-column: 1; grid-row: 2; align-self: start; }

  #controls { grid-column: 3; grid-row: 1; min-height: 46px; }
  #controls button,
  #speeds button { min-height: 46px; padding-inline: 3px; font-size: 9px; }
  #autoBtn { font-size: 0 !important; }
  #autoBtn::after { content: '🔁'; font-size: 14px; }

  #skills { grid-column: 1; grid-row: 4; }
  #skills .skill {
    min-height: 70px;
    grid-template-columns: 1fr;
    place-items: center;
    padding: 3px;
  }
  #skills .skill-copy { display: none; }

  .lv-row { grid-column: 2; grid-row: 3; min-height: 42px; }
  #palette {
    grid-column: 2;
    grid-row: 4;
    height: 70px;
    grid-auto-columns: 70px;
    grid-template-rows: 66px;
    gap: 4px;
  }
  #palette .tool {
    min-height: 66px;
    grid-template-columns: 30px minmax(0, 1fr);
    padding: 4px;
  }
  #palette .tool-icon,
  #palette .tool-icon img { width: 31px; height: 31px; }
  #palette .tool-name { font-size: 8px; }
  #palette .tool-cost { font-size: 7px; }

  #repair { grid-column: 3; grid-row: 3; min-height: 42px; }
  #startWave { grid-column: 3; grid-row: 4; min-height: 70px; }

  .camera-reset { top: 56px; right: 8px; }
  .build-confirm { bottom: 79px; }
  #quickPop { right: 198px; bottom: 79px !important; left: auto !important; width: min(350px, 48vw); }
  .tutorial-coach { top: 55px; }
}

@media (min-width: 821px) and (max-width: 1180px) and (max-height: 900px) {
  #app {
    position: relative;
    display: block;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    padding: 7px;
  }

  #stage {
    position: absolute;
    inset: 7px;
    z-index: auto;
    width: auto;
    height: auto;
    min-height: 0;
    aspect-ratio: auto;
  }

  #sidebar {
    position: absolute;
    inset: 7px;
    z-index: 8;
    display: grid;
    width: auto;
    height: auto;
    min-height: 0;
    grid-template-columns: minmax(210px, 0.78fr) minmax(440px, 1.8fr) minmax(240px, 0.9fr);
    grid-template-rows: 50px minmax(0, 1fr) 46px 80px;
    gap: 7px 10px;
    padding: 0;
    overflow: visible;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    pointer-events: none;
  }

  #sidebar > * { min-width: 0; pointer-events: auto; }
  #sidebar > header {
    grid-column: 1;
    grid-row: 1;
    min-height: 50px;
    padding: 5px 8px;
    border: 0;
    border-radius: 11px;
    background: rgba(24, 22, 18, 0.9);
    box-shadow: 0 0 0 1px rgba(245, 210, 139, 0.18);
    backdrop-filter: blur(9px);
    -webkit-backdrop-filter: blur(9px);
  }
  #sidebar > header h1 { font-size: 13px; }
  #sidebar .best,
  #modeBadge { display: none; }

  #hud { grid-column: 2; grid-row: 1; }
  #hud .stat { min-height: 50px; background: rgba(39, 35, 29, 0.9); }
  #hud .stat.combo { display: none; }

  .core-row {
    grid-column: 1;
    grid-row: 2;
    align-self: start;
    min-height: 30px;
    padding: 5px 8px;
    border-radius: 8px;
    background: rgba(19, 18, 15, 0.86);
  }

  #controls { grid-column: 3; grid-row: 1; }
  #controls button,
  #speeds button { min-height: 50px; padding-inline: 4px; background: rgba(42, 38, 32, 0.92); }

  #skills { grid-column: 1; grid-row: 4; }
  #skills .skill { min-height: 80px; background: rgba(43, 38, 32, 0.92); }

  .lv-row {
    grid-column: 2;
    grid-row: 3;
    min-height: 46px;
    padding: 3px 6px;
    border-radius: 10px;
    background: rgba(24, 22, 18, 0.9);
  }
  .lv-row .section-title { display: none; }

  #palette {
    grid-column: 2;
    grid-row: 4;
    display: grid;
    width: 100%;
    height: 80px;
    grid-auto-columns: 76px;
    grid-auto-flow: column;
    grid-template-columns: none;
    grid-template-rows: 76px;
    gap: 5px;
    padding: 2px;
    overflow-x: auto;
    overflow-y: hidden;
    border-radius: 11px;
    background: rgba(19, 18, 15, 0.9);
    scrollbar-width: none;
    backdrop-filter: blur(9px);
    -webkit-backdrop-filter: blur(9px);
  }
  #palette::-webkit-scrollbar { display: none; }
  #palette .tool {
    min-height: 76px;
    grid-template-columns: 32px minmax(0, 1fr);
    padding: 5px;
  }
  #palette .tool-icon,
  #palette .tool-icon img { width: 34px; height: 34px; }

  #startWave { grid-column: 3; grid-row: 3; min-height: 46px; }
  #repair { grid-column: 3; grid-row: 4; min-height: 80px; }

  #wavePreview,
  #sidebar > .section-title,
  #selected,
  #sidebar > .btn-row,
  #cycleMode,
  #buffs,
  #sidebar > .hint { display: none !important; }

  .camera-reset { top: 62px; right: 10px; z-index: 10; }
  .build-confirm { bottom: 92px; z-index: 12 !important; }
  #quickPop { right: 250px; bottom: 92px !important; left: auto !important; z-index: 12 !important; }
  .tutorial-coach { top: 62px; z-index: 12 !important; }
}

/* 大屏手机横屏（iPhone Plus/Max 等 CSS 宽度会超过 820px）。 */
@media (min-width: 821px) and (max-width: 932px) and (orientation: landscape) and (max-height: 500px) {
  #app { padding: 5px; }
  #stage,
  #sidebar { inset: 5px; }

  #sidebar {
    grid-template-columns: 180px minmax(260px, 1fr) 190px;
    grid-template-rows: 46px minmax(0, 1fr) 42px 70px;
    gap: 5px 7px;
  }

  #sidebar > header { min-height: 46px; padding: 4px 6px; }
  #sidebar > header h1 { font-size: 11px; }
  #modeMenu,
  #resetRun { min-width: 34px; min-height: 34px; }

  #hud .stat { min-height: 46px; padding: 5px 7px; }
  #hud .stat > span:last-child { font-size: 15px; }
  #controls button,
  #speeds button { min-height: 46px; padding-inline: 2px; font-size: 9px; }
  #autoBtn { font-size: 0 !important; }
  #autoBtn::after { content: '🔁'; font-size: 14px; }

  #skills .skill {
    min-height: 70px;
    grid-template-columns: 1fr;
    place-items: center;
    padding: 3px;
  }
  #skills .skill-copy { display: none; }

  .lv-row { min-height: 42px; }
  #palette {
    height: 70px;
    grid-auto-columns: 70px;
    grid-template-rows: 66px;
    gap: 4px;
  }
  #palette .tool {
    min-height: 66px;
    grid-template-columns: 30px minmax(0, 1fr);
    padding: 4px;
  }
  #palette .tool-icon,
  #palette .tool-icon img { width: 31px; height: 31px; }
  #palette .tool-name { font-size: 8px; }
  #palette .tool-cost { font-size: 7px; }

  #startWave { min-height: 42px; }
  #repair { min-height: 70px; }
  .camera-reset { top: 56px; }
  .build-confirm { bottom: 79px; }
  #quickPop { right: 198px; bottom: 79px !important; }
  .tutorial-coach { top: 55px; }
}
