    :root {
      color-scheme: light;
      --bg: #f4f0e7;
      --bg2: #f2eadc;
      --panel: rgba(242, 234, 220, 0.9);
      --panel2: rgba(246, 239, 226, 0.96);
      --border: #d8cfbf;
      --text: #22231f;
      --muted: #69685f;
      --accent: #234b3d;
      --wood: #a7653c;
      --brass: #b28a4a;
      --board-light-rgb: 239 209 166;
      --board-dark-rgb: 166 93 56;
      --light: #efd1a6;
      --dark: #a65d38;
      --move: rgba(178, 138, 74, 0.32);
      --select: rgba(35, 75, 61, 0.3);
      --legal: rgba(35, 75, 61, 0.2);
      --body-gradient:
        radial-gradient(circle at 20% 12%, rgba(246, 239, 226, 0.5), transparent 34%),
        radial-gradient(circle at 82% 88%, rgba(35, 75, 61, 0.13), transparent 38%),
        linear-gradient(rgba(244, 240, 231, 0.26), rgba(244, 240, 231, 0.5)),
        conic-gradient(
          from 90deg,
          rgb(var(--board-light-rgb) / 0.46) 25%,
          rgb(var(--board-dark-rgb) / 0.56) 0 50%,
          rgb(var(--board-light-rgb) / 0.46) 0 75%,
          rgb(var(--board-dark-rgb) / 0.56) 0
        );
      --surface: rgba(242, 234, 220, 0.9);
      --shadow: 0 22px 70px rgba(34, 35, 31, 0.13);
      --button-start: #234b3d;
      --button-end: #234b3d;
      --header-bg: #dfe7db;
      --row-hover: rgba(35, 75, 61, 0.08);
      --row-active-start: rgba(223, 231, 219, 0.98);
      --row-active-end: rgba(246, 239, 226, 0.98);
      --variation-border: rgba(167, 101, 60, 0.54);
      --variation-bg: rgba(223, 231, 219, 0.56);
      --variation-text: #234b3d;
      --variation-text-hover: #a7653c;
    }
    * { box-sizing: border-box; }
    html, body { margin: 0; padding: 0; }
    html {
      scrollbar-gutter: stable;
    }
    body {
      min-height: 100vh;
      overflow-y: scroll;
      font-family: Georgia, "Times New Roman", serif;
      background-color: var(--bg);
      background: var(--body-gradient);
      background-size: auto, auto, auto, 160px 160px;
      color: var(--text);
    }
    .app {
      max-width: 1680px;
      margin: 0 auto;
      padding: 18px;
      display: grid;
      gap: 18px;
    }
    .topbar, .panel {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 0;
      box-shadow: var(--shadow);
      backdrop-filter: blur(10px);
    }
    .topbar {
      position: relative;
      z-index: 30;
      padding: 18px 20px;
      display: flex;
      align-items: flex-start;
      justify-content: space-between;
      gap: 16px;
    }
    .topbar h1 { margin: 0; color: var(--accent); font-size: 28px; }
    .topbar p { margin: 4px 0 0; color: var(--muted); }
    .topbar-actions {
      margin-left: auto;
      flex-shrink: 0;
      display: flex;
      gap: 10px;
      align-items: center;
    }
    .toolbar { display: none; }
    .mobile-games-toggle,
    .mobile-panel-head {
      display: none;
    }
    button, .action-link {
      border: 1px solid var(--border);
      background: transparent;
      color: var(--accent);
      border-radius: 0;
      padding: 11px 16px;
      font-size: 15px;
      cursor: pointer;
      text-decoration: none;
      display: inline-flex;
      align-items: center;
      gap: 8px;
      transition: .18s ease;
    }
    button:hover, .action-link:hover {
      border-color: var(--accent);
      background: rgba(35, 75, 61, 0.08);
      transform: translateY(-1px);
    }
    button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
    .layout {
      display: grid;
      grid-template-columns: minmax(520px, 1.35fr) minmax(420px, 760px) 420px;
      gap: 18px;
      align-items: start;
    }
    .panel { padding: 18px; min-width: 0; }
    .panel h2 { margin: 0 0 14px; font-size: 18px; }
    .games-list {
      max-height: calc(100vh - 180px);
      overflow: auto;
      border: 1px solid var(--border);
      border-radius: 0;
      background: var(--panel2);
    }
    .games-table {
      width: max-content;
      min-width: 100%;
      border-collapse: collapse;
      font-size: 13px;
    }
    .games-table th,
    .games-table td {
      padding: 10px 12px;
      border-bottom: 1px solid var(--border);
      vertical-align: top;
      white-space: nowrap;
    }
    .games-table th {
      position: sticky;
      top: 0;
      z-index: 1;
      background: var(--header-bg);
      color: var(--muted);
      font-size: 12px;
      font-family: Arial, Helvetica, sans-serif;
      text-transform: uppercase;
      letter-spacing: .03em;
    }
    .games-table tbody tr {
      cursor: pointer;
      transition: background .18s ease;
    }
    .games-table tbody tr:hover {
      background: var(--row-hover);
    }
    .games-table tbody tr.active {
      background: linear-gradient(180deg, var(--row-active-start), var(--row-active-end));
      box-shadow: inset 4px 0 0 var(--accent);
    }
    .games-table td.numeric {
      text-align: right;
      font-variant-numeric: tabular-nums;
    }
    .games-table th:first-child,
    .games-table td.index-cell {
      width: 30px;
      min-width: 30px;
      padding-left: 4px;
      padding-right: 1px;
      text-align: left;
    }
    .games-table th:nth-child(2),
    .games-table td:nth-child(2) {
      padding-left: 5px;
    }
    .games-table td.event-cell {
      white-space: normal;
      min-width: 240px;
      line-height: 1.35;
    }
    .games-table th:nth-child(4),
    .games-table td:nth-child(4) {
      padding-right: 3px;
    }
    .games-table th:nth-child(5),
    .games-table td:nth-child(5) {
      padding-left: 3px;
    }
    .table-sort-btn {
      appearance: none;
      -webkit-appearance: none;
      background: none;
      border: none;
      border-radius: 0;
      box-shadow: none;
      color: inherit;
      padding: 0;
      min-width: 0;
      font: inherit;
      letter-spacing: inherit;
      text-transform: inherit;
      cursor: pointer;
      transform: none;
    }
    .table-sort-btn:hover {
      color: var(--text);
      background: none;
      border: none;
      transform: none;
    }
    .table-sort-btn.active {
      color: var(--accent);
      font-weight: 700;
    }
    .subline, .meta-line, .small-note { color: var(--muted); font-size: 13px; }
    .subline { margin-top: 5px; }
    .board-col { display: grid; gap: 14px; }
    .board-stage {
      display: grid;
      gap: 14px;
    }
    .board-shell {
      position: relative;
      width: min(100%, 700px, calc(100vh - 340px));
      max-width: 100%;
      margin: 0 auto;
      padding-right: 28px;
    }
    .board-head {
      display: grid;
      gap: 6px;
      min-height: 72px;
      align-content: start;
    }
    .board-title {
      font-size: 18px;
      font-weight: 700;
      line-height: 1.3;
      overflow-wrap: anywhere;
    }
    .board-subtitle { color: var(--muted); line-height: 1.45; }
    .board {
      width: 100%;
      max-width: 100%;
      aspect-ratio: 1 / 1;
      display: grid;
      grid-template-columns: repeat(8, 1fr);
      grid-template-rows: repeat(8, 1fr);
      border-radius: 0;
      overflow: hidden;
      border: 1px solid var(--border);
      background: var(--wood);
      touch-action: none;
      user-select: none;
      margin: 0 auto;
      align-self: start;
    }
    .board-resize-handle {
      position: absolute;
      right: 6px;
      bottom: -12px;
      width: 24px;
      height: 24px;
      min-width: 24px;
      padding: 0;
      border-radius: 999px;
      border: 1px solid var(--border);
      background: var(--bg2);
      box-shadow: 0 8px 18px rgba(34,35,31,.14);
      cursor: nwse-resize;
      z-index: 3;
    }
    .board-resize-handle::before {
      content: "";
      width: 9px;
      height: 9px;
      border-right: 2px solid var(--accent);
      border-bottom: 2px solid var(--accent);
      transform: rotate(0deg);
      display: block;
      margin: 5px 0 0 5px;
    }
    .board-shell.resizing .board-resize-handle {
      border-color: var(--accent);
      box-shadow: 0 0 0 4px rgba(35,75,61,.14), 0 8px 18px rgba(34,35,31,.14);
    }
    .square {
      position: relative;
      display: flex;
      align-items: center;
      justify-content: center;
    }
    .square.light { background: var(--light); }
    .square.dark { background: var(--dark); }
    .square.last::before,
    .square.selected::before,
    .square.legal::after {
      content: "";
      position: absolute;
      inset: 0;
      pointer-events: none;
    }
    .square.last::before { background: var(--move); }
    .square.selected::before { background: var(--select); }
    .square.legal::after {
      inset: 28%;
      border-radius: 999px;
      background: var(--legal);
      box-shadow: inset 0 0 0 2px rgba(35,75,61,.18);
    }
    .coord {
      position: absolute;
      font-size: 11px;
      font-weight: 700;
      opacity: .85;
      pointer-events: none;
    }
    .coord.file { right: 5px; bottom: 4px; }
    .coord.rank { left: 5px; top: 4px; }
    .square.light .coord { color: rgba(105, 77, 48, 0.92); }
    .square.dark .coord { color: rgba(246, 230, 209, 0.95); }
    .piece {
      width: 84%;
      height: 84%;
      object-fit: contain;
      pointer-events: none;
      -webkit-user-drag: none;
      filter: drop-shadow(0 1px 1px rgba(0,0,0,.22));
    }
    .board-actions, .nav-actions {
      display: flex;
      gap: 10px;
      flex-wrap: wrap;
    }
    .status-grid {
      display: grid;
      grid-template-columns: repeat(2, minmax(0, 1fr));
      gap: 10px;
    }
    .status-card {
      background: var(--panel2);
      border: 1px solid var(--border);
      border-radius: 0;
      padding: 10px 12px;
    }
    .status-card .label { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
    .status-card .value { font-size: 14px; word-break: break-word; }
    .moves-col {
      display: grid;
      gap: 14px;
      align-content: start;
      min-width: 0;
    }
    .analysis-box {
      order: -2;
    }
    .moves-wrap {
      order: -1;
    }
    .moves-controls {
      order: 0;
    }
    .analysis-box {
      background: var(--panel2);
      border: 1px solid var(--border);
      border-radius: 0;
      padding: 14px;
      display: grid;
      gap: 8px;
      align-content: start;
      min-width: 0;
    }
    .analysis-head {
      display: grid;
      align-items: start;
      gap: 12px;
      min-width: 0;
    }
    .analysis-head > * {
      min-width: 0;
    }
    .analysis-line {
      font-size: 15px;
      min-width: 0;
      overflow-wrap: anywhere;
    }
    .analysis-controls {
      display: inline-flex;
      gap: 10px;
      align-items: center;
      flex-wrap: nowrap;
      justify-content: start;
      min-width: 0;
    }
    .analysis-mode-grid {
      display: grid;
      grid-template-columns: repeat(2, minmax(44px, auto));
      gap: 8px;
      align-items: center;
    }
    .analysis-lines-control {
      display: grid;
      gap: 4px;
      min-width: 140px;
    }
    .analysis-lines-label {
      color: var(--muted);
      font-size: 12px;
      line-height: 1.2;
    }
    .analysis-lines-row {
      display: grid;
      grid-template-columns: 96px auto;
      gap: 8px;
      align-items: center;
    }
    .analysis-mode-btn,
    .analysis-icon-btn {
      min-width: 44px;
      padding: 8px 10px;
      justify-content: center;
      font-size: 14px;
      line-height: 1;
    }
    .analysis-icon-btn {
      font-size: 16px;
      padding-top: 7px;
      padding-bottom: 7px;
    }
    .analysis-lines-range {
      width: 100%;
      accent-color: var(--accent);
    }
    .analysis-lines-value {
      min-width: 22px;
      text-align: center;
      font-size: 13px;
      color: var(--text);
    }
    .analysis-mode-btn.active {
      border-color: var(--accent);
      background: var(--accent);
      color: var(--bg2);
    }
    .pv-line {
      color: var(--muted);
      line-height: 1.5;
      font-size: 13px;
      min-height: calc(1.5em * 4);
      max-height: calc(1.5em * 4);
      overflow: auto;
      white-space: pre-line;
      scrollbar-gutter: stable;
      overflow-wrap: anywhere;
    }
    .moves-wrap {
      background: var(--panel2);
      border: 1px solid var(--border);
      border-radius: 0;
      padding: 10px;
      max-height: calc(100vh - 360px);
      overflow: auto;
      scrollbar-gutter: stable;
      min-width: 0;
    }
    .move-row {
      display: grid;
      grid-template-columns: 34px 1fr 1fr;
      gap: 8px;
      margin-bottom: 8px;
      align-items: center;
    }
    .move-no { color: var(--muted); text-align: right; padding-right: 4px; }
    .move-btn {
      width: 100%;
      justify-content: flex-start;
      padding: 9px 12px;
      border-radius: 0;
      font-weight: 600;
    }
    .move-btn.current {
      border-color: var(--accent);
      background: var(--accent);
      color: var(--bg2);
    }
    .variation-block {
      margin: -2px 0 10px 42px;
      padding: 10px 12px;
      border-left: 3px solid var(--variation-border);
      background: var(--variation-bg);
      border-radius: 10px;
      line-height: 1.9;
      font-size: 0;
    }
    .variation-group {
      display: inline;
      white-space: normal;
    }
    .variation-paren,
    .variation-prefix {
      color: var(--muted);
      font-size: 13px;
      font-weight: 700;
      margin-right: 6px;
    }
    .variation-paren {
      margin-right: 4px;
    }
    .variation-btn {
      appearance: none;
      -webkit-appearance: none;
      background: none;
      border: none;
      border-radius: 0;
      box-shadow: none;
      display: inline;
      padding: 0;
      min-width: 0;
      margin: 0 6px 0 0;
      vertical-align: baseline;
      font-size: 14px;
      font-weight: 600;
      color: var(--variation-text);
      cursor: pointer;
      transform: none;
      text-decoration: none;
    }
    .variation-btn:hover {
      color: var(--variation-text-hover);
      transform: none;
      border: none;
      background: none;
    }
    .variation-btn.current {
      color: var(--wood);
      text-decoration: underline;
      text-underline-offset: 2px;
    }

    .turn-dot {
      position: absolute;
      right: 4px;
      width: 16px;
      height: 16px;
      border-radius: 999px;
      border: 2px solid rgba(255,255,255,.28);
      box-shadow: 0 0 0 1px rgba(0,0,0,.18);
      opacity: .38;
      transition: .18s ease;
      z-index: 2;
      pointer-events: none;
    }
    .turn-dot.top { top: 10px; }
    .turn-dot.bottom { bottom: 10px; }
    .turn-dot.white { background: #f6f7fb; }
    .turn-dot.black { background: #11161f; }
    .turn-dot.active {
      opacity: 1;
      box-shadow: 0 0 0 1px rgba(34,35,31,.22), 0 0 12px rgba(35,75,61,.18);
      transform: scale(1.06);
    }
    .board-footer-actions {
      display: grid;
      grid-template-columns: auto auto auto auto;
      grid-template-areas:
        "prev flip fen next"
        ". download-game download-game .";
      gap: 10px;
      justify-content: center;
      align-items: center;
    }
    .board-footer-actions #prevGameBtn { grid-area: prev; }
    .board-footer-actions #flipBtn { grid-area: flip; }
    .board-footer-actions #copyFenBtn { grid-area: fen; }
    .board-footer-actions .download-menu-wrap { grid-area: download-game; }
    .board-footer-actions #nextGameBtn { grid-area: next; }
    .board-footer-actions #prevGameBtn,
    .board-footer-actions #nextGameBtn {
      min-width: 46px;
      padding-left: 12px;
      padding-right: 12px;
      justify-content: center;
      font-size: 18px;
      line-height: 1;
    }
    .button-icon {
      display: none;
    }
    .download-menu-wrap {
      position: relative;
      display: inline-flex;
      justify-content: center;
    }
    .download-menu {
      position: absolute;
      right: 0;
      bottom: calc(100% + 8px);
      z-index: 40;
      display: none;
      min-width: 168px;
      padding: 8px;
      border: 1px solid var(--border);
      background: var(--panel2);
      box-shadow: 0 16px 36px rgba(34, 35, 31, 0.18);
    }
    .download-menu.open {
      display: grid;
      gap: 6px;
    }
    .download-menu button {
      width: 100%;
      justify-content: flex-start;
      padding: 9px 10px;
      font-size: 13px;
    }
    .moves-controls {
      display: grid;
      grid-template-columns: 1fr auto 1fr;
      gap: 10px;
      align-items: center;
    }
    .moves-controls button {
      min-width: 46px;
      justify-content: center;
      padding: 11px 12px;
    }
    .moves-nav-group {
      grid-column: 2;
      display: flex;
      gap: 10px;
      justify-content: center;
    }
    .analysis-return-btn {
      grid-column: 3;
      justify-self: end;
      display: none;
      animation: pulseGlow 1.5s ease-in-out infinite;
    }
    .analysis-return-btn.visible { display: inline-flex; }
    @keyframes pulseGlow {
      0%, 100% { box-shadow: 0 0 0 rgba(105,167,255,0); }
      50% { box-shadow: 0 0 0 4px rgba(105,167,255,.14); }
    }
    .footer-note { color: var(--muted); font-size: 13px; line-height: 1.45; }
    .notice {
      color: var(--muted);
      background: var(--panel2);
      border: 1px dashed var(--border);
      border-radius: 0;
      padding: 12px 14px;
      line-height: 1.45;
      font-size: 13px;
    }
    @media (max-width: 1420px) {
      .layout { grid-template-columns: minmax(440px, 1.2fr) minmax(380px, 1fr) 360px; }
    }
    @media (max-width: 1180px) {
      .layout { grid-template-columns: 1fr; }
      .games-list, .moves-wrap { max-height: none; }
    }
    @media (max-width: 640px) {
      body {
        overflow-x: hidden;
      }
      .app {
        width: 100vw;
        max-width: 100vw;
        overflow-x: hidden;
        padding: 10px;
        gap: 10px;
      }
      .topbar,
      .layout,
      .panel {
        width: 100%;
        max-width: 100%;
      }
      .panel {
        padding: 12px;
        min-width: 0;
      }
      .topbar {
        display: grid;
        gap: 8px;
        padding: 10px 12px;
      }
      .topbar > div:first-child {
        min-width: 0;
      }
      .topbar h1 {
        padding-right: 0;
        font-size: 1rem;
        line-height: 1.15;
      }
      .topbar-actions {
        position: static;
        display: flex;
        justify-content: flex-end;
        gap: 8px;
        width: auto;
        height: auto;
        margin-left: 0;
        min-width: 0;
      }
      .mobile-games-toggle {
        display: inline-flex;
        position: static;
        width: 40px;
        min-width: 40px;
        height: 40px;
        min-height: 40px;
        justify-content: center;
        padding: 0;
        min-width: 0;
        color: var(--accent);
        font-size: 20px;
        line-height: 1;
      }
      .return-link {
        position: static;
        width: 40px;
        min-width: 40px;
        height: 40px;
        justify-content: center;
        padding: 0;
      }
      .return-link-text {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
      }
      .return-link-icon {
        font-size: 22px;
        line-height: 1;
      }
      .layout {
        gap: 10px;
        min-width: 0;
      }
      .board-col {
        order: 1;
      }
      .moves-col {
        order: 2;
      }
      .moves-wrap {
        order: 2;
      }
      .moves-controls {
        order: 1;
      }
      .analysis-box {
        order: 3;
      }
      .games-panel {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 80;
        order: 3;
        max-height: min(68vh, 560px);
        padding: 12px;
        border-right: 0;
        border-bottom: 0;
        border-left: 0;
        box-shadow: 0 -18px 42px rgba(34, 35, 31, 0.24);
        transform: translateY(calc(100% + 16px));
        transition: transform 180ms ease;
      }
      .app.games-list-open .games-panel {
        transform: translateY(0);
      }
      .mobile-panel-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        margin-bottom: 10px;
      }
      .mobile-panel-head h2 {
        margin: 0;
        color: var(--accent);
        font-size: 1rem;
      }
      .panel-close-btn {
        width: 38px;
        height: 38px;
        justify-content: center;
        padding: 0;
        font-size: 24px;
        line-height: 1;
      }
      .games-list {
        max-height: calc(min(68vh, 560px) - 62px);
      }
      .board-head {
        min-height: 0;
      }
      .board-title {
        font-size: 1rem;
      }
      .board-subtitle {
        font-size: 0.9rem;
      }
      .board-stage {
        grid-template-columns: minmax(0, 1fr) 44px;
        gap: 8px;
        align-items: start;
      }
      .board-shell {
        width: min(100%, calc(100vw - 96px));
        max-width: calc(100vw - 96px);
        padding-right: 0;
        margin: 0;
      }
      .board {
        width: 100%;
        min-width: 0;
      }
      .board-resize-handle {
        display: none;
      }
      .analysis-box {
        padding: 10px;
        gap: 7px;
      }
      .analysis-head {
        gap: 10px;
      }
      .analysis-line {
        font-size: 0.86rem;
      }
      .analysis-controls {
        display: grid;
        grid-template-columns: minmax(0, auto) minmax(0, 1fr);
        width: 100%;
        gap: 8px;
      }
      .analysis-mode-grid {
        grid-template-columns: repeat(4, minmax(38px, 1fr));
      }
      .analysis-lines-control {
        min-width: 0;
      }
      .analysis-lines-row {
        grid-template-columns: minmax(76px, 1fr) auto;
      }
      .pv-line {
        min-height: calc(1.35em * 3);
        max-height: calc(1.35em * 3);
        line-height: 1.35;
      }
      .moves-wrap {
        max-height: 188px;
      }
      .board-footer-actions {
        grid-template-columns: 42px;
        grid-template-areas:
          "flip"
          "download-game";
        gap: 8px;
        justify-content: stretch;
        align-content: start;
      }
      .board-footer-actions button,
      .moves-controls button {
        min-width: 0;
        padding: 10px 8px;
        justify-content: center;
        font-size: 0.82rem;
        white-space: normal;
      }
      .board-footer-actions #prevGameBtn,
      .board-footer-actions #nextGameBtn,
      .board-footer-actions #copyFenBtn {
        display: none;
      }
      .board-footer-actions #flipBtn,
      .board-footer-actions #downloadMenuToggle {
        width: 42px;
        height: 40px;
        padding: 0;
        font-size: 1rem;
      }
      .board-footer-actions .button-text {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
      }
      .board-footer-actions .button-icon {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-family: Arial, Helvetica, sans-serif;
        font-weight: 700;
        line-height: 1;
      }
      .download-menu {
        right: 0;
        bottom: auto;
        top: calc(100% + 8px);
        min-width: 150px;
      }
      .moves-controls {
        grid-template-columns: 1fr;
        gap: 8px;
      }
      .moves-nav-group {
        grid-column: 1;
        width: 100%;
        display: grid;
        grid-template-columns: 0.75fr 1.25fr 1.25fr 0.75fr;
        gap: 8px;
      }
      .moves-nav-group button {
        width: 100%;
        min-height: 42px;
        font-size: 1rem;
      }
      .moves-nav-group #prevBtn,
      .moves-nav-group #nextBtn {
        font-size: 1.12rem;
      }
      .analysis-return-btn {
        grid-column: 1;
        justify-self: end;
      }
    }
