/* ============================================
   RESET & ROOT VARIABLES
   ============================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Color Palette - Emerald & Gold (Sci-Fi / Hacker) */
    --primary-color: #00ffaa;
    --primary-hover: #00cc88;
    --primary-glow: rgba(0, 255, 170, 0.4);
    --secondary-color: #ffb700;
    --secondary-hover: #cc9300;
    --secondary-glow: rgba(255, 183, 0, 0.4);
    --accent-color: #b000ff;
    --bg-dark: #070913;
    --bg-darker: #020308;
    --bg-gradient-end: #0a0d24;
    --text-primary: #ffffff;
    --text-secondary: #8c9eff;
    --border-color: rgba(0, 255, 170, 0.3);
    --card-bg: rgba(10, 14, 39, 0.45);
    --canvas-bg: rgba(0, 255, 170, 0.05);
    --canvas-bg-end: rgba(255, 183, 0, 0.05);
    --header-bg: rgba(0, 255, 170, 0.1);
    --header-bg-end: rgba(255, 183, 0, 0.1);
    --score-bg: rgba(0, 255, 170, 0.1);
    --score-bg-end: rgba(255, 183, 0, 0.1);
    --tree-bg: rgba(0, 255, 170, 0.03);
    --tree-bg-end: rgba(255, 183, 0, 0.03);
    --btn-algo-bg: rgba(0, 255, 170, 0.1);
    --btn-secondary-bg: rgba(255, 183, 0, 0.1);
    --shadow: 0 8px 32px rgba(0, 255, 170, 0.15);
}

/* Light theme */
body.light-mode {
    --bg-dark: #f0f2f8;
    --bg-darker: #e8ebf5;
    --bg-gradient-end: #d5daf0;
    --text-primary: #1a1a2e;
    --text-secondary: #5a5a7a;
    --border-color: rgba(0, 200, 130, 0.4);
    --card-bg: rgba(255, 255, 255, 0.85);
    --canvas-bg: rgba(0, 255, 170, 0.08);
    --canvas-bg-end: rgba(255, 183, 0, 0.08);
    --header-bg: rgba(0, 255, 170, 0.15);
    --header-bg-end: rgba(255, 183, 0, 0.15);
    --score-bg: rgba(0, 255, 170, 0.1);
    --score-bg-end: rgba(255, 183, 0, 0.1);
    --tree-bg: rgba(0, 255, 170, 0.05);
    --tree-bg-end: rgba(255, 183, 0, 0.05);
    --btn-algo-bg: rgba(0, 255, 170, 0.1);
    --btn-secondary-bg: rgba(255, 183, 0, 0.1);
    --shadow: 0 8px 32px rgba(0, 255, 170, 0.1);
}

html, body {
    height: 100%;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--bg-darker) 0%, var(--bg-gradient-end) 100%);
    color: var(--text-primary);
    overflow-x: hidden;
    line-height: 1.6;
    transition: background 0.3s ease, color 0.3s ease;
}

/* ============================================
   SCREEN SYSTEM
   ============================================ */
.screen {
    display: none;
    min-height: 100vh;
    flex-direction: column;
}

.screen.screen-active {
    display: flex;
}

/* ============================================
   SPLASH SCREEN
   ============================================ */
#screen-splash {
    position: relative;
    background: linear-gradient(135deg, #020308 0%, #070913 50%, #0a0d24 100%);
    overflow-x: hidden;
    overflow-y: auto;
}

#screen-splash.screen-active {
    /* remove center align to allow natural flow for scrolling */
    display: block; 
}

.splash-bg {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at 30% 40%, rgba(0, 255, 170, 0.08) 0%, transparent 60%),
                radial-gradient(ellipse at 70% 60%, rgba(255, 183, 0, 0.06) 0%, transparent 60%);
    animation: splashBgPulse 4s ease-in-out infinite alternate;
}

@keyframes splashBgPulse {
    0% { opacity: 0.6; }
    100% { opacity: 1; }
}

.splash-particles {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.splash-particle {
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--primary-color);
    opacity: 0;
    animation: particleFloat linear infinite;
}

@keyframes particleFloat {
    0%   { transform: translateY(100vh) scale(0); opacity: 0; }
    10%  { opacity: 0.6; }
    90%  { opacity: 0.4; }
    100% { transform: translateY(-20px) scale(1); opacity: 0; }
}

