:root {
    /* Typographic Families */
    --font-heading: 'Lora', 'Cambria', 'Georgia', serif;
    --font-body: 'Aptos', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    /* Light Theme Custom Properties (Default) */
    --bg-base: #f8fafc;
    --bg-surface: #ffffff;
    --bg-surface-hover: #f1f5f9;
    --border-color: #e2e8f0;
    --border-hover: #cbd5e1;
    
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    
    --accent: #1e3a8a;         /* Scholarly Navy */
    --accent-hover: #1e40af;
    --accent-soft: #eff6ff;
    
    /* Game Chip Tokens */
    --color-empty: #e2e8f0;
    --color-p1: #dc2626;       /* Red */
    --color-p2: #1e3a8a;       /* Blue */
    --color-human: #dc2626;
    --color-ai: #1e3a8a;
    
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.05), 0 2px 4px -1px rgba(15, 23, 42, 0.03);
    
    --transition: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark Theme applied via prefers-color-scheme media query */
@media (prefers-color-scheme: dark) {
    :root:not(.theme-light) {
        --bg-base: #0b0f19;
        --bg-surface: #111827;
        --bg-surface-hover: #1f2937;
        --border-color: #1f2937;
        --border-hover: #374151;
        
        --text-primary: #f1f5f9;
        --text-secondary: #cbd5e1;
        --text-muted: #94a3b8;
        
        --accent: #60a5fa;     /* Professional Light Blue */
        --accent-hover: #93c5fd;
        --accent-soft: #1e3a8a;
        
        --color-empty: #1f2937;
        --color-p1: #ef4444;   /* S ligeramente más brillante en fondo oscuro */
        --color-p2: #60a5fa;
        --color-human: #ef4444;
        --color-ai: #60a5fa;
        
        --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
        --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
    }
}

/* Explicit Dark Theme overrides */
:root.theme-dark {
    --bg-base: #0b0f19;
    --bg-surface: #111827;
    --bg-surface-hover: #1f2937;
    --border-color: #1f2937;
    --border-hover: #374151;
    
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    
    --accent: #60a5fa;
    --accent-hover: #93c5fd;
    --accent-soft: #1e3a8a;
    
    --color-empty: #1f2937;
    --color-p1: #ef4444;
    --color-p2: #60a5fa;
    --color-human: #ef4444;
    --color-ai: #60a5fa;
    
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
}

/* Explicit Light Theme overrides */
:root.theme-light {
    --bg-base: #f8fafc;
    --bg-surface: #ffffff;
    --bg-surface-hover: #f1f5f9;
    --border-color: #e2e8f0;
    --border-hover: #cbd5e1;
    
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    
    --accent: #1e3a8a;
    --accent-hover: #1e40af;
    --accent-soft: #eff6ff;
    
    --color-empty: #e2e8f0;
    --color-p1: #dc2626;
    --color-p2: #1e3a8a;
    --color-human: #dc2626;
    --color-ai: #1e3a8a;
    
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.05), 0 2px 4px -1px rgba(15, 23, 42, 0.03);
}

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

body {
    font-family: var(--font-body);
    background-color: var(--bg-base);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    transition: background-color var(--transition), color var(--transition);
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 1100px;
    width: 100%;
    margin: 0 auto;
    padding: 0 2rem;
}

/* Skip Link */
.skip-link {
    position: absolute;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent);
    color: #ffffff;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    z-index: 100;
    transition: top var(--transition);
    font-weight: 500;
    text-decoration: none;
    font-size: 0.875rem;
}

.skip-link:focus {
    top: 15px;
    outline: 2px solid var(--accent);
}

/* Top Navigation Bar */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 0;
    margin-bottom: -1rem;
}

.back-home-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 600;
    transition: all var(--transition);
}

.back-home-link:hover {
    color: var(--text-primary);
}

.back-home-link svg {
    width: 16px;
    height: 16px;
    transition: transform var(--transition);
}

.back-home-link:hover svg {
    transform: translateX(-3px);
}

.theme-toggle-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    padding: 0.5rem;
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.theme-toggle-btn:hover {
    border-color: var(--border-hover);
    color: var(--text-primary);
    background: var(--bg-surface-hover);
}

.theme-toggle-btn svg {
    width: 20px;
    height: 20px;
}

/* Toggle icon visibility */
.sun-icon { display: block; }
.moon-icon { display: none; }

:root.theme-dark .sun-icon { display: none; }
:root.theme-dark .moon-icon { display: block; }

@media (prefers-color-scheme: dark) {
    :root:not(.theme-light) .sun-icon { display: none; }
    :root:not(.theme-light) .moon-icon { display: block; }
}

/* Header */
header {
    padding: 2.5rem 0 2rem;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
}

.header-accent {
    font-family: var(--font-body);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    display: inline-block;
}

