/* ============================================================================
   ROBOTIC CHESS - MAIN STYLESHEET
   ============================================================================ */

/* ============================================================================
   CSS CUSTOM PROPERTIES (VARIABLES)
   ============================================================================ */

:root {
    /* Color Palette */
    --color-bg-primary: #222;
    --color-bg-secondary: #333;
    --color-bg-tertiary: #444;
    --color-text-primary: whitesmoke;
    --color-text-secondary: #fff;
    --color-text-dark: #222;
    --color-text-black: #000;
    
    /* Chess Board Colors */
    --color-square-light: #f0d9b5;
    --color-square-dark: #b58863;
    --color-square-selected-light: #d32f2f;
    --color-square-selected-dark: #b71c1c;
    --color-square-light-move-from: #ffd700;
    --color-square-light-move-to: #ffd700;
    --color-square-dark-move-from: #da9c00;
    --color-square-dark-move-to: #da9c00;

    /* Timer Colors */
    --color-timer-bg: #444;
    --color-timer-active-bg: whitesmoke;
    --color-timer-active-text: #000;
    
    /* Interactive Colors */
    --color-focus-outline: #007acc;
    --color-button-selected-bg: #f1f1f1;
    --color-button-selected-text: #000;
    
    /* Overlay Colors */
    --color-overlay-bg: #1e1e1e80;
    --color-shadow: #00000066;
    
    /* Spacing */
    --spacing-xs: 2px;
    --spacing-sm: 4px;
    --spacing-md: 8px;
    --spacing-lg: 16px;
    --spacing-xl: 20px;
    --spacing-xxl: 24px;
    
    /* Border Radius */
    --radius-sm: 6px;
    --radius-md: 7px;
    --radius-lg: 16px;
    
    /* Font Sizes */
    --font-size-sm: 12px;
    --font-size-md: 14px;
    --font-size-lg: 15px;
    
    /* Layout Dimensions */
    --board-label-size: 16px;
    --timer-min-width: 75px;
    --timer-height: 31px;
    --overlay-min-width: 400px;
    --chess-container-min-width: 300px;
    --menu-min-width: 200px;
    --code-editor-btn-min-width: 110px;
}

/* ============================================================================
   BASE LAYOUT & TYPOGRAPHY
   ============================================================================ */

.app-body {
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ============================================================================
   LAYOUT CONTAINERS
   ============================================================================ */

.main-content-container {
    flex: 1 1 auto;
    display: flex;
    flex-wrap: wrap;
}

.chess-game-container {
    display: flex;
    justify-content: center;
    align-items: center;
    flex: 1 1 400px;
    min-width: var(--chess-container-min-width);
    align-self: flex-start;
}

/* Navigation and sidebar menus */
.app-sidemenu {
    background-color: var(--color-bg-secondary);
    color: var(--color-text-primary);
}

.menu-section {
    background-color: var(--color-bg-tertiary);
}

/* ============================================================================
   CHESS BOARD COMPONENTS
   ============================================================================ */

.chess-board-wrapper {
    margin: var(--spacing-xl) 40px;
    width: 100%;
    max-width: 70vh;
}

.chess-game-board {
    aspect-ratio: 1 / 1;
    margin: var(--spacing-lg) 0;
    box-shadow: 0 0 var(--spacing-xl) #0008;
}

/* Board structure */
.board-game-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    height: calc(calc(100% - 32px) / 8);
}

.board-label-row {
    height: var(--board-label-size);
}

/* Board labels and coordinates */
.board-coordinate-label {
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--color-text-dark);
    font-weight: bold;
    font-size: var(--font-size-sm);
    user-select: none;
}

.board-vertical-label {
    width: var(--board-label-size);
    height: 100%;
}

.board-horizontal-label {
    width: calc(calc(100% - var(--board-label-size) * 2) / 8);
    height: 100%;
}

.board-corner-element {
    width: var(--board-label-size);
    height: 100%;
    border-top-left-radius: var(--board-label-size);
}

/* Chess squares */
.chess-game-square {
    width: calc(calc(100% - var(--board-label-size) * 2) / 8);
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
}

/* Square colors */
.square-light { background: var(--color-square-light); }
.square-dark { background: var(--color-square-dark); }

/* Move highlighting */
.square-light.move-from { background: var(--color-square-light-move-from); }
.square-light.move-to   { background: var(--color-square-light-move-to); }
.square-dark.move-from  { background: var(--color-square-dark-move-from); }
.square-dark.move-to    { background: var(--color-square-dark-move-to); }

