:root {
  /* Woodpecker Method palette: warm ink + walnut + cadmium orange */
  --ink: #0E0B08;
  --ink-2: #1A140E;
  --ink-3: #25201A;
  --paper: #E8DFCF;
  --walnut: #3A2D1F;
  --walnut-2: #5C4A37;
  --cadmium: #D4571E;
  --cadmium-dim: #A8421A;
  --cobalt: #1B4F8C;
  --cobalt-soft: #2A6BB0;
  --pale: #A89A87;
  --pale-2: #6F6453;
  --line: #2C241B;
  --line-2: #3D3328;
  --text: #E8DFCF;
  --text-dim: #8C8070;
  --success: #6FA85B;
  --danger: #C0392B;
}

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

html, body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--ink);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 20% 0%, rgba(212, 87, 30, 0.06), transparent),
    radial-gradient(ellipse 60% 40% at 80% 100%, rgba(27, 79, 140, 0.05), transparent);
  pointer-events: none;
  z-index: 0;
}

#app {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  padding-top: 72px;
  display: grid;
  grid-template-columns: 300px 1fr 380px;
  grid-template-rows: minmax(0, calc(100dvh - 72px));
  grid-template-areas:
    "sidebar board panel";
}

/* ---------- HEADER ---------- */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  min-height: 72px;
  background: var(--ink-2);
  border-bottom: 1px solid var(--line);
}
.app-header .header-logo {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  margin-right: 12px;
  text-decoration: none;
  border-radius: 6px;
  transition: opacity 0.15s;
}
.app-header .header-logo:hover { opacity: 0.75; }
.app-header .header-logo img {
  display: block;
  height: 38px;
  width: auto;
}
.app-header .hamburger {
  display: none;
  background: transparent;
  border: 1px solid var(--line-2);
  border-radius: 4px;
  width: 36px;
  height: 36px;
  cursor: pointer;
  padding: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: border-color 0.15s;
}
.app-header .hamburger[hidden] { display: none; }
.app-header .hamburger:hover { border-color: var(--cadmium); }
.app-header .hamburger span {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--paper);
  border-radius: 1px;
  transition: transform 0.2s, opacity 0.2s;
}
.app-header .hamburger.open span:nth-child(1) {
  transform: translateY(6px) rotate(45deg);
}
.app-header .hamburger.open span:nth-child(2) { opacity: 0; }
.app-header .hamburger.open span:nth-child(3) {
  transform: translateY(-6px) rotate(-45deg);
}
.app-header .mobile-title {
  display: none;
  flex: 1;
  text-align: center;
  font-family: system-ui, sans-serif;
  font-style: italic;
  font-size: 0.95rem;
  color: var(--paper);
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 10px;
}
.app-header .brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.app-header .brand h1 {
  font-family: system-ui, sans-serif;
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--paper);
}
.app-header .brand h1 .accent {
  color: var(--cadmium);
  font-style: italic;
}
.app-header .brand .crumbs {
  font-family: system-ui, sans-serif;
  font-style: italic;
  font-size: 0.95rem;
  color: var(--text-dim);
}
.app-header .actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.app-header .actions button {
  background: transparent;
  border: 1px solid transparent;
  color: var(--pale);
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 0.85rem;
  min-height: 36px;
  transition: all 0.15s;
}
.app-header .actions button:hover {
  color: var(--paper);
  border-color: var(--line-2);
}
.app-header .avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid var(--walnut-2);
}