.splash-main {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    position: relative;
}

.splash-content {
    position: relative;
    z-index: 2;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.2rem;
    animation: splashContentIn 1s ease-out forwards;
}

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

.splash-logo-wrap {
    width: 120px;
    height: 120px;
    border-radius: 30px;
    border: 2px solid var(--primary-color);
    background: rgba(0, 255, 170, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 40px rgba(0, 255, 170, 0.25), inset 0 0 20px rgba(0, 255, 170, 0.05);
    animation: logoGlow 3s ease-in-out infinite alternate;
}

@keyframes logoGlow {
    0%   { box-shadow: 0 0 20px rgba(0, 255, 170, 0.2), inset 0 0 10px rgba(0, 255, 170, 0.05); }
    100% { box-shadow: 0 0 60px rgba(0, 255, 170, 0.5), inset 0 0 30px rgba(0, 255, 170, 0.1); }
}

.splash-logo {
    width: 80px;
    height: 80px;
    filter: drop-shadow(0 0 12px rgba(0, 255, 170, 0.7));
}

.splash-title {
    font-size: clamp(1.8rem, 5vw, 3.5rem);
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 2px;
    line-height: 1.2;
}

.splash-subtitle {
    font-size: clamp(0.9rem, 2vw, 1.1rem);
    color: var(--text-secondary);
    letter-spacing: 1px;
}

.splash-badge {
    padding: 0.4rem 1.2rem;
    border-radius: 20px;
    background: rgba(0, 255, 170, 0.12);
    border: 1px solid var(--primary-color);
    color: var(--primary-color);
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.splash-play-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 3rem;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: #020308;
    border: none;
    border-radius: 50px;
    font-size: 1.3rem;
    font-weight: 800;
    cursor: pointer;
    letter-spacing: 1px;
    transition: all 0.3s ease;
    box-shadow: 0 0 30px rgba(0, 255, 170, 0.4), 0 8px 24px rgba(0, 0, 0, 0.5);
    animation: playBtnPulse 2s ease-in-out infinite;
}

@keyframes playBtnPulse {
    0%, 100% { box-shadow: 0 0 30px rgba(0, 255, 170, 0.4), 0 8px 24px rgba(0, 0, 0, 0.5); }
    50%       { box-shadow: 0 0 60px rgba(0, 255, 170, 0.7), 0 12px 30px rgba(0, 0, 0, 0.5); }
}

.splash-play-btn:hover {
    transform: scale(1.07) translateY(-3px);
    background: linear-gradient(135deg, #00ffcc, #00ee99);
}

.splash-play-btn:active {
    transform: scale(0.97);
}

.play-icon {
    font-size: 1.5rem;
}

.splash-hint {
    font-size: 0.85rem;
    color: rgba(140, 158, 255, 0.6);
    animation: blinkHint 1.5s ease-in-out infinite;
}

@keyframes blinkHint {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

.splash-footer {
    text-align: center;
    padding-bottom: 2rem;
    font-size: 0.85rem;
    color: rgba(140, 158, 255, 0.6);
}

/* Info Section Styling */
.splash-info-section {
    position: relative;
    z-index: 2;
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem;
    color: rgba(255, 255, 255, 0.9);
}

.info-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 2.5rem;
    margin-bottom: 2rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
}

.info-card h2 {
    color: var(--primary-color);
    font-size: 1.8rem;
    margin-bottom: 1rem;
    letter-spacing: 1px;
}

.info-card h3 {
    color: var(--secondary-color);
    font-size: 1.3rem;
    margin-top: 1.8rem;
    margin-bottom: 0.8rem;
}

.info-card p, .info-card li {
    font-size: 1.05rem;
    line-height: 1.6;
    margin-bottom: 0.8rem;
    color: var(--text-primary);
}

.info-card ul {
    margin-left: 1.8rem;
    margin-bottom: 1.5rem;
}

body.light-mode .splash-info-section {
    color: #1a1a2e;
}

body:not(.light-mode) #soundIcon,
body:not(.light-mode) #setupSoundIcon {
    filter: invert(1) brightness(2);
}

/* ============================================
   SETUP SCREEN
   ============================================ */
#screen-setup {
    background: linear-gradient(135deg, var(--bg-darker) 0%, var(--bg-gradient-end) 100%);
}

