/* ============================================
   VOID CHESS - Professional Dark Theme CSS
   Chess.com Inspired Design
   ============================================ */

/* CSS Variables */
:root {
    /* Colors - Premium Dark + Gold */
    --bg-primary: #0a0a0f;
    --bg-secondary: #111118;
    --bg-tertiary: #18181f;
    --accent-primary: #FF5E3A;
    --accent-secondary: #3dd6c8;
    --text-primary: #f5f0e8;
    --text-secondary: #9a9a9a;
    --text-muted: #555555;

    /* Board Colors */
    --tile-light: #eeeed2;
    --tile-dark: #769656;
    --tile-selected: rgba(255, 220, 0, 0.4);
    --tile-move-hint: rgba(100, 100, 100, 0.5);
    --tile-last-move: rgba(255, 200, 50, 0.3);
    --tile-check: rgba(255, 0, 0, 0.5);

    /* Void System Colors */
    --tile-unstable: #ff4444;
    --tile-unstable-glow: rgba(255, 68, 68, 0.6);
    --tile-void: #1a1a1a;
    --tile-void-border: #000000;

    /* UI */
    --panel-bg: rgba(17, 17, 24, 0.95);
    --border-color: #2a2a2f;
    --button-bg: #1e1e26;
    --button-hover: #2a2a35;
    --button-primary: #FF5E3A;
    --button-primary-hover: #FF7A5C;

    /* Sizing - Desktop default, overridden by media queries for mobile */
    --board-size: min(500px, calc(100vh - 230px));
    --tile-size: calc(var(--board-size) / 9);
    --piece-size: calc(var(--tile-size) * 0.92);
}

/* Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100dvh;
    height: 100%;
    width: 100%;
    overflow: hidden;
    overflow-x: hidden;
    overflow-y: hidden;
    margin: 0;
    padding: 0;
    -webkit-overflow-scrolling: touch;
    /* Prevent pull-to-refresh on mobile */
    overscroll-behavior: none;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100dvh;
}

#app {
    width: 100%;
    height: 100dvh;
    height: 100%;
    position: relative;
}

/* ============================================
   SCREENS
   ============================================ */
.screen {
    display: none;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

.screen.active {
    display: flex;
    flex-direction: column;
}

/* ============================================
   MAIN MENU
   ============================================ */
.menu-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 2rem;
    text-align: center;
}

.game-title {
    font-size: 4rem;
    font-weight: 800;
    color: var(--accent-primary);
    text-shadow: 0 0 30px rgba(255, 94, 58, 0.4);
    letter-spacing: 0.3em;
    margin-bottom: 0.5rem;
    animation: titleGlow 2s ease-in-out infinite alternate;
}

@keyframes titleGlow {
    from { text-shadow: 0 0 20px rgba(255, 94, 58, 0.3); }
    to { text-shadow: 0 0 40px rgba(255, 94, 58, 0.6), 0 0 60px rgba(255, 94, 58, 0.3); }
}

.subtitle {
    font-size: 1.2rem;
    color: var(--text-secondary);
    margin-bottom: 3rem;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
    max-width: 320px;
}

.menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.8rem;
    padding: 1rem 2rem;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    background: var(--button-bg);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.menu-btn:hover {
    background: var(--button-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.menu-btn.primary {
    background: linear-gradient(135deg, #FF5E3A 0%, #E8461E 100%);
    border-color: #FF5E3A;
    color: #0a0a0f;
}

.menu-btn.primary:hover {
    background: linear-gradient(135deg, #FF7A5C 0%, #F05A32 100%);
    border-color: #FF7A5C;
    color: #0a0a0f;
}

.btn-icon {
    font-size: 1.5rem;
}

.version-info {
    position: absolute;
    bottom: 1rem;
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* ============================================
   LEVEL SELECTION
   ============================================ */
.level-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    flex: 1;
    overflow: hidden;
}

/* Screen Header Bar (for level select, rules, etc.) */
.screen-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    width: 100%;
    flex-shrink: 0;
}

.screen-header .header-title {
    flex: 1;
    text-align: center;
}

.header-back-btn {
    width: 40px;
    height: 40px;
    font-size: 1.3rem;
    color: var(--text-primary);
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.header-back-btn:hover {
    color: var(--accent-secondary);
}

.header-spacer {
    width: 40px;
    flex-shrink: 0;
}

.section-title {
    font-size: 1.2rem;
    color: var(--accent-secondary);
    margin-bottom: 0.8rem;
}

/* Levels wrapper */
.levels-wrapper {
    width: 100%;
    max-width: 280px;
    margin-bottom: 1rem;
}

/* Difficulty labels */
.difficulty-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 4px;
    margin-top: 8px;
    padding-left: 2px;
}

.difficulty-label.beginner { color: #4ade80; }
.difficulty-label.intermediate { color: #facc15; }
.difficulty-label.advanced { color: #f97316; }
.difficulty-label.expert { color: #ef4444; }

/* Level row - 5 buttons per row */
.level-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
}

/* Small level buttons */
.level-btn-small {
    width: 100%;
    aspect-ratio: 1;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-primary);
    background: var(--button-bg);
    border: 2px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.level-btn-small .lock-icon {
    font-size: 0.75rem;
    opacity: 0.6;
}

.level-btn-small:hover:not(.locked):not(.selected) {
    background: var(--button-hover);
    transform: scale(1.08);
}

.level-btn-small.selected {
    background: linear-gradient(135deg, #FF5E3A 0%, #E8461E 100%);
    border-color: #FF5E3A;
    color: #0a0a0f;
}

.level-btn-small.locked {
    background: #1a1a2a;
    color: var(--text-muted);
    cursor: not-allowed;
}

/* Compact Side Selection */
.side-selection-compact {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.side-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.side-toggle {
    display: flex;
    gap: 0.5rem;
}

.side-btn-compact {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    color: var(--text-primary);
    background: var(--button-bg);
    border: 2px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.side-btn-compact:hover {
    background: var(--button-hover);
}

.side-btn-compact.selected {
    border-color: #FF5E3A;
    background: rgba(255, 94, 58, 0.1);
}

.piece-icon-small {
    font-size: 1.2rem;
}

.start-btn-compact {
    padding: 0.8rem 2.5rem;
    font-size: 1rem;
}

/* ============================================
   RULES SCREEN
   ============================================ */
.rules-container {
    display: flex;
    flex-direction: column;
    padding: 1rem;
    flex: 1;
    overflow-y: auto;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.rules-container .section-title {
    text-align: center;
    margin-bottom: 1rem;
}

.rules-content {
    flex: 1;
}

.rule-section {
    background: var(--panel-bg);
    padding: 1.5rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
}

.rule-section h3 {
    color: var(--accent-secondary);
    margin-bottom: 0.8rem;
}

.rule-section p, .rule-section li {
    color: var(--text-secondary);
    line-height: 1.6;
}

.rule-section ul, .rule-section ol {
    margin-left: 1.5rem;
    margin-top: 0.5rem;
}

.unstable-text {
    color: var(--tile-unstable);
    font-weight: 600;
}

.void-text {
    color: #666;
    font-weight: 600;
}

/* ============================================
   GAME SCREEN
   ============================================ */
#game-screen {
    display: none;
}

#game-screen.active {
    display: -webkit-box;
    display: -webkit-flex;
    display: -moz-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    -webkit-flex-direction: column;
    -moz-box-orient: vertical;
    -moz-box-direction: normal;
    -ms-flex-direction: column;
    flex-direction: column;
    height: 100%;
    width: 100%;
}

/* Header */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.header-btn {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    color: var(--text-primary);
    background: var(--button-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.header-btn:hover {
    background: var(--button-hover);
}

/* Game Layout */
.game-layout {
    display: flex;
    flex: 1;
    justify-content: center;
    align-items: center;
    padding: 0;
    margin: 0;
    width: 100%;
    min-height: 0;
    overflow: hidden;
}

/* Hide side panel to maximize board space */
.side-panel {
    display: none;
}

/* Bottom Moves Bar */
.moves-bar {
    width: 100%;
    background: var(--bg-secondary);
    border-top: 2px solid rgba(255, 94, 58, 0.4);
    padding: 0.5rem;
    flex-shrink: 0;
    min-height: 50px;
    position: relative;
    z-index: 50;
}

/* Mobile: Extra padding for Android nav buttons */
@media (max-width: 768px) {
    .moves-bar {
        padding-bottom: 2.5rem;
        min-height: 65px;
    }
}

/* Safe area for devices with notch/gesture navigation */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    @media (max-width: 768px) {
        .moves-bar {
            padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
        }
    }
}

.moves-list {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-orient: horizontal;
    -webkit-box-direction: normal;
    -ms-flex-wrap: nowrap;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 0.5rem;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.moves-list::-webkit-scrollbar {
    display: none;
}

.move-row {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-shrink: 0;
    font-size: 0.9rem;
    padding: 0.3rem 0.5rem;
    background: var(--bg-tertiary);
    border-radius: 4px;
}

.move-number {
    color: var(--text-muted);
    font-weight: 600;
}

.move-white, .move-black {
    color: var(--text-primary);
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
}

.move-white {
    background: rgba(255, 255, 255, 0.1);
}

.move-black {
    background: rgba(0, 0, 0, 0.3);
}

.move-capture {
    color: var(--tile-unstable);
}

/* Header Center - Turn Indicator */
.header-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.turn-indicator {
    font-size: 1rem;
    font-weight: 600;
    padding: 0.4rem 1rem;
    background: var(--bg-tertiary);
    border-radius: 4px;
}

.turn-indicator.white-turn {
    color: #fff;
    background: linear-gradient(135deg, #555 0%, #333 100%);
    border: 1px solid #666;
}

.turn-indicator.black-turn {
    color: #333;
    background: linear-gradient(135deg, #eee 0%, #ccc 100%);
    border: 1px solid #999;
}

.game-status {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.game-status.check {
    color: #e84057;
    font-weight: 600;
}

/* Board Area */
.board-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    width: 100%;
    max-height: 100%;
}

/* Player Bars - Chess.com Style */
.player-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: min(500px, calc(100vh - 230px));
    padding: 0.4rem 0.75rem;
    background: #2a2a32;
    border-radius: 4px;
    margin: 0.3rem auto;
    flex-shrink: 0;
}

.player-identity {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.player-avatar {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #333;
    border-radius: 4px;
    font-size: 1.2rem;
}

.player-avatar-you {
    background: linear-gradient(135deg, #FF5E3A 0%, #E8461E 100%);
    color: #0a0a0f;
}

.opponent-avatar {
    background: #555;
}

.player-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.captured-pieces {
    display: flex;
    flex-wrap: wrap;
    gap: 1px;
    justify-content: flex-end;
    max-width: 50%;
}

.captured-piece {
    font-size: 1rem;
    opacity: 0.9;
    line-height: 1;
}

.captured-piece-image {
    width: 20px;
    height: 20px;
    object-fit: contain;
    vertical-align: middle;
    filter: drop-shadow(0 0 1px rgba(255, 255, 255, 0.3));
}

/* Board Wrapper */
.board-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
}

/* Coordinate labels inside tiles (chess.com style) */
.coord-label {
    position: absolute;
    font-size: 0.6rem;
    font-weight: 700;
    pointer-events: none;
    z-index: 15;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.coord-rank {
    top: 2px;
    left: 3px;
}

.coord-file {
    bottom: 2px;
    right: 3px;
}

/* Coordinate colors based on tile */
.tile.light .coord-label {
    color: var(--tile-dark);
}

.tile.dark .coord-label {
    color: var(--tile-light);
}

/* ============================================
   CHESS BOARD
   ============================================ */
.chess-board {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    grid-template-rows: repeat(9, 1fr);
    border: 2px solid var(--border-color);
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.5);
    /* Desktop: fit viewport height, max 500px */
    width: min(500px, calc(100vh - 230px));
    height: min(500px, calc(100vh - 230px));
    margin: 0 auto;
    flex-shrink: 0;
}

.tile {
    aspect-ratio: 1 / 1;
    display: -webkit-box;
    display: -webkit-flex;
    display: -moz-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -moz-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    -webkit-box-pack: center;
    -webkit-justify-content: center;
    -moz-box-pack: center;
    -ms-flex-pack: center;
    justify-content: center;
    position: relative;
    cursor: pointer;
    -webkit-transition: background 0.15s;
    -moz-transition: background 0.15s;
    -o-transition: background 0.15s;
    transition: background 0.15s;
}

.tile.light {
    background: var(--tile-light);
}

.tile.dark {
    background: var(--tile-dark);
}

/* Tile States */
.tile.selected::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 0, 0.4);
    pointer-events: none;
    z-index: 1;
}

.tile.last-move::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 0, 0.35);
    pointer-events: none;
    z-index: 1;
}

.tile.check {
    background: var(--tile-check) !important;
}

.tile.legal-move::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 25%;
    height: 25%;
    background: var(--tile-move-hint);
    border-radius: 50%;
    -webkit-transform: translate(-50%, -50%);
    -moz-transform: translate(-50%, -50%);
    -ms-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 5;
}

.tile.legal-capture::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 90%;
    height: 90%;
    border: 4px solid var(--tile-move-hint);
    border-radius: 50%;
    background: transparent;
    -webkit-transform: translate(-50%, -50%);
    -moz-transform: translate(-50%, -50%);
    -ms-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 5;
}

/* Void System Tiles */
.tile.unstable {
    background: var(--tile-unstable) !important;
    animation: unstablePulse 1s ease-in-out infinite;
}

@keyframes unstablePulse {
    0%, 100% {
        box-shadow: inset 0 0 20px var(--tile-unstable-glow);
    }
    50% {
        box-shadow: inset 0 0 35px var(--tile-unstable-glow), 0 0 15px var(--tile-unstable-glow);
    }
}

/* Piece falling into void death animation */
.piece.void-death {
    animation: fallIntoVoid 0.6s ease-in forwards;
    pointer-events: none;
}

@keyframes fallIntoVoid {
    0% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
    40% {
        transform: scale(0.7) rotate(30deg);
        opacity: 0.8;
    }
    70% {
        transform: scale(0.3) rotate(90deg);
        opacity: 0.4;
    }
    100% {
        transform: scale(0) rotate(180deg);
        opacity: 0;
    }
}

/* Tile transitioning from unstable to void during death */
.tile.becoming-void {
    transition: background 0.5s ease-in;
    background: #000 !important;
    box-shadow: inset 0 0 10px 3px rgba(0, 0, 0, 0.9);
}

/* Void tile - deep black with subtle edge separation */
.tile.void {
    background: #000 !important;
    cursor: not-allowed;
    box-shadow: inset 0 0 0 1px #1a1a1a;
}

/* Chess Pieces */
.piece {
    display: -webkit-box;
    display: -webkit-flex;
    display: -moz-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -moz-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    -webkit-box-pack: center;
    -webkit-justify-content: center;
    -moz-box-pack: center;
    -ms-flex-pack: center;
    justify-content: center;
    width: var(--piece-size);
    height: var(--piece-size);
    font-size: var(--piece-size);
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    cursor: grab;
    -webkit-transition: transform 0.1s;
    -moz-transition: transform 0.1s;
    -ms-transition: transform 0.1s;
    -o-transition: transform 0.1s;
    transition: transform 0.1s;
    z-index: 10;
    line-height: 1;
}

.piece:hover {
    -webkit-transform: scale(1.1);
    -moz-transform: scale(1.1);
    -ms-transform: scale(1.1);
    -o-transform: scale(1.1);
    transform: scale(1.1);
}

.piece.white {
    color: #fff;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.piece.black {
    color: #000;
    text-shadow: 0 2px 4px rgba(255, 255, 255, 0.3);
}

.piece.dragging {
    cursor: grabbing;
    -webkit-transform: scale(1.2);
    -moz-transform: scale(1.2);
    -ms-transform: scale(1.2);
    -o-transform: scale(1.2);
    transform: scale(1.2);
    z-index: 100;
}

/* Piece Images */
.piece-image {
    width: 100%;
    height: 100%;
    max-width: var(--piece-size);
    max-height: var(--piece-size);
    -o-object-fit: contain;
    object-fit: contain;
    pointer-events: none;
    -webkit-filter: drop-shadow(1px 2px 3px rgba(0, 0, 0, 0.4));
    filter: drop-shadow(1px 2px 3px rgba(0, 0, 0, 0.4));
}

/* ============================================
   DIALOGS
   ============================================ */
.dialog {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

.dialog.hidden {
    display: none;
}

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

.dialog-content {
    background: var(--bg-secondary);
    padding: 2rem;
    border-radius: 12px;
    border: 2px solid var(--border-color);
    text-align: center;
    animation: slideIn 0.3s ease;
    max-width: 90%;
}

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

.dialog-content h2, .dialog-content h3 {
    margin-bottom: 1rem;
    color: var(--accent-secondary);
}

.dialog-content p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.dialog-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.dialog-btn {
    padding: 0.8rem 2rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    background: var(--button-bg);
    border: 2px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.dialog-btn:hover {
    background: var(--button-hover);
}

.dialog-btn.primary {
    background: linear-gradient(135deg, #FF5E3A 0%, #E8461E 100%);
    border-color: #FF5E3A;
    color: #0a0a0f;
}

.dialog-btn.primary:hover {
    background: linear-gradient(135deg, #FF7A5C 0%, #F05A32 100%);
    color: #0a0a0f;
}

/* Promotion Dialog */
.promotion-content {
    padding: 1.5rem 2rem;
}

.promotion-pieces {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

.promotion-btn {
    width: 70px;
    height: 70px;
    font-size: 50px;
    background: var(--button-bg);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.promotion-btn:hover {
    background: var(--button-hover);
    transform: scale(1.1);
}

.promo-piece-image {
    width: 48px;
    height: 48px;
    object-fit: contain;
}

/* Game Over Dialog */
.gameover-content {
    position: relative;
}

.gameover-content h2 {
    font-size: 2rem;
    color: var(--accent-primary);
    letter-spacing: 0.05em;
}

/* Close button for dialogs */
.dialog-close-btn {
    position: absolute;
    top: 8px;
    right: 12px;
    background: none;
    border: none;
    color: var(--text-secondary, #999);
    font-size: 1.8rem;
    cursor: pointer;
    line-height: 1;
    padding: 4px 8px;
    border-radius: 4px;
    transition: color 0.2s, background 0.2s;
}

.dialog-close-btn:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */
@media (max-width: 1200px) {
    .side-panel {
        width: 150px;
    }
}

/* Tablet / iPad screens (portrait and landscape) */
@media (max-width: 1024px) and (min-width: 769px) {
    .side-panel {
        display: none;
    }

    .game-layout {
        flex-direction: column;
    }

    .board-area {
        padding: 0.5rem;
        width: 100%;
    }

    /* Board fits the smaller of width or height, with breathing room */
    .chess-board {
        width: min(calc(100vw - 40px), calc(100dvh - 230px));
        height: min(calc(100vw - 40px), calc(100dvh - 230px));
    }

    .player-bar {
        width: min(calc(100vw - 40px), calc(100dvh - 230px));
    }
}

@media (max-width: 600px) {
    .game-title {
        font-size: 2.5rem;
    }

    .coord-label {
        font-size: 0.55rem;
    }

    .player-panel {
        padding: 0.3rem 0.5rem;
    }

    .header-title {
        font-size: 1rem;
    }
}

/* ============================================
   SCROLLBAR STYLING
   ============================================ */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--button-bg);
}

/* ============================================
   SETTINGS SCREEN
   ============================================ */
.settings-container {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    max-width: 500px;
    margin: 0 auto;
    width: 100%;
}

.settings-section {
    background: var(--panel-bg);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border-color);
}

.settings-section h3 {
    color: var(--accent-secondary);
    margin-bottom: 1rem;
    font-size: 1.1rem;
}

.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.8rem 0;
    border-bottom: 1px solid var(--border-color);
}

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

.setting-label {
    color: var(--text-primary);
    font-size: 1rem;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    width: 50px;
    height: 28px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border-color);
    transition: 0.3s;
    border-radius: 28px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 22px;
    width: 22px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
}

.toggle-switch input:checked + .toggle-slider {
    background-color: #FF5E3A;
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(22px);
}

/* Volume Slider */
.volume-slider {
    width: 120px;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border-color);
    border-radius: 3px;
    outline: none;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: #FF5E3A;
    border-radius: 50%;
    cursor: pointer;
}

.volume-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: #FF5E3A;
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.account-info {
    text-align: center;
}

.account-info p {
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

/* ============================================
   LOGIN SCREEN
   ============================================ */
.login-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.login-box {
    background: var(--panel-bg);
    border-radius: 16px;
    padding: 2.5rem;
    max-width: 400px;
    width: 100%;
    text-align: center;
    border: 1px solid var(--border-color);
}

.login-box h2 {
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    font-size: 1.5rem;
}

.login-subtitle {
    color: var(--text-secondary);
    margin-bottom: 2rem;
    font-size: 0.95rem;
}

.login-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.login-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.8rem;
    padding: 1rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
}

.login-btn.guest {
    background: var(--button-bg);
    color: var(--text-primary);
}

.login-btn.guest:hover {
    background: var(--button-hover);
}

.login-btn.google {
    background: #fff;
    color: #333;
    border-color: #ddd;
}

.login-btn.google:hover {
    background: #f5f5f5;
}

.login-icon {
    font-size: 1.3rem;
}

.google-icon {
    flex-shrink: 0;
}

.login-divider {
    display: flex;
    align-items: center;
    margin: 0.5rem 0;
}

.login-divider::before,
.login-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-color);
}

.login-divider span {
    padding: 0 1rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.login-note {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 1.5rem;
}

/* User Info in Menu */
.user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1.5rem;
    padding: 0.8rem 1.5rem;
    background: var(--panel-bg);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.user-info.hidden {
    display: none;
}

#user-name {
    color: var(--text-primary);
    font-weight: 600;
}

.small-btn {
    padding: 0.4rem 1rem;
    font-size: 0.85rem;
    background: var(--button-bg);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.small-btn:hover {
    background: var(--button-hover);
}

.login-prompt {
    margin-top: 1.5rem;
}

.menu-btn.secondary {
    background: transparent;
    border: 2px solid var(--border-color);
}

.menu-btn.secondary:hover {
    background: var(--button-bg);
}

/* ============================================
   WELCOME SCREEN
   ============================================ */
.welcome-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 2rem;
    text-align: center;
}

.welcome-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
    max-width: 320px;
    margin-top: 2rem;
}

.welcome-divider {
    display: flex;
    align-items: center;
    gap: 1rem;
    color: var(--text-muted);
    margin: 0.5rem 0;
}

.welcome-divider::before,
.welcome-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-color);
}

.welcome-note {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 2rem;
    max-width: 280px;
}

.login-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.8rem;
    padding: 1rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
}

.login-btn.google {
    background: #fff;
    color: #333;
    border-color: #ddd;
}

.login-btn.google:hover {
    background: #f5f5f5;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    transform: translateY(-2px);
}

.login-btn.guest {
    background: var(--button-bg);
    color: var(--text-primary);
}

.login-btn.guest:hover {
    background: var(--button-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.guest-icon {
    font-size: 1.3rem;
}

/* Back to Website link */
.back-to-site-link {
    display: inline-block;
    margin-top: 1rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.2s;
}

.back-to-site-link:hover {
    color: var(--accent-secondary);
}

.google-icon {
    width: 24px;
    height: 24px;
}

/* ============================================
   HAMBURGER MENU & SIDE MENU
   ============================================ */
.hamburger-btn {
    position: absolute;
    top: 1rem;
    left: 1rem;
    width: 48px;
    height: 48px;
    font-size: 1.8rem;
    background: var(--button-bg);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.hamburger-btn:hover {
    background: var(--button-hover);
}

.side-menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 200;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.side-menu-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.side-menu {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    max-width: 80%;
    height: 100%;
    background: var(--bg-secondary);
    border-right: 2px solid var(--border-color);
    z-index: 300;
    transform: translateX(0);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}

.side-menu.hidden {
    transform: translateX(-100%);
}

.side-menu-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem 1rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-primary);
}

.side-menu-header span {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.side-menu-close {
    width: 36px;
    height: 36px;
    font-size: 1.5rem;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
}

.side-menu-close:hover {
    background: var(--button-bg);
    color: var(--text-primary);
}

.side-menu-content {
    flex: 1;
    padding: 1rem 0;
}

.side-menu-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    width: 100%;
    padding: 1rem 1.5rem;
    font-size: 1rem;
    color: var(--text-primary);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
}

.side-menu-item:hover {
    background: var(--button-bg);
}

.side-menu-item.hidden {
    display: none;
}

.side-menu-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.side-menu-icon svg {
    width: 20px;
    height: 20px;
}

/* ============================================
   FIREFOX & MOBILE BROWSER FIXES
   ============================================ */

/* Firefox-specific fixes */
@-moz-document url-prefix() {
    .tile {
        height: auto;
        padding-bottom: 0;
    }

    .chess-board {
        display: grid;
    }

    .moves-bar {
        padding-bottom: 3rem;
    }
}

/* Mobile & small tablet viewport fix - accounts for browser chrome */
@media (max-width: 768px) {
    :root {
        --board-size: 100vw;
        --tile-size: calc(var(--board-size) / 9);
        --piece-size: calc(var(--tile-size) * 0.92);
    }

    html, body {
        height: 100dvh;
        height: -webkit-fill-available;
    }

    #app {
        height: 100dvh;
        min-height: -webkit-fill-available;
    }

    #game-screen.active {
        height: 100dvh;
        height: -webkit-fill-available;
        min-height: 0;
    }

    .game-layout {
        flex: 1 1 auto;
        min-height: 0;
        overflow: hidden;
    }

    .board-area {
        flex: 1 1 auto;
        min-height: 0;
        padding: 0;
    }

    /* Mobile: full width board - edge to edge */
    .chess-board {
        width: 100vw;
        height: 100vw;
        max-height: calc(100dvh - 200px);
        border-left: none;
        border-right: none;
        border-radius: 0;
    }

    .player-bar {
        width: 100vw;
    }
}

