@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&display=swap');

:root {
  --bg-primary: #060611;
  --bg-secondary: #0d1127;
  --bg-card: rgba(255, 255, 255, 0.035);
  --bg-card-hover: rgba(255, 255, 255, 0.065);
  --border: rgba(255, 255, 255, 0.07);
  --border-bright: rgba(255, 255, 255, 0.18);

  --text-primary: #e8eaf6;
  --text-secondary: #7986cb;
  --text-muted: #3d4a6b;

  --accent-cyan: #00e5ff;
  --accent-purple: #a78bfa;
  --accent-gold: #fbbf24;
  --accent-red: #f87171;
  --accent-green: #34d399;

  --point-start: #ff6b6b;
  --point-user: #60a5fa;
  --point-active: #fbbf24;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;

  --font: 'Space Grotesk', system-ui, sans-serif;
}

*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

/* Ambient background gradients */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 50% at 15% 15%, rgba(167,139,250,0.07) 0%, transparent 60%),
    radial-gradient(ellipse 50% 60% at 85% 80%, rgba(0,229,255,0.05) 0%, transparent 60%),
    radial-gradient(ellipse 40% 40% at 50% 50%, rgba(251,191,36,0.02) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* =====================
   MENU / INDEX PAGE
   ===================== */

.menu-page {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 56px 24px 48px;
}

/* Logo */
.logo {
  text-align: center;
  margin-bottom: 56px;
}

.logo-title {
  font-size: clamp(52px, 9vw, 96px);
  font-weight: 700;
  letter-spacing: -3px;
  line-height: 1;
  background: linear-gradient(135deg, var(--accent-cyan) 0%, var(--accent-purple) 55%, var(--accent-gold) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-decoration: line-through;
  text-decoration-color: rgba(255,255,255,0.25);
  animation: logoFloat 4s ease-in-out infinite alternate;
}

@keyframes logoFloat {
  from { filter: drop-shadow(0 0 24px rgba(0,229,255,0.25)); }
  to   { filter: drop-shadow(0 0 48px rgba(167,139,250,0.45)); }
}

.logo-sub {
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 5px;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-top: 12px;
}

/* Level grid */
.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
  width: 100%;
  max-width: 920px;
}

/* Level card */
.level-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 20px 18px;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease, background 0.2s ease;
  overflow: hidden;
  backdrop-filter: blur(12px);
}

.level-card::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent 0%, var(--accent-cyan) 50%, transparent 100%);
  opacity: 0;
  transition: opacity 0.25s;
}

.level-card:hover {
  background: var(--bg-card-hover);
  border-color: rgba(0,229,255,0.22);
  transform: translateY(-3px);
  box-shadow: 0 12px 40px rgba(0,229,255,0.09), 0 4px 16px rgba(0,0,0,0.4);
}

.level-card:hover::after { opacity: 1; }

.level-card.locked {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

.level-card.boss {
  border-color: rgba(251,191,36,0.2);
}

.level-card.boss:hover {
  border-color: rgba(251,191,36,0.45);
  box-shadow: 0 12px 40px rgba(251,191,36,0.1);
}

.level-card.boss::after {
  background: linear-gradient(90deg, transparent 0%, var(--accent-gold) 50%, transparent 100%);
}

.card-number {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--accent-cyan);
}

.level-card.boss .card-number { color: var(--accent-gold); }

.card-name {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.2;
}

.card-desc {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 4px;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}

.difficulty-dots {
  display: flex;
  gap: 3px;
}

.difficulty-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
}

.difficulty-dot.filled {
  background: var(--accent-purple);
  box-shadow: 0 0 4px rgba(167,139,250,0.6);
}

.level-card.boss .difficulty-dot.filled {
  background: var(--accent-gold);
  box-shadow: 0 0 4px rgba(251,191,36,0.6);
}

.card-stars {
  margin-left: auto;
  display: flex;
  gap: 1px;
  font-size: 13px;
}

.card-star { color: var(--text-muted); transition: color 0.3s; }
.card-star.earned { color: var(--accent-gold); }

.card-best {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.5px;
  min-height: 14px;
}

.lock-icon {
  font-size: 20px;
  position: absolute;
  top: 16px;
  right: 16px;
  opacity: 0.4;
}

/* =====================
   GAME PAGE
   ===================== */

.game-page {
  position: relative;
  z-index: 1;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Top HUD */
.hud-top {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: rgba(6,6,17,0.85);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(24px);
  flex-shrink: 0;
  z-index: 10;
}

.hud-back {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}

.hud-back:hover {
  border-color: var(--border-bright);
  color: var(--text-primary);
}

.hud-level-info {
  flex: 1;
  text-align: center;
}

.hud-level-num {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--accent-cyan);
}

.hud-level-name {
  font-size: 15px;
  font-weight: 600;
}

.hud-stars {
  display: flex;
  align-items: center;
  gap: 4px;
}