.setup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 2rem;
    background: linear-gradient(135deg, var(--header-bg), var(--header-bg-end));
    border-bottom: 1px solid var(--border-color);
    backdrop-filter: blur(10px);
}

.setup-header-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 700;
    font-size: 1.1rem;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.setup-logo {
    width: 36px;
    height: 36px;
    filter: drop-shadow(0 0 6px rgba(0, 255, 170, 0.5));
}

.setup-header-actions {
    display: flex;
    gap: 0.5rem;
}

.setup-body {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
}

.setup-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 2rem 2.5rem;
    width: 100%;
    max-width: 520px;
    backdrop-filter: blur(20px);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4), inset 0 0 30px rgba(0, 255, 170, 0.03);
    animation: setupCardIn 0.5s ease-out forwards;
}

@keyframes setupCardIn {
    from { opacity: 0; transform: translateY(20px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.setup-title {
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    color: var(--primary-color);
    margin-bottom: 1.75rem;
    letter-spacing: 2px;
}

.setup-row {
    margin-bottom: 1.5rem;
}

.setup-label {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.6rem;
    letter-spacing: 0.3px;
}

.setup-hint {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-top: 0.4rem;
    font-style: italic;
}

/* Arrow Selector (gametable style) */
.setup-selector {
    display: flex;
    align-items: center;
    gap: 0;
    background: rgba(0, 255, 170, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    overflow: hidden;
}

.sel-arrow {
    width: 48px;
    height: 48px;
    background: rgba(0, 255, 170, 0.1);
    border: none;
    color: var(--primary-color);
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sel-arrow:hover {
    background: rgba(0, 255, 170, 0.25);
    color: #ffffff;
}

.sel-arrow:active {
    transform: scale(0.9);
}

.sel-value {
    flex: 1;
    text-align: center;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    padding: 0.6rem 0.5rem;
    transition: all 0.2s ease;
}

/* Player icons in setup */
.setup-player-icons {
    display: flex;
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.player-icon {
    width: 50px;
    height: 50px;
    border-radius: 12px;
    border: 2px solid var(--border-color);
    background: rgba(0, 255, 170, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.25s ease;
    user-select: none;
}

.player-icon.human { border-color: var(--primary-color); }
.player-icon.ai    { border-color: var(--secondary-color); }

.player-icon:hover {
    transform: scale(1.1);
    box-shadow: 0 0 15px rgba(0, 255, 170, 0.3);
}

/* Board Preview dots */
.board-preview {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem 0 0.5rem;
    gap: 0;
}

.board-preview-grid {
    display: grid;
    gap: 20px;
}

.preview-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--primary-color);
    box-shadow: 0 0 6px rgba(0, 255, 170, 0.6);
}

/* Start Button */
.setup-start-btn {
    width: 100%;
    padding: 1rem;
    margin-top: 1rem;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: #020308;
    border: none;
    border-radius: 50px;
    font-size: 1.2rem;
    font-weight: 800;
    cursor: pointer;
    letter-spacing: 1px;
    transition: all 0.3s ease;
    box-shadow: 0 0 25px rgba(0, 255, 170, 0.35), 0 6px 20px rgba(0, 0, 0, 0.4);
}

.setup-start-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 0 40px rgba(0, 255, 170, 0.55), 0 10px 28px rgba(0, 0, 0, 0.4);
}

.setup-start-btn:active {
    transform: translateY(0) scale(0.98);
}

/* ============================================
   GAME SCREEN — LAYOUT
   ============================================ */
#screen-game {
    min-height: 100vh;
}

.container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: 1600px;
    margin: 0 auto;
}

.header {
    background: linear-gradient(135deg, var(--header-bg) 0%, var(--header-bg-end) 100%);
    border-bottom: 2px solid var(--border-color);
    padding: 1.2rem 2rem;
    backdrop-filter: blur(10px);
    animation: fadeIn 0.6s ease-out;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
    max-width: 1400px;
    margin: 0 auto;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-logo {
    width: 48px;
    height: 48px;
    filter: drop-shadow(0 0 8px rgba(0, 255, 170, 0.5));
}

.header-actions {
    display: flex;
    gap: 0.6rem;
}

.header-content h1 {
    font-size: clamp(1.3rem, 3vw, 2rem);
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.2rem;
    line-height: 1.2;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.85rem;
    letter-spacing: 0.5px;
}

/* ============================================
   ICON BUTTONS
   ============================================ */
.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: 10px;
    border: 2px solid var(--border-color);
    background: var(--card-bg);
    cursor: pointer;
    transition: all 0.25s ease;
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 600;
}

.icon-btn:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 255, 170, 0.25);
}

