/* ============================================
   ChessMaster - Professional Chess Web App
   Mobile-First, Responsive Design
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,400;12..96,500;12..96,600;12..96,700&family=JetBrains+Mono:wght@400;500;700&display=swap');

/* ============================================
   CSS Variables
   ============================================ */

:root {
    --font-ui: 'Bricolage Grotesque', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Consolas, monospace;

    /* Core Colors */
    --bg-primary: #0c1110;
    --bg-secondary: #121816;
    --bg-tertiary: #1a211f;
    --bg-card: #202722;
    --bg-elevated: #2a322c;
    
    /* Accent */
    --accent: #d4a017;
    --accent-light: #facc15;
    --accent-dark: #9a6b00;
    --accent-glow: rgba(250, 204, 21, 0.24);
    --accent-2: #38bdf8;
    --accent-3: #f43f5e;
    --line: rgba(255,255,255,0.09);
    
    /* Secondary Accent */
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    
    /* Text */
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    /* Board */
    --board-light: #eeeed2;
    --board-dark: #769656;
    --board-border: #5d7c3f;
    --board-frame: #101614;
    
    /* Game States */
    --selected: rgba(99, 102, 241, 0.5);
    --valid-move: rgba(34, 197, 94, 0.5);
    --capture: rgba(239, 68, 68, 0.55);
    --last-move: rgba(255, 215, 0, 0.4);
    --check: rgba(239, 68, 68, 0.5);
    
    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;
    
    /* Radius */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 8px;
    --radius-xl: 8px;
    --radius-full: 9999px;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.5);
    --shadow-xl: 0 20px 50px rgba(0,0,0,0.6);
    
    /* Safe Areas for notched devices */
    --safe-top: env(safe-area-inset-top);
    --safe-bottom: env(safe-area-inset-bottom);
    --safe-left: env(safe-area-inset-left);
    --safe-right: env(safe-area-inset-right);
    
    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-base: 250ms ease;
    --transition-slow: 400ms ease;
}

/* ============================================
   Reset & Base
   ============================================ */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-ui);
    background:
        linear-gradient(135deg, rgba(56, 189, 248, 0.08), transparent 28%),
        linear-gradient(315deg, rgba(244, 63, 94, 0.07), transparent 30%),
        repeating-linear-gradient(45deg, rgba(255,255,255,0.018) 0 1px, transparent 1px 18px),
        var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    min-height: 100dvh;
    line-height: 1.5;
    overflow-x: hidden;
    overflow-x: clip;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ============================================
   Loading Screen
   ============================================ */

#loading-screen {
    position: fixed;
    inset: 0;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

#loading-screen.fade-out {
    opacity: 0;
    visibility: hidden;
}

.loader-content {
    text-align: center;
    animation: fadeInUp 0.6s ease;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.loader-logo {
    margin-bottom: var(--space-lg);
}

.loader-piece {
    width: 80px;
    height: 80px;
    animation: float 2s ease-in-out infinite, glow 2s ease-in-out infinite;
    filter: drop-shadow(0 0 20px var(--accent-glow));
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-15px); }
}

@keyframes glow {
    0%, 100% { filter: drop-shadow(0 0 20px var(--accent-glow)); }
    50% { filter: drop-shadow(0 0 40px var(--accent)); }
}

.loader-title {
    font-size: 2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--text-primary) 0%, var(--accent-light) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: var(--space-xl);
}

.loader-bar {
    width: 200px;
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
    overflow: hidden;
    margin: 0 auto var(--space-md);
}

.loader-progress {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--accent), var(--accent-light));
    border-radius: var(--radius-full);
    animation: loading 1.5s ease-in-out forwards;
}

@keyframes loading {
    0% { width: 0; }
    50% { width: 70%; }
    100% { width: 100%; }
}

.loader-text {
    font-size: 0.875rem;
    color: var(--text-secondary);
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* ============================================
   Utility Classes
   ============================================ */

.hidden {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* ============================================
   Buttons
   ============================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    font-family: inherit;
    font-size: 0.9375rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-base);
    text-decoration: none;
    min-height: 44px;
    min-width: 0;
    white-space: normal;
    text-align: center;
    line-height: 1.15;
    overflow-wrap: anywhere;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

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

.btn-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.btn-icon-only {
    width: 44px;
    padding: 0;
    border-radius: var(--radius-md);
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
    color: white;
    box-shadow: var(--shadow-md), 0 0 20px var(--accent-glow);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg), 0 0 30px var(--accent-glow);
}

