/* --- Global Styles & Variables --- */
:root {
    --primary-color: #6a0dad; /* A deep, rich purple */
    --primary-light: #8e2de2; /* Lighter purple for accents */
    --primary-hover: #5a0aaa;
    --secondary-color: #343a40; /* Muted dark gray for secondary actions */
    --secondary-hover: #212529;
    --success-color: #28a745;
    --danger-color: #dc3545;
    
    --bg-main: #1a1a1d;       /* Very dark background */
    --bg-card: #2c2c31;       /* Slightly lighter background for cards/containers */
    --bg-input: #3a3a3e;      /* Input field background */
    --bg-highlight: #4a4a50;  /* Subtle highlight for interactive elements */

    --text-main: #e0e0e0;     /* Light gray for main text */
    --text-secondary: #a0a0a0; /* Muted gray for secondary text */
    --text-accent: var(--primary-light); /* Accent color for important info */

    --border-color: #44444a;
    --border-radius-main: 10px;
    --border-radius-sm: 6px;
    --font-family: 'Poppins', sans-serif;
    --font-mono: 'Fira Code', 'JetBrains Mono', 'Courier New', monospace;
}

html, body {
    height: 100vh;
    overflow: hidden; /* Prevents the whole page from scrolling */
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-main);
    color: var(--text-main);
    margin: 0;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.container {
    width: 100%;
    max-width: 800px;
    background: var(--bg-card);
    padding: 2.5rem 3rem;
    border-radius: var(--border-radius-main);
    box-sizing: border-box;
    max-height: 90vh;
    overflow-y: auto;
}

/* Custom scrollbar for container */
.container::-webkit-scrollbar {
    width: 10px;
}
.container::-webkit-scrollbar-track {
    background: var(--bg-card);
}
.container::-webkit-scrollbar-thumb {
    background-color: var(--bg-highlight);
    border-radius: 5px;
}
.container::-webkit-scrollbar-thumb:hover {
    background-color: var(--text-secondary);
}

/* --- Screen Management --- */
.screen { display: none; }
.screen.active { display: block; }
.hidden { display: none !important; }

/* --- Typography & Elements --- */
h1, h2 {
    color: var(--text-main);
    text-align: center;
    margin-top: 0;
    font-weight: 600;
}
h1 { font-size: 3rem; margin-bottom: 1rem;} /* Reduced margin */
h2 { font-size: 2.2rem; margin-bottom: 1.2rem;}

p {
    font-size: 1.05rem;
    line-height: 1.6;
    text-align: center;
    margin-bottom: 1.5rem;
    color: var(--text-secondary);
}

input[type="text"], textarea {
    width: 100%;
    padding: 15px 20px;
    font-size: 1.1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    box-sizing: border-box;
    margin-bottom: 1rem;
    background: var(--bg-input);
    color: var(--text-main);
    outline: none;
    transition: border-color 0.2s; /* Removed box-shadow transition */
}

input[type="text"]::placeholder, textarea::placeholder {
    color: var(--text-secondary);
    opacity: 0.7;
}

input[type="text"]:focus, textarea:focus {
    border-color: var(--primary-light);
    /* Removed box-shadow */
}

textarea {
    font-family: var(--font-mono); /* Modern monospace font */
    font-size: 1.25rem; /* Adjusted size */
    line-height: 1.6;
    resize: none;
    padding: 10px 20px;
}

button {
    display: block;
    width: 100%;
    padding: 16px;
    font-size: 1.15rem;
    font-weight: 600;
    color: #fff;
    background-color: var(--primary-color);
    border: none;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
    letter-spacing: 0.05em;
    /* Removed box-shadow */
}

button:hover {
    background-color: var(--primary-hover);
    /* Removed box-shadow */
}
button:active {
    transform: translateY(1px); /* Keep the press effect */
    /* Removed box-shadow */
}

button:disabled {
    background-color: var(--secondary-color);
    cursor: not-allowed;
    opacity: 0.6;
    transform: none;
}

button.secondary {
    background-color: var(--secondary-color);
}
button.secondary:hover {
    background-color: var(--secondary-hover);
    /* Removed box-shadow */
}
button.secondary:active {
    transform: translateY(1px);
    /* Removed box-shadow */
}


.error {
    color: var(--danger-color);
    font-weight: 500;
    font-size: 1rem;
    text-align: center;
    margin-top: -0.5rem;
    margin-bottom: 1rem;
}

/* --- Name Screen Specifics --- */
#name-screen .logo-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 1rem; /* Reduced gap */
}

#blankspace-logo {
    width: 90px; /* Slightly smaller */
    height: auto;
    margin-bottom: 0.5rem;
}

.conducted-by {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-top: 0;
    margin-bottom: 1rem; /* Reduced gap */
}

/* --- Game Screen --- */
#stats-bar {
    display: flex;
    justify-content: space-around;
    padding: 1.2rem 1rem;
    background: var(--bg-input);
    border-radius: var(--border-radius-sm);
    margin-bottom: 1.5rem;
    /* Removed inset shadow */
}
#stats-bar div {
    display: flex;
    flex-direction: column;
    align-items: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    width: 100px;
}
#stats-bar div span {
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--primary-light);
    margin-top: 8px;
    line-height: 1;
}

