:root {
  --bg: #0d1f29;
  --bg-deep: #09151c;
  --panel: rgba(243, 237, 223, 0.96);
  --panel-border: #d5c3a7;
  --text: #17313b;
  --accent: #d56f2b;
  --accent-dark: #a85118;
  --secondary: #315867;
  --secondary-dark: #234450;
  --selected: #2e8b57;
  --stat-bg: #fffaf0;
  --stat-border: #dfcfb5;
  --canvas-frame: #294757;
  --status-bg: #fffaf0;
  --app-height: 100dvh;
}

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

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: "Trebuchet MS", Verdana, sans-serif;
  background:
    radial-gradient(circle at top, rgba(255, 210, 120, 0.16), transparent 28%),
    linear-gradient(180deg, #173746 0%, var(--bg) 52%, var(--bg-deep) 100%);
  color: var(--text);
  overscroll-behavior: none;
}

body {
  touch-action: manipulation;
}

.app {
  height: var(--app-height);
  min-height: var(--app-height);
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 6px;
}

.game-area {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 6px;
}

.hud-bar {
  display: grid;
  gap: 6px;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px 0;
}

.brand h1 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.1;
  color: #f8efe2;
}

.eyebrow {
  margin: 0;
  font-size: 0.58rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(248, 239, 226, 0.72);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.compact-stats {
  padding: 0 0 2px;
}

.stat {
  min-width: 0;
  background: linear-gradient(180deg, #fffdf8 0%, var(--stat-bg) 100%);
  border: 2px solid var(--stat-border);
  border-radius: 12px;
  padding: 7px 6px;
  text-align: center;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.active-stat {
  border-color: #8bbd7d;
}

.label {
  display: block;
  font-size: 0.62rem;
  color: #6d665d;
  margin-bottom: 2px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat strong {
  display: block;
  font-size: 0.94rem;
  line-height: 1.1;
}

.board-wrap {
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

canvas {
  display: block;
  width: min(100%, calc((var(--app-height) - 220px) * 1.6667));
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 960 / 576;
  height: auto;
  background: #799c52;
  border: 3px solid var(--canvas-frame);
  border-radius: 14px;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.22);
  touch-action: none;
  user-select: none;
}

.panel {
  min-height: 0;
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: 16px;
  padding: 8px;
  display: grid;
  gap: 8px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(6px);
}

.action-row {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) repeat(4, minmax(0, 0.8fr));
  gap: 6px;
}

#toggleBuildMenuButton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

button {
  border: none;
  border-radius: 12px;
  min-height: 40px;
  padding: 9px 10px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  color: #fff9ef;
  background: var(--accent);
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease;
}

button:active:not(:disabled) {
  transform: scale(0.985);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.secondary {
  background: var(--secondary);
}

.icon-button {
  min-width: 0;
}

.tower-drawer[hidden] {
  display: none;
}

.tower-picker {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.tower-button {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 4px;
  min-height: 68px;
  padding: 10px;
  text-align: left;
  background: linear-gradient(180deg, #5b7158 0%, #4b5f48 100%);
}

.tower-button strong {
  font-size: 0.78rem;
}

.tower-button span,
.tower-button small {
  font-size: 0.63rem;
  line-height: 1.2;
}

.tower-button.selected {
  outline: 3px solid var(--selected);
  background: linear-gradient(180deg, #759261 0%, #5d754d 100%);
}

#splashTowerButton {
  background: linear-gradient(180deg, #4f6389 0%, #3c4d71 100%);
}

.status {
  margin: 0;
  padding: 8px 10px;
  background: var(--status-bg);
  border: 2px solid var(--stat-border);
  border-radius: 12px;
  font-size: 0.76rem;
  line-height: 1.3;
}

@media (min-width: 981px) {
  .app {
    grid-template-columns: minmax(0, 1fr) 340px;
    grid-template-rows: 1fr;
    gap: 18px;
    padding: 16px;
  }

  .game-area {
    order: 1;
    gap: 12px;
  }

  .panel {
    order: 2;
    padding: 16px;
    gap: 14px;
    border-width: 3px;
    border-radius: 20px;
  }

  .brand {
    padding: 4px 2px 0;
  }

  .brand h1 {
    font-size: 1.8rem;
    color: #f8efe2;
  }

  .eyebrow {
    font-size: 0.72rem;
  }

  .stats {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 10px;
  }

  .stat {
    border-radius: 14px;
    padding: 10px 8px;
  }

  .label {
    font-size: 0.72rem;
    margin-bottom: 4px;
  }

  .stat strong {
    font-size: 1.12rem;
  }

  canvas {
    width: min(100%, 1040px);
    max-height: calc(var(--app-height) - 120px);
    border-width: 4px;
    border-radius: 22px;
  }

  .action-row {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  #toggleBuildMenuButton {
    display: none;
  }

  button {
    min-height: 50px;
    padding: 12px 14px;
    font-size: 0.95rem;
  }

  .tower-drawer[hidden] {
    display: block;
  }

  .tower-picker {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .tower-button {
    min-height: 84px;
    padding: 14px;
  }

  .tower-button strong {
    font-size: 1rem;
  }

  .tower-button span,
  .tower-button small {
    font-size: 0.8rem;
  }

  .status {
    padding: 12px 14px;
    font-size: 0.92rem;
  }
}
