/* =====================================================
   PUZZLES PAGE - Cogitalude
   ===================================================== */

.puzzles-container {
  min-height: 100vh;
  background: var(--bg-primary);
  color: var(--text-primary);
}

/* Header */
.puzzles-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.back-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  transition: color 0.2s;
}

.back-link:hover {
  color: var(--primary-light);
}

.puzzles-header h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.user-stats {
  display: flex;
  gap: 1rem;
}

.stat-item {
  background: var(--bg-elevated);
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

.auth-section {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.user-avatar {
  width: 32px;
  height: 32px;
  background: var(--primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.9rem;
}

.user-name {
  font-weight: 500;
}

/* Login Required */
.login-required {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: calc(100vh - 80px);
  padding: 2rem;
}

.login-card {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: 3rem;
  text-align: center;
  max-width: 400px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.login-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
}

.login-card h2 {
  margin-bottom: 0.5rem;
}

.login-card p {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

.link-secondary {
  display: block;
  margin-top: 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Main Content */
.puzzles-main {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 2rem;
  padding: 2rem;
  max-width: 1400px;
  margin: 0 auto;
}

@media (max-width: 900px) {
  .puzzles-main {
    grid-template-columns: 1fr;
  }
}

/* Sections */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.section-header h2 {
  font-size: 1.2rem;
  font-weight: 600;
  margin: 0;
}

/* Leaderboard */
.leaderboard-section {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  height: fit-content;
  position: sticky;
  top: 100px;
}

.leaderboard-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.leaderboard-entry {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  background: var(--bg-elevated);
  border-radius: var(--radius);
  transition: transform 0.2s;
}

.leaderboard-entry:hover {
  transform: translateX(4px);
}

.leaderboard-entry.top-3 {
  background: linear-gradient(135deg, rgba(255,215,0,0.1), rgba(255,215,0,0.05));
  border: 1px solid rgba(255,215,0,0.3);
}

.leaderboard-entry.current-user {
  background: linear-gradient(135deg, rgba(99,102,241,0.2), rgba(139,92,246,0.1));
  border: 1px solid var(--primary);
}

.rank-badge {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  border-radius: 50%;
  background: var(--bg-primary);
}

.rank-badge.gold { background: linear-gradient(135deg, #FFD700, #FFA500); color: #000; }
.rank-badge.silver { background: linear-gradient(135deg, #C0C0C0, #A8A8A8); color: #000; }
.rank-badge.bronze { background: linear-gradient(135deg, #CD7F32, #8B4513); color: #fff; }

.leaderboard-user {
  flex: 1;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.leaderboard-points {
  font-weight: 600;
  color: var(--accent);
}

.leaderboard-puzzles {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Filter Tabs */
.filter-tabs {
  display: flex;
  gap: 0.5rem;
}

.filter-tab {
  padding: 0.4rem 0.8rem;
  background: var(--bg-elevated);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
}

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

.filter-tab.active {
  background: var(--primary);
  color: white;
}

/* Puzzles Grid */
.puzzles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
}

.puzzle-card {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  cursor: pointer;
  transition: all 0.3s;
  border: 2px solid transparent;
  position: relative;
  overflow: hidden;
}

.puzzle-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  border-color: var(--primary);
}

.puzzle-card.completed {
  opacity: 0.7;
}

.puzzle-card.completed::after {
  content: '✓';
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 28px;
  height: 28px;
  background: var(--success);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  color: white;
}

.puzzle-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.75rem;
}

.puzzle-card-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0;
}

.puzzle-card-points {
  background: var(--accent);
  color: white;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
}

.puzzle-card-description {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 1rem;
  line-height: 1.4;
}

.puzzle-card-meta {
  display: flex;
  gap: 1rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.puzzle-card-meta .difficulty {
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
}

.difficulty.easy { background: rgba(34, 197, 94, 0.2); color: #22c55e; }
.difficulty.medium { background: rgba(234, 179, 8, 0.2); color: #eab308; }
.difficulty.hard { background: rgba(239, 68, 68, 0.2); color: #ef4444; }

.puzzle-card-score {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-muted);
}

.puzzle-card-score strong {
  color: var(--accent);
}

/* Modal Styles */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.8);
  z-index: 1000;
  justify-content: center;
  align-items: center;
  padding: 1rem;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: var(--bg-elevated);
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-primary);
  z-index: 10;
}

/* Puzzle Modal */
.puzzle-modal-content {
  width: 100%;
  max-width: 1000px;
  padding: 2rem;
}

.puzzle-info {
  text-align: center;
  margin-bottom: 1.5rem;
}

.puzzle-info h2 {
  margin-bottom: 0.5rem;
}

.puzzle-info p {
  color: var(--text-muted);
}

.puzzle-meta {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-top: 1rem;
}

.meta-item {
  font-size: 0.9rem;
}

/* Puzzle Game Area */
.puzzle-game-area {
  display: flex;
  justify-content: center;
  margin: 1.5rem 0;
}

.puzzle-grid {
  display: grid;
  gap: 2px;
  background: var(--border);
  padding: 2px;
  border-radius: var(--radius);
}

.puzzle-cell {
  width: 36px;
  height: 36px;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 1.1rem;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
}

.puzzle-cell.empty {
  background: var(--bg-secondary);
  cursor: default;
}

.puzzle-cell.selected {
  background: var(--primary);
  color: white;
}

.puzzle-cell.highlighted {
  background: rgba(99, 102, 241, 0.3);
}

.puzzle-cell.correct {
  background: rgba(34, 197, 94, 0.3);
}

.puzzle-cell .cell-number {
  position: absolute;
  top: 2px;
  left: 3px;
  font-size: 0.6rem;
  color: var(--text-muted);
}

.puzzle-cell input {
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
  text-align: center;
  font-weight: 600;
  font-size: 1.1rem;
  text-transform: uppercase;
  color: inherit;
  caret-color: var(--primary-light);
}

.puzzle-cell input:focus {
  outline: none;
}

/* Puzzle Controls */
.puzzle-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 0;
  border-top: 1px solid var(--border);
  margin-top: 1rem;
}

.timer-display {
  font-size: 1.5rem;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  color: var(--primary-light);
}

.timer-display.warning {
  color: var(--warning);
}

.timer-display.danger {
  color: var(--danger);
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.puzzle-actions {
  display: flex;
  gap: 0.75rem;
}

/* Puzzle Clues */
.puzzle-clues {
  margin-top: 1.5rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

.clues-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.clue-tab {
  padding: 0.5rem 1rem;
  background: var(--bg-elevated);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-secondary);
  transition: all 0.2s;
}

.clue-tab.active {
  background: var(--primary);
  color: white;
}

.clues-content {
  max-height: 200px;
  overflow-y: auto;
}

.clues-list {
  display: none;
  flex-direction: column;
  gap: 0.5rem;
}

.clues-list.active {
  display: flex;
}

.clue-item {
  display: flex;
  gap: 0.75rem;
  padding: 0.5rem;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.2s;
}

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

.clue-item.solved {
  opacity: 0.5;
  text-decoration: line-through;
}

.clue-number {
  font-weight: 700;
  color: var(--primary-light);
  min-width: 24px;
}

.clue-text {
  flex: 1;
  font-size: 0.9rem;
}

.clue-length {
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* Result Modal */
.result-modal-content {
  padding: 3rem;
  text-align: center;
  max-width: 400px;
}

.result-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
}

.result-stats {
  display: flex;
  justify-content: center;
  gap: 2rem;
  margin: 2rem 0;
}

.result-stat {
  text-align: center;
}

.stat-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* Auth Modal */
.auth-modal-content {
  padding: 2rem;
  width: 100%;
  max-width: 400px;
}

.auth-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.auth-tab {
  flex: 1;
  padding: 0.75rem;
  background: var(--bg-elevated);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.95rem;
  color: var(--text-secondary);
  transition: all 0.2s;
}

.auth-tab.active {
  background: var(--primary);
  color: white;
}

.auth-form {
  display: none;
}

.auth-form.active {
  display: block;
}

.auth-form .form-group {
  margin-bottom: 1rem;
}

.auth-form label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.auth-form input[type="text"],
.auth-form input[type="email"],
.auth-form input[type="password"] {
  width: 100%;
  padding: 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 1rem;
}

.auth-form input:focus {
  outline: none;
  border-color: var(--primary);
}

.checkbox-group label {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-size: 0.85rem;
}

.checkbox-group input[type="checkbox"] {
  margin-top: 0.2rem;
}

.auth-form .btn-primary {
  width: 100%;
  margin-top: 0.5rem;
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  padding: 1rem 1.5rem;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  animation: slideIn 0.3s ease;
  max-width: 350px;
}

.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.info { border-left: 4px solid var(--primary); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Loading */
.loading {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
}

/* Responsive */
@media (max-width: 768px) {
  .puzzles-header {
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
  }
  
  .header-left, .header-right {
    width: 100%;
    justify-content: center;
  }
  
  .user-stats {
    flex-wrap: wrap;
    justify-content: center;
  }
  
  .puzzles-main {
    padding: 1rem;
  }
  
  .leaderboard-section {
    position: static;
  }
  
  .puzzle-modal-content {
    padding: 1rem;
  }
  
  .puzzle-cell {
    width: 28px;
    height: 28px;
    font-size: 0.9rem;
  }
  
  .puzzle-cell .cell-number {
    font-size: 0.5rem;
  }
}

/* Leaderboard Badge */
.leaderboard-badge {
  font-size: 1.2rem;
  margin-right: 0.25rem;
}

.leaderboard-entry.current-user {
  background: rgba(78, 205, 196, 0.1);
  border-left: 3px solid var(--primary);
}