/* ---------- SIDEBAR (lista de ejercicios) ---------- */
.sidebar {
  grid-area: sidebar;
  background: var(--ink-2);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 4;
}
.sidebar-backdrop.open { display: block; }
.sidebar .sidebar-head {
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--ink-2);
  z-index: 2;
}
.sidebar .sidebar-head h2 {
  font-family: system-ui, sans-serif;
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--paper);
  letter-spacing: 0.01em;
}
.sidebar .sidebar-head .meta {
  font-size: 0.72rem;
  color: var(--pale-2);
  margin-top: 2px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.exercise-list {
  list-style: none;
  padding: 4px 0;
  flex: 1;
}
.exercise-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 18px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--pale);
  border-left: 2px solid transparent;
  transition: all 0.1s;
}
.exercise-list li:hover {
  background: var(--ink-3);
  color: var(--paper);
}
.exercise-list li.active {
  background: var(--ink-3);
  border-left-color: var(--cadmium);
  color: var(--paper);
}
.exercise-list li.resolved {
  color: var(--success);
}
.exercise-list li .num {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.78rem;
  color: var(--cobalt-soft);
  min-width: 22px;
  text-align: right;
}
.exercise-list li.active .num { color: var(--cadmium); }
.exercise-list li .title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.exercise-list li .star {
  font-size: 0.7rem;
  color: var(--pale-2);
  letter-spacing: 2px;
}
.exercise-list li.resolved .star { color: var(--success); }

/* ---------- BOARD (centro) ---------- */
.board-area {
  grid-area: board;
  display: flex;
  flex-direction: column;
  background: var(--ink);
  overflow: hidden;
  position: relative;
  min-height: 0;
}
.board-stage {
  flex: 1 1 auto;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow: hidden;
  min-height: 0;
}
.board-frame {
  display: grid;
  grid-template-rows: auto auto auto auto;
  gap: 6px;
  width: var(--board-size, 100%);
  max-width: 100%;
}
.board-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 4px 6px 8px;
}
.board-title .ex-num {
  font-family: system-ui, sans-serif;
  font-weight: 600;
  font-size: 2.1rem;
  color: var(--paper);
  line-height: 1;
}
.board-title .ex-num .accent {
  color: var(--cadmium);
}
.board-title .ex-meta {
  font-family: system-ui, sans-serif;
  font-style: italic;
  font-size: 0.95rem;
  color: var(--pale);
}
.board-title .material {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  color: var(--pale);
  display: flex;
  align-items: center;
  gap: 4px;
}

.board-container {
  width: 100%;
  aspect-ratio: 1 / 1;
  position: relative;
  background: var(--ink-2);
  border-radius: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  min-height: 0;
}

#board.cg-wrap {
  width: 100%;
  height: 100%;
}

/* Temas del tablero: cambiamos solo el color de fondo del cg-board
   con un damero CSS (linear-gradient repeating). Como chessground
   versión 10 usa un SVG interno superpuesto con sus propios
   colores, estos temas se aplican ANTES (background-image) y los
   highlights (square.move-dest, square.selected, etc.) se renderizan
   encima por z-index natural. */
#board.theme-blue cg-board {
  background: repeating-conic-gradient(#dee3e6 0% 25%, #487eb8 0% 50%);
  background-size: 25% 25% !important;
}
#board.theme-green cg-board {
  background: repeating-conic-gradient(#eef0d4 0% 25%, #86a666 0% 50%);
  background-size: 25% 25% !important;
}
#board.theme-grey cg-board {
  background: repeating-conic-gradient(#e8e8e8 0% 25%, #6e6e6e 0% 50%);
  background-size: 25% 25% !important;
}
/* Brown: usar el asset oficial de chessground (no override aquí) */

.board-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 6px 4px;
}
.board-footer .level-tag {
  font-family: system-ui, sans-serif;
  font-style: italic;
  color: var(--pale);
  font-size: 1.05rem;
}
.board-footer .nav-btns {
  display: flex;
  gap: 6px;
}
.board-footer .nav-btn {
  background: transparent;
  border: 1px solid var(--line-2);
  color: var(--pale);
  width: 36px;
  height: 36px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.15s;
}
.board-footer .nav-btn:hover {
  border-color: var(--cadmium);
  color: var(--cadmium);
}

