:root {
    --gold: #e2b04a;
    --gold-light: #f5d78c;
    --gold-dark: #b8860b;
    --board-light: #d4a574;
    --board-dark: #6b3a2a;
    --bg: #1a0a00;
    --surface: #23140a;
    --text: #fdf3e0;
    --text-muted: #c4a88c;
    --accent: #ff6b35;
    --accent-glow: #ff9f6b;
    --white-piece: #fefefe;
    --black-piece: #1c1008;
    --danger: #e74c3c;
    --success: #2ecc71;
    --radius-sm: 10px;
    --radius: 18px;
    --radius-lg: 24px;
    --shadow-gold: 0 0 30px rgba(226, 176, 74, 0.35);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.6);
    --font-display: 'Georgia', 'Times New Roman', serif;
    --font-body: 'Segoe UI', 'Inter', system-ui, -apple-system, sans-serif;
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    background: radial-gradient(ellipse at center, #2b1605 0%, #0d0501 70%);
    color: var(--text);
    font-family: var(--font-body);
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    position: relative;
}

/* Ambient background particles */
.bg-ambiance {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

.bg-ambiance .orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.08;
    animation: floatOrb 12s infinite ease-in-out;
}

.bg-ambiance .orb:nth-child(1) {
    width: 350px;
    height: 350px;
    background: var(--gold);
    top: -80px;
    left: -80px;
    animation-delay: 0s;
}

.bg-ambiance .orb:nth-child(2) {
    width: 280px;
    height: 280px;
    background: var(--accent);
    bottom: -60px;
    right: -60px;
    animation-delay: -5s;
    animation-duration: 15s;
}

.bg-ambiance .orb:nth-child(3) {
    width: 200px;
    height: 200px;
    background: #c084fc;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation-delay: -9s;
    animation-duration: 18s;
    opacity: 0.04;
}

@keyframes floatOrb {

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

    25% {
        transform: translate(40px, -30px) scale(1.1);
    }

    50% {
        transform: translate(-20px, 20px) scale(0.9);
    }

    75% {
        transform: translate(-30px, -15px) scale(1.05);
    }
}

/* Canvas container */
.canvas-wrapper {
    position: relative;
    z-index: 2;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg), var(--shadow-gold);
    border: 3px solid #9b4817;
    transition: var(--transition);
}

.canvas-wrapper:hover {
    border-color: rgba(226, 176, 74, 0.55);
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.7), 0 0 50px rgba(226, 176, 74, 0.45);
}

canvas {
    display: block;
    border-radius: calc(var(--radius-lg) - 3px);
    max-width: 100vw;
    max-height: 100vh;
}

/* UI Layer */
#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    pointer-events: none;
    z-index: 20;
}

.panel {
    background: linear-gradient(145deg, rgba(35, 20, 10, 0.92) 0%, rgba(20, 8, 2, 0.96) 100%);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 2px solid rgba(226, 176, 74, 0.25);
    padding: 2.5rem 2rem;
    border-radius: var(--radius-lg);
    text-align: center;
    pointer-events: auto;
    box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255, 255, 255, 0.03);
    max-width: 92%;
    width: 430px;
    transition: var(--transition);
    animation: panelIn 0.5s cubic-bezier(0.22, 0.61, 0.36, 1);
}

@keyframes panelIn {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }

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

.panel h1 {
    font-family: var(--font-display);
    font-size: 2.4rem;
    margin-bottom: 0.3rem;
    background: linear-gradient(180deg, #f9d976 0%, #e2b04a 40%, #b8860b 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: 1px;
    text-shadow: none;
    filter: drop-shadow(0 2px 4px rgba(184, 134, 11, 0.4));
}

.panel .subtitle {
    font-family: var(--font-display);
    color: var(--text-muted);
    font-size: 0.9rem;
    letter-spacing: 3px;
    text-transform: uppercase;
    margin-bottom: 2rem;
}

.panel h2 {
    font-family: var(--font-display);
    margin-bottom: 1.2rem;
    color: var(--gold-light);
    font-size: 1.6rem;
    letter-spacing: 1px;
}

.btn-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}

