:root {
    --bg-color: #0d0d0d;
    --text-color: #8a8f98;
    --input-bg: #1a1a1a;
    --border-color: #5a5f66;
    --glow: rgba(138, 143, 152, 0.3);
    --menu-bg: #000000;
    --focus-color: #5a9fd4;
    --leaderboard-bg: rgba(5, 5, 5, 0.95);
}

[data-theme="light"] {
    --bg-color: #f5f5f5;
    --text-color: #2d2d2d;
    --input-bg: #ffffff;
    --border-color: #888888;
    --glow: rgba(45, 45, 45, 0.15);
    --menu-bg: #e0e0e0;
    --focus-color: #2a7cc4;
    --leaderboard-bg: rgba(245, 245, 245, 0.95);
}

.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--text-color);
    color: var(--bg-color);
    padding: 8px 16px;
    z-index: 1000;
    text-decoration: none;
    font-weight: 600;
    transition: top 0.2s;
}

.skip-link:focus {
    top: 0;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

:focus-visible {
    outline: 2px solid var(--focus-color);
    outline-offset: 2px;
}

body {
    background-color: var(--bg-color);
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    transition: background-color 0.3s ease, color 0.3s ease;
}

body,
h1,
h2,
h3,
p {
    color: var(--text-color);
}

.top {
    display: flex;
    justify-content: space-between;
    padding: 15px 5px;
    position: relative;
}

#title h1 {
    font-size: 2rem;
    letter-spacing: 3px;
    text-transform: uppercase;
    opacity: 0.7;
    margin-left: 50%;
}

#score {
    position: absolute;
    top: 200px;
    right: 25%;
}

#score p {
    font-size: 1.2rem;
    font-weight: 600;
    color: #635028;
}

#level-display {
    position: absolute;
    top: 200px;
    left: 25%;
}

#level-display p {
    font-size: 1.2rem;
    font-weight: 600;
    color: #635028;
}

#timer-display {
    margin-bottom: 40px;
}

#timer-display span {
    font-size: 2rem;
    font-weight: 800;
    font-family: 'Nunito', sans-serif;
    letter-spacing: 2px;
    color: var(--text-color);
    transition: color 0.15s ease-out;
}

#score-value {
    color: #e6b514;
    display: inline-block;
}

#level-value {
    color: #e6b514;
    display: inline-block;
}

@keyframes slideUpOut {
    0% {
        opacity: 1;
        transform: translateY(0);
    }
    100% {
        opacity: 0;
        transform: translateY(-15px);
    }
}

@keyframes slideUpIn {
    0% {
        opacity: 0;
        transform: translateY(15px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

#score-value.anim-out {
    animation: slideUpOut 0.12s ease-out forwards;
}

#score-value.anim-in {
    animation: slideUpIn 0.15s ease-out forwards;
}

#level-value.anim-out {
    animation: slideUpOut 0.12s ease-out forwards;
}

#level-value.anim-in {
    animation: slideUpIn 0.15s ease-out forwards;
}

main {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
}

#number-display h2 {
    font-size: 10rem;
    margin: 20px 0;
    font-weight: 600;
    letter-spacing: 10px;
    text-shadow: 0 0 30px var(--glow);
}

#answer-input input {
    background-color: var(--input-bg);
    color: var(--text-color);
    border: 3px solid var(--border-color);
    border-radius: 8px;
    padding: 18px;
    font-size: 1.8rem;
    width: 220px;
    text-align: center;
    outline: none;
    transition: border-color 0.3s, box-shadow 0.3s, background-color 0.3s, color 0.3s;
    -moz-appearance: textfield;
}

#answer-input input::placeholder {
    color: var(--text-color);
    opacity: 0.5;
}

#answer-input input::-webkit-outer-spin-button,
#answer-input input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

#answer-input input:focus {
    border-color: var(--text-color);
    box-shadow: 0 0 15px var(--glow);
}

.bottom {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    padding: 10px;
    min-height: 150px;
}

#message p {
    font-size: 2rem;
    letter-spacing: 1px;
    margin: 0;
    line-height: 1;
}

#message {
    position: relative;
    top: -40px;
    font-size: 2rem;
}

#message.initial-message {
    position: absolute;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
}

#message.initial-message p {
    font-size: 4.8rem;
    font-weight: 600;
    letter-spacing: 2px;
}

#message.initial-message .timeout-hint {
    font-size: 1.5rem;
    font-weight: 400;
    opacity: 0.7;
}

.game-over {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(5, 5, 5, 0.95);
    border: 6px solid #cc3333;
    border-radius: 20px;
    padding: 60px 80px;
    text-align: center;
    font-family: 'VT323', monospace;
    z-index: 10;
}

.game-over h1 {
    font-size: 4rem;
    margin: 0;
    color: #cc3333;
    text-shadow: 0 0 20px rgba(204, 51, 51, 0.5);
    letter-spacing: 5px;
}

.game-over .final-score {
    font-size: 2rem;
    color: #ff9900;
    margin-top: 20px;
    font-family: 'VT323', monospace;
}

.game-over .timed-out {
    font-size: 2rem;
    color: #cc3333;
    margin-top: 10px;
    font-family: 'VT323', monospace;
    text-shadow: 0 0 10px rgba(204, 51, 51, 0.5);
}

.game-over .new-high-score {
    font-size: 2.5rem;
    margin-top: 20px;
    font-family: 'VT323', monospace;
    font-weight: bold;
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.game-over .pb-smashed {
    font-size: 2.5rem;
    margin-top: 20px;
    font-family: 'VT323', monospace;
    font-weight: bold;
    color: #ff9900;
    text-shadow: 0 0 15px rgba(255, 153, 0, 0.7);
    animation: shake 0.5s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px) rotate(-2deg); }
    75% { transform: translateX(5px) rotate(2deg); }
}

