body {
    background-color: #121212;
    color: #e0e0e0;
    font-family: 'Comic Sans MS', cursive, sans-serif;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    margin: 0;
    font-size: 16px;
    image-rendering: auto;
    overflow-x: hidden;
}

#game-container {
    width: 100%;
    max-width: 1200px;
    padding: 20px;
    text-align: center;
}

header h1 {
    font-family: 'Silkscreen', sans-serif;
    font-size: 3rem;
    color: #8a2be2;
    text-shadow: 0 0 8px rgba(138, 43, 226, 0.7);
    margin-bottom: 0;
}

header p {
    color: #bbbbbb;
    font-size: 1rem;
    margin-top: 5px;
}

#game-stats {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-top: 20px;
    flex-wrap: wrap;
}

.stat-item {
    font-size: 0.9rem;
    color: #bbb;
}

.stat-item span {
    color: #3498db;
}

#controls-container {
    margin-top: 30px;
    margin-bottom: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

#username-input {
    background-color: #2a2a2a;
    border: 1px solid #444;
    color: #eee;
    font-family: 'Comic Sans MS', cursive, sans-serif;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.9rem;
    width: 200px;
}

#username-input::placeholder {
    color: #888;
}

#controls-container button {
    background-color: #3498db;
    color: #fff;
    border: none;
    padding: 10px 15px;
    font-family: 'Comic Sans MS', cursive, sans-serif;
    cursor: pointer;
    border-radius: 6px;
    border-bottom: none;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

#controls-container button:hover {
    background-color: #4ca9e4;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

#controls-container button:active {
    transform: translateY(1px);
    border-bottom-width: 0;
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

main {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    margin-top: 40px;
    align-items: flex-start;
    justify-content: center;
}

#typing-display-container {
    width: 100%;
    background-color: #1a1a1a;
    border: 1px solid #444;
    border-radius: 6px;
    padding: 10px 15px;
    font-size: 1.5rem;
    height: 40px;
    line-height: 40px;
    margin-bottom: 20px;
    box-sizing: border-box;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    position: relative;
    color: #e0e0e0;
    font-family: 'Silkscreen', sans-serif;
}

#typing-display {
    display: inline-block;
    vertical-align: middle;
}

.cursor {
    display: inline-block;
    vertical-align: middle;
    animation: blink 1s step-end infinite;
    margin-left: 2px;
    color: #3498db;
}

@keyframes blink {
    from, to { color: transparent; }
    50% { color: #3498db; }
}

#keyboard-container {
    padding: 15px;
    background-color: #1c1c1c;
    border-radius: 8px;
    border: 1px solid #333;
    display: inline-block;
    flex-shrink: 0;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

.keyboard-row {
    display: flex;
    justify-content: center;
    margin-bottom: 5px;
}

.key {
    background-color: #444;
    border: 1px solid #333;
    border-bottom: 2px solid #333;
    border-radius: 6px;
    padding: 12px;
    margin: 0 4px;
    font-size: 12px;
    min-width: 25px;
    height: 25px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.1s ease-out;
    user-select: none;
    color: #fff;
    white-space: pre;
    font-family: 'Comic Sans MS', sans-serif;
}

.key.pressed {
    transform: translateY(1px);
    border-bottom-width: 1px;
    background-color: #555;
}

.key.unlocked {
    background-color: #3498db;
    color: #fff;
    border-color: #2980b9;
    text-shadow: 0 0 5px #fff;
}

/* Special key sizes */
.key[data-key="Backspace"], .key[data-key="Tab"], .key[data-key="CapsLock"], .key[data-key="Enter"], .key[data-key="ShiftLeft"], .key[data-key="ShiftRight"] {
    flex-grow: 1;
}
.key[data-key="Space"] {
    flex-grow: 5;
}

#achievements-container, #leaderboard-container, #chat-container, #minigames-container {
    background-color: #1c1c1c;
    border: 1px solid #333;
    border-radius: 8px;
    padding: 20px;
    width: 100%;
    max-width: 400px;
    text-align: left;
    flex-grow: 1;
    flex-basis: 350px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

#achievements-container h2, #leaderboard-container h2, #chat-container h2, #minigames-container h2 {
    margin-top: 0;
    color: #8a2be2;
    border-bottom: 1px solid #444;
    padding-bottom: 10px;
    font-family: 'Silkscreen', sans-serif;
}

