:root,
html[data-theme="dark"] {
  --bg: #15181e;
  --bg-2: #1a1f27;
  --line: rgba(232, 237, 244, 0.14);
  --text: #e8edf4;
  --muted: #9aa6b4;
  --cyan: #5ee0d0;
  --magenta: #ff8aa0;
  --green: #7ee0a2;
  --gold: #f0c14b;
  --red: #ff6b6b;
  --purple: #b8a9ff;
  --orange: #ff9a6b;
  --glass: rgba(26, 31, 39, 0.88);
  --glass-2: rgba(35, 42, 53, 0.92);
  --surface: #232a35;
  --surface-2: #1c222c;
  --overlay: rgba(8, 10, 14, 0.72);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --glow-a: rgba(94, 224, 208, 0.16);
  --glow-b: rgba(255, 154, 107, 0.12);
  --glow-c: rgba(184, 169, 255, 0.1);
  --body-from: #12151a;
  --body-mid: #15181e;
  --body-to: #1a1f27;
  --press: #2e3644;
  --buy-bg: #2a2618;
  --buy-border: #6b5a22;
  --hud-h: 56px;
  --tool-h: 118px;
  --tool-w: 92px;
  --safe-t: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
  --safe-b: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
  --safe-l: var(--safe-area-inset-left, env(safe-area-inset-left, 0px));
  --safe-r: var(--safe-area-inset-right, env(safe-area-inset-right, 0px));
  --radius: 18px;
  --ti-h: 118px;
  font-synthesis: none;
  color-scheme: dark;
}

html[data-theme="light"] {
  --bg: #eef1f6;
  --bg-2: #f7f9fc;
  --line: rgba(28, 36, 48, 0.14);
  --text: #1c2430;
  --muted: #5d6b7a;
  --cyan: #0f9d94;
  --magenta: #d9486f;
  --green: #2f9e5c;
  --gold: #c4841d;
  --red: #d64545;
  --purple: #6b5ce0;
  --orange: #e86b3a;
  --glass: rgba(255, 255, 255, 0.86);
  --glass-2: rgba(247, 249, 252, 0.94);
  --surface: #ffffff;
  --surface-2: #e8eef5;
  --overlay: rgba(226, 232, 240, 0.72);
  --shadow: 0 8px 24px rgba(28, 36, 48, 0.1);
  --glow-a: rgba(15, 157, 148, 0.18);
  --glow-b: rgba(232, 107, 60, 0.12);
  --glow-c: rgba(107, 92, 224, 0.1);
  --body-from: #e8eef5;
  --body-mid: #eef1f6;
  --body-to: #f7f9fc;
  --press: #d9e2ec;
  --buy-bg: #fff6de;
  --buy-border: #e0c36a;
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

body {
  min-height: 100dvh;
  background:
    radial-gradient(900px 560px at 0% -10%, var(--glow-a), transparent 58%),
    radial-gradient(820px 520px at 110% 0%, var(--glow-b), transparent 55%),
    radial-gradient(640px 420px at 50% 110%, var(--glow-c), transparent 50%),
    linear-gradient(180deg, var(--body-from) 0%, var(--body-mid) 42%, var(--body-to) 100%);
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: 0;
  background: none;
  touch-action: manipulation;
}

.hidden {
  display: none !important;
}

#app {
  position: relative;
  display: grid;
  grid-template-rows: calc(var(--hud-h) + var(--safe-t)) minmax(0, 1fr) calc(var(--tool-h) + var(--safe-b));
  height: var(--app-h, 100dvh);
  width: 100%;
  max-width: 100vw;
  overflow: hidden;
}

.glass {
  background: linear-gradient(180deg, var(--glass), var(--glass-2));
  border: 1px solid var(--line);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  box-shadow: var(--shadow);
}

#hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  padding: calc(8px + var(--safe-t)) calc(12px + var(--safe-r)) 8px calc(12px + var(--safe-l));
  border-left: 0;
  border-right: 0;
  border-top: 0;
  z-index: 3;
}

