




:root {
  --td-bg: #10141c;
  --td-panel: #1b2230;
  --td-panel-2: #232c3e;
  --td-border: #33405a;
  --td-text: #e6ebf4;
  --td-text-dim: #8b98b0;
  --td-accent: #57c26f;
  --td-danger: #e5645f;
  --td-gold: #e8c14f;
  --td-radius: 8px;
  --td-font: system-ui, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  
  --td-action-h: 64px;
  

  --td-top-h: 56px;
}


*,
*::before,
*::after { box-sizing: border-box; }



[hidden] { display: none !important; }


* {
  
  scrollbar-width: thin;
  scrollbar-color: var(--td-border) transparent;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--td-border);
  border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover {
  background: #46567a;
}
::-webkit-scrollbar-thumb:active {
  background: var(--td-accent);
}
::-webkit-scrollbar-corner {
  background: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--td-bg);
  color: var(--td-text);
  font-family: var(--td-font);
  overflow: hidden;
  
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}


.app {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-end; 
  justify-content: center;
  
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           calc(env(safe-area-inset-bottom) + var(--td-action-h) * var(--td-zoom, 1))
           env(safe-area-inset-left);
}

.app__canvas {
  display: block;
  background: #000;
  
}




body.layout-landscape .app {
  align-items: center;
  justify-content: center;
  padding-top: calc(env(safe-area-inset-top) + (var(--td-top-h, 56px) + 8px) * var(--td-zoom, 1));
}

