:root {
  --bg: #06040f;
  --panel-bg: #12101f;
  --panel-border: #2a2545;
  --text: #e8e6f7;
  --muted: #9b96b8;
  --accent: #8b5cf6;
  --accent-2: #22d3ee;
  --danger: #ff3b6b;
  --success: #4ade80;
  --gold: #facc15;
  --radius: 14px;
  --focus-ring: #22d3ee;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
  overflow: hidden;
}

body.high-contrast {
  --bg: #000000;
  --panel-bg: #000000;
  --panel-border: #ffffff;
  --text: #ffffff;
  --muted: #ffffff;
  --accent: #ffffff;
  --accent-2: #ffffff;
  --focus-ring: #ffff00;
}

body.reduced-motion * {
  animation-duration: 0.001s !important;
  transition-duration: 0.001s !important;
}

button, select, input {
  font-family: inherit;
}

button:focus-visible, select:focus-visible, input:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

#app {
  height: 100%;
  width: 100%;
  position: relative;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
}

.screen.active {
  display: flex;
}

/* ---------- studio intro ---------- */

#screen-intro {
  background: #000;
  cursor: pointer;
}

.intro-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  animation: intro-fade-in 0.6s ease both, intro-fade-out 0.6s ease 2.2s both;
}

.intro-logo {
  max-width: min(480px, 82vw);
  width: 100%;
  height: auto;
  filter: drop-shadow(0 0 30px rgba(34, 211, 238, 0.35));
}

.intro-skip {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  animation: intro-pulse 1.6s ease-in-out infinite;
}

@keyframes intro-fade-in {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes intro-fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}
@keyframes intro-pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* ---------- shared cards ---------- */

.menu-card, .panel-card {
  background: linear-gradient(160deg, var(--panel-bg), #0a0816);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 28px 26px;
  width: min(420px, 100%);
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: 0 0 0 1px rgba(139, 92, 246, 0.08), 0 20px 60px rgba(0,0,0,0.6);
  text-align: center;
}

.logo {
  margin: 0 0 4px;
  font-size: 2.1rem;
  letter-spacing: 0.08em;
  font-weight: 800;
}
.logo span { color: var(--accent-2); text-shadow: 0 0 18px var(--accent-2); }

.tagline { color: var(--muted); margin: 0 0 18px; font-size: 0.85rem; }

.menu-highscore {
  font-size: 0.95rem;
  color: var(--muted);
  margin-bottom: 20px;
}
.menu-highscore strong { color: var(--gold); margin-left: 8px; font-size: 1.1rem; }

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
}

.btn {
  appearance: none;
  border: 1px solid var(--panel-border);
  background: rgba(255,255,255,0.03);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.btn:hover { background: rgba(255,255,255,0.08); }
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  color: #0a0816;
  box-shadow: 0 4px 24px rgba(139, 92, 246, 0.4);
}
.btn-primary:hover { filter: brightness(1.08); }

.btn-toggle[aria-pressed="false"] { opacity: 0.6; }

.menu-settings { display: flex; flex-direction: column; gap: 10px; }

.menu-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--muted);
  gap: 10px;
}
.menu-row select {
  background: var(--panel-bg);
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 6px 8px;
}
.menu-row-checks { flex-direction: column; align-items: flex-start; gap: 6px; }
.check { display: flex; align-items: center; gap: 6px; cursor: pointer; }

/* ---------- instructions / achievements ---------- */

.panel-card { text-align: left; }
.panel-card h2 { text-align: center; margin-top: 0; }
.instructions-list { padding-left: 18px; line-height: 1.6; font-size: 0.88rem; color: var(--muted); }
.instructions-list strong { color: var(--text); }

.achievements-list { list-style: none; padding: 0; margin: 0 0 20px; display: flex; flex-direction: column; gap: 8px; }
.achievements-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--panel-border);
  font-size: 0.82rem;
}
.achievements-list li.unlocked { border-color: var(--accent-2); background: rgba(34, 211, 238, 0.08); }
.achievements-list .ach-icon { font-size: 1.1rem; }
.achievements-list .ach-title { font-weight: 700; display: block; }
.achievements-list .ach-desc { color: var(--muted); display: block; font-size: 0.78rem; }

