:root {
  --bg: #05080f;
  --panel: rgba(9, 15, 29, 0.78);
  --panel-strong: rgba(12, 20, 38, 0.92);
  --border: rgba(148, 163, 184, 0.16);
  --border-strong: rgba(148, 163, 184, 0.28);
  --text: #e6edf7;
  --muted: #8ba0bd;
  --accent: #38bdf8;
  --accent-deep: #0284c7;
  --gold: #fbbf24;
  --life: #f87171;
  --enemy: #c084fc;
  --score: #34d399;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: radial-gradient(circle at 50% 30%, #0b1428 0%, #05080f 58%, #020409 100%);
}

body {
  font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

button,
select {
  font-family: inherit;
  color: inherit;
}

#app,
#app canvas {
  position: fixed;
  inset: 0;
  display: block;
}

#vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  background: radial-gradient(circle at 50% 42%, transparent 42%, rgba(1, 4, 10, 0.58) 100%);
}

#hud {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.hud-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
}

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

.stat {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  backdrop-filter: blur(14px);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.25);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
}

.dot.gold {
  background: var(--gold);
  box-shadow: 0 0 10px rgba(251, 191, 36, 0.8);
}

.dot.life {
  background: var(--life);
  box-shadow: 0 0 10px rgba(248, 113, 113, 0.8);
}

.dot.wave {
  background: var(--accent);
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.8);
}

.dot.enemy {
  background: var(--enemy);
  box-shadow: 0 0 10px rgba(192, 132, 252, 0.8);
}

.dot.score {
  background: var(--score);
  box-shadow: 0 0 10px rgba(52, 211, 153, 0.8);
}

.label {
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.stat strong {
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  min-width: 20px;
}

.seed-area {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  pointer-events: auto;
}

button,
select {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  padding: 9px 13px;
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
  backdrop-filter: blur(14px);
}

button:hover,
select:hover {
  border-color: var(--border-strong);
  background: rgba(18, 30, 55, 0.9);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: default;
  opacity: 0.55;
}

select {
  appearance: none;
  padding-right: 28px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.ghost {
  background: var(--panel);
}

#btn-copy b {
  color: var(--accent);
  letter-spacing: 0.06em;
}

#wave-panel {
  position: fixed;
  top: 82px;
  right: 18px;
  width: 288px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  pointer-events: auto;
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 10px;
}

#wave-title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.speed {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.speed button {
  border: 0;
  border-radius: 0;
  padding: 4px 8px;
  font-size: 10px;
  background: transparent;
  color: var(--muted);
  backdrop-filter: none;
}

.speed button.active {
  background: rgba(56, 189, 248, 0.16);
  color: var(--accent);
}

.speed .pause-toggle {
  border-right: 1px solid var(--border);
  color: var(--text);
  font-weight: 600;
}

.speed .pause-toggle.active {
  background: rgba(56, 189, 248, 0.16);
  color: var(--accent);
}

.preview {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.09);
  font-size: 10.5px;
  color: #bacbe2;
  white-space: nowrap;
}

.chip i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.chip.total {
  background: transparent;
  color: var(--muted);
  padding-left: 2px;
}

.primary {
  border: 0;
  background: linear-gradient(135deg, #38bdf8, #0ea5e9 55%, #0284c7);
  color: #03111f;
  font-weight: 700;
  box-shadow: 0 10px 26px rgba(14, 165, 233, 0.28);
}

.primary:hover {
  background: linear-gradient(135deg, #5bcbfa, #22b3f2 55%, #0693d8);
  color: #02101c;
}

#btn-wave {
  width: 100%;
  padding: 11px 14px;
  font-size: 13px;
  border-radius: 11px;
}

.tip {
  margin-top: 10px;
  font-size: 10.5px;
  line-height: 1.55;
  color: var(--muted);
}

#tower-bar {
  position: fixed;
  left: 18px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 4px;
  pointer-events: auto;
}

