/* Custom Variable Definitions */
:root {
    --bg-gradient: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    --card-bg: #ffffff;
    --text-primary: #2d3748;
    --text-secondary: #718096;
    --border-color: #e2e8f0;
    --primary-color: #4a90e2;
    --primary-hover: #357abd;
    --danger-color: #e53e3e;
    --danger-hover: #c53030;
    --success-bg: #c6f6d5;
    --success-text: #22543d;
    --error-bg: #fed7d7;
    --error-text: #742a2a;
    --shadow: 0 10px 20px rgba(0,0,0,0.05), 0 6px 6px rgba(0,0,0,0.07);
    --radius: 12px;
    --transition: all 0.25s ease;
}

body.dark-mode {
    --bg-gradient: linear-gradient(135deg, #1a202c 0%, #2d3748 100%);
    --card-bg: #1a202c;
    --text-primary: #f7fafc;
    --text-secondary: #a0aec0;
    --border-color: #4a5568;
    --shadow: 0 10px 25px rgba(0,0,0,0.3);
}

/* Global Layout & Typography Defaults */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
    background: var(--bg-gradient);
    color: var(--text-primary);
    min-height: 100vh;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

/* Main Outer Page Wrapper */
.container, .game-container {
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Header Banner */
header, .game-header {
    text-align: center;
    padding: 20px;
    background: linear-gradient(90deg, #4a90e2, #63b3ed);
    color: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

header h1, .game-header h1 { 
    font-size: 2.2rem; 
    font-weight: 700; 
    margin-bottom: 5px; 
}

.subtitle {
    font-size: 1rem;
    opacity: 0.9;
}

/* 2-Column Desktop Grid Layout */
.main-layout, .game-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 20px;
    align-items: start;
    width: 100%;
}

/* Sidebar & Main Columns */
.sidebar, .game-area {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
}

/* Reusable Cards */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    transition: var(--transition);
}

/* Forms & Inputs */
input[type="text"], select {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: transparent;
    color: var(--text-primary);
    font-size: 1rem;
    outline: none;
    transition: var(--transition);
}

input[type="text"]:focus, select:focus {
    border-color: var(--primary-color);
}

button {
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    background: var(--primary-color);
    color: white;
}

button:hover:not(:disabled) { 
    background: var(--primary-hover); 
    transform: translateY(-1px); 
}

button:active:not(:disabled) { transform: translateY(0); }
button:disabled { opacity: 0.4; cursor: not-allowed; }

.secondary-btn { 
    background: var(--text-secondary); 
    width: 100%;
    margin-top: 5px;
}
.secondary-btn:hover:not(:disabled) { background: #4a5568; }

/* Display Cards */
.display-card {
    display: flex;
    gap: 16px;
    text-align: center;
}

.word-display-box, .letter-display-box {
    flex: 1;
    padding: 16px;
    border-radius: var(--radius);
    background: var(--border-color);
    opacity: 0.95;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.label {
    display: block;
    font-size: 0.75rem;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.word-value, #current-word-display { 
    font-size: 1.8rem; 
    font-weight: 700;
    color: var(--primary-color); 
    letter-spacing: 1px;
}

.letter-value, #target-letter-display { 
    font-size: 2.8rem; 
    font-weight: 800;
    color: var(--text-primary); 
    text-transform: uppercase;
}

.timer-display { 
    font-size: 1.1rem; 
    font-weight: 700; 
    color: var(--danger-color); 
    margin-top: 6px;
}

.status-box {
    padding: 12px 16px;
    border-radius: 8px;
    font-weight: 500;
    text-align: center;
    margin-bottom: 16px;
    background: var(--border-color);
}

.status-box.success { background: var(--success-bg); color: var(--success-text); }
.status-box.error { background: var(--error-bg); color: var(--error-text); }

.input-group {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}
.input-group input { flex: 1; font-size: 1.1rem; }

/* History Card - Flex Container */
.history-card {
    display: flex;
    flex-direction: column;
    height: 100%; /* Fills the vertical space available in the sidebar */
}

/* History List - Fixed Scroll Container */
.history-list {
    flex: 1;
    min-height: 120px;
    max-height: 220px; /* Constrains height to force scrollbar */
    height: 220px; /* Ensures a strict box height for scroll calculations */
    overflow-y: auto !important; /* Forces scrollbar when overflowing */
    
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px;
    margin-top: 10px;
    
    /* Layout for wrapped word tags */
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 6px;
    
    scroll-behavior: smooth;
}

/* On Desktop (2-Column Layout): Sync height with the main game area cards */
@media (min-width: 769px) {
    .history-list {
        max-height: calc(100% - 40px); /* Restricts list height to card boundary */
    }
}

.history-item {
    padding: 4px 10px;
    border-radius: 15px;
    font-size: 0.9rem;
    font-weight: 500;
}
.history-item.player { background: #ebf8ff; color: #2b6cb0; }
.history-item.ai { background: #feebc8; color: #9c4221; }
.placeholder-text { color: var(--text-secondary); font-style: italic; width: 100%; text-align: center; }

/* Central Splash Turn Overlay */
.status-card {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.8);
    z-index: 10000;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(12px);
    border-radius: 24px;
    padding: 32px 48px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.8);
    text-align: center;
}

.turn-indicator {
    font-size: 2.2rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    white-space: nowrap;
}

@keyframes centralTurnSplash {
    0% { opacity: 0; visibility: visible; transform: translate(-50%, -50%) scale(0.7); }
    15% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
    25% { transform: translate(-50%, -50%) scale(1); }
    75% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; visibility: hidden; transform: translate(-50%, -50%) scale(0.9); }
}

.turn-splash-anim {
    animation: centralTurnSplash 1.8s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.fairy-turn { color: #2563eb; text-shadow: 0 4px 12px rgba(37, 99, 235, 0.2); }
.player-turn { color: #059669; text-shadow: 0 4px 12px rgba(5, 150, 105, 0.2); }

.hidden { display: none !important; }

/* -------------------------------------------------------------
 * Responsive Mobile Fixes (Clean Full-Width Stacking)
 * ------------------------------------------------------------- */
@media (max-width: 768px) {
    body {
        padding: 12px 8px;
        align-items: stretch;
    }
    .container, .game-container {
        width: 100%;
        max-width: 100%;
        gap: 12px;
    }
    .main-layout, .game-layout {
        display: flex;
        flex-direction: column;
        grid-template-columns: none;
        width: 100%;
        gap: 12px;
    }
    .sidebar, .game-area {
        width: 100%;
        gap: 12px;
    }
    .display-card {
        flex-direction: row; /* Keeps Word & Letter side-by-side on mobile */
        gap: 10px;
    }
    .word-display-box, .letter-display-box {
        padding: 12px 8px;
    }
    .turn-indicator { font-size: 1.4rem; }
    .status-card { padding: 18px 24px; width: 90%; }
    header h1, .game-header h1 { font-size: 1.5rem; }
}

/* Definition Card Styling */
.definition-card {
    background: #f8fafc;
    border: 1px solid var(--border-color);
    border-left: 5px solid #16a34a;
    padding: 16px;
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    transition: all 0.25s ease-in-out;
}

body.dark-mode .definition-card {
    background: #2d3748;
}

.def-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.def-title {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.def-tag {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 3px 10px;
    border-radius: 12px;
    font-weight: 700;
    background: rgba(22, 163, 74, 0.15);
    color: #16a34a;
}

.def-body {
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--text-primary);
}