:root {
      --bg-main: #111827;
      --card-bg: #1f2937;
      --board-bg: #f5e6ca;
      --p1-color: #2563eb;
      --p2-color: #dc2626;
      --accent-cyan: #0ea5e9;
      --accent-red: #ef4444;
      --accent-green: #16a34a;
    }

    * { box-sizing: border-box; }

    html, body {
      margin: 0;
      padding: 0;
      width: 100%;
      height: 100vh;
      background-color: var(--bg-main);
      color: #f3f4f6;
      font-family: system-ui, -apple-system, sans-serif;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      overflow: hidden;
      user-select: none;
      -webkit-user-select: none;
    }

    #gif-overlay {
      position: fixed;
      top: 0; left: 0;
      width: 100vw; height: 100vh;
      background-color: #0d1117;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      z-index: 999;
      transition: opacity 0.8s ease-out;
    }

    #gif-overlay img {
      max-width: 85vw; max-height: 80vh;
      border-radius: 12px;
      box-shadow: 0 10px 30px rgba(0,0,0,0.8);
      object-fit: contain;
    }

    #gif-overlay .splash-txt {
      margin-top: 16px;
      font-size: 1.1rem;
      font-weight: bold;
      color: #38bdf8;
      letter-spacing: 1px;
    }

    #game-container {
      position: relative;
      background-color: var(--board-bg);
      border: 4px solid #374151;
      border-radius: 8px;
      box-shadow: 0 10px 25px rgba(0,0,0,0.5);
      max-width: 100vw; max-height: 100vh;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
    }

    canvas {
      display: block;
      cursor: pointer;
      max-width: 100vw; max-height: 100vh;
      object-fit: contain;
    }

    /* Interactive Bottom Footer Bar */
    #board-footer {
      position: absolute;
      bottom: 6px;
      left: 0;
      width: 100%;
      text-align: center;
      font-size: 11px;
      font-weight: 600;
      color: #4b5563;
      z-index: 20;
      pointer-events: auto;
    }
    #board-footer a {
      color: #1d4ed8;
      text-decoration: none;
      margin: 0 6px;
      cursor: pointer;
    }
    #board-footer a:hover {
      text-decoration: underline;
      color: #0284c7;
    }

    .icon-btn {
      position: absolute;
      width: 38px; height: 38px;
      background-color: #374151;
      border: 2px solid #38bdf8;
      border-radius: 50%;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      box-shadow: 0 4px 8px rgba(0,0,0,0.4);
      transform: translate(-50%, -50%);
      z-index: 10;
      transition: transform 0.15s, background-color 0.2s;
    }
    .icon-btn:hover {
      background-color: #0ea5e9;
      transform: translate(-50%, -50%) scale(1.1);
    }
    .icon-btn svg {
      width: 22px; height: 22px;
      fill: none; stroke: #ffffff;
      stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round;
    }

    #menu-overlay {
      display: flex;
      position: absolute;
      top: 5%; left: 12.5%;
      width: 75%; height: 36%;
      background: rgba(17, 24, 39, 0.96);
      backdrop-filter: blur(4px);
      border: 3px solid #38bdf8;
      border-radius: 8px;
      box-shadow: 0 12px 30px rgba(0,0,0,0.7);
      z-index: 100;
      flex-direction: column;
      padding: 12px 16px;
      box-sizing: border-box;
      overflow-y: auto;
    }

    #menu-overlay h2 {
      margin: 0 0 8px 0;
      color: #38bdf8;
      font-size: 1.1rem;
      text-align: center;
      border-bottom: 1px solid #374151;
      padding-bottom: 4px;
    }

    .menu-group {
      margin-bottom: 8px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      font-size: 0.85rem;
    }

    .menu-group label {
      font-weight: 600;
      color: #e5e7eb;
    }

    .menu-group select, .menu-group input[type="checkbox"] {
      padding: 3px 6px;
      border-radius: 4px;
      background: #374151;
      color: white;
      border: 1px solid #4b5563;
      cursor: pointer;
      font-size: 0.8rem;
    }

    .menu-actions {
      display: flex;
      flex-direction: column;
      gap: 6px;
      margin-top: 6px;
    }

    .menu-actions button {
      padding: 6px;
      font-weight: bold;
      border: none;
      border-radius: 4px;
      cursor: pointer;
      color: white;
      background-color: #4b5563;
      font-size: 0.8rem;
    }
    .menu-actions button:hover { opacity: 0.9; }
    .menu-actions .btn-start { background-color: var(--accent-green); font-size: 0.9rem; }

    #instructions-modal {
      display: none;
      position: fixed;
      top: 50%; left: 50%;
      transform: translate(-50%, -50%);
      width: 90%; max-width: 500px; max-height: 85vh;
      background-color: var(--card-bg);
      border: 3px solid #38bdf8;
      border-radius: 8px;
      padding: 18px;
      z-index: 200;
      box-shadow: 0 10px 30px rgba(0,0,0,0.8);
      overflow-y: auto;
      font-size: 0.85rem;
      line-height: 1.4;
    }
    #instructions-modal h3 { margin-top: 0; color: #38bdf8; }
    #instructions-modal button {
      margin-top: 12px;
      background-color: var(--accent-cyan);
      color: white; border: none;
      padding: 6px 14px; border-radius: 4px;
      cursor: pointer; font-weight: bold;
    }

    /* Compact Movable Pieces Pool Window (Middle of Blue Board) */
    #pool-modal {
      display: block;
      position: absolute;
      top: 63%;
      left: 30%;
      width: 40%;
      background: rgba(17, 24, 39, 0.95);
      border: 2px solid #0ea5e9;
      border-radius: 6px;
      padding: 5px;
      z-index: 150;
      box-shadow: 0 6px 16px rgba(0,0,0,0.75);
      touch-action: none;
      transition: opacity 0.15s ease;
    }
    #pool-modal.dragging {
      opacity: 0.45;
    }
    #pool-top-bar {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 4px;
      background: rgba(30, 41, 59, 0.95);
      border-bottom: 1px solid #374151;
      border-radius: 3px;
      padding: 3px 4px;
      margin-bottom: 4px;
    }
    #pool-header {
      flex: 1;
      cursor: move;
      color: #38bdf8;
      font-size: 0.64rem;
      font-weight: 700;
      text-align: left;
      line-height: 1.15;
    }
    #btnAutoFillPool {
      background-color: var(--accent-green);
      color: #ffffff;
      border: 1px solid #86efac;
      border-radius: 3px;
      padding: 2px 5px;
      font-size: 0.6rem;
      font-weight: 700;
      cursor: pointer;
      white-space: nowrap;
      flex-shrink: 0;
    }
    #btnAutoFillPool:hover {
      background-color: #15803d;
    }
    .pool-grid {
      display: grid;
      grid-template-columns: repeat(4, 1fr);
      gap: 3px;
    }
    .pool-card {
      background: #2563eb;
      color: white;
      border: 1px solid #ffffff;
      border-radius: 3px;
      padding: 2px 1px;
      text-align: center;
      font-weight: bold;
      font-size: 0.64rem;
      line-height: 1.05;
      cursor: pointer;
      transition: transform 0.1s, background-color 0.15s;
    }
    .pool-card:hover {
      background-color: #1d4ed8;
      transform: scale(1.04);
    }
    .pool-card.active-piece {
      background-color: #eab308;
      color: #111827;
      border-color: #fef08a;
    }
    .pool-card.disabled {
      background: #4b5563;
      opacity: 0.4;
      cursor: not-allowed;
      border-color: #6b7280;
    }

    #file-input { display: none; }