:root {
  color-scheme: dark;
  --accent: #a855f7;
  --accent-glow: #c084fc;
  --accent-dim: rgba(168, 85, 247, 0.18);
  --bg: #0f0c1a;
  --bg-card: #1a152b;
  --bg-card-soft: #221b38;
  --text: #e9e3f7;
  --text-muted: #8b7da3;
  --border: #3d2f5c;
  --tile-empty: #1a152b;
  --tile-wall:  #3d2f5c;
  --tile-lava:  #5b2a1c;
  --tile-door:  #5a4216;
  --tile-goal:  #1d3a4a;
  --tile-start: #2a1f44;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { min-height: 100%; }
body {
  font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(ellipse at top, var(--bg-card-soft) 0%, var(--bg) 60%, #060410 100%);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 12, 26, 0.7);
}
.game-header h1 {
  color: var(--accent);
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.01em;
}
.back {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
}
.back:hover { color: var(--text); }
.mode-badge {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 4px 12px;
  border-radius: 16px;
  font-size: 12px;
  color: var(--text-muted);
}

.level-title {
  text-align: center;
  margin: 12px auto 0;
  font-size: 14px;
  color: var(--text-muted);
}

.game-shell {
  display: grid;
  grid-template-columns: 220px 1fr 300px;
  gap: 18px;
  padding: 20px 24px;
  max-width: 1240px;
  margin: 0 auto;
  width: 100%;
  align-items: start;
}

.token-tray {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.token-tray::before {
  content: "Spells";
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 4px;
}

.token {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  border-radius: 6px;
  cursor: grab;
  user-select: none;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 12.5px;
  transition: transform 0.1s ease, background 0.15s ease;
}
.token:hover { background: rgba(168, 85, 247, 0.25); }
.token:active { cursor: grabbing; }
.token.dragging { opacity: 0.45; }
.token code { color: var(--text); }
.token .mana-tag {
  color: #fde047;
  font-size: 11px;
  margin-left: 8px;
  white-space: nowrap;
}

.play-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
#grid-canvas {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  max-width: 100%;
  height: auto;
  display: block;
}
.hud {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 13px;
  color: var(--text-muted);
  align-items: center;
}
.hud strong { color: var(--accent); font-weight: 700; }
.hud .hint { font-style: italic; color: #fde047; font-size: 12px; }

.slot-strip {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  min-height: 420px;
}
.slot-strip::before {
  content: "Spell sequence";
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 6px;
}

.slot {
  min-height: 34px;
  padding: 6px 10px;
  border: 1px dashed var(--border);
  border-radius: 5px;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 12.5px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.slot.has-token {
  border-style: solid;
  border-color: var(--accent);
  background: rgba(168, 85, 247, 0.1);
  color: var(--text);
}
.slot.indented { margin-left: 22px; border-left: 2px solid var(--accent); }
.slot.drop-target { background: rgba(168, 85, 247, 0.25); border-style: solid; }
.slot .remove {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 0 6px;
  line-height: 1;
}
.slot .remove:hover { color: #ff6b6b; }

.run-bar {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 20px;
}
.btn-primary, .btn-secondary {
  font: inherit;
  cursor: pointer;
  padding: 11px 28px;
  border-radius: 7px;
  font-weight: 600;
  border: none;
}
.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-glow); }
.btn-primary:disabled { background: var(--border); cursor: not-allowed; opacity: 0.6; }
.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-card); }

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.78);
  z-index: 1000;
  padding: 1rem;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--bg-card);
  padding: 28px 32px;
  border-radius: 12px;
  border: 1px solid var(--accent);
  text-align: center;
  min-width: 280px;
  max-width: 92vw;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
}
.modal-card h2 { color: var(--accent); margin-bottom: 12px; }
.modal-card p { margin: 6px 0; color: var(--text); }
.modal-card .name-input {
  width: 100%;
  padding: 8px 10px;
  margin: 10px 0;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
}
.modal-card button {
  margin-top: 14px;
  padding: 10px 24px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
}
.modal-card button:hover { background: var(--accent-glow); }
.modal-card .small {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
}

@media (max-width: 900px) {
  .game-shell { grid-template-columns: 1fr; gap: 14px; padding: 14px; }
  .token-tray { flex-direction: row; flex-wrap: wrap; }
  .token { flex: 1 1 calc(50% - 8px); }
  #grid-canvas { width: 100%; max-width: 480px; }
}
