body {
    margin: 0;
    background-color: #111;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    width: 100vw;
    color: white;
    font-family: 'Orbitron', sans-serif; /* Global Theme Font */
    font-weight: 500;
    letter-spacing: 0.5px;
    overflow: hidden;
}

* {
    font-family: 'Orbitron', sans-serif !important;
}
#scale-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100vw;
    height: 100vh;
}

.game-container {
    display: flex;
    gap: 20px;
    padding: 20px;
    background: #000;
    border: 1px solid #333;
    border-radius: 8px;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    position: relative;
    width: max-content;
    height: max-content;
}

#game-over-screen {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.95);
    border: 2px solid #ff5555;
    border-radius: 8px;
    box-shadow: 0 0 30px #ff5555;
    padding: 40px;
    z-index: 100;
    text-align: center;
    min-width: 400px;
    font-family: 'Orbitron', sans-serif;
}

.hidden { display: none !important; }

canvas {
    background-color: #000;
    border: 2px solid #222;
    border-radius: 4px;
    display: block;
}
.sidebar {
    width: 260px;
    height: 900px; 
    flex-shrink: 0;
    padding: 20px;
    background: #0a0a0a;
    border: 1px solid #333;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 15px; /* Restoring default gap for stats sidebar */
    box-shadow: inset 0 0 15px rgba(255, 255, 255, 0.05);
    transition: opacity 0.3s, visibility 0.3s;
    box-sizing: border-box;
}

#leaderboard-sidebar {
    gap: 0; /* Keeps the margin-top:auto docking for leaderboard controls */
}

.wide-active .sidebar {
    display: none;
}

.wide-active .game-container {
    gap: 0;
    width: 100vw;
    height: 100vh;
    padding: 0;
    margin: 0;
    justify-content: center;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 9999;
    background: #000;
}

.wide-active canvas {
    width: 100vw;
    height: 100vh;
    border: none;
    box-shadow: none;
}

/* Leaderboard Scrolling */
#live-leaderboard-list {
    flex: 1 1 auto; /* Aggressively take up space */
    width: 100%;
    margin: 18px 0;
    overflow-y: auto;
    padding-right: 5px;
    min-height: 0; /* Important for flex-shrink/grow in some browsers */
}

#live-leaderboard-list::-webkit-scrollbar {
    width: 6px;
}

#live-leaderboard-list::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
}

#live-leaderboard-list::-webkit-scrollbar-thumb {
    background: var(--scrollbar-color);
    border-radius: 3px;
    box-shadow: 0 0 10px var(--scrollbar-color);
    filter: drop-shadow(0 0 5px var(--scrollbar-color)); /* Glow fallback */
}

#live-leaderboard-list::-webkit-scrollbar-thumb:hover {
    background: white;
    filter: drop-shadow(0 0 8px white);
}
.score-entry {
    font-size: 16px;
    transition: background 0.2s;
    padding: 10px 15px; /* Optimizing for 4-row stack */
    margin-bottom: 8px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    background: rgba(255,255,255,0.04);
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    gap: 2px; /* Tight vertical spacing */
    align-items: center; /* Center primary data */
    position: relative;
    overflow: visible !important; /* Fix for cut-off borders/glows */
    min-height: 110px;
    backface-visibility: hidden;
    transform: translateZ(0); /* Stabilize rendering against ghosting */
    will-change: transform, background;
}
.score-entry:hover {
    background: rgba(255,255,255,0.08);
}
.score-row-main {
    display: flex;
    flex-direction: row;
    align-items: baseline;
    gap: 8px; /* Reduced space before score/name as requested */
    width: 100%;
    margin-bottom: 2px;
}
.score-rank {
    align-self: flex-start; /* Anchored Top-Left */
    font-size: 10px;
    opacity: 0.8;
    font-family: 'Orbitron', sans-serif;
    margin-bottom: 0px;
}
.score-name {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 220px; 
    font-family: 'Orbitron', sans-serif;
    letter-spacing: 1px;
    font-size: 14px;
    margin-bottom: 2px;
}
.score-row-sub {
    display: flex;
    justify-content: space-between; /* Far Left / Far Right docking */
    align-items: center;
    font-size: 9px;
    margin-top: auto; /* Push metadata to absolute bottom of card */
    letter-spacing: 1px;
    width: 100%;
    padding-top: 0px;
}
.score-diff-label {
    text-transform: uppercase;
    font-weight: 700;
}
.score-value-bold {
    font-family: 'Orbitron', sans-serif;
    font-size: 26px; /* Increased for Row 2 emphasis */
    font-weight: 900;
    margin: 2px 0;
    filter: brightness(2.0);
}