.hud-cluster {
  display: flex;
  gap: 10px;
  align-items: center;
}

.stat {
  min-width: 72px;
  padding: 6px 10px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.stat-k {
  display: block;
  font-size: 9px;
  letter-spacing: 0.18em;
  color: var(--muted);
}

.stat-v {
  display: block;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 16px;
  line-height: 1.2;
}

.stat-v.gold { color: var(--gold); }
.stat-v.hp { color: var(--green); }
.stat-v.shake {
  animation: gold-shake 0.35s ease;
}

@keyframes gold-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

.speed-opts {
  display: flex;
  gap: 4px;
}

.speed-opts button {
  min-width: 36px;
  height: 40px;
  padding: 0 8px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.speed-opts button.active {
  border-color: var(--cyan);
  color: var(--cyan);
  background: color-mix(in srgb, var(--cyan) 16%, transparent);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.icon-btn svg {
  width: 18px;
  height: 18px;
  display: block;
}

.auto-label {
  display: none;
}

.icon-btn.active {
  border-color: var(--cyan);
  color: var(--cyan);
  background: color-mix(in srgb, var(--cyan) 16%, transparent);
}

#auto-count {
  font-size: 15px;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.icon-btn:active {
  transform: scale(0.96);
  background: var(--press);
}

#stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

#boss-bar {
  position: absolute;
  left: 50%;
  top: 10px;
  transform: translateX(-50%);
  width: min(520px, calc(100% - 24px));
  pointer-events: none;
}

.boss-label {
  font-size: 10px;
  letter-spacing: 0.22em;
  color: var(--magenta);
  margin-bottom: 4px;
  text-align: center;
}

.boss-track {
  height: 8px;
  border-radius: 99px;
  background: color-mix(in srgb, var(--magenta) 18%, transparent);
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--magenta) 40%, transparent);
}

#boss-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--magenta), var(--gold));
  transform-origin: left center;
}

#tower-info {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: calc(var(--tool-h) + var(--safe-b) + 10px);
  z-index: 4;
  padding: 12px 12px 10px;
  border-radius: 14px;
  pointer-events: none;
  max-width: 520px;
  margin: 0 auto;
  background: var(--bg-2);
  border: 1px solid var(--line);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
  font-family: ui-rounded, "Avenir Next", "Segoe UI", system-ui, sans-serif;
}

.ti-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.ti-icon {
  width: 36px;
  height: 36px;
  object-fit: contain;
  flex-shrink: 0;
}

.ti-titles {
  min-width: 0;
  flex: 1;
}

.ti-head strong {
  display: block;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0;
}

#ti-lvl {
  display: block;
  margin-top: 1px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--muted);
}

#ti-close {
  height: 28px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0;
  pointer-events: auto;
  flex-shrink: 0;
}

#ti-close:active {
  transform: scale(0.94);
  background: var(--press);
}

#ti-desc {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.ti-match {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.ti-match p {
  margin: 0;
  font-size: 11px;
  line-height: 1.35;
  color: var(--text);
}

.ti-match .ok,
.ti-match .bad {
  display: block;
  font-size: 12px;
  letter-spacing: 0;
  font-weight: 700;
  margin-bottom: 1px;
}

.ti-match .ok { color: var(--green); }
.ti-match .bad { color: var(--red); }

#ti-up {
  margin: 0;
  font-size: 11px;
  line-height: 1.4;
  color: var(--gold);
}

#app:has(#tower-info:not(.hidden)) #toast {
  bottom: calc(var(--ti-h) + 18px);
}

#toast {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  pointer-events: none;
  box-shadow: var(--shadow);
  z-index: 4;
}