.btn-secondary {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border: 1px solid rgba(255,255,255,0.1);
}

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

.btn-accent {
    background: var(--accent);
    color: white;
}

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

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    padding: var(--space-sm);
}

.btn-ghost:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

.tippy-box[data-theme~='chessmaster'] {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border: 1px solid var(--line);
    box-shadow: var(--shadow-md);
    font-family: var(--font-ui);
    font-weight: 600;
}

.tippy-box[data-theme~='chessmaster'] > .tippy-arrow {
    color: var(--bg-elevated);
}

body[data-theme="royal"] {
    --board-light: #ead7ff;
    --board-dark: #6d4fc2;
    --board-border: #9f7aea;
    --board-frame: #191127;
    --accent: #a78bfa;
    --accent-light: #c4b5fd;
    --accent-dark: #7c3aed;
    --accent-glow: rgba(167, 139, 250, 0.28);
    --accent-2: #67e8f9;
    --accent-3: #fb7185;
}

body[data-theme="glacier"] {
    --board-light: #dff7ff;
    --board-dark: #27758a;
    --board-border: #38bdf8;
    --board-frame: #071923;
    --accent: #38bdf8;
    --accent-light: #7dd3fc;
    --accent-dark: #0284c7;
    --accent-glow: rgba(56, 189, 248, 0.25);
    --accent-2: #bef264;
    --accent-3: #f97316;
}

body[data-theme="ember"] {
    --board-light: #f6d9bd;
    --board-dark: #9f4536;
    --board-border: #fb923c;
    --board-frame: #23100d;
    --accent: #fb923c;
    --accent-light: #fdba74;
    --accent-dark: #c2410c;
    --accent-glow: rgba(251, 146, 60, 0.26);
    --accent-2: #22c55e;
    --accent-3: #60a5fa;
}

.btn:disabled,
.control-group select:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.btn:disabled:hover {
    transform: none;
}

.btn-lg {
    padding: var(--space-md) var(--space-xl);
    font-size: 1.0625rem;
    border-radius: var(--radius-lg);
    min-height: 54px;
}

/* ============================================
   Landing Page
   ============================================ */

#landing-page {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    position: relative;
    padding: var(--space-md);
    padding-top: calc(var(--safe-top) + var(--space-md));
    padding-bottom: calc(var(--safe-bottom) + var(--space-md));
}

.landing-bg {
    position: fixed;
    inset: 0;
    background: 
        linear-gradient(90deg, rgba(255,255,255,0.035) 1px, transparent 1px),
        linear-gradient(0deg, rgba(255,255,255,0.03) 1px, transparent 1px),
        linear-gradient(135deg, rgba(212, 160, 23, 0.14), transparent 42%),
        var(--bg-primary);
    background-size: 38px 38px, 38px 38px, auto;
    z-index: -1;
}

.landing-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    padding: var(--space-md) 0;
    animation: fadeInDown 0.6s ease 0.2s both;
    width: 100%;
    max-width: 1120px;
    margin: 0 auto;
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    min-width: 0;
}

.logo-icon {
    width: 36px;
    height: 36px;
}

.legal-nav {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    font-size: 0.875rem;
}

.legal-nav a,
.site-footer a {
    color: var(--text-secondary);
    text-decoration: none;
}

.legal-nav a:hover,
.site-footer a:hover {
    color: var(--accent-light);
}

/* Hero Section */
.hero {
    flex: 0 1 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: var(--space-xl);
    padding: var(--space-xl) 0 var(--space-lg);
}

.hero-content {
    max-width: 680px;
    animation: fadeInUp 0.8s ease 0.4s both;
}

