/* Import Cinzel font */
@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;500;700&display=swap');

:root {
    --marble-bg: #d4cfc4;
    --dark-stone: #2a2520;
    --player1-color: #ffffff;
    --player2-color: #1a1a1a;
    --selection-glow: #f59e0b;
    --valid-move: #10b981;
    --direction-field: #ef4444;
    --border-color: rgba(100, 90, 80, 0.3);
    --cell-size: min(8vmin, 50px);
    --gold: #C5A059;
    --ivory: #f5f0e8;
    --menu-width: 320px;
    --transition-speed: 0.4s;
}

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

body {
    font-family: 'Cinzel', serif;
    background-color: var(--marble-bg);
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px),
        url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="400" height="400"><filter id="noise"><feTurbulence type="fractalNoise" baseFrequency="0.9" numOctaves="4" /></filter><rect width="400" height="400" filter="url(%23noise)" opacity="0.05"/></svg>');
    background-size: 100px 100px, 100px 100px, 400px 400px;
    min-height: 100vh;
    color: var(--dark-stone);
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background:
        radial-gradient(ellipse at 20% 30%, rgba(255, 255, 255, 0.1) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 70%, rgba(200, 190, 180, 0.15) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

.back-link {
    position: absolute;
    top: 20px;
    left: 20px;
    color: var(--dark-stone);
    text-decoration: none;
    font-size: 0.95rem;
    letter-spacing: 0.05em;
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
    z-index: 10;
}

.back-link:hover {
    background: rgba(255, 255, 255, 0.35);
}

.game-header {
    text-align: center;
    margin: 40px 0 20px;
    z-index: 1;
}

.game-title {
    font-size: 3rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    color: var(--dark-stone);
    text-shadow:
        2px 2px 0px rgba(255, 255, 255, 0.3),
        -1px -1px 0px rgba(0, 0, 0, 0.1);
    margin-bottom: 8px;
}

.game-subtitle {
    font-size: 1rem;
    letter-spacing: 0.1em;
    color: rgba(42, 37, 32, 0.7);
}

.status-panel {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.25) 0%, rgba(240, 235, 225, 0.2) 100%);
    border: 1px solid var(--border-color);
    padding: 16px 24px;
    margin: 20px 0;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    max-width: 600px;
    width: 100%;
    z-index: 1;
}

.turn-display {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    font-weight: 500;
    margin-bottom: 8px;
}

.current-player-indicator {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    margin-right: 12px;
    border: 2px solid var(--dark-stone);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.stone-counts {
    display: flex;
    gap: 24px;
    justify-content: center;
    font-size: 0.9rem;
}

.board-wrapper {
    display: flex;
    justify-content: center;
    margin: 20px 0;
    z-index: 1;
}

.board-container {
    display: grid;
    grid-template-columns: repeat(11, var(--cell-size));
    grid-template-rows: repeat(11, var(--cell-size));
    gap: 1px;
    background: var(--border-color);
    border: 2px solid var(--border-color);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

.cell {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.15) 0%, rgba(240, 235, 225, 0.1) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    transition: background-color 0.2s;
}

.cell.inactive {
    background: transparent;
    cursor: default;
    pointer-events: none;
}

.cell.direction-field {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.3) 0%, rgba(220, 38, 38, 0.2) 100%);
}

.cell.cell-dark {
    background: rgba(0, 0, 0, 0.12) !important;
}

.cell.direction-field::after {
    content: '▼';
    font-size: 1.2rem;
    color: var(--direction-field);
    position: absolute;
    pointer-events: none;
}

.cell.direction-up::after {
    content: '▲';
}

.cell.direction-down::after {
    content: '▼';
}

.cell.direction-left::after {
    content: '◀';
}

.cell.direction-right::after {
    content: '▶';
}

.cell.valid-move {
    background: rgba(16, 185, 129, 0.4);
    box-shadow: inset 0 0 10px rgba(16, 185, 129, 0.6);
}

.stone {
    width: 70%;
    height: 70%;
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    transition: transform 0.3s ease-in-out, box-shadow 0.2s;
    cursor: pointer;
    z-index: 5;
}

