:root {
  --bg: #07060f;
  --text: #f4f8ff;
  --muted: #a8b0c8;
  --line: rgba(255,255,255,.12);
  --accent: #ffd34d;
  --accent-2: #7c5cff;
  --storm: #4dd4ff;
  --danger: #ff5c7a;
  --ok: #5cff9a;
}

* { box-sizing: border-box; }

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

body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 0%, rgba(124,92,255,.22), transparent 32rem),
    radial-gradient(circle at 85% 10%, rgba(77,212,255,.16), transparent 28rem),
    radial-gradient(circle at 50% 100%, rgba(255,211,77,.08), transparent 40rem),
    linear-gradient(180deg, #07060f, #0c0a18 55%, #07060f);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
}

button {
  font: inherit;
  cursor: pointer;
}

.site-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: .75rem 1.5rem;
  padding: .85rem clamp(1rem, 3vw, 2rem);
  border-bottom: 1px solid var(--line);
  background: rgba(7,6,15,.9);
  backdrop-filter: blur(14px);
}

.brand {
  font-weight: 950;
  letter-spacing: .08em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--accent);
}

.header-stats {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.stat {
  font-weight: 800;
  font-size: .92rem;
  padding: .35rem .75rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,.35);
}

.nav {
  display: flex;
  gap: .6rem;
  align-items: center;
}

.button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 2.6rem;
  padding: .65rem 1.1rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-weight: 800;
  color: var(--text);
  background: rgba(255,255,255,.06);
}

.button.small {
  min-height: 2.2rem;
  padding: .45rem .9rem;
  font-size: .88rem;
}

.button.primary {
  color: #1a1200;
  background: linear-gradient(135deg, var(--accent), #fff0b8);
  border-color: transparent;
}

.button.secondary:hover,
.button.primary:hover {
  filter: brightness(1.08);
}

.button:disabled {
  opacity: .45;
  cursor: not-allowed;
  filter: none;
}

.game-shell {
  flex: 1;
  display: grid;
  grid-template-columns: 200px 1fr 240px;
  gap: 0;
  min-height: 0;
}

.palette,
.storm-feed {
  padding: 1rem;
  border: 1px solid var(--line);
  background: rgba(0,0,0,.28);
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

.palette {
  border-left: none;
  border-top: none;
}

.storm-feed {
  border-right: none;
  border-top: none;
}

.panel-title {
  margin: 0;
  font-size: .72rem;
  font-weight: 900;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--storm);
}

.phase-label {
  margin: 0;
  font-weight: 900;
  font-size: 1rem;
  color: var(--accent);
}

.phase-label.fighting {
  color: var(--danger);
  animation: pulse 1s ease infinite;
}

.phase-label.boss-prep {
  color: #ff8899;
  animation: pulse 1.4s ease infinite;
}

@keyframes pulse {
  50% { opacity: .65; }
}

.build-tools {
  display: grid;
  gap: .5rem;
}

.tool {
  display: grid;
  grid-template-columns: 2.2rem 1fr auto;
  align-items: center;
  gap: .5rem;
  padding: .55rem .65rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.04);
  color: var(--text);
  text-align: left;
}

.tool:hover {
  background: rgba(124,92,255,.18);
}

.tool.active {
  border-color: var(--storm);
  background: rgba(77,212,255,.14);
  box-shadow: 0 0 0 1px rgba(77,212,255,.25);
}

.tool:disabled {
  opacity: .4;
  cursor: not-allowed;
}

.tool-icon {
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: .85rem;
}

.wall-icon { background: #4a5568; }
.turret-icon { background: linear-gradient(135deg, var(--accent), #c9a020); }
.barracks-icon { background: linear-gradient(135deg, var(--accent-2), #5a3fd4); }
.trap-icon { background: linear-gradient(135deg, var(--storm), #2a9fc4); }
.remove-icon { background: rgba(255,92,122,.25); color: var(--danger); }

.tool-name {
  font-weight: 700;
  font-size: .82rem;
}

.tool-cost {
  font-size: .72rem;
  font-weight: 800;
  color: var(--accent);
}

.palette-actions {
  display: grid;
  gap: .45rem;
  margin-top: auto;
}

.arena-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: .75rem;
  min-height: 0;
  background: rgba(0,0,0,.2);
}

#game-canvas {
  max-width: 100%;
  height: auto;
  border-radius: 16px;
  border: 2px solid var(--line);
  box-shadow: 0 24px 80px rgba(0,0,0,.55);
  cursor: crosshair;
  touch-action: none;
}

.arena-overlay {
  position: absolute;
  inset: .75rem;
  display: grid;
  place-items: center;
  background: rgba(7,6,15,.72);
  border-radius: 16px;
  backdrop-filter: blur(6px);
}

.overlay-card {
  text-align: center;
  padding: 2rem 2.5rem;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,.1), rgba(255,255,255,.04));
  max-width: 22rem;
}

.overlay-card h2 {
  margin: 0 0 .5rem;
  font-size: 2rem;
}

.overlay-card p {
  color: var(--muted);
  margin: 0 0 1.25rem;
}

.feed-hint {
  margin: 0;
  font-size: .78rem;
  color: var(--muted);
}

.feed-scroll {
  flex: 1;
  min-height: 12rem;
  max-height: calc(100vh - 16rem);
  overflow-y: auto;
  display: grid;
  gap: .45rem;
  align-content: start;
  padding: .5rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,.4);
}

.feed-line {
  padding: .45rem .6rem;
  border-radius: 10px;
  font-size: .8rem;
  border: 1px solid var(--line);
  background: linear-gradient(90deg, rgba(255,211,77,.07), rgba(77,212,255,.05));
  word-break: break-word;
}

.feed-line.system { color: var(--storm); font-style: italic; }
.feed-line.combat { color: var(--text); }
.feed-line.player { color: var(--accent); }
.feed-line .who { font-weight: 900; margin-right: .35rem; }

.feed-compose {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .4rem;
}

.feed-compose input {
  padding: .5rem .65rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,.35);
  color: var(--text);
  font: inherit;
  font-size: .82rem;
}

.feed-compose input:focus {
  outline: 2px solid rgba(77,212,255,.4);
}

.feed-compose button {
  grid-column: 1 / -1;
}

.help-dialog {
  max-width: 32rem;
  padding: 1.5rem 1.75rem;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: #12101f;
  color: var(--text);
}

.help-dialog::backdrop {
  background: rgba(0,0,0,.65);
}

.help-dialog h2 {
  margin-top: 0;
}

.help-dialog ol {
  padding-left: 1.2rem;
  color: var(--muted);
}

.help-dialog li {
  margin-bottom: .5rem;
}

.site-footer {
  padding: 1rem clamp(1rem, 3vw, 2rem);
  color: var(--muted);
  text-align: center;
  font-size: .82rem;
  border-top: 1px solid var(--line);
}

@media (max-width: 1100px) {
  .game-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
  }

  .palette {
    order: 2;
    border-left: none;
  }

  .storm-feed {
    order: 3;
    border-left: none;
  }

  .arena-wrap {
    order: 1;
  }

  .build-tools {
    grid-template-columns: repeat(2, 1fr);
  }

  .feed-scroll {
    max-height: 14rem;
  }
}

@media (max-width: 600px) {
  .site-header {
    flex-direction: column;
    align-items: stretch;
  }

  .header-stats,
  .nav {
    justify-content: center;
  }

  .build-tools {
    grid-template-columns: 1fr;
  }
}