.solution-bar {
  display: none;
}
.solution-bar button {
  background: transparent;
  border: 1px solid var(--line-2);
  color: var(--pale);
  padding: 8px 18px;
  border-radius: 4px;
  cursor: pointer;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 0.82rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.15s;
}
.solution-bar button:hover {
  border-color: var(--cadmium);
  color: var(--cadmium);
}
.solution-bar button .play-icon {
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 7px solid currentColor;
}

/* Solution panel */
.solution-panel {
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 14px 16px;
  margin: 6px 6px 0;
  font-size: 0.85rem;
}
.solution-panel.hidden { display: none; }
.solution-panel .solution-moves {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.92rem;
  color: var(--paper);
  line-height: 1.6;
  margin-bottom: 8px;
  word-break: break-word;
}
.solution-panel .solution-comment {
  font-family: system-ui, sans-serif;
  font-style: italic;
  color: var(--pale);
  font-size: 0.95rem;
  line-height: 1.5;
}

/* Final card (después del último movimiento del oponente) */
.wp-correct-banner { display: block; }
.wp-correct-banner.hidden { display: none; }
.wp-final-card {
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin: 14px 0 0;
  padding: 14px 16px;
  background: var(--ink-2);
  border-radius: 6px;
}
.wp-final-head {
  display: flex;
  align-items: center;
  gap: 12px;
}
.wp-final-check {
  font-family: system-ui, sans-serif;
  font-size: 2rem;
  line-height: 1;
  color: var(--success);
  width: 36px;
  height: 36px;
  border: 2px solid var(--success);
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.wp-final-status {
  font-family: system-ui, sans-serif;
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
  color: var(--success);
  flex: 1;
}
.wp-final-bubble {
  position: relative;
  background: var(--ink-3);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px 16px;
  font-family: system-ui, sans-serif;
  font-style: italic;
  font-size: 1.05rem;
  line-height: 1.45;
  color: var(--paper);
  min-height: 0;
  width: 100%;
}
.wp-final-message { white-space: pre-wrap; }
.wp-final-cta {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}
.wp-final-btn {
  background: transparent;
  border: 1px solid var(--line-2);
  color: var(--pale);
  padding: 11px 16px;
  border-radius: 4px;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 10px;
  letter-spacing: 0.04em;
  transition: all 0.15s;
  text-align: center;
}
.wp-final-btn:hover {
  border-color: var(--cadmium);
  color: var(--cadmium);
}
.wp-final-btn .wp-final-icon {
  font-size: 1.1rem;
  line-height: 1;
}
.wp-final-btn-primary {
  background: var(--cadmium);
  border-color: var(--cadmium);
  color: var(--ink);
}
.wp-final-btn-primary:hover {
  background: var(--cadmium-dim);
  border-color: var(--cadmium-dim);
  color: var(--ink);
}

/* Mascota (pájaro carpintero) — opcional, suaviza visualmente el cierre */
.wp-final-mascot {
  position: fixed;
  bottom: 28px;
  right: 24px;
  width: 84px;
  height: 84px;
  opacity: 0.85;
  pointer-events: none;
  z-index: 10;
}
.wp-final-mascot svg { width: 100%; height: 100%; display: block; }

/* Banner-note modo análisis */
.wp-final-banner-note {
  margin: 10px 6px 0;
  padding: 10px 14px;
  background: rgba(27, 79, 140, 0.12);
  border: 1px dashed var(--cobalt-soft);
  border-radius: 4px;
  font-size: 0.85rem;
  color: var(--pale);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.wp-final-banner-note button {
  background: transparent;
  border: 1px solid var(--cobalt-soft);
  color: var(--cobalt-soft);
  padding: 6px 12px;
  border-radius: 4px;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 0.8rem;
  cursor: pointer;
}
.wp-final-banner-note button:hover {
  background: var(--cobalt-soft);
  color: var(--ink);
}

/* ---------- GAME PANEL (derecha) ---------- */
.game-panel {
  grid-area: panel;
  background: var(--ink-2);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 20px 24px;
  overflow-y: auto;
  min-height: 0;
}
.game-panel .game-title {
  font-family: system-ui, sans-serif;
  font-weight: 600;
  font-size: 1.15rem;
  color: var(--paper);
  line-height: 1.3;
  margin-bottom: 4px;
}
.game-panel .game-year {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.78rem;
  color: var(--pale-2);
  letter-spacing: 0.06em;
  margin-bottom: 22px;
}

.game-panel .prompt {
  position: relative;
  background: var(--ink-3);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px 16px;
  margin-bottom: 18px;
}
.game-panel .prompt::after {
  content: '';
  position: absolute;
  bottom: -7px;
  right: 32px;
  width: 12px;
  height: 12px;
  background: var(--ink-3);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  transform: rotate(45deg);
}
.game-panel .prompt .turn-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: system-ui, sans-serif;
  font-size: 1.2rem;
  font-weight: 600;
  font-style: italic;
  color: var(--cadmium);
  margin-bottom: 4px;
}
.game-panel .prompt .turn-label svg {
  width: 22px;
  height: 22px;
}
.game-panel .prompt .turn-hint {
  font-size: 0.82rem;
  color: var(--pale);
  line-height: 1.45;
}

.game-panel .hint-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
.game-panel .hint-btn {
  background: transparent;
  border: 1px dashed var(--cobalt-soft);
  color: var(--cobalt-soft);
  padding: 7px 14px;
  border-radius: 4px;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.15s;
}
.game-panel .hint-btn:hover {
  border-style: solid;
  background: rgba(42, 107, 176, 0.08);
}

.timer-readout {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.05rem;
  color: var(--pale);
}
.timer-readout .clock {
  color: var(--paper);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* ---------- HOME / STATS / SETTINGS ---------- */
.home-view, .stats-view, .settings-view, .list-view {
  grid-column: 1 / -1;
  padding: 40px 20px;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
  overflow-y: auto;
}
.home-view .brand-block {
  text-align: center;
  margin-bottom: 40px;
}
.home-view .brand-block .brand-logo {
  display: block;
  width: 140px;
  height: auto;
  margin: 0 auto 18px;
}
.home-view .brand-block h1 {
  font-family: system-ui, sans-serif;
  font-weight: 600;
  font-size: 3.4rem;
  letter-spacing: 0.01em;
  color: var(--paper);
  line-height: 1;
}
.home-view .brand-block h1 .accent {
  color: var(--cadmium);
  font-style: italic;
}
.home-view .brand-block .tagline {
  font-family: system-ui, sans-serif;
  font-style: italic;
  color: var(--pale);
  font-size: 1.15rem;
  margin-top: 10px;
}

.level-card {
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 22px 26px;
  margin-bottom: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.cycle-card {
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--cadmium);
  border-radius: 6px;
  padding: 18px 22px;
  margin-bottom: 18px;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto auto;
  column-gap: 18px;
  align-items: center;
}
.cycle-card .cycle-label {
  grid-column: 1;
  grid-row: 1;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--pale-2);
}
.cycle-card .cycle-number {
  grid-column: 2;
  grid-row: 1 / span 2;
  font-family: system-ui, sans-serif;
  font-size: 3.4rem;
  font-weight: 600;
  line-height: 1;
  color: var(--cadmium);
}
.cycle-card .cycle-meta {
  grid-column: 1;
  grid-row: 2;
  font-family: system-ui, sans-serif;
  font-style: italic;
  font-size: 0.95rem;
  color: var(--pale);
}
.cycle-card .cycle-action {
  grid-column: 1 / -1;
  grid-row: 3;
  margin-top: 12px;
  background: transparent;
  border: 1px solid var(--cadmium);
  color: var(--cadmium);
  padding: 9px 14px;
  border-radius: 4px;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  justify-self: start;
}
.cycle-card .cycle-action:hover {
  background: var(--cadmium);
  color: var(--ink);
}
.level-card:hover {
  border-color: var(--cadmium);
  background: var(--ink-3);
}
.level-card h2 {
  font-family: system-ui, sans-serif;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--paper);
  margin-bottom: 4px;
}
.level-card .level-meta {
  font-size: 0.85rem;
  color: var(--pale-2);
  margin-bottom: 14px;
  letter-spacing: 0.04em;
}
.level-card .progress-bar {
  height: 3px;
  background: var(--line);
  border-radius: 2px;
  overflow: hidden;
}
.level-card .progress-fill {
  height: 100%;
  background: var(--cadmium);
  transition: width 0.4s;
}