/* Selected square highlighting */
.square-light.square-selected { background: var(--color-square-selected-light) !important; }
.square-dark.square-selected { background: var(--color-square-selected-dark) !important; }

/* Chess pieces */
.chess-game-piece {
    width: 100%;
    height: 100%;
    user-select: none;
    -webkit-user-drag: none;
    pointer-events: none;
}

.piece-dragging {
    position: absolute;
}

/* ============================================================================
   PLAYER INTERFACE
   ============================================================================ */

.player-info-container {
    padding: 0 10px;
    min-height: var(--timer-height);
    height: var(--timer-height);
}

.player-display-name {
    height: 100%;
    display: flex;
    align-items: center;
}

/* Timer displays */
.game-timer,
.timer-display {
    background-color: var(--color-timer-bg);
    color: var(--color-text-primary);
    min-width: var(--timer-min-width);
    min-height: var(--timer-height);
    text-align: center;
    margin-left: 5px;
}

.timer-active {
    background-color: var(--color-timer-active-bg);
    color: var(--color-timer-active-text);
}

/* ============================================================================
   MENU & NAVIGATION
   ============================================================================ */

.bot-list-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--spacing-md);
}

.bot-list-item {
    display: inline-flex;
    align-items: center;
    width: 100%;
    background: #333;
    color: white;
    user-select: none;
    position: relative;
    min-height: 31px;
    margin-top: 2px;
}

.bot-list-item .bot-list-badge {
    margin-left: 4px;
    padding: 0px;
    font-size: 14px;
    min-width: 28px;
    min-height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    outline: 4px solid #333;
}

.bot-list-item .bot-list-badge.hover-only {
    display: none;
    outline: none;
}

.bot-list-item:hover .bot-list-badge.hover-only {
    display: flex !important;
    outline: 4px solid #333;
}

.bot-list-item:hover .bot-list-badge.left {
    left: 0;
}

.bot-list-item .bot-list-name {
    flex: 1;
    min-width: 0;
    overflow: show;
    white-space: nowrap;
}

.language-color.js {
    background: #f7e018;
    color: black;
}

.language-color.ts {
    background: #3178c6;
    color: black;
}

.language-color.py {
    background: #3572A5;
    color: black;
}

/* Bot list items */
.custom-bot-item {
    display: inline-flex;
    align-items: center;
    width: 100%;
    background: var(--color-bg-secondary);
    color: var(--color-text-secondary);
    user-select: none;
    position: relative;
    min-height: var(--timer-height);
    margin-top: var(--spacing-xs);
}

.bot-action-button {
    margin-left: var(--spacing-sm);
    padding: 0;
    font-size: var(--font-size-md);
    min-width: 28px;
    display: none;
}

.custom-bot-item:hover .bot-action-button {
    display: inline-block !important;
}


/* Loader */
.loader,
.loader div {
    box-sizing: border-box;
}
.loader {
    display: inline-block;
    position: relative;
    width: 56px;
    height: 56px;
}
.loader div {
    box-sizing: border-box;
    display: block;
    position: absolute;
    width: 40px;
    height: 40px;
    margin: 8px;
    border: 8px solid currentColor;
    border-radius: 100%;
    animation: loader 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
    border-color: currentColor transparent transparent transparent;
}
.loader div:nth-child(1) {
    animation-delay: 0s;
    border-color: whitesmoke transparent transparent transparent;
}
.loader div:nth-child(2) {
    animation-delay: -0.6s;
    border-color: #007acc transparent transparent transparent;
}
@keyframes loader {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}


/* ============================================================================
   OVERLAY SYSTEM
   ============================================================================ */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--color-overlay-bg);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    isolation: isolate;
}

/* Make content behind overlay non-interactive */
.modal-overlay-active {
    overflow: hidden;
}

.modal-overlay-active > *:not(.modal-overlay) {
    pointer-events: none;
    filter: blur(1px);
    transition: filter 0.2s ease;
}

.modal-overlay-active > *:not(.modal-overlay) * {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    pointer-events: none;
}

.modal-content-wrapper {
    background: var(--color-bg-primary);
    padding: var(--spacing-xl);
    box-shadow: 0 4px var(--spacing-xxl) var(--color-shadow);
    min-width: var(--overlay-min-width);
    border-radius: var(--radius-md);
    position: relative;
}

