/* Design System & Variables */
:root {
    --bg-dark: #0f0e13;
    --bg-card: rgba(26, 24, 38, 0.65);
    --border-color: rgba(255, 255, 255, 0.08);
    --border-focus: rgba(255, 209, 117, 0.4);
    
    /* Branding Colors */
    --primary: #ffd175; /* Smug Copernicus Blonde/Gold */
    --primary-hover: #fcdfa2;
    --primary-dark: #e0ac43;
    --secondary: #9bf6ff; /* Soft Turquoise */
    --accent-pink: #ffadad; /* Soft Pink */
    --accent-purple: #bdb2ff; /* Soft Violet */
    --accent-green: #caffbf; /* Soft Sage */
    --text-main: #f4f3f6;
    --text-muted: #a3a1ad;
    --glass-blur: blur(16px);
    
    /* Font stacks */
    --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-display: 'Fredoka', cursive, sans-serif;
}

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

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: var(--font-sans);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Ambient glow backgrounds */
.ambient-glow {
    position: absolute;
    border-radius: 50%;
    filter: blur(120px);
    z-index: -1;
    pointer-events: none;
    opacity: 0.25;
}

.glow-1 {
    width: 400px;
    height: 400px;
    background: var(--primary);
    top: -100px;
    right: -100px;
}

.glow-2 {
    width: 500px;
    height: 500px;
    background: var(--accent-purple);
    bottom: -150px;
    left: -150px;
}

/* App Container */
.app-container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    gap: 20px;
}

/* Glassmorphism Panel */
.glass-panel {
    background: var(--bg-card);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
}

.logo {
    font-family: var(--font-display);
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 10px;
    letter-spacing: 0.5px;
}

.logo-paw {
    color: var(--primary);
    display: inline-block;
    animation: wiggle 3s infinite ease-in-out;
}

