/* ==========================================================================
   ELITECHESS TACTICS STUDIO (#view-puzzles)
   - Balanced 2-Column Desktop Studio (Hero 1:1 Board + Unified Right Studio Panel)
   - Cohesive Obsidian + Hyper Gold Palette (Zero Clashing Neon Purple/Cyan)
   - Steady-Height Feedback Dock + Quick Themes + 10-Slot Sequential Level Rail
   - Ergonomic Zero-Scroll Mobile Flow + Full Light Theme Support
   ========================================================================== */

/* ==========================================================================
   1. VIEWPORT SHELL
   ========================================================================== */
body:has(#view-puzzles.active) .main-viewport,
body.puzzles-view-active .main-viewport {
  padding: calc(44px + 14px) 22px 28px 22px !important;
  margin: 0 !important;
  max-width: 100% !important;
  width: 100% !important;
  min-height: 100% !important;
  height: auto !important;
  max-height: none !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  box-sizing: border-box !important;
}

body:has(#view-puzzles.active) #view-puzzles.active,
body.puzzles-view-active #view-puzzles.active {
  width: 100% !important;
  min-height: 100% !important;
  height: auto !important;
  max-height: none !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: visible !important;
  padding: 0 !important;
  margin: 0 !important;
  box-sizing: border-box !important;
}

#view-puzzles .puzzles-arena-viewport {
  width: 100% !important;
  max-width: 1120px !important;
  margin: 0 auto !important;
  padding: 4px 0 24px 0 !important;
  display: flex !important;
  flex-direction: column !important;
  box-sizing: border-box !important;
}

/* ==========================================================================
   2. DESKTOP TWO-COLUMN TACTICS STUDIO GRID (> 960px)
   ========================================================================== */
.puzzles-studio-grid {
  display: grid;
  grid-template-columns: minmax(420px, 590px) minmax(350px, 430px);
  justify-content: center;
  align-items: start;
  gap: 30px;
  width: 100%;
  box-sizing: border-box;
  animation: puzzleStudioReveal 0.36s cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* ==========================================================================
   3. LEFT STAGE: OPEN TURN STRIP + 1:1 HERO CHESSBOARD
   ========================================================================== */
.puzzle-stage-col {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  width: 100%;
  box-sizing: border-box;
}

.puzzle-stage-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 4px;
  box-sizing: border-box;
}

.puzzle-stage-header .turn-badge-left {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  flex-wrap: wrap;
}

.puzzle-stage-header .turn-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.puzzle-stage-header .turn-dot.w {
  background: #F8FAFC;
  border: 1.5px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.55);
}

.puzzle-stage-header .turn-dot.b {
  background: #0F172A;
  border: 2px solid #CBD5E1;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.7);
}

.puzzle-stage-header .turn-title {
  font-size: 0.96rem;
  font-weight: 800;
  color: #F8FAFC;
  letter-spacing: -0.01em;
}

.puzzle-stage-sep {
  color: #64748B;
  font-weight: 700;
}

#view-puzzles .puzzle-goal-tag {
  font-size: 0.88rem;
  font-weight: 700;
  color: #FBBF24;
  white-space: nowrap;
}

.puzzle-stage-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.puzzle-icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #94A3B8;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

.puzzle-icon-btn:hover {
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.4);
  color: #FBBF24;
  transform: translateY(-1px);
}

.puzzle-icon-btn:active {
  transform: scale(0.95);
}

.puzzle-icon-btn.active-flipped {
  background: rgba(245, 158, 11, 0.16);
  border-color: rgba(245, 158, 11, 0.55);
  color: #FBBF24;
}

.puzzle-board-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  transition: opacity 0.22s ease, transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

.puzzle-board-wrap.puzzle-switching {
  opacity: 0.72;
  transform: scale(0.985);
}

#view-puzzles #puzzle-board-container {
  width: min(calc(100vh - 165px), 590px) !important;
  height: min(calc(100vh - 165px), 590px) !important;
  min-width: 340px;
  min-height: 340px;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 22px 54px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(255, 255, 255, 0.06);
  position: relative;
  box-sizing: border-box;
}