.game-over .pb-score {
    font-size: 1.5rem;
    margin-top: 10px;
    font-family: 'VT323', monospace;
    color: var(--text-color);
    opacity: 0.9;
}

.global-leaderboard {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: var(--leaderboard-bg);
    border: 6px solid #2a7cc4;
    border-radius: 20px;
    padding: 40px 60px;
    text-align: center;
    font-family: 'VT323', monospace;
    z-index: 10;
    max-height: 80vh;
    overflow-y: auto;
    visibility: hidden;
    transition: background-color 0.3s ease;
}

.global-leaderboard h2 {
    font-size: 2.5rem;
    margin: 0 0 20px 0;
    color: #ff9900;
    text-shadow: 0 0 10px rgba(255, 153, 0, 0.5);
    letter-spacing: 3px;
}

.lb-grid {
    display: grid;
    grid-template-columns: 40px 1fr 80px 70px 80px;
    gap: 10px;
    font-family: 'VT323', monospace;
    font-size: 1.4rem;
    color: var(--text-color);
    margin: 8px 0;
    text-align: left;
}

.lb-header {
    font-weight: bold;
    opacity: 0.7;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
    margin-bottom: 4px;
}

.lb-entry {
    display: grid;
    grid-template-columns: 40px 1fr 80px 70px 80px;
    gap: 10px;
    font-family: 'VT323', monospace;
    font-size: 1.4rem;
    color: var(--text-color);
    margin: 4px 0;
    text-align: left;
}

.lb-rank {
    text-align: center;
}

.lb-score {
    text-align: right;
}

.lb-level {
    text-align: center;
}

.lb-country {
    text-align: center;
    opacity: 0.6;
    font-size: 1rem;
}

.lb-entry.current-player {
    color: #9b59b6;
    font-weight: bold;
}

.lb-entry.new-high {
    color: #4caf50;
    font-weight: bold;
}

.leaderboard-nav {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 20px;
}

.lb-btn {
    background: none;
    border: 2px solid var(--border-color);
    color: var(--text-color);
    padding: 8px 16px;
    font-family: 'VT323', monospace;
    font-size: 1.2rem;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s;
}

.lb-btn:hover {
    background-color: var(--border-color);
    color: var(--bg-color);
}

.lb-close {
    margin-top: 20px;
    font-size: 1rem;
    opacity: 0.6;
}

.menu-link {
    display: block;
    color: var(--text-color);
    text-decoration: none;
    font-size: 1rem;
    padding: 14px 0;
    transition: color 0.2s ease, transform 0.2s ease, text-shadow 0.2s ease;
    cursor: pointer;
}

.menu-link:hover {
    color: var(--focus-color);
    transform: translateX(8px) scale(1.05);
    text-shadow: 0 0 12px var(--focus-color);
}

#menu-icon {
    position: absolute;
    top: 15px;
    right: 15px;
    cursor: pointer;
    color: var(--text-color);
    transition: all 1s ease;
    z-index: 100;
    background: none;
    border: none;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

#menu-icon:hover {
    transform: scale(1.1);
}

#menu-icon.open {
    right: calc(20% - 42px);
    transform: rotate(-540deg);
}

#slide-menu {
    position: fixed;
    top: 0;
    right: -20%;
    width: 20%;
    height: 100vh;
    background-color: var(--menu-bg);
    border-left: 2px solid var(--border-color);
    transition: right 0.3s ease, box-shadow 0.3s ease, background-color 0.3s ease;
    z-index: 99;
    padding: 60px 20px;
    box-sizing: border-box;
}

#slide-menu.open {
    right: 0;
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.5);
}

#start-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background-color: var(--bg-color);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    transition: opacity 0.4s ease, transform 0.4s ease;
}

#start-screen.hidden {
    opacity: 0;
    transform: scale(1.1);
    pointer-events: none;
}

#start-screen-content {
    text-align: center;
    padding: 40px;
}

#start-screen h1 {
    font-size: 3rem;
    letter-spacing: 4px;
    text-transform: uppercase;
    opacity: 0.8;
    margin-bottom: 40px;
}

#start-screen .start-instructions {
    font-size: 1.5rem;
    margin-bottom: 30px;
    opacity: 0.7;
}

#name-input {
    background-color: var(--input-bg);
    color: var(--text-color);
    border: 3px solid var(--border-color);
    border-radius: 8px;
    padding: 15px 25px;
    font-size: 1.5rem;
    width: 250px;
    text-align: center;
    outline: none;
    text-transform: uppercase;
    transition: border-color 0.3s, box-shadow 0.3s, background-color 0.3s, color 0.3s;
}

#name-input::placeholder {
    color: var(--text-color);
    opacity: 0.4;
    text-transform: none;
}

#name-input:focus {
    border-color: var(--text-color);
    box-shadow: 0 0 15px var(--glow);
}

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    margin-top: 25vh;
}

.theme-label {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-color);
    transition: color 0.2s ease, text-shadow 0.2s ease;
    cursor: pointer;
}

.theme-label:hover {
    color: var(--focus-color);
    text-shadow: 0 0 12px var(--focus-color);
}

.switch {
    position: relative;
    display: inline-block;
    width: 56px;
    height: 30px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #333;
    transition: 0.3s;
    border-radius: 30px;
    border: 2px solid var(--border-color);
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 2px;
    bottom: 2px;
    background-color: #f5f5f5;
    transition: 0.3s;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

input:checked+.slider {
    background-color: #4a4a4a;
}

input:checked+.slider:before {
    transform: translateX(26px);
    background-color: #ff9900;
}