.home-view .instructions {
  margin-top: 32px;
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 20px;
  text-align: left;
  color: var(--pale);
  font-family: system-ui, sans-serif;
  font-size: 0.95rem;
  line-height: 1.55;
}
.home-view .instructions summary {
  cursor: pointer;
  padding: 14px 0;
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--paper);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
.home-view .instructions summary::before {
  content: "▸";
  display: inline-block;
  transition: transform 0.15s;
  color: var(--cadmium);
}
.home-view .instructions[open] summary::before { transform: rotate(90deg); }
.home-view .instructions summary::-webkit-details-marker { display: none; }
.home-view .instructions ol {
  margin: 0 0 16px 0;
  padding-left: 22px;
}
.home-view .instructions ol li { margin-bottom: 8px; }
.home-view .instructions strong { color: var(--paper); font-weight: 600; }
.home-view .instructions kbd {
  display: inline-block;
  padding: 1px 6px;
  background: var(--ink-3);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.82em;
  color: var(--paper);
}

.list-view .list-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 24px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.list-view h1 {
  font-family: system-ui, sans-serif;
  font-size: 2.2rem;
  font-weight: 600;
  color: var(--paper);
}
.list-view .grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
}
.list-view .cell {
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 14px 10px;
  text-align: center;
  cursor: pointer;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  color: var(--pale);
  transition: all 0.1s;
}
.list-view .cell:hover {
  border-color: var(--cadmium);
  color: var(--cadmium);
}
.list-view .cell.resolved {
  background: rgba(111, 168, 91, 0.08);
  border-color: var(--success);
  color: var(--success);
}
.list-view .cell.current {
  border-color: var(--cadmium);
  color: var(--cadmium);
}