#view-puzzles #puzzle-board-container .chessboard,
#view-puzzles #puzzle-board-container .board-grid {
  width: 100% !important;
  height: 100% !important;
}

/* ==========================================================================
   4. RIGHT STUDIO PANEL (OBSIDIAN + HYPER GOLD)
   ========================================================================== */
.puzzle-studio-panel {
  background: rgba(15, 18, 26, 0.86);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  padding: 20px 22px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.48);
  display: flex;
  flex-direction: column;
  gap: 15px;
  width: 100%;
  box-sizing: border-box;
}

/* 4.1 Studio Head: Mode Tabs + Browse Pill */
.puzzle-studio-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

#view-puzzles .puzzle-arena-mode-tabs {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: rgba(8, 10, 15, 0.85);
  padding: 3px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

#view-puzzles .puzzle-mode-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 7px;
  font-size: 0.8rem;
  font-weight: 700;
  color: #94A3B8;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  white-space: nowrap;
}

#view-puzzles .puzzle-mode-tab:hover:not(.active) {
  color: #F8FAFC;
  background: rgba(255, 255, 255, 0.05);
}

#view-puzzles .puzzle-mode-tab.active {
  color: #090B10;
  background: linear-gradient(135deg, #FFD166 0%, #FFB703 55%, #F59E0B 100%);
  font-weight: 800;
  box-shadow: 0 3px 12px rgba(245, 158, 11, 0.28);
}

#view-puzzles .puzzle-mode-tab.active .ec-svg-icon,
#view-puzzles .puzzle-mode-tab.active svg {
  color: #090B10 !important;
  filter: none !important;
}

#view-puzzles .puzzle-category-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  height: 34px;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.09);
  color: #E2E8F0;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  white-space: nowrap;
  max-width: 185px;
}

#view-puzzles .puzzle-category-pill-btn .category-pill-icon {
  color: #FBBF24;
  display: inline-flex;
  flex-shrink: 0;
}

#view-puzzles .puzzle-category-pill-btn .category-pill-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#view-puzzles .puzzle-category-pill-btn:hover {
  border-color: rgba(245, 158, 11, 0.5);
  background: rgba(245, 158, 11, 0.1);
  color: #FBBF24;
  transform: translateY(-1px);
}

.category-pill-caret {
  font-size: 0.72rem;
  opacity: 0.75;
}

/* 4.2 Open 3-KPI Row */
.puzzle-kpi-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.puzzle-kpi-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 0;
}

.puzzle-kpi-divider {
  width: 1px;
  height: 28px;
  background: rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.puzzle-kpi-label {
  font-size: 0.67rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #7B8598;
  white-space: nowrap;
}

.puzzle-kpi-val {
  font-family: var(--font-mono, 'JetBrains Mono', monospace);
  font-size: 1.05rem;
  font-weight: 800;
  color: #F8FAFC;
  line-height: 1.15;
  white-space: nowrap;
}

.puzzle-kpi-val.gold {
  color: #FBBF24;
}

.puzzle-kpi-val.flame {
  color: #FB923C;
}

.puzzle-daily-counter-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono, monospace);
  font-size: 0.84rem;
  font-weight: 800;
  color: #10B981;
  white-space: nowrap;
}

.puzzle-daily-pips {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.daily-pip {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  transition: background 0.25s ease, transform 0.25s ease, box-shadow 0.25s ease;
}

.daily-pip.filled {
  background: #10B981;
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.65);
}