.progress-text {
    font-size: 0.9rem;
    color: #ccc;
    margin-bottom: 20px;
}

#achievement-list, #leaderboard-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 400px;
    overflow-y: auto;
    flex-grow: 1;
}

#chat-messages {
    list-style: none;
    padding: 0;
    margin: 0;
    flex-grow: 1;
    overflow-y: auto;
    max-height: 350px;
}

.chat-message {
    padding: 8px 4px;
    font-size: 0.9rem;
    word-break: break-word;
}

.chat-message:not(:last-child) {
    border-bottom: 1px solid #2a2a2a;
}

.chat-message-user {
    color: #3498db;
    font-weight: bold;
    margin-right: 5px;
}

.chat-message-text {
    color: #eee;
}

#chat-form {
    display: flex;
    margin-top: 10px;
    flex-shrink: 0;
}

#chat-input {
    flex-grow: 1;
    background-color: #2a2a2a;
    border: 1px solid #444;
    color: #eee;
    font-family: 'Comic Sans MS', cursive, sans-serif;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.9rem;
    margin-right: 10px;
}

#chat-form button {
    background-color: #8a2be2;
    color: #fff;
    border: none;
    padding: 10px 15px;
    font-family: 'Comic Sans MS', cursive, sans-serif;
    cursor: pointer;
    border-radius: 6px;
    border-bottom: none;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    flex-shrink: 0;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

#chat-form button:hover {
    background-color: #993be2;
    transform: translateY(-1px);
}

#chat-form button:active {
    transform: translateY(1px);
    border-bottom-width: 0;
}

.achievement-item {
    background-color: #2a2a2a;
    padding: 12px;
    margin-bottom: 8px;
    border-radius: 6px;
    opacity: 0.6;
    transition: all 0.3s ease;
    border-left: 5px solid #555;
}

.achievement-item.unlocked {
    opacity: 1;
    border-left: 5px solid #3498db;
    background-color: #333;
}

.achievement-item.unlocked.rare {
    border-left-color: #ffd700;
    box-shadow: 0 0 10px -2px #ffd700;
}

.achievement-item h3 {
    margin: 0 0 5px 0;
    font-size: 1rem;
    color: #eee;
    font-family: 'Silkscreen', sans-serif;
}
.achievement-item.unlocked h3 {
    color: #3498db;
}

.achievement-item.unlocked.rare h3 {
    color: #ffd700;
}

.achievement-item p {
    margin: 0;
    font-size: 0.8rem;
    color: #aaa;
}

.leaderboard-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 5px;
    font-size: 1rem;
}

.leaderboard-item:not(:last-child) {
    border-bottom: 1px dashed #444;
}

.leaderboard-item .name {
    color: #eee;
}

.leaderboard-item .score {
    color: #3498db;
    font-weight: bold;
}

.leaderboard-item.player {
    background-color: rgba(52, 152, 219, 0.1);
    border-radius: 4px;
}

.leaderboard-item.player .name, .leaderboard-item.player .score {
    color: #fff;
    text-shadow: 0 0 5px #fff;
}

#leaderboard-container button {
    margin-top: 15px;
    background-color: #3498db;
    color: #fff;
    border: none;
    padding: 10px 15px;
    font-family: 'Comic Sans MS', cursive, sans-serif;
    cursor: pointer;
    border-radius: 6px;
    border-bottom: none;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    flex-shrink: 0;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

#leaderboard-container button:hover {
    background-color: #4ca9e4;
    transform: translateY(-1px);
}

