/* ==========================================================================
   Chess Tricks Master - Professional Chess.com-Style Stylesheet
   Responsive Split-Screen (Desktop) & Zero-Scroll Clean-Fit (Mobile)
   ========================================================================== */

:root, [data-board-theme="forest"] {
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);

  --bg-primary: #121211;
  --bg-surface: #1e1d1a;
  --bg-card: #272522;
  --bg-card-hover: #34322d;
  --border-subtle: #3a3733;
  --text-bright: #ffffff;
  --text-regular: #e6e3dd;
  --text-muted: #9e9b94;
  
  --accent-green: #81b64c;
  --accent-green-hover: #97cc5c;
  --accent-green-ink: #14210a;
  --accent-red: #fa412d;
  --accent-amber: #f1b333;

  /* Forest Green (Chess.com Eye-Comfort Theme) */
  --sq-light: #eeeed2;
  --sq-dark: #769656;
  --sq-highlight: rgba(247, 247, 105, 0.55);
  --sq-target: rgba(20, 85, 30, 0.45);
  --sq-error: rgba(250, 65, 45, 0.65);
  --sq-check: rgba(255, 50, 50, 0.65);
}

/* Walnut Wood Theme */
[data-board-theme="walnut"] {
  --sq-light: #d6b88b;
  --sq-dark: #976b43;
  --sq-highlight: rgba(255, 230, 120, 0.58);
  --sq-target: rgba(70, 40, 15, 0.45);
}

/* Slate Ocean Theme */
[data-board-theme="ocean"] {
  --sq-light: #dee3e6;
  --sq-dark: #8ca2ad;
  --sq-highlight: rgba(140, 200, 255, 0.58);
  --sq-target: rgba(30, 70, 95, 0.45);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

*:focus-visible {
  outline: 2px solid var(--accent-green);
  outline-offset: 2px;
}

input, textarea {
  user-select: text !important;
}

html, body {
  height: 100%;
  background-color: var(--bg-primary);
  color: var(--text-regular);
  overflow-x: hidden;
}

body {
  display: flex;
  flex-direction: column;
}

/* Top App Header */
.top-header {
  padding-top: max(8px, var(--sat));
  padding-left: max(16px, var(--sal));
  padding-right: max(16px, var(--sar));
  padding-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  z-index: 30;
  flex-shrink: 0;
  gap: 12px;
}

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text-bright);
  white-space: nowrap;
}

.brand-badge {
  width: 28px;
  height: 28px;
  background: var(--accent-green);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 900;
  color: var(--accent-green-ink);
  box-shadow: 0 2px 6px rgba(129, 182, 76, 0.4);
}

.brand-name {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text-bright);
  letter-spacing: 0.01em;
}

.header-action-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.action-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-regular);
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s ease;
}

.action-icon-btn {
  width: 36px;
  height: 36px;
  padding: 0 !important;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  flex-shrink: 0;
}

.btn-library-header {
  padding: 7px 13px;
  font-size: 0.84rem;
  font-weight: 800;
  white-space: nowrap;
  border-radius: 8px;
  flex-shrink: 0;
}

.action-btn:hover, .action-btn:active {
  background: var(--bg-card-hover);
  color: var(--text-bright);
  border-color: var(--accent-green);
}

/* Main Responsive Layout */
.app-main-layout {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 12px 20px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  gap: 24px;
  min-height: 0;
}

/* Left Column: Board & Eval Bar */
.board-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 600px;
  flex-shrink: 0;
}

/* Player Info Strips */
.player-strip {
  width: 100%;
  max-width: 580px;
  padding: 6px 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.92rem;
  font-weight: 700;
}

.player-details {
  display: flex;
  align-items: center;
  gap: 8px;
}

.avatar-badge {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
}

.avatar-opponent {
  background: #3e3b37;
  color: #c4c1ba;
}

.avatar-player {
  background: var(--accent-green);
  color: var(--accent-green-ink);
  font-weight: 800;
}

.captured-list {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 15px;
  color: var(--text-muted);
}

/* Board + Eval Wrapper - Centered and Symmetrical */
.board-eval-wrapper {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  max-width: 100%;
}

/* Chess.com-Style Evaluation Bar */
.chess-eval-bar-container {
  width: 14px;
  height: min(90vw, calc(100vh - 190px), 580px);
  background: #2b2926;
  border-radius: 4px;
  overflow: hidden;
  position: relative;
  box-shadow: inset 0 0 4px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  flex-shrink: 0;
}