#toolbar {
  display: flex;
  gap: 10px;
  align-items: stretch;
  min-width: 0;
  padding: 8px calc(10px + var(--safe-r)) calc(10px + var(--safe-b)) calc(10px + var(--safe-l));
  border-left: 0;
  border-right: 0;
  border-bottom: 0;
  z-index: 3;
}

.tower-tray {
  display: flex;
  gap: 8px;
  flex: 1;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}

.tower-tray::-webkit-scrollbar { display: none; }

.tower-card {
  position: relative;
  flex: 1 0 72px;
  min-width: 72px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 6px 4px 8px;
  color: var(--text);
  overflow: hidden;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.18);
  font-family: ui-rounded, "Avenir Next", "Segoe UI", system-ui, sans-serif;
  -webkit-touch-callout: none;
}

.card-copy {
  display: contents;
}

.tower-card .glyph {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 0;
  object-fit: contain;
  background: transparent;
  flex-shrink: 0;
}

.tower-card .nm {
  font-size: 12px;
  letter-spacing: 0;
  font-weight: 700;
  line-height: 1.15;
}

.tower-card .cs {
  font-size: 12px;
  font-weight: 700;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.tower-card .vs {
  font-size: 10px;
  letter-spacing: 0;
  color: var(--muted);
  line-height: 1.15;
  text-align: center;
  max-width: 100%;
}

.tower-card.holding::after,
.tower-card.peek::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: currentColor;
}

.tower-card.holding::after {
  transform-origin: left center;
  animation: hold-fill 0.45s linear forwards;
}

@keyframes hold-fill {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

.tower-card.active {
  border-color: currentColor;
  background: color-mix(in srgb, currentColor 16%, var(--surface));
  box-shadow: inset 0 -3px 0 currentColor;
}

.tower-card.peek:not(.active) {
  border-color: currentColor;
}

.tower-tray.converting .tower-card:not([data-type='block']) {
  border-style: dashed;
}

.tower-card.disabled {
  opacity: 0.38;
}

.tool-side {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 6px;
  width: 132px;
  flex-shrink: 0;
}

.tool-btn {
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
}

.tool-btn.go {
  grid-column: 1 / -1;
  background: color-mix(in srgb, var(--green) 22%, transparent);
  border-color: color-mix(in srgb, var(--green) 55%, transparent);
  color: var(--green);
}

.tool-btn.up {
  color: var(--gold);
  border-color: color-mix(in srgb, var(--gold) 45%, transparent);
}

.tool-btn.active,
.tool-btn:disabled {
  filter: saturate(0.2);
}

.tool-btn:disabled {
  opacity: 0.35;
}

.tool-btn.active:not(:disabled) {
  filter: none;
  background: color-mix(in srgb, var(--magenta) 16%, transparent);
}

.overlay {
  position: fixed;
  top: var(--vv-top, 0px);
  right: 0;
  left: 0;
  height: var(--app-h, 100dvh);
  z-index: 20;
  display: grid;
  place-items: center;
  padding: calc(18px + var(--safe-t)) 16px calc(18px + var(--safe-b));
  background: rgba(6, 8, 12, 0.74);
  overflow: auto;
}

html[data-theme="light"] .overlay {
  background: rgba(232, 236, 242, 0.72);
}

#screen-upgrades { z-index: 24; }
#screen-about { z-index: 26; }
#screen-wipe { z-index: 28; }
#screen-ad { z-index: 30; }
#screen-exit { z-index: 40; }

.faq { margin: 4px 0 12px; }
.faq dt {
  margin-top: 10px;
  font-size: 14px;
  font-weight: 700;
}
.faq dd {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}
a.ghost {
  display: block;
  text-align: center;
  text-decoration: none;
}

.panel {
  width: min(440px, 100%);
  border-radius: 18px;
  padding: 18px 18px 16px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.42);
  font-family: ui-rounded, "Avenir Next", "Segoe UI", system-ui, sans-serif;
}

