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

/* CSS Variables */
:root {
    --marble-bg: #d4cfc4;
    --dark-stone: #2a2520;
    --light-stone: #f5f1e8;
    --border-color: rgba(100, 90, 80, 0.3);
    --player1-color: #ffffff;
    --player2-color: #1a1a1a;
    --selection-glow: #f59e0b;
    --valid-move: #10b981;
    --artemis-glow: #a855f7;
    --shadow-subtle: rgba(0, 0, 0, 0.1);
    --connection-line: rgba(100, 90, 80, 0.4);
}

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

body {
    font-family: 'Cinzel', 'Times New Roman', 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;
    touch-action: manipulation;
}

/* Marble overlay */
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 */
.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: 1000;
}

.back-link:hover {
    background: rgba(255, 255, 255, 0.35);
    border-color: rgba(100, 90, 80, 0.5);
}

/* Header */
.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);
    font-weight: 400;
}

/* Status Panel */
.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 var(--shadow-subtle);
    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;
    letter-spacing: 0.03em;
}

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

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

#canvas3d {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 0;
    display: none;
}

body.view-3d #canvas3d {
    display: block;
}
body.view-3d #game-board {
    display: none !important;
}
body:not(.view-3d) #game-board {
    display: block;
}
body.view-3d .board-wrapper {
    flex-grow: 1;
    width: 100%;
}
body.view-3d {
    background: transparent;
    justify-content: space-between;
}
body.view-3d::before {
    display: none;
}

/* SVG Game Board */
#game-board {
    display: none;
    max-width: 90vw;
    max-height: 80vh;
    width: auto;
    height: auto;
    aspect-ratio: 100 / 120;
    pointer-events: auto;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.15) 0%, rgba(240, 235, 225, 0.1) 100%);
    border: 2px solid var(--border-color);
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
    z-index: 1;
}

/* SVG Elements */
.connection-line {
    stroke: var(--connection-line);
    stroke-width: 1.5;
}

.node-spot {
    fill: rgba(161, 161, 170, 1.0);
    stroke: rgba(63, 63, 70, 0.4);
    stroke-width: 1.5;
    transition: fill 0.2s, stroke 0.2s;
    cursor: pointer;
}

.node-spot.artemis {
    fill: rgba(168, 85, 247, 0.2);
    stroke: var(--artemis-glow);
    stroke-width: 2;
}

.node-spot.valid-move {
    fill: rgba(16, 185, 129, 0.3);
    stroke: var(--valid-move);
    stroke-width: 2;
    opacity: 1;
    filter: drop-shadow(0 0 4px var(--valid-move));
}

.stone {
    stroke: rgba(0, 0, 0, 0.3);
    stroke-width: 1.5;
    transition: transform 0.2s, filter 0.2s, stroke 0.2s;
    cursor: pointer;
}

.stone.white {
    fill: var(--player1-color);
}

.stone.black {
    fill: var(--player2-color);
}

.stone.selected {
    filter: drop-shadow(0 0 10px var(--selection-glow));
    stroke: var(--selection-glow);
    stroke-width: 2;
    /* Removed scale transform for flatter look */
}

.stone.in-leap-chain {
    filter: drop-shadow(0 0 6px var(--artemis-glow));
    stroke: var(--artemis-glow);
    stroke-width: 2.5;
}

.leap-of-faith-spot {
    fill: rgba(239, 68, 68, 0.7);
    stroke: #dc2626;
    stroke-width: 2.5;
    cursor: pointer;
    transition: all 0.2s;
    animation: pulse-red 1.5s ease-in-out infinite;
}

.leap-of-faith-spot:hover {
    fill: rgba(239, 68, 68, 0.9);
    stroke: #b91c1c;
    stroke-width: 3;
    /* Removed scale transform for flatter look */
}

@keyframes pulse-red {

    0%,
    100% {
        opacity: 0.7;
    }

    50% {
        opacity: 1;
    }
}

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