.puzzle-daily-counter-pill.practice-mode,
.puzzle-unlimited-tag {
  color: #10B981;
  font-size: 0.82rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* 4.3 Mission Meta Row */
.puzzle-mission-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.mission-meta-left,
.mission-meta-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.puzzle-num-badge {
  font-family: var(--font-mono, monospace);
  font-size: 0.78rem;
  font-weight: 800;
  color: #94A3B8;
}

.puzzle-mission-meta .intel-theme {
  font-size: 0.98rem;
  font-weight: 800;
  color: #F8FAFC;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.puzzle-mission-meta .intel-rating {
  font-family: var(--font-mono, monospace);
  font-size: 0.74rem;
  font-weight: 700;
  color: #CBD5E1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 3px 8px;
  border-radius: 6px;
  white-space: nowrap;
}

.puzzle-mission-meta .intel-reward-pill {
  font-family: var(--font-mono, monospace);
  font-size: 0.74rem;
  font-weight: 800;
  color: #FBBF24;
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.28);
  padding: 3px 8px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

/* 4.4 Steady Tactical Feedback Slot */
.puzzle-feedback-dock {
  width: 100%;
  min-height: 44px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.puzzle-status-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 13px;
  min-height: 42px;
  border-radius: 10px;
  font-size: 0.84rem;
  font-weight: 600;
  line-height: 1.35;
  box-sizing: border-box;
  transition: all 0.24s cubic-bezier(0.16, 1, 0.3, 1);
  animation: puzzleFeedbackPop 0.26s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.puzzle-status-bar .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.puzzle-status-bar .status-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.puzzle-status-bar.default {
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #CBD5E1;
}

.puzzle-status-bar.default .status-dot {
  background: #FBBF24;
  box-shadow: 0 0 8px rgba(251, 191, 36, 0.5);
}

.puzzle-status-bar.verifying {
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.3);
  color: #FBBF24;
}

.puzzle-status-bar.hint {
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: #FDE68A;
}

.puzzle-status-bar.solution {
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.32);
  color: #BAE6FD;
}

.puzzle-status-bar.success {
  background: rgba(16, 185, 129, 0.16);
  border: 1px solid rgba(16, 185, 129, 0.45);
  color: #6EE7B7;
  box-shadow: 0 4px 16px rgba(16, 185, 129, 0.18);
}

.puzzle-status-bar.error {
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.42);
  color: #FCA5A5;
  animation: puzzleShakeX 0.36s ease both;
}

/* 4.5 Primary Ergonomic Action Controls */
.puzzle-action-dock {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  box-sizing: border-box;
}

.puzzle-tools-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: 100%;
}

.puzzle-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 42px;
  padding: 0 12px;
  border-radius: 10px;
  font-size: 0.83rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  white-space: nowrap;
  box-sizing: border-box;
  user-select: none;
}

.puzzle-action-btn:active:not(:disabled) {
  transform: scale(0.97);
}

.puzzle-action-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.puzzle-action-btn.btn-hint {
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.3);
  color: #FBBF24;
}

#view-puzzles .puzzle-action-btn.btn-hint .ec-svg-icon,
#view-puzzles .puzzle-action-btn.btn-hint svg {
  color: #FBBF24 !important;
  filter: none !important;
}

.puzzle-action-btn.btn-hint:hover:not(:disabled),
.puzzle-action-btn.btn-hint.btn-hint-active {
  background: rgba(245, 158, 11, 0.18);
  border-color: rgba(245, 158, 11, 0.6);
  color: #FDE68A;
  transform: translateY(-1px);
}

.puzzle-action-btn.btn-retry {
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #E2E8F0;
}

.puzzle-action-btn.btn-retry:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.22);
  color: #FFFFFF;
  transform: translateY(-1px);
}

.puzzle-action-btn.btn-solution {
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.25);
  color: #7DD3FC;
}

.puzzle-action-btn.btn-solution:hover:not(:disabled) {
  background: rgba(56, 189, 248, 0.16);
  border-color: rgba(56, 189, 248, 0.5);
  color: #BAE6FD;
  transform: translateY(-1px);
}

