@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;500;700&family=Crimson+Text:wght@400;600&display=swap');

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

:root {
    --gold: #C5A059;
    --ivory: #f5f0e8;
    --dark-stone: #1a1510;
    --white-stone: #ffffff;
    --black-stone: #1a1a1a;
    --menu-width: 320px;
    --transition-speed: 0.4s;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Crimson Text', serif;
    background: #050505;
    color: var(--ivory);
}

#game-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

.canvas-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: auto;
    touch-action: none;
}

.canvas-container.hidden {
    display: none;
}

#canvas3d {
    width: 100%;
    height: 100%;
}

/* 2D Board Fallback */
#board-container {
    display: grid;
    grid-template-columns: repeat(11, 1fr);
    width: 90vmin;
    height: 90vmin;
    margin: 50vh auto 0;
    transform: translateY(-50%);
    background: #1e1e1e;
    border: 2px solid var(--gold);
}

.board-square {
    border: 1px solid rgba(197, 160, 89, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
}

.board-square.removed {
    background: #000;
}

/* Back Link */
.back-link {
    position: absolute;
    top: 20px;
    left: 20px;
    color: var(--gold);
    text-decoration: none;
    font-size: 0.95rem;
    padding: 8px 16px;
    border: 1px solid var(--gold);
    background: rgba(197, 160, 89, 0.15);
    z-index: 10;
    font-family: 'Cinzel', serif;
    transition: all 0.3s;
}

.back-link:hover {
    background: rgba(197, 160, 89, 0.3);
    transform: translateY(-2px);
}

/* Top Bar */
.top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: linear-gradient(180deg, rgba(0,0,0,0.8) 0%, rgba(0,0,0,0) 100%);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    z-index: 5000; /* Above 3D content and most overlays */
    pointer-events: none; /* Allow clicks through bar to background */
}

.top-bar-btn {
    pointer-events: auto; /* Buttons are clickable */
    font-family: 'Cinzel', serif;
    font-size: 0.9rem;
    padding: 10px 18px;
    background: rgba(197, 160, 89, 0.15);
    border: 1px solid var(--gold);
    color: var(--ivory);
    cursor: pointer;
    transition: all 0.3s;
    border-radius: 6px;
    letter-spacing: 0.03em;
    backdrop-filter: blur(10px);
    text-decoration: none;
}

.top-bar-btn:hover {
    background: rgba(197, 160, 89, 0.3);
    transform: translateY(-2px);
}

/* Context Menu (Horizontal Bar) */
.context-menu {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(150%);
    width: auto;
    min-width: 600px;
    background: rgba(245, 240, 232, 0.9); /* Ivory Cloud */
    backdrop-filter: blur(8px);
    border: 1px solid rgba(197, 162, 110, 0.3); /* Gold border hint */
    border-radius: 10px;
    padding: 10px 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 1000;
    display: flex;
    justify-content: space-around;
    align-items: center;
    gap: 10px;
}

.context-menu.active {
    transform: translateX(-50%) translateY(0);
}

.context-menu h2 {
    display: none; /* Hide title in horizontal mode */
}

.menu-options {
    display: flex;
    flex-direction: row;
    gap: 10px;
    width: 100%;
}

.menu-item {
    padding: 5px 15px;
    background: rgba(255, 255, 255, 0.4);
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 700;
    color: #444;
    text-transform: uppercase;
    letter-spacing: 1px;
    white-space: nowrap;
}

.menu-item .value {
    color: var(--gold);
    margin-left: 5px;
}

.menu-btn {
    padding: 8px 15px;
    background: transparent;
    color: #444;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    width: 100%;
    margin-top: 10px;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 1px;
    transition: 0.2s;
}

.menu-btn:hover {
    background: var(--gold);
    color: white;
    border-color: var(--gold);
    transform: none;
}