.icon-btn img {
    width: 20px;
    height: 20px;
}

.icon-btn.muted {
    opacity: 0.55;
}

.icon-btn-sm {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-weight: 600;
}

.icon-btn-sm:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    box-shadow: 0 2px 10px rgba(0, 255, 170, 0.2);
}

/* ============================================
   MAIN GRID LAYOUT
   ============================================ */
.main-content {
    display: grid;
    grid-template-columns: minmax(240px, 1fr) minmax(380px, auto) minmax(240px, 1fr);
    grid-template-areas:
        "controls game right-panel"
        "tree tree tree";
    gap: 1.5rem;
    padding: 1.5rem 2rem;
    flex: 1;
    align-items: start;
}

/* Section Icons */
.section-icon {
    width: 20px;
    height: 20px;
    vertical-align: middle;
    margin-right: 0.4rem;
}

.score-icon {
    width: 16px;
    height: 16px;
    vertical-align: middle;
    margin-right: 0.25rem;
}

.btn-icon {
    width: 17px;
    height: 17px;
    vertical-align: middle;
    margin-right: 0.4rem;
    flex-shrink: 0;
}

/* ============================================
   CONTROL SECTION (Left Panel)
   ============================================ */
.control-section {
    grid-area: controls;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

/* Shared card styles */
.scoreboard,
.settings-panel,
.stats-panel {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 1.25rem;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3), inset 0 0 12px rgba(0, 255, 170, 0.04);
    animation: fadeSlideUp 0.6s ease forwards;
    opacity: 0;
    transform: translateY(20px);
}

.scoreboard { animation-delay: 0.1s; }
.settings-panel { animation-delay: 0.2s; }
.stats-panel { animation-delay: 0.3s; }

.scoreboard:hover, .settings-panel:hover, .stats-panel:hover {
    box-shadow: 0 10px 36px rgba(0, 255, 170, 0.12), inset 0 0 15px rgba(0, 255, 170, 0.07);
    border-color: rgba(0, 255, 170, 0.4);
    transition: box-shadow 0.3s, border-color 0.3s;
}

.scoreboard h3,
.settings-panel h3,
.stats-panel h3 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
}

/* ============================================
   SCOREBOARD
   ============================================ */
.score-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.score-box {
    background: linear-gradient(135deg, var(--score-bg) 0%, var(--score-bg-end) 100%);
    border: 2px solid var(--primary-color);
    border-radius: 12px;
    padding: 1rem;
    text-align: center;
    position: relative;
    transition: all 0.3s ease;
}

.score-box.ai {
    border-color: var(--secondary-color);
}

.score-box.turn-active {
    box-shadow: 0 0 20px rgba(0, 255, 170, 0.4);
    border-color: var(--primary-color);
    transform: scale(1.03);
}

.score-box.ai.turn-active {
    box-shadow: 0 0 20px rgba(255, 183, 0, 0.4);
    border-color: var(--secondary-color);
}

.score-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.score-value {
    font-size: 2.2rem;
    font-weight: 800;
    color: var(--primary-color);
    line-height: 1;
}

.score-box.ai .score-value {
    color: var(--secondary-color);
}

.turn-indicator {
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 1px;
    color: var(--primary-color);
    background: rgba(0, 255, 170, 0.15);
    border-radius: 6px;
    padding: 0.2rem 0.4rem;
    margin-top: 0.5rem;
    opacity: 0;
    transition: opacity 0.3s;
    text-transform: uppercase;
}

.score-box.turn-active .turn-indicator {
    opacity: 1;
    animation: turnPulse 1.2s ease-in-out infinite;
}

.score-box.ai .turn-indicator {
    color: var(--secondary-color);
    background: rgba(255, 183, 0, 0.15);
}