.hud-star {
  font-size: 18px;
  color: var(--text-muted);
  transition: color 0.35s, filter 0.35s, transform 0.35s;
  filter: grayscale(1) brightness(0.4);
}

.hud-star.earned {
  color: var(--accent-gold);
  filter: drop-shadow(0 0 6px rgba(251,191,36,0.8));
  animation: starPop 0.45s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes starPop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.6) rotate(-8deg); }
  70%  { transform: scale(0.9) rotate(4deg); }
  100% { transform: scale(1); }
}

/* Game main layout */
.game-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 16px;
  overflow: hidden;
}

.canvas-wrapper {
  position: relative;
  flex-shrink: 0;
}

#canvas {
  display: block;
  border-radius: var(--radius-md);
  cursor: crosshair;
  box-shadow:
    0 0 0 1px var(--border),
    0 0 80px rgba(0,229,255,0.06),
    0 20px 60px rgba(0,0,0,0.5);
}

/* Stats sidebar */
.stats-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 200px;
  flex-shrink: 0;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  backdrop-filter: blur(10px);
}

.stat-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
  line-height: 1;
  color: var(--text-primary);
}

.stat-value.cyan  { color: var(--accent-cyan); }
.stat-value.purple { color: var(--accent-purple); }

.stat-sub {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 3px;
}

/* Par / progress bar */
.par-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
}

.par-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.par-bar-track {
  position: relative;
  height: 5px;
  background: rgba(255,255,255,0.06);
  border-radius: 3px;
  margin-bottom: 10px;
}

.par-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent-purple), var(--accent-cyan));
  box-shadow: 0 0 10px rgba(0,229,255,0.35);
  transition: width 0.1s linear;
  max-width: 100%;
}

.par-marker {
  position: absolute;
  top: -5px;
  width: 2px;
  height: 15px;
  border-radius: 1px;
  transform: translateX(-50%);
}
.par-marker.s1 { background: rgba(251,191,36,0.5); }
.par-marker.s2 { background: rgba(251,191,36,0.75); }
.par-marker.s3 { background: var(--accent-gold); box-shadow: 0 0 6px rgba(251,191,36,0.6); }

.par-stars-row {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
}

.par-star-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--text-muted);
}

.par-star-item .pi { font-size: 15px; }
.par-star-item.reached { color: var(--text-primary); }
.par-star-item.reached .pi { color: var(--accent-gold); }

/* Points counter */
.points-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
}

.points-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.points-pips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.point-pip {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1.5px solid rgba(96,165,250,0.25);
  background: transparent;
  transition: background 0.2s, box-shadow 0.2s, border-color 0.2s;
}

.point-pip.placed {
  background: var(--point-user);
  border-color: var(--point-user);
  box-shadow: 0 0 7px rgba(96,165,250,0.6);
}

/* Action buttons */
.game-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  letter-spacing: 0.5px;
}

.btn:hover {
  border-color: var(--border-bright);
  color: var(--text-primary);
  background: var(--bg-card-hover);
}

.btn-submit {
  border-color: rgba(0,229,255,0.4);
  color: var(--accent-cyan);
  font-size: 14px;
  background: rgba(0,229,255,0.06);
}

.btn-submit:hover {
  border-color: var(--accent-cyan);
  background: rgba(0,229,255,0.12);
  color: var(--accent-cyan);
  box-shadow: 0 0 20px rgba(0,229,255,0.2);
}

.btn-hint {

  border-color: rgba(167,139,250,0.3);
  color: var(--accent-purple);
}

.btn-hint:hover {
  border-color: var(--accent-purple);
  box-shadow: 0 0 16px rgba(167,139,250,0.2);
  color: var(--accent-purple);
}

.btn-hint.active {
  border-color: var(--accent-purple);
  background: rgba(167,139,250,0.1);
  color: var(--accent-purple);
  box-shadow: 0 0 20px rgba(167,139,250,0.25);
  animation: hintPulse 1s ease-in-out infinite;
}

@keyframes hintPulse {
  0%, 100% { box-shadow: 0 0 16px rgba(167,139,250,0.2); }
  50%       { box-shadow: 0 0 32px rgba(167,139,250,0.5); }
}

.btn-reset {
  border-color: rgba(248,113,113,0.2);
  color: rgba(248,113,113,0.7);
}

.btn-reset:hover {
  border-color: var(--accent-red);
  color: var(--accent-red);
  box-shadow: 0 0 16px rgba(248,113,113,0.15);
}

/* =====================
   WIN OVERLAY
   ===================== */

.win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6,6,17,0.88);
  backdrop-filter: blur(16px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.win-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

.win-card {
  background: rgba(13,17,39,0.9);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-xl, 28px);
  padding: 48px 56px;
  text-align: center;
  max-width: 420px;
  width: 90%;
  box-shadow: 0 40px 100px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.05);
  transform: scale(0.92) translateY(20px);
  transition: transform 0.4s cubic-bezier(0.34,1.56,0.64,1);
}