/* Settings */
.settings-view h1 {
  font-family: system-ui, sans-serif;
  font-size: 2rem;
  font-weight: 600;
  color: var(--paper);
  margin-bottom: 20px;
}
.settings-view .settings-group {
  margin-bottom: 22px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
}
.settings-view .settings-group h3 {
  font-family: system-ui, sans-serif;
  font-style: italic;
  color: var(--pale);
  font-size: 1.05rem;
  margin-bottom: 14px;
}
.settings-view .setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  font-size: 0.92rem;
}
.toggle {
  position: relative;
  width: 44px;
  height: 24px;
  background: var(--line-2);
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.3s;
}
.toggle.active { background: var(--cadmium); }
.toggle::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  background: var(--paper);
  border-radius: 50%;
  transition: transform 0.3s;
}
.toggle.active::after { transform: translateX(20px); }

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

/* Tablet horizontal / pantallas medianas: 900-1199px
   Reduce el ancho del sidebar y del panel, y deja el tablero en su tamaño natural. */
@media (max-width: 1199px) {
  #app {
    grid-template-columns: 240px 1fr 320px;
  }
  .game-panel { padding: 18px 16px; }
}

/* Tablet vertical / pantallas pequeñas: 700-899px
   Sidebar colapsa a una barra superior horizontal con scroll, panel debajo del tablero. */