.fullscreen-modal {
    width: 100vw;
    height: 100vh;
}

.modal-close-button {
    font-size: var(--font-size-md);
    position: absolute;
    top: var(--spacing-sm);
    right: var(--spacing-sm);
    background: transparent;
    color: var(--color-text-secondary);
    width: var(--spacing-xxl);
    height: var(--spacing-xxl);
    padding: 0;
    aspect-ratio: 1 / 1;
}

/* ============================================================================
   FORM COMPONENTS
   ============================================================================ */

.game-configuration-form {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.player-config-section {
    color: var(--color-text-secondary);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.config-section-label {
    font-weight: bold;
    margin-bottom: var(--spacing-sm);
}

.button-selection-group {
    display: flex;
    align-items: center;
}

.selection-toggle-button {
    flex: 1;
}

.hidden-form-select {
    flex: 1;
    display: none !important;
}

.bot-configuration-panel {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.bot-selection-dropdown {
    height: 30px;
}

.bot-file-input {
    display: none;
}

.form-submit-button {
    margin-top: 18px;
}

/* ============================================================================
   CODE EDITOR
   ============================================================================ */

.code-editor-layout {
    display: flex;
    flex-direction: column;
    user-select: none;
}

.code-editor-panel {
    display: flex;
    flex: 1 1 auto;
    width: 100%;
    height: 100%;
    min-height: 400px;
    margin: var(--spacing-lg) 0 0 0;
    background: #1e1e1e;
    color: var(--color-text-secondary);
    border: 2px solid var(--color-text-secondary);
    border-radius: var(--radius-sm);
    overflow: hidden;
    padding: 0 !important;
    position: relative;
}

/* Ensure Monaco Editor takes full space */
.code-editor-panel .monaco-editor {
    width: 100% !important;
    height: 100% !important;
}

/* Monaco Editor scrollbar styling to match theme */
.code-editor-panel .monaco-scrollable-element > .scrollbar {
    background: rgba(255, 255, 255, 0.1) !important;
}

.code-editor-panel .monaco-scrollable-element > .scrollbar > .slider {
    background: rgba(255, 255, 255, 0.3) !important;
}

.code-editor-panel .monaco-scrollable-element > .scrollbar > .slider:hover {
    background: rgba(255, 255, 255, 0.5) !important;
}

.code-editor-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-lg);
    width: 100%;
    text-align: center;
    flex-shrink: 0;
    z-index: 1000;
}

.editor-toolbar-button {
    min-width: var(--code-editor-btn-min-width);
}

.editor-title-input {
    flex: 1;
    text-align: center;
}

.editor-language-select {
    min-width: 120px;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: var(--radius-sm);
    background: white;
    font-size: 14px;
}

/* ============================================================================
   GAME INFO COMPONENTS
   ============================================================================ */

.moves-list-scrollable {
    max-height: 200px;
    overflow-y: auto;
    margin-top: var(--spacing-sm);
    border: 1px solid #ddd;
    border-radius: var(--radius-sm);
    background: #f9f9f9;
}

.moves-list-content {
    padding: var(--spacing-sm);
    min-height: 40px;
}

.move-pair {
    display: flex;
    align-items: center;
    margin-bottom: var(--spacing-xs);
    font-family: 'Courier New', 'Consolas', monospace;
    font-size: var(--font-size-sm);
}

.move-number {
    font-weight: bold;
    color: var(--color-text-dark);
    min-width: 20px;
    margin-right: var(--spacing-sm);
}

.move-notation {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--spacing-sm);
}