.tower-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  width: 158px;
  height: 40px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  backdrop-filter: blur(16px);
  text-align: left;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease, opacity 0.16s ease;
}

.tower-card:hover {
  transform: translateX(2px);
  border-color: var(--border-strong);
}

.tower-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.5), 0 12px 34px rgba(14, 165, 233, 0.22);
}

.tower-card.unaffordable {
  opacity: 0.52;
}

.tower-card.unaffordable .tower-cost {
  color: var(--life);
}

.tower-key {
  flex: none;
  font-size: 9px;
  color: rgba(139, 160, 189, 0.72);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 4px;
  padding: 0 4px;
  line-height: 14px;
}

.tower-dot {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 3px;
  background: var(--c);
  box-shadow: 0 0 12px var(--c);
  transform: rotate(45deg);
}

.tower-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 600;
}

.tower-cost {
  margin-left: auto;
  font-size: 12px;
  font-weight: 700;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

.tower-tooltip {
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 7px;
  width: 228px;
  padding: 12px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--panel-strong);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.42);
  text-align: left;
  opacity: 0;
  visibility: hidden;
  transform: translate(-4px, -50%);
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
  pointer-events: none;
}

.tower-card:hover .tower-tooltip,
.tower-card:focus-visible .tower-tooltip {
  opacity: 1;
  visibility: visible;
  transform: translate(0, -50%);
}

.tt-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.tt-desc {
  font-size: 10.5px;
  line-height: 1.55;
  color: var(--muted);
}

.tt-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 10px;
}

.tt-grid span {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  padding-bottom: 2px;
  border-bottom: 1px dashed rgba(148, 163, 184, 0.14);
  font-size: 10.5px;
  color: var(--muted);
}

.tt-grid i {
  font-style: normal;
}

.tt-grid b {
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.tt-title b {
  font-size: 11px;
  font-weight: 600;
}

.tt-tags {
  font-size: 10px;
  line-height: 1.5;
  color: var(--accent);
}

.tt-tags .fire {
  color: #fb923c;
}

.tt-tags .ice {
  color: #67e8f9;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 130px;
  z-index: 8;
  transform: translate(-50%, 8px);
  padding: 9px 16px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--panel-strong);
  font-size: 12px;
  color: #dbe7f6;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  backdrop-filter: blur(14px);
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

#site-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  column-gap: 7px;
  row-gap: 2px;
  padding: 6px 12px;
  font-size: 10px;
  color: rgba(220, 232, 247, 0.9);
  letter-spacing: 0.03em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.75);
  pointer-events: auto;
}

#site-footer a {
  color: var(--muted);
  text-decoration: none;
  border-bottom: 1px dotted rgba(148, 163, 184, 0.35);
}

#site-footer a:hover {
  color: var(--accent);
  border-bottom-color: rgba(56, 189, 248, 0.65);
}

#site-footer .footer-sep {
  opacity: 0.35;
}

#overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(2, 5, 12, 0.62);
  backdrop-filter: blur(7px);
  transition: opacity 0.28s ease;
}

#overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.overlay-card {
  width: min(460px, 100%);
  padding: 28px;
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(16, 27, 49, 0.97), rgba(8, 13, 25, 0.98));
  box-shadow: 0 40px 90px rgba(0, 0, 0, 0.5);
  text-align: center;
}

.eyebrow {
  margin: 0 0 8px;
  font-size: 10px;
  letter-spacing: 0.34em;
  color: var(--accent);
}

.overlay-card h1 {
  margin: 0 0 10px;
  font-size: 30px;
  letter-spacing: 0.04em;
}

.overlay-desc {
  margin: 0 0 18px;
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--muted);
}

.overlay-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 20px;
}

.overlay-stats span {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 11px;
  color: var(--muted);
}

.overlay-stats b {
  color: var(--text);
  font-size: 13px;
}

