:root {
  --bg: #061012;
  --panel: #102a2d;
  --panel2: #17383b;
  --line: rgba(70, 229, 255, 0.18);
  --paper: #f0fff7;
  --muted: #a9c9c7;
  --lime: #7cff4f;
  --aqua: #46e5ff;
  --pink: #ff5fb7;
  --orange: #ff9f1c;
  --essence: #ffe45e;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 18% 12%, rgba(124, 255, 79, 0.18), transparent 32%),
    radial-gradient(circle at 82% 18%, rgba(255, 95, 183, 0.14), transparent 28%),
    linear-gradient(135deg, #061012, #0d2427 55%, #05090a);
  color: var(--paper);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
  overflow-x: hidden;
}

button {
  border: 1px solid rgba(70, 229, 255, 0.2);
  background: rgba(255, 255, 255, 0.07);
  color: var(--paper);
  border-radius: 8px;
  min-height: 40px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

button:hover {
  transform: translateY(-1px);
  border-color: rgba(124, 255, 79, 0.45);
  background: rgba(124, 255, 79, 0.11);
}

button.active {
  border-color: rgba(124, 255, 79, 0.8);
  background: rgba(124, 255, 79, 0.16);
}

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

.shell {
  width: min(1280px, 100vw);
  min-height: 100vh;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  align-items: center;
}

.game-wrap {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: #081314;
  border: 1px solid var(--line);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.36);
}

canvas {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 2;
  background: #071315;
}

.hud-top {
  position: absolute;
  left: 12px;
  right: 12px;
  top: 12px;
  display: flex;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}

.brand,
.stat,
.toast,
.panel,
.selected,
.wave-preview {
  backdrop-filter: blur(12px);
  background: rgba(16, 42, 45, 0.78);
  border: 1px solid var(--line);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.24);
}

.brand {
  border-radius: 10px;
  padding: 8px 11px;
  display: grid;
  line-height: 1;
}

.brand span {
  color: var(--essence);
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.brand strong {
  font-size: 16px;
}

.stat {
  border-radius: 999px;
  padding: 7px 11px;
  min-width: 86px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.stat span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.stat strong {
  color: var(--essence);
}

.icon-btn {
  padding: 0 12px;
  min-height: 36px;
  pointer-events: auto;
}

#editorToggle {
  margin-left: auto;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  border-radius: 999px;
  padding: 9px 16px;
  color: #ddfff4;
  font-size: 13px;
  font-weight: 800;
  transition: opacity 200ms ease, transform 200ms ease;
}

.toast.hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(10px);
}

.panel {
  border-radius: 12px;
  padding: 14px;
}

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

.section-head span {
  color: var(--essence);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.section-head small {
  color: var(--muted);
  font-weight: 800;
}

.tower-tray {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.tower-card {
  min-height: 72px;
  padding: 8px;
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 8px;
  align-items: center;
  text-align: left;
}

.tower-card.active {
  border-color: rgba(124, 255, 79, 0.8);
  background: rgba(124, 255, 79, 0.14);
}

.tower-card img {
  width: 42px;
  height: 42px;
  object-fit: cover;
  object-position: center;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
}

.tower-card strong {
  display: block;
  font-size: 12px;
}

.tower-card small {
  color: var(--muted);
  font-size: 11px;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.actions .primary {
  grid-column: 1 / -1;
  color: #08200b;
  background: linear-gradient(135deg, var(--lime), var(--essence));
  border-color: rgba(255, 255, 255, 0.25);
}

.selected,
.wave-preview,
.editor-panel {
  margin-top: 12px;
  border-radius: 10px;
  padding: 12px;
}

.selected.has-selection {
  border-color: rgba(255, 228, 94, 0.75);
  background: rgba(74, 70, 25, 0.56);
  box-shadow: 0 0 0 1px rgba(255, 228, 94, 0.18), 0 16px 44px rgba(0, 0, 0, 0.28);
}

.selected p,
.wave-preview p,
.editor-panel p {
  margin: 0;
  color: #d8f2ef;
  font-size: 13px;
  line-height: 1.35;
}

.hidden {
  display: none;
}

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

.editor-grid .primary {
  grid-column: span 2;
  color: #08200b;
  background: linear-gradient(135deg, var(--aqua), var(--lime));
}

.editor-panel.drag-ready {
  outline: 2px solid rgba(124, 255, 79, 0.72);
  outline-offset: 3px;
}

#editorHint {
  margin-top: 10px;
}

.tower-card canvas {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
}

.tutorial-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  padding: 20px;
  background: rgba(2, 7, 8, 0.42);
  backdrop-filter: blur(2px);
}

.tutorial-overlay.hidden {
  display: none;
}

.tutorial-card {
  position: absolute;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  width: min(520px, calc(100vw - 32px));
  overflow: hidden;
  border-radius: 16px;
  border: 1px solid rgba(70, 229, 255, 0.32);
  background: linear-gradient(145deg, rgba(12, 35, 37, 0.96), rgba(7, 16, 18, 0.98));
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.5);
  pointer-events: auto;
}