.view-dropdown .view-menu.show-menu,
.opp-dropdown .opp-menu.show-menu,
.players-dropdown .players-menu.show-menu {
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.view-menu button, .opp-menu button, .players-menu button {
    white-space: nowrap;
    width: 100%;
}
.view-menu button:hover, .opp-menu button:hover, .players-menu button:hover {
    background: rgba(255, 255, 255, 0.2);
}

.view-dropdown, .opp-dropdown, .players-dropdown {
    position: relative;
    display: inline-block;
}
.view-menu, .opp-menu, .players-menu {
    display: none;
    position: absolute;
    bottom: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(to bottom, #d4cfc4, #b5b0a3);
    border: 1px solid #a39e93;
    border-radius: 4px;
    padding: 5px;
    box-shadow: 0 10px 20px rgba(0,0,0,0.6);
    z-index: 100;
}
.players-menu button.active {
    background: rgba(255, 255, 255, 0.3);
    font-weight: bold;
}

/* Duplicate HUD block removed - now moved to appropriate interactive section */

.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 var(--shadow-subtle);
}

.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);
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.4);
}

.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);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

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

.action-btn:active:not(:disabled) {
    transform: translateY(0);
}

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

.hidden {
    display: none !important;
}

.rules-btn {
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.75), rgba(126, 58, 200, 0.7));
    color: #f5f1f8;
    border-color: rgba(168, 85, 247, 0.4);
}

.rules-btn:hover {
    transform: translateY(-2px);
    background: linear-gradient(135deg, rgba(192, 110, 255, 0.85), rgba(148, 78, 218, 0.8));
    box-shadow: 0 4px 12px rgba(168, 85, 247, 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(168, 85, 247, 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(168, 85, 247, 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(126, 58, 200, 0.9);
}

.rules-close-btn {
    display: block;
    margin: 24px auto 0;
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.9), rgba(126, 58, 200, 0.85));
    color: white;
    border-color: rgba(168, 85, 247, 0.4);
}

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

/* Message Box */
.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;
    letter-spacing: 0.03em;
    line-height: 1.6;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    z-index: 1;
}

/* Game Over Modal */
.message-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
    backdrop-filter: blur(5px);
}

.message-overlay.visible {
    opacity: 1;
    transform: scale(1);
    pointer-events: all;
}

.message-content {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.95) 0%, rgba(240, 235, 225, 0.9) 100%);
    border: 2px solid var(--border-color);
    padding: 40px;
    max-width: 440px;
    width: 100%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

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

.modal-btn {
    padding: 12px 24px;
    background: #4c1d95;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-family: 'Cinzel', serif;
    font-weight: bold;
    font-size: 0.9rem;
    letter-spacing: 1px;
    transition: all 0.2s ease;
}

.modal-btn:hover {
    background: #6d28d9;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

.message-title {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    margin-bottom: 16px;
    color: var(--dark-stone);
}

.message-text {
    font-size: 1rem;
    letter-spacing: 0.03em;
    line-height: 1.6;
    margin-bottom: 24px;
    color: rgba(42, 37, 32, 0.8);
}

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

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

    .game-subtitle {
        font-size: 0.9rem;
    }

    #game-board {
        width: 90vmin;
        height: calc(90vmin * 1.4);
    }
}

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

    .back-link {
        font-size: 0.85rem;
        padding: 6px 12px;
    }

    .action-buttons {
        flex-direction: column;
        width: 100%;
        max-width: 300px;
    }

    .action-btn {
        width: 100%;
    }
}

/* =========================================
   SKYSCRAPER HUD & MENU SYSTEM PORT
   ========================================= */

#menu-trigger {
    position: fixed;
    top: 20px;
    right: 30px;
    width: 35px;
    height: 30px;
    cursor: pointer;
    z-index: 100;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}
