 /* --- USER PROVIDED MAIN.CSS (Partial Snippets Preserved for Variables) --- */
        @counter-style parenthesisalplist {
            system: extends lower-alpha;
            suffix: ') ';
            prefix: '(';
        }
        @counter-style parenthesiscapalplist {
            system: extends upper-alpha;
            suffix: ') ';
            prefix: '(';
        }
        @counter-style parenthesisnumlist {
            system: extends decimal;
            suffix: ') ';
            prefix: '(';
        }
        @counter-style sectionnumlist {
            system: extends decimal;
            suffix: '. ';
            prefix: '\00A7';
        }
        @counter-style section2numlist {
            system: extends decimal;
            suffix: '. ';
            prefix: 'Section ';
        }
        @counter-style parenthesislowerromanlist {
            system: extends lower-roman;
            suffix: ') ';
            prefix: '(';
        }
        * {
            box-sizing: border-box;  
        }
        :root{
            --main-color:#1A48EE;
            --secondary-color:#008AFF;
            --tertiary-color:#2c20E6;
            --secondary-background:#f9f9f9;
            --main-background:#e5f3ff;
            --tertiary-background:#e6e5ea;
            --color-white:#ffffff;
            --color-error-dark: #c53030;
            --color-green: #16a34a;
            --color-green-dark: #047857;
            --color-light-green: #D1FAE5;
            --color-contrast-green:#065F46;
            --border-color:#e2e8f0;
            --color-gray:#4a5568;
            --color-light-gray:#ccc;
            --color-very-light-gray:#e0e0e0;
        }
        
        /* Body and Wrapper CSS removed as requested */

        h1{
            width: 100%;
            display: inline-block;
            text-align: center;
            margin-top: 0px;
            color: #1a202c;
        }
        b, .bold-text { font-weight: bold; }
        i, .italic-text { font-style: italic; }
        .text-center{ text-align: center; }
        ul, ol, dl{ line-height: 1.5; }
        
        .hidden { display: none !important; }
        .visually-hidden {
            border: 0; clip: rect(0 0 0 0); height: 1px; margin: -1px; overflow: hidden;
            padding: 0; position: absolute; width: 1px;
        }
        /* Make skip link visible on focus */
        .skip-link {
            position: absolute;
            top: -40px;
            left: 0;
            background: var(--main-color);
            color: white;
            padding: 8px;
            z-index: 100;
            transition: top 0.2s;
        }
        .skip-link:focus {
            top: 0;
        }

        li{ margin-bottom: 4px; }
        .articlecontainer{
            margin: auto;
            max-width: 1280px;
            padding:0 16px;
        }
        p{ margin-top: 0; margin-bottom: 16px; }
        a:hover{ cursor: pointer; color: var(--main-color); }
        a:active{ color: var(--secondary-color); }
        
        /* --- GAME SPECIFIC CSS --- */
        
        /* Reduced Motion */
        @media (prefers-reduced-motion: reduce) {
            *, ::before, ::after {
                animation-duration: 0.01ms !important;
                animation-iteration-count: 1 !important;
                transition-duration: 0.01ms !important;
                scroll-behavior: auto !important;
            }
        }

        /* Layout Utilities */
        .flex { display: flex; }
        .flex-col { flex-direction: column; }
        .items-center { align-items: center; }
        .justify-between { justify-content: space-between; }
        .justify-center { justify-content: center; }
        .gap-2 { gap: 0.5rem; }
        .gap-4 { gap: 1rem; }
        .w-full { width: 100%; }
        .max-w-6xl { max-width: 72rem; }
        .mb-4 { margin-bottom: 1rem; }
        .text-left { text-align: left; }
        
        /* Header Replacement Section */
        .game-header-section {
            padding: 1rem 0;
            border-bottom: 1px solid var(--border-color);
            margin-bottom: 2rem;
            width: 100%;
            /* Removed max-width restriction to allow full span, but inner content is constrained */
        }

        /* NEW: Grid-based header layout for robust centering without overlap */
        .header-layout {
            display: flex;
            flex-direction: column;
            align-items: center;
            text-align: center;
            gap: 1rem;
        }

        /* Desktop Grid: Left (Empty) | Center (Title) | Right (Controls) */
        @media (min-width: 1024px) {
            .header-layout {
                display: grid;
                grid-template-columns: 1fr auto 1fr; /* Middle is auto sized to fit content, sides take remaining space equally */
                align-items: center; 
                gap: 2rem; /* Ensure space between title and controls */
            }
            
            .header-title-block {
                grid-column: 2; /* Center column */
                white-space: nowrap; /* Prevent title wrapping on large screens if possible */
            }

            .header-controls-block {
                grid-column: 3; /* Right column */
                justify-self: end; /* Push to far right */
                display: flex;
                flex-direction: column;
                align-items: flex-end;
                width: auto;
                margin-top: 0;
            }
            
            /* Helper to balance grid if left is empty */
            .header-layout::before {
                content: "";
                grid-column: 1;
            }
        }

        .game-header-section h1 {
            text-align: center;
            margin: 0;
            color: var(--main-color);
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
            flex-wrap: wrap;
        }

        /* Buttons */
        .btn {
            background: none;
            border: 1px solid var(--border-color);
            padding: 8px 16px;
            border-radius: 6px;
            cursor: pointer;
            font-weight: bold;
            display: flex;
            align-items: center;
            gap: 8px;
            transition: all 0.2s;
            color: var(--color-gray);
            font-size: 1rem;
            /* Mobile touch optimization */
            touch-action: manipulation; 
            min-height: 44px; /* Accessible touch target */
        }
        .btn:hover {
            background-color: var(--main-color);
            color: var(--color-white);
            border-color: var(--main-color);
        }
        .btn:focus-visible {
            outline: 3px solid var(--tertiary-color);
            outline-offset: 2px;
        }
        .btn-primary {
            background-color: var(--main-color);
            color: var(--color-white);
            border: none;
        }
        .btn-primary:hover {
            background-color: var(--secondary-color);
        }
        
        /* Toggle Buttons */
        .btn.active {
            background-color: var(--secondary-background);
            border-color: var(--main-color);
            color: var(--main-color);
        }
        
        /* Main Layout */
        .game-container {
            display: flex;
            flex-direction: column;
            gap: 2rem;
            width: 100%;
            max-width: 1280px;
            margin: 0 auto;
        }
        @media(min-width: 1024px) {
            .game-container {
                flex-direction: row;
                align-items: flex-start;
            }
        }
        
        /* Chess Board Area */
        .board-wrapper {
            background-color: var(--color-white);
            padding: 1rem;
            border-radius: 8px;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
            border: 1px solid var(--border-color);
            position: relative;
        }
        
        @media (max-width: 640px) {
            /* Slim down padding on mobile to maximize board size */
            .board-wrapper {
                padding: 0.5rem;
                border: none;
                box-shadow: none;
                background: transparent;
            }
        }
        
        .chess-board {
            display: grid;
            grid-template-columns: repeat(8, 1fr);
            border: 2px solid var(--color-gray);
            aspect-ratio: 1/1;
            max-width: 600px;
            margin: 0 auto;
            width: 100%; /* Ensure it fills container */
        }
        
        .square {
            width: 100%;
            aspect-ratio: 1/1;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 3rem; 
            border: none;
            cursor: pointer;
            position: relative;
            padding: 0;
            line-height: 1;
            outline: none;
            /* Dynamic Font Size for Pieces based on Viewport Width */
            font-size: clamp(1.5rem, 8vw, 3rem); 
            /* Mobile touch optimization */
            touch-action: manipulation;
        }
        
        /* Keyboard Focus State - High Contrast */
        .square:focus-visible {
            z-index: 20;
            box-shadow: inset 0 0 0 6px var(--tertiary-color), 0 0 0 8px #fff;
            outline: 2px solid #000;
        }
        
        /* Themes */
        .square.dark {
            background-color: var(--secondary-color);
            color: var(--color-white);
        }
        .square.light {
            background-color: var(--main-background);
            color: var(--main-color);
        }
        
        /* ACCESSIBILITY: Pattern Overlay for Dark Squares */
        body.pattern-mode .square.dark {
            background-image: repeating-linear-gradient(
                45deg,
                rgba(0, 0, 0, 0.1),
                rgba(0, 0, 0, 0.1) 10px,
                transparent 10px,
                transparent 20px
            );
        }
        
        /* ACCESSIBLE PIECE CONTRAST */
        /* White Pieces: Solid White Fill with Heavy Black Outline ("Stroke" via shadow) */
        .piece-w { 
            color: #ffffff; 
            text-shadow: 
                -1.5px -1.5px 0 #000,  
                 1.5px -1.5px 0 #000,
                -1.5px  1.5px 0 #000,  
                 1.5px  1.5px 0 #000,
                 0 2px 4px rgba(0,0,0,0.5); /* Drop shadow for depth */
        }
        
        /* Black Pieces: Black Fill with White Outline */
        .piece-b { 
            color: #000000;
            text-shadow: 
                -1.5px -1.5px 0 #fff,  
                 1.5px -1.5px 0 #fff,
                -1.5px  1.5px 0 #fff,  
                 1.5px  1.5px 0 #fff,
                 0 2px 4px rgba(0,0,0,0.5); /* Drop shadow */
        }

        /* Selection & Moves */
        .square.selected {
            background-color: #fbbf24 !important;
            box-shadow: inset 0 0 0 4px #d97706;
        }
        /* Override patterns on selection to keep it clean */
        body.pattern-mode .square.selected {
            background-image: none;
        }
        
        /* Ensure pieces are readable on Yellow selection background */
        .square.selected .piece-w { 
            color: #ffffff; 
            text-shadow: 
                -1.5px -1.5px 0 #000, 
                 1.5px -1.5px 0 #000,
                -1.5px  1.5px 0 #000, 
                 1.5px  1.5px 0 #000; 
        }
        .square.selected .piece-b { 
            color: #000; 
            text-shadow: 
                -1.5px -1.5px 0 #fff, 
                 1.5px -1.5px 0 #fff,
                -1.5px  1.5px 0 #fff, 
                 1.5px  1.5px 0 #fff; 
        }

        .square.valid-move::after {
            content: "";
            position: absolute;
            width: 30%;
            height: 30%;
            background-color: var(--color-green);
            border-radius: 50%;
            opacity: 0.8;
            box-shadow: 0 0 0 2px #fff;
        }
        .square.valid-capture {
            background-color: var(--color-error-dark) !important;
            opacity: 0.9;
        }

        /* Sidebar / Dashboard */
        .dashboard {
            width: 100%;
            display: flex;
            flex-direction: column;
            gap: 1.5rem;
        }
        @media(min-width: 1024px) {
            .dashboard { width: 350px; flex-shrink: 0; }
        }
        
        .panel {
            background-color: var(--color-white);
            border: 1px solid var(--border-color);
            border-radius: 8px;
            padding: 1.5rem;
            box-shadow: 0 2px 4px rgba(0,0,0,0.05);
        }
        
        .turn-indicator {
            border-left: 5px solid var(--secondary-color);
            background-color: var(--color-white);
        }
        .turn-indicator.check {
            border-left-color: var(--color-error-dark);
            background-color: #fff5f5;
        }
        
        /* Progress Bar */
        .progress-container {
            width: 100%;
            height: 16px;
            background-color: var(--border-color);
            border-radius: 999px;
            overflow: hidden;
            display: flex;
            margin-bottom: 1rem;
        }
        .bar-w { background-color: var(--main-color); height: 100%; transition: width 0.5s; }
        .bar-b { background-color: var(--color-error-dark); height: 100%; transition: width 0.5s; }

        /* Logs */
        .log-container {
            max-height: 300px;
            overflow-y: auto;
            display: flex;
            flex-direction: column-reverse;
            gap: 0.5rem;
            padding-left: 0;
        }
        .log-item {
            padding: 0.5rem;
            border-left: 3px solid var(--border-color);
            background: var(--secondary-background);
            font-size: 0.9rem;
            margin-bottom: 0.5rem;
        }
        .log-alert { border-color: var(--color-error-dark); background: #fff5f5; color: var(--color-error-dark); }
        .log-success { border-color: var(--color-green); background: var(--color-light-green); color: var(--color-green-dark); }
        
        /* --- MODAL (For Rules only) --- */
        .overlay {
            position: fixed;
            top: 0; left: 0; right: 0; bottom: 0;
            background-color: rgba(26, 72, 238, 0.95);
            background-image: radial-gradient(circle at center, rgba(255,255,255,0.1) 0%, transparent 70%);
            z-index: 50;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 1rem;
        }
        
        /* Reusing panel style for menu view cards */
        .menu-view-container {
            width: 100%;
            max-width: 800px;
            margin: 0 auto;
            background: var(--color-white);
            border-radius: 16px;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
            border: 1px solid var(--border-color);
            padding: 2.5rem;
        }
        @media (max-width: 640px) {
            .menu-view-container {
                padding: 1.5rem; /* Less padding on mobile */
            }
        }

        .modal-content {
            background: var(--color-white);
            padding: 2.5rem;
            border-radius: 16px;
            max-width: 800px;
            width: 100%;
            max-height: 90vh;
            overflow-y: auto;
            box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
            border: 1px solid var(--border-color);
        }

        /* Mode Selection Cards */
        .mode-selection-container {
            display: flex;
            flex-direction: column;
            gap: 1.5rem;
        }
        @media(min-width: 640px) {
            .mode-selection-container {
                flex-direction: row;
                justify-content: center;
            }
        }
        
        .mode-card {
            flex: 1;
            padding: 2rem;
            border: 2px solid var(--border-color);
            border-radius: 12px;
            text-align: center;
            cursor: pointer;
            transition: all 0.2s ease;
            background: var(--color-white);
            /* Mobile touch optimization */
            touch-action: manipulation;
        }
        .mode-card:hover {
            border-color: var(--main-color);
            transform: translateY(-4px);
            box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
            background-color: var(--main-background);
        }
        .mode-card:focus-visible {
            outline: 3px solid var(--tertiary-color);
            outline-offset: 4px;
        }
        .mode-card h3 {
            margin: 1rem 0 0.5rem 0;
            color: var(--main-color);
            font-size: 1.25rem;
        }
        .mode-card p {
            color: var(--color-gray);
            font-size: 0.9rem;
            margin: 0;
        }

        /* AI Difficulty Grid */
        .difficulty-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
            gap: 1rem;
            margin-top: 1rem;
        }

        .diff-card {
            border: 1px solid var(--border-color);
            border-radius: 10px;
            padding: 1.5rem;
            text-align: left;
            cursor: pointer;
            transition: all 0.2s;
            position: relative;
            background: var(--color-white);
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            min-height: 140px;
            touch-action: manipulation;
        }
        .diff-card:hover {
            border-color: var(--main-color);
            background-color: var(--secondary-background);
            transform: scale(1.02);
        }
        .diff-card:focus-visible {
            outline: 3px solid var(--tertiary-color);
            transform: scale(1.02);
        }
        
        /* Badge for difficulty */
        .diff-badge {
            display: inline-block;
            padding: 2px 8px;
            border-radius: 999px;
            font-size: 0.75rem;
            font-weight: bold;
            margin-bottom: 0.5rem;
            text-transform: uppercase;
        }
        
        .diff-title {
            font-weight: bold;
            font-size: 1.1rem;
            color: #1a202c;
            margin-bottom: 0.25rem;
        }
        
        .diff-desc {
            font-size: 0.85rem;
            color: var(--color-gray);
            line-height: 1.4;
        }

        .legend-grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 0.5rem;
            font-size: 0.8rem;
        }
         @media (max-width: 768px) {
            .game-header-section .flex {
                flex-direction: column;
                align-items: flex-start;
            }
            .game-header-section h1 {
                font-size: 1.5rem;
                margin-bottom: 0.5rem;
            }
            /* Controls wrap nicely */
            .game-header-section .flex-col.items-end {
                align-items: flex-start;
                width: 100%;
            }
            #game-controls .flex {
                flex-wrap: wrap;
            }
        }
        /* Icons styling */
        svg { vertical-align: middle; }
        .text-main { color: var(--main-color); }
        .text-error { color: var(--color-error-dark); }
        .text-green { color: var(--color-green); }