@media (max-width: 899px) {
  #app {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    padding-top: 56px;
  }
  .app-header {
    min-height: 56px;
    padding: 8px 12px;
  }
  .app-header .hamburger { display: flex; }
  .app-header .brand { display: none; }
  .app-header .mobile-title { display: block; }
  .app-header .actions button { padding: 6px 8px; font-size: 0.78rem; min-height: 32px; }
  .app-header .actions button span:not(.icon) { display: none; }
  .sidebar {
    position: fixed;
    top: 56px;
    left: 0;
    bottom: 0;
    width: min(320px, 86vw);
    z-index: 25;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    border-right: 1px solid var(--line);
    border-bottom: none;
    max-height: none;
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar .sidebar-head {
    position: relative;
    padding: 8px 16px;
  }
  .board-area {
    flex: 0 0 auto;
    overflow: visible;
  }
  .board-title,
  .board-footer,
  .solution-bar { display: none !important; }
  .board-frame {
    grid-template-rows: auto;
    gap: 0;
  }
  .board-container { padding: 8px; }
  .board-stage { padding: 6px 4px; }
  .game-panel {
    flex: 0 0 auto;
    border-left: none;
    border-top: 1px solid var(--line);
    max-height: none;
    overflow: visible;
  }
}

/* Móvil vertical / pantallas pequeñas: <700px
   Compacta más el header, la sidebar queda como una tira con scroll,
   el tablero ocupa el ancho disponible, el panel se sitúa debajo. */
@media (max-width: 700px) {
  body::before { display: none; }
  .sidebar { width: min(300px, 88vw); }
  .sidebar .sidebar-head h2 { font-size: 0.95rem; }
  .game-panel { padding: 12px 14px; }
  .game-panel .game-title { font-size: 1rem; }
  .game-panel .game-year { font-size: 0.72rem; margin-bottom: 12px; }
  .game-panel .prompt { padding: 10px 12px; margin-bottom: 12px; }
  .game-panel .prompt .turn-label { font-size: 1.05rem; }
  .game-panel .hint-row { margin-bottom: 12px; }
  .home-view .brand-block h1 { font-size: 2.2rem; }
  .home-view .level-card h2 { font-size: 1.2rem; }
  .stats-view, .settings-view, .list-view { padding: 24px 14px; }
  .stats-view .stat-value { font-size: 1.8rem; }
  .board-container { padding: 6px; }
  .board-stage { padding: 4px 2px; }
  .wp-final-card { padding: 12px 14px; gap: 12px; }
  .wp-final-status { font-size: 1rem; }
}

/* Móvil muy pequeño: <480px */
@media (max-width: 480px) {
  .app-header .actions button { padding: 6px 6px; }
  .app-header .mobile-title { font-size: 0.85rem; }
  .settings-view .settings-group { padding: 14px; }
  .stats-view .stat-grid { grid-template-columns: 1fr; }
}

/* Hidden utility */
.hidden { display: none !important; }

/* ============================================================
   Loading screen — minimalist
   ============================================================ */

@keyframes wp-mark-pulse {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 0 rgba(212, 87, 30, 0)); }
  50% { transform: scale(1.04); filter: drop-shadow(0 4px 18px rgba(212, 87, 30, 0.35)); }
}

@keyframes wp-pulse-dot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.6); opacity: 0.45; }
}

.app-loading {
  position: fixed;
  inset: 0;
  background: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 50;
  overflow: hidden;
  padding: 24px;
}

.app-loading::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 45% at 50% 42%, rgba(212, 87, 30, 0.18), transparent 70%);
  pointer-events: none;
  z-index: 0;
}

.app-loading .loading-mark {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  margin-bottom: 28px;
}

.app-loading .loading-mark img {
  width: 84px;
  height: auto;
  display: block;
  animation: wp-mark-pulse 2.4s ease-in-out infinite;
}

.app-loading .loading-brand {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-family: system-ui, sans-serif;
  font-weight: 600;
  font-size: 1.6rem;
  letter-spacing: 0.02em;
  text-align: center;
}

.app-loading .loading-brand-name {
  color: var(--cadmium);
  font-style: italic;
}