.stone.white {
    background: var(--player1-color);
    border: 2px solid rgba(107, 114, 128, 0.5);
}

.stone.black {
    background: var(--player2-color);
    border: 2px solid rgba(75, 85, 99, 0.5);
}

.stone.selected {
    transform: scale(1.15);
    box-shadow: 0 0 15px 5px var(--selection-glow);
    z-index: 10;
}

.action-buttons {
    display: flex;
    gap: 16px;
    margin: 20px 0;
    position: relative;
    z-index: 1001;
}

.action-btn {
    font-family: 'Cinzel', serif;
    font-size: 0.95rem;
    font-weight: 500;
    letter-spacing: 0.05em;
    padding: 12px 24px;
    border: 2px solid var(--border-color);
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.cancel-btn {
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.9) 0%, rgba(245, 158, 11, 0.85) 100%);
    color: var(--dark-stone);
}

.cancel-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.95) 0%, rgba(217, 119, 6, 0.9) 100%);
    transform: translateY(-2px);
}

.reset-btn {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.9) 0%, rgba(220, 38, 38, 0.85) 100%);
    color: white;
}

.reset-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, rgba(220, 38, 38, 0.95) 0%, rgba(185, 28, 28, 0.9) 100%);
    transform: translateY(-2px);
}

.action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.hidden {
    display: none !important;
}

.rules-btn {
    background: linear-gradient(135deg, rgba(180, 60, 60, 0.8), rgba(150, 40, 40, 0.75));
    color: #fdf0f0;
    border-color: rgba(239, 68, 68, 0.45);
}

.rules-btn:hover {
    transform: translateY(-2px);
    background: linear-gradient(135deg, rgba(200, 80, 80, 0.9), rgba(170, 55, 55, 0.85));
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.35);
}

.opponent-btn {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.9), rgba(37, 99, 235, 0.85));
    color: white;
}

.opponent-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

/* Rules Modal */
.rules-modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.rules-overlay {
    position: absolute;
    inset: 0;
    background: rgba(42, 37, 32, 0.6);
    backdrop-filter: blur(3px);
}

.rules-content {
    position: relative;
    z-index: 1;
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.97), rgba(240, 235, 225, 0.95));
    border: 2px solid rgba(239, 68, 68, 0.3);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
    padding: 36px 40px;
    max-width: 560px;
    width: 90%;
    max-height: 82vh;
    overflow-y: auto;
    text-align: left;
}

.rules-content h2 {
    font-family: 'Cinzel', serif;
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    color: var(--dark-stone);
    text-align: center;
    margin-bottom: 24px;
    border-bottom: 1px solid rgba(239, 68, 68, 0.3);
    padding-bottom: 16px;
}

.rules-body p {
    font-family: 'Cinzel', serif;
    font-size: 0.82rem;
    line-height: 1.75;
    color: var(--dark-stone);
    margin-bottom: 14px;
}

.rules-body p strong {
    display: block;
    font-size: 0.88rem;
    letter-spacing: 0.05em;
    margin-bottom: 2px;
    color: rgba(180, 40, 40, 0.95);
}

.rules-close-btn {
    display: block;
    margin: 24px auto 0;
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.9), rgba(220, 38, 38, 0.85));
    color: white;
    border-color: rgba(185, 28, 28, 0.4);
}

.rules-close-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

.message-box {
    background: linear-gradient(135deg, rgba(55, 65, 81, 0.95) 0%, rgba(31, 41, 55, 0.9) 100%);
    border: 1px solid rgba(156, 163, 175, 0.3);
    color: #f3f4f6;
    padding: 16px 24px;
    margin: 16px 0;
    max-width: 600px;
    width: 100%;
    text-align: center;
    font-size: 0.9rem;
    line-height: 1.6;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    z-index: 1;
}

.game-footer {
    margin-top: 20px;
    text-align: center;
    font-size: 0.85rem;
    color: rgba(42, 37, 32, 0.6);
    z-index: 1;
}

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

    :root {
        --cell-size: min(7vmin, 40px);
    }
}