.hero-title {
    font-size: 3.5rem;
    font-weight: 700;
    line-height: 1.1;
    margin-bottom: var(--space-md);
    background: linear-gradient(135deg, var(--text-primary) 0%, var(--accent-light) 50%, var(--text-primary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero-subtitle {
    font-size: 1.25rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-xl);
    max-width: 480px;
    margin-inline: auto;
}

.hero-actions {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    width: 100%;
    max-width: 760px;
    margin-inline: auto;
}

.hero-actions .btn {
    flex: 1 1 0;
}

@media (min-width: 480px) {
    .hero-actions {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
    }

    .hero-actions .btn {
        min-width: 190px;
    }
}

/* Floating Pieces Animation */
.hero-visual {
    position: relative;
    width: 100%;
    max-width: 400px;
    height: 200px;
    animation: fadeIn 1s ease 0.6s both;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.floating-pieces {
    position: relative;
    width: 100%;
    height: 100%;
}

.float-piece {
    position: absolute;
    filter: drop-shadow(0 10px 20px rgba(0,0,0,0.4));
}

.p1 { width: 60px; top: 10%; left: 10%; animation: floatA 4s ease-in-out infinite; }
.p2 { width: 50px; top: 5%; right: 15%; animation: floatB 5s ease-in-out infinite 0.5s; }
.p3 { width: 55px; bottom: 20%; left: 20%; animation: floatC 4.5s ease-in-out infinite 1s; }
.p4 { width: 45px; bottom: 10%; right: 25%; animation: floatA 5.5s ease-in-out infinite 1.5s; }
.p5 { width: 65px; top: 40%; left: 45%; animation: floatB 4s ease-in-out infinite 0.3s; }
.p6 { width: 40px; top: 60%; right: 10%; animation: floatC 5s ease-in-out infinite 0.8s; }

@keyframes floatA {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-20px) rotate(5deg); }
}

@keyframes floatB {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-25px) rotate(-5deg); }
}

@keyframes floatC {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-15px) rotate(3deg); }
}

/* Features */
.features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: var(--space-md);
    width: min(100%, 680px);
    margin: 0 auto;
    animation: fadeInUp 0.8s ease 0.8s both;
}

.feature {
    background: var(--bg-card);
    padding: var(--space-lg);
    border-radius: var(--radius-lg);
    text-align: center;
    border: 1px solid rgba(255,255,255,0.05);
    transition: all var(--transition-base);
    min-width: 0;
}

.feature:hover {
    transform: translateY(-4px);
    border-color: var(--accent);
    box-shadow: 0 0 30px var(--accent-glow);
}

.feature-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto var(--space-md);
    background: var(--accent-glow);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
}

.feature-icon svg {
    width: 24px;
    height: 24px;
    color: var(--accent-light);
}

.feature h3 {
    font-size: 0.9375rem;
    font-weight: 600;
    margin-bottom: var(--space-xs);
}

.feature p {
    font-size: 0.8125rem;
    color: var(--text-muted);
}

.learning-content {
    width: 100%;
    padding: var(--space-2xl) 0 var(--space-xl);
}

.learning-inner {
    width: min(100%, 960px);
    margin: 0 auto;
}

.learning-inner h2 {
    font-size: 2.25rem;
    line-height: 1.15;
    margin-bottom: var(--space-md);
}

.learning-inner > p {
    color: var(--text-secondary);
    max-width: 780px;
    margin-bottom: var(--space-xl);
}

.faq-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--space-md);
}

.faq-grid article {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    min-width: 0;
}

.faq-grid h3 {
    font-size: 1rem;
    margin-bottom: var(--space-sm);
}

.faq-grid p {
    color: var(--text-secondary);
    font-size: 0.9375rem;
}

.site-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: var(--space-md);
    color: var(--text-muted);
    font-size: 0.875rem;
    padding: var(--space-lg) 0 var(--space-sm);
}

.legal-page {
    min-height: 100vh;
    background: var(--bg-primary);
    color: var(--text-primary);
    padding: var(--space-lg);
}

.legal-page main {
    width: min(100%, 820px);
    margin: 0 auto;
}

.legal-page h1 {
    font-size: 3.5rem;
    line-height: 1.1;
    margin: var(--space-xl) 0 var(--space-md);
}

.legal-page h2 {
    margin: var(--space-xl) 0 var(--space-sm);
    font-size: 1.25rem;
}

.legal-page p,
.legal-page li {
    color: var(--text-secondary);
    margin-bottom: var(--space-md);
}

.legal-page ul {
    padding-left: var(--space-lg);
}