.white-move, .black-move {
    padding: 2px var(--spacing-sm);
    border-radius: var(--radius-sm);
    cursor: pointer;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.white-move {
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid #ccc;
}

.black-move {
    background: rgba(0, 0, 0, 0.1);
    border: 1px solid #999;
}

.black-move-placeholder {
    /* Grid will automatically place this in the second column */
    min-width: 0;
}

.white-move:hover, .black-move:hover {
    background: rgba(0, 123, 255, 0.1);
    border-color: #007bff;
}

.move-current {
    background: rgba(0, 123, 255, 0.2) !important;
    border-color: #007bff !important;
    font-weight: bold;
}

/* Move History Controls */
.move-history-header {
    margin-bottom: var(--spacing-sm);
}

.move-history-controls {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

.move-history-controls button {
    min-width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.move-history-controls button:disabled {
    opacity: 0.4;
    cursor: default;
    transform: none;
    box-shadow: none;
    background-color: #ccc !important;
    color: #666 !important;
    border-color: #ccc !important;
}

/* Custom scrollbar for moves list */
.moves-list-scrollable::-webkit-scrollbar {
    width: 6px;
}

.moves-list-scrollable::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.moves-list-scrollable::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

.moves-list-scrollable::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* ============================================================================
   RESPONSIVE DESIGN
   ============================================================================ */

@media (min-width: 993px) {
    .expand-on-large {
        height: 100%;
    }
}

@media (min-width: 601px) {
    .expand-on-medium {
        height: 100%;
    }
}

@media (max-width: 600px) {    
    .editor-toolbar-button {
        min-width: 0px;
    }

    .editor-toolbar-button .editor-toolbar-button-label {
        display: none;
    }
}

/* ============================================================================
   ACCESSIBILITY & INTERACTION
   ============================================================================ */

/* Focus indicators */
*:focus-visible:not(.monaco-editor):not(.monaco-editor *) {
    outline: 3px solid var(--color-focus-outline) !important;
    outline-offset: -3px;
}

/* Visual feedback */
.selection-toggle-button.w3-light-grey {
    background-color: var(--color-button-selected-bg) !important;
    color: var(--color-button-selected-text) !important;
}

/* ============================================================================
   PROMOTION SELECTION UI
   ============================================================================ */

.promotion-pieces-container {
    display: flex;
    justify-content: center;
    gap: var(--spacing-lg);
    margin-top: var(--spacing-lg);
}

.promotion-piece-button {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--spacing-lg) !important;
    min-width: 80px;
    min-height: 80px;
    cursor: pointer;
    transition: transform 0.03s ease;
}

.promotion-piece-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px var(--color-shadow);
    background: var(--color-bg-secondary) !important;
}

.promotion-piece-button:active {
    transform: translateY(0);
}

.promotion-piece-icon {
    font-size: 36px;
    margin-bottom: var(--spacing-sm);
    color: var(--color-text-primary);
}

.promotion-piece-label {
    font-size: 14px;
    font-weight: bold;
    color: var(--color-text-primary);
}

.promotion-piece-shortcut {
    font-size: 11px;
    color: var(--color-text-secondary);
    margin-top: 2px;
}

/* Responsive design for promotion UI */
@media (max-width: 600px) {
    .promotion-pieces-container {
        flex-wrap: wrap;
        gap: var(--spacing-md);
    }
    
    .promotion-piece-button {
        min-width: 70px;
        min-height: 70px;
        padding: var(--spacing-md) !important;
    }
    
    .promotion-piece-icon {
        font-size: 28px;
    }
    
    .promotion-piece-label {
        font-size: 12px;
    }
}

/* Monaco Editor Integration Styles */
.code-editor-overlay .modal-content-wrapper {
    max-width: 95vw;
    max-height: 95vh;
    width: 90vw;
    height: 85vh;
}

/* Monaco Editor loading state */
.code-editor-panel.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1e1e1e;
    color: #fff;
    font-family: 'Consolas', monospace;
}

.code-editor-panel.loading::after {
    content: "Loading Monaco Editor...";
    font-size: 16px;
    opacity: 0.7;
}

/* Monaco Editor error state */
.code-editor-panel .monaco-editor-error {
    padding: 20px;
    background: #1e1e1e;
    color: #ff6b6b;
    font-family: 'Consolas', monospace;
    text-align: center;
    border-radius: 4px;
}

.code-editor-panel .monaco-editor-error h3 {
    margin: 0 0 10px 0;
    color: #ff6b6b;
}

.code-editor-panel .monaco-editor-error button {
    background: #444;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-family: inherit;
    margin-top: 10px;
}

.code-editor-panel .monaco-editor-error button:hover {
    background: #666;
}

/* Responsive design for smaller screens */
@media (max-width: 768px) {
    .code-editor-overlay .modal-content-wrapper {
        width: 98vw;
        height: 95vh;
        max-width: 98vw;
        max-height: 95vh;
    }
    
    .code-editor-panel {
        min-height: 300px;
    }
    
    .editor-toolbar-button-label {
        display: none;
    }
    
    .editor-toolbar-button {
        min-width: 40px;
        padding: 8px 12px;
    }
}