#leaderboard-container button:active {
    transform: translateY(1px);
    border-bottom-width: 0;
}

/* Toast Notifications */
#toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    width: 350px;
}

.toast {
    background: #2c2c2e;
    color: #fff;
    border-radius: 12px;
    margin-top: 15px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
    animation: slideIn 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94), fadeOut 0.5s ease 5.5s forwards;
    border: 1px solid #444;
    overflow: hidden;
    font-family: 'Comic Sans MS', sans-serif;
    padding: 12px;
}

.toast.rare {
    border-color: #ffd700;
    box-shadow: 0 5px 20px rgba(255, 215, 0, 0.3), inset 0 0 0 1px rgba(255, 215, 0, 0.5);
}

.toast-header {
    display: flex;
    align-items: center;
    padding-bottom: 8px;
    border-bottom: 1px solid #444;
    margin-bottom: 8px;
}

.toast-icon {
    width: 24px;
    height: 24px;
    margin-right: 10px;
    image-rendering: auto;
    flex-shrink: 0;
}

.toast.rare .toast-icon {
    filter: drop-shadow(0 0 3px #ffd700);
}

.toast-title {
    font-weight: bold;
    font-family: 'Silkscreen', sans-serif;
    font-size: 0.9rem;
    color: #3498db;
    flex-grow: 1;
}

.toast.rare .toast-title {
    color: #ffd700;
}

.toast-number {
    font-size: 0.75rem;
    color: #aaa;
    background-color: #1c1c1e;
    padding: 2px 6px;
    border-radius: 6px;
    font-weight: bold;
}

.toast-body h4 {
    margin: 0 0 4px 0;
    font-size: 1rem;
    color: #f0f0f0;
    font-weight: bold;
    font-family: 'Silkscreen', sans-serif;
}

.toast-body p {
    margin: 0;
    font-size: 0.85rem;
    color: #ccc;
    line-height: 1.4;
}

@keyframes slideIn {
    from {
        transform: translateX(120%);
    }
    to {
        transform: translateX(0);
    }
}

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

#made-by-text {
    position: fixed;
    bottom: 10px;
    right: 20px;
    font-size: 0.7rem;
    color: #888;
    z-index: 999;
}

.popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    padding: 20px;
    box-sizing: border-box;
    backdrop-filter: blur(5px);
}

.popup-overlay.hidden {
    display: none;
}

.popup-content {
    background-color: #1c1c1c;
    border: 1px solid #333;
    border-radius: 8px;
    padding: 20px 40px 30px 40px;
    max-width: 90vw;
    max-height: 90vh;
    text-align: center;
    position: relative;
    color: #eee;
    overflow-y: auto;
    box-shadow: 0 5px 20px rgba(0,0,0,0.4);
}

.popup-content h3 {
    margin-top: 0;
    color: #8a2be2;
    font-size: 1.8rem;
    font-family: 'Silkscreen', sans-serif;
}

.popup-content p {
    font-size: 1rem;
    margin-bottom: 20px;
    color: #ccc;
    max-width: 45ch;
}

.popup-content img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    border: 1px solid #444;
}

.popup-close {
    position: absolute;
    top: 5px;
    right: 15px;
    background: none;
    border: none;
    color: #888;
    font-size: 2rem;
    cursor: pointer;
    font-family: Arial, sans-serif;
    line-height: 1;
}

.popup-close:hover {
    color: #fff;
}

#horror-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: #000;
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 3s ease-in-out;
}

#horror-overlay.fade-in {
    opacity: 1;
}

#horror-overlay.fade-out {
    transition-duration: 2s;
    opacity: 0;
}

#horror-video {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

#twitch-image {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 9998;
    width: 150px;
    height: auto;
    border: 3px solid #111;
}

#twitch-image.twitch {
    animation: twitch 0.1s infinite;
}