/* ============================================
   Game Screen
   ============================================ */

#game-screen {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
    animation: fadeIn 0.4s ease;
}

/* Game Header */
.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-secondary);
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.game-logo {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    font-size: 1rem;
    font-weight: 600;
}

.logo-icon-sm {
    width: 28px;
    height: 28px;
}

/* Game Info */
#game-info {
    background: var(--bg-secondary);
    padding: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    min-width: 0;
}

#player-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-md);
}

.player-badge {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    transition: all var(--transition-base);
    border: 2px solid transparent;
    min-width: 0;
}

.player-badge.active {
    background: var(--bg-elevated);
    border-color: var(--accent);
    box-shadow: 0 0 15px var(--accent-glow);
}

.player-piece {
    width: 32px;
    height: 32px;
}

#vs-indicator {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0;
}

#game-controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    width: min(100%, 1240px);
    margin-inline: auto;
}

.control-group {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    background: var(--bg-tertiary);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    min-height: 44px;
    min-width: 0;
    justify-content: space-between;
}

.control-group label {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.control-group select {
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: var(--radius-sm);
    padding: var(--space-xs) var(--space-sm);
    font-family: inherit;
    font-size: 0.875rem;
    cursor: pointer;
    width: min(100%, 150px);
    min-width: 0;
}

.control-group select:focus {
    outline: none;
    border-color: var(--accent);
}

.timer-group {
    font-family: var(--font-mono);
    font-size: 1rem;
    font-weight: 500;
}

.control-icon {
    width: 18px;
    height: 18px;
    color: var(--accent);
}

.game-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--space-sm);
    width: min(100%, 860px);
    margin-inline: auto;
}

.stat-pill {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    min-width: 0;
    padding: var(--space-sm) var(--space-md);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: color-mix(in srgb, var(--bg-tertiary), transparent 8%);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}

.stat-pill span {
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0;
}

.stat-pill strong {
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.9rem;
    white-space: nowrap;
}

/* Game Container */
#game-container {
    flex: 1;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: var(--space-lg);
    min-width: 0;
}

#game {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    justify-items: center;
    align-items: center;
    gap: var(--space-md);
    width: 100%;
    max-width: 1260px;
    min-width: 0;
}

@media (min-width: 760px) and (max-width: 1179px) {
    #game {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        align-items: stretch;
        max-width: 960px;
    }

    #board-wrapper {
        grid-column: 1 / -1;
        justify-self: center;
    }

    #move-history,
    #coach-panel {
        max-width: none;
        min-height: 190px;
    }
}

@media (min-width: 1180px) {
    #game {
        grid-template-columns: 280px minmax(500px, 620px) 280px;
        align-items: stretch;
    }

    #board-wrapper {
        grid-column: 2;
        grid-row: 1;
        align-self: center;
    }

    #move-history {
        grid-column: 1;
        grid-row: 1;
    }

    #coach-panel {
        grid-column: 3;
        grid-row: 1;
    }
}

/* Board Wrapper */
#board-wrapper {
    position: relative;
    --board-size: min(88vw, 66dvh, 560px);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    width: min(100%, calc(var(--board-size) + 34px));
    min-width: 0;
}

.board-stage {
    display: grid;
    grid-template-columns: 22px minmax(0, var(--board-size));
    align-items: stretch;
    gap: var(--space-sm);
    width: 100%;
}

#board-shell {
    position: relative;
    border-radius: var(--radius-lg);
    background: var(--board-frame);
    padding: clamp(5px, 1vw, 8px);
    box-shadow:
        var(--shadow-xl),
        inset 0 1px 0 rgba(255,255,255,0.08),
        0 0 44px rgba(0,0,0,0.45);
}

#eval-bar {
    position: relative;
    width: 100%;
    min-height: 100%;
    border-radius: var(--radius-full);
    overflow: hidden;
    background: linear-gradient(180deg, #f8fafc 0%, #cbd5e1 50%, #111827 50%, #020617 100%);
    border: 1px solid var(--line);
    box-shadow: inset 0 0 10px rgba(0,0,0,0.55);
}

#eval-fill {
    position: absolute;
    inset-inline: 0;
    bottom: 0;
    height: 50%;
    background: linear-gradient(180deg, rgba(248,250,252,0.94), rgba(250,204,21,0.82));
    transition: height var(--transition-slow);
}