.logo {
    font-family: var(--font-heading);
    font-size: 2.75rem;
    font-weight: 400;
    line-height: 1.1;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    letter-spacing: -0.01em;
}

.logo span {
    color: var(--accent);
    font-weight: 700;
}

.tagline {
    font-size: 1.05rem;
    color: var(--text-secondary);
}

/* App structure container */
.app-container {
    flex: 1;
    max-width: 1000px;
    width: 100%;
    margin: 0 auto;
    padding: 2.5rem 2rem 5rem;
}

main {
    padding-top: 3.5rem;
    padding-bottom: 3.5rem;
}

/* Card layout widget */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 2rem;
    box-shadow: var(--shadow-sm);
}

.card-header h2 {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    font-weight: 400;
    margin-bottom: 0.25rem;
    color: var(--text-primary);
}

.card-header p {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.card-body {
    margin-top: 1.5rem;
}

/* Setup Panel step prompts */
.question-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
    padding: 1rem 0;
}

.prompt-text {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.btn-group {
    display: flex;
    gap: 0.75rem;
}

/* Restrained Professional Buttons */
.btn {
    padding: 0.6rem 1.5rem;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: var(--font-body);
    cursor: pointer;
    transition: all var(--transition);
    border: 1px solid transparent;
}

.btn-primary {
    background: var(--accent);
    color: #ffffff;
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
    border-color: var(--border-hover);
}

.btn-danger {
    background: transparent;
    color: #ef4444;
    border-color: #fca5a5;
}

.btn-danger:hover {
    background: #fee2e2;
    border-color: #ef4444;
}

/* Main Gameplay Area layout grid */
.game-layout {
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    gap: 2.5rem;
}

/* Game Board widget styling */
.board-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--bg-surface);
    padding: 2rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.column-indicators {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    width: 100%;
    max-width: 440px;
    margin-bottom: 0.75rem;
    gap: 8px;
}

.col-drop-btn {
    background: var(--bg-base);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 0.4rem;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
    transition: all var(--transition);
}

.col-drop-btn:hover:not(:disabled) {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: var(--accent);
}

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

/* The actual board */
.board {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    grid-template-rows: repeat(6, 1fr);
    gap: 8px;
    background: var(--bg-base);
    padding: 12px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    width: 100%;
    max-width: 440px;
    aspect-ratio: 7 / 6;
}

.cell {
    background: transparent;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}

.slot {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 50%;
    transition: background-color var(--transition), box-shadow var(--transition);
    position: relative;
    border: 1px solid var(--border-color);
}

.slot.empty {
    background: var(--bg-surface);
}

.slot.human, .slot.p1 {
    background: var(--color-p1);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.15);
    border-color: transparent;
}

.slot.ai, .slot.p2 {
    background: var(--color-p2);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.15);
    border-color: transparent;
}

/* Sidebar structure */
.sidebar-panel {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.status-card h3, .log-card h3 {
    font-family: var(--font-heading);
    font-size: 1.1rem;
    font-weight: 400;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.35rem;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1rem;
    margin-bottom: 1.25rem;
    font-weight: 600;
}

.pulse-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #10b981;
    animation: pulse 1.8s infinite ease-in-out;
}

.turn-display {
    display: flex;
    align-items: center;
    justify-content: space-around;
    margin-bottom: 1.5rem;
    background: var(--bg-base);
    padding: 0.75rem;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.player-pill {
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    font-weight: 600;
    font-size: 0.8rem;
    border: 1px solid transparent;
}

.player-h, .player-1 {
    background: var(--accent-soft);
    color: var(--color-p1);
    border-color: rgba(220, 38, 38, 0.2);
}

.player-a, .player-2 {
    background: var(--accent-soft);
    color: var(--color-p2);
    border-color: rgba(30, 58, 138, 0.2);
}

.vs {
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.8rem;
}

/* System logs visual frame */
.log-card pre {
    background: var(--bg-base);
    padding: 1rem;
    border-radius: 6px;
    height: 180px;
    overflow-y: auto;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    line-height: 1.45;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

/* Modals Overlay visual guides */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 10;
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    padding: 2.5rem;
    border-radius: 8px;
    text-align: center;
    box-shadow: var(--shadow-md);
    max-width: 420px;
    width: 90%;
}

.modal-card h2 {
    font-family: var(--font-heading);
    font-size: 1.8rem;
    font-weight: 400;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.modal-card p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
}

/* State controls */
.hidden { display: none !important; }
.fade-in { animation: simpleFadeIn 0.3s ease-out; }

@keyframes simpleFadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
    0% { transform: scale(0.92); opacity: 0.4; }
    50% { transform: scale(1.08); opacity: 1; }
    100% { transform: scale(0.92); opacity: 0.4; }
}

@media (max-width: 820px) {
    .game-layout {
        grid-template-columns: 1fr;
        gap: 2rem;
    }
    .app-container {
        padding: 1.5rem 1rem 3rem;
    }
}