.win-overlay.visible .win-card {
  transform: scale(1) translateY(0);
}

.win-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 4px;
  text-transform: uppercase;
  color: var(--accent-cyan);
  margin-bottom: 8px;
}

.win-level-name {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 28px;
}

.win-stars {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 28px;
  font-size: 44px;
}

.win-star {
  color: var(--text-muted);
  filter: grayscale(1) brightness(0.3);
  transition: all 0.5s;
}

.win-star.earned {
  color: var(--accent-gold);
  filter: drop-shadow(0 0 12px rgba(251,191,36,0.8));
}

.win-score-label {
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.win-score-value {
  font-size: 40px;
  font-weight: 700;
  color: var(--accent-cyan);
  margin-bottom: 32px;
}

.win-buttons {
  display: flex;
  gap: 12px;
}

.btn-win-retry {
  flex: 1;
  padding: 12px;
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-win-retry:hover {
  color: var(--text-primary);
  border-color: rgba(255,255,255,0.3);
}

.btn-win-next {
  flex: 2;
  padding: 12px;
  border: none;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent-purple), var(--accent-cyan));
  color: #060611;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.2s;
  letter-spacing: 0.5px;
}

.btn-win-next:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.btn-win-next:disabled {
  background: var(--text-muted);
  cursor: not-allowed;
  transform: none;
}

/* =====================
   HINT PASSWORD MODAL
   ===================== */

.pw-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6,6,17,0.82);
  backdrop-filter: blur(18px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.pw-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

.pw-card {
  background: rgba(13,17,39,0.95);
  border: 1px solid rgba(167,139,250,0.2);
  border-radius: 24px;
  padding: 40px 44px;
  text-align: center;
  width: 360px;
  max-width: 92vw;
  box-shadow:
    0 0 0 1px rgba(167,139,250,0.08),
    0 32px 80px rgba(0,0,0,0.6),
    0 0 60px rgba(167,139,250,0.06);
  transform: scale(0.94) translateY(16px);
  transition: transform 0.35s cubic-bezier(0.34,1.56,0.64,1);
}

.pw-overlay.visible .pw-card {
  transform: scale(1) translateY(0);
}

.pw-card.shake {
  animation: pwShake 0.45s ease;
}

@keyframes pwShake {
  0%, 100% { transform: translateX(0); }
  15%       { transform: translateX(-8px); }
  30%       { transform: translateX(7px); }
  45%       { transform: translateX(-6px); }
  60%       { transform: translateX(5px); }
  75%       { transform: translateX(-3px); }
  90%       { transform: translateX(2px); }
}

.pw-icon {
  font-size: 32px;
  color: var(--accent-purple);
  filter: drop-shadow(0 0 10px rgba(167,139,250,0.6));
  margin-bottom: 12px;
}

.pw-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.pw-sub {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 24px;
}

.pw-input {
  width: 100%;
  padding: 12px 16px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(167,139,250,0.25);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 16px;
  font-weight: 500;
  text-align: center;
  letter-spacing: 3px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  caret-color: var(--accent-purple);
}

.pw-input::placeholder {
  letter-spacing: 1px;
  color: var(--text-muted);
  font-size: 14px;
}

.pw-input:focus {
  border-color: var(--accent-purple);
  box-shadow: 0 0 20px rgba(167,139,250,0.2);
}

.pw-input.error {
  border-color: var(--accent-red);
  box-shadow: 0 0 20px rgba(248,113,113,0.2);
  color: var(--accent-red);
}

.pw-error {
  font-size: 12px;
  color: var(--accent-red);
  min-height: 18px;
  margin-top: 8px;
  font-weight: 500;
  letter-spacing: 0.3px;
}

.pw-buttons {
  display: flex;
  gap: 10px;
  margin-top: 24px;
}

.btn-pw-cancel {
  flex: 1;
  padding: 11px;
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-pw-cancel:hover {
  color: var(--text-primary);
  border-color: rgba(255,255,255,0.3);
}

.btn-pw-submit {
  flex: 2;
  padding: 11px;
  border: none;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, rgba(167,139,250,0.9), rgba(0,229,255,0.85));
  color: #060611;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.5px;
  transition: opacity 0.2s, transform 0.2s;
}

.btn-pw-submit:hover {
  opacity: 0.88;
  transform: translateY(-1px);
}

/* =====================
   RESPONSIVE
   ===================== */

@media (max-width: 768px) {
  .stats-panel { display: none; }

  .game-main {
    padding: 8px;
    flex-direction: column;
  }

  #canvas {
    width: 100% !important;
    height: auto !important;
    aspect-ratio: 1 / 1;
    max-width: 100vw;
    max-height: 60vh;
  }

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

  .win-card {
    padding: 32px 24px;
  }
}