.capture-row {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    min-height: 34px;
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-md);
    border: 1px solid var(--line);
    background: rgba(255,255,255,0.04);
    overflow: hidden;
}

.capture-row span:first-child {
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    white-space: nowrap;
}

.captured-pieces {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 2px;
    min-width: 0;
}

.captured-piece {
    width: 22px;
    height: 22px;
    display: inline-flex;
    opacity: 0.88;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.35));
}

.captured-piece svg {
    width: 100%;
    height: 100%;
}

/* Chess Board */
#board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    width: 100%;
    height: auto;
    aspect-ratio: 1;
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: 
        0 0 0 3px var(--board-border),
        0 0 34px rgba(0,0,0,0.45);
}

.square {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    isolation: isolate;
    transition: background-color var(--transition-fast), box-shadow var(--transition-fast);
}

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

.square.selected { background: var(--selected) !important; }
.square.last-move { background: var(--last-move) !important; }

.square.in-check {
    box-shadow: inset 0 0 0 4px var(--danger), inset 0 0 30px rgba(239, 68, 68, 0.45);
}

.coord {
    position: absolute;
    z-index: 2;
    color: rgba(15, 23, 42, 0.58);
    font-family: var(--font-mono);
    font-size: clamp(0.55rem, 1.5vw, 0.72rem);
    font-weight: 800;
    line-height: 1;
    pointer-events: none;
}

.dark .coord {
    color: rgba(248, 250, 252, 0.74);
}

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

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

.square.highlight::after {
    content: '';
    position: absolute;
    width: 30%;
    height: 30%;
    background: var(--valid-move);
    border-radius: 50%;
    pointer-events: none;
    box-shadow: 0 0 10px var(--valid-move);
}

.square.capture::after {
    width: 90%;
    height: 90%;
    background: transparent;
    border: 4px solid var(--capture);
    border-radius: 50%;
}

/* Chess Pieces */
.piece {
    width: 85%;
    height: 85%;
    cursor: grab;
    user-select: none;
    z-index: 10;
    transition: transform var(--transition-fast);
    touch-action: none;
    display: flex;
    align-items: center;
    justify-content: center;
    will-change: transform;
}

.piece svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(1px 2px 3px rgba(0,0,0,0.4));
}

.piece:hover {
    transform: scale(1.1);
    z-index: 100;
}

.piece-enter {
    animation: pieceLand 260ms cubic-bezier(.2,.9,.2,1.2);
}

@keyframes pieceLand {
    0% { transform: scale(0.72); filter: brightness(1.3); }
    70% { transform: scale(1.12); }
    100% { transform: scale(1); filter: brightness(1); }
}

.piece:active {
    cursor: grabbing;
}

.piece.dragging {
    position: fixed;
    z-index: 9999;
    pointer-events: none;
    transform: translate(-50%, -50%);
    transition: none;
    /* Fixed size when dragging - not percentage based */
    width: 65px;
    height: 65px;
}

.piece.dragging svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(4px 8px 15px rgba(0,0,0,0.5));
}

/* Move History */
#move-history,
#coach-panel {
    background:
        linear-gradient(180deg, rgba(255,255,255,0.045), transparent 42%),
        var(--bg-card);
    border-radius: var(--radius-lg);
    padding: var(--space-md);
    width: 100%;
    max-width: 320px;
    max-height: 230px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--line);
    min-width: 0;
}

@media (min-width: 1180px) {
    #move-history,
    #coach-panel {
        max-height: 500px;
        width: 280px;
    }
}

#move-history h2,
#coach-panel h2 {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    font-size: 0.9375rem;
    font-weight: 600;
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-md);
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.panel-icon {
    width: 18px;
    height: 18px;
    color: var(--accent);
}

#history-list {
    list-style: decimal;
    padding-left: var(--space-lg);
    margin: 0;
    overflow-y: auto;
    flex: 1;
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

#coach-panel {
    gap: var(--space-sm);
}

.ai-status {
    min-height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 0.8125rem;
    font-weight: 600;
    text-align: center;
    padding: var(--space-xs) var(--space-sm);
}