#screen-instructions .btn { width: 100%; margin-top: 4px; }

/* ---------- game screen ---------- */

#screen-game { padding: 8px; gap: 8px; height: 100%; }

#hud {
  width: min(560px, 100%);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 14px;
  padding: 8px 12px;
  background: rgba(18, 16, 31, 0.8);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
}

.hud-group { display: flex; gap: 14px; }
.hud-item { display: flex; flex-direction: column; font-size: 0.65rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.hud-item strong { font-size: 1.05rem; color: var(--text); }

.hud-mission { font-size: 0.75rem; color: var(--accent-2); flex-basis: 100%; text-align: center; }

.hud-powerups { display: flex; gap: 6px; flex-wrap: wrap; }
.powerup-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.7rem;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--panel-border);
}

.hud-controls { display: flex; gap: 6px; }
.icon-btn {
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--panel-border);
  color: var(--text);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  cursor: pointer;
  font-size: 0.9rem;
}
.icon-btn:hover { background: rgba(255,255,255,0.12); }

#board-wrap {
  position: relative;
  width: 100%;
  max-width: 560px;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--panel-border);
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}

#board { display: block; touch-action: none; }

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(6, 4, 15, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  padding: 20px;
}
.overlay.hidden { display: none; }
.overlay h2 { margin: 0; font-size: 1.3rem; }
.overlay .btn { width: 70%; }

#levelup-overlay h2 { color: var(--gold); text-shadow: 0 0 20px var(--gold); font-size: 1.6rem; }
#levelup-overlay p { color: var(--muted); margin: 0; }

#toast-container {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
  z-index: 5;
  width: 90%;
  align-items: center;
}
.toast {
  background: rgba(18, 16, 31, 0.92);
  border: 1px solid var(--accent-2);
  color: var(--text);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  animation: toastIn 0.25s ease, toastOut 0.4s ease 1.6s forwards;
  box-shadow: 0 0 16px rgba(34,211,238,0.35);
}
.toast.achievement { border-color: var(--gold); box-shadow: 0 0 16px rgba(250,204,21,0.4); }
.toast.danger { border-color: var(--danger); box-shadow: 0 0 16px rgba(255,59,107,0.4); }

@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-8px); } }

#touch-controls {
  display: none;
  grid-template-columns: repeat(3, 54px);
  grid-template-rows: repeat(2, 54px);
  gap: 6px;
  margin-top: 4px;
}
#touch-controls .dpad {
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--panel-border);
  color: var(--text);
  font-size: 1.2rem;
  border-radius: 10px;
  cursor: pointer;
}
#dpad-up { grid-column: 2; grid-row: 1; }
#dpad-left { grid-column: 1; grid-row: 2; }
#dpad-down { grid-column: 2; grid-row: 2; }
#dpad-right { grid-column: 3; grid-row: 2; }

@media (max-width: 640px), (pointer: coarse) {
  #touch-controls { display: grid; }
}

/* ---------- game over ---------- */

.new-highscore {
  text-align: center;
  color: var(--gold);
  font-weight: 800;
  margin-bottom: 12px;
  text-shadow: 0 0 14px var(--gold);
}
.new-highscore.hidden { display: none; }

.stats-list {
  list-style: none;
  padding: 0;
  margin: 0 0 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stats-list li {
  display: flex;
  justify-content: space-between;
  font-size: 0.88rem;
  border-bottom: 1px dashed var(--panel-border);
  padding-bottom: 4px;
}
.stats-list strong { color: var(--accent-2); }

.hidden { display: none !important; }

@media (max-width: 420px) {
  .menu-card, .panel-card { padding: 20px 16px; }
  .logo { font-size: 1.7rem; }
}