@keyframes turnPulse {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

/* ============================================
   SETTINGS PANEL
   ============================================ */
.setting-group {
    margin-bottom: 1.25rem;
}

.setting-group label {
    display: block;
    margin-bottom: 0.6rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.button-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
}

.button-group.vertical {
    grid-template-columns: 1fr;
    gap: 0.5rem;
}

.btn-algo,
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-algo {
    padding: 0.65rem 0.75rem;
    background: var(--btn-algo-bg);
    border: 2px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.88rem;
    transition: all 0.25s ease;
}

.btn-algo:hover {
    background: rgba(0, 255, 170, 0.15);
    border-color: var(--primary-color);
    transform: translateY(-1px);
}

.btn-algo.active {
    background: linear-gradient(135deg, rgba(0, 255, 170, 0.3), rgba(0, 200, 130, 0.2));
    border-color: var(--primary-color);
    color: var(--primary-color);
    box-shadow: 0 0 15px rgba(0, 255, 170, 0.3);
    font-weight: 700;
}

.mode-hint,
.depth-hint {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.4rem;
    line-height: 1.4;
    font-style: italic;
}

/* Depth Slider */
.depth-slider {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

#depthSlider {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    outline: none;
    -webkit-appearance: none;
}

#depthSlider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    box-shadow: 0 0 8px rgba(0, 255, 170, 0.5);
}

#depthSlider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    border: none;
}

#depthValue {
    min-width: 26px;
    text-align: center;
    font-weight: 700;
    color: var(--primary-color);
    font-size: 1rem;
}

/* Buttons */
.btn {
    padding: 0.7rem 1.25rem;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: #020308;
    box-shadow: 0 0 18px rgba(0, 255, 170, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 28px rgba(0, 255, 170, 0.5);
}

.btn-setup {
    background: transparent;
    border: 2px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
}

.btn-setup:hover {
    border-color: var(--secondary-color);
    color: var(--secondary-color);
    background: rgba(255, 183, 0, 0.08);
    transform: translateY(-1px);
}

/* ============================================
   GAME SECTION (Center Panel)
   ============================================ */
.game-section {
    grid-area: game;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
    width: 100%;
    max-width: 520px;
    justify-self: center;
}

.game-wrapper {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 1.25rem 1.5rem 1.5rem;
    backdrop-filter: blur(20px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3), inset 0 0 15px rgba(0, 255, 170, 0.05);
    width: 100%;
    max-width: 480px;
    text-align: center;
    transition: box-shadow 0.3s ease;
    animation: fadeSlideUp 0.6s ease forwards;
    animation-delay: 0.15s;
    opacity: 0;
    transform: translateY(20px);
}

.game-wrapper:hover {
    box-shadow: 0 12px 40px rgba(0, 255, 170, 0.15), inset 0 0 20px rgba(0, 255, 170, 0.07);
}

/* Game Top Bar */
.game-top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.game-top-bar h2 {
    font-size: 1.15rem;
    display: flex;
    align-items: center;
}

/* Status chips */
.game-status-bar {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.status-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 1rem;
    border-radius: 20px;
    background: rgba(0, 255, 170, 0.1);
    border: 1px solid rgba(0, 255, 170, 0.25);
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--primary-color);
}

.active-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary-color);
    animation: dotBlink 1s ease-in-out infinite;
    flex-shrink: 0;
}

@keyframes dotBlink {
    0%, 100% { opacity: 1; box-shadow: 0 0 4px rgba(0,255,170,0.8); }
    50% { opacity: 0.4; box-shadow: none; }
}

/* Canvas */
.canvas-container {
    display: flex;
    justify-content: center;
    margin-bottom: 0.5rem;
}

#gameCanvas {
    display: block;
    border: 2px solid var(--primary-color);
    border-radius: 10px;
    background: linear-gradient(135deg, var(--canvas-bg) 0%, var(--canvas-bg-end) 100%);
    cursor: crosshair;
    width: 400px;
    height: 400px;
    max-width: 100%;
    transition: box-shadow 0.3s ease;
}

#gameCanvas:hover {
    box-shadow: 0 0 20px rgba(0, 255, 170, 0.4);
}

/* AI Thinking Bar */
.ai-thinking-bar {
    display: none;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1rem;
    background: rgba(255, 183, 0, 0.1);
    border: 1px solid rgba(255, 183, 0, 0.3);
    border-radius: 8px;
    margin-top: 0.75rem;
    font-size: 0.88rem;
    color: var(--secondary-color);
    font-weight: 500;
    overflow: hidden;
    position: relative;
}

.ai-thinking-bar.visible {
    display: flex;
}

.ai-bar-fill {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 30%;
    background: linear-gradient(90deg, transparent, rgba(255, 183, 0, 0.15), transparent);
    animation: thinkingSweep 1.5s ease-in-out infinite;
}

