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

:root {
    --bg-color: #1a1a2e;
    --surface-color: #16213e;
    --primary-color: #e94560;
    --secondary-color: #0f3460;
    --text-color: #eee;
    --text-muted: #888;
    --green-piece: #16a34a;    /* Green for first player */
    --red-piece: #dc2626;      /* Red for second player */
    --bobail-color: #fbbf24;   /* Yellow/amber bobail */
    --win-color: #4ade80;
    --draw-color: #facc15;
    --loss-color: #f87171;
    --board-light: #d4a76a;    /* Sandy/earthy board */
    --board-dark: #8b5a2b;     /* Darker earth tone */
    --highlight: rgba(251, 191, 36, 0.4);
    --selected: rgba(233, 69, 96, 0.5);
}

.hidden {
    display: none !important;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    margin-bottom: 30px;
}

header h1 {
    font-size: 3rem;
    color: var(--primary-color);
    text-transform: uppercase;
    letter-spacing: 4px;
    margin-bottom: 5px;
}

.subtitle {
    color: var(--text-muted);
    font-size: 1.1rem;
}

main {
    display: flex;
    gap: 30px;
    justify-content: center;
    flex-wrap: wrap;
}

.game-area {
    display: flex;
    gap: 30px;
    flex-wrap: wrap;
    justify-content: center;
}

