:root {
    --bg: #0b0f19;
    --card: #132026;
    --muted: #7a88a5;
    --text: #e8efff;
    --accent: #7c5cff;
    --accent-2: #20d4ff;
    --square-light: #e8edf9;
    --square-dark: #97a3c0;
    --highlight: #ffb703;
    --danger: #ff5b5b;
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.45);
  }
  
  * {
    box-sizing: border-box;
  }
  
  html, body {
    height: 100%;
  }
  
  body {
    margin: 0;
    font-family: 'Poppins', system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
  }
  
.app {
  display: grid;
  grid-template-areas: 
    "header header header"
    "sidebar-left board sidebar-right";
  grid-template-columns: minmax(260px, 340px) 1fr minmax(260px, 340px);
  grid-template-rows: auto 1fr;
  min-height: 100vh;
  gap: clamp(16px, 3vw, 32px);
  padding: 0 clamp(20px, 4vw, 48px) 32px;
}
/* Medium screens (iPad Pro 1024x1366 and similar): tighten sidebars so board gets more width */
@media (max-width: 1200px) {
  .app {
    grid-template-columns: minmax(220px, 300px) 1fr minmax(220px, 300px);
    gap: clamp(12px, 2.5vw, 24px);
  }
}
  
  .app-header {
    grid-area: header;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px clamp(20px, 4vw, 48px);
    font-size: 24px;
  }
  
  .brand { display: flex; align-items: center; gap: 12px; }
  .logo { font-size: 28px; filter: drop-shadow(0 4px 10px rgba(124, 92, 255, 0.8)); }
  .app-header h1 {
    font-weight: 700;
    letter-spacing: 0.2px;
    margin: 0;
  }
  .app-header .sub {
    color: var(--muted);
    font-weight: 300;
  }
  
  .content {
    display: contents;
  }
  
  /* Hidden by default; only shown/used on mobile layout */
  .mobile-top-cards { display: none; }
  