.puzzle-action-btn.btn-next {
  width: 100%;
  height: 44px;
  font-size: 0.9rem;
  font-weight: 800;
  background: linear-gradient(135deg, #FFD166 0%, #FFB703 55%, #F59E0B 100%);
  border: none;
  color: #090B10;
  box-shadow: 0 6px 18px rgba(245, 158, 11, 0.28);
  animation: puzzleFeedbackPop 0.26s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.puzzle-action-btn.btn-next.pulse-ready {
  background: linear-gradient(135deg, #10B981 0%, #059669 100%);
  color: #FFFFFF;
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.38);
  animation: puzzleFeedbackPop 0.26s cubic-bezier(0.16, 1, 0.3, 1) both, pulseNextReady 1.8s infinite ease-in-out;
}

.puzzle-action-btn.btn-next:hover:not(:disabled) {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.puzzle-key-badge {
  font-size: 0.65rem;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.24);
  color: inherit;
}

/* 4.6 Section Headers & Played Moves Trail */
.puzzle-section-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #7B8598;
}

.puzzle-section-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.puzzle-link-btn {
  background: transparent;
  border: none;
  padding: 2px 0;
  color: #FBBF24;
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.puzzle-link-btn:hover {
  opacity: 0.85;
  transform: translateX(2px);
}

.puzzle-history-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.puzzle-history-moves {
  min-height: 38px;
  max-height: 62px;
  overflow-x: auto;
  overflow-y: hidden;
  background: rgba(8, 10, 15, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 9px;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  box-sizing: border-box;
}

.history-empty {
  font-size: 0.76rem;
  color: #64748B;
}

.history-move-chip {
  font-family: var(--font-mono, monospace);
  font-size: 0.74rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #CBD5E1;
  white-space: nowrap;
  animation: puzzleChipPop 0.2s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.history-move-chip.is-correct {
  background: rgba(16, 185, 129, 0.15);
  border-color: rgba(16, 185, 129, 0.38);
  color: #34D399;
}

.history-move-chip.is-wrong,
.history-move-chip.is-incorrect {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.35);
  color: #F87171;
}

/* 4.7 Quick Tactical Themes Strip */
.puzzle-themes-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.puzzle-quick-themes-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.puzzle-quick-theme-chip {
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #A3ACBA;
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  white-space: nowrap;
}

.puzzle-quick-theme-chip:hover:not(.active) {
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 255, 255, 0.18);
  color: #FFFFFF;
}

.puzzle-quick-theme-chip.active {
  background: rgba(245, 158, 11, 0.14);
  border-color: rgba(245, 158, 11, 0.5);
  color: #FBBF24;
  font-weight: 700;
}

/* 4.8 Sequential Level Rail + Prev/Next Stepper */
.puzzle-progress-section {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.puzzle-level-rail {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 5px;
  width: 100%;
}

.puzzle-rail-btn {
  height: 28px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #94A3B8;
  font-family: var(--font-mono, monospace);
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  padding: 0;
}

.puzzle-rail-btn:hover {
  border-color: rgba(245, 158, 11, 0.45);
  color: #FFFFFF;
  transform: translateY(-1px);
}

.puzzle-rail-btn.is-cleared {
  background: rgba(16, 185, 129, 0.15);
  border-color: rgba(16, 185, 129, 0.42);
  color: #34D399;
}

.puzzle-rail-btn.is-current {
  background: rgba(245, 158, 11, 0.2);
  border-color: #FFB703;
  color: #FFD166;
  font-weight: 800;
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.25);
}

.puzzle-sub-dock {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
}

.puzzle-sub-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 36px;
  padding: 0 13px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid rgba(255, 255, 255, 0.09);
  color: #CBD5E1;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.puzzle-sub-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.22);
  color: #FFFFFF;
}

.puzzle-sub-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.puzzle-compact-counter {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: rgba(8, 10, 15, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 8px;
  padding: 4px 12px;
  height: 36px;
  box-sizing: border-box;
  cursor: pointer;
  transition: all 0.2s ease;
}

.puzzle-compact-counter:hover {
  border-color: rgba(245, 158, 11, 0.45);
  background: rgba(245, 158, 11, 0.07);
}

.counter-num {
  font-size: 0.74rem;
  font-weight: 700;
  color: #E2E8F0;
  line-height: 1;
  white-space: nowrap;
}

.counter-mini-track {
  width: 100%;
  max-width: 120px;
  height: 3px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  overflow: hidden;
}

.counter-mini-fill {
  height: 100%;
  background: linear-gradient(90deg, #F59E0B, #10B981);
  border-radius: 2px;
  transition: width 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

/* 4.9 Subtle Keyboard Shortcuts Bar */
.puzzle-shortcuts-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 0.7rem;
  color: #7B8598;
}

.shortcut-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.shortcut-item kbd {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: var(--font-mono, monospace);
  font-size: 0.65rem;
  color: #CBD5E1;
  font-weight: 700;
}

/* ==========================================================================
   5. TACTICAL LIBRARY & CATEGORIES MODAL
   ========================================================================== */
.puzzle-library-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(4, 6, 10, 0.82);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  box-sizing: border-box;
  animation: puzzleFadeIn 0.2s ease both;
}

.puzzle-library-modal-box {
  background: linear-gradient(165deg, #131722 0%, #090B10 100%);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  width: 100%;
  max-width: 680px;
  max-height: 84vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.9);
  box-sizing: border-box;
  animation: puzzleFeedbackPop 0.26s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.puzzle-library-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.puzzle-library-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.puzzle-library-title-icon {
  color: #FFB703;
}

.puzzle-library-heading {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 800;
  color: #F8FAFC;
}

.puzzle-library-sub {
  margin: 2px 0 0 0;
  font-size: 0.76rem;
  color: #94A3B8;
}

.puzzle-library-close-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: #94A3B8;
  font-size: 1.35rem;
  line-height: 1;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.18s ease;
}

.puzzle-library-close-btn:hover {
  color: #FFFFFF;
  background: rgba(255, 255, 255, 0.1);
}

.puzzle-library-categories-bar {
  display: flex;
  gap: 8px;
  padding: 10px 20px;
  overflow-x: auto;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}

.puzzle-lib-cat-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #CBD5E1;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.puzzle-lib-cat-tab:hover {
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(245, 158, 11, 0.4);
}

.puzzle-lib-cat-tab.active {
  background: rgba(245, 158, 11, 0.15);
  border-color: #FFB703;
  color: #FFD166;
}

.puzzle-lib-cat-count {
  font-size: 0.7rem;
  opacity: 0.7;
}

.puzzle-library-meta-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 20px;
  background: rgba(0, 0, 0, 0.24);
  font-size: 0.78rem;
  font-weight: 700;
}