.eval-bar-fill {
  width: 100%;
  height: 50%;
  background: #ffffff;
  transition: height 0.35s ease;
}

.eval-bar-text {
  position: absolute;
  bottom: 4px;
  width: 100%;
  text-align: center;
  font-size: 9px;
  font-weight: 800;
  color: #111;
  pointer-events: none;
}

/* Chess Board Container & Framed Grid - Strict 1:1 Square */
.chess-board-container {
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 0 0 auto;
  max-width: 100%;
}

.chess-board-frame {
  width: min(90vw, calc(100vh - 190px), 580px);
  height: min(90vw, calc(100vh - 190px), 580px);
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: 18px 1fr;
  grid-template-rows: 1fr 18px;
  background: rgba(28, 26, 23, 0.95);
  border-radius: 10px;
  padding: 2px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
  flex-shrink: 0;
}

.board-coords-rank-track {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: center;
  user-select: none;
  padding-right: 2px;
}

.board-coords-file-track {
  display: flex;
  flex-direction: row;
  justify-content: space-around;
  align-items: center;
  user-select: none;
  padding-top: 2px;
}

.board-coords-corner {
  width: 16px;
  height: 16px;
}

.outside-coord {
  font-size: 11px;
  font-weight: 800;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.85;
}

.rank-coord {
  height: 12.5%;
}

.file-coord {
  width: 12.5%;
}

.chess-board-grid {
  width: 100%;
  height: 100%;
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
  position: relative;
}

.board-square {
  position: relative;
  width: 100%;
  height: 100%;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
}

.board-square.light {
  background-color: var(--sq-light);
  color: var(--sq-dark);
}

.board-square.dark {
  background-color: var(--sq-dark);
  color: var(--sq-light);
}

.board-square.sq-selected {
  background-color: var(--sq-highlight) !important;
}

.board-square.sq-last-move {
  background-color: var(--sq-highlight) !important;
}

.board-square.sq-in-check {
  background-color: var(--sq-check) !important;
}

.board-square.sq-brilliant {
  background-color: rgba(27, 166, 166, 0.45) !important;
}

.brilliant-badge-indicator {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 20px;
  height: 20px;
  background: #1ba6a6;
  border: 1.5px solid #ffffff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 900;
  color: #ffffff;
  z-index: 50;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5), 0 0 10px rgba(27, 166, 166, 0.85);
  animation: brilliantBadgePop 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
  pointer-events: none;
  line-height: 1;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  letter-spacing: -0.5px;
}