/* TOP PLAYER EFFECTS - PREMIUM ACHIEVEMENT THEMES */
.top-1 .score-rank, .top-1 .score-value-bold, .top-1 .score-name, .top-1 .score-time-label, .top-1 .score-diff-label {
    color: #fff000 !important;
    text-shadow: 0 0 15px rgba(255, 240, 0, 0.6);
}
.top-1 {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.25), rgba(255, 215, 0, 0.05)) !important;
    border: 2px solid rgba(255, 215, 0, 0.8) !important;
    box-shadow: 0 0 30px rgba(255, 215, 0, 0.3), inset 0 0 15px rgba(255, 215, 0, 0.1) !important;
    transform: scale(1.03);
    margin: 15px 5px !important;
    z-index: 5;
    position: relative;
    overflow: visible !important;
}
.top-1::after {
    content: '';
    position: absolute;
    top: -2px; left: -2px; right: -2px; bottom: -2px;
    border-radius: 4px;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
    background-size: 200% 100%;
    animation: leaderboardShine 3s infinite linear, goldPulse 2s infinite alternate;
    pointer-events: none;
}
.top-1 .score-value-bold { font-size: 32px; letter-spacing: 2px; }

.top-2 .score-rank, .top-2 .score-value-bold, .top-2 .score-name, .top-2 .score-time-label, .top-2 .score-diff-label {
    color: #ffffff !important;
    text-shadow: 0 0 10px rgba(220, 220, 220, 0.5);
}
.top-2 {
    background: linear-gradient(135deg, rgba(200, 200, 200, 0.2), rgba(200, 200, 200, 0.05)) !important;
    border: 1px solid rgba(200, 200, 200, 0.6) !important;
    box-shadow: 0 0 20px rgba(200, 200, 200, 0.2) !important;
    transform: scale(1.01);
    margin: 10px 5px !important;
}
.top-2 .score-value-bold { font-size: 28px; }

.top-3 .score-rank, .top-3 .score-value-bold, .top-3 .score-name, .top-3 .score-time-label, .top-3 .score-diff-label {
    color: #FF8C00 !important;
    text-shadow: 0 0 10px rgba(255, 140, 0, 0.5);
    filter: brightness(1.2) !important;
}
.top-3 {
    background: linear-gradient(135deg, rgba(255, 140, 0, 0.15), rgba(255, 140, 0, 0.05)) !important;
    border: 1px solid rgba(255, 140, 0, 0.3) !important;
    box-shadow: 0 0 15px rgba(255, 140, 0, 0.15) !important;
    margin: 10px 5px !important;
}

.rank-medal {
    position: absolute;
    top: -12px;
    right: -5px;
    font-size: 28px;
    filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.4));
    z-index: 10;
}

@keyframes leaderboardShine {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

@keyframes goldPulse {
    from { box-shadow: 0 0 5px rgba(255, 240, 0, 0.1); }
    to { box-shadow: 0 0 20px rgba(255, 240, 0, 0.3); }
}
.stat-box {
    border-bottom: 1px solid #222;
    padding-bottom: 10px;
}
.stat-label {
    font-size: 12px;
    color: #888;
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.stat-value {
    font-family: 'Orbitron', sans-serif;
    font-size: 24px;
    color: #00ffff;
    text-shadow: 0 0 5px #00ffff;
    font-weight: 700;
}

#typo-value {
    color: #ff5555; 
    text-shadow: 0 0 5px #ff5555;
}
#wpm-value {
    color: #55ff55;
    text-shadow: 0 0 5px #55ff55;
}
#accuracy-value {
    color: #55ccff;
    text-shadow: 0 0 5px #55ccff;
}

#lives-value {
    display: flex;
    gap: 5px;
    font-size: 18px;
    transition: all 0.3s ease;
}

.integrity-heart {
    color: #ff3366;
    text-shadow: 0 0 10px #ff3366;
    display: inline-block;
    transition: color 0.3s, text-shadow 0.3s;
    font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", "Segoe UI Symbol", sans-serif !important;
}

.integrity-heart.empty {
    opacity: 0.15;
    color: #ffffff;
    text-shadow: none;
}

/* SHIELDED STATE */
.shielded-active .integrity-heart:not(.empty) {
    color: #00ffff !important;
    text-shadow: 0 0 15px #00ffff, 0 0 5px #fff !important;
}

