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

:root {
  --bg-primary: #0a0a14;
  --bg-secondary: #12122a;
  --bg-card: #1a1a35;
  --bg-cell: #22224a;
  --bg-cell-hover: #2a2a55;
  --text-primary: #f0f0f5;
  --text-secondary: #8888aa;
  --text-muted: #555577;
  --accent-gradient: linear-gradient(135deg, #667eea, #764ba2);
  --success-color: #4ade80;
  --glow-intensity: 0.5;
  --cell-size: 56px;
  --cell-gap: 3px;
  --grid-padding: 6px;
  --border-radius: 14px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  position: fixed;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
}

/* === HEADER === */
.game-header {
  text-align: center;
  margin-bottom: 16px;
}

.game-title {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.game-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.player-name {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* === INFO BAR === */
.info-bar {
  display: flex;
  gap: 20px;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.info-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
}

.info-label {
  color: var(--text-secondary);
}

.info-value {
  font-weight: 700;
  color: var(--text-primary);
}

.info-select {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid #333355;
  border-radius: 6px;
  padding: 4px 8px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238888aa' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 6px center;
  background-size: 14px;
  padding-right: 28px;
}

.info-select:hover {
  border-color: #555577;
}

.info-select:focus {
  border-color: #667eea;
  box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.25);
}

.info-value.level {
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-size: 1.1rem;
  cursor: pointer;
}

/* === GRID CONTAINER === */
.grid-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.grid-container {
  background: var(--bg-secondary);
  border-radius: calc(var(--border-radius) + 4px);
  padding: var(--grid-padding);
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.4),
    0 2px 8px rgba(0, 0, 0, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.03);
  position: relative;
  touch-action: none;
}

.grid {
  display: grid;
  gap: var(--cell-gap);
  position: relative;
}

/* === CELLS === */
.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: 10px;
  background: var(--bg-cell);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
  cursor: pointer;
}

.cell:hover {
  background: var(--bg-cell-hover);
}

.cell.filled {
  transition: background 0.1s ease;
}

/* === ENDPOINTS (dots) === */
.endpoint {
  width: 60%;
  height: 60%;
  border-radius: 50%;
  position: absolute;
  z-index: 3;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.endpoint.pulse {
  animation: endpointPulse 2s ease-in-out infinite;
}

@keyframes endpointPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.endpoint.blink {
  animation: endpointBlink 0.5s ease-in-out infinite;
}

@keyframes endpointBlink {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.3); }
}

/* === PATH SEGMENTS === */
.path-segment {
  position: absolute;
  z-index: 2;
  border-radius: 8px;
  opacity: 0.55;
  transition: opacity 0.15s;
}

/* === SVG OVERLAY for smooth paths === */
.path-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
}

/* === BUTTONS === */
.controls {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  flex-wrap: wrap;
  justify-content: center;
}

.btn {
  font-family: 'Inter', sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  border: none;
  border-radius: 10px;
  padding: 10px 20px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: var(--accent-gradient);
  color: white;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.btn-primary:hover {
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid #333355;
}

.btn-secondary:hover {
  background: #252550;
  color: var(--text-primary);
}

.btn-ad {
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  color: white;
  box-shadow: 0 4px 15px rgba(245, 158, 11, 0.3);
}

.btn-ad:hover {
  box-shadow: 0 6px 20px rgba(245, 158, 11, 0.4);
}

.btn-muted {
  opacity: 0.45;
  color: var(--text-muted);
}

/* === AD OVERLAY === */
.ad-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(10, 10, 20, 0.88);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 110;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.ad-overlay.show {
  opacity: 1;
  pointer-events: all;
}

.ad-box {
  background: var(--bg-card);
  border-radius: 20px;
  padding: 32px 40px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

.ad-emoji {
  font-size: 3rem;
}

.ad-title {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text-primary);
}

.ad-subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.ad-countdown {
  font-size: 2.8rem;
  font-weight: 800;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  min-width: 2ch;
  text-align: center;
}

/* === COMPLETION OVERLAY === */
.completion-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(10, 10, 20, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.completion-overlay.show {
  opacity: 1;
  pointer-events: all;
}

.completion-emoji {
  font-size: 4rem;
  margin-bottom: 16px;
  animation: bounceIn 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes bounceIn {
  0% { transform: scale(0); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.completion-title {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(135deg, #4ade80, #22d3ee);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.completion-subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-bottom: 24px;
}

/* === PROGRESS DOTS === */
.flow-count {
  display: flex;
  gap: 4px;
  margin-bottom: 6px;
}

.flow-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.3s, box-shadow 0.3s;
}

.flow-dot.connected {
  box-shadow: 0 0 6px var(--dot-bg);
}

/* === CONFETTI === */
.confetti-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 99;
  overflow: hidden;
}

.confetti {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  top: -10px;
  animation: confettiFall linear forwards;
}

@keyframes hintToastFade {
  0%   { opacity: 0; transform: translateX(-50%) translateY(-8px); }
  20%  { opacity: 1; transform: translateX(-50%) translateY(0); }
  70%  { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) translateY(-4px); }
}

@keyframes confettiFall {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(100vh) rotate(720deg);
    opacity: 0;
  }
}

/* === LEADERBOARD PANEL === */
.leaderboard-panel {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 14px 18px;
  margin-bottom: 16px;
  width: 280px;
  max-width: 90vw;
}

.lb-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.lb-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-primary);
}

#myCleared {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.leaderboard-panel ol {
  list-style: none;
  padding: 0;
  margin: 0;
}

.leaderboard-panel li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 0.8rem;
  color: var(--text-secondary);
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.leaderboard-panel li:last-child {
  border-bottom: none;
}

.lb-rank {
  width: 22px;
  text-align: center;
  font-weight: 700;
  color: var(--text-muted);
}

.lb-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-score {
  font-weight: 700;
  color: var(--text-primary);
}

.lb-empty {
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.78rem;
  padding: 8px 0;
}

/* === RESPONSIVE === */
@media (max-width: 500px) {
  :root {
    --cell-size: 44px;
    --cell-gap: 2px;
    --grid-padding: 5px;
  }
  .game-title { font-size: 1.3rem; }
  .btn { padding: 8px 16px; font-size: 0.78rem; }
}

@media (max-width: 380px) {
  :root {
    --cell-size: 38px;
  }
}

/* === HINT FLASH ANIMATION === */
@keyframes hintFlashAdded {
  0%   { opacity: 0; background: rgba(74, 222, 128, 0.8); }
  40%  { opacity: 1; }
  100% { opacity: 0; background: rgba(74, 222, 128, 0.3); }
}

@keyframes hintFlashRemoved {
  0%   { opacity: 0.9; background: rgba(239, 68, 68, 0.8); }
  100% { opacity: 0;   background: rgba(239, 68, 68, 0.2); }
}

.hint-flash-added {
  animation: hintFlashAdded 0.7s ease forwards;
  border-radius: 10px;
  pointer-events: none;
  position: absolute;
  z-index: 10;
}

.hint-flash-removed {
  animation: hintFlashRemoved 0.5s ease forwards;
  border-radius: 10px;
  pointer-events: none;
  position: absolute;
  z-index: 10;
}