.ai-status[data-tone="success"] {
    color: #bbf7d0;
    background: rgba(34, 197, 94, 0.16);
}

.ai-status[data-tone="warning"] {
    color: #fde68a;
    background: rgba(245, 158, 11, 0.16);
}

.coach-content {
    flex: 1;
    overflow-y: auto;
    color: var(--text-secondary);
    font-size: 0.875rem;
    line-height: 1.45;
    padding-right: var(--space-xs);
}

.coach-content p,
.coach-content li {
    margin-bottom: var(--space-sm);
}

.coach-content ul {
    padding-left: var(--space-lg);
}

.coach-best-move {
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-weight: 700;
}

.coach-warning {
    color: #fde68a;
}

#history-list li {
    padding: var(--space-xs) 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

#history-list li:last-child {
    border-bottom: none;
    color: var(--text-primary);
    font-weight: 500;
}

#history-list::-webkit-scrollbar {
    width: 4px;
}

#history-list::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.15);
    border-radius: 2px;
}

.coach-content::-webkit-scrollbar,
.review-result::-webkit-scrollbar {
    width: 4px;
}

.coach-content::-webkit-scrollbar-thumb,
.review-result::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.15);
    border-radius: 2px;
}

/* Status Bar */
.status-bar {
    background: var(--bg-secondary);
    padding: var(--space-md);
    text-align: center;
    font-weight: 600;
    border-top: 1px solid rgba(255,255,255,0.05);
}

.status-bar.check {
    background: var(--danger);
    animation: pulseStatus 0.8s ease-in-out infinite;
}

@keyframes pulseStatus {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* ============================================
   Modals
   ============================================ */

.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    justify-content: center;
    align-items: center;
    z-index: 10000;
    backdrop-filter: blur(8px);
    padding: var(--space-md);
}

.modal-content {
    background: var(--bg-card);
    padding: var(--space-xl);
    border-radius: var(--radius-xl);
    text-align: center;
    max-width: 400px;
    width: 100%;
    box-shadow: var(--shadow-xl);
    animation: modalIn 0.3s ease;
    border: 1px solid rgba(255,255,255,0.1);
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-content h2 {
    font-size: 1.5rem;
    margin-bottom: var(--space-md);
}

.modal-content p {
    color: var(--text-secondary);
    margin-bottom: var(--space-lg);
}

.modal-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto var(--space-md);
    background: var(--accent-glow);
    border-radius: 50%;
}

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    flex-wrap: wrap;
}

@media (min-width: 400px) {
    .modal-actions {
        flex-direction: row;
        justify-content: center;
    }
}

.review-result {
    max-height: 220px;
    overflow-y: auto;
    color: var(--text-secondary);
    text-align: left;
    margin-bottom: var(--space-md);
    font-size: 0.875rem;
}

.review-result p,
.review-result li {
    margin-bottom: var(--space-sm);
}

.review-result ul {
    padding-left: var(--space-lg);
}

/* Promotion Options */
#promotion-options {
    display: flex;
    justify-content: center;
    gap: var(--space-md);
    margin-top: var(--space-lg);
}

.promotion-piece {
    width: 70px;
    height: 70px;
    padding: var(--space-sm);
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-base);
    border: 2px solid transparent;
    display: flex;
    align-items: center;
    justify-content: center;
}

.promotion-piece svg {
    width: 100%;
    height: 100%;
}

.promotion-piece:hover {
    transform: scale(1.1);
    border-color: var(--accent);
    background: var(--bg-elevated);
}

/* Settings Modal */
.settings-list {
    text-align: left;
    margin-bottom: var(--space-lg);
}

.setting-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) 0;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.setting-item:last-child {
    border-bottom: none;
}

.setting-item label {
    font-weight: 500;
}

.setting-item input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--accent);
    cursor: pointer;
}

.setting-item select {
    width: min(52%, 180px);
    min-height: 38px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: inherit;
    padding: var(--space-xs) var(--space-sm);
}

.focus-mode #game-screen {
    background:
        linear-gradient(135deg, rgba(56, 189, 248, 0.08), transparent 34%),
        linear-gradient(315deg, rgba(250, 204, 21, 0.08), transparent 34%),
        var(--bg-primary);
}

