:root {
  --tangerine: #FF482A;
  --tangerine-600: #ED3315;
  --tangerine-300: #FFAB9D;
  --tangerine-50: #FFF3F1;
  --midnight: #0B020A;
  --eggshell: #FAFAFA;

  --g-50:  #FAFAFA;
  --g-100: #F5F5F5;
  --g-200: #E5E5E5;
  --g-300: #D4D4D4;
  --g-400: #A1A1A1;
  --g-500: #737373;
  --g-600: #525252;
  --g-700: #404040;
  --g-800: #262626;
  --g-900: #171717;
  --g-950: #0A0A0A;

  --info: #615FFF;
  --warn: #F59E0B;
  --error: #FB2C36;
  --success: #00BC7D;

  --board-light: #f0d9b5;
  --board-dark:  #b58863;
  --board-hl-from: rgba(255,72,42,0.35);
  --board-hl-to:   rgba(255,72,42,0.55);
  --board-hl-legal: rgba(0, 188, 125, 0.55);
  --board-hl-check: rgba(251, 44, 54, 0.65);

  --serif: 'Sansation', 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --sans:  'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--midnight);
  color: var(--eggshell);
  font-family: var(--sans);
  font-weight: 400;
  overflow-x: hidden;
}

body {
  display: flex; flex-direction: column;
  min-height: 100vh;
}

/* ===================================================================
 *  MOBILE-FIRST RESPONSIVE STRATEGY
 *  Defaults below = mobile layout. Tablet/desktop kicks in via
 *  @media (min-width: 769px) and (min-width: 1101px) at the bottom.
 *  This guarantees mobile rendering on any device that hits the page
 *  narrow, regardless of viewport-quirks (iOS Safari in particular).
 * =================================================================== */