.overlay-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.overlay-actions button {
  padding: 11px 18px;
  font-size: 12.5px;
}

.seed-line {
  margin: 18px 0 0;
  font-size: 10.5px;
  color: rgba(139, 160, 189, 0.65);
  letter-spacing: 0.08em;
}

.seed-line b {
  color: var(--muted);
}

#help-wrap {
  position: fixed;
  right: 18px;
  bottom: 44px;
  z-index: 9;
  display: flex;
  align-items: center;
  pointer-events: auto;
}

#help-button {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--panel-strong);
  color: var(--muted);
  font-size: 20px;
  font-weight: 600;
  line-height: 1;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.32);
}

#help-button:hover {
  color: var(--accent);
  border-color: rgba(56, 189, 248, 0.55);
}

.help-tooltip {
  position: absolute;
  right: 54px;
  top: 50%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-strong);
  font-size: 11px;
  color: var(--text);
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transform: translate(4px, -50%);
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
  pointer-events: none;
}

#help-wrap:hover .help-tooltip,
#help-button:focus-visible + .help-tooltip {
  opacity: 1;
  visibility: visible;
  transform: translate(0, -50%);
}

#minimap {
  position: fixed;
  right: 18px;
  bottom: 76px;
  z-index: 6;
  width: 200px;
  height: 200px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: rgba(5, 10, 18, 0.88);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.35);
  cursor: crosshair;
  pointer-events: auto;
}

#minimap.hidden {
  display: none;
}

#help-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(2, 5, 12, 0.64);
  backdrop-filter: blur(8px);
  transition: opacity 0.22s ease;
}

#help-modal.hidden {
  opacity: 0;
  pointer-events: none;
}

.help-card {
  width: min(940px, 100%);
  max-height: 88vh;
  overflow: auto;
  padding: 26px;
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(16, 27, 49, 0.98), rgba(8, 13, 25, 0.99));
  box-shadow: 0 40px 90px rgba(0, 0, 0, 0.55);
  text-align: left;
}

#help-readme[hidden] {
  display: none !important;
}

.help-markdown {
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.65;
}

.help-markdown > :first-child {
  margin-top: 0;
}

.help-markdown h1 {
  margin: 0 0 12px;
  color: var(--text);
  font-size: 23px;
  line-height: 1.25;
}

.help-markdown h2 {
  margin: 20px 0 8px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 16px;
  line-height: 1.35;
}

.help-markdown h3 {
  margin: 15px 0 6px;
  color: var(--accent);
  font-size: 13.5px;
}

.help-markdown p {
  margin: 9px 0;
}

.help-markdown ul,
.help-markdown ol {
  margin: 7px 0;
  padding-left: 20px;
}

.help-markdown li {
  margin: 3px 0;
}

.help-markdown a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dotted rgba(56, 189, 248, 0.45);
}

.help-markdown a:hover {
  border-bottom-color: var(--accent);
}

.help-markdown code {
  padding: 1px 4px;
  border-radius: 4px;
  background: rgba(56, 189, 248, 0.1);
  color: var(--accent);
  font-size: 0.92em;
}

.help-markdown pre.help-code {
  margin: 10px 0;
  padding: 10px 12px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: rgba(2, 6, 14, 0.55);
}

.help-markdown pre.help-code code {
  padding: 0;
  background: transparent;
  color: var(--text);
  white-space: pre;
}

.help-markdown blockquote {
  margin: 10px 0;
  padding: 7px 12px;
  border-left: 2px solid var(--accent);
  background: rgba(56, 189, 248, 0.06);
  color: var(--muted);
}

.help-markdown hr {
  margin: 18px 0;
  border: 0;
  border-top: 1px solid var(--border);
}

.help-markdown .help-table {
  margin: 9px 0 14px;
}

.help-table {
  width: 100%;
  border-collapse: collapse;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.55;
  table-layout: auto;
}