@keyframes thinkingSweep {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(400%); }
}

/* ============================================
   RIGHT SECTION
   ============================================ */
.right-section {
    grid-area: right-panel;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    animation: fadeIn 0.6s 0.25s ease-out both;
}

/* ============================================
   STATS PANEL
   ============================================ */
.stats-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.stat-item-2 {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 0.65rem 0.5rem;
    background: linear-gradient(135deg, var(--score-bg) 0%, var(--score-bg-end) 100%);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.stat-item-2 .stat-label {
    font-size: 0.72rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.stat-item-2 .stat-value {
    font-weight: 700;
    font-size: 1rem;
    color: var(--primary-color);
}

.stat-value.stat-updated {
    animation: statPulse 0.5s ease;
}

@keyframes statPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); color: #ffffff; }
    100% { transform: scale(1); }
}

.stats-hint {
    color: var(--text-secondary);
    font-size: 0.78rem;
    margin-bottom: 0.75rem;
}

/* ============================================
   COMPARE TABLE
   ============================================ */
.compare-panel {
    width: 100%;
    max-width: 520px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1.1rem 1.25rem;
    backdrop-filter: blur(10px);
    box-shadow: var(--shadow);
    animation: fadeSlideUp 0.6s 0.3s ease forwards;
    opacity: 0;
    transform: translateY(20px);
}

.compare-header h3 {
    font-size: 0.95rem;
    margin-bottom: 0.2rem;
}

.compare-table-wrapper {
    max-height: 175px;
    overflow-y: auto;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    margin-top: 0.65rem;
}

.compare-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.compare-table thead {
    position: sticky;
    top: 0;
    z-index: 1;
    background: rgba(0, 255, 170, 0.15);
}

