/* --- FONTS --- */
@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@600;800&family=Raleway:wght@300;400;600&family=Share+Tech+Mono&display=swap');

:root {
    --bg-color: #1a1a1a;
    --panel-bg: rgba(35, 35, 35, 0.98);
    --text-color: #fff;
    --board-light: #ebecd0;
    --board-dark: #739552;

    /* Highlights */
    --highlight-last: rgba(255, 255, 50, 0.5);
    --highlight-check: rgba(255, 215, 0, 0.9);
    --highlight-mate: rgba(255, 0, 0, 0.9);
    --highlight-draw: rgba(255, 140, 0, 0.9);
    --highlight-suggest: rgba(0, 255, 255, 0.6); 
    
    /* Hints */
    --hint-safe: rgba(100, 200, 100, 0.6);
    --hint-danger: rgba(255, 0, 0, 0.9);
    --hint-capture-glow: rgba(220, 50, 50, 0.8);
    --threat-glow: rgba(255, 140, 0, 0.8);
}

* { box-sizing: border-box; list-style: none; }
hr { border: 0; height: 1px; background: #444; margin: 8px 0; width: 100%; flex-shrink: 0; }

body, html { 
    margin: 0; padding: 0; 
    width: 100%; height: 100%; 
    background-color: var(--bg-color); 
    font-family: 'Raleway', sans-serif; 
    color: var(--text-color); 
    /* Prevent bouncy scroll on mobile */
    overflow-x: hidden;
}

/* --- TOAST NOTIFICATIONS --- */
#toast-container {
    position: absolute; top: 80px; left: 50%; transform: translateX(-50%);
    z-index: 3000; width: 300px; display: flex; flex-direction: column; gap: 10px;
    pointer-events: none;
}
.toast {
    background: rgba(20, 20, 20, 0.95);
    border: 1px solid #00ffff;
    color: #fff;
    padding: 12px 20px;
    border-radius: 4px;
    box-shadow: 0 0 15px rgba(0, 255, 255, 0.3);
    font-family: 'Raleway', sans-serif; font-weight: 600;
    text-align: center; font-size: 0.9rem;
    animation: slide-down 0.3s ease-out;
    pointer-events: auto;
    display: flex; align-items: center; justify-content: center; gap: 10px;
}
.toast::before { content: 'ℹ'; color: #00ffff; font-weight: bold; font-size: 1.1rem; }
.toast.success::before { content: '✔'; color: #00ff00; }
.toast.error::before { content: '⚠'; color: #ff4444; border-color: #ff4444; }
.toast.fade-out { opacity: 0; transform: translateY(-20px); transition: all 0.3s ease-in; }
@keyframes slide-down { from { opacity: 0; transform: translateY(-20px); } to { opacity: 1; transform: translateY(0); } }

/* --- PROMOTION MODAL --- */
#promotion-modal {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    background: rgba(20, 20, 20, 0.95); border: 2px solid #00ffff; border-radius: 8px; padding: 15px;
    display: flex; gap: 10px; z-index: 2000; box-shadow: 0 0 20px rgba(0, 255, 255, 0.3);
}
#promotion-modal.hidden { display: none; }
.promo-option {
    width: 60px; height: 60px; background-size: contain; background-repeat: no-repeat; background-position: center;
    cursor: pointer; transition: transform 0.2s; border: 1px solid #444; border-radius: 4px; background-color: rgba(255,255,255,0.1);
}
.promo-option:hover { transform: scale(1.1); background-color: rgba(0, 255, 255, 0.2); border-color: #00ffff; }

/* --- LAYOUT --- */
#app-container { 
    position: relative; 
    width: 100vw; height: 100vh; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
}

#game-layout { 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    justify-content: center; 
}

#board-container { 
    width: 95vmin; height: 95vmin; 
    position: relative; 
    pointer-events: auto; 
    /* Touch Optimization: Prevents scroll/zoom while dragging pieces */
    touch-action: none; 
}

#board { 
    width: 100%; height: 100%; 
    display: grid; 
    grid-template-columns: repeat(8, 1fr); 
    grid-template-rows: repeat(8, 1fr); 
    border: 5px solid #333; 
    box-sizing: border-box; 
    user-select: none; 
}