.puzzle-library-active-name {
  color: #FBBF24;
}

.puzzle-library-active-progress {
  color: #34D399;
}

.puzzle-library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(105px, 1fr));
  gap: 8px;
  padding: 14px 20px;
  overflow-y: auto;
  flex: 1;
}

.puzzle-lib-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 9px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.puzzle-lib-card:hover {
  border-color: rgba(245, 158, 11, 0.55);
  transform: translateY(-2px);
  background: rgba(255, 255, 255, 0.06);
}

.puzzle-lib-card.active-level {
  border-color: #FFB703;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.26);
}

.puzzle-lib-card.cleared-level {
  border-color: rgba(16, 185, 129, 0.42);
  background: rgba(16, 185, 129, 0.08);
}

.puzzle-lib-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.puzzle-lib-card-num {
  font-size: 0.78rem;
  font-weight: 800;
  color: #F8FAFC;
}

.puzzle-lib-card-check {
  color: #34D399;
}

.puzzle-lib-card-tier {
  font-size: 0.64rem;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.07);
  color: #CBD5E1;
}

.puzzle-lib-card-rating {
  font-size: 0.74rem;
  font-weight: 700;
  color: #FBBF24;
}

.puzzle-lib-card-reward {
  font-size: 0.68rem;
  color: #94A3B8;
}

/* ==========================================================================
   6. SQUARE HIGHLIGHTS, KEYFRAMES & LOADING STATES
   ========================================================================== */
.square.puzzle-square-correct {
  background-color: rgba(16, 185, 129, 0.52) !important;
}

.square.puzzle-square-incorrect {
  background-color: rgba(239, 68, 68, 0.52) !important;
}

.square.puzzle-square-hint-origin {
  box-shadow: inset 0 0 0 4px #F59E0B !important;
  animation: pulseGold 1.3s infinite ease-in-out;
}

.square.puzzle-square-hint-dest {
  box-shadow: inset 0 0 0 4px #10B981 !important;
  animation: pulseEmerald 1.3s infinite ease-in-out;
}

.piece.piece-error-shake {
  animation: pieceShake 0.4s ease-in-out;
}

