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

:root {
    --garden-bg: #e8e4d8;
    --garden-green: #5a7c4f;
    --garden-light: #7a9c6f;
    --garden-dark: #3a5c3f;
    --wall-color: #8b7355;
    --stairs-color: #6b5345;
    --dark-stone: #2a2520;
    --player1-color: #ffffff;
    --player2-color: #1a1a1a;
    --selection-glow: #f59e0b;
    --valid-move: #10b981;
    --border-color: rgba(100, 90, 80, 0.3);
    --cell-size: min(8vmin, 55px);
}

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

body {
    font-family: 'Cinzel', serif;
    background-color: var(--garden-bg);
    background-image:
        linear-gradient(rgba(90, 124, 79, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(90, 124, 79, 0.03) 1px, transparent 1px);
    background-size: 100px 100px;
    min-height: 100vh;
    color: var(--dark-stone);
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

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

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

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

.game-title {
    font-size: 3rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    color: var(--garden-dark);
    text-shadow: 2px 2px 0px rgba(122, 156, 111, 0.3);
}

.game-subtitle {
    font-size: 1rem;
    letter-spacing: 0.1em;
    color: rgba(58, 92, 63, 0.7);
}

.status-panel {
    background: linear-gradient(135deg, rgba(122, 156, 111, 0.25), rgba(90, 124, 79, 0.2));
    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%;
}

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

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

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

.hand-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin: 10px 0;
    padding: 6px 24px;
    background: rgba(255, 255, 255, 0.4);
    border-radius: 20px;
    font-weight: bold;
    color: var(--dark-stone);
    min-height: 40px;
    /* Reserve space to prevent jumping */
    min-width: 200px;
    visibility: hidden;
    /* Hidden by default, toggled to visible */
    border: 1px solid rgba(100, 90, 80, 0.2);
}

.hand-display.visible {
    visibility: visible;
}

.hand-stones {
    display: flex;
    gap: 4px;
}

.hand-stone {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.3);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

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

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

.board-container {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 30px 0;
}

.gardens-board {
    display: flex;
    gap: 12px;
    align-items: stretch;
    /* Sandstone background */
    background: linear-gradient(135deg, #d2b48c, #c2a47c);
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.garden-column {
    display: flex;
    flex-direction: column;
    gap: 8px;
    justify-content: space-between;
}

.garden-field {
    width: calc(var(--cell-size) * 1.4);
    /* Compact width for 2 small columns */
    height: calc(var(--cell-size) * 2.8);
    /* Fit within the 2-row height (plus margins) */
    background: linear-gradient(135deg, var(--garden-green), var(--garden-light));
    border: 3px solid var(--garden-dark);
    border-radius: 16px;
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.2), 0 4px 12px rgba(0, 0, 0, 0.15);
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(5, 1fr);
    gap: 2px;
    padding: 6px;
    align-items: center;
    justify-items: center;
}

/* Garden Stone (Flat View) */
.garden-stone {
    width: 80%;
    height: 80%;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.2);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    transition: opacity 0.2s, transform 0.2s;
}

.garden-stone.white {
    background: radial-gradient(circle at 30% 30%, #ffffff, #e0e0e0);
}

.garden-stone.black {
    background: radial-gradient(circle at 30% 30%, #4a4a4a, #2a2a2a);
}

.garden-stone.selected-ghost {
    opacity: 0.2;
    transform: scale(0.9);
}

.stairs {
    height: 40px;
    width: 100%;
    /* Match garden field width */
    align-self: center;
    /* Default color, overridden below */
    background: repeating-linear-gradient(to bottom,
            var(--stairs-color),
            var(--stairs-color) 4px,
            transparent 4px,
            transparent 8px);
    border-left: 4px solid var(--stairs-color);
    border-right: 4px solid var(--stairs-color);
    opacity: 0.8;
    margin: 0;
    /* Connect visually */
}

.left-gardens .stairs {
    --stairs-color: #2a2520;
    /* Black/Dark */
}

.right-gardens .stairs {
    --stairs-color: #e8e8e8;
    /* White/Light */
    border-color: #ccc;
    /* Slightly darker border for visibility on light bg */
}

/* Ensure relative positioning for pseudo-element placement */
.garden-field {
    position: relative;
}

.playing-areas {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.playing-field {
    display: grid;
    grid-template-columns: repeat(5, var(--cell-size));
    grid-template-rows: repeat(3, var(--cell-size));
    gap: 3px;
    background: var(--border-color);
    padding: 8px;
    border-radius: 16px;
}

.wall-separator {
    height: 20px;
    background: linear-gradient(135deg, var(--wall-color), #7a6355);
    border-top: 2px solid #6b5345;
    border-bottom: 2px solid #6b5345;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.cell {
    background: linear-gradient(135deg, rgba(232, 228, 216, 0.9), rgba(220, 216, 204, 0.85));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    transition: all 0.2s;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.cell:hover {
    transform: scale(1.05);
}

.cell.valid-move {
    background: rgba(16, 185, 129, 0.5);
    box-shadow: inset 0 0 12px rgba(16, 185, 129, 0.7);
}

.cell.full-tower {
    background: rgba(200, 100, 100, 0.3);
    cursor: not-allowed;
}

/* Stone stack container */
.stone-stack {
    position: relative;
    width: 80%;
    height: 80%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Individual stone disc in stack */
.stone-disc {
    position: absolute;
    width: 100%;
    height: 35%;
    border-radius: 50%;
    border: 2px solid rgba(0, 0, 0, 0.3);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s;
}

.stone-disc.white {
    background: radial-gradient(ellipse at 30% 30%, #ffffff, #e8e8e8);
    border-color: rgba(100, 100, 100, 0.5);
}

.stone-disc.black {
    background: radial-gradient(ellipse at 30% 30%, #3a3a3a, #1a1a1a);
    border-color: rgba(50, 50, 50, 0.7);
}

/* Layer positioning - bottom to top */
.stone-disc[data-layer="0"] {
    bottom: 0%;
    transform: scale(1.0);
    z-index: 1;
}

.stone-disc[data-layer="1"] {
    bottom: 15%;
    transform: scale(0.95);
    z-index: 2;
}

.stone-disc[data-layer="2"] {
    bottom: 30%;
    transform: scale(0.90);
    z-index: 3;
}

.stone-disc[data-layer="3"] {
    bottom: 45%;
    transform: scale(0.85);
    z-index: 4;
}

.stone-disc[data-layer="4"] {
    bottom: 60%;
    transform: scale(0.80);
    z-index: 5;
}

/* Stack count indicator */
.stack-count {
    position: absolute;
    top: -8px;
    right: -8px;
    background: var(--garden-dark);
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: bold;
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

/* Selected stack highlighting */
.stone-stack.selected {
    transform: scale(1.1);
}

.stone-stack.selected .stone-disc {
    box-shadow: 0 0 10px 3px var(--selection-glow);
}

/* Selection count indicator */
.selection-indicator {
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--selection-glow);
    color: white;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: bold;
    z-index: 15;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    white-space: nowrap;
}

.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;
    padding: 12px 24px;
    border: 2px solid var(--border-color);
    cursor: pointer;
    transition: all 0.3s;
}

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

.cancel-btn:hover:not(:disabled) {
    transform: translateY(-2px);
}

.reset-btn {
    background: linear-gradient(135deg, rgba(90, 124, 79, 0.9), rgba(58, 92, 63, 0.85));
    color: white;
}

.reset-btn:hover:not(:disabled) {
    transform: translateY(-2px);
}

.hidden {
    display: none !important;
}

.message-box {
    background: linear-gradient(135deg, rgba(58, 92, 63, 0.95), rgba(42, 72, 47, 0.9));
    border: 1px solid rgba(122, 156, 111, 0.3);
    color: #f3f4f6;
    padding: 16px 24px;
    margin: 16px 0;
    max-width: 600px;
    width: 100%;
    text-align: center;
    font-size: 0.9rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.game-footer {
    margin-top: 20px;
    text-align: center;
    font-size: 0.85rem;
    color: rgba(58, 92, 63, 0.6);
}

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

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