/* --- PANEL --- */
.panel {
    position: absolute; top: 10px; right: 10px; width: 280px; 
    background: var(--panel-bg); border-radius: 8px; padding: 10px; 
    box-shadow: 0 4px 15px rgba(0,0,0,0.5); backdrop-filter: blur(5px); 
    transition: opacity 0.3s, transform 0.3s; z-index: 100;
    max-height: calc(100vh - 20px); 
    display: flex; flex-direction: column;
}
.panel.hidden { opacity: 0; pointer-events: none; transform: translateY(-10px); }

.panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 5px; flex-shrink: 0; border-bottom: 1px solid #444; padding-bottom: 5px; }
.panel-footer { margin-top: auto; padding-top: 8px; border-top: 1px solid #555; display: flex; justify-content: space-between; align-items: center; font-size: 0.7rem; color: #888; white-space: nowrap; flex-shrink: 0; }

.panel-content { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; padding-right: 5px; flex-grow: 1; }
.panel-content::-webkit-scrollbar, .move-history::-webkit-scrollbar { width: 6px; }
.panel-content::-webkit-scrollbar-track, .move-history::-webkit-scrollbar-track { background: rgba(0,0,0,0.1); border-radius: 3px; }
.panel-content::-webkit-scrollbar-thumb, .move-history::-webkit-scrollbar-thumb { background: #555; border-radius: 3px; }

/* --- LOGO --- */
.app-logo {
    font-family: 'Cinzel', serif; font-weight: 800; font-size: 1.2rem; letter-spacing: 1px;
    background: linear-gradient(90deg, #ffffff, #aaaaaa); -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    display: flex; align-items: center; gap: 6px; cursor: default;
}
.logo-icon { font-size: 1.4rem; -webkit-text-fill-color: #00ffff; filter: drop-shadow(0 0 5px rgba(0, 255, 255, 0.6)); }
.logo-accent { font-weight: 600; -webkit-text-fill-color: #00ffff; }

/* --- SIDEBAR CONTROLS --- */
#toggle-panel-btn {
    background: transparent; border: 1px solid #555; color: #888;
    width: 24px; height: 24px; font-size: 0.8rem; line-height: 1; padding: 0;
    border-radius: 4px; cursor: pointer; transition: all 0.2s;
}
#toggle-panel-btn:hover { border-color: #ff4444; color: #ff4444; }

#show-panel-btn {
    position: absolute; top: 20px; right: 20px; z-index: 90; 
    width: 50px; height: 50px; border-radius: 50%; font-size: 1.5rem; 
    background: rgba(0, 0, 0, 0.8); color: #00ffff;
    border: 2px solid #00ffff; box-shadow: 0 0 15px rgba(0, 255, 255, 0.4);
    cursor: pointer; transition: transform 0.2s, box-shadow 0.2s;
}
#show-panel-btn:hover { transform: scale(1.1) rotate(90deg); box-shadow: 0 0 25px rgba(0, 255, 255, 0.8); }
#show-panel-btn.hidden { display: none; }

/* --- COMPONENTS --- */
.scoreboard { display: flex; justify-content: space-between; background: rgba(0,0,0,0.4); padding: 5px 10px; border-radius: 4px; font-weight: bold; font-size: 0.9rem; flex-shrink: 0; }
.score-item span { color: #aaa; font-size: 0.8em; display: block; font-family: 'Cinzel', serif; } 
.score-item strong { font-size: 1.1em; color: #fff; }

.captured-section { display: flex; flex-direction: column; gap: 6px; flex-shrink: 0; }
.captured-panel { min-height: 55px; width: 100%; display: flex; flex-wrap: wrap; alignItems: center; gap: 0px; background: rgba(0, 0, 0, 0.4); border: 1px solid #444; border-radius: 4px; padding: 4px; box-sizing: border-box; }

/* Captured Zoom Effect */
.captured-piece { 
    width: 45px; height: 45px; 
    background-size: contain; background-repeat: no-repeat; background-position: center; 
    filter: drop-shadow(0 2px 2px rgba(0,0,0,0.5));
    transition: transform 0.2s ease, filter 0.2s ease;
}
.captured-piece:hover {
    transform: scale(2.0); z-index: 100; cursor: help;
    filter: drop-shadow(0 5px 15px rgba(0,0,0,0.8));
}

.eval-graph-wrapper { width: 100%; background: #222; border: 1px solid #555; border-radius: 4px; margin: 5px 0 10px 0; padding: 0; flex-shrink: 0; }
#eval-graph { width: 100%; height: 50px; display: block; background: #222; }

/* --- CONTROLS & INPUTS --- */
.control-group { flex-shrink: 0; }
.control-group label { font-size: 0.85rem; margin-bottom: 2px; color: #bbb; font-weight: 600; }

button, select { 
    padding: 6px; 
    cursor: pointer; 
    background: #444; 
    color: white; 
    border: 1px solid #555; 
    border-radius: 4px; 
    font-weight: 600; 
    width: 100%; 
    font-size: 0.85rem; 
    font-family: 'Raleway', sans-serif;
    transition: all 0.2s ease;
    /* Faster touch response */
    touch-action: manipulation;
}

/* Hover Effect: Cyan text & Border */
button:hover, select:hover { 
    background: #555; color: #00ffff; border-color: #00ffff; 
    box-shadow: 0 0 8px rgba(0, 255, 255, 0.3);
}

/* --- UNIFIED SAVE/LOAD LED SYSTEM --- */
#btn-save, #btn-load {
    position: relative;
    padding-right: 35px !important; 
    transition: all 0.2s;
}
/* The Light Itself (Default: Off/Invisible) */
#btn-save::after, #btn-load::after {
    content: '';
    position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
    width: 8px; height: 8px; border-radius: 50%;
    background-color: #333; opacity: 0;
    transition: background-color 0.3s, box-shadow 0.3s, opacity 0.3s;
}
/* Green State */
#btn-save.led-green::after, #btn-load.led-green::after {
    opacity: 1; background-color: #00ff00; box-shadow: 0 0 6px #00ff00;
}
/* Blue State */
#btn-save.led-blue::after, #btn-load.led-blue::after {
    opacity: 1; background-color: #0088ff !important; box-shadow: 0 0 10px #0088ff !important;
}
/* Hover Pulse */
#btn-save.led-green:hover::after, #btn-save.led-blue:hover::after,
#btn-load.led-green:hover::after, #btn-load.led-blue:hover::after {
    transform: translateY(-50%) scale(1.2);
}

/* Mode Button - Always Cyan */
#btn-mode-toggle {
    background: #222; border: 1px solid #00ffff; color: #00ffff;
    font-size: 0.85rem; padding: 8px; font-weight: bold;
    box-shadow: 0 0 5px rgba(0, 255, 255, 0.2); 
}
#btn-mode-toggle:hover { background: rgba(0, 255, 255, 0.1); box-shadow: 0 0 10px rgba(0, 255, 255, 0.4); }

.move-history { background: rgba(0,0,0,0.3); border-radius: 4px; padding: 5px; height: 120px; min-height: 80px; overflow-y: auto; display: flex; flexDirection: column; font-size: 0.85rem; border: 1px solid #444; font-family: monospace; flex-shrink: 0; }
.move-row { display: grid; grid-template-columns: 30px 1fr 1fr; padding: 2px 5px; border-bottom: 1px solid #333; }
.move-row:nth-child(even) { background: rgba(255,255,255,0.05); }
.move-row.header { font-weight: bold; color: #aaa; background: #333; position: sticky; top: 0; z-index: 2; font-family: 'Raleway', sans-serif; }
.pgn-btn { position: absolute; bottom: 10px; right: 10px; width: 30px !important; height: 30px; padding: 0; background: rgba(0,0,0,0.5); }

/* --- STATUS HUD --- */
.status-hud {
    font-family: 'Cinzel', serif; font-weight: 800; font-size: 1.5rem; text-align: center;
    color: #00ffff; text-shadow: 0 0 15px rgba(0, 255, 255, 0.4);
    margin: 12px 0 8px 0; letter-spacing: 1px; text-transform: uppercase; transition: color 0.3s;
}
.eval-text {
    font-family: 'Share Tech Mono', monospace; text-align: center; color: #00ffff;
    font-size: 0.9rem; margin-bottom: 5px; opacity: 0.9;
}

/* --- SQUARES --- */
.square { width: 100%; height: 100%; position: relative; display: flex; justify-content: center; align-items: center; transition: background-color 0.2s ease; z-index: 1; }
.square.light { background-color: var(--board-light); } .square.dark { background-color: var(--board-dark); }
.square.last-move { background-color: var(--highlight-last) !important; }

/* --- SELECTED PIECE EFFECT --- */
.square.selected { box-shadow: none !important; }
.square.selected .piece { transform: scale(1.1); filter: drop-shadow(0 0 2px #00ffff) drop-shadow(0 0 2px #00ffff); z-index: 10; }

/* Status Highlights */
.square.check { background-color: var(--highlight-check) !important; box-shadow: inset 0 0 20px rgba(255, 255, 0, 0.8); }
.square.suggestion { background-color: var(--highlight-suggest) !important; box-shadow: inset 0 0 15px rgba(0, 255, 255, 0.8); animation: pulse-glow 1.5s infinite; }
.square.checkmate { background-color: var(--highlight-mate) !important; animation: mate-pulse 0.8s infinite; z-index: 2; box-shadow: inset 0 0 40px rgba(0,0,0,0.6) !important; }

/* Draw & Stalemate */
@keyframes draw-pulse { 0%, 100% { background-color: rgba(255, 140, 0, 0.5); } 50% { background-color: rgba(255, 140, 0, 0.8); } }
.square.draw { background-color: var(--highlight-draw) !important; box-shadow: inset 0 0 30px rgba(255, 140, 0, 0.5) !important; animation: draw-pulse 3s infinite; z-index: 2; }
@keyframes stalemate-pulse { 0%, 100% { background-color: #555; transform: scale(1); } 50% { background-color: #888; transform: scale(0.95); } }
.square.stalemate { background-color: #555 !important; box-shadow: inset 0 0 40px rgba(255, 255, 255, 0.2) !important; animation: stalemate-pulse 2s infinite; z-index: 2; }

/* Animations */
@keyframes mate-pulse { 0% { background-color: var(--highlight-mate); transform: scale(1); } 50% { background-color: #800000; transform: scale(0.95); } 100% { background-color: var(--highlight-mate); transform: scale(1); } }
@keyframes pulse-glow { 0% { transform: scale(0.8); opacity: 0.5; } 50% { transform: scale(1.1); opacity: 1; } 100% { transform: scale(0.8); opacity: 0.5; } }

/* Hints */
.square.threat::before { content: ''; position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: radial-gradient(circle, var(--threat-glow) 20%, transparent 70%); z-index: 4; animation: pulse-glow 2s infinite; }
.square.hint-capture::before { content: ''; position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: radial-gradient(circle, var(--hint-capture-glow) 20%, transparent 70%); z-index: 4; animation: pulse-glow 2s infinite; }
.square.hint-move::after { content: ''; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 25%; height: 25%; background-color: var(--hint-safe); border-radius: 50%; z-index: 10; pointer-events: none; }
.square.hint-danger::after { content: ''; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 15%; height: 15%; background-color: var(--hint-danger); border-radius: 50%; z-index: 10; pointer-events: none; animation: red-dot-pulse 1.5s infinite; }
@keyframes red-dot-pulse { 0% { box-shadow: 0 0 5px var(--hint-danger); } 50% { box-shadow: 0 0 15px var(--hint-danger); } 100% { box-shadow: 0 0 5px var(--hint-danger); } }

/* Orb */
#ai-thinking { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 120px; height: 120px; z-index: 1000; pointer-events: none; display: flex; justify-content: center; align-items: center; }
#ai-thinking.hidden { display: none !important; }
.orb-core { width: 30px; height: 30px; background: #00ffff; border-radius: 50%; box-shadow: 0 0 20px #00ffff, 0 0 40px rgba(0, 255, 255, 0.6); animation: pulse-core 0.8s ease-in-out infinite alternate; }
.orb-ring { width: 80px; height: 80px; border-top: 4px solid #00ffff; border-bottom: 4px solid #00ffff; box-shadow: 0 0 10px rgba(0, 255, 255, 0.3); animation: spin-cw 1.5s linear infinite; position: absolute; border-radius: 50%; }
.orb-ring-inner { width: 50px; height: 50px; border-left: 4px solid rgba(0, 255, 255, 0.7); border-right: 4px solid rgba(0, 255, 255, 0.7); animation: spin-ccw 1s linear infinite; position: absolute; border-radius: 50%; }
@keyframes spin-cw { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
@keyframes spin-ccw { from { transform: rotate(0deg); } to { transform: rotate(-360deg); } }
@keyframes pulse-core { from { transform: scale(0.8); opacity: 0.8; } to { transform: scale(1.2); opacity: 1; } }

/* Pieces */
.piece { width: 90%; height: 90%; background-size: contain; background-repeat: no-repeat; background-position: center; cursor: grab; z-index: 5; position: absolute; transition: transform 0.4s ease-in-out; }
.piece:active { cursor: grabbing; }
.piece.dragging { position: fixed !important; z-index: 9999 !important; cursor: grabbing; pointer-events: none; opacity: 0.9; transform: scale(1.1); transition: none; }

/* Themes */
.theme-blue { --board-light: #dee3e6; --board-dark: #8ca2ad; }
.theme-tan { --board-light: #f0d9b5; --board-dark: #b58863; }
.theme-gray { --board-light: #e0e0e0; --board-dark: #707070; }
.theme-green { --board-light: #ebecd0; --board-dark: #739552; }
.texture-grooves .square { background-image: repeating-linear-gradient(45deg, transparent, transparent 2px, rgba(0,0,0,0.05) 2px, rgba(0,0,0,0.05) 4px); }
.texture-dots .square { background-image: radial-gradient(rgba(0,0,0,0.1) 15%, transparent 16%); background-size: 8px 8px; }
.texture-geo .square { background-image: linear-gradient(45deg, rgba(0,0,0,0.05) 25%, transparent 25%, transparent 75%, rgba(0,0,0,0.05) 75%, rgba(0,0,0,0.05)), linear-gradient(45deg, rgba(0,0,0,0.05) 25%, transparent 25%, transparent 75%, rgba(0,0,0,0.05) 75%, rgba(0,0,0,0.05)); background-size: 20px 20px; }
.texture-shadow .square { box-shadow: inset 0 0 15px rgba(0,0,0,0.2); }

/* Utility */
.hidden { display: none !important; }

/* --- MOBILE & TABLET LAYOUT (The Responsive Magic) --- */
@media (max-width: 768px) {
    /* 1. Stack the layout vertically */
    #app-container {
        flex-direction: column;
        justify-content: flex-start;
        padding-top: 10px;
        overflow-y: auto; /* Allow scrolling if panel is tall */
    }

    /* 2. Board sizing for mobile */
    #board-container {
        width: 95vw;
        height: 95vw; /* Maintain square aspect ratio */
        margin-bottom: 10px;
        flex-shrink: 0; /* Keep board size fixed */
    }

    /* 3. Panel Styling for Mobile */
    .panel {
        position: relative; /* No longer floating absolute */
        top: auto; right: auto; left: auto;
        width: 100%;
        max-width: 95vw;
        border-radius: 8px;
        box-shadow: none;
        background: rgba(35, 35, 35, 0.95);
        max-height: none; /* Allow it to grow */
        overflow: visible;
        margin-bottom: 20px;
    }

    /* 4. Hide the "Toggle Sidebar" buttons on mobile since it's always visible */
    #toggle-panel-btn, #show-panel-btn {
        display: none !important;
    }

    /* 5. Make buttons slightly larger/easier to tap */
    button, select {
        padding: 10px;
        font-size: 1rem;
    }
}