:root {
    /* Premium Color Palette */
    --bg-primary: #1a1612;
    --bg-secondary: #252019;
    --bg-card: #2d2620;
    --bg-elevated: #3a3028;

    --gold: #d4a853;
    --gold-light: #e8c876;
    --gold-dark: #b8923f;

    --text-primary: #f5f0e8;
    --text-secondary: #a8a090;
    --text-muted: #6b6560;

    --white-piece: #ffffff;
    --black-piece: #1a1a1a;

    --light-square: #e8dcc8;
    --dark-square: #b58863;

    --highlight: rgba(212, 168, 83, 0.6);
    --danger: #c44b4b;
    --success: #5cb85c;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
}

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

#loading-screen.fade-out {
    opacity: 0;
    pointer-events: none;
}

.loading-content {
    text-align: center;
}

.loading-icon {
    font-size: 4rem;
    color: var(--gold);
    animation: float 2s ease-in-out infinite;
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

.loading-title {
    font-family: 'Playfair Display', serif;
    font-size: 1.8rem;
    margin: 20px 0 10px;
    color: var(--gold);
    font-weight: 600;
    letter-spacing: 2px;
}

.loading-bar-container {
    width: 180px;
    height: 3px;
    background: var(--bg-card);
    border-radius: 2px;
    overflow: hidden;
    margin: 15px auto;
}

.loading-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--gold-dark), var(--gold-light));
    animation: loading 1.5s ease-in-out forwards;
}

@keyframes loading {
    to {
        width: 100%;
    }
}

.loading-text {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Game Container */
#game-container {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    max-width: 500px;
    margin: 0 auto;
    padding: 0;
}

/* Screens */
.screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 20px;
    animation: fadeIn 0.3s ease;
}

.screen.hidden {
    display: none;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Start Screen */
.brand-header {
    text-align: center;
    margin-bottom: 40px;
}

.crown-icon {
    font-size: 3rem;
    color: var(--gold);
    display: block;
    margin-bottom: 10px;
}

.brand-header h1 {
    font-family: 'Playfair Display', serif;
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 1px;
}

.tagline {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-top: 5px;
}

/* Menu Cards */
.menu-cards {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
    max-width: 300px;
}

.menu-card {
    background: var(--bg-card);
    border: 1px solid var(--bg-elevated);
    border-radius: 16px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    color: inherit;
}

.menu-card:hover,
.menu-card:active {
    background: var(--bg-elevated);
    border-color: var(--gold-dark);
    transform: translateY(-2px);
}

.card-icon {
    font-size: 2rem;
}

.card-title {
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--text-primary);
}

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

/* Mode Selector */
.mode-selector {
    display: flex;
    gap: 8px;
    width: 100%;
    max-width: 340px;
    margin-bottom: 15px;
    padding: 5px;
    background: var(--bg-secondary);
    border-radius: 14px;
}

.mode-option {
    flex: 1;
    background: var(--bg-card);
    border: 1px solid var(--bg-elevated);
    border-radius: 12px;
    padding: 12px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.mode-option.active {
    background: var(--bg-elevated);
    border-color: var(--gold);
    box-shadow: 0 0 15px rgba(212, 168, 83, 0.15);
}

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

.mode-time {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.mode-option.active .mode-name {
    color: var(--gold);
}

.link-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
    padding: 10px;
    margin-top: 20px;
    font-family: inherit;
}

.link-btn:hover {
    color: var(--text-primary);
}

.link-btn.danger {
    color: var(--danger);
}

/* Waiting Screen */
.waiting-content {
    text-align: center;
    width: 100%;
    max-width: 320px;
}

.waiting-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 30px;
    color: var(--text-secondary);
}

.pulse-dot {
    width: 10px;
    height: 10px;
    background: var(--gold);
    border-radius: 50%;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.3);
        opacity: 0.7;
    }
}

.room-code-card {
    background: var(--bg-card);
    border: 1px solid var(--bg-elevated);
    border-radius: 16px;
    padding: 25px;
    margin-bottom: 20px;
}

.code-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 10px;
}