.focus-mode #game-info,
.focus-mode .status-bar {
    background: rgba(18, 24, 22, 0.88);
    backdrop-filter: blur(14px);
}

.motion-off *,
.motion-off *::before,
.motion-off *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
}

/* ============================================
   Responsive Design
   ============================================ */

@media (max-width: 760px) {
    .hero-title,
    .legal-page h1 {
        font-size: 2.5rem;
    }

    .learning-inner h2 {
        font-size: 1.75rem;
    }

    #game-info {
        padding: var(--space-sm);
    }

    .game-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    #game-container {
        padding: var(--space-md);
    }
}

@media (max-width: 480px) {
    .landing-header {
        flex-direction: column;
        gap: var(--space-sm);
    }

    .hero-title {
        font-size: 1.875rem;
    }
    
    .hero-subtitle {
        font-size: 0.9375rem;
    }

    .legal-page h1 {
        font-size: 2rem;
    }

    .learning-inner h2 {
        font-size: 1.5rem;
    }
    
    .btn-lg {
        width: 100%;
    }
    
    .features {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: var(--space-sm);
    }
    
    .feature {
        padding: var(--space-md);
    }
    
    .feature-icon {
        width: 36px;
        height: 36px;
    }
    
    .feature h3 {
        font-size: 0.75rem;
    }
    
    .feature p {
        display: none;
    }
    
    #board-wrapper {
        --board-size: min(88vw, 56dvh, 520px);
        width: min(100%, calc(var(--board-size) + 26px));
    }

    .board-stage {
        grid-template-columns: 16px minmax(0, var(--board-size));
        gap: 6px;
    }

    #game-container {
        padding: var(--space-sm);
    }

    #game-controls {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        align-items: stretch;
    }

    #new-game-btn {
        grid-column: 1 / -1;
    }

    .control-group,
    #game-controls .btn {
        width: 100%;
    }

    .control-group {
        justify-content: space-between;
    }

    .control-group select {
        width: min(58%, 170px);
    }
    
    .piece.dragging {
        width: 50px;
        height: 50px;
    }
    
    #move-history,
    #coach-panel {
        max-width: 100%;
        max-height: 180px;
    }

    .capture-row {
        min-height: 30px;
    }

    .capture-row span:first-child {
        display: none;
    }

    .captured-piece {
        width: 20px;
        height: 20px;
    }

    .stat-pill {
        padding: var(--space-sm);
    }

    .stat-pill span {
        font-size: 0.68rem;
    }

    .stat-pill strong {
        font-size: 0.78rem;
    }
    
    .promotion-piece {
        width: 60px;
        height: 60px;
    }
}

@media (max-height: 700px) {
    .hero-visual {
        display: none;
    }
}

@media (max-height: 500px) and (orientation: landscape) {
    #game-screen {
        flex-direction: row;
        flex-wrap: wrap;
    }
    
    .game-header {
        width: 100%;
    }
    
    #game-info {
        width: 100%;
        padding: var(--space-sm);
    }
    
    #player-indicator {
        gap: var(--space-sm);
    }
    
    .player-badge {
        padding: var(--space-xs) var(--space-sm);
    }
    
    #board-wrapper {
        --board-size: min(62vh, 350px);
        width: min(100%, calc(var(--board-size) + 24px));
    }

    #move-history,
    #coach-panel {
        max-height: 160px;
    }
    
    .status-bar {
        width: 100%;
    }
}

@media (max-width: 360px) {
    .hero-title {
        font-size: 1.625rem;
    }

    .logo,
    .game-logo {
        font-size: 0.9375rem;
    }

    .feature {
        padding: var(--space-sm);
    }

    .feature h3 {
        font-size: 0.6875rem;
    }
}

/* Touch Optimizations */
@media (hover: none) and (pointer: coarse) {
    .piece:hover {
        transform: none;
    }
    
    .btn:hover {
        transform: none;
    }
    
    .feature:hover {
        transform: none;
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    :root {
        --board-light: #fff;
        --board-dark: #666;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Print Styles */
@media print {
    #loading-screen,
    #landing-page,
    .game-header,
    #game-info,
    .status-bar,
    .modal {
        display: none !important;
    }
    
    #board {
        box-shadow: none;
        border: 2px solid #000;
    }
}