@keyframes brilliantBadgePop {
  0% { transform: scale(0) rotate(-20deg); opacity: 0; }
  60% { transform: scale(1.25) rotate(5deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

.board-square.sq-error-shake {
  background-color: var(--sq-error) !important;
  animation: squareShake 0.38s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

.board-square.sq-landing-glow {
  animation: landingGlow 0.42s ease-out;
}

.board-square.sq-capture-pop {
  animation: capturePop 0.24s ease-out;
}

@keyframes squareShake {
  10%, 90% { transform: translate3d(-2px, 0, 0); }
  20%, 80% { transform: translate3d(3px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
  40%, 60% { transform: translate3d(4px, 0, 0); }
}

@keyframes landingGlow {
  0% { box-shadow: inset 0 0 0px rgba(129, 182, 76, 0); }
  35% { box-shadow: inset 0 0 16px rgba(129, 182, 76, 0.9); }
  100% { box-shadow: inset 0 0 0px rgba(129, 182, 76, 0); }
}

@keyframes capturePop {
  0% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

.coord {
  position: absolute;
  font-size: 10px;
  font-weight: 800;
  pointer-events: none;
  opacity: 0.8;
}

.coord-file {
  bottom: 2px;
  right: 4px;
}

.coord-rank {
  top: 2px;
  left: 4px;
}

.board-piece-img {
  width: 90%;
  height: 90%;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0px 2px 4px rgba(0, 0, 0, 0.35));
  transition: transform 0.13s cubic-bezier(0.2, 0.8, 0.25, 1);
  will-change: transform;
}

/* Indicators */
.target-move-dot {
  width: 26%;
  height: 26%;
  background: var(--sq-target);
  border-radius: 50%;
  pointer-events: none;
}

.target-capture-ring {
  position: absolute;
  inset: 6px;
  border: 4px solid var(--sq-target);
  border-radius: 50%;
  pointer-events: none;
}

/* Right Side: Training & Coaching Panel */
.panel-column {
  flex: 1;
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 8px;
  background: var(--bg-surface);
  padding: 14px 18px;
  border-radius: 16px;
  border: 1px solid var(--border-subtle);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

@media (min-width: 860px) {
  .panel-column {
    height: 520px;
    min-height: 520px;
    max-height: 520px;
  }
}

/* Mode Switch Tabs */
.mode-switch-bar {
  display: flex;
  background: var(--bg-card);
  border-radius: 10px;
  padding: 4px;
  gap: 4px;
  border: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.mode-tab {
  flex: 1;
  text-align: center;
  padding: 7px 0;
  font-size: 0.84rem;
  font-weight: 700;
  border-radius: 7px;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.2s ease;
}

.mode-tab.active {
  background: var(--accent-green);
  color: var(--accent-green-ink);
  font-weight: 800;
  box-shadow: 0 2px 8px rgba(129, 182, 76, 0.35);
}

/* Active Lesson Banner */
.lesson-card {
  padding: 8px 12px;
  background: var(--bg-card);
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  flex-shrink: 0;
  min-height: 72px;
}

.lesson-progress-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.74rem;
  font-weight: 800;
  color: var(--accent-green);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  gap: 6px;
}

.lesson-progress-row > span:first-child {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1 1 auto;
}

.lesson-header-actions {
  display: flex;
  gap: 5px;
  align-items: center;
  flex-shrink: 0;
}

.pill-btn {
  padding: 3px 8px !important;
  font-size: 0.74rem !important;
  white-space: nowrap;
}

.lesson-year-badge {
  background: rgba(229, 167, 82, 0.15);
  color: #e5a752;
  border: 1px solid rgba(229, 167, 82, 0.35);
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: none;
  white-space: nowrap;
}

.library-year-tag {
  display: inline-block;
  background: rgba(229, 167, 82, 0.15);
  color: #e5a752;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 5px;
  margin-left: 6px;
  border: 1px solid rgba(229, 167, 82, 0.3);
  vertical-align: middle;
}

.lesson-title-text {
  font-size: 1.06rem;
  font-weight: 800;
  color: var(--text-bright);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lesson-players-text {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Coaching & Feedback */
.coaching-bar {
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--bg-card);
  border-left: 5px solid var(--accent-green);
  display: flex;
  align-items: center;
  flex-shrink: 0;
  min-height: 64px;
  height: 64px;
  transition: all 0.2s ease;
}

.coaching-bar.state-error {
  border-left-color: var(--accent-red);
  background: #331f1d;
}

.coaching-bar.state-success {
  border-left-color: var(--accent-green);
  background: #1f2d18;
}

.coaching-bar.state-brilliant {
  border-left-color: #1ba6a6;
  background: linear-gradient(90deg, rgba(27, 166, 166, 0.22) 0%, rgba(39, 37, 34, 0.98) 100%);
  animation: pulseBrilliant 0.4s ease-out;
}

@keyframes pulseBrilliant {
  0% { transform: scale(0.98); }
  50% { transform: scale(1.015); box-shadow: 0 0 16px rgba(27, 166, 166, 0.45); }
  100% { transform: scale(1); }
}

.coaching-text-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
}

.coaching-title {
  font-size: 0.90rem;
  font-weight: 800;
  color: var(--text-bright);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.coaching-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Commentary Box */
.commentary-box {
  padding: 8px 12px;
  background: #1d251a;
  border: 1px solid #334427;
  border-radius: 10px;
  font-size: 0.80rem;
  line-height: 1.35;
  color: #cfdece;
  flex-shrink: 0;
  min-height: 52px;
  height: 52px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.commentary-header {
  font-weight: 800;
  color: #9bd466;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
  font-size: 0.76rem;
}

/* Game Story & Tactical Secrets Card (Desktop) */
.game-story-card {
  padding: 10px 12px;
  background: rgba(33, 31, 28, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1 1 auto;
  min-height: 70px;
  overflow-y: auto;
}

.story-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.story-header-title {
  font-size: 0.74rem;
  font-weight: 800;
  color: #e5a752;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.motif-tag {
  background: rgba(129, 182, 76, 0.15);
  color: #a3e635;
  border: 1px solid rgba(163, 230, 53, 0.3);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.story-body {
  font-size: 0.78rem;
  color: #c4c1ba;
  line-height: 1.4;
}

/* Navigation & Action Controls */
.nav-control-bar {
  display: grid;
  grid-template-columns: 1fr 1fr 2fr 1fr;
  gap: 8px;
  margin-top: auto;
  padding-top: 4px;
  flex-shrink: 0;
  height: 44px;
}

.btn {
  height: 44px;
  padding: 0 8px;
  border-radius: 9px;
  font-size: 0.86rem;
  font-weight: 800;
  cursor: pointer;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: transform 0.1s ease, filter 0.15s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-regular);
  border: 1px solid var(--border-subtle);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  color: var(--text-bright);
}

.btn-primary {
  background: var(--accent-green);
  color: var(--accent-green-ink);
  font-weight: 800;
  box-shadow: 0 4px 12px rgba(129, 182, 76, 0.35);
}

.btn-primary:hover {
  background: var(--accent-green-hover);
}

/* Modals */
/* Modals */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: modalFadeIn 0.2s ease-out;
}

@keyframes modalFadeIn {
  from { opacity: 0; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1); }
}

.modal-overlay.active {
  display: flex;
}

.modal-card {
  background: #1c1a17;
  width: 100%;
  max-width: 630px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 20px 22px;
  box-shadow: 0 25px 65px rgba(0, 0, 0, 0.9);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  gap: 12px;
}

.modal-head h3 {
  font-size: 1.16rem;
  font-weight: 800;
  color: var(--text-bright);
  margin: 0;
  line-height: 1.2;
  display: flex;
  align-items: center;
  gap: 6px;
}

.close-cross {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin: 0;
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
  line-height: 1;
}

.close-cross svg {
  display: block;
  pointer-events: none;
}

.close-cross:hover {
  background: rgba(235, 97, 80, 0.22);
  color: #ff6b6b;
  border-color: rgba(255, 107, 107, 0.45);
}

/* Library Instant Search Input Bar */
.library-search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}

.library-search-wrapper input {
  width: 100%;
  padding: 8px 32px 8px 34px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  color: #ffffff;
  font-size: 0.82rem;
  font-weight: 500;
  outline: none;
  transition: all 0.15s ease;
}

.library-search-wrapper input:focus {
  border-color: var(--accent-green);
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 0 0 2px rgba(129, 182, 76, 0.25);
}

.library-search-wrapper input::placeholder {
  color: #8c8982;
  font-size: 0.78rem;
}

.search-icon {
  position: absolute;
  left: 10px;
  color: #8c8982;
  pointer-events: none;
}

.search-clear-btn {
  position: absolute;
  right: 8px;
  background: rgba(255, 255, 255, 0.12);
  border: none;
  color: #ccc;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

.search-clear-btn:hover {
  background: rgba(235, 97, 80, 0.3);
  color: #ff6b6b;
}

.library-opening-tag {
  display: inline-block;
  background: rgba(129, 182, 76, 0.14);
  color: #a3e635;
  font-size: 0.70rem;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid rgba(163, 230, 53, 0.25);
  margin-left: 6px;
  vertical-align: middle;
}

.lesson-players-line {
  font-size: 0.76rem;
  font-weight: 600;
  color: #a8a59e;
  margin-top: 1px;
}

/* Category Filter Chips (Clean Wrapped Layout with Rounded Corners) */
.category-pills-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 0;
  margin-bottom: 12px;
}

.category-pill {
  padding: 6px 12px;
  font-size: 0.80rem;
  font-weight: 700;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  color: #b8b5ad;
  border: 1px solid rgba(255, 255, 255, 0.09);
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  line-height: 1.3;
}

.category-pill:hover {
  background: rgba(255, 255, 255, 0.11);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.2);
}

.category-pill.active {
  background: var(--accent-green);
  color: var(--accent-green-ink);
  border-color: var(--accent-green);
  box-shadow: 0 2px 8px rgba(129, 182, 76, 0.35);
  font-weight: 800;
}

/* Library Filter Status & Sort Bar */
.library-filter-status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 4px 2px 8px 2px;
  font-size: 0.78rem;
  color: var(--text-muted);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  margin-bottom: 8px;
  width: 100%;
  box-sizing: border-box;
}

#libraryCountLabel {
  white-space: nowrap;
  font-weight: 700;
  font-size: 0.76rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.library-sort-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  justify-content: flex-end;
  min-width: 0;
}

.library-sort-controls label {
  font-weight: 700;
  font-size: 0.74rem;
  white-space: nowrap;
  color: var(--text-muted);
}

.library-sort-controls select {
  background: #252320;
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--text-bright);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  max-width: 160px;
  width: auto;
  text-overflow: ellipsis;
  outline: none;
  box-sizing: border-box;
}

.library-sort-controls select:focus {
  border-color: var(--accent-green);
}

.theme-palette-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}

.theme-option-card {
  background: var(--bg-card);
  border: 2px solid var(--border-subtle);
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
  text-align: center;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-regular);
}

.theme-option-card.active {
  border-color: var(--accent-green);
  color: var(--text-bright);
}

.theme-swatch {
  width: 100%;
  height: 48px;
  border-radius: 6px;
  margin-bottom: 6px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  overflow: hidden;
}

/* Premium Scrollable List */
.lesson-list-scroll {
  flex: 1 1 auto;
  max-height: 440px;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
  padding-right: 6px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.25) rgba(0, 0, 0, 0.3);
}