/* LOW HEALTH PULSE */
.low-health-pulse {
    animation: heartPulse 1.5s infinite alternate ease-in-out;
}

@keyframes heartPulse {
    from { filter: brightness(1); transform: scale(1); }
    to { filter: brightness(1.8); transform: scale(1.05); text-shadow: 0 0 20px #ff0000; }
}

/* DAMAGE GLITCH EFFECT */
.is-damaged {
    animation: integrityDamage 0.5s step-end;
}

@keyframes integrityDamage {
    0%, 100% { background: rgba(255, 255, 255, 0.04); transform: translate(0,0); }
    10%, 30%, 50%, 70%, 90% { background: rgba(255, 0, 0, 0.2); transform: translate(2px, -2px); }
    20%, 40%, 60%, 80% { background: rgba(255, 0, 0, 0.1); transform: translate(-2px, 2px); }
}

:root {
    --scrollbar-color: #ffffff;
}

.terminal-header {
    font-size: 19px;
    padding-bottom: 10px;
    margin-bottom: 10px;
    text-align: center;
    border-bottom: 2px solid transparent; 
}

/* Modal Styles */
.modal {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    height: 100%;
    width: 100%;
    max-height: 800px;
    max-width: 1400px;
    background-color: rgba(0, 0, 0, 0.98);
    border: 2px solid #00ffcc;
    border-radius: 12px;
    box-shadow: 0 0 30px rgba(0, 255, 204, 0.3);
    z-index: 200;
    padding: 30px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}

.modal-content {
    width: 100%;
    text-align: left;
}

.modal-header {
    font-size: 28px;
    color: #00ffcc;
    border-bottom: 2px solid #00ffcc;
    margin-bottom: 20px;
    text-shadow: 0 0 10px #00ffcc;
}

.codex-flex-container {
    display: flex;
    gap: 30px;
    margin-bottom: 20px;
}

.codex-section {
    flex: 1;
}

.codex-section-header {
    font-size: 18px;
    border-bottom: 1px solid #444;
    padding-bottom: 5px;
    margin-bottom: 15px;
}

.codex-item {
    margin-bottom: 12px;
    line-height: 1;
    font-size: 16px;
}

.codex-label {
    font-weight: bold;
    margin-right: 8px;
    font-size: 16px;
}

.close-x-btn {
    position: absolute;
    top: 15px;
    right: 20px;
    background: transparent;
    color: #ff5555;
    border: none;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s, text-shadow 0.2s;
    padding: 0;
    margin: 0;
}

.close-x-btn:hover {
    color: #ff0000;
    text-shadow: 0 0 10px #ff0000;
}

#codex-btn {
    background: transparent;
    color: #00ffcc;
    border: 1px solid #00ffcc;
    padding: 8px;
    font-family: monospace;
    font-size: 12px;
    cursor: pointer;
    margin-top: 10px;
    width: 100%;
    text-transform: uppercase;
    transition: all 0.2s;
}

#codex-btn:hover {
    background: #00ffcc;
    color: black;
    box-shadow: 0 0 10px #00ffcc;
}

/* Difficulty Buttons */
.diff-btn {
    background: transparent;
    color: #00ffcc;
    border: 2px solid #00ffcc;
    padding: 10px 20px;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    min-width: 120px;
    letter-spacing: 2px;
}

.diff-btn:hover {
    background: rgba(0, 255, 204, 0.1);
    box-shadow: 0 0 15px rgba(0, 255, 204, 0.5);
    transform: translateY(-2px);
}

.diff-btn.active {
    background: #00ffcc;
    color: black;
    box-shadow: 0 0 20px #00ffcc;
    font-weight: bold;
}

.dev-notes-body {
    line-height: 1.4;
    font-size: 18px; 
    overflow-y: auto;
    max-height: 600px;
    padding-right: 18px;
}

.debug-info {
    font-size: 12px;
    color: #00ff00;
    background: rgba(0, 40, 0, 0.8);
    border: 1px solid #00ff00;
    padding: 8px;
    margin-bottom: 20px;
    text-shadow: 0 0 5px #00ff00;
    line-height: 1.4;
}

/* Sidebar Specifics */
#live-leaderboard-list {
    color: white;
    font-size: 16px;
    text-align: left;
    display: flex;
    flex-grow: 1; /* Match canvas height accurately */
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    padding-right: 5px;
}

#leaderboard-controls {
    margin-top: auto;
    padding-top: 15px;
    border-top: 1px solid #333;
    font-size: 12px;
    color: #888;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}