.panel.wide {
  width: min(620px, 100%);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.logo {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  flex: 0 0 auto;
  display: block;
}

.panel.hero h1 {
  font-size: clamp(34px, 8vw, 48px);
  line-height: 1;
  margin: 0;
  letter-spacing: -0.03em;
  font-weight: 750;
  color: var(--text);
  background: none;
}

.brand .eyebrow { margin: 0 0 4px; }

.eyebrow {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0;
  color: var(--orange);
}

.eyebrow.warn { color: var(--red); }

h2 {
  margin: 0 0 8px;
  font-size: 26px;
  font-weight: 750;
  letter-spacing: -0.02em;
}

.lede {
  color: var(--text);
  opacity: 0.78;
  line-height: 1.45;
  font-size: 15px;
  margin: 0 0 16px;
}

.ad-note {
  margin-top: -6px;
}

.ad-inline {
  width: 100%;
  margin: 0 0 12px;
}

.setting {
  display: grid;
  gap: 8px;
  margin: 0 0 14px;
}

.setting > span {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0;
  color: var(--text);
}

.setting-opts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.setting-opts button {
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 14px;
  font-weight: 650;
  letter-spacing: 0;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.16);
}

.setting-opts button.active {
  border-color: var(--cyan);
  background: color-mix(in srgb, var(--cyan) 16%, transparent);
  color: var(--cyan);
}

.ad-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.theme-opt {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.theme-opt.active {
  border-color: var(--cyan);
  background: color-mix(in srgb, var(--cyan) 16%, transparent);
  color: var(--cyan);
}

.menu-stats {
  display: flex;
  justify-content: center;
  gap: 36px;
  margin-bottom: 20px;
  text-align: center;
}

.mode-row {
  display: flex;
  gap: 6px;
}

.mode-btn {
  flex: 1 1 0;
  min-width: 0;
  padding: 8px 4px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0;
  white-space: nowrap;
}

.mode-btn.active {
  border-color: var(--cyan);
  color: var(--cyan);
  background: color-mix(in srgb, var(--cyan) 14%, transparent);
}

.contract-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 4px 0 12px;
}

.contract-list p {
  margin: 0;
  font-size: 13px;
  line-height: 1.35;
}

.contract-list p.done {
  color: var(--muted);
}

.menu-stats div {
  padding: 0;
  border: 0;
  background: none;
}

.menu-stats span {
  display: block;
  font-size: 26px;
  font-weight: 750;
  color: var(--text);
  line-height: 1.1;
}

#menu-crystals { color: var(--gold); }

.menu-stats small {
  color: var(--muted);
  letter-spacing: 0;
  font-size: 12px;
  font-weight: 600;
}

.choice-cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.choice-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: inset 3px 0 0 var(--cyan);
}

.choice-card:active {
  transform: scale(0.98);
  background: var(--press);
}

.choice-tag {
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0;
  color: var(--muted);
  padding: 0;
  border-radius: 0;
  background: none;
}

.choice-card strong {
  font-size: 16px;
  letter-spacing: -0.02em;
}

.choice-blurb {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  font-weight: 600;
}

.btn-row,
.btn-col {
  display: flex;
  gap: 10px;
}

.btn-col { flex-direction: column; }

.panel.actions {
  width: min(300px, 100%);
  padding: 14px;
}

.panel.actions .btn-col {
  gap: 10px;
}

.btn-row > .primary,
.btn-row > .ghost,
.btn-row > .danger,
.btn-row > .ad-btn {
  flex: 1 1 0;
  min-height: 48px;
}

.panel > .ghost,
.panel > .primary,
.panel > .danger,
.panel > .ad-btn,
.btn-col > .ghost,
.btn-col > .primary,
.btn-col > .danger,
.btn-col > .ad-btn {
  width: 100%;
}
.btn-row { flex-wrap: wrap; }

.primary,
.ghost,
.danger,
.ad-btn {
  border-radius: 12px;
  padding: 12px 14px;
  font-weight: 700;
  letter-spacing: 0;
  font-size: 15px;
}

