:root {
  color-scheme: dark;
  --bg: #111414;
  --panel: #171c1d;
  --panel-2: #202728;
  --ink: #f3f7f4;
  --muted: #a9b7b2;
  --line: #33403d;
  --accent: #54d6a6;
  --accent-2: #5bb8ff;
  --warn: #f3b35b;
  --danger: #ef6b70;
  --path: #6f6352;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(circle at 18% 12%, rgba(84, 214, 166, 0.16), transparent 30%),
    linear-gradient(135deg, #111414 0%, #151817 42%, #1b1715 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #22292a;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  min-height: 42px;
  padding: 0 14px;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

button:hover {
  border-color: #5c746d;
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  transform: none;
}

.primary {
  background: linear-gradient(135deg, #2ed08f, #35a8ff);
  border-color: transparent;
  color: #061010;
}

.app-shell {
  margin: 0 auto;
  max-width: 1500px;
  padding: 22px;
}

.game-surface {
  background: rgba(19, 23, 23, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.topbar {
  align-items: center;
  display: flex;
  gap: 18px;
  justify-content: space-between;
  padding: 18px 20px;
}

.eyebrow {
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  margin: 0 0 4px;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.6rem, 3vw, 2.6rem);
  letter-spacing: 0;
  line-height: 1;
}

h2 {
  font-size: 0.92rem;
  letter-spacing: 0;
}

.status-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(4, minmax(94px, 1fr));
  min-width: min(620px, 58%);
}

.stat {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.stat span,
.section-head span {
  color: var(--muted);
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
}

.stat strong {
  display: block;
  font-size: 1.22rem;
  line-height: 1.25;
  margin-top: 3px;
}

.play-layout {
  display: grid;
  gap: 0;
  grid-template-columns: minmax(0, 1fr) 390px;
}

.canvas-wrap {
  background: #0e1111;
  border-top: 1px solid var(--line);
  min-height: 540px;
  padding: 14px;
  position: relative;
}

canvas {
  aspect-ratio: 48 / 31;
  background: #16201e;
  border: 1px solid #25312e;
  border-radius: 8px;
  display: block;
  height: auto;
  max-height: calc(100vh - 180px);
  max-width: 100%;
  width: 100%;
}

.mobile-actions {
  display: none;
  gap: 8px;
  margin-top: 10px;
}

.control-panel {
  background: var(--panel);
  border-left: 1px solid var(--line);
  border-top: 1px solid var(--line);
  max-height: calc(100vh - 112px);
  overflow: auto;
  padding: 14px;
}

.panel-section {
  border-bottom: 1px solid var(--line);
  padding: 0 0 14px;
  margin-bottom: 14px;
}

.panel-section:last-child {
  border-bottom: 0;
  margin-bottom: 0;
}

.compact-controls {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr 1fr;
}

.section-head {
  align-items: end;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  margin-bottom: 10px;
}

.tower-shop {
  display: grid;
  gap: 8px;
}

.tower-button {
  align-items: center;
  background: var(--panel-2);
  display: grid;
  gap: 10px;
  grid-template-columns: 42px 1fr auto;
  min-height: 66px;
  padding: 9px 10px;
  text-align: left;
  touch-action: none;
  width: 100%;
}

.tower-button.active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(84, 214, 166, 0.3);
}

.tower-button.dragging {
  border-color: var(--accent-2);
  cursor: grabbing;
  opacity: 0.78;
}

body.placing-tower {
  user-select: none;
}

.tower-icon {
  align-items: center;
  border-radius: 8px;
  color: #071010;
  display: flex;
  font-size: 1.1rem;
  font-weight: 900;
  height: 42px;
  justify-content: center;
  width: 42px;
}

.tower-copy strong {
  display: block;
  font-size: 0.88rem;
  line-height: 1.15;
}

.tower-copy span {
  color: var(--muted);
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.3;
  margin-top: 3px;
}

.tower-cost {
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 900;
  white-space: nowrap;
}

.card-row {
  display: grid;
  gap: 8px;
}

.control-card {
  background: #202728;
  min-height: 56px;
  text-align: left;
  width: 100%;
}

.control-card strong {
  display: block;
  font-size: 0.82rem;
}

.control-card span {
  color: var(--muted);
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  margin-top: 2px;
}

.codex {
  color: #d6dfdc;
  font-size: 0.86rem;
  line-height: 1.5;
}

.log-section {
  padding-bottom: 2px;
}

.incident-log {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
  list-style: decimal;
  margin: 0;
  min-height: 86px;
  padding-left: 20px;
}

.incident-log li {
  margin-bottom: 5px;
}

@media (max-width: 1120px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .status-grid {
    min-width: 0;
    width: 100%;
  }

  .play-layout {
    grid-template-columns: 1fr;
  }

  .control-panel {
    border-left: 0;
    max-height: none;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 10px;
  }

  .topbar {
    padding: 14px;
  }

  .status-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .canvas-wrap {
    min-height: auto;
    padding: 8px;
  }

  .compact-controls {
    display: none;
  }

  .mobile-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}