@keyframes twitch {
    0% { transform: translate(0, 0) rotate(0deg); }
    25% { transform: translate(-3px, 3px) rotate(-1deg); }
    50% { transform: translate(3px, -3px) rotate(1deg); }
    75% { transform: translate(3px, 3px) rotate(-1deg); }
    100% { transform: translate(-3px, -3px) rotate(1deg); }
}

#device-options {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 20px;
    flex-wrap: wrap;
}

.arrow-key-row {
    margin-top: 10px;
    display: grid;
    grid-template-areas: ". up ." "left down right";
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 5px;
    width: 150px; /* Adjust size as needed */
    margin-left: auto;
    margin-right: auto;
}

.arrow-key-row .key {
    margin: 0 !important;
    padding: 15px !important;
    font-size: 1.2rem;
}

.arrow-key-row .key[data-key="ArrowUp"] { grid-area: up; }
.arrow-key-row .key[data-key="ArrowLeft"] { grid-area: left; }
.arrow-key-row .key[data-key="ArrowDown"] { grid-area: down; }
.arrow-key-row .key[data-key="ArrowRight"] { grid-area: right; }

#device-options button {
    background-color: #3498db;
    color: #fff;
    border: none;
    padding: 15px 25px;
    font-family: 'Comic Sans MS', cursive, sans-serif;
    cursor: pointer;
    border-radius: 6px;
    border-bottom: none;
    font-size: 1rem;
    transition: all 0.2s ease;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

#device-options button:hover {
    background-color: #4ca9e4;
    transform: translateY(-2px);
}

#device-options button:active {
    transform: translateY(1px);
    border-bottom-width: 0;
}

.hidden {
    display: none !important;
}

/* Typing Test Styles */
#minigame-content h4 {
    margin-top: 0;
    font-size: 1.2rem;
    color: #e0e0e0;
    font-family: 'Silkscreen', sans-serif;
}
#typing-test-text-display {
    background-color: #1c1c1c;
    border: 1px solid #444;
    padding: 10px;
    border-radius: 4px;
    margin: 10px 0;
    font-size: 1.1rem;
    letter-spacing: 1px;
    user-select: none;
}
#typing-test-text-display span.correct { color: #2ecc71; }
#typing-test-text-display span.incorrect { color: #e74c3c; background-color: rgba(231, 76, 60, 0.2); }

#typing-test-input {
    width: 100%;
    padding: 10px;
    font-size: 1.1rem;
    background-color: #1c1c1c;
    border: 1px solid #555;
    color: #fff;
    border-radius: 4px;
    font-family: 'Comic Sans MS', cursive, sans-serif;
}
#typing-test-input:focus {
    outline: none;
    border-color: #3498db;
}
#typing-test-results {
    margin-top: 15px;
}
#typing-test-results p { margin: 5px 0; }
#typing-test-results strong { color: #3498db; }

/* Reaction Test Styles */
#reaction-box {
    width: 100%;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    transition: background-color 0.2s;
    user-select: none;
}
#reaction-box.waiting { background-color: #e74c3c; }
#reaction-box.ready { background-color: #2ecc71; }
#reaction-box.fail { background-color: #f39c12; cursor: default; }
#reaction-box.finished { background-color: #3498db; cursor: default; }
#reaction-box p {
    font-size: 1.2rem;
    font-weight: bold;
    margin: 0;
}
#reaction-result {
    font-size: 1.5rem;
    margin-top: 10px !important;
    font-family: 'Silkscreen', sans-serif;
}

.minigame-reset-btn {
    margin-top: 15px;
    background-color: #8a2be2;
    color: #fff;
    border: none;
    padding: 10px 20px;
    font-family: 'Comic Sans MS', cursive, sans-serif;
    cursor: pointer;
    border-radius: 6px;
    font-size: 0.9rem;
    transition: background-color 0.2s ease;
}
.minigame-reset-btn.hidden { display: none; }
.minigame-reset-btn:hover { background-color: #993be2; }