/* --- Header --- */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  gap: 8px;
  border-bottom: 1px solid #1a0e15;
  background: linear-gradient(180deg, #160409 0%, #0B020A 100%);
}
.brand { display:flex; align-items:center; gap:10px; min-width: 0; flex: 1 1 auto; }
.brand-text { min-width: 0; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px;
  display: grid; place-items: center;
  background: var(--tangerine); color: white;
  font-family: var(--serif); font-weight: 700; font-size: 14px;
  box-shadow: 0 4px 12px rgba(255,72,42,0.4);
  flex-shrink: 0;
}
.brand-text h1 {
  margin: 0; font-family: var(--serif); font-weight: 700;
  font-size: 15px; letter-spacing: 0.2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand-tag {
  display: none; /* hidden on mobile; revealed on tablet+ */
  margin: 2px 0 0; font-size: 11px; color: var(--g-400);
  text-transform: uppercase; letter-spacing: 1px;
}
.mode-switch {
  display: inline-flex; gap: 2px; flex-shrink: 0;
  background: #1a0e15; padding: 3px; border-radius: 10px;
}
.mode-btn {
  -webkit-appearance: none; appearance: none; border: 0; cursor: pointer;
  padding: 6px 12px; border-radius: 7px;
  background: transparent; color: var(--g-300);
  font-family: var(--sans); font-weight: 500; font-size: 12px;
  transition: all .15s ease;
}
.mode-btn:hover { color: var(--eggshell); }
.mode-btn.is-active {
  background: var(--tangerine); color: white;
  box-shadow: 0 2px 8px rgba(255,72,42,0.3);
}

/* --- Main layout: MOBILE DEFAULT — stacked block layout --- */
.app {
  flex: 1; display: block;
  min-height: calc(100vh - 110px);
}
.sidebar {
  background: #100509;
  border-right: 1px solid #1a0e15;
  /* Mobile default: drawer mode (off-canvas) */
  position: fixed;
  top: 0; left: 0;
  width: 85vw; max-width: 320px;
  height: 100vh;
  z-index: 100;
  transform: translateX(-100%);
  transition: transform .25s ease;
  box-shadow: 4px 0 20px rgba(0,0,0,.4);
  padding: 18px 14px;
  overflow-y: auto;
}
.drawer-open .sidebar { transform: translateX(0); }
.filter-row { display: flex; gap: 6px; margin-bottom: 14px; }
.chip {
  appearance:none; border: 1px solid #2a1620; cursor: pointer;
  background: transparent; color: var(--g-400);
  padding: 5px 12px; border-radius: 999px;
  font-family: var(--sans); font-size: 11px; font-weight: 500;
  letter-spacing: .5px; text-transform: uppercase;
  transition: all .15s ease;
}
.chip:hover { color: var(--eggshell); border-color: var(--tangerine); }
.chip.is-active {
  background: var(--tangerine); color: white; border-color: var(--tangerine);
}

.opening-list { list-style: none; padding: 0; margin: 0; }
.opening-item {
  padding: 12px 12px; border-radius: 8px; cursor: pointer;
  margin-bottom: 4px; border: 1px solid transparent;
  transition: all .15s ease;
}
.opening-item:hover { background: #1a0e15; border-color: #2a1620; }
.opening-item.is-active {
  background: rgba(255,72,42,0.12);
  border-color: rgba(255,72,42,0.4);
}
.opening-item .o-name {
  font-family: var(--serif); font-weight: 700; font-size: 14px;
  color: var(--eggshell);
}
.opening-item .o-meta {
  margin-top: 3px;
  display: flex; gap: 8px; align-items: center;
  font-size: 11px; color: var(--g-400);
}
.opening-item .o-vs {
  margin-top: 5px;
  font-family: 'Geist Mono', Consolas, monospace;
  font-size: 10px;
  color: var(--tangerine-300);
  letter-spacing: .2px;
}
.side-badge {
  display:inline-block; width: 10px; height: 10px; border-radius: 50%;
  border: 1px solid var(--g-500);
}
.side-badge.white { background: var(--eggshell); }
.side-badge.black { background: #111; }
.side-badge.both { background: linear-gradient(90deg, var(--eggshell) 50%, #111 50%); }

/* --- Stage: MOBILE DEFAULT — single column stack --- */
.stage {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 14px;
  min-height: 0;
}
.board-wrap { display: flex; flex-direction: column; gap: 12px; }
.board-chrome {
  background: #160409;
  border-radius: 14px;
  padding: 12px;
  border: 1px solid #2a1620;
}
.player-strip {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 8px;
  font-size: 12px; color: var(--g-400);
  font-family: var(--sans);
}
.player-name { font-weight: 500; }
.player-eval { font-family: 'Geist Mono', Consolas, monospace; color: var(--tangerine-300); }

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  aspect-ratio: 1 / 1;
  width: 100%;
  border-radius: 6px;
  overflow: hidden;
  user-select: none;
  position: relative;
  box-shadow: 0 6px 24px rgba(0,0,0,.5);
}
.sq {
  position: relative;
  display: grid; place-items: center;
  cursor: pointer;
}
.sq.light { background: var(--board-light); }
.sq.dark  { background: var(--board-dark); }
.sq.hl-from { box-shadow: inset 0 0 0 9999px var(--board-hl-from); }
.sq.hl-to   { box-shadow: inset 0 0 0 9999px var(--board-hl-to); }
.sq.hl-check { box-shadow: inset 0 0 0 9999px var(--board-hl-check); }
.sq.selected { box-shadow: inset 0 0 0 3px var(--tangerine); }
.sq .dot {
  position: absolute;
  width: 26%; height: 26%; border-radius: 50%;
  background: var(--board-hl-legal);
  pointer-events: none;
}
.sq .ring {
  position: absolute;
  inset: 4%;
  border-radius: 50%;
  border: 5px solid var(--board-hl-legal);
  pointer-events: none;
}
.sq .coord {
  position: absolute;
  font-family: var(--sans); font-size: 10px; font-weight: 600;
  opacity: .7;
  pointer-events: none;
}
.sq .coord.file { right: 4px; bottom: 2px; }
.sq .coord.rank { left: 4px; top: 2px; }
.sq.light .coord { color: #8a6a3a; }
.sq.dark .coord  { color: #f0d9b5; }

.piece {
  width: 88%; height: 88%;
  pointer-events: none;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.4));
}
.piece.dragging { opacity: .35; }

.board-controls {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 2px;
}
.board-controls button {
  appearance: none; border: 1px solid #2a1620; cursor: pointer;
  background: #160409; color: var(--g-200);
  padding: 8px 12px; border-radius: 8px;
  font-family: var(--sans); font-size: 12px; font-weight: 500;
  transition: all .15s ease;
}
.board-controls button:hover {
  background: rgba(255,72,42,0.15);
  border-color: var(--tangerine);
  color: var(--eggshell);
}
.board-controls .grow { flex: 1; }
.side-pick {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px;
  background: #1a0e15; border-radius: 8px;
}
.side-pick-label {
  font-size: 11px; color: var(--g-400);
  text-transform: uppercase; letter-spacing: .5px;
  padding: 0 6px;
}
.side-btn {
  appearance: none; border: 0; cursor: pointer;
  padding: 6px 12px; border-radius: 6px;
  background: transparent; color: var(--g-300);
  font-family: var(--sans); font-size: 12px; font-weight: 500;
}
.side-btn:hover { color: var(--eggshell); }
.side-btn.is-active {
  background: var(--tangerine); color: white;
}

/* --- Info column --- */
.info {
  display: flex; flex-direction: column; gap: 14px;
  min-height: 0;
}
.info-head {
  background: #160409; border-radius: 12px; padding: 18px;
  border: 1px solid #2a1620;
}
.info-head h2 {
  margin: 0; font-family: var(--serif); font-weight: 700; font-size: 22px;
}
.title-row {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap;
}
.responds-badge {
  font-family: 'Geist Mono', Consolas, monospace;
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 4px;
  background: rgba(255,72,42,.12);
  color: var(--tangerine);
  border: 1px solid rgba(255,72,42,.35);
  white-space: nowrap;
}
.responds-badge[hidden] { display: none; }
.info-head .muted { margin: 8px 0 0; font-size: 13px; line-height: 1.5; color: var(--g-300); }
.theme-row { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.theme-tag {
  font-size: 10px; padding: 3px 9px; border-radius: 999px;
  background: rgba(97,95,255,.15); color: #C6D2FF;
  text-transform: uppercase; letter-spacing: .5px; font-weight: 500;
}

/* --- Collapsible enrichment sections (history, master notes) --- */
.enrich {
  margin-top: 12px;
  border: 1px solid #2a1620;
  border-radius: 8px;
  background: #0d0307;
  overflow: hidden;
}
.enrich[hidden] { display: none !important; }
.enrich summary {
  cursor: pointer;
  padding: 10px 14px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .8px;
  font-weight: 600;
  color: var(--g-300);
  list-style: none;
  display: flex; align-items: center; gap: 8px;
  user-select: none;
  transition: background .12s ease;
}
.enrich summary::-webkit-details-marker { display: none; }
.enrich summary:hover { background: rgba(255,72,42,.08); color: var(--eggshell); }
.enrich summary::before {
  content: '▶';
  font-size: 9px;
  color: var(--tangerine);
  transition: transform .18s ease;
}
.enrich[open] summary::before { transform: rotate(90deg); }
.enrich summary .count {
  margin-left: auto;
  font-size: 10px;
  color: var(--g-500);
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
}
.enrich .body {
  padding: 4px 14px 14px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--g-200);
}
.enrich h4 {
  margin: 12px 0 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--tangerine-300);
  text-transform: uppercase;
  letter-spacing: .5px;
}
.enrich h4:first-child { margin-top: 4px; }
.enrich .history-text {
  margin: 4px 0;
  color: var(--g-200);
}
.enrich .practitioner-list {
  list-style: none;
  padding: 0; margin: 0;
  display: flex; flex-direction: column; gap: 8px;
}
.enrich .practitioner-list li {
  padding: 8px 10px;
  background: #160409;
  border-left: 2px solid var(--tangerine);
  border-radius: 0 4px 4px 0;
  font-size: 12px;
  line-height: 1.5;
}
.enrich .practitioner-list .name {
  font-weight: 600;
  color: var(--eggshell);
}
.enrich .practitioner-list .name .years {
  color: var(--g-500);
  font-weight: 400;
  margin-left: 4px;
}
.enrich .game-list {
  display: flex; flex-direction: column; gap: 8px;
}
.enrich .game-card {
  display: block;
  padding: 10px 12px;
  background: #160409;
  border: 1px solid #2a1620;
  border-radius: 6px;
  text-decoration: none;
  color: inherit;
  transition: all .12s ease;
}
.enrich .game-card:hover {
  border-color: var(--tangerine);
  background: rgba(255,72,42,.06);
}
.enrich .game-card .game-title {
  font-weight: 600;
  font-size: 12px;
  color: var(--eggshell);
  font-family: var(--sans);
}
.enrich .game-card .game-meta {
  font-size: 11px;
  color: var(--g-500);
  margin-top: 1px;
  font-family: 'Geist Mono', Consolas, monospace;
}
.enrich .game-card .game-note {
  font-size: 12px;
  color: var(--g-300);
  margin-top: 4px;
  line-height: 1.45;
}
.enrich .game-card .game-link-icon {
  float: right;
  color: var(--tangerine-300);
  font-size: 10px;
  margin-top: 2px;
}

/* Master note quotes per move */
.master-note {
  padding: 10px 12px 10px 14px;
  background: #160409;
  border-left: 3px solid var(--info);
  border-radius: 0 4px 4px 0;
  margin-bottom: 8px;
  font-size: 13px;
  line-height: 1.55;
}
.master-note:last-child { margin-bottom: 0; }
.master-note .quote {
  font-style: italic;
  color: var(--g-200);
}
.master-note .quote::before { content: '“'; color: var(--info); margin-right: 1px; }
.master-note .quote::after  { content: '”'; color: var(--info); margin-left:  1px; }
.master-note .attrib {
  margin-top: 5px;
  font-size: 11px;
  color: var(--g-400);
}
.master-note .attrib .who {
  color: var(--eggshell);
  font-weight: 600;
}
.master-note .attrib .source {
  color: var(--g-500);
  font-style: italic;
}

.lesson-pane, .practice-pane {
  background: #160409; border-radius: 12px; padding: 18px;
  border: 1px solid #2a1620;
}
.hidden { display: none !important; }

.move-header {
  display: flex; align-items: baseline; gap: 10px;
  padding-bottom: 10px; margin-bottom: 12px;
  border-bottom: 1px solid #2a1620;
}
.move-num {
  font-family: 'Geist Mono', Consolas, monospace;
  color: var(--g-400); font-size: 13px;
}
.move-san {
  font-family: var(--serif); font-weight: 700; font-size: 20px;
  color: var(--tangerine);
}
.move-side {
  font-size: 11px; color: var(--g-400);
  text-transform: uppercase; letter-spacing: .5px;
}
.narrative {
  margin: 0 0 14px; line-height: 1.55; font-size: 14px; color: var(--g-200);
}

.pros-cons {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  margin-bottom: 14px;
}
.pros, .cons {
  background: #0d0307; border-radius: 8px; padding: 12px;
  border: 1px solid #2a1620;
}
.pros h3, .cons h3 {
  margin: 0 0 8px; font-size: 11px;
  text-transform: uppercase; letter-spacing: .8px;
  font-family: var(--sans); font-weight: 600;
}
.pros h3 { color: var(--success); }
.cons h3 { color: var(--warn); }
.pros ul, .cons ul { margin: 0; padding-left: 16px; }
.pros li, .cons li { font-size: 12px; line-height: 1.5; color: var(--g-300); margin-bottom: 4px; }

.line-strip {
  display: flex; flex-wrap: wrap; gap: 4px;
  padding-top: 12px; border-top: 1px solid #2a1620;
}
.line-move {
  font-family: 'Geist Mono', Consolas, monospace;
  font-size: 12px; padding: 4px 8px; border-radius: 5px;
  background: #0d0307; color: var(--g-300); cursor: pointer;
  border: 1px solid transparent;
  transition: all .12s ease;
}
.line-move:hover { background: #1a0e15; color: var(--eggshell); }
.line-move.is-active {
  background: var(--tangerine); color: white;
}
.line-move .num {
  color: var(--g-500); margin-right: 4px;
}
.line-move.is-active .num { color: rgba(255,255,255,.7); }

/* --- Practice pane --- */
.practice-status {
  padding: 10px 14px; border-radius: 8px;
  background: #0d0307; border: 1px solid #2a1620;
  font-size: 13px; margin-bottom: 14px;
}
.practice-status.ok { border-color: var(--success); color: var(--success); }
.practice-status.warn { border-color: var(--warn); color: var(--warn); }
.practice-status.err { border-color: var(--error); color: var(--error); }
.practice-readout {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  margin-bottom: 14px;
}
.practice-readout > div {
  background: #0d0307; border-radius: 8px; padding: 12px;
  border: 1px solid #2a1620;
}
.practice-readout h3 {
  margin: 0 0 8px; font-size: 11px;
  text-transform: uppercase; letter-spacing: .8px;
  font-weight: 600; color: var(--g-400);
}
.readout-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; font-size: 12px; }
.readout-row label { color: var(--g-300); display: flex; gap: 6px; align-items: center; }
.readout-row input[type=range] { width: 100%; accent-color: var(--tangerine); }
.practice-actions { display: flex; gap: 8px; }
.practice-actions button {
  appearance: none; border: 1px solid var(--tangerine); cursor: pointer;
  background: rgba(255,72,42,.12); color: var(--eggshell);
  padding: 8px 14px; border-radius: 8px;
  font-family: var(--sans); font-size: 12px; font-weight: 500;
  transition: all .15s ease;
}
.practice-actions button:hover {
  background: var(--tangerine); color: white;
}

/* --- Footer --- */
.app-foot {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 22px;
  border-top: 1px solid #1a0e15;
  font-size: 11px; color: var(--g-500);
}
.muted { color: var(--g-400); }

/* ============================================
 *  RESPONSIVE LAYOUT
 *  Desktop  (>1100px): 3-column — sidebar | board | info
 *  Tablet   (768–1100): 2-column — sidebar | (board over info, stacked)
 *  Mobile   (<768px):  single column, sidebar becomes a drawer
 * ============================================ */

/* --- Hamburger button (visible by default; hidden on tablet+) --- */
.drawer-toggle {
  display: flex;
  -webkit-appearance: none; appearance: none;
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 8px;
  margin-right: 4px;
  width: 40px; height: 40px;
  border-radius: 8px;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  flex-shrink: 0;
}
.drawer-toggle:hover { background: rgba(255,72,42,.12); }
.drawer-toggle .bar {
  display: block;
  width: 22px; height: 2px;
  background: var(--eggshell);
  border-radius: 2px;
  transition: transform .2s ease, opacity .2s ease;
}
.drawer-open .drawer-toggle .bar:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.drawer-open .drawer-toggle .bar:nth-child(2) { opacity: 0; }
.drawer-open .drawer-toggle .bar:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* --- Drawer overlay (visible mobile only) --- */
.drawer-overlay {
  display: block;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 90;
  opacity: 0;
  transition: opacity .2s ease;
  pointer-events: none;
}
.drawer-open .drawer-overlay {
  opacity: 1;
  pointer-events: auto;
}

/* --- Mobile defaults that need explicit setup before tablet+ kicks in --- */
.pros-cons { grid-template-columns: 1fr; gap: 8px; }
.practice-readout { grid-template-columns: 1fr; }
.practice-actions { flex-wrap: wrap; }
.practice-actions button { flex: 1 1 auto; min-width: 100px; padding: 10px; }
.board-controls { flex-wrap: wrap; gap: 6px; }
.board-controls button { flex: 1 1 auto; min-width: 70px; padding: 10px 8px; font-size: 13px; }
.board-controls .grow { display: none; }
.side-pick { flex: 1 1 100%; justify-content: center; margin-top: 4px; }
.side-pick-label { display: none; }
.side-btn { padding: 8px 16px; font-size: 13px; }
.line-move { padding: 6px 10px; font-size: 13px; }
.app-foot { padding: 8px 14px; font-size: 10px; gap: 8px; }
.info-head, .lesson-pane, .practice-pane { padding: 14px; }
.info-head h2 { font-size: 18px; }

/* ===================================================================
 *  TABLET (>=769px): show permanent sidebar, hide drawer, restore
 *  bigger header typography. 2-column app layout.
 * =================================================================== */
@media (min-width: 769px) {
  .app-header { padding: 14px 22px; gap: 14px; }
  .drawer-toggle { display: none; }
  .drawer-overlay { display: none; }
  .brand { gap: 14px; }
  .brand-mark { width: 38px; height: 38px; font-size: 18px; }
  .brand-text h1 { font-size: 18px; white-space: normal; overflow: visible; }
  .brand-tag { display: block; }
  .mode-switch { padding: 4px; gap: 4px; }
  .mode-btn { padding: 8px 18px; font-size: 13px; }

  .app {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 0;
    min-height: 0;
  }
  .sidebar {
    position: static;
    transform: none;
    width: auto; max-width: none;
    height: auto; max-height: calc(100vh - 130px);
    z-index: auto;
    box-shadow: none;
    padding: 18px 16px;
    border-right: 1px solid #1a0e15;
    border-radius: 0;
  }
  .stage {
    display: grid;
    grid-template-columns: 1fr;
    gap: 22px;
    padding: 22px;
    overflow-y: auto;
    max-height: calc(100vh - 130px);
  }
  .board-controls { flex-wrap: nowrap; gap: 8px; }
  .board-controls button { flex: 0 0 auto; min-width: auto; padding: 8px 12px; font-size: 12px; }
  .board-controls .grow { display: block; flex: 1; }
  .side-pick { flex: 0 0 auto; margin-top: 0; justify-content: flex-start; }
  .side-pick-label { display: inline; }
  .pros-cons { grid-template-columns: 1fr 1fr; gap: 12px; }
  .practice-readout { grid-template-columns: 1fr 1fr; }
  .practice-actions { flex-wrap: nowrap; }
  .practice-actions button { flex: 0 0 auto; min-width: auto; }
  .info-head, .lesson-pane, .practice-pane { padding: 18px; }
  .info-head h2 { font-size: 22px; }
  .app-foot { padding: 10px 22px; font-size: 11px; }
}

/* ===================================================================
 *  WIDE DESKTOP (>=1101px): 3-column with permanent info panel
 * =================================================================== */
@media (min-width: 1101px) {
  .app { grid-template-columns: 280px 1fr; }
  .stage { grid-template-columns: minmax(420px, 1fr) minmax(360px, 480px); }
}

/* --- Very small phones (under 380px) tighten further --- */
@media (max-width: 380px) {
  .brand-text h1 { font-size: 14px; }
  .mode-btn { padding: 5px 10px; font-size: 11px; }
  .info-head h2 { font-size: 16px; }
  .move-san { font-size: 17px; }
  .stage { padding: 10px; gap: 12px; }
}