button {
    background: linear-gradient(180deg,
            rgba(226, 176, 74, 0.18) 0%,
            rgba(184, 134, 11, 0.28) 100%);
    border: 1.5px solid rgba(20, 14, 2, 0.55);

    padding: 14px 28px;
    color: var(--gold-light);
    font-size: 1.05rem;
    font-weight: 600;
    font-family: var(--font-body);
    letter-spacing: 0.5px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    width: 100%;
    transition: all var(--transition);
    position: relative;
    overflow: hidden;
    margin-bottom: 8px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);

    box-shadow:
        /* Top gold highlight */
        inset 0 2px 0 rgba(20, 14, 1, 0.35),

        /* Bottom dark gold */
        inset 0 -3px 0 rgba(120, 82, 8, 0.75),

        /* 3D outer border */
        0 0 0 2px rgba(226, 176, 74, 0.18),

        /* Bottom depth */
        0 5px 0 rgba(120, 82, 8, 0.9),

        /* Drop shadow */
        0 10px 20px rgba(0, 0, 0, 0.35),

        /* Gold glow */
        0 0 18px rgba(226, 176, 74, 0.25);
}

button:hover {
    transform: translateY(-2px);

    box-shadow:
        inset 0 2px 0 rgba(255, 214, 120, 0.45),
        inset 0 -3px 0 rgba(120, 82, 8, 0.85),
        0 0 0 2px rgba(226, 176, 74, 0.28),
        0 7px 0 rgba(120, 82, 8, 0.9),
        0 14px 24px rgba(0, 0, 0, 0.4),
        0 0 24px rgba(226, 176, 74, 0.35);
}

button:active {
    transform: translateY(5px);

    box-shadow:
        inset 0 2px 3px rgba(120, 82, 8, 0.45),
        inset 0 -1px 0 rgba(226, 176, 74, 0.2),
        0 2px 0 rgba(120, 82, 8, 0.9),
        0 4px 10px rgba(0, 0, 0, 0.3);
}

button::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.08), transparent);
    transition: left 0.5s ease;
}

button:hover {
    background: linear-gradient(180deg, rgba(226, 176, 74, 0.3) 0%, rgba(184, 134, 11, 0.45) 100%);
    border-color: rgba(226, 176, 74, 0.7);
    color: #fff;
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4), 0 0 30px rgba(226, 176, 74, 0.3);
}

button:hover::before {
    left: 100%;
}

button:active {
    transform: translateY(-1px) scale(0.98);
    transition: 0.1s;
}

button.accent-btn {
    background: linear-gradient(180deg, var(--accent) 0%, #d4521e 100%);
    border: 1px solid #ff8b57;
    color: #fff;
    font-weight: 700;
    letter-spacing: 1px;
    position: relative;

    box-shadow:
        /* Top orange highlight */
        inset 0 2px 0 rgba(255, 165, 110, 0.45),

        /* Bottom dark orange */
        inset 0 -3px 0 rgba(145, 52, 18, 0.8),

        /* 3D outer border */
        0 0 0 2px rgba(255, 125, 70, 0.35),

        /* Bottom depth */
        0 5px 0 #8e3514,

        /* Soft shadow */
        0 10px 18px rgba(0, 0, 0, 0.3),

        /* Orange glow */
        0 0 18px rgba(255, 107, 53, 0.45);
}

button.accent-btn:hover {
    transform: translateY(-2px);
    box-shadow:
        inset 0 2px 0 rgba(255, 175, 120, 0.55),
        inset 0 -3px 0 rgba(145, 52, 18, 0.85),
        0 0 0 2px rgba(255, 125, 70, 0.45),
        0 7px 0 #8e3514,
        0 14px 24px rgba(0, 0, 0, 0.35),
        0 0 22px rgba(255, 107, 53, 0.6);
}

button.accent-btn:active {
    transform: translateY(5px);
    box-shadow:
        inset 0 2px 3px rgba(145, 52, 18, 0.45),
        inset 0 -1px 0 rgba(255, 140, 90, 0.25),
        0 2px 0 #8e3514,
        0 4px 10px rgba(0, 0, 0, 0.25);
}

/* HUD */
#game-hud {
    position: absolute;
    top: 5px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(20, 8, 2, 0.85);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    padding: 12px 28px;
    border-radius: 30px;
    font-size: 1.05rem;
    font-weight: 600;
    pointer-events: auto;
    border: 1.5px solid rgba(226, 176, 74, 0.3);
    letter-spacing: 0.5px;
    color: var(--text);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.5);
    transition: var(--transition);
    white-space: nowrap;
}