.app-loading .loading-brand-sub {
  color: var(--paper);
}

.app-loading .loading-tagline {
  position: relative;
  z-index: 1;
  margin-top: 6px;
  font-family: system-ui, sans-serif;
  font-style: italic;
  font-size: 0.9rem;
  color: var(--pale);
  letter-spacing: 0.04em;
  text-align: center;
}

.app-loading .loading-progress {
  position: relative;
  z-index: 1;
  width: min(220px, 60vw);
  height: 1px;
  background: var(--line);
  border-radius: 1px;
  overflow: hidden;
  margin-top: 36px;
}

.app-loading .loading-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--cadmium);
  transition: width 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
  box-shadow: 0 0 8px rgba(212, 87, 30, 0.55);
}

.app-loading .loading-foot {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--pale-2);
  margin-top: 14px;
}

.app-loading .loading-foot-pulse {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cadmium);
  animation: wp-pulse-dot 1.4s ease-in-out infinite;
}

.app-loading .loading-foot-count {
  font-variant-numeric: tabular-nums;
  color: var(--pale);
  letter-spacing: 0.1em;
}

.app-loading .loading-foot-sep {
  color: var(--pale-2);
  margin: 0 3px;
}

.app-loading.app-loading-error {
  display: grid;
  place-items: center;
  text-align: center;
  padding: 24px;
}

.app-loading.app-loading-error .loading-error-mark {
  width: 56px;
  height: 56px;
  border: 2px solid var(--danger);
  border-radius: 50%;
  color: var(--danger);
  display: grid;
  place-items: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.4rem;
  font-weight: 600;
  margin-bottom: 18px;
}

.app-loading.app-loading-error .loading-error-title {
  font-family: system-ui, sans-serif;
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--paper);
  margin-bottom: 6px;
}

.app-loading.app-loading-error .loading-error-hint {
  color: var(--pale);
  font-size: 0.92rem;
  margin-bottom: 22px;
}

.app-loading.app-loading-error .loading-error-retry {
  background: var(--cadmium);
  color: var(--ink);
  border: none;
  padding: 10px 22px;
  border-radius: 4px;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-weight: 600;
  font-size: 0.88rem;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background 0.15s;
}
.app-loading.app-loading-error .loading-error-retry:hover {
  background: var(--cadmium-dim);
}

@media (max-width: 700px) {
  .app-loading .loading-mark img { width: 64px; }
  .app-loading .loading-brand { font-size: 1.3rem; }
  .app-loading .loading-tagline { font-size: 0.82rem; }
  .app-loading .loading-foot { font-size: 0.62rem; letter-spacing: 0.14em; }
}

/* ============================================================
   Sticky header — backdrop blur + scroll shadow
   ============================================================ */

.app-header.is-scrolled {
  background: rgba(26, 20, 14, 0.78);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  box-shadow:
    0 1px 0 0 var(--line),
    0 6px 18px -8px rgba(0, 0, 0, 0.6);
  border-bottom-color: transparent;
}

@media (max-width: 899px) {
  .app-header.is-scrolled {
    background: rgba(26, 20, 14, 0.86);
  }
}

@supports not (backdrop-filter: blur(1px)) {
  .app-header.is-scrolled {
    background: rgba(14, 11, 8, 0.96);
  }
}

.history-controls {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.history-btn {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  border: 1px solid var(--line-2);
  background: var(--ink-2);
  color: var(--paper);
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
  font-family: 'JetBrains Mono', monospace;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.history-btn:hover:not(.is-disabled) {
  border-color: var(--cadmium);
  color: var(--cadmium);
}

.history-btn.is-disabled {
  opacity: 0.35;
  pointer-events: none;
}

.wp-final-history {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 14px 0 8px;
}

.wp-final-history .history-btn {
  width: 42px;
  height: 42px;
}

.board-history {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 10px 0 6px;
  min-height: 44px;
  align-items: center;
}

.board-history.hidden {
  display: none;
}