.puzzle-loading-card,
.puzzle-error-card,
.puzzle-empty-card {
  background: rgba(15, 18, 26, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 48px 24px;
  text-align: center;
  max-width: 480px;
  margin: 48px auto;
  box-sizing: border-box;
}

@keyframes puzzleStudioReveal {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes puzzleFeedbackPop {
  from {
    opacity: 0;
    transform: scale(0.96);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes puzzleChipPop {
  from {
    opacity: 0;
    transform: translateY(4px) scale(0.92);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes puzzleFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes puzzleShakeX {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-5px); }
  40%, 80% { transform: translateX(5px); }
}

@keyframes pulseNextReady {
  0%, 100% { box-shadow: 0 4px 14px rgba(16, 185, 129, 0.35); }
  50% { box-shadow: 0 4px 22px rgba(16, 185, 129, 0.6); }
}

@keyframes pulseGold {
  0%, 100% { box-shadow: inset 0 0 0 3px #F59E0B; }
  50% { box-shadow: inset 0 0 0 6px #F59E0B, 0 0 12px rgba(245, 158, 11, 0.55); }
}

@keyframes pulseEmerald {
  0%, 100% { box-shadow: inset 0 0 0 3px #10B981; }
  50% { box-shadow: inset 0 0 0 6px #10B981, 0 0 12px rgba(16, 185, 129, 0.55); }
}

@keyframes pieceShake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-4px); }
  40%, 80% { transform: translateX(4px); }
}

/* ==========================================================================
   7. RESPONSIVE TABLET & MOBILE LAYOUT (<= 960px)
   ========================================================================== */
@media (max-width: 960px) {
  body:has(#view-puzzles.active) .main-viewport,
  body.puzzles-view-active .main-viewport {
    padding: calc(48px + env(safe-area-inset-top, 0px)) 0 calc(84px + env(safe-area-inset-bottom, 12px)) 0 !important;
  }

  #view-puzzles .puzzles-arena-viewport {
    padding: 0 !important;
    gap: 10px !important;
  }

  .puzzles-studio-grid {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
    width: 100% !important;
  }

  .puzzle-stage-col {
    gap: 8px !important;
  }

  .puzzle-stage-header {
    padding: 6px 12px !important;
  }

  .puzzle-stage-header .turn-title {
    font-size: 0.88rem !important;
  }

  #view-puzzles .puzzle-goal-tag {
    font-size: 0.8rem !important;
  }

  #view-puzzles #puzzle-board-container {
    width: min(100vw, calc(100dvh - 245px)) !important;
    height: min(100vw, calc(100dvh - 245px)) !important;
    min-width: 260px !important;
    min-height: 260px !important;
    max-width: 100vw !important;
    border-radius: 0 !important;
    margin: 0 auto !important;
    box-shadow: none !important;
  }

  .puzzle-studio-panel {
    margin: 0 auto !important;
    width: calc(100% - 20px) !important;
    max-width: 560px !important;
    padding: 14px !important;
    gap: 12px !important;
    border-radius: 14px !important;
  }

  /* Put Feedback, Hint/Retry/Solution, and Level Stepper immediately below the board above the fold on mobile */
  .puzzle-feedback-dock {
    order: 1 !important;
  }
  .puzzle-action-dock {
    order: 2 !important;
  }
  .puzzle-progress-section {
    order: 3 !important;
  }
  .puzzle-studio-head {
    order: 4 !important;
    gap: 8px !important;
  }
  .puzzle-kpi-row {
    order: 5 !important;
  }
  .puzzle-mission-meta {
    order: 6 !important;
  }
  .puzzle-themes-section {
    order: 7 !important;
  }
  .puzzle-history-section {
    order: 8 !important;
  }

  #view-puzzles .puzzle-mode-tab {
    padding: 6px 12px !important;
    min-height: 36px !important;
    font-size: 0.78rem !important;
  }

  #view-puzzles .puzzle-category-pill-btn {
    height: 36px !important;
    min-height: 36px !important;
    font-size: 0.76rem !important;
  }

  .puzzle-quick-themes-row {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
  }

  .puzzle-level-rail {
    grid-template-columns: repeat(5, 1fr) !important;
  }

  .puzzle-shortcuts-bar,
  .puzzle-key-badge {
    display: none !important;
  }
}

/* ==========================================================================
   8. LIGHT THEME SUPPORT
   ========================================================================== */
html.light-theme #view-puzzles .puzzle-stage-header .turn-title,
body.light-theme #view-puzzles .puzzle-stage-header .turn-title {
  color: #0F172A;
}