.primary {
  background: #f0984a;
  color: #2b170c;
  box-shadow: inset 0 -3px 0 #c56a28;
}

.ghost {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.16);
}

.danger {
  background: color-mix(in srgb, var(--red) 14%, var(--surface));
  color: var(--red);
  box-shadow: inset 0 -3px 0 color-mix(in srgb, var(--red) 40%, transparent);
}

.ad-btn {
  background: #7d6cf2;
  border: 0;
  color: #fff;
  box-shadow: inset 0 -3px 0 #5344b8;
}

.primary:active,
.ghost:active,
.danger:active,
.ad-btn:active {
  transform: translateY(1px);
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.crystals-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
  letter-spacing: 0;
}

.crystals-chip strong {
  color: var(--gold);
  font-size: 18px;
}

.upgrade-list {
  display: grid;
  gap: 10px;
  margin: 16px 0 18px;
}

.upgrade-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  width: 100%;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  text-align: left;
  cursor: pointer;
}

.upgrade-card:active {
  transform: scale(0.99);
  background: var(--press);
}

.upgrade-card.poor .buy,
.upgrade-card.maxed {
  opacity: 0.5;
}

.upgrade-card.maxed {
  cursor: default;
}

.upgrade-card h3 {
  margin: 0;
  font-size: 15px;
}

.upgrade-card p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  grid-column: 1 / -1;
}

.upgrade-card .lvl {
  color: var(--cyan);
  font-size: 12px;
  font-weight: 700;
}

.buy {
  justify-self: end;
  align-self: start;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--buy-bg);
  border: 1px solid var(--buy-border);
  color: var(--gold);
  font-size: 11px;
  font-weight: 800;
}

.buy:disabled {
  opacity: 0.4;
}

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 18px;
}

.result-grid div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.gem {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  object-fit: cover;
  vertical-align: -3px;
}

.gem-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.result-grid strong {
  display: block;
  color: var(--text);
  font-size: 20px;
  margin-top: 0;
}

.ad-frame {
  text-align: center;
}

.ad-timer {
  width: 72px;
  height: 72px;
  margin: 4px auto 16px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-size: 28px;
  font-weight: 750;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
}

@media (max-width: 520px) {
  #hud {
    gap: 6px;
    padding-left: calc(8px + var(--safe-l));
    padding-right: calc(8px + var(--safe-r));
  }
  .hud-cluster { gap: 4px; }
  .stat { min-width: 0; padding: 4px 6px; }
  .stat-k { letter-spacing: 0.08em; }
  .stat-v { font-size: 13px; }
  .speed-opts { gap: 3px; }
  .speed-opts button {
    min-width: 28px;
    height: 32px;
    padding: 0 5px;
    font-size: 11px;
  }
  .icon-btn { width: 32px; height: 32px; }
  .icon-btn svg { width: 16px; height: 16px; }
  .tool-side { width: 112px; }
  .panel { padding: 22px 16px 16px; }
  #tower-info { left: 8px; right: 8px; bottom: calc(var(--tool-h) + var(--safe-b) + 8px); padding: 8px 10px; }
  .ti-match { grid-template-columns: 1fr; gap: 4px; }
  #ti-desc { font-size: 11px; }
}