.room-code {
    font-family: 'Playfair Display', monospace;
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: 6px;
    color: var(--gold);
    margin-bottom: 15px;
}

.copy-btn {
    background: var(--bg-elevated);
    border: none;
    color: var(--text-secondary);
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
    font-family: inherit;
}

.copy-btn:hover {
    background: var(--gold-dark);
    color: var(--bg-primary);
}

.your-color-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
    color: var(--text-secondary);
}

.color-badge {
    font-weight: 600;
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 0.95rem;
}

.color-badge.white {
    background: #fff;
    color: #000;
}

.color-badge.black {
    background: #222;
    color: #fff;
}

.timeout-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.timeout-value {
    font-weight: 600;
    color: var(--text-secondary);
    font-family: monospace;
}

.timeout-value.low {
    color: var(--danger);
}

/* Join Screen */
.join-content {
    text-align: center;
    width: 100%;
    max-width: 300px;
}

.join-content h2 {
    font-family: 'Playfair Display', serif;
    font-size: 1.8rem;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.instruction {
    color: var(--text-secondary);
    margin-bottom: 25px;
    font-size: 0.9rem;
}

.room-input {
    width: 100%;
    font-family: monospace;
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: 4px;
    text-align: center;
    text-transform: uppercase;
    background: var(--bg-card);
    border: 2px solid var(--bg-elevated);
    border-radius: 12px;
    padding: 16px;
    color: var(--gold);
    margin-bottom: 20px;
    transition: border-color 0.2s;
}

.room-input:focus {
    outline: none;
    border-color: var(--gold);
}

.room-input::placeholder {
    color: var(--text-muted);
}

/* Primary/Secondary Buttons */
.primary-btn {
    width: 100%;
    background: linear-gradient(135deg, var(--gold), var(--gold-dark));
    border: none;
    color: var(--bg-primary);
    padding: 14px 28px;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(212, 168, 83, 0.3);
}

.secondary-btn {
    width: 100%;
    background: var(--bg-card);
    border: 1px solid var(--bg-elevated);
    color: var(--text-secondary);
    padding: 14px 28px;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    margin-top: 10px;
}

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

/* ===== GAME SCREEN - MOBILE OPTIMIZED ===== */
#game-screen {
    padding-top: 70px;
    /* Space for Telegram header */
    justify-content: flex-start;
    height: 100%;
}

/* Player Bars */
.player-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 15px;
    background: var(--bg-secondary);
    width: 100%;
}

.player-bar.opponent {
    border-bottom: 1px solid var(--bg-elevated);
}

.player-bar.you {
    border-top: 1px solid var(--bg-elevated);
}

.player-avatar {
    width: 36px;
    height: 36px;
    background: var(--bg-card);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
}

.player-avatar.your-avatar {
    background: linear-gradient(135deg, var(--gold-dark), var(--gold));
}

.player-details {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    justify-content: center;
}

.status-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.player-timer {
    font-family: monospace;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
    background: rgba(0, 0, 0, 0.2);
    padding: 2px 6px;
    border-radius: 4px;
    margin-right: 4px;
    border: 1px solid var(--bg-elevated);
}

.player-timer.low {
    color: var(--danger);
    border-color: var(--danger);
    animation: flash 1s infinite;
}

@keyframes flash {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.material-advantage {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
    max-width: 100px;
    margin-left: 8px;
}

.captured-piece {
    font-size: 1rem;
    line-height: 1;
    color: var(--text-secondary);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.captured-piece.advantage {
    font-weight: 700;
    margin-left: 4px;
    font-size: 0.75rem;
    color: var(--success);
}

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

.player-status {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.turn-badge {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gold);
    background: rgba(212, 168, 83, 0.15);
    padding: 3px 8px;
    border-radius: 4px;
    display: inline-block;
    width: fit-content;
    transition: all 0.3s;
}

.turn-badge.my-turn {
    background: var(--gold);
    color: var(--bg-primary);
    box-shadow: 0 0 10px rgba(212, 168, 83, 0.4);
    animation: turnPulse 2s infinite;
}

@keyframes turnPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(212, 168, 83, 0.4);
    }

    70% {
        box-shadow: 0 0 0 6px rgba(212, 168, 83, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(212, 168, 83, 0);
    }
}

.turn-badge.waiting {
    color: var(--text-muted);
    background: var(--bg-card);
    animation: none;
}

/* Confetti Effect (Simple CSS implementation) */
.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    background-color: var(--gold);
    animation: fall linear forwards;
    z-index: 1001;
}