.tutorial-target {
  position: absolute;
  left: var(--target-x, 50%);
  top: var(--target-y, 50%);
  width: var(--target-w, 96px);
  height: var(--target-h, 72px);
  transform: translate(-50%, -50%);
  border-radius: 14px;
  border: 3px solid rgba(255, 228, 94, 0.92);
  box-shadow:
    0 0 0 9999px rgba(2, 7, 8, 0.34),
    0 0 28px rgba(255, 228, 94, 0.42),
    inset 0 0 18px rgba(124, 255, 79, 0.18);
  pointer-events: none;
  transition: left 280ms ease, top 280ms ease, width 280ms ease, height 280ms ease;
}

.tutorial-cursor {
  position: absolute;
  left: var(--cursor-x, 50%);
  top: var(--cursor-y, 50%);
  width: 34px;
  height: 34px;
  transform: translate(8px, 8px) rotate(-18deg);
  clip-path: polygon(0 0, 0 100%, 29% 74%, 45% 100%, 61% 91%, 47% 66%, 83% 66%);
  background: #f0fff7;
  border: 2px solid #071314;
  filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.45));
  pointer-events: none;
  transition: left 360ms ease, top 360ms ease;
  animation: tutorialClick 1.35s ease-in-out infinite;
}

@keyframes tutorialClick {
  0%, 100% { transform: translate(8px, 8px) rotate(-18deg) scale(1); }
  52% { transform: translate(8px, 8px) rotate(-18deg) scale(0.86); }
  64% { transform: translate(8px, 8px) rotate(-18deg) scale(1.04); }
}

.tutorial-copy {
  padding: 28px;
}

.tutorial-kicker {
  margin: 0 0 8px;
  color: var(--essence);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.tutorial-copy h1 {
  margin: 0;
  font-size: 32px;
  line-height: 1.04;
}

.tutorial-copy > p:not(.tutorial-kicker) {
  min-height: 96px;
  margin: 14px 0 18px;
  color: #d8f2ef;
  font-size: 16px;
  line-height: 1.48;
}

.tutorial-steps {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
}

.tutorial-dot {
  width: 34px;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
}

.tutorial-dot.active {
  background: linear-gradient(135deg, var(--lime), var(--essence));
}

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

.tutorial-actions .primary {
  color: #08200b;
  background: linear-gradient(135deg, var(--lime), var(--essence));
  border-color: rgba(255, 255, 255, 0.25);
}

@media (max-width: 980px) {
  .shell {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .panel {
    order: -1;
  }

  .hud-top {
    flex-wrap: wrap;
  }

  .tutorial-card {
    bottom: 14px;
  }

  .tutorial-copy {
    padding: 22px;
  }

  .tutorial-copy h1 {
    font-size: 27px;
  }
}
