:root {
  --bg-top: #1d3028;
  --bg-bottom: #0c1517;
  --panel: rgba(12, 24, 26, 0.88);
  --panel-border: rgba(176, 221, 196, 0.12);
  --text-main: #eef6ee;
  --text-muted: #b0c5b6;
  --accent: #f4c95d;
  --accent-strong: #ff9d42;
  --good: #76d39c;
  --danger: #ff7a7a;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(244, 201, 93, 0.22), transparent 28%),
    radial-gradient(circle at bottom right, rgba(118, 211, 156, 0.18), transparent 30%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  color: var(--text-main);
  font-family: "Trebuchet MS", "Apple SD Gothic Neo", sans-serif;
}

body {
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
}

.app-shell {
  max-width: 1260px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.eyebrow {
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.24em;
}

h1 {
  margin: 4px 0 0;
  font-size: clamp(28px, 5vw, 42px);
  line-height: 1.02;
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 720px) minmax(290px, 420px);
  gap: 16px;
  align-items: start;
}

.board-panel,
.hud-panel > section,
.hud-panel > .stats-grid {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.board-panel {
  position: sticky;
  top: 12px;
  border-radius: 28px;
  padding: 12px;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 22px;
  background: linear-gradient(180deg, #244336 0%, #16261f 100%);
  touch-action: manipulation;
}

.message-banner {
  min-height: 28px;
  margin-top: 10px;
  padding: 6px 10px;
  color: var(--accent);
  font-size: 14px;
  font-weight: 700;
  text-align: center;
}

.hud-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 10px;
  border-radius: 24px;
}

.stat-card {
  padding: 14px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255,255,255,0.07), rgba(255,255,255,0.02));
}

.label,
.section-title,
.status-row span {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.stat-card strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
}

.status-card,
.control-card,
.bottom-actions {
  border-radius: 24px;
  padding: 14px;
}

.status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.status-row:last-child {
  border-bottom: 0;
}

.status-row strong {
  font-size: 15px;
}

.selection-title {
  margin-top: 10px;
  font-size: 18px;
  font-weight: 700;
}

.selection-body {
  margin-top: 8px;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.5;
}

.selection-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.tower-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.tower-card,
.selection-actions button,
.ghost-button,
.primary-button,
.secondary-button {
  border: 0;
  border-radius: 18px;
  color: var(--text-main);
  font: inherit;
}

.tower-card,
.selection-actions button {
  padding: 12px;
  text-align: left;
  background: linear-gradient(180deg, rgba(255,255,255,0.08), rgba(255,255,255,0.03));
  cursor: pointer;
}

.tower-card[disabled],
.selection-actions button[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
}

.tower-card strong {
  display: block;
  margin-bottom: 6px;
  font-size: 16px;
}

.tower-card span {
  display: block;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.35;
}

.ghost-button,
.secondary-button {
  padding: 10px 14px;
  background: rgba(255,255,255,0.08);
  cursor: pointer;
}

.primary-button {
  padding: 14px 18px;
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  color: #2c1803;
  font-weight: 800;
  cursor: pointer;
}

.bottom-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: space-between;
  align-items: center;
}

.rank-link {
  color: var(--good);
  text-decoration: none;
  font-weight: 700;
}

.rule-list {
  margin: 10px 0 0;
  padding-left: 18px;
  color: var(--text-muted);
  line-height: 1.55;
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .board-panel {
    position: static;
  }
}

@media (max-width: 640px) {
  body {
    padding-left: 8px;
    padding-right: 8px;
  }

  .topbar {
    flex-direction: column;
  }

  .topbar-actions,
  .bottom-actions {
    width: 100%;
  }

  .topbar-actions > button,
  .bottom-actions > button,
  .bottom-actions > a {
    flex: 1 1 auto;
    text-align: center;
  }
}