@keyframes fall {
    to {
        transform: translateY(100vh) rotate(720deg);
    }
}

.bar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.conn-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
}

.conn-dot.disconnected {
    background: var(--danger);
}

.icon-btn {
    width: 36px;
    height: 36px;
    background: var(--bg-card);
    border: none;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1rem;
}

.icon-btn.danger:hover {
    background: var(--danger);
}

/* Board Wrapper - Fills remaining space */
#board-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    background: var(--bg-primary);
}

/* Chessboard - MAXIMIZED */
#chessboard {
    width: 95vw;
    max-width: 500px;
    aspect-ratio: 1;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    border-radius: 6px;
    overflow: hidden;
    box-shadow:
        0 0 0 4px var(--gold-dark),
        0 0 0 6px var(--bg-secondary),
        0 8px 30px rgba(0, 0, 0, 0.5);
}

.square {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10vw;
    cursor: pointer;
    position: relative;
    user-select: none;
}

@media (min-width: 500px) {
    .square {
        font-size: 3.2rem;
    }
}

.square.light {
    background-color: var(--light-square);
}

.square.dark {
    background-color: var(--dark-square);
}

.square.selected {
    background-color: var(--highlight) !important;
}

.square.move-hint::after {
    content: '';
    position: absolute;
    width: 28%;
    height: 28%;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 50%;
}

.square.capture-hint::after {
    content: '';
    position: absolute;
    width: 85%;
    height: 85%;
    border: 4px solid rgba(0, 0, 0, 0.15);
    border-radius: 50%;
}

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

.square.check {
    background: radial-gradient(circle, #c44b4b 40%, transparent 75%);
}

.piece {
    line-height: 1;
    z-index: 2;
}

.piece.piece-white {
    color: var(--white-piece);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.piece.piece-black {
    color: var(--black-piece);
    filter: drop-shadow(0 1px 2px rgba(255, 255, 255, 0.2));
}

/* Game Over Screen */
#game-over-screen {
    background: var(--bg-primary);
}

.result-content {
    text-align: center;
    width: 100%;
    max-width: 320px;
}

.result-icon {
    font-size: 4rem;
    margin-bottom: 15px;
}

.result-content h1 {
    font-family: 'Playfair Display', serif;
    font-size: 2rem;
    color: var(--gold);
    margin-bottom: 5px;
}

.result-msg {
    color: var(--text-secondary);
    font-size: 1rem;
    margin-bottom: 25px;
}

.game-stats {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-bottom: 30px;
}

.stat {
    background: var(--bg-card);
    padding: 15px 25px;
    border-radius: 12px;
    text-align: center;
}

.stat .stat-value {
    display: block;
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-primary);
}

.stat.sparks .stat-value {
    color: var(--gold);
}

.stat .stat-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-top: 5px;
}

.result-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 25px;
    text-align: center;
}

.promotion-content h3 {
    color: var(--text-primary);
    margin-bottom: 20px;
    font-family: 'Playfair Display', serif;
}

.promotion-pieces {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.promo-piece {
    width: 50px;
    height: 50px;
    background: var(--light-square);
    border: none;
    border-radius: 8px;
    font-size: 2rem;
    cursor: pointer;
    transition: all 0.2s;
}

.promo-piece:hover {
    transform: scale(1.1);
    background: var(--gold-light);
}

/* Responsive - very small phones */
@media (max-height: 600px) {
    .player-bar {
        padding: 6px 12px;
    }

    .player-avatar {
        width: 30px;
        height: 30px;
        font-size: 1.1rem;
    }

    #board-wrapper {
        padding: 4px;
    }
}