/* style.css */

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600;800&family=Noto+Sans+KR:wght@300;400;700;900&display=swap');

:root {
  --bg-primary: #05060b;
  --bg-secondary: #0d0f1a;
  --panel-bg: rgba(15, 18, 36, 0.7);
  --panel-border: rgba(255, 255, 255, 0.07);
  
  --primary-color: #a855f7;      /* Nebula Purple */
  --primary-glow: rgba(168, 85, 247, 0.35);
  --secondary-color: #06b6d4;    /* Aurora Cyan */
  --secondary-glow: rgba(6, 182, 212, 0.35);
  
  --accent-easy: #10b981;        /* Emerald Star */
  --accent-normal: #f59e0b;      /* Nova Amber */
  --accent-hard: #ef4444;        /* Supernova Red */
  
  --text-main: #f3f4f6;
  --text-muted: #8e95a5;
  --glass-specular: rgba(255, 255, 255, 0.02);
  
  --transition-smooth: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-drag: none;
}

body {
  font-family: 'Outfit', 'Noto Sans KR', sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-main);
  min-height: 100vh;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  /* Starry background effect */
  background-image: 
    radial-gradient(circle at 20% 30%, rgba(168, 85, 247, 0.18) 0%, transparent 45%),
    radial-gradient(circle at 80% 70%, rgba(6, 182, 212, 0.15) 0%, transparent 45%),
    radial-gradient(1px 1px at 25px 35px, #fff, rgba(0,0,0,0)),
    radial-gradient(1.5px 1.5px at 60px 120px, #fff, rgba(0,0,0,0)),
    radial-gradient(1px 1px at 150px 80px, #fff, rgba(0,0,0,0)),
    radial-gradient(2px 2px at 220px 300px, rgba(255,255,255,0.8), rgba(0,0,0,0)),
    radial-gradient(1px 1px at 300px 180px, #fff, rgba(0,0,0,0)),
    radial-gradient(1.5px 1.5px at 450px 280px, rgba(255,255,255,0.7), rgba(0,0,0,0));
  background-size: 550px 550px;
  background-attachment: fixed;
}

/* Header & Controls */
header {
  width: 100%;
  max-width: 900px;
  padding: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 10;
}

.logo {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 4px 20px var(--primary-glow);
}

.top-controls {
  display: flex;
  gap: 10px;
}

.btn-icon {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  color: var(--text-main);
  padding: 10px 14px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: var(--transition-smooth);
  backdrop-filter: blur(10px);
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--primary-color);
  box-shadow: 0 0 15px rgba(168, 85, 247, 0.2);
  transform: translateY(-2px);
}

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

/* Game Area Layout */
main {
  width: 100%;
  max-width: 1000px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  flex-grow: 1;
  justify-content: center;
}

.stats-panel {
  display: flex;
  justify-content: space-around;
  align-items: center;
  width: 100%;
  max-width: 500px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 15px 25px;
  backdrop-filter: blur(12px);
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 1px;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 22px;
  font-weight: 800;
  background: linear-gradient(135deg, #ffffff, #d1d5db);
  -webkit-background-clip: text;
}

.stat-value.highlight {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Difficulty/Level Selector */
.difficulty-selector {
  display: flex;
  gap: 8px;
  background: rgba(15, 18, 36, 0.4);
  padding: 8px;
  border-radius: 16px;
  border: 1px solid var(--panel-border);
}

.diff-btn {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.diff-btn:hover:not(.locked) {
  border-color: var(--primary-color);
  color: #fff;
}

.diff-btn.active {
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  color: #ffffff;
  border-color: transparent;
  box-shadow: 0 4px 15px rgba(168, 85, 247, 0.35);
}

.diff-btn.locked {
  opacity: 0.3;
  cursor: not-allowed;
  background: rgba(0, 0, 0, 0.3);
}

/* Board Arena (Supports AI side-by-side) */
.arena {
  display: flex;
  gap: 40px;
  align-items: center;
  justify-content: center;
  width: 100%;
  flex-wrap: wrap;
}

.board-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.board-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* Grid Board */
.grid-board {
  display: grid;
  grid-template-rows: repeat(8, 1fr);
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  width: 320px;
  height: 320px;
  background: rgba(15, 17, 28, 0.8);
  border: 2px solid var(--panel-border);
  border-radius: 16px;
  padding: 6px;
  position: relative;
  box-shadow: inset 0 4px 20px rgba(0, 0, 0, 0.5);
  transition: var(--transition-smooth);
}

.grid-board.ai-board {
  border-color: rgba(239, 68, 68, 0.3);
}

.grid-cell {
  background: rgba(255, 255, 255, 0.02);
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.01);
  position: relative;
  transition: background-color 0.1s ease;
}

.grid-cell.highlight-target {
  background: rgba(168, 85, 247, 0.2);
  border: 1px dashed var(--primary-color);
}

/* Block styles */
.block-cell {
  border-radius: 6px;
  box-shadow: 
    inset 0 2px 4px rgba(255, 255, 255, 0.3),
    0 2px 4px rgba(0, 0, 0, 0.3);
  transition: var(--transition-smooth);
  animation: popIn 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.cell-color-1 { background: linear-gradient(135deg, #ec4899, #db2777); } /* Pink */
.cell-color-2 { background: linear-gradient(135deg, #3b82f6, #2563eb); } /* Blue */
.cell-color-3 { background: linear-gradient(135deg, #10b981, #059669); } /* Green */
.cell-color-4 { background: linear-gradient(135deg, #f59e0b, #d97706); } /* Orange */
.cell-color-5 { background: linear-gradient(135deg, #8b5cf6, #7c3aed); } /* Violet */
.cell-color-6 { background: linear-gradient(135deg, #06b6d4, #0891b2); } /* Cyan */
.cell-color-obstacle { 
  background: repeating-linear-gradient(45deg, #4b5563, #4b5563 6px, #374151 6px, #374151 12px); 
  box-shadow: inset 0 2px 4px rgba(255,255,255,0.1);
}

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

/* Dock (Wait Blocks) */
.dock {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
  width: 100%;
  max-width: 500px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 15px;
  backdrop-filter: blur(12px);
  min-height: 120px;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.2);
}

.dock-slot {
  width: 100px;
  height: 100px;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 12px;
  border: 1px dashed rgba(255, 255, 255, 0.05);
  position: relative;
  cursor: grab;
  transition: var(--transition-smooth);
}

.dock-slot:active {
  cursor: grabbing;
}

.dock-slot.selected {
  border-color: var(--primary-color);
  box-shadow: 0 0 15px var(--primary-glow);
  background: rgba(168, 85, 247, 0.05);
}

.dock-slot.disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* Helper to render variable size block in slot */
.dock-block-grid {
  display: grid;
  gap: 2px;
  pointer-events: none;
}

/* Modals & Overlays */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(6, 8, 14, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100; /* Results modal overlay */
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  padding: 30px;
  width: 90%;
  max-width: 440px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6), 0 0 40px var(--primary-glow);
  transform: translateY(20px);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.overlay.active .modal-content {
  transform: translateY(0);
}

.modal-title {
  font-size: 26px;
  font-weight: 800;
  margin-bottom: 12px;
  background: linear-gradient(135deg, #ffffff, #9ca3af);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.modal-body {
  font-size: 15px;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 24px;
}

/* Form Styles inside Modal */
.input-group {
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.text-input {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  color: #fff;
  padding: 12px 16px;
  font-size: 15px;
  width: 100%;
  outline: none;
  text-align: center;
  transition: var(--transition-smooth);
}

.text-input:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 10px var(--primary-glow);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-color), #7c3aed);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 12px 24px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  box-shadow: 0 4px 15px rgba(168, 85, 247, 0.3);
  transition: var(--transition-smooth);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(168, 85, 247, 0.5);
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--panel-border);
  color: var(--text-main);
  border-radius: 12px;
  padding: 12px 24px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  margin-top: 10px;
  transition: var(--transition-smooth);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.05);
}

/* Leaderboard Sidebar */
.leaderboard-sidebar {
  position: fixed;
  top: 0;
  right: -360px; /* Slide out initial state */
  width: 340px;
  height: 100vh;
  background: rgba(19, 21, 32, 0.95);
  backdrop-filter: blur(20px);
  border-left: 1px solid var(--panel-border);
  box-shadow: -10px 0 30px rgba(0, 0, 0, 0.5);
  z-index: 110; /* Always above result overlay (z-index 100) */
  transition: right 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  padding: 30px 20px;
  display: flex;
  flex-direction: column;
}

.leaderboard-sidebar.active {
  right: 0;
}

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

.sidebar-title {
  font-size: 20px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
}

.leaderboard-list {
  flex-grow: 1;
  overflow-y: auto;
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 5px;
}

/* Customize scrollbar */
.leaderboard-list::-webkit-scrollbar {
  width: 4px;
}
.leaderboard-list::-webkit-scrollbar-thumb {
  background: var(--panel-border);
  border-radius: 2px;
}

.rank-item {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: 12px;
}

.rank-num {
  font-weight: 800;
  font-size: 15px;
  width: 28px;
  color: var(--text-muted);
}

.rank-item:nth-child(1) .rank-num { color: #f59e0b; font-size: 18px; }
.rank-item:nth-child(2) .rank-num { color: #94a3b8; font-size: 16px; }
.rank-item:nth-child(3) .rank-num { color: #b45309; font-size: 15px; }

.rank-name {
  flex-grow: 1;
  font-weight: 600;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-score {
  font-weight: 800;
  font-size: 14px;
  color: var(--secondary-color);
}

.no-entry-banner {
  background: rgba(239, 68, 68, 0.1);
  border: 1px dashed rgba(239, 68, 68, 0.3);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 15px;
  color: #fca5a5;
  font-size: 13px;
  display: none;
}

.no-entry-banner.active {
  display: block;
}

/* Hotkey Instruction Panel */
.hotkeys-panel {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 10px 15px;
  font-size: 11px;
  color: var(--text-muted);
  max-width: 500px;
  width: 100%;
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
  gap: 8px;
}

.hotkey-badge {
  background: rgba(255, 255, 255, 0.08);
  border-bottom: 2px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  padding: 1px 6px;
  border-radius: 4px;
  font-family: monospace;
}

/* Footer Copyright */
footer {
  width: 100%;
  padding: 20px;
  text-align: center;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.2);
  z-index: 10;
}

footer a {
  color: inherit;
  text-decoration: none;
}

/* Responsive Scaling */
@media (max-width: 768px) {
  .arena {
    gap: 20px;
  }
  
  .grid-board {
    width: 280px;
    height: 280px;
  }
  
  .dock {
    gap: 12px;
  }
  
  .dock-slot {
    width: 80px;
    height: 80px;
  }
  
  .stats-panel {
    padding: 10px 15px;
  }
  
  .stat-value {
    font-size: 18px;
  }
}