.help-table th,
.help-table td {
  padding: 5px 6px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.14);
  text-align: left;
  vertical-align: top;
}

.help-table th {
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.help-table td:first-child {
  color: var(--text);
  white-space: nowrap;
}

#help-close {
  padding: 10px 20px;
  font-size: 12px;
}

#file-warning {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 30%, #0b1428 0%, #05080f 65%);
}

html.file-protocol #file-warning {
  display: flex;
}

html.file-protocol #app,
html.file-protocol #vignette,
html.file-protocol #hud,
html.file-protocol #toast,
html.file-protocol #overlay,
html.file-protocol #help-modal,
html.file-protocol #minimap,
html.file-protocol #site-footer {
  display: none !important;
}

.warning-card {
  width: min(560px, 100%);
  padding: 30px;
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  background: var(--panel-strong);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
}

.warning-card h1 {
  margin: 0 0 12px;
  font-size: 28px;
}

.warning-card p {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.warning-card ol {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 2;
}

.warning-card code {
  padding: 2px 6px;
  border-radius: 5px;
  background: rgba(56, 189, 248, 0.1);
  color: var(--accent);
}

#toast {
  bottom: 50px;
}

#tower-panel {
  position: fixed;
  left: 50%;
  bottom: 44px;
  z-index: 7;
  width: 392px;
  max-width: calc(100vw - 24px);
  padding: 12px;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  background: var(--panel-strong);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(18px);
  transform: translateX(-50%);
  transition: opacity 0.16s ease, transform 0.16s ease;
  pointer-events: auto;
}

#tower-panel.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
}

.tp-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tp-title {
  font-size: 14px;
  font-weight: 700;
}

.tp-level {
  font-size: 10px;
  color: var(--accent);
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-radius: 5px;
  padding: 1px 5px;
}

.tp-close {
  margin-left: auto;
  padding: 3px 7px;
  font-size: 10px;
  color: var(--muted);
}

.tp-hp-track {
  height: 6px;
  margin-top: 9px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.16);
  overflow: hidden;
}

.tp-hp-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #22c55e, #4ade80);
  transition: width 0.18s ease;
}

.tp-hp-label {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-size: 9.5px;
  color: var(--muted);
}

.tp-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 12px;
  margin-top: 9px;
}

.tp-stats span {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 2px;
  border-bottom: 1px dashed rgba(148, 163, 184, 0.12);
  font-size: 10px;
  color: var(--muted);
}

.tp-stats i {
  font-style: normal;
}

.tp-stats b {
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.tp-section-title {
  margin: 9px 0 5px;
  font-size: 9px;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.tp-upgrades {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 6px;
}

.tp-upgrade {
  min-width: 0;
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: rgba(148, 163, 184, 0.05);
  text-align: left;
  font-size: 10px;
  line-height: 1.4;
}

.tp-upgrade:hover:not(:disabled) {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.08);
}

.tp-upgrade:disabled {
  opacity: 0.42;
}

.tp-upgrade strong {
  display: block;
  font-size: 11px;
  color: var(--text);
}

.tp-upgrade small {
  display: block;
  color: var(--muted);
  font-size: 9px;
}

.tp-upgrade .tp-cost {
  display: block;
  margin-top: 2px;
  color: var(--gold);
  font-size: 10.5px;
  font-weight: 700;
}

.tp-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 9px;
}

.tp-sell {
  padding: 5px 9px;
  font-size: 10px;
  color: var(--life);
  border-color: rgba(248, 113, 113, 0.25);
  background: rgba(248, 113, 113, 0.06);
}

.tp-note {
  font-size: 10px;
  color: var(--muted);
}