/* View Toggle Menu Logic - DEPRECATED for side menu */
.view-menu { display: none !important; }

/* Side Menu & Top Bar Implementation */
.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;
    pointer-events: none;
}

.top-bar-btn {
    pointer-events: auto;
    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);
}

.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 {
    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;
    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;
}

.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-divider {
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--gold), transparent);
    opacity: 0.3;
}

.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;
}

.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;
    color: var(--ivory);
}

.stone-counts-display {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    color: var(--ivory);
}

.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); }

/* Update visibility */
body.view-3d .action-buttons,
body.view-3d .game-header,
body.view-3d .status-panel {
    display: none;
}

/* Gravity Selection Arrows */
.gravity-arrow-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: rgba(255, 255, 255, 0.3);
    cursor: pointer;
    z-index: 1000;
    animation: pulse-arrow 1.5s infinite;
    pointer-events: auto;
}

.gravity-arrow-overlay::after {
    content: '';
    display: block;
    width: 0;
    height: 0;
    border-style: solid;
}

.gravity-arrow-overlay.arrow-up::after {
    border-width: 0 10px 15px 10px;
    border-color: transparent transparent #ff0000 transparent;
}

.gravity-arrow-overlay.arrow-down::after {
    border-width: 15px 10px 0 10px;
    border-color: #ff0000 transparent transparent transparent;
}

.gravity-arrow-overlay.arrow-left::after {
    border-width: 10px 15px 10px 0;
    border-color: transparent #ff0000 transparent transparent;
}

.gravity-arrow-overlay.arrow-right::after {
    border-width: 10px 0 10px 15px;
    border-color: transparent transparent transparent #ff0000;
}

@keyframes pulse-arrow {
    0% {
        transform: scale(1);
        opacity: 0.8;
    }

    50% {
        transform: scale(1.2);
        opacity: 1;
    }

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

/* 3D View Specific Styles */
#canvas3d {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 5;
}

body.view-3d #canvas3d {
    display: block;
}

body.view-3d .board-container {
    display: none;
}

body.view-3d .game-header,
body.view-3d .status-panel,
body.view-3d .action-buttons,
body.view-3d .message-box,
body.view-3d .game-footer {
    position: relative;
    z-index: 10;
    pointer-events: auto;
}

body.view-3d .status-panel,
body.view-3d .message-box {
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

body.view-3d {
    overflow: hidden;
}

/* View Toggle Menu */
.view-menu {
    position: absolute;
    bottom: 100%;
    left: 0;
    background: white;
    border: 1px solid var(--border-color);
    display: none;
    flex-direction: column;
    width: 150px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1002;
}

.view-menu.show-menu {
    display: flex;
}

.view-menu button {
    padding: 10px 15px;
    border: none;
    background: none;
    text-align: left;
    cursor: pointer;
    font-family: inherit;
}

.view-menu button:hover {
    background: #f0f0f0;
}

/* Game Over Modal Styles */
.game-over-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 20000;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(10px);
    transition: opacity 0.3s ease;
}

.message-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
}

.game-over-content {
    background: linear-gradient(145deg, #1a1510, #0a0a0a);
    border: 2px solid var(--gold);
    padding: 40px;
    text-align: center;
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
    display: flex;
    flex-direction: column;
    gap: 25px;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.9);
    position: relative;
    z-index: 10;
    animation: modalPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modalPop {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

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

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

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

.winner-icon.white { background: #fff; }
.winner-icon.black { background: #111; }

#modal-text {
    font-size: 1.15rem;
    color: var(--ivory);
    line-height: 1.5;
    margin: 0;
    font-family: 'Cinzel', serif;
    letter-spacing: 0.05em;
}

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

.primary-btn {
    background: var(--gold) !important;
    color: #111 !important;
    font-weight: bold !important;
    font-family: 'Cinzel', serif !important;
}

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

.secondary-btn {
    background: transparent !important;
    border: 2px solid var(--gold) !important;
    color: var(--gold) !important;
    font-family: 'Cinzel', serif !important;
}

.secondary-btn:hover {
    background: rgba(197, 160, 89, 0.1) !important;
}