#idle-indicator {
    font-weight: bold;
    display: none;
}

/* Game Over Overlay Refinement */
#game-over-screen h1.terminal-header {
    color: #ff5555;
    text-shadow: 0 0 10px #ff5555;
    border: none;
    font-size: 48px;
    margin-bottom: 30px;
}

.final-score-container {
    font-size: 24px;
    color: #ff5555;
    margin: 20px 0;
}

#name-input-section {
    margin-top: 30px;
}

#name-input-section p {
    color: #ff5555;
    margin-bottom: 10px;
}

#player-initials {
    background: black;
    color: #00ffcc;
    border: 2px solid #00ffcc;
    font-size: 36px;
    width: 250px;
    text-align: center;
    text-transform: uppercase;
    font-family: monospace;
    outline: none;
    padding: 5px;
}

#submit-score-btn {
    display: block;
    margin: 20px auto;
    background: #00ffcc;
    color: black;
    border: none;
    padding: 10px 20px;
    font-family: monospace;
    font-size: 20px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s;
}

#submit-score-btn:hover {
    box-shadow: 0 0 15px #00ffcc;
    transform: scale(1.05);
}

#restart-section {
    margin-top: 20px;
}

#restart-section h2 {
    color: #ff5555;
}

#restart-btn {
    margin-top: 20px;
    background: #ff5555;
    color: black;
    border: none;
    padding: 10px 20px;
    font-family: monospace;
    font-size: 20px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s;
}

#restart-btn:hover {
    box-shadow: 0 0 15px #ff5555;
    transform: scale(1.05);
}

/* Stat Box Customizations */
#lives-value { color: #ff5555; text-shadow: 0 0 5px #ff5555; letter-spacing: 2px; }
#typo-value { color: #ff5555; text-shadow: 0 0 5px #ff5555; }
#difficulty-value { color: #00ff00; text-shadow: 0 0 5px #00ff00; }
#accuracy-value { color: #00ccff; text-shadow: 0 0 5px #00ccff; }
#letters-value { color: #ffaa00; text-shadow: 0 0 5px #ffaa00; }
#words-value { color: #cc55ff; text-shadow: 0 0 5px #cc55ff; }
#multiplier-value { color: #ffff55; text-shadow: 0 0 5px #ffff55; }
#next-boss-value { color: #ff55aa; text-shadow: 0 0 5px #ff55aa; }
#spawn-rate-value { color: #55ffff; text-shadow: 0 0 5px #55ffff; }

@keyframes pulse {
    0% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.98); }
    100% { opacity: 1; transform: scale(1); }
}

/* Scrollbar Styling - Corrected to remove faint cyan backgrounds */
#live-leaderboard-list::-webkit-scrollbar {
    width: 6px;
}

#live-leaderboard-list::-webkit-scrollbar-track {
    background: #000000; /* Strict black background to prevent bleed */
    border-radius: 10px;
}

#live-leaderboard-list::-webkit-scrollbar-thumb {
    background: var(--scrollbar-color, #ffffff);
    border-radius: 10px;
    box-shadow: 0 0 5px var(--scrollbar-color, #ffffff);
}

#live-leaderboard-list::-webkit-scrollbar-thumb:hover {
    background: #ffffff;
}

/* Sidebar Neutrality - Matches stats panel */
#leaderboard-sidebar {
    border-color: #333;
}

/* --- HARD-LOCKED DIFFICULTY COLORS FOR LEADERBOARD HEADER & DIVIDER --- */
#leaderboard-header{
    font-size: 19px;
}
#leaderboard-header.diff-ALL { color: var(--theme-color) !important; border-bottom-color: var(--theme-color) !important; text-shadow: 0 0 10px var(--theme-color) !important; }
#leaderboard-header.diff-EASY { color: #00ff00 !important; border-bottom-color: #00ff00 !important; text-shadow: 0 0 10px #00ff00 !important; }
#leaderboard-header.diff-NORMAL { color: #ffff55 !important; border-bottom-color: #ffff55 !important; text-shadow: 0 0 10px #ffff55 !important; }
#leaderboard-header.diff-HARD { color: #ff8800 !important; border-bottom-color: #ff8800 !important; text-shadow: 0 0 10px #ff8800 !important; }
#leaderboard-header.diff-ELITE { color: #ff0000 !important; border-bottom-color: #ff0000 !important; text-shadow: 0 0 10px #ff0000 !important; }