.text-display {
    font-family: var(--font-mono); /* Modern monospace font */
    font-size: 1.35rem; /* Adjusted size */
    line-height: 1.7; /* Increased line height */
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
    border-radius: var(--border-radius-sm);
    margin-bottom: 1.5rem;
    color: var(--text-secondary);
    user-select: none;
    min-height: 200px; /* Tall enough to show all text */
}

/* Text styling for typed characters */
.text-display span {
    transition: color 0.05s, background-color 0.05s;
}
.text-display span.correct {
    color: var(--text-main);
}
.text-display span.incorrect {
    color: var(--danger-color);
    background-color: rgba(220, 53, 69, 0.15);
    text-decoration: underline; /* Flat underline */
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
    border: none; /* Remove old border */
}
.text-display span.current {
    background-color: var(--primary-light);
    color: var(--bg-main);
    border-radius: 3px;
}

.game-buttons {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
}
.game-buttons button {
    flex: 1;
}

/* --- Summary Screen --- */
.final-stats {
    background: var(--bg-input);
    padding: 2rem;
    border-radius: var(--border-radius-sm);
    margin: 2.5rem 0;
    font-size: 1.1rem;
    line-height: 2.5;
    /* Removed border */
}
.final-stats div {
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    padding: 0.5rem 0;
    font-weight: 500;
}
.final-stats div:last-child {
    border-bottom: none;
}
.final-stats span {
    font-weight: 700;
    color: var(--primary-light);
    font-size: 1.3rem;
    letter-spacing: 0.02em;
}


/* --- Leaderboard Screen --- */
#leaderboard-table {
    width: 100%;
    margin-top: 1.5rem;
    font-size: 1rem;
    border-collapse: collapse;
}
.leaderboard-header, .leaderboard-row {
    display: grid;
    grid-template-columns: 0.5fr 2fr 1.5fr 1.2fr 1fr 1fr;
    gap: 10px;
    padding: 15px 12px;
    border-bottom: 1px solid var(--border-color);
    align-items: center;
}
.leaderboard-header {
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-input);
    font-size: 0.85rem;
    text-transform: uppercase;
    border-radius: var(--border-radius-sm) var(--border-radius-sm) 0 0;
}
#leaderboard-entries {
    max-height: 350px;
    overflow-y: auto;
    -ms-overflow-style: none;
    scrollbar-width: none;
}
#leaderboard-entries::-webkit-scrollbar {
    display: none;
}

.leaderboard-row {
    transition: background-color 0.2s;
    font-weight: 400;
    /* Removed border-bottom, handled by grid parent */
}
.leaderboard-row:last-child {
    border-bottom: none; /* No double border */
}
.leaderboard-row:hover {
    background-color: var(--bg-highlight);
}
.leaderboard-row div:first-child { /* Rank */
    font-weight: 700;
    color: var(--primary-light);
    font-size: 1.2rem;
    text-align: center;
}
.leaderboard-row div:nth-child(2) { /* Name */
    font-weight: 500;
    color: var(--text-main);
}
.leaderboard-row div:nth-child(3) { /* Score */
    font-weight: 600;
    color: var(--success-color);
    font-size: 1.1rem;
}
.leaderboard-row div:not(:first-child):not(:nth-child(2)):not(:nth-child(3)) {
    color: var(--text-secondary);
}


/* --- Responsiveness --- */
@media (max-width: 768px) {
    body { 
        padding: 0; 
        align-items: flex-start; /* Align to top on mobile */
    }
    html, body {
        height: auto;
        min-height: 100vh;
        overflow: auto; /* Allow scrolling on mobile */
    }
    .container { 
        padding: 1.5rem; 
        border-radius: 0;
        min-height: 100vh;
        max-height: none;
    }
    h1 { font-size: 2.2rem; }
    h2 { font-size: 1.8rem; }
    p { font-size: 1rem; }

    #blankspace-logo { width: 70px; }
    .conducted-by { font-size: 1rem; margin-top: -0.5rem; }

    #stats-bar {
        flex-wrap: wrap;
        gap: 0.8rem;
        padding: 1rem;
    }
    #stats-bar div {
        width: 30%;
        font-size: 0.75rem;
    }
    #stats-bar div span {
        font-size: 1.8rem;
    }
    
    .text-display { 
        font-size: 1.15rem; 
        min-height: 150px;
    }
    textarea { 
        font-size: 1.1rem;
        min-height: 80px; 
    }

    .game-buttons { flex-direction: column; }
    .game-buttons button { margin-bottom: 0.5rem; }

    .final-stats { padding: 1.5rem; margin: 2rem 0; }
    .final-stats div { font-size: 0.95rem; }
    .final-stats span { font-size: 1.1rem; }

    .leaderboard-header, .leaderboard-row {
        grid-template-columns: 40px 1.8fr 1fr; /* Rank, Name, Score */
        font-size: 0.85rem;
        padding: 12px 8px;
    }
    .leaderboard-header div:nth-child(n+4),
    .leaderboard-row div:nth-child(n+4) {
        display: none; /* Hide Time, WPM, Acc on mobile */
    }
    .leaderboard-row div:first-child { font-size: 1.1rem; }
}