.logo-sub {
    font-size: 0.9rem;
    font-family: var(--font-sans);
    font-weight: 400;
    color: var(--primary);
    background: rgba(255, 209, 117, 0.1);
    padding: 2px 8px;
    border-radius: 12px;
    margin-left: 10px;
    align-self: center;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.header-actions {
    display: flex;
    gap: 12px;
}

/* Buttons */
.btn {
    font-family: var(--font-sans);
    font-size: 0.95rem;
    font-weight: 600;
    padding: 10px 18px;
    border: 1px solid transparent;
    border-radius: 12px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-primary {
    background-color: var(--primary);
    color: #1a1826;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(255, 209, 117, 0.3);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    border-color: var(--border-color);
}

.btn-secondary:hover {
    background-color: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

/* Game Arena Layout */
.game-arena {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Copernicus AI Section */
.copernicus-section {
    display: flex;
    align-items: center;
    padding: 20px;
    gap: 20px;
}

.copernicus-avatar-container {
    position: relative;
    width: 100px;
    height: 100px;
    flex-shrink: 0;
}

.copernicus-img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--border-color);
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    transition: border-color 0.5s ease, box-shadow 0.5s ease;
}

/* Ring pulse when thinking */
.copernicus-avatar-container.thinking .copernicus-img {
    border-color: var(--primary);
    box-shadow: 0 0 20px var(--primary);
    animation: pulse-avatar 1.5s infinite alternate;
}

.status-indicator {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background-color: #52c41a; /* Idle Green */
    border: 3px solid #1a1826;
    transition: background-color 0.3s ease;
}

.copernicus-avatar-container.thinking .status-indicator {
    background-color: var(--primary);
    animation: pulse-indicator 1s infinite alternate;
}

.copernicus-info {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.copernicus-name-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.copernicus-name {
    font-family: var(--font-display);
    font-size: 1.4rem;
    color: var(--text-main);
}

.badge {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-ai {
    background: rgba(255, 209, 117, 0.15);
    color: var(--primary);
    border: 1px solid rgba(255, 209, 117, 0.3);
}

/* Speech Bubble styling */
.speech-bubble-container {
    position: relative;
    width: 100%;
}

.speech-bubble {
    position: relative;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 12px 18px;
    border-radius: 16px;
    font-style: italic;
    color: var(--text-main);
    line-height: 1.5;
    font-size: 1.05rem;
}

.speech-bubble p {
    font-family: var(--font-sans);
}

.bubble-arrow {
    content: '';
    position: absolute;
    left: -10px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
    border-right: 10px solid rgba(255, 255, 255, 0.04);
}

/* Status Bar */
.status-bar {
    padding: 14px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 500;
    font-size: 1.1rem;
}

.status-text {
    display: flex;
    align-items: center;
    gap: 8px;
}

.resume-badge {
    background: rgba(155, 246, 255, 0.15);
    color: var(--secondary);
    border: 1px solid rgba(155, 246, 255, 0.3);
    font-size: 0.8rem;
    padding: 4px 8px;
    border-radius: 8px;
    animation: fade-out 4s forwards;
}

.hidden {
    display: none !important;
}

/* The Mancala Board container */
.board-container {
    padding: 24px;
    display: flex;
    justify-content: center;
    overflow-x: auto;
}

.mancala-board {
    display: grid;
    grid-template-columns: 100px repeat(6, 90px) 100px;
    grid-template-rows: 130px 130px;
    gap: 15px;
    background: rgba(0, 0, 0, 0.2);
    padding: 25px;
    border-radius: 30px;
    border: 1px solid rgba(255, 255, 255, 0.04);
    box-shadow: inset 0 4px 20px rgba(0, 0, 0, 0.4);
    width: fit-content;
}

/* Stores */
.mancala-store {
    grid-row: 1 / span 2;
    border-radius: 50px;
    background: rgba(255, 255, 255, 0.02);
    border: 1.5px solid rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 20px 10px;
    position: relative;
    box-shadow: inset 0 2px 10px rgba(0,0,0,0.3);
    overflow: hidden;
}

.store-ai {
    grid-column: 1;
    border-color: rgba(255, 209, 117, 0.2);
}

.store-player {
    grid-column: 8;
    border-color: rgba(155, 246, 255, 0.2);
}


.store-player .store-value {
    color: var(--secondary);
}

.store-ai .store-value {
    color: var(--primary);
}

.store-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 1px;
    color: var(--text-muted);
    z-index: 10;
    background: rgba(15, 14, 19, 0.75);
    padding: 3px 8px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    pointer-events: none;
}

.store-label .mobile-label {
    display: none;
}

.store-value {
    font-family: var(--font-display);
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-main);
    z-index: 10;
    background: rgba(15, 14, 19, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.15);
    min-width: 46px;
    height: 46px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
    margin-top: 10px;
    pointer-events: none;
}
.cat-silhouette {
    position: absolute;
    width: 80px;
    height: 80px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: rgba(255, 255, 255, 0.07);
    z-index: 1;
    pointer-events: none;
}

.store-player .cat-silhouette {
    color: rgba(155, 246, 255, 0.08);
}

.store-ai .cat-silhouette {
    color: rgba(255, 209, 117, 0.08);
}

/* Pits Area Layout */
.board-pits {
    grid-column: 2 / span 6;
    grid-row: 1 / span 2;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 15px;
}

.pits-row {
    display: flex;
    justify-content: space-between;
    gap: 15px;
    height: 130px;
}

.pit-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    gap: 4px;
}

.pit-label {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-muted);
    user-select: none;
}