.app__ui {
  
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.app__ui > * { pointer-events: auto; }


.debug-panel {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 90;
  padding: 8px 10px;
  background: rgba(10, 14, 20, 0.82);
  border: 1px solid var(--td-border);
  border-radius: 6px;
  font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace;
  color: #9fe3b1;
  white-space: pre;
  pointer-events: none;
}


.hud-top {
  position: absolute;
  top: 2px;
  


  min-height: max(var(--td-top-h, 56px), calc(var(--hud-strip-h, 80px) - 2px));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: clamp(3px, 0.8vw, 8px);
  flex-wrap: nowrap; 
  max-width: calc(100vw - 10px); 
  align-items: center;
  padding: 0.4em 0.55em; 
  
  font-size: clamp(11px, 1.8vw, 14px);
  background: rgba(16, 20, 28, 0.82);
  border: 1px solid var(--td-border);
  border-radius: var(--td-radius);
  z-index: 20;
}

.hud-item { white-space: nowrap; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.hud-gold { color: var(--td-gold); }
.hud-lives { color: var(--td-danger); }
.hud-btn { min-width: 36px; }


.hud-top > * {
  height: 2.15em;
  line-height: 2.15em;
  min-height: 0; 
  box-sizing: border-box;
}



.hud-top .hud-btn {
  flex: 0 1 auto;
  min-width: 0;
  min-height: 0; 
  padding: 0 0.55em;
  line-height: 2.15em; 
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud-btn.is-active,
.hud-build-btn.is-active { outline: 2px solid var(--td-accent); }


.hud-action {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: calc(var(--td-action-h) + env(safe-area-inset-bottom)); 
  padding: 6px 12px;
  padding-bottom: calc(6px + env(safe-area-inset-bottom));
  background: rgba(16, 20, 28, 0.92);
  
  box-shadow: inset 0 1px 0 var(--td-border);
  z-index: 20;
}



.hud-top .hud-skill-icon { padding: 0 0.35em; }
.hud-skill-icon.is-miss { opacity: 0.5; }


.hud-top .hud-settings { padding: 0 0.35em; }




.hud-build {
  display: flex;
  gap: clamp(4px, 1.2vw, 8px);
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto; 
  container-type: inline-size; 
}
.hud-build::before,
.hud-build::after { content: ''; flex: 1 0 0; }

.hud-build-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center; 
  gap: 2px;
  flex: 0 0 auto; 
  padding: 4px 3px; 
  overflow: hidden;
}




.hud-build .hud-build-btn { font-size: clamp(8px, 1.8cqi, 12px); }
.hud-build-btn.is-miss { opacity: 0.5; }


.hud-build-name { font-size: 1em; min-width: max-content; }
.hud-build-cost { font-size: 0.92em; color: var(--td-gold); min-width: max-content; }
.hud-build-name, .hud-build-cost {
  white-space: nowrap;
}


.hud-tower-card {
  position: absolute;
  right: 12px;
  bottom: calc(var(--td-action-h) * var(--td-zoom, 1) + 10px);
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  background: rgba(16, 20, 28, 0.88);
  border: 1px solid var(--td-border);
  border-radius: var(--td-radius);
  z-index: 20;
  font-size: 14px;
  max-width: 240px;
}

.hud-tower-dps, .hud-tower-def { color: var(--td-text-dim); font-size: 12px; }
.hud-tower-row { display: flex; gap: 6px; flex-wrap: wrap; }
.hud-tower-row .td-btn { font-size: 12px; min-height: 32px; padding: 4px 8px; }

.hud-tower-specs { display: flex; flex-direction: column; gap: 4px; }
.hud-spec-label { font-size: 12px; color: var(--td-text-dim); }
.hud-spec-btn { font-size: 12px; min-height: 32px; padding: 6px 8px; text-align: left; line-height: 1.35; }
.hud-spec-btn small { color: var(--td-text-dim); }


.tut-mask {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 50;
}

.tut-ring {
  position: absolute;
  border: 2px solid var(--td-accent);
  border-radius: 8px;
  box-shadow: 0 0 0 9999px rgba(8, 10, 16, 0.45);
  pointer-events: none;
  z-index: 51;
}

.tut-bubble {
  position: absolute;
  max-width: 240px;
  padding: 10px 12px;
  background: rgba(22, 27, 38, 0.96);
  border: 1px solid var(--td-accent);
  border-radius: var(--td-radius);
  z-index: 52;
  font-size: 13px;
  line-height: 1.5;
}

.tut-bubble p { margin: 0 0 8px; }
.tut-btns { display: flex; gap: 6px; justify-content: flex-end; }
.tut-btns .td-btn { min-height: 32px; padding: 4px 10px; font-size: 12px; }
.tut-skip { color: var(--td-text-dim); }
.is-tut { position: relative; z-index: 53; }


.hud-result {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
  justify-content: center;
  background: rgba(8, 10, 16, 0.72);
  z-index: 40;
}

.hud-result-title { font-size: 40px; margin: 0; letter-spacing: 2px; }
.hud-result-title.is-win { color: var(--td-accent); }
.hud-result-title.is-lose { color: var(--td-danger); }
.hud-result-sub { margin: 0; color: var(--td-text-dim); font-size: 16px; }


.td-btn {
  min-width: 44px;
  min-height: 44px;
  padding: 8px 14px;
  background: var(--td-panel-2);
  color: var(--td-text);
  border: 1px solid var(--td-border);
  border-radius: 6px;
  font: inherit;
  cursor: pointer;
}
.td-btn:hover { background: #2c3950; }
.td-btn:disabled { opacity: 0.45; cursor: default; }


.shell {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 30%, rgba(28, 36, 54, 0.92) 0%, rgba(16, 20, 28, 0.96) 70%);
  overflow: auto;
}
.shell[hidden] { display: none; }
.shell--game { background: rgba(10, 12, 18, 0.55); }
.shell-card {
  width: min(560px, 92%);
  max-height: 92%;
  overflow: auto;
  padding: 22px 26px;
  background: var(--td-panel);
  border: 1px solid var(--td-border);
  border-radius: var(--td-radius);
  text-align: center;
}



.shell--game .shell-card {
  width: min(460px, 92%, max(280px, calc(var(--canvas-w, 100vw) - 16px)));
}


.shell-points {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: -6px 0 12px;
}
.shell-points-label {
  color: var(--td-gold);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}
.shell-donate-btn {
  min-height: 0;
  padding: 2px 12px;
  font-size: 13px;
  border-radius: 999px;
  color: var(--td-gold);
}
.shell-donate-btn:hover { border-color: var(--td-gold); }
.donate-overlay {
  position: fixed;
  inset: 0;
  z-index: 80; 
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 11, 16, 0.72);
  backdrop-filter: blur(2px);
}
.donate-overlay[hidden] { display: none; }
.donate-card {
  width: min(480px, 92%);
  max-height: 92%;
  overflow: auto;
  padding: 20px 26px;
  background: var(--td-panel);
  border: 1px solid var(--td-border);
  border-radius: var(--td-radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  text-align: center;
}
.donate-head { display: flex; align-items: center; justify-content: center; gap: 12px; }
.donate-head h2 { margin: 0; font-size: 20px; letter-spacing: 2px; color: var(--td-gold); }
.donate-body { margin-top: 12px; }
.donate-qr {
  display: block;
  margin: 0 auto 12px;
  width: min(260px, 64vw);
  padding: 6px;
  background: #fff; 
  border: 1px solid var(--td-border);
  border-radius: 8px;
}
.donate-qr svg { display: block; width: 100%; height: auto; }
.donate-qr[hidden] { display: none; }
.donate-addr {
  margin: 0 0 10px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--td-text);
  overflow-wrap: anywhere;
  word-break: break-all;
  user-select: all;
  cursor: text;
}
.donate-note { margin: 0; font-size: 13px; line-height: 1.6; color: var(--td-text-dim); }
.donate-gate-note { margin: 0 0 10px; font-size: 13px; line-height: 1.6; color: var(--td-danger); }
.donate-claim {
  margin-top: 16px;
  width: 100%;
  font-weight: 700;
  letter-spacing: 1px;
  border-radius: 999px;
  color: var(--td-bg);
  background: var(--td-gold);
  border-color: var(--td-gold);
  font-variant-numeric: tabular-nums;
}
.donate-claim:hover:not(:disabled) { filter: brightness(1.08); background: var(--td-gold); }
.donate-claim:disabled { cursor: not-allowed; }
.shell-title { margin: 0 0 14px; font-size: 26px; letter-spacing: 3px; color: var(--td-accent); }
.shell-subtitle { margin: 14px 0 6px; font-size: 14px; color: var(--td-text-dim); text-align: left; }
.shell-body { display: flex; flex-direction: column; gap: 8px; }
.shell-body--form { text-align: left; }
.shell-hint { color: var(--td-text-dim); font-size: 13px; margin: 4px 0; }
.shell-btn { width: 100%; }
.shell-btn--primary { border-color: var(--td-accent); color: var(--td-accent); }
.shell-btn--danger { border-color: var(--td-danger); color: var(--td-danger); }
.shell-btn--ghost { opacity: 0.75; }
.shell-btn--disabled { opacity: 0.45; }
.shell-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.shell-level {
  position: relative;
  min-height: 72px;
  padding: 8px 6px;
  background: var(--td-panel-2);
  border: 1px solid var(--td-border);
  border-radius: 6px;
  color: var(--td-text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: center;
  justify-content: center;
}
.shell-level:hover { border-color: var(--td-accent); }
.shell-level.is-locked { opacity: 0.45; cursor: default; }
.shell-level.is-locked:hover { border-color: var(--td-border); }
.shell-level-no { font-size: 12px; color: var(--td-text-dim); }
.shell-level-name { font-size: 13px; }
.shell-level-stars { color: var(--td-gold); font-size: 12px; letter-spacing: 1px; }
.shell-level-lock { position: absolute; top: 4px; right: 6px; font-size: 12px; }
.shell-level--sandbox { grid-column: span 4; flex-direction: row; gap: 10px; }
.shell-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.shell-row-label { color: var(--td-text); font-size: 14px; }
.td-input { background: var(--td-bg); color: var(--td-text); border: 1px solid var(--td-border); border-radius: 4px; min-height: 32px; }
.shell-keys { margin-top: 8px; }
.shell-keys-row { display: flex; justify-content: space-between; font-size: 13px; color: var(--td-text-dim); border-bottom: 1px dashed var(--td-border); padding: 3px 0; }
.shell-keys-row b { color: var(--td-text); font-weight: 600; }
.shell-result-title { margin: 0; font-size: 30px; }
.shell-result-title.is-win { color: var(--td-accent); }
.shell-result-title.is-lose { color: var(--td-danger); }
.shell-result-stars { font-size: 30px; color: var(--td-gold); letter-spacing: 6px; margin: 4px 0; }
.shell-badges {
  display: flex; flex-wrap: wrap; gap: 6px; justify-content: center;
}

.shell-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px 3px 4px; border: 1px solid var(--td-gold);
  border-radius: 999px; color: var(--td-gold); font-size: 13px;
}
.shell-badge.is-locked {
  border-color: var(--td-border); color: var(--td-text-dim); opacity: 0.72;
}
.shell-badge canvas { display: block; flex: none; }
.shell-badge-name { white-space: nowrap; }

.shell-badge--row {
  padding: 0; border: 0; border-radius: 0; background: none; color: inherit; opacity: 1;
}
.shell-stats { text-align: left; }
.shell-stats-row { display: flex; justify-content: space-between; font-size: 13px; color: var(--td-text-dim); border-bottom: 1px dashed var(--td-border); padding: 3px 2px; }
.shell-stats-row b { color: var(--td-text); font-weight: 500; }

.shell-tabs { display: flex; gap: 6px; margin-bottom: 10px; justify-content: center; }
.shell-tab { min-height: 36px; padding: 6px 12px; font-size: 13px; }
.shell-tab.is-active { border-color: var(--td-accent); color: var(--td-accent); }
.shell-codex { text-align: left; max-height: 420px; overflow: auto; }



.shell-card--codex { display: flex; flex-direction: column; overflow: hidden; }
.shell-card--codex > * { flex: none; }
.shell-card--codex .shell-codex { flex: 1 1 auto; min-height: 0; max-height: none; }
.shell-codex-row { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; color: var(--td-text-dim); border-bottom: 1px dashed var(--td-border); padding: 6px 2px; }
.shell-codex-row b { color: var(--td-text); font-weight: 500; white-space: nowrap; }
.shell-codex-row.is-got b { color: var(--td-gold); }
.shell-codex-badge { align-items: center; justify-content: flex-start; gap: 10px; } 
.shell-codex-unit { align-items: center; justify-content: flex-start; gap: 12px; } 
.shell-codex-icon {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: center;
  width: 56px; height: 56px; border: 1px solid var(--td-border); border-radius: 10px;
  background: radial-gradient(130% 110% at 50% 8%, rgba(126, 148, 200, 0.16), rgba(8, 10, 18, 0.55) 70%);
}
.shell-codex-icon canvas { display: block; }
.shell-codex-col { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.shell-codex-col b { white-space: normal; }


.app__ui { zoom: var(--td-zoom, 1); }


.td-btn:focus-visible,
.shell-level:focus-visible,
.td-input:focus-visible,
.hud-build-btn:focus-visible {
  outline: 2px solid var(--td-accent);
  outline-offset: 1px;
}


html {
  touch-action: manipulation; 
}
body {
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}


body.layout-compact {
  

  --td-top-h: 48px;
}
body.layout-compact .hud-top {
  left: 4px;
  right: 4px;
  
  top: env(safe-area-inset-top);
  
  min-height: max(var(--td-top-h, 56px), var(--hud-strip-h, 80px));
  transform: none;
  flex-wrap: nowrap; 
  justify-content: center;
  max-width: none;
}

body.layout-compact .hud-btn,
body.layout-compact .hud-pause,
body.layout-compact .hud-settings { min-width: 0; padding: 0 0.5em; }



body.layout-compact:not(.layout-portrait) .hud-top {
  top: 1px;
  min-height: max(var(--td-top-h, 56px), calc(var(--hud-strip-h, 40px) - 2px));
  max-width: calc(100vw - 10px); 
  width: fit-content; 
  margin-inline: auto;
  padding: 0.3em 0.4em;
}

body.layout-compact .hud-action {
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
}
body.layout-compact .hud-build {
  gap: 6px;
  flex: 1 1 auto;
  min-width: 0;
}
body.layout-compact .hud-build .hud-build-btn { min-height: 44px; }
body.layout-compact .hud-tower-card {
  left: 6px;
  right: 6px;
  bottom: calc(var(--td-action-h) * var(--td-zoom, 1) + 8px);
  transform: none;
  max-width: none;
}
body.layout-compact .hud-tower-row .td-btn,
body.layout-compact .hud-spec-btn { min-height: 44px; font-size: 13px; }