.lesson-list-scroll::-webkit-scrollbar {
  width: 6px;
}

.lesson-list-scroll::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 4px;
}

.lesson-list-scroll::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.25);
  border-radius: 4px;
}

.lesson-list-scroll::-webkit-scrollbar-thumb:hover {
  background: var(--accent-green);
}

.lesson-list-item {
  flex-shrink: 0;
  min-height: 64px;
  background: rgba(38, 36, 33, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 12px;
  padding: 12px 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  overflow: hidden;
}

.lesson-list-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: transparent;
  transition: background 0.18s ease;
}

.lesson-list-item:hover, .lesson-list-item:active {
  background: #332f29;
  border-color: rgba(129, 182, 76, 0.5);
  transform: translateX(4px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.lesson-list-item:hover::before {
  background: var(--accent-green);
}

.lesson-item-meta {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.lesson-item-meta h4 {
  font-size: 0.98rem;
  font-weight: 700;
  color: #ffffff;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  line-height: 1.3;
}

.lesson-item-meta p {
  font-size: 0.82rem;
  font-weight: 500;
  color: #a8a59d;
  line-height: 1.35;
}

.stars-badge {
  color: var(--accent-amber);
  font-size: 0.95rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.status-pill-new {
  font-size: 0.78rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.08);
  color: #e5e3dd;
  padding: 5px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.lesson-list-item:hover .status-pill-new {
  background: var(--accent-green);
  color: #ffffff;
  border-color: var(--accent-green);
}

/* ==========================================================================
   Mobile-Specific Layout (< 860px) - DEFINITIVE CLEAN FIT & PERFECT SQUARE
   ========================================================================== */
@media (max-width: 859px) {
  html, body {
    height: 100%;
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .top-header {
    flex: 0 0 auto;
    padding-top: max(40px, calc(var(--sat) + 10px), env(safe-area-inset-top, 40px));
    padding-bottom: 6px;
    padding-left: max(10px, var(--sal));
    padding-right: max(10px, var(--sar));
    gap: 6px;
  }

  .brand-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    flex-shrink: 0;
    text-align: center;
  }

  .brand-badge {
    width: 22px;
    height: 22px;
    font-size: 12px;
    border-radius: 6px;
    flex-shrink: 0;
  }

  .brand-name {
    font-size: 0.64rem;
    font-weight: 800;
    color: var(--text-bright);
    letter-spacing: 0.01em;
    white-space: nowrap;
    line-height: 1;
  }

  .header-action-group {
    gap: 5px;
    display: flex;
    align-items: center;
    flex-shrink: 0;
  }

  .action-icon-btn {
    width: 32px;
    height: 32px;
    font-size: 0.88rem;
    border-radius: 7px;
  }

  .btn-library-header {
    padding: 6px 10px;
    font-size: 0.78rem;
    font-weight: 800;
    white-space: nowrap;
    border-radius: 8px;
  }

  .app-main-layout {
    flex: 1 1 auto;
    width: 100%;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-evenly;
    padding-top: 4px;
    padding-bottom: max(16px, calc(var(--sab) + 10px), env(safe-area-inset-bottom, 16px));
    padding-left: max(8px, var(--sal));
    padding-right: max(8px, var(--sar));
    gap: 6px;
    overflow-y: visible;
  }

  .board-column {
    flex: 0 0 auto;
    width: 100%;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 3px;
  }

  .player-strip {
    flex: 0 0 auto;
    padding: 3px 6px;
    font-size: 0.78rem;
    width: min(94vw, calc(100dvh - 370px), 410px);
    margin: 0 auto;
  }

  .avatar-badge {
    width: 20px;
    height: 20px;
    font-size: 9.5px;
  }

  .captured-list {
    font-size: 13px;
  }

  /* Board Area is strictly guaranteed to be 100% square on all mobile screens */
  .chess-board-container {
    flex: 0 0 auto;
    width: auto;
    height: auto;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0 auto;
  }

  .board-eval-wrapper {
    display: flex;
    gap: 6px;
    justify-content: center;
    align-items: center;
    width: 100%;
  }

  .chess-board-frame {
    width: min(94vw, calc(100dvh - 370px), 410px);
    height: min(94vw, calc(100dvh - 370px), 410px);
    aspect-ratio: 1 / 1;
    display: grid;
    grid-template-columns: 14px 1fr;
    grid-template-rows: 1fr 14px;
    padding: 2px;
    flex-shrink: 0;
  }
  
  .outside-coord {
    font-size: 9px;
  }
  
  .board-coords-corner {
    width: 14px;
    height: 14px;
  }

  .chess-eval-bar-container {
    width: 8px;
    height: min(94vw, calc(100dvh - 370px), 410px);
    flex-shrink: 0;
  }

  .chess-board-grid {
    height: 100%;
    width: 100%;
    aspect-ratio: 1 / 1;
  }

  .board-square {
    aspect-ratio: 1 / 1;
    width: 100%;
    height: 100%;
  }

  /* Fixed & Stable Bottom Panel - Zero-Scroll on Mobile */
  .panel-column {
    flex: 0 0 auto;
    width: min(94vw, calc(100dvh - 370px), 410px);
    margin: 0 auto;
    padding: 8px 12px;
    gap: 5px;
    border-radius: 14px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
  }

  .mode-switch-bar {
    padding: 3px;
    border-radius: 7px;
  }

  .mode-tab {
    padding: 5px 0;
    font-size: 0.76rem;
    border-radius: 6px;
  }

  .lesson-card {
    padding: 6px 10px;
    border-radius: 9px;
    gap: 2px;
  }

  .lesson-progress-row {
    font-size: 0.72rem;
  }

  .lesson-title-text {
    font-size: 0.98rem;
  }

  .lesson-players-text {
    font-size: 0.76rem;
  }

  .coaching-bar {
    padding: 6px 10px;
    border-radius: 9px;
    border-left-width: 4px;
    min-height: 50px;
    display: flex;
    align-items: center;
  }

  .coaching-title {
    font-size: 0.84rem;
  }

  .coaching-desc {
    font-size: 0.76rem;
    line-height: 1.35;
    word-break: break-word;
  }

  .commentary-box {
    display: none !important;
  }

  .game-story-card {
    display: none !important;
  }

  .nav-control-bar {
    gap: 6px;
    padding-top: 2px;
    height: 44px;
  }

  .btn {
    height: 44px;
    padding: 0 4px;
    font-size: 0.82rem;
    border-radius: 8px;
    gap: 3px;
  }

  .modal-card {
    max-width: 95vw;
    max-height: 92dvh;
    padding-top: max(16px, var(--sat));
    padding-bottom: max(16px, var(--sab));
    padding-left: max(14px, var(--sal));
    padding-right: max(14px, var(--sar));
    border-radius: 14px;
  }

  .modal-head h3 {
    font-size: 1.02rem;
  }

  .category-pills-bar {
    gap: 5px;
    margin-bottom: 8px;
  }

  .category-pill {
    padding: 5px 9px;
    font-size: 0.74rem;
    border-radius: 6px;
  }

  .library-sort-controls select {
    max-width: 140px;
    font-size: 0.72rem;
    padding: 3px 6px;
  }

  .lesson-list-scroll {
    max-height: 52vh;
  }

  .lesson-list-item {
    padding: 10px 12px;
    min-height: 56px;
  }

  .brilliant-badge-indicator {
    width: 16px;
    height: 16px;
    font-size: 8.5px;
    top: 2px;
    right: 2px;
    border-width: 1px;
  }
}
