:root {
    --bg-color: #111;
    --text-color: #eee;
    --highlight-color: #ffcc00;
    --font-main: 'Roboto Mono', monospace;
}

* { box-sizing: border-box; }

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-main);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    min-height: 100vh;
    margin: 0;
    overflow-x: hidden;
    padding-top: 50px;
    padding-bottom: 50px;
}

#game-ui {
    width: 900px;
    max-width: 95%;
    text-align: center;
    margin: 0 auto;
}

/* Header */
#header-bar {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 40px;
    padding-bottom: 15px;
    border-bottom: 2px solid #333;
    font-size: 16px;
    position: relative; /* Ensure z-index works */
    z-index: 50; /* Above scrolling words */
    background-color: var(--bg-color); /* Mask anything behind */
}

#header-left, #header-right { flex: 1; }
#header-left { text-align: left; }
#header-right { text-align: right; }

#header-center {
    flex: 2;
    display: flex;
    justify-content: center;
    gap: 30px;
}

.logo {
    font-size: 20px;
    font-weight: bold;
    color: #fff;
    white-space: nowrap;
}
.logo span { color: var(--highlight-color); }

.stat-item {
    color: #888;
    white-space: nowrap;
}
.stat-item span { color: var(--highlight-color); font-weight: bold; }

.setting-btn {
    background: transparent;
    color: #444;
    border: 1px solid transparent;
    padding: 5px 10px;
    cursor: pointer;
    font-family: var(--font-main);
    font-size: 14px;
    transition: all 0.2s;
    border-radius: 4px;
}
.setting-btn:hover { color: #888; border-color: #333; }
.setting-btn.active { color: var(--highlight-color); border-color: var(--highlight-color); }

/* Word Display */
#word-display-wrapper {
    width: 100%;
    height: 150px;
    overflow: hidden; /* Critical for clipping */
    position: relative;
    z-index: 10; /* Lower than header */
    background: #000;
    padding: 20px;
    border-radius: 8px;
    border: 1px solid #222;
    margin-bottom: 40px;
}

#word-display {
    text-align: left;
    font-size: 24px;
    line-height: 1.6;
    color: #444;
    transition: transform 0.2s ease-out;
}

.word {
    display: inline-block;
    margin-right: 15px;
    margin-bottom: 10px;
}

.letter { position: relative; }
.letter.correct { color: #eee; }
.letter.incorrect { color: #ff4444; }

.word.active .letter.active {
    background-color: rgba(255, 204, 0, 0.2);
    color: var(--highlight-color);
}
.word.active .letter.active::after {
    content: '';
    position: absolute;
    left: 0; bottom: 0; width: 100%; height: 3px;
    background: var(--highlight-color);
    animation: blink 1s infinite;
}
.word.incorrect-word {
    text-decoration: underline;
    text-decoration-color: #ff4444;
}
@keyframes blink { 50% { opacity: 0; } }

/* Keyboard */
#keyboard-container {
    display: inline-block;
    width: 100%;
    max-width: 800px;
    background: #000;
    padding: 20px;
    border-radius: 10px;
    border: 1px solid #222;
}

.kb-row {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-bottom: 6px;
}

.key {
    width: 40px; height: 40px;
    border: 1px solid #333;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #555;
    font-size: 12px;
    transition: all 0.1s;
    text-transform: uppercase;
}

.key.pressed {
    background: var(--highlight-color);
    color: #000;
    transform: scale(0.95);
    box-shadow: 0 0 10px var(--highlight-color);
    border-color: var(--highlight-color);
}

.key.backspace { width: 80px; }
.key.tab { width: 60px; }
.key.caps { width: 70px; }
.key.enter { width: 80px; }
.key.shift { width: 95px; }
.key.space { width: 250px; }

/* Leaderboard */
#leaderboard-section {
    width: 100%;
    margin-top: 50px;
    background: #1a1a1a;
    border-radius: 8px;
    padding: 20px;
    text-align: left;
}

.lb-title {
    color: var(--highlight-color);
    font-size: 20px;
    margin-bottom: 15px;
    border-bottom: 1px solid #333;
    padding-bottom: 10px;
}

#lb-table {
    width: 100%;
    border-collapse: collapse;
    color: #888;
}
#lb-table th {
    text-align: left; padding: 10px; border-bottom: 1px solid #333; color: #fff;
}
#lb-table td {
    padding: 10px; border-bottom: 1px solid #222;
}
#lb-table tr:first-child td { color: var(--highlight-color); }

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}
.modal-content {
    background: #1a1a1a;
    width: 90%; max-width: 500px;
    padding: 20px;
    border-radius: 8px;
    border: 1px solid #333;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
    color: #eee;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #333;
    padding-bottom: 10px;
    margin-bottom: 15px;
}
.modal-header h2 { margin: 0; font-size: 1.2rem; color: #ffcc00; }
.close-btn { cursor: pointer; font-size: 24px; color: #666; }
.close-btn:hover { color: #fff; }

.form-group { margin-bottom: 15px; }
.form-group label { display: block; margin-bottom: 5px; color: #888; font-size: 0.9rem; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    background: #222;
    border: 1px solid #444;
    color: #fff;
    padding: 8px;
    border-radius: 4px;
    font-family: inherit;
    box-sizing: border-box; /* Fix padding pushing width */
}
.form-group input:focus, .form-group textarea:focus {
    border-color: #ffcc00;
    outline: none;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}
.btn-cancel {
    background: transparent; border: 1px solid #444; color: #aaa; padding: 8px 15px; cursor: pointer; border-radius: 4px;
}
.btn-submit {
    background: #ffcc00; border: none; color: #111; padding: 8px 20px; font-weight: bold; cursor: pointer; border-radius: 4px;
}
.btn-submit:hover { background: #e6b800; }
#contrib-msg { margin-top: 10px; font-size: 0.9rem; }
.msg-success { color: #00ffcc; }
.msg-error { color: #ff3333; }

/* Footer */
#footer-instruction {
    margin-top: 30px;
    font-size: 14px;
    color: #444;
    cursor: pointer;
    animation: pulse 2s infinite;
}
#footer-instruction:hover { color: var(--highlight-color); }
@keyframes pulse { 0% { opacity: 0.5; } 50% { opacity: 1; } 100% { opacity: 0.5; } }

/* Misc */
#hidden-input { position: absolute; top: -1000px; opacity: 0; }
#overlay-message {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.9); z-index: 100;
    display: none; flex-direction: column;
    align-items: center; justify-content: center;
}
#restart-btn {
    margin-top: 20px; padding: 10px 30px;
    background: var(--highlight-color);
    border: none; font-weight: bold; font-size: 18px; cursor: pointer; color: #000;
    font-family: var(--font-main);
}