@media (max-width: 900px) {
  .hud-top {
    padding: 12px;
  }

  .stat {
    min-height: 34px;
    padding: 6px 10px;
  }

  .stat .label {
    display: none;
  }

  #wave-panel {
    top: 72px;
    right: 12px;
    width: 232px;
  }

  #tower-bar {
    left: 12px;
  }

  .tower-card {
    width: 140px;
  }

  .tower-tooltip {
    width: 208px;
  }

  #minimap {
    width: 168px;
    height: 168px;
    right: 12px;
    bottom: 72px;
  }
}

@media (max-width: 760px) {
  .seed-area select,
  .seed-area .ghost {
    padding: 7px 9px;
    font-size: 11px;
  }

  #btn-copy b {
    max-width: 74px;
    display: inline-block;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: bottom;
  }

  #wave-panel {
    width: 208px;
    padding: 11px;
  }

  .speed button {
    padding: 4px 6px;
  }

  #tower-bar {
    left: 8px;
    gap: 6px;
  }

  .tower-card {
    width: 118px;
    height: 38px;
    padding: 5px 8px;
  }

  .tower-name {
    font-size: 10.5px;
  }

  .tower-cost {
    font-size: 11px;
  }

  .tower-key {
    display: none;
  }

  .tower-dot {
    width: 8px;
    height: 8px;
  }

  .tower-tooltip {
    width: 190px;
    left: calc(100% + 8px);
  }

  #minimap {
    width: 140px;
    height: 140px;
    right: 10px;
    bottom: 66px;
  }


#help-wrap {
    right: 10px;
    bottom: 44px;
  }

  #help-button {
    width: 38px;
    height: 38px;
    font-size: 18px;
  }

  .help-tooltip {
    right: 46px;
  }

  .help-card {
    padding: 18px;
  }

  #toast {
    bottom: 50px;
  }

  #site-footer {
    column-gap: 5px;
    padding: 5px 8px;
    font-size: 9px;
  }
}

@media (max-height: 680px) {
  #tower-bar {
    gap: 3px;
  }

  .tower-card {
    height: 30px;
    padding: 4px 8px;
  }

  .tower-name {
    font-size: 10px;
  }

  .tower-cost {
    font-size: 10.5px;
  }
}

@media (max-height: 560px) {
  #tower-bar {
    gap: 2px;
  }

  .tower-card {
    height: 26px;
    padding: 3px 7px;
  }

  .tower-key {
    display: none;
  }

  .tower-name {
    font-size: 9.5px;
  }

  .tower-cost {
    font-size: 9.5px;
  }

  .tower-dot {
    width: 7px;
    height: 7px;
  }
}

/* ── Home screen ───────────────────────────────────────────── */
body.home-mode #hud,
body.home-mode #vignette {
  display: none;
}

#home-screen {
  position: fixed;
  inset: 0;
  z-index: 3;
  overflow: auto;
  padding: 54px 28px 70px;
  background:
    radial-gradient(circle at 12% 18%, rgba(56, 189, 248, 0.12), transparent 30%),
    radial-gradient(circle at 88% 74%, rgba(168, 85, 247, 0.13), transparent 34%),
    linear-gradient(135deg, #05080f 0%, #08111f 48%, #05080f 100%);
}

#home-screen::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(148, 163, 184, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 163, 184, 0.035) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: radial-gradient(circle at 50% 40%, black, transparent 78%);
}

#home-screen.hidden {
  display: none;
}