.sky-line {
    width: 100%;
    height: 3px;
    background-color: var(--dark-stone);
    transition: all 0.3s ease;
    box-shadow: 0 0 5px rgba(0,0,0,0.2);
}
#menu-trigger.active .sky-line:nth-child(1) { transform: translateY(13px) rotate(45deg); }
#menu-trigger.active .sky-line:nth-child(2) { opacity: 0; }
#menu-trigger.active .sky-line:nth-child(3) { transform: translateY(-14px) rotate(-45deg); }

#main-header {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translate(-50%, -150%);
    z-index: 100;
    display: flex;
    align-items: center;
    background: linear-gradient(to bottom, #eae6df, #f5f1e8, #d4cfc4, #b5b0a3);
    padding: 10px 40px;
    border-top: 1px solid #ffffff;
    border-bottom: 2px solid #a39e93;
    transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: none;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    border-radius: 2px;
}
#main-header::before, #main-header::after {
    content: '';
    position: absolute;
    top: -2px;
    bottom: -2px;
    width: 15px;
    background: #ccc7bd;
    border: 1px solid #a39e93;
    box-shadow: inset 2px 0 5px rgba(0,0,0,0.1), inset -2px 0 5px rgba(255,255,255,0.5);
}
#main-header::before { left: -15px; border-radius: 4px 0 0 4px; }
#main-header::after { right: -15px; border-radius: 0 4px 4px 0; }

#main-header.visible {
    transform: translate(-50%, 0);
}
#main-header h1 {
    font-family: 'Ancient Tulip', 'Cinzel', serif;
    color: #1a1a1a; /* Black font */
    margin: 0;
    font-size: 1.6rem;
    text-transform: uppercase;
    letter-spacing: 10px;
    text-shadow: 0 1px 1px rgba(255, 255, 255, 0.8);
    pointer-events: auto;
}

#hud {
    position: fixed;
    bottom: 40px;
    display: flex;
    gap: 15px;
    align-items: center;
    background: linear-gradient(to bottom, #eae6df, #f5f1e8, #d4cfc4, #b5b0a3);
    padding: 12px 30px;
    border-top: 1px solid #ffffff;
    border-bottom: 2px solid #a39e93;
    left: 50%;
    transform: translate(-50%, 200%);
    transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 30;
    pointer-events: none;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
}
#hud::before, #hud::after {
    content: '';
    position: absolute;
    top: -3px;
    bottom: -3px;
    width: 25px;
    background: linear-gradient(to bottom, #d4cfc4, #b5b0a3);
    border-radius: 4px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
}
#hud::before {
    left: -20px;
    border-left: 2px solid #f5f1e8;
    border-right: 2px solid #a39e93;
}
#hud::after {
    right: -20px;
    border-right: 2px solid #f5f1e8;
    border-left: 2px solid #a39e93;
}
#hud * { pointer-events: auto; }
#hud.visible { transform: translate(-50%, 0); }

.controls { display: flex; gap: 10px; z-index: 2; position: relative; }
.controls button, #hud button {
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 16px;
    background: transparent;
    color: #4a4a4a;
    border: 1px solid #a39e93;
    border-radius: 2px;
    font-family: 'Cinzel', serif;
    font-size: 0.75rem;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 2px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-sizing: border-box;
    box-shadow: inset 0 1px 3px rgba(255,255,255,0.7), 0 2px 4px rgba(0,0,0,0.1);
}
.controls button:hover, #hud button:hover {
    background: rgba(0, 0, 0, 0.05);
    color: #000;
}

#cancel-button {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 50;
    padding: 10px 20px;
    background: rgba(10, 10, 10, 0.8);
    color: var(--selection-glow);
    border: 1px solid var(--border-color);
    font-family: 'Cinzel', serif;
    font-size: 0.9rem;
    text-transform: uppercase;
    cursor: pointer;
    border-radius: 4px;
}

#view-container {
    width: 100vw;
    height: 100vh;
    position: absolute;
    top: 0;
    left: 0;
    overflow: hidden;
    z-index: 0;
    display: flex;
    justify-content: center;
    align-items: center;
}