/* Turn Indicator HUD */
.turn-indicator-hud {
    position: fixed;
    bottom: 85px; /* Offset from bottom bar */
    left: 50%;
    transform: translateX(-50%) translateY(200%);
    background: rgba(245, 240, 232, 0.7);
    padding: 8px 20px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-size: 0.8rem;
    color: #555;
    transition: transform 0.4s ease-out;
    z-index: 1000;
}

.turn-indicator-hud.active {
    transform: translateX(-50%) translateY(0);
}

.indicator-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,0.2);
}

.indicator-dot.white { background: #fff; }
.indicator-dot.black { background: #1a1a1a; }

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    visibility: hidden;
    display: none;
    z-index: 9999;
    backdrop-filter: blur(4px);
    cursor: pointer;
}

.overlay.active {
    visibility: visible;
    display: block;
    pointer-events: auto;
}

/* Animations for clouds background effect */
@keyframes cloudFloat {
    0% { transform: translate(0, 0); }
    50% { transform: translate(10px, 10px); }
    100% { transform: translate(0, 0); }
}

.context-menu::before {
    content: '';
    position: absolute;
    top: -20px;
    left: 10%;
    width: 80px;
    height: 40px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 50px;
    filter: blur(10px);
    z-index: -1;
    animation: cloudFloat 4s infinite ease-in-out;
}

.menu-toggle-btn {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4px;
    width: 44px;
    height: 44px;
}

.menu-toggle-btn span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--gold);
    transition: all 0.3s;
}

.menu-toggle-btn.active span:nth-child(1) { transform: rotate(45deg) translate(4px, 4px); }
.menu-toggle-btn.active span:nth-child(2) { opacity: 0; }
.menu-toggle-btn.active span:nth-child(3) { transform: rotate(-45deg) translate(4px, -4px); }

/* Side Menu */
.side-menu {
    position: fixed;
    top: 0;
    right: 0;
    width: var(--menu-width);
    height: 100%;
    background: linear-gradient(180deg, rgba(15, 12, 10, 0.98) 0%, rgba(5, 5, 5, 0.98) 100%);
    border-left: 2px solid var(--gold);
    z-index: 10000; /* Highest z-index for side menu */
    pointer-events: auto;
    transform: translateX(100%);
    transition: transform var(--transition-speed) cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(20px);
    overflow-y: auto;
}

.side-menu.open {
    transform: translateX(0);
}

.menu-content {
    padding: 80px 24px 40px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.game-title {
    font-family: 'Cinzel', serif;
    font-size: 2.5rem;
    text-align: center;
    color: var(--gold);
    letter-spacing: 0.15em;
    text-shadow: 0 2px 10px rgba(197, 160, 89, 0.3);
}

.current-player-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 12px;
    background: rgba(197, 160, 89, 0.1);
    border: 1px solid rgba(197, 160, 89, 0.3);
    border-radius: 8px;
}

.player-indicator {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid var(--gold);
}

.player-indicator.white { background: #fff; box-shadow: 0 0 10px rgba(255,255,255,0.5); }
.player-indicator.black { background: #333; box-shadow: 0 0 10px rgba(0,0,0,0.5); }

.stone-counts-display {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
}

.count-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.1rem;
}

.count-stone {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.count-stone.white { background: #fff; box-shadow: 0 0 10px rgba(255,255,255,0.3); }
.count-stone.black { background: #333; box-shadow: 0 0 10px rgba(0,0,0,0.5); }

.menu-divider {
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--gold), transparent);
    opacity: 0.3;
}

.menu-btn {
    font-family: 'Cinzel', serif;
    font-size: 1rem;
    padding: 14px;
    background: rgba(197, 160, 89, 0.15);
    border: 1px solid var(--gold);
    color: var(--ivory);
    cursor: pointer;
    transition: all 0.3s;
    border-radius: 6px;
    letter-spacing: 0.05em;
    width: 100%;
}

.menu-btn:hover:not(:disabled) {
    background: rgba(197, 160, 89, 0.3);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(197, 160, 89, 0.3);
}

.menu-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.cancel-btn {
    border-color: #ff6b6b;
    color: #ff6b6b;
    background: rgba(255, 107, 107, 0.1);
}

/* Game Message */
.game-message {
    position: fixed;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    padding: 16px 32px;
    background: rgba(15, 12, 10, 0.95);
    border: 2px solid var(--gold);
    border-radius: 8px;
    font-family: 'Cinzel', serif;
    z-index: 100;
    backdrop-filter: blur(10px);
    transition: opacity 0.3s;
    color: var(--ivory);
}

.game-message.hidden { opacity: 0; pointer-events: none; }

/* Overlays */
.game-over-overlay, .rules-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.98);
    z-index: 20000;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(8px);
}