@media (orientation: landscape) and (max-height: 640px) {
  :root,
  html[data-theme="dark"],
  html[data-theme="light"] {
    --hud-h: 52px;
    --tool-h: 0px;
    --tool-w: 208px;
    --ti-h: 0px;
  }

  #app {
    grid-template-rows: minmax(0, 1fr);
    grid-template-columns: minmax(0, 1fr) calc(var(--tool-w) + var(--safe-r));
  }

  #hud {
    position: absolute;
    top: 0;
    left: 0;
    right: calc(var(--tool-w) + var(--safe-r));
    height: calc(var(--hud-h) + var(--safe-t));
    min-width: 0;
    gap: 8px;
    padding: calc(6px + var(--safe-t)) 8px 6px calc(8px + var(--safe-l));
    overflow: hidden;
    z-index: 4;
  }

  .hud-cluster { gap: 6px; min-width: 0; }
  .hud-actions { flex-shrink: 0; }
  .stat { min-width: 0; padding: 4px 8px; border-radius: 10px; }
  .stat-k { font-size: 9px; letter-spacing: 0.08em; line-height: 1.1; }
  .stat-v { font-size: 16px; line-height: 1.15; }
  .icon-btn {
    width: 40px;
    min-width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 12px;
    font-size: 13px;
    letter-spacing: 0;
  }

  .icon-btn svg { width: 18px; height: 18px; }
  .auto-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    width: auto;
    min-width: 76px;
    padding: 0 10px 0 8px;
  }
  .auto-label {
    display: block;
    font-size: 13px;
    font-weight: 750;
    letter-spacing: 0;
    line-height: 1;
  }
  #auto-count { display: none; }

  .speed-opts { gap: 4px; }
  .speed-opts button {
    min-width: 40px;
    height: 40px;
    padding: 0 8px;
    border-radius: 12px;
    font-size: 14px;
  }

  #stage {
    grid-row: 1;
    grid-column: 1;
    display: block;
    min-width: 0;
    padding: calc(var(--hud-h) + var(--safe-t) + 2px) 2px 2px calc(2px + var(--safe-l));
  }

  #game {
    width: 100%;
    height: 100%;
  }

  #boss-bar { top: calc(var(--hud-h) + var(--safe-t) + 8px); width: min(420px, calc(100% - 16px)); }

  #tower-info {
    position: absolute;
    left: auto;
    right: calc(100% + 10px);
    top: auto;
    bottom: calc(8px + var(--safe-b));
    flex: none;
    width: min(340px, calc(100vw - var(--tool-w) - var(--safe-l) - var(--safe-r) - 28px));
    min-height: 0;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 10px 12px;
    border-radius: 14px;
    overflow: auto;
    pointer-events: auto;
    z-index: 6;
  }

  .ti-head { margin-bottom: 6px; gap: 8px; }
  .ti-icon { width: 32px; height: 32px; }
  .ti-head strong {
    font-size: 16px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #ti-lvl { font-size: 12px; letter-spacing: 0; white-space: nowrap; }
  #ti-close { height: 36px; padding: 0 12px; border-radius: 10px; font-size: 14px; flex-shrink: 0; }
  #ti-desc {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: 13px;
    margin-bottom: 6px;
  }
  #ti-up {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-top: 4px;
    font-size: 12px;
    line-height: 1.35;
    white-space: normal;
  }
  .choice-cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .choice-card { padding: 12px; border-radius: 12px; min-width: 0; min-height: 96px; }
  .choice-card strong {
    font-size: 15px;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .choice-blurb { font-size: 12px; }
  .ti-match { grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 0; }
  .ti-match p { font-size: 12px; white-space: normal; }
  .ti-match .ok,
  .ti-match .bad { font-size: 12px; }

  #toast,
  #app:has(#tower-info:not(.hidden)) #toast {
    bottom: auto;
    top: calc(var(--hud-h) + var(--safe-t) + 8px);
    font-size: 13px;
    padding: 8px 12px;
  }

  #toolbar {
    grid-row: 1;
    grid-column: 2;
    flex-direction: column;
    width: auto;
    min-height: 0;
    overflow: visible;
    gap: 6px;
    padding: 6px calc(8px + var(--safe-r)) calc(8px + var(--safe-b)) 6px;
  }

  .tower-tray {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
  }

  .tower-card {
    flex: 1 1 0;
    min-height: 0;
    max-height: none;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    width: 100%;
    min-width: 0;
    height: auto;
    border-radius: 12px;
    padding: 0 8px;
  }

  .tower-card .glyph { width: 28px; height: 28px; border: 0; border-radius: 0; background: transparent; flex-shrink: 0; }
  .tower-card .card-copy {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 1px;
    min-width: 0;
    flex: 1;
  }
  .tower-card .nm,
  .tower-card .cs,
  .tower-card .vs,
  .tool-btn,
  .primary,
  .ghost,
  .danger,
  .ad-btn,
  .icon-btn {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .tower-card .nm { font-size: 14px; letter-spacing: 0; max-width: 100%; }
  .tower-card .cs { margin-left: 0; font-size: 13px; flex-shrink: 0; }
  .tower-card .vs { display: block; font-size: 11px; text-align: left; max-width: 100%; }

  .tool-side {
    width: 100%;
    height: auto;
    flex: 0 0 auto;
    gap: 6px;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 40px 46px;
  }

  .tool-btn {
    min-width: 0;
    min-height: 0;
    border-radius: 12px;
    font-size: 14px;
    letter-spacing: 0;
    padding: 0 8px;
  }

  .tool-btn.go {
    font-size: 16px;
    background: #3ecf8e;
    color: #10241a;
    border-color: transparent;
    box-shadow: inset 0 -3px 0 #1c9a62;
    filter: none;
    opacity: 1;
  }

  .tool-btn.go:disabled {
    background: var(--surface);
    color: var(--muted);
    border-color: var(--line);
    box-shadow: none;
    filter: none;
    opacity: 1;
  }

  .overlay {
    padding: calc(12px + var(--safe-t)) calc(16px + var(--safe-r)) calc(12px + var(--safe-b)) calc(16px + var(--safe-l));
    align-items: center;
  }
  .panel {
    padding: 16px 18px 14px;
    width: min(560px, 100%);
    max-height: 100%;
    overflow: auto;
    border-radius: 18px;
  }
  .panel.actions {
    width: min(300px, 100%);
    padding: 12px;
  }
  .panel h2 { margin: 0 0 4px; }
  .panel .btn-col { gap: 8px; }
  #screen-settings .panel {
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(148px, 0.55fr);
    column-gap: 18px;
    row-gap: 6px;
    align-items: start;
    width: min(640px, 100%);
  }
  #screen-settings h2,
  #screen-settings .lede,
  #screen-settings .setting { grid-column: 1; }
  #screen-settings .lede { margin-bottom: 2px; }
  #screen-settings .setting { margin-bottom: 2px; }
  #screen-settings .btn-col {
    grid-column: 2;
    grid-row: 1 / span 5;
    align-self: end;
  }
  .panel.hero {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(168px, 0.85fr);
    column-gap: 14px;
    align-items: center;
    overflow: hidden;
  }
  .panel.hero .brand,
  .panel.hero .lede,
  .panel.hero .menu-stats { grid-column: 1; }
  .panel.hero .btn-col { grid-column: 2; grid-row: 1 / span 3; align-self: center; gap: 8px; }
  .brand { margin-bottom: 6px; gap: 10px; }
  .logo { width: 44px; height: 44px; border-radius: 12px; }
  .panel.hero h1 { font-size: 28px; }
  .lede {
    font-size: 13px;
    line-height: 1.35;
    margin-bottom: 8px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .menu-stats { margin-bottom: 0; gap: 20px; justify-content: flex-start; }
  .menu-stats div { padding: 0; }
  .menu-stats span { font-size: 22px; }
  .primary, .ghost, .danger, .ad-btn { padding: 12px 12px; font-size: 16px; min-height: 44px; }
  .mode-btn { font-size: 15px; letter-spacing: 0; padding: 10px 8px; min-height: 44px; }
  h2 { font-size: 22px; margin: 2px 0 6px; }
  .setting { margin-bottom: 8px; }
  .upgrade-list { margin: 6px 0 8px; max-height: 42dvh; overflow: auto; }
}