.board-wrap {
  grid-area: board;
  position: relative;
  place-self: start center;
  display: grid;
  width: 100%;
  /* Center the board inside the available column */
  place-items: center;
}
  
  /* Video overlay styles */
  .video-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.8;
    pointer-events: none;
  }
  
  .video-overlay video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 16px;
  }
  
  .board {
    /* JS sets --square-size so the board fills most of the screen while staying square */
    --square-size: 80px;
    display: grid;
    grid-template-columns: repeat(8, var(--square-size));
    grid-auto-rows: var(--square-size);
    background: linear-gradient(180deg, rgba(16, 23, 40, 0.95), rgba(16, 23, 40, 0.85));
    border-radius: 16px;
    padding: 10px;
    gap: 0;
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-lg), inset 0 0 0 1px rgba(255,255,255,0.05), inset 0 10px 30px rgba(255,255,255,0.08), inset 0 -18px 40px rgba(0,0,0,0.35);
  }
  
  @media (max-width: 1120px) {
    .board { padding: 0; border-radius: 0; box-shadow: none; }
  }
  
  /* Glossy overlays */
  .board::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    background: linear-gradient(
        180deg,
        rgba(255, 255, 255, 0.18) 0%,
        rgba(255, 255, 255, 0.10) 10%,
        rgba(255, 255, 255, 0.05) 22%,
        rgba(255, 255, 255, 0.02) 36%,
        rgba(255, 255, 255, 0) 56%
    );
    z-index: 3;
  }
  .board::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    background:
      radial-gradient(120% 70% at 50% -10%, rgba(255,255,255,0.12), rgba(255,255,255,0) 60%),
      radial-gradient(120% 90% at 50% 120%, rgba(0,0,0,0.35), rgba(0,0,0,0) 60%);
    z-index: 3;
  }
  
  .square {
    width: 100%;
    height: 100%;
    position: relative;
    display: grid;
    place-items: center;
    user-select: none;
    transition: transform 120ms ease;
  }
  .square.light { background: var(--square-light); }
  .square.dark  { background: var(--square-dark); }

  /* Difficulty-driven board themes (alter dark squares only, darker solids) */
  .board.theme-super-easy .square.dark { background: #d96a5c; } /* darker salmon/pink */
  .board.theme-easy .square.dark { background: #1e9a92; } /* darker cool teal */
  .board.theme-medium .square.dark { background: var(--square-dark); } /* keep current */
  .board.theme-easy-medium .square.dark { background: #6f8f2f; } /* darker green/orange family */
  .board.theme-hard .square.dark { background: #593ccf; } /* darker cool purple */
  .board.theme-master .square.dark { background: #6e4b2a; } /* darker brown (white/brown scheme) */
  .square:hover { outline: 2px solid rgba(124, 92, 255, 0.35); outline-offset: -2px; }
  
  .square.selected { box-shadow: inset 0 0 0 3px var(--accent); z-index: 2; }
  .square.move-target { box-shadow: inset 0 0 0 3px var(--accent-2); }
.square.hint-from {
  box-shadow: inset 0 0 0 4px rgba(72, 255, 158, 0.95);
  z-index: 5;
}
  /* Feedback overlay */
  .feedback-overlay { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; z-index: 1200; }
  .feedback-badge { font-size: clamp(28px, 6vw, 64px); font-weight: 800; letter-spacing: 0.5px; color: #ffffff; text-shadow: 0 6px 24px rgba(0,0,0,0.6); padding: 10px 18px; border-radius: 12px; backdrop-filter: blur(2px); opacity: 0; transform: scale(0.9); transition: opacity 200ms ease, transform 200ms ease; }
  .feedback-badge.show { opacity: 1; transform: scale(1); }
  .feedback-badge.cat-brilliant { color: #5cf0a7; }
  .feedback-badge.cat-best-move { color: #5cc9ff; }
  .feedback-badge.cat-excellent { color: #b59cff; }
  .feedback-badge.cat-good { color: #49e0ff; }
  .feedback-badge.cat-book-move { color: #ffe791; }
  .feedback-badge.cat-inaccuracy { color: #ffcc66; }
  .feedback-badge.cat-mistake { color: #ff9966; }
  .feedback-badge.cat-blunder { color: #ff6666; }
  .feedback-badge.cat-missed-win { color: #ff6699; }
/* Improve board scaling for tall tablets: use viewport-based sizing caps */
@media (min-width: 1024px) and (max-width: 1366px) and (orientation: portrait) {
  .board {
    --square-size: clamp(56px, 7.2vh, 92px);
  }
}
.square.hint-to {
  box-shadow: inset 0 0 0 4px rgba(72, 255, 158, 0.75);
  z-index: 5;
}
  .square.last-move { outline: 3px solid rgba(255, 183, 3, 0.9); outline-offset: -3px; }
.square.hint-from, .square.hint-to { position: relative; }
  .square.check { box-shadow: inset 0 0 0 4px var(--danger); }
  
  .square::after, .square::before {
    content: '';
    position: absolute;
    color: rgba(0,0,0,0.55);
    font-size: clamp(10px, 1.6vmin, 12px);
    font-weight: 600;
    pointer-events: none;
    text-shadow: 0 1px 0 rgba(255,255,255,0.6);
  }
  /* File letter: bottom-left of each square on the bottom rank (from White's perspective) */
  .board:not(.flipped) .square[data-rank="1"]::after {
    content: attr(data-file);
    bottom: 6px;
    left: 8px;
  }
  /* Rank number: top-left of each square on the leftmost file on White's perspective */
  .board:not(.flipped) .square[data-file="a"]::before {
    content: attr(data-rank);
    top: 6px;
    left: 8px;
  }
  /* Flipped orientation: swap reference edges */
  .board.flipped .square[data-rank="8"]::after {
    content: attr(data-file);
    top: 6px;
    right: 8px;
  }
  .board.flipped .square[data-file="h"]::before {
    content: attr(data-rank);
    bottom: 6px;
    right: 8px;
  }
  
  .piece-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    image-rendering: auto;
    transition: transform 0.3s ease-out;
    position: relative;
  }
  
  /* Moving piece animation styles */
  .piece-moving {
    z-index: 100 !important;
    position: absolute !important;
    pointer-events: none;
    transition: all 0.3s ease-out;
    background: none !important;
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
  }
  
  /* Animating piece for incorrect puzzle moves */
  .animating-piece {
    z-index: 1000 !important;
    position: absolute !important;
    pointer-events: none !important;
    transition: none; /* Initially no transition, will be added via JS */
  }
  
  /* Use pixelated rendering only for Pokemon pieces (PNG) */
  .piece-img[src*="pokemon"] {
    image-rendering: pixelated;
  }
  
  /* Monochrome rendering per side */
  .piece-img.light-side {
    /* Preserve tonal differences but shift to light spectrum */
    filter: grayscale(1) brightness(1.45) contrast(0.9) drop-shadow(0 8px 16px rgba(0,0,0,0.35));
  }
  .piece-img.dark-side {
    /* Preserve tonal differences but shift to dark spectrum */
    filter: grayscale(1) brightness(0.55) contrast(1.25) drop-shadow(0 8px 16px rgba(0,0,0,0.35));
  }
  
  /* Subtle pulsating glow for side-to-move pieces after first move */
  .piece-glow {
    position: relative;
    z-index: 1;
  }
  .piece-glow::after {
    content: '';
    position: absolute;
    inset: 8%;
    border-radius: 12px;
    box-shadow: 0 0 0 0 rgba(124, 92, 255, 0.0), 0 0 16px 6px rgba(124, 92, 255, 0.25);
    animation: pulseGlow 1.6s ease-in-out infinite;
    pointer-events: none;
  }
  @keyframes pulseGlow {
    0% { opacity: 0.65; transform: scale(0.98); }
    50% { opacity: 0.2; transform: scale(1.02); }
    100% { opacity: 0.65; transform: scale(0.98); }
  }
  
  /* Full square shading for last moves using inset shadow (avoids pseudo-element conflicts) */
  .square.last-move { outline: none; box-shadow: inset 0 0 0 9999px rgba(255, 183, 3, 0.35); }
  
  /* Removed external legends; use in-square labels */
  
.sidebar-left {
  grid-area: sidebar-left;
  display: grid;
  align-content: start;
  gap: 16px;
  margin-top: 0;
}

.sidebar-right {
  grid-area: sidebar-right;
  display: grid;
  align-content: start;
  gap: 16px;
  margin-top: 0;
}
  
  .panel {
    background: var(--card);
    border: 1px solid rgba(255,255,255,0.08);
    box-shadow: var(--shadow-lg);
    border-radius: 14px;
    padding: 16px;
  }
  
  .status { font-size: 18px; font-weight: 600; }
  .substatus { color: var(--muted); margin-top: 6px; white-space: pre-line; }
  
  .controls { 
    display: flex; 
    flex-direction: column;
    gap: 12px;
  }
  
  .controls-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
  }
  
  
  .btn {
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.12);
    color: var(--text);
    padding: 10px 14px;
    border-radius: 10px;
    cursor: pointer;
    transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
  }
  .btn:hover { transform: translateY(-1px); background: rgba(255,255,255,0.1); border-color: rgba(255,255,255,0.2); }
  .btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: none; }
  
  /* Classic mode: dark orange/red background for new game button */
  body.classic-mode #newGame.btn.primary,
  body.classic-mode #newGameStart.btn.primary {
    background: #b33a01;
    border: none;
  }
  body.classic-mode #newGame.btn.primary:hover,
  body.classic-mode #newGameStart.btn.primary:hover {
    background: linear-gradient(135deg, #dd5511, #bb3311);
    transform: translateY(-1px);
  }
  
  .panel-title { font-weight: 600; margin-bottom: 8px; opacity: 0.9; }
  
  .game-mode {
    margin-bottom: 16px;
  }
  
  .mode-selector {
    display: grid;
    gap: 8px;
    margin-bottom: 12px;
  }
  
  .mode-option {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: #d7def3;
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 6px;
    transition: background-color 0.2s ease;
  }
  
  .mode-option:hover {
    background: rgba(255, 255, 255, 0.05);
  }
  
  .mode-option input[type="radio"] {
    accent-color: var(--accent);
  }
  
  .difficulty-selector {
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 12px;
    margin-top: 12px;
  }
  
  .difficulty-options {
    display: grid;
    gap: 6px;
  }
  
  .difficulty-option {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #d7def3;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    transition: background-color 0.2s ease;
  }
  
  .difficulty-option:hover {
    background: rgba(255, 255, 255, 0.05);
  }
  
  .difficulty-option input[type="radio"] {
    accent-color: var(--accent-2);
  }
  
  .color-selector {
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 12px;
    margin-top: 12px;
  }
  
  .color-options {
    display: grid;
    gap: 6px;
  }
  
  .color-option {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #d7def3;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    transition: background-color 0.2s ease;
  }
  
  .color-option:hover {
    background: rgba(255, 255, 255, 0.05);
  }
  
  .color-option input[type="radio"] {
    accent-color: var(--accent);
  }
  
  .move-list { margin: 0; padding-left: 22px; max-height: 42vh; overflow: auto; }
  .move-list li { margin: 4px 0; color: #d7def3; }
  
  /* Captures panel */
  .captures-row { display: grid; grid-template-columns: 1fr; gap: 12px; }
  .cap-section { display: grid; gap: 6px; }
  .cap-title { color: #d7def3; font-size: 14px; display: flex; justify-content: space-between; }
  .cap-score { color: var(--muted); }
  .cap-list { display: flex; flex-wrap: wrap; gap: 6px; min-height: 28px; }
  .cap-list img { width: 48px; height: 48px; image-rendering: auto; filter: grayscale(0.1) contrast(1.05); }
  
  /* Use pixelated rendering only for Pokemon pieces (PNG) in captured list */
  .cap-list img[src*="pokemon"] { image-rendering: pixelated; }
  
  /* Controls */
  .toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: #d7def3; }
  .toggle input { accent-color: var(--accent); }
  
  .set-info { color: var(--muted); margin-bottom: 8px; }
  .set-map { display: grid; grid-template-columns: 1fr; gap: 4px; color: #d7def3; font-size: 14px; }
  
  /* Footer removed */
  
@media (max-width: 1120px) {
  .app {
    grid-template-areas: 
      "header"
      "mobile-top"
      "board"
      "sidebar-left"
      "sidebar-right";
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto auto auto;
    padding: 0;
  }
  
  .mobile-top-cards { 
    grid-area: mobile-top; 
    display: grid; 
    gap: 16px; 
  }
  
  .board-wrap { 
    place-self: center; 
    margin-bottom: 2px; 
  }
  
  .sidebar-left,
  .sidebar-right {
    margin-top: 0;
  }

  /* Hide status panel on mobile */
  .status-panel { display: none; }
  /* Hide moves panel on mobile */
  .panel.moves { display: none; }
  /* Hide titles for Game Mechanics and Captures on mobile */
  .hint-panel .panel-title,
  .captures .panel-title { display: none; }
  
  /* Center buttons horizontally on mobile */
  .controls-row {
    justify-content: center;
  }
  
  /* Center checkbox items horizontally on mobile */
  .controls-row .toggle {
    justify-content: center;
  }
  
  /* Hide the entire controls-row containing export and import game buttons on mobile */
  .panel.controls .controls-row:nth-child(2) {
    display: none;
  }
  
  /* Hide the controls-row containing checkboxes in hint-panel on mobile */
  .hint-panel .controls-row:nth-child(3) {
    display: none;
  }
  
  /* Vertically center buttons in panels on mobile */
  .panel.controls,
  .panel.hint-panel {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }
  
  /* Center modal buttons on mobile */
  .modal-body > div[style*="justify-content:center"] {
    justify-content: center !important;
  }
  
  /* Center mode options, difficulty options, and color options on mobile */
  .mode-selector,
  .difficulty-options,
  .color-options {
    justify-content: center;
    align-items: center;
  }
  
  .mode-option,
  .difficulty-option,
  .color-option {
    justify-content: center;
  }
}
  
  /* Analysis modal */
  .modal-overlay { position: fixed; inset: 0; background: transparent; display: grid; place-items: center; z-index: 2000; }
  
  /* Dark backdrop overlay for modals */
  .modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1999;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
  }
  
  .modal-backdrop.show {
    opacity: 1;
    pointer-events: auto;
  }
  .modal { max-height: 96vh; overflow: hidden; border-radius: 14px; background: var(--card); border: 2px solid #ffffff; box-shadow: var(--shadow-lg); display: grid; grid-template-rows: auto 1fr; font-size: 15px; line-height: 1.5; }
  .modal-header { 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    padding: 12px 16px; 
    border-bottom: 1px solid rgba(255,255,255,0.08); 
    position: relative; 
  }
  .modal-title { font-weight: 600; }
  /* Close button styling */
  .close-btn { 
    position: absolute;
    top: 50%;
    right: 16px;
    transform: translateY(-50%);
    width: 32px; 
    height: 32px; 
    padding: 0; 
    border-radius: 50%; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    font-size: 24px; 
    font-weight: bold; 
    background: rgba(255,255,255,0.1); 
    border: 1px solid rgba(255,255,255,0.2); 
    color: var(--text); 
    cursor: pointer; 
    transition: all 200ms ease; 
  }
  .close-btn:hover { 
    background: rgba(255,255,255,0.2); 
    transform: translateY(-50%) scale(1.1); 
  }
  .tabs { display: flex; gap: 8px; }
  .tab { background: #1a2033; border: 1px solid rgba(255,255,255,0.12); color: var(--text); padding: 6px 10px; border-radius: 8px; cursor: pointer; }
  .tab.active { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: none; }
  .modal-body { display: grid; gap: 16px; padding: 14px; overflow-y: auto; }
  .analysis-left { display: grid; grid-template-rows: 1fr auto auto; gap: 10px; }
  .analysis-board { --square-size: clamp(56px, 7.5vh, 92px); display: grid; grid-template-columns: repeat(8, var(--square-size)); grid-auto-rows: var(--square-size); background: #0e1526; border-radius: 10px; padding: 0 8px 0 0; gap: 0; position: relative; align-self: start; justify-self: center; width: calc(var(--square-size) * 8 + 8px); }
  .analysis-square { width: 100%; height: 100%; display: grid; place-items: center; }
  .analysis-square.light { background: var(--square-light); }
  .analysis-square.dark { background: var(--square-dark); }
  .analysis-square.hint-from { box-shadow: inset 0 0 0 4px rgba(72, 255, 158, 0.95); }
  .analysis-square.hint-to { box-shadow: inset 0 0 0 4px rgba(72, 255, 158, 0.7); }
  .analysis-square.bad-from { box-shadow: inset 0 0 0 4px rgba(255, 90, 90, 0.95); }
  .analysis-square.bad-to { box-shadow: inset 0 0 0 4px rgba(255, 90, 90, 0.7); }
  /* Dual outlines when best and played share a square: red inner (3px), green outer (6px) */
  .analysis-square.hint-from.bad-from,
  .analysis-square.bad-from.hint-from,
  .analysis-square.hint-to.bad-to,
  .analysis-square.bad-to.hint-to,
  .analysis-square.hint-from.bad-to,
  .analysis-square.bad-to.hint-from,
  .analysis-square.hint-to.bad-from,
  .analysis-square.bad-from.hint-to { box-shadow: inset 0 0 0 3px rgba(255, 90, 90, 0.95), inset 0 0 0 6px rgba(72, 255, 158, 0.95); }
  /* Puzzle wrong move highlights on main board */
  .square.bad-from { box-shadow: inset 0 0 0 4px rgba(255, 90, 90, 0.95); z-index: 6; }
  .square.bad-to { box-shadow: inset 0 0 0 4px rgba(255, 90, 90, 0.7); z-index: 6; }
  
  /* Puzzle move feedback icons */
  .puzzle-feedback {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    z-index: 10;
    opacity: 0;
    transform: scale(0.5);
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
  }
  
  .puzzle-feedback.show {
    opacity: 1;
    transform: scale(1);
  }
  
  .puzzle-feedback.correct {
    background: #22c55e;
    color: white;
    box-shadow: 0 2px 8px rgba(34, 197, 94, 0.4);
  }
  
  .puzzle-feedback.incorrect {
    background: #ef4444;
    color: white;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4);
  }
  /* Dual outlines when best and played share a square on main board: red inner (3px), green outer (6px) */
  .square.hint-from.bad-from,
  .square.bad-from.hint-from,
  .square.hint-to.bad-to,
  .square.bad-to.hint-to,
  .square.hint-from.bad-to,
  .square.bad-to.hint-from,
  .square.hint-to.bad-from,
  .square.bad-from.hint-to { box-shadow: inset 0 0 0 3px rgba(255, 90, 90, 0.95), inset 0 0 0 6px rgba(72, 255, 158, 0.9); }
  .analysis-piece { width: 100%; height: 100%; object-fit: contain; image-rendering: auto; }
  
  /* Use pixelated rendering only for Pokemon pieces (PNG) in analysis */
  .analysis-piece[src*="pokemon"] { image-rendering: pixelated; }
  .analysis-piece.light-side { filter: grayscale(1) brightness(1.35) contrast(0.95); }
  .analysis-piece.dark-side { filter: grayscale(1) brightness(0.6) contrast(1.2); }
  .analysis-controls { display: flex; align-items: center; justify-content: center; gap: 10px; }
  .ply-label { color: var(--muted); font-size: 14px; }
  .tag-label { text-align: center; color: #d7def3; min-height: 22px; }
  .analysis-right { display: grid; grid-template-rows: auto auto 1fr; gap: 10px; }
  .category-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  /* Center category nav under the grid and bring buttons closer */
  .category-nav { display: grid; grid-template-columns: auto auto auto; justify-content: center; align-items: center; gap: 8px; margin-top: 8px; }
  #analysisCatPrev, #analysisCatNext { padding: 6px 10px; }
  #analysisCatLabel { min-width: 48px; text-align: center; }
  /* Space the event list a bit below the nav */
  .event-list { margin-top: 8px; }

  /* Responsive analysis modal layout for iPad Pro and narrower */
  @media (max-width: 1120px) {
    .modal { width: 96vw; max-height: 96vh; }
    .modal-body { grid-template-columns: 1fr; overflow-y: auto; }
    .analysis-left { order: 1; }
    .analysis-right { order: 2; }
    /* Make analysis board fill available width with proper squares */
    .analysis-board { --square-size: clamp(44px, calc((96vw - 48px) / 8), 88px); width: calc(var(--square-size) * 8 + 8px); }
    .category-grid { grid-template-columns: repeat(2, 1fr); }
    .event-list { max-height: 40vh; }
  }
  .category-chip { background: #1a2033; border: 1px solid rgba(255,255,255,0.12); border-radius: 8px; padding: 8px; font-size: 12px; cursor: pointer; display: flex; align-items: center; justify-content: space-between; }
  .category-chip .count { color: var(--muted); }

  /* Category color coding */
  .category-chip.cat-brilliant { background: linear-gradient(135deg, #1a3321, #1f6b3a); border-color: rgba(60, 255, 170, 0.35); }
  .category-chip.cat-best-move { background: linear-gradient(135deg, #182c3a, #1e6391); border-color: rgba(64, 174, 255, 0.35); }
  .category-chip.cat-excellent { background: linear-gradient(135deg, #231a3a, #5a35a4); border-color: rgba(160, 120, 255, 0.35); }
  .category-chip.cat-good { background: linear-gradient(135deg, #1a2f33, #2fa3b8); border-color: rgba(32, 212, 255, 0.35); }
  .category-chip.cat-book-move { background: linear-gradient(135deg, #2a2a1c, #807a28); border-color: rgba(255, 235, 120, 0.35); }
  .category-chip.cat-inaccuracy { background: linear-gradient(135deg, #372b12, #8a6c19); border-color: rgba(255, 197, 61, 0.4); }
  .category-chip.cat-mistake { background: linear-gradient(135deg, #3a2418, #a1411c); border-color: rgba(255, 136, 76, 0.45); }
  .category-chip.cat-blunder { background: linear-gradient(135deg, #3a1717, #9b1e1e); border-color: rgba(255, 80, 80, 0.5); }
  .category-chip.cat-missed-win { background: linear-gradient(135deg, #3a131a, #a1173f); border-color: rgba(255, 64, 128, 0.5); }

  .category-chip.cat-brilliant span,
  .category-chip.cat-best-move span,
  .category-chip.cat-excellent span,
  .category-chip.cat-good span,
  .category-chip.cat-book-move span,
  .category-chip.cat-inaccuracy span,
  .category-chip.cat-mistake span,
  .category-chip.cat-blunder span,
  .category-chip.cat-missed-win span { color: #eaf3ff; }
  .event-list { background: var(--card); border: 1px solid rgba(255,255,255,0.08); border-radius: 8px; padding: 8px; overflow: auto; max-height: 50vh; }
  .event-item { padding: 6px 8px; border-radius: 6px; cursor: pointer; display: grid; grid-template-columns: auto 1fr auto; gap: 10px; }
  .event-item:hover { background: rgba(255,255,255,0.06); }
  .event-item .ply { color: var(--muted); font-size: 12px; }
  .event-item .desc { color: #d7def3; font-size: 14px; }
  .event-item .tag { font-weight: 600; }
  .event-item.active { background: rgba(124, 92, 255, 0.18); border: 1px solid rgba(124, 92, 255, 0.35); }
  /* Wide tooltip for move analyses */
  .tooltip-wide {
    position: fixed;
    z-index: 3000;
    width: auto;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    background: #0f162a;
    color: #eaf3ff;
    border: 1px solid rgba(255,255,255,0.16);
    box-shadow: 0 10px 30px rgba(0,0,0,0.45);
    padding: 12px 14px;
    border-radius: 10px;
    font-size: 13.5px;
    line-height: 1.35;
    pointer-events: auto;
  }

  /* Pawn Promotion Modal */
  .promotion-modal {
    width: min(360px, 90vw);
    max-height: auto;
    z-index: 3000;
  }

  #promotionModal {
    z-index: 3000 !important;
  }

  .promotion-body {
    padding: 16px;
    display: grid;
    place-items: center;
  }

  .promotion-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    width: 100%;
    max-width: 280px;
  }

  .promotion-option {
    background: rgba(255,255,255,0.06);
    border: 2px solid rgba(255,255,255,0.12);
    color: var(--text);
    padding: 12px 8px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 200ms ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    min-height: 100px;
    aspect-ratio: 1;
  }

  .promotion-option:hover {
    transform: translateY(-2px);
    background: rgba(255,255,255,0.1);
    border-color: var(--accent);
    box-shadow: 0 8px 25px rgba(124, 92, 255, 0.25);
  }

  .promotion-option:active {
    transform: translateY(0);
  }

  .promotion-piece-img {
    width: 80px;
    height: 80px;
    object-fit: contain;
    image-rendering: auto;
  }
  
  /* Use pixelated rendering only for Pokemon pieces (PNG) in promotion */
  .promotion-piece-img[src*="pokemon"] {
    image-rendering: pixelated;
  }

  .promotion-option span {
    font-weight: 600;
    font-size: 14px;
    text-align: center;
  }

  /* Mobile responsive for promotion modal */
  @media (max-width: 480px) {
    .promotion-options {
      grid-template-columns: repeat(4, 1fr);
      gap: 12px;
    }

    .promotion-option {
      padding: 12px 8px;
      min-height: 100px;
    }

    .promotion-piece-img {
      width: 48px;
      height: 48px;
      image-rendering: auto;
    }
    
    /* Use pixelated rendering only for Pokemon pieces (PNG) in mobile promotion */
    .promotion-piece-img[src*="pokemon"] {
      image-rendering: pixelated;
    }

    .promotion-option span {
      font-size: 12px;
    }
  }
  
  /* Export/Import buttons styling */
  #exportGame, #importGame, #gameInfo {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: var(--text);
    transition: all 200ms ease;
  }
  
  #exportGame:hover, #importGame:hover, #gameInfo:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: var(--accent);
    transform: translateY(-1px);
  }
  
  #exportGame:active, #importGame:active, #gameInfo:active {
    transform: translateY(0);
  }

  
  /* Save status indicator styling */
  #subStatus[data-save-handler-added="true"] {
    cursor: pointer;
    text-decoration: underline;
    text-decoration-style: dotted;
    transition: all 200ms ease;
  }
  
  #subStatus[data-save-handler-added="true"]:hover {
    color: var(--accent);
    text-decoration-color: var(--accent);
  }
  