#turn-indicator {
    transition: color 0.4s ease;
}

#turn-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin-right: 8px;
    vertical-align: middle;
    box-shadow: 0 0 12px currentColor;
    transition: all 0.4s ease;
}

#btn-back {
    position: absolute;
    top: 22px;
    left: 20px;
    width: auto;
    padding: 10px 20px;
    font-size: 0.85rem;
    pointer-events: auto;
    border-radius: 25px;
    letter-spacing: 0.5px;
    background: rgba(231, 76, 60, 0.2);
    border-color: rgba(231, 76, 60, 0.5);
    color: #f5a3a3;
}

#btn-back:hover {
    background: rgba(231, 76, 60, 0.4);
    border-color: rgba(231, 76, 60, 0.8);
    color: #fff;
    box-shadow: 0 6px 20px rgba(231, 76, 60, 0.3);
}

/* How to play */
.how-to-text {
    text-align: left;
    font-size: 0.95rem;
    line-height: 1.7;
    margin-bottom: 1.8rem;
    color: var(--text-muted);
    padding: 0 0.5rem;
}

.how-to-text li {
    margin-bottom: 0.6rem;
    margin-left: 1.5rem;
    position: relative;
}

.how-to-text li::marker {
    color: var(--gold);
    content: '◆ ';
}

/* Game over modal */
.crown-icon {
    font-size: 4rem;
    display: block;
    margin-bottom: 0.5rem;
    animation: crownBounce 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes crownBounce {
    0% {
        transform: scale(0) rotate(-30deg);
        opacity: 0;
    }

    60% {
        transform: scale(1.3) rotate(5deg);
        opacity: 1;
    }

    100% {
        transform: scale(1) rotate(0deg);
    }
}

#winner-text {
    font-family: var(--font-display);
    font-size: 1.7rem;
    color: var(--gold-light);
    letter-spacing: 1px;
}

.hidden {
    display: none !important;
}

/* Preloader */
#preloader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #0d0501;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
    transition: opacity 0.6s ease;
    gap: 20px;
}

.preloader-logo {
    font-family: var(--font-display);
    font-size: 2rem;
    color: var(--gold-light);
    letter-spacing: 2px;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 0.6;
    }

    50% {
        opacity: 1;
    }
}

.spinner-ring {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: 3px solid rgba(226, 176, 74, 0.15);
    border-top-color: var(--gold);
    animation: spin 0.9s linear infinite;
    box-shadow: 0 0 20px rgba(226, 176, 74, 0.3);
}

@keyframes spin {
    100% {
        transform: rotate(360deg);
    }
}

/* Responsive */
@media (max-width: 480px) {
    .panel {
        padding: 1.8rem 1.2rem;
        width: 90%;
        border-radius: var(--radius);
    }

    .panel h1 {
        font-size: 1.8rem;
    }

    .panel h2 {
        font-size: 1.3rem;
    }

    button {
        padding: 12px 20px;
        font-size: 0.95rem;
    }

    #game-hud {
        padding: 10px 18px;
        font-size: 0.9rem;
        top: 14px;
    }

    #btn-back {
        top: 14px;
        left: 10px;
        padding: 8px 14px;
        font-size: 0.78rem;
    }

    .crown-icon {
        font-size: 3rem;
    }

    #winner-text {
        font-size: 1.3rem;
    }
}