html.light-theme #view-puzzles .puzzle-stage-header .turn-dot.w,
body.light-theme #view-puzzles .puzzle-stage-header .turn-dot.w {
  background: #FFFFFF;
  border-color: #CBD5E1;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.15);
}

html.light-theme #view-puzzles .puzzle-goal-tag,
body.light-theme #view-puzzles .puzzle-goal-tag {
  color: #B45309;
}

html.light-theme #view-puzzles .puzzle-studio-panel,
body.light-theme #view-puzzles .puzzle-studio-panel {
  background: rgba(255, 255, 255, 0.94);
  border-color: rgba(15, 23, 42, 0.1);
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
}

html.light-theme #view-puzzles .puzzle-arena-mode-tabs,
body.light-theme #view-puzzles .puzzle-arena-mode-tabs {
  background: #F1F5F9;
  border-color: rgba(15, 23, 42, 0.08);
}

html.light-theme #view-puzzles .puzzle-mode-tab,
body.light-theme #view-puzzles .puzzle-mode-tab {
  color: #475569;
}

html.light-theme #view-puzzles .puzzle-kpi-row,
body.light-theme #view-puzzles .puzzle-kpi-row,
html.light-theme #view-puzzles .puzzle-history-moves,
body.light-theme #view-puzzles .puzzle-history-moves,
html.light-theme #view-puzzles .puzzle-compact-counter,
body.light-theme #view-puzzles .puzzle-compact-counter {
  background: #F8FAFC;
  border-color: rgba(15, 23, 42, 0.08);
}

html.light-theme #view-puzzles .puzzle-mission-meta .intel-theme,
body.light-theme #view-puzzles .puzzle-mission-meta .intel-theme,
html.light-theme #view-puzzles .counter-num,
body.light-theme #view-puzzles .counter-num {
  color: #0F172A;
}

html.light-theme #view-puzzles .puzzle-kpi-val,
body.light-theme #view-puzzles .puzzle-kpi-val {
  color: #0F172A;
}

html.light-theme #view-puzzles .puzzle-kpi-val.gold,
body.light-theme #view-puzzles .puzzle-kpi-val.gold {
  color: #B45309;
}

html.light-theme #view-puzzles .puzzle-status-bar.default,
body.light-theme #view-puzzles .puzzle-status-bar.default {
  background: #F1F5F9;
  border-color: rgba(15, 23, 42, 0.08);
  color: #334155;
}

html.light-theme #view-puzzles .puzzle-action-btn.btn-retry,
body.light-theme #view-puzzles .puzzle-action-btn.btn-retry,
html.light-theme #view-puzzles .puzzle-sub-btn,
body.light-theme #view-puzzles .puzzle-sub-btn,
html.light-theme #view-puzzles .puzzle-rail-btn,
body.light-theme #view-puzzles .puzzle-rail-btn,
html.light-theme #view-puzzles .puzzle-quick-theme-chip,
body.light-theme #view-puzzles .puzzle-quick-theme-chip,
html.light-theme #view-puzzles .puzzle-category-pill-btn,
body.light-theme #view-puzzles .puzzle-category-pill-btn {
  background: #F8FAFC;
  border-color: rgba(15, 23, 42, 0.12);
  color: #334155;
}

/* ==========================================================================
   9. ACCESSIBILITY: REDUCED MOTION
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  .puzzles-studio-grid,
  .puzzle-status-bar,
  .history-move-chip,
  .puzzle-action-btn.btn-next.pulse-ready,
  .square.puzzle-square-hint-origin,
  .square.puzzle-square-hint-dest,
  .piece.piece-error-shake,
  .puzzle-library-modal-backdrop,
  .puzzle-library-modal-box {
    animation: none !important;
    transition: none !important;
  }
}