.home-shell {
  position: relative;
  z-index: 1;
  width: min(1180px, 100%);
  min-height: calc(100vh - 124px);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.home-brand {
  margin-bottom: 26px;
}

.home-brand .eyebrow {
  margin-bottom: 10px;
  color: #67e8f9;
}

.home-brand h1 {
  margin: 0;
  font-size: clamp(42px, 7vw, 78px);
  letter-spacing: -0.045em;
  line-height: 0.95;
  text-shadow: 0 0 42px rgba(56, 189, 248, 0.18);
}

.home-subtitle {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.16em;
}

.home-main {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(330px, 0.8fr);
  gap: 34px;
  align-items: stretch;
}

.home-copy {
  padding: 20px 0 12px;
}

.home-kicker {
  margin: 0 0 12px;
  color: #67e8f9;
  font-size: 11px;
  letter-spacing: 0.18em;
}

.home-copy h2 {
  margin: 0 0 18px;
  font-size: clamp(26px, 3.2vw, 42px);
  line-height: 1.18;
  letter-spacing: -0.03em;
}

.home-copy > p:not(.home-kicker) {
  max-width: 600px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.85;
}

.home-features {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 28px;
}

.home-features span {
  padding: 7px 10px;
  border: 1px solid rgba(103, 232, 249, 0.16);
  border-radius: 999px;
  background: rgba(8, 47, 73, 0.22);
  color: #bae6fd;
  font-size: 11px;
}

.home-setup {
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  padding: 22px;
  background: linear-gradient(180deg, rgba(13, 23, 43, 0.92), rgba(7, 12, 23, 0.97));
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.home-field {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
}

.home-field label,
.home-seed-row span {
  color: var(--muted);
  font-size: 10.5px;
  letter-spacing: 0.12em;
}

.home-field select {
  width: 100%;
  height: 42px;
  font-size: 13px;
}

.home-seed-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.home-seed-row > div {
  min-width: 0;
}

.home-seed-row b {
  display: block;
  margin-top: 4px;
  color: var(--text);
  font-size: 17px;
  letter-spacing: 0.12em;
  overflow: hidden;
  text-overflow: ellipsis;
}

.home-seed-row button {
  flex: none;
  font-size: 10.5px;
}

.home-hint {
  min-height: 34px;
  margin: 11px 0 13px;
  color: #fbbf24;
  font-size: 10.5px;
  line-height: 1.55;
}

.home-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.home-actions button {
  display: flex;
  min-height: 61px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 13px;
  font-weight: 700;
}

.home-actions button small {
  color: rgba(139, 160, 189, 0.8);
  font-size: 9.5px;
  font-weight: 400;
}

.home-actions .primary {
  background: linear-gradient(135deg, #0ea5e9, #2563eb);
  border-color: rgba(125, 211, 252, 0.65);
  box-shadow: 0 10px 30px rgba(14, 165, 233, 0.22);
}

.home-actions .primary:hover {
  background: linear-gradient(135deg, #38bdf8, #3b82f6);
}

.home-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  margin-top: 28px;
  color: rgba(139, 160, 189, 0.68);
  font-size: 10.5px;
}

/* ── Pause / faction overlays ─────────────────────────────── */
#pause-menu,
#faction-modal {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(2, 5, 12, 0.58);
  backdrop-filter: blur(7px);
}

#faction-modal {
  z-index: 26;
}

#pause-menu.hidden,
#faction-modal.hidden {
  opacity: 0;
  pointer-events: none;
}

.pause-card,
.faction-card {
  width: min(460px, 100%);
  padding: 28px;
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(16, 27, 49, 0.98), rgba(8, 13, 25, 0.99));
  box-shadow: 0 40px 90px rgba(0, 0, 0, 0.55);
  text-align: center;
}

.faction-card {
  width: min(620px, 100%);
}

.pause-card h1,
.faction-card h1 {
  margin: 0 0 9px;
  font-size: 28px;
}

.pause-meta,
.faction-desc {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
}

.pause-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
}

.pause-actions button {
  min-width: 92px;
  padding: 10px 15px;
}

.pause-hint {
  margin: 16px 0 0;
  color: rgba(139, 160, 189, 0.55);
  font-size: 10px;
}

.faction-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.faction-option {
  display: flex;
  min-height: 132px;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 5px;
  padding: 18px;
  text-align: left;
}

.faction-option strong {
  font-size: 17px;
}

.faction-option span {
  font-size: 11px;
  color: var(--muted);
}