/* iPad Mini / large phones in landscape — prevent oversized board */
@media (min-width: 600px) and (max-width: 768px) {
    .chess-board {
        width: min(100vw, calc(100dvh - 200px));
        height: min(100vw, calc(100dvh - 200px));
    }
}

/* Very small screens */
@media (max-width: 400px) {
    .chess-board {
        width: 100vw;
        height: 100vw;
        max-height: calc(100dvh - 200px);
    }

    .player-bar {
        padding: 0.3rem 0.5rem;
    }

    .player-name {
        font-size: 0.85rem;
    }

    .player-avatar {
        width: 28px;
        height: 28px;
        font-size: 1rem;
    }

    .header-btn {
        padding: 0.4rem 0.6rem;
        font-size: 0.8rem;
    }

    .turn-indicator {
        font-size: 0.85rem;
        padding: 0.3rem 0.8rem;
    }

    .moves-bar {
        min-height: 55px;
        padding-bottom: 2rem;
    }

    .move-row {
        font-size: 0.8rem;
        padding: 0.25rem 0.4rem;
    }
}

/* Landscape mode on mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .chess-board {
        width: calc(100vh - 100px);
        height: calc(100vh - 100px);
        max-width: none;
        max-height: none;
    }

    .player-bar {
        width: calc(100vh - 100px);
        max-width: none;
    }

    .game-header {
        padding: 0.3rem 0.5rem;
    }

    .moves-bar {
        padding: 0.3rem;
        padding-bottom: 1rem;
        min-height: 40px;
    }
}