/* Pit Style */
.mancala-pit {
    width: 90px;
    height: 90px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    box-shadow: inset 0 2px 8px rgba(0,0,0,0.3);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.pit-ai {
    cursor: not-allowed;
}

/* Active Player Pits Hover and Highlight */
body.player-turn .pit-player:hover:not(.empty-pit) {
    background: rgba(155, 246, 255, 0.05);
    border-color: rgba(155, 246, 255, 0.4);
    box-shadow: 0 0 15px rgba(155, 246, 255, 0.15), inset 0 2px 8px rgba(0,0,0,0.1);
    transform: scale(1.05);
}

.empty-pit {
    cursor: default;
}

/* Count Indicator */
.pit-count {
    position: absolute;
    bottom: -6px;
    background: #1e1d2c;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    padding: 1px 6px;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-main);
    z-index: 10;
    pointer-events: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.pit-player .pit-count {
    border-color: rgba(155, 246, 255, 0.3);
}

.pit-ai .pit-count {
    border-color: rgba(255, 209, 117, 0.3);
}

/* Sowing animations */
.sowing-active {
    animation: pulse-pit 0.3s ease-out;
}

/* Stones Styling */
.stones-container, .stones-grid {
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    bottom: 10px;
    pointer-events: none;
}

.stones-grid {
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    justify-content: center;
    gap: 3px;
    overflow-y: auto;
    padding: 2px;
}

.stone {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3), inset 0 -2px 4px rgba(0,0,0,0.2);
    transition: all 0.4s cubic-bezier(0.25, 1, 0.5, 1);
    z-index: 5;
}

.store-player .stone, .store-ai .stone {
    position: relative;
    margin: 1px;
}

/* Stone SVG paw print details */
.stone svg {
    width: 90%;
    height: 90%;
    color: rgba(0, 0, 0, 0.75);
}

/* Stone Pastel Colors */
.stone-color-0 { background: var(--accent-pink); color: #8a3b3b; }
.stone-color-1 { background: var(--secondary); color: #2d6b70; }
.stone-color-2 { background: var(--primary); color: #806323; }
.stone-color-3 { background: var(--accent-purple); color: #584f8c; }
.stone-color-4 { background: var(--accent-green); color: #436e3c; }

/* Turn indicators and helper states */
body.ai-turn .pit-player {
    cursor: not-allowed !important;
}

/* Footer */
.app-footer {
    text-align: center;
    padding: 15px 0;
    font-size: 0.85rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border-color);
    margin-top: auto;
}

/* Modal Backedrop */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(10, 9, 15, 0.8);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    padding: 30px;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    animation: scale-up 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.modal-close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 2rem;
    cursor: pointer;
    line-height: 1;
}

.modal-close:hover {
    color: var(--text-main);
}

.modal-header h2 {
    font-family: var(--font-display);
    font-size: 1.8rem;
    margin-bottom: 20px;
}

.modal-body {
    overflow-y: auto;
    padding-right: 10px;
    font-size: 1rem;
    line-height: 1.6;
}

.modal-body h3 {
    margin: 15px 0 8px;
    font-family: var(--font-display);
    color: var(--primary);
}

.modal-body ul {
    margin-left: 20px;
    margin-bottom: 15px;
}

.modal-body li {
    margin-bottom: 8px;
}

.modal-footer {
    margin-top: 20px;
    display: flex;
    justify-content: flex-end;
}

/* Animations */
@keyframes wiggle {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-8deg); }
    75% { transform: rotate(8deg); }
}

@keyframes pulse-avatar {
    0% { transform: scale(1); box-shadow: 0 0 10px rgba(255, 209, 117, 0.4); }
    100% { transform: scale(1.03); box-shadow: 0 0 25px rgba(255, 209, 117, 0.8); }
}

@keyframes pulse-indicator {
    0% { opacity: 0.6; }
    100% { opacity: 1; }
}

@keyframes pulse-pit {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); background: rgba(255, 255, 255, 0.1); }
    100% { transform: scale(1); }
}