.compare-table th {
    padding: 0.5rem 0.6rem;
    text-align: center;
    font-weight: 600;
    font-size: 0.75rem;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.compare-table td {
    padding: 0.4rem 0.6rem;
    text-align: center;
    border-bottom: 1px solid rgba(0, 255, 170, 0.08);
    color: var(--text-primary);
    transition: background 0.2s;
}

.compare-table tr:last-child td { border-bottom: none; }

.compare-table tbody tr:hover td {
    background: rgba(0, 255, 170, 0.06);
}

.table-empty {
    color: var(--text-secondary);
    font-style: italic;
    padding: 1rem !important;
}

.compare-table .nodes-val {
    font-weight: 600;
    color: var(--primary-color);
}

.compare-table .pruned-val {
    color: #ff5252;
    font-weight: 600;
}

.algo-badge {
    display: inline-block;
    padding: 0.18rem 0.5rem;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 700;
    white-space: nowrap;
}

.algo-badge.minimax {
    background: rgba(255, 23, 68, 0.15);
    color: #ff5252;
    border: 1px solid rgba(255, 23, 68, 0.35);
}

.algo-badge.alphabeta {
    background: rgba(0, 255, 170, 0.12);
    color: var(--primary-color);
    border: 1px solid rgba(0, 255, 170, 0.3);
}

/* ============================================
   TREE SECTION (Bottom Panel)
   ============================================ */
.tree-section {
    grid-area: tree;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 1.25rem;
    backdrop-filter: blur(20px);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    animation: fadeSlideUp 0.6s 0.4s ease forwards;
    opacity: 0;
    transform: translateY(20px);
}

.tree-section:hover {
    box-shadow: 0 10px 36px rgba(0, 255, 170, 0.12);
    border-color: rgba(0, 255, 170, 0.4);
    transition: box-shadow 0.3s, border-color 0.3s;
}

.tree-wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.tree-wrapper h3 {
    margin-bottom: 0.5rem;
    font-size: 1.05rem;
    display: flex;
    align-items: center;
}

.tree-hint {
    color: var(--text-secondary);
    font-size: 0.78rem;
    margin-bottom: 0.75rem;
}

.tree-container {
    flex: 1;
    background: linear-gradient(135deg, var(--tree-bg) 0%, var(--tree-bg-end) 100%);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 1rem;
    min-height: 280px;
    margin-bottom: 1rem;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.tree-empty {
    color: var(--text-secondary);
    font-size: 0.88rem;
    text-align: center;
    padding: 2rem 1rem;
}

.tree-svg-wrapper {
    width: 100%;
    flex: 1;
    min-height: 250px;
    overflow: auto;
    cursor: grab;
}

.tree-svg-wrapper:active { cursor: grabbing; }

.tree-svg {
    display: block;
    width: 100%;
    height: auto;
    transform-origin: 0 0;
    transition: transform 0.1s ease-out;
}

.tree-controls {
    position: absolute;
    bottom: 0.75rem;
    right: 0.75rem;
    display: flex;
    gap: 0.4rem;
    background: rgba(10, 14, 39, 0.85);
    padding: 0.4rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    backdrop-filter: blur(5px);
}

.tree-btn {
    background: transparent;
    border: 1px solid var(--text-secondary);
    color: var(--text-primary);
    width: 26px;
    height: 26px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    font-weight: bold;
    transition: all 0.2s;
}

.tree-btn:hover {
    background: rgba(0, 255, 170, 0.15);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.tree-legend {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.82rem;
}

.legend-color {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex-shrink: 0;
}

.legend-color.max     { background: #ff1744; }
.legend-color.min     { background: #ffb300; }
.legend-color.pruned  { background: #ff5252; }
.legend-color.selected{ background: #00ff41; }

/* ============================================
   LOG MONITOR
   ============================================ */
.log-monitor-panel {
    background: #0f111a;
    border: 1px solid #2a2e40;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 320px;
    font-family: 'Consolas', 'Courier New', monospace;
    box-shadow: 0 4px 15px rgba(0,0,0,0.4);
}

.log-header {
    background: #171a26;
    border-bottom: 1px solid #2a2e40;
    padding: 0.6rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.log-dots { display: flex; gap: 5px; }

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.dot.red    { background: #ff5f56; }
.dot.yellow { background: #ffbd2e; }
.dot.green  { background: #27c93f; }

.log-title {
    color: #8c92a6;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 1px;
}

.log-content {
    padding: 0.75rem;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.log-content::-webkit-scrollbar { width: 6px; }
.log-content::-webkit-scrollbar-thumb {
    background: #3e4459;
    border-radius: 3px;
}

.log-entry {
    display: flex;
    gap: 0.5rem;
    font-size: 0.82rem;
    line-height: 1.4;
    padding-left: 6px;
    border-left: 2px solid transparent;
}

.log-time {
    color: #5c6370;
    white-space: nowrap;
    font-size: 0.75rem;
}

.log-text.ai       { color: #56b6c2; border-left-color: #56b6c2; }
.log-text.ai-move  { color: #c678dd; border-left-color: #c678dd; }
.log-text.human    { color: #98c379; border-left-color: #98c379; }
.log-text.system   { color: #e5c07b; border-left-color: #e5c07b; }

/* ============================================
   AI THINKING OVERLAY ON GAME WRAPPER
   ============================================ */
.game-wrapper.ai-thinking #gameCanvas {
    opacity: 0.75;
}

/* ============================================
   GAME OVER MODAL
   ============================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(2, 3, 8, 0.82);
    backdrop-filter: blur(6px);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    animation: modalFadeIn 0.3s ease;
}

.modal-overlay.visible {
    display: flex;
}

@keyframes modalFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.modal-card {
    background: var(--card-bg);
    border: 2px solid var(--primary-color);
    border-radius: 24px;
    padding: 2.5rem 2rem;
    text-align: center;
    max-width: 380px;
    width: 90%;
    box-shadow: 0 0 60px rgba(0, 255, 170, 0.25), 0 20px 60px rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(20px);
    animation: modalCardIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes modalCardIn {
    from { transform: scale(0.7); opacity: 0; }
    to   { transform: scale(1); opacity: 1; }
}

.modal-icon {
    font-size: 3.5rem;
    margin-bottom: 0.75rem;
    animation: modalIconBounce 0.5s 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes modalIconBounce {
    from { transform: scale(0) rotate(-20deg); opacity: 0; }
    to   { transform: scale(1) rotate(0deg); opacity: 1; }
}

.modal-title {
    font-size: 1.75rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 1.5rem;
}

.modal-scores {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    margin-bottom: 1.75rem;
    padding: 1rem;
    background: rgba(0, 255, 170, 0.06);
    border-radius: 14px;
    border: 1px solid var(--border-color);
}

.modal-score-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
}

.modal-score-item span {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.modal-score-item strong {
    font-size: 2.2rem;
    font-weight: 800;
    color: var(--primary-color);
}

.modal-score-sep {
    font-size: 1rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.modal-btns {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
}

.modal-btns .btn {
    flex: 1;
}

/* ============================================
   FOOTER
   ============================================ */
.footer {
    text-align: center;
    padding: 1.25rem;
    border-top: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.footer-sub {
    font-size: 0.75rem;
    color: var(--text-secondary);
    opacity: 0.6;
    margin-top: 0.2rem;
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

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

/* Tree Animations */
.tree-node-group {
    animation: treeNodeIn 0.35s ease-out both;
}

@keyframes treeNodeIn {
    from { opacity: 0; transform: scale(0.5); transform-origin: center; }
    to   { opacity: 1; transform: scale(1); }
}

.tree-node-selected {
    animation: treeNodeIn 0.35s ease-out both, bestNodePulse 1.8s ease-in-out 0.35s infinite;
}

@keyframes bestNodePulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.75; }
}

.tree-node-pruned {
    animation: treeNodeIn 0.35s ease-out both, prunedBlink 1.2s ease-in-out 0.35s infinite;
}

@keyframes prunedBlink {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.45; }
}

.tree-link-best {
    stroke-dasharray: 120;
    stroke-dashoffset: 120;
    animation: drawPath 0.5s ease-out forwards;
}

@keyframes drawPath {
    to { stroke-dashoffset: 0; }
}

.tree-link-pruned {
    animation: dashSlide 1.5s linear infinite;
}

@keyframes dashSlide {
    to { stroke-dashoffset: -14; }
}

/* Screen transitions */
@keyframes screenFadeIn {
    from { opacity: 0; transform: translateY(15px); }
    to   { opacity: 1; transform: translateY(0); }
}

.screen.entering {
    animation: screenFadeIn 0.4s ease forwards;
}

/* Scrollbar */
::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: rgba(0, 255, 170, 0.04); }
::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    border-radius: 4px;
}

/* ============================================
   RESPONSIVE — TABLET (max 1200px)
   ============================================ */
@media (max-width: 1200px) {
    .main-content {
        grid-template-columns: 1fr;
        grid-template-areas:
            "game"
            "controls"
            "right-panel"
            "tree";
        gap: 1.25rem;
        padding: 1.25rem;
    }

    .game-section {
        justify-self: center;
        max-width: 100%;
    }

    .compare-panel {
        max-width: 100%;
    }

    .stats-panel {
        width: 100%;
    }
}

/* ============================================
   RESPONSIVE — MOBILE (max 768px)
   ============================================ */
@media (max-width: 768px) {
    .header {
        padding: 1rem;
    }

    .header-content {
        flex-direction: column;
        gap: 0.75rem;
    }

    .header-brand {
        justify-content: center;
    }

    .header-content h1 {
        font-size: 1.4rem;
        text-align: center;
    }

    .subtitle {
        text-align: center;
    }

    .main-content {
        padding: 1rem;
        gap: 1rem;
    }

    .game-wrapper {
        padding: 1rem;
    }

    #gameCanvas {
        width: 100%;
        height: auto;
    }

    .button-group {
        grid-template-columns: 1fr;
    }

    .tree-legend {
        grid-template-columns: 1fr;
    }

    .score-container {
        gap: 0.5rem;
    }

    .score-value {
        font-size: 1.75rem;
    }

    .compare-table th,
    .compare-table td {
        padding: 0.35rem 0.4rem;
        font-size: 0.72rem;
    }

    /* Setup responsive */
    .setup-card {
        padding: 1.5rem;
    }

    .sel-arrow {
        width: 40px;
        height: 42px;
    }

    /* Modal responsive */
    .modal-card {
        padding: 2rem 1.5rem;
    }

    .modal-title {
        font-size: 1.4rem;
    }

    .modal-icon {
        font-size: 2.5rem;
    }
}

@media (max-width: 480px) {
    .splash-play-btn {
        padding: 0.9rem 2rem;
        font-size: 1.1rem;
    }

    .setup-card {
        border-radius: 16px;
        padding: 1.25rem;
    }

    .setup-title {
        font-size: 1.2rem;
    }

    .stats-grid-2 {
        grid-template-columns: 1fr 1fr;
        gap: 0.4rem;
    }

    .modal-btns {
        flex-direction: column;
    }
}