.hidden { display: none !important; }

.game-over-content, .rules-panel {
    background: linear-gradient(145deg, #1a1510, #0a0a0a);
    border: 2px solid var(--gold);
    padding: 25px;
    text-align: center;
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
    display: flex;
    flex-direction: column;
    gap: 20px;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.9);
}

.game-over-content h2 {
    font-family: 'Cinzel', serif;
    color: var(--gold);
    font-size: 2.2rem;
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.winner-display {
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.winner-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 3px solid var(--gold);
    box-shadow: 0 0 20px var(--gold);
}

.winner-icon.white { background: var(--ivory); }
.winner-icon.black { background: #111; }

#modal-text {
    font-size: 1.1rem;
    color: var(--ivory);
    line-height: 1.5;
    margin: 0;
}

.modal-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 10px;
}

.primary-btn {
    background: var(--gold);
    color: #111;
    font-weight: bold;
}

.primary-btn:hover {
    background: var(--ivory);
    box-shadow: 0 0 15px var(--ivory);
}

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

.secondary-btn:hover {
    background: rgba(184, 150, 87, 0.1);
}

.rules-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    text-align: left;
    margin: 15px 0;
    padding-right: 5px;
    padding-bottom: 30px; /* Extra space at bottom to prevent overlap */
    box-sizing: border-box;
    width: 100%;
}

.rules-scroll p { margin-bottom: 15px; line-height: 1.6; }
.rules-scroll strong { color: var(--gold); font-family: 'Cinzel', serif; }

.rules-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

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

.view-3d #canvas-3d { animation: fadeIn 0.5s ease-out; }

/* Floating Diminish Button Over Stone */
.floating-diminish-btn {
    position: fixed;
    z-index: 9999; /* Ensure it is absolutely on top of everything */
    padding: 12px 24px;
    background: #ff4d4d;
    color: #fff;
    border: 3px solid #ffd700;
    border-radius: 30px;
    font-family: 'Cinzel', serif;
    font-size: 1rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
    cursor: pointer;
    box-shadow: 0 0 35px rgba(255, 77, 77, 0.9), 0 0 15px rgba(255, 215, 0, 0.6);
    transition: all 0.2s;
    transform: translate(-50%, -180%); /* Sit even higher above the stone */
    pointer-events: auto !important;
}

.floating-diminish-btn:hover {
    transform: translate(-50%, -190%) scale(1.1);
    background: #ff1a1a;
    box-shadow: 0 0 50px rgba(255, 26, 26, 1);
}

.floating-diminish-btn.hidden {
    display: none;
    opacity: 0;
    pointer-events: none !important;
}

/* Demo Timer in Menu */
#game-menu-timer {
    text-align: center;
    padding: 10px 15px;
    background: rgba(197, 160, 89, 0.1);
    border: 1px solid rgba(197, 160, 89, 0.3);
    border-radius: 6px;
    margin-bottom: 20px;
    font-family: 'Cinzel', serif;
}

#game-menu-timer-display {
    font-size: 1.1rem;
    color: var(--gold);
    font-weight: 700;
}

#permanent-demo-timer {
    z-index: 11000 !important; /* Above side menu */
}