@keyframes scale-up {
    0% { transform: scale(0.9); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes fade-out {
    0% { opacity: 1; }
    70% { opacity: 1; }
    100% { opacity: 0; display: none; }
}

/* Media Queries for Mobile Responsiveness */
@media (max-width: 900px) {
    .store-label .desktop-label {
        display: none;
    }
    
    .store-label .mobile-label {
        display: inline;
    }

    .mancala-board {
        grid-template-columns: 80px repeat(6, 70px) 80px;
        grid-template-rows: 110px 110px;
        padding: 15px;
        gap: 10px;
    }
    
    .pits-row {
        height: 110px;
        gap: 10px;
    }
    
    .mancala-pit {
        width: 70px;
        height: 70px;
    }
    
    .app-header {
        flex-direction: column;
        gap: 15px;
        align-items: center;
        text-align: center;
    }
    
    .copernicus-section {
        flex-direction: column;
        text-align: center;
        padding: 15px;
    }
    
    .bubble-arrow {
        left: 50%;
        top: -10px;
        transform: translateX(-50%) rotate(90deg);
    }
}

@media (max-width: 700px) {
    /* Fluid board scaling using vw units on smaller screens to prevent overflow and keep horizontal structure */
    .board-container {
        padding: 10px;
    }
    
    .mancala-board {
        grid-template-columns: 10vw repeat(6, 8.5vw) 10vw;
        grid-template-rows: 14vw 14vw;
        padding: 8px 6px;
        gap: 5px;
        border-radius: 16px;
        width: fit-content;
        justify-content: center;
        box-sizing: border-box;
    }
    
    .pits-row {
        height: 14vw;
        gap: 5px;
    }
    
    .mancala-pit {
        width: 8.5vw;
        height: 8.5vw;
    }
    
    .mancala-store {
        border-radius: 20px;
        padding: 8px 3px;
    }
    
    .store-label {
        font-size: 0.45rem;
        padding: 2px 4px;
        border-radius: 4px;
    }
    
    .store-value {
        font-size: 1.1rem;
        min-width: 32px;
        height: 32px;
        margin-top: 5px;
    }
    
    .cat-silhouette {
        width: 10vw;
        height: 10vw;
    }
    
    .pit-label {
        font-size: 0.55rem;
    }
    
    .stone {
        width: 2vw;
        height: 2vw;
        box-shadow: 0 1px 2px rgba(0,0,0,0.3);
    }
    
    .pit-count {
        font-size: 0.6rem;
        padding: 0px 4px;
        bottom: -4px;
    }
    
    .logo {
        font-size: 1.8rem;
    }
}

/* Game Log Styles */
.log-container {
    padding: 15px 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 10px;
}

.log-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding-bottom: 8px;
}

.log-title {
    font-family: var(--font-display);
    font-size: 1.1rem;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.log-content-wrapper {
    position: relative;
    width: 100%;
}

.log-content {
    max-height: 180px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-right: 5px;
    font-size: 0.95rem;
    line-height: 1.45;
}

/* Custom scrollbar for log content */
.log-content::-webkit-scrollbar {
    width: 6px;
}

.log-content::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 3px;
}

.log-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.log-content::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 209, 117, 0.3);
}

.log-placeholder {
    color: var(--text-muted);
    font-style: italic;
    text-align: center;
    padding: 10px 0;
}

.log-entry {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: 8px;
    animation: slide-in 0.3s ease-out;
}

.log-entry-content {
    display: flex;
    align-items: center;
    gap: 8px;
}

.log-entry-text {
    color: var(--text-main);
}

.log-entry-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
    background: rgba(0, 0, 0, 0.2);
    padding: 2px 6px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    flex-shrink: 0;
}

/* Turn colors inside log */
.log-entry.player-log {
    border-left: 3px solid var(--secondary);
}

.log-entry.ai-log {
    border-left: 3px solid var(--primary);
}

.log-entry.system-log {
    border-left: 3px solid var(--accent-purple);
    background: rgba(189, 178, 255, 0.05);
}

.log-entry.double-turn-log {
    border-left: 3px solid var(--accent-pink);
    background: rgba(255, 173, 173, 0.05);
}

.log-entry.capture-log {
    border-left: 3px solid var(--accent-green);
    background: rgba(202, 255, 191, 0.05);
}

@keyframes slide-in {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Mobile responsive styles for the log */
@media (max-width: 700px) {
    .log-container {
        padding: 12px 15px;
        gap: 8px;
    }
    
    .log-content {
        max-height: 110px; /* keep it short enough to fit on the screen alongside the board */
        font-size: 1.1rem; /* font size is large enough on mobile */
    }
    
    .log-entry {
        padding: 8px 10px;
    }
    
    .log-entry-meta {
        font-size: 0.85rem;
    }
}

/* More Games Modal List & Favicon Styles */
.btn-sm {
    padding: 8px 14px;
    font-size: 0.85rem;
    border-radius: 10px;
}

.games-list {
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.games-list li {
    margin-bottom: 0 !important;
}

.games-list a {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    text-decoration: none;
    color: var(--text-main);
    font-size: 1.1rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.games-list a:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--primary);
    color: var(--primary);
    transform: translateX(4px);
    box-shadow: 0 4px 12px rgba(255, 209, 117, 0.15);
}

.game-favicon {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    object-fit: contain;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.05);
    padding: 2px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}