.faction-option small {
  margin-top: 7px;
  font-size: 9.5px;
  color: rgba(139, 160, 189, 0.7);
}

.faction-option.light {
  border-color: rgba(251, 191, 36, 0.38);
  background: linear-gradient(145deg, rgba(251, 191, 36, 0.11), rgba(15, 23, 42, 0.6));
}

.faction-option.dark {
  border-color: rgba(168, 85, 247, 0.42);
  background: linear-gradient(145deg, rgba(168, 85, 247, 0.13), rgba(15, 23, 42, 0.6));
}

.faction-option:hover {
  border-color: rgba(255, 255, 255, 0.42);
  transform: translateY(-2px);
}

html.file-protocol #home-screen {
  display: none;
}

@media (max-width: 800px) {
  #home-screen {
    padding: 34px 16px 58px;
  }

  .home-main {
    grid-template-columns: 1fr;
    gap: 18px;
  }

  .home-copy {
    padding-top: 0;
  }

  .home-brand h1 {
    font-size: clamp(38px, 12vw, 62px);
  }

  .home-foot {
    margin-top: 20px;
  }
}

@media (max-width: 520px) {
  .home-actions,
  .faction-actions {
    grid-template-columns: 1fr;
  }

  .home-setup {
    padding: 16px;
  }
}

/* ── Home v2: compact centered layout ─────────────────────── */
#home-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 20px 52px;
}

#home-screen .home-shell {
  width: min(440px, 100%);
  min-height: 0;
  margin: 0 auto;
  display: block;
  text-align: center;
}

#home-screen .home-brand {
  margin: 0 0 20px;
}

#home-screen .home-brand .eyebrow {
  margin-bottom: 8px;
  font-size: 9px;
  color: #67e8f9;
}

#home-screen .home-brand h1 {
  font-size: clamp(32px, 4.5vw, 44px);
  line-height: 1.04;
  letter-spacing: -0.05em;
  text-shadow: 0 0 34px rgba(56, 189, 248, 0.16);
}

#home-screen .home-subtitle {
  margin: 11px 0 0;
  font-size: 12px;
  letter-spacing: 0.1em;
}

#home-screen .home-setup {
  padding: 18px;
  text-align: left;
}

.home-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

#home-screen .home-field {
  display: grid;
  gap: 6px;
  margin: 0;
}

#home-screen .home-field span,
#home-screen .home-field label,
#home-screen .home-seed-row span {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.1em;
}

#home-screen .home-field select {
  width: 100%;
  height: 38px;
  padding: 7px 9px;
  font-size: 12px;
}

#home-screen .home-hint {
  min-height: 0;
  margin: 12px 0;
  color: #fbbf24;
  font-size: 10px;
  line-height: 1.5;
  text-align: center;
}

#home-screen .home-actions {
  gap: 8px;
}

#home-screen .home-actions button {
  min-height: 52px;
  font-size: 12px;
}

#home-screen .home-actions button small {
  font-size: 9px;
}

.home-help {
  width: 100%;
  margin-top: 8px;
  padding: 9px 12px;
  font-size: 11px;
  color: var(--muted);
}

#home-screen .home-foot {
  margin: 14px 0 0;
  justify-content: center;
  color: rgba(139, 160, 189, 0.56);
  font-size: 9.5px;
}

.pause-seed-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 16px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(5, 10, 18, 0.38);
  text-align: left;
}

.pause-seed-row span {
  flex: none;
  color: var(--muted);
  font-size: 10px;
}

.pause-seed-row b {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  letter-spacing: 0.1em;
}

.pause-seed-row button {
  flex: none;
  padding: 5px 8px;
  font-size: 9.5px;
}

@media (max-width: 520px) {
  #home-screen {
    padding: 22px 14px 46px;
  }

  .home-fields {
    grid-template-columns: 1fr;
  }

  #home-screen .home-actions {
    grid-template-columns: 1fr;
  }
}