/* Board Styles - African carved wood aesthetic */
.board-container {
    background: linear-gradient(145deg, #8b5a2b 0%, #6b4423 50%, #5c3a1e 100%);
    padding: 25px;
    border-radius: 12px;
    box-shadow:
        0 10px 40px rgba(0, 0, 0, 0.4),
        inset 0 2px 4px rgba(255, 255, 255, 0.1),
        inset 0 -2px 4px rgba(0, 0, 0, 0.2);
    border: 3px solid #4a2c17;
}

/* Navigation below board */
.board-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 15px;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.board-nav span {
    font-size: 0.85rem;
    color: #d4a76a;
    min-width: 50px;
    text-align: center;
}

.board {
    display: grid;
    grid-template-columns: repeat(5, 90px);
    grid-template-rows: repeat(5, 90px);
    gap: 4px;
    background: linear-gradient(135deg, #3d2512 0%, #2a1a0e 100%);
    padding: 4px;
    border-radius: 6px;
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.5);
}

.square {
    width: 90px;
    height: 90px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    transition: all 0.2s ease;
    border-radius: 3px;
    box-shadow:
        inset 0 1px 2px rgba(255, 255, 255, 0.15),
        inset 0 -1px 2px rgba(0, 0, 0, 0.15);
}

.square.light {
    background: linear-gradient(145deg, #deb887 0%, #d4a76a 50%, #c9976a 100%);
}

.square.dark {
    background: linear-gradient(145deg, #a67c52 0%, #8b6b47 50%, #7a5a3a 100%);
}

.square:hover {
    filter: brightness(1.1);
}

.square.selected {
    box-shadow: inset 0 0 0 4px var(--primary-color);
}

.square.valid-move {
    cursor: pointer;
}

.square.valid-move::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 50%;
}

.square.valid-move.has-piece::after {
    width: 100%;
    height: 100%;
    background: transparent;
    border-radius: 4px;
    box-shadow: inset 0 0 0 4px rgba(0, 0, 0, 0.4);
}

/* Hint overlays */
.square.hint-win::before {
    content: '';
    position: absolute;
    inset: 4px;
    background: var(--win-color);
    opacity: 0.5;
    border-radius: 4px;
    z-index: 1;
}

.square.hint-draw::before {
    content: '';
    position: absolute;
    inset: 4px;
    background: var(--draw-color);
    opacity: 0.5;
    border-radius: 4px;
    z-index: 1;
}

.square.hint-loss::before {
    content: '';
    position: absolute;
    inset: 4px;
    background: var(--loss-color);
    opacity: 0.5;
    border-radius: 4px;
    z-index: 1;
}

/* Pieces - Carved wooden token style */
.piece {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    position: relative;
    z-index: 2;
    transition: transform 0.15s ease;
    box-shadow:
        0 4px 8px rgba(0, 0, 0, 0.4),
        inset 0 2px 4px rgba(255, 255, 255, 0.3),
        inset 0 -2px 4px rgba(0, 0, 0, 0.2);
}

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

/* Green token (first player) */
.piece.green {
    background: linear-gradient(145deg, #22c55e 0%, #16a34a 40%, #15803d 100%);
    border: 3px solid #14532d;
}

/* Red token (second player) */
.piece.red {
    background: linear-gradient(145deg, #ef4444 0%, #dc2626 40%, #b91c1c 100%);
    border: 3px solid #7f1d1d;
}

/* Yellow bobail */
.piece.bobail {
    background: linear-gradient(145deg, #fcd34d 0%, #fbbf24 40%, #f59e0b 100%);
    border: 3px solid #b45309;
    box-shadow:
        0 4px 12px rgba(251, 191, 36, 0.4),
        inset 0 2px 4px rgba(255, 255, 255, 0.4),
        inset 0 -2px 4px rgba(0, 0, 0, 0.15);
}

/* Pulsing bobail when it's time to move it */
.piece.bobail.needs-move {
    animation: bobail-pulse 1.2s ease-in-out infinite;
}

@keyframes bobail-pulse {
    0%, 100% {
        box-shadow:
            0 4px 12px rgba(251, 191, 36, 0.4),
            inset 0 2px 4px rgba(255, 255, 255, 0.4),
            inset 0 -2px 4px rgba(0, 0, 0, 0.15);
        transform: scale(1);
    }
    50% {
        box-shadow:
            0 0 25px rgba(251, 191, 36, 0.8),
            0 0 50px rgba(251, 191, 36, 0.4),
            inset 0 2px 4px rgba(255, 255, 255, 0.4),
            inset 0 -2px 4px rgba(0, 0, 0, 0.15);
        transform: scale(1.08);
    }
}

/* Game Info Panel */
.game-info {
    background: var(--surface-color);
    padding: 25px;
    border-radius: 12px;
    min-width: 250px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.turn-indicator {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #333;
}

.turn-indicator.thinking {
    animation: thinking-pulse 1s ease-in-out infinite;
}

@keyframes thinking-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.turn-dot {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.turn-dot.green-dot {
    background: linear-gradient(145deg, #22c55e, #16a34a);
    border: 2px solid #14532d;
}

.turn-dot.red-dot {
    background: linear-gradient(145deg, #ef4444, #dc2626);
    border: 2px solid #7f1d1d;
}

.evaluation {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    font-size: 1.1rem;
}

.eval-label {
    color: var(--text-muted);
}

.eval-value {
    font-weight: 700;
    padding: 4px 12px;
    border-radius: 4px;
    background: var(--secondary-color);
}

.eval-value.win {
    background: var(--win-color);
    color: #000;
}

.eval-value.draw {
    background: var(--draw-color);
    color: #000;
}

.eval-value.loss {
    background: var(--loss-color);
    color: #000;
}

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
}

.btn {
    padding: 10px 18px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    transition: all 0.2s ease;
    background: var(--secondary-color);
    color: var(--text-color);
}

.btn:hover {
    background: #1a4a80;
    transform: translateY(-1px);
}

.btn-hint {
    background: var(--primary-color);
}

.btn-hint:hover {
    background: #d13a52;
}

.btn-hint.active {
    background: var(--win-color);
    color: #000;
}

.hint-icon {
    margin-right: 4px;
}

.selects-row {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
}

.mode-select {
    flex: 1;
}

.mode-select label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.mode-select select {
    width: 100%;
    padding: 10px;
    border-radius: 6px;
    border: none;
    background: var(--secondary-color);
    color: var(--text-color);
    font-size: 0.95rem;
    cursor: pointer;
}

.stats-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    background: var(--secondary-color);
    border-radius: 6px;
    margin-bottom: 20px;
}

#stats-display {
    font-weight: 600;
    font-size: 0.95rem;
}

.stat-win {
    color: var(--win-color);
}

.stat-loss {
    color: var(--loss-color);
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.8rem;
}

.btn-icon {
    padding: 10px 12px;
    font-size: 1.1rem;
}

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

.hint-legend {
    display: none;
    padding-top: 15px;
    border-top: 1px solid #333;
}

.hint-legend.visible {
    display: block;
}

.hint-legend h4 {
    margin-bottom: 12px;
    color: var(--text-muted);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.legend-color {
    width: 20px;
    height: 20px;
    border-radius: 4px;
}

.legend-color.win {
    background: var(--win-color);
}

.legend-color.draw {
    background: var(--draw-color);
}

.legend-color.loss {
    background: var(--loss-color);
}

.best-moves {
    margin-top: 12px;
    padding: 10px;
    background: rgba(74, 222, 128, 0.15);
    border-radius: 6px;
    font-size: 0.9rem;
    border: 1px solid rgba(74, 222, 128, 0.3);
}

.best-moves strong {
    color: var(--win-color);
}

/* Hint loading indicator */
.hint-loading {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    font-style: italic;
}

.loading-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--text-muted);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Setup Panel */
.setup-panel {
    padding-top: 15px;
    border-top: 1px solid #333;
}

.setup-panel h4 {
    margin-bottom: 12px;
    color: var(--text-muted);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.setup-pieces {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.setup-piece-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border: 2px solid transparent;
    border-radius: 6px;
    background: var(--secondary-color);
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.85rem;
}

.setup-piece-btn:hover {
    background: var(--surface-color);
    border-color: var(--text-muted);
}

.setup-piece-btn.active {
    border-color: var(--primary-color);
    background: var(--surface-color);
}

.piece-icon {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: inline-block;
}

.piece-icon.green {
    background: var(--green-piece);
}

.piece-icon.red {
    background: var(--red-piece);
}

.piece-icon.bobail {
    background: var(--bobail-color);
}

.piece-icon.clear {
    background: #555;
    color: #fff;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

.setup-controls {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.setup-controls label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9rem;
    cursor: pointer;
}

.setup-controls input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

/* History Panel */
.history-panel {
    background: var(--surface-color);
    padding: 20px;
    border-radius: 12px;
    min-width: 220px;
    max-height: 700px;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.history-panel h3 {
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid #333;
    color: var(--text-muted);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.history-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid #333;
}

.btn-nav {
    padding: 4px 10px;
    min-width: 36px;
    font-size: 0.9rem;
    font-weight: bold;
}

.btn-nav:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

#nav-position {
    font-size: 0.85rem;
    color: var(--text-muted);
    min-width: 50px;
    text-align: center;
}

.move-list {
    max-height: 200px;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
}

/* Game History Section */
.game-history-section {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #333;
}

.game-history-section h3 {
    margin-bottom: 10px;
    color: var(--text-muted);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.game-history-list {
    max-height: 200px;
    overflow-y: auto;
}

.game-history-entry {
    background: var(--secondary-color);
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 8px;
}

.game-info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.game-date {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.game-result {
    font-weight: 600;
    font-size: 0.85rem;
    padding: 2px 8px;
    border-radius: 4px;
}

.game-result.win {
    background: var(--win-color);
    color: #000;
}

.game-result.loss {
    background: var(--loss-color);
    color: #000;
}

.game-result.draw {
    background: var(--draw-color);
    color: #000;
}

.game-details {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.game-actions {
    display: flex;
    gap: 6px;
}

.game-actions .btn {
    padding: 4px 10px;
    font-size: 0.75rem;
}

.no-games {
    text-align: center;
    color: var(--text-muted);
    font-style: italic;
    padding: 20px;
    font-size: 0.85rem;
}

.move-entry {
    padding: 6px 8px;
    border-radius: 4px;
    margin-bottom: 4px;
}

.move-entry:nth-child(odd) {
    background: rgba(255, 255, 255, 0.05);
}

.move-number {
    color: var(--text-muted);
    margin-right: 8px;
}

/* Rules Section */
.rules {
    margin-top: 50px;
    padding: 30px;
    background: var(--surface-color);
    border-radius: 12px;
}

.rules h2 {
    text-align: center;
    margin-bottom: 25px;
    color: var(--primary-color);
}

.rules-content {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 25px;
}

.rule h4 {
    color: var(--bobail-color);
    margin-bottom: 10px;
}

.rule p {
    color: var(--text-muted);
    margin-bottom: 8px;
}

.rule ol {
    color: var(--text-muted);
    margin-left: 20px;
}

/* Footer */
footer {
    text-align: center;
    margin-top: 50px;
    padding: 20px;
    color: var(--text-muted);
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

/* Responsive - Wide screens: horizontal layout */
@media (min-width: 1200px) {
    main {
        flex-wrap: nowrap;
        align-items: flex-start;
    }

    .game-area {
        flex-wrap: nowrap;
    }

    .history-panel {
        min-width: 280px;
        max-height: 600px;
    }
}

/* Even wider screens: more compact */
@media (min-width: 1400px) {
    .container {
        max-width: 1400px;
    }

    .game-info {
        min-width: 280px;
    }

    .history-panel {
        min-width: 300px;
    }
}

/* Responsive - Smaller screens */
@media (max-width: 900px) {
    .board {
        grid-template-columns: repeat(5, 70px);
        grid-template-rows: repeat(5, 70px);
    }

    .square {
        width: 70px;
        height: 70px;
    }

    .piece {
        width: 54px;
        height: 54px;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 10px;
    }

    .board {
        grid-template-columns: repeat(5, 64px);
        grid-template-rows: repeat(5, 64px);
    }

    .square {
        width: 64px;
        height: 64px;
    }

    .piece {
        width: 50px;
        height: 50px;
    }

    header h1 {
        font-size: 2rem;
    }

    .game-area {
        flex-direction: column;
        align-items: center;
    }

    .game-info {
        width: 100%;
        max-width: 380px;
    }

    .controls {
        justify-content: center;
    }

    .btn {
        padding: 8px 14px;
        font-size: 0.85rem;
    }

    .selects-row {
        flex-direction: column;
        gap: 10px;
    }

    .history-panel {
        width: 100%;
        max-width: 380px;
    }

    .rules-content {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 400px) {
    .board {
        grid-template-columns: repeat(5, 56px);
        grid-template-rows: repeat(5, 56px);
        gap: 2px;
        padding: 2px;
    }

    .square {
        width: 56px;
        height: 56px;
    }

    .piece {
        width: 44px;
        height: 44px;
    }

    .board-container {
        padding: 12px;
    }

    header h1 {
        font-size: 1.6rem;
        letter-spacing: 2px;
    }

    .subtitle {
        font-size: 0.9rem;
    }

    .controls {
        gap: 6px;
    }

    .btn {
        padding: 8px 10px;
        font-size: 0.8rem;
    }

    .btn-icon {
        padding: 8px 10px;
    }
}

/* Touch-friendly improvements */
@media (hover: none) {
    .square:hover {
        filter: none;
    }

    .piece:hover {
        transform: none;
    }

    .square.selected {
        box-shadow: inset 0 0 0 5px var(--primary-color);
    }

    .btn:active {
        transform: scale(0.95);
    }
}

/* Animations */
@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.piece.last-moved {
    animation: pulse 0.3s ease;
}

/* Game over overlay */
.game-over-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.game-over-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.game-over-content {
    background: var(--surface-color);
    padding: 40px 60px;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.game-over-content h2 {
    font-size: 2rem;
    margin-bottom: 15px;
}

.game-over-content p {
    color: var(--text-muted);
    margin-bottom: 25px;
}

.game-over-content .btn {
    font-size: 1.1rem;
    padding: 12px 30px;
}

.game-over-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
}

/* Toast notification */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--surface-color);
    color: var(--text-color);
    padding: 15px 25px;
    border-radius: 8px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.4);
    z-index: 200;
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    font-weight: 500;
}

.toast.visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* Animated piece */
.piece.animating {
    pointer-events: none;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.5);
}
