@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;500;700&display=swap');

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'JetBrains Mono', monospace;
    background-color: #121214;
    color: #e2e8f0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    overflow-x: hidden;
}

header {
    background-color: #1a1a1e;
    border-bottom: 2px solid #2a2a30;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 15px;
}

.logo {
    height: 40px;
    width: auto;
    object-fit: contain;
}

header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: #00adb5;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 10px;
}

#user-profile-header {
    display: flex;
    align-items: center;
    gap: 15px;
}

.username-badge {
    background: #2a2a30;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.9rem;
    border: 1px solid #3e3e4a;
    display: flex;
    align-items: center;
    gap: 8px;
}

.username-badge::before {
    content: "●";
    color: #00e676;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { opacity: 0.4; }
    50% { opacity: 1; }
    100% { opacity: 0.4; }
}

.logout-btn {
    background: transparent;
    border: 1px solid #ff5252;
    color: #ff5252;
    padding: 0.4rem 0.8rem;
    border-radius: 4px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.8rem;
    transition: all 0.2s;
}

.logout-btn:hover {
    background: #ff5252;
    color: #fff;
}

main {
    flex: 1;
    display: flex;
    max-width: 1300px;
    width: 100%;
    margin: 0 auto;
    padding: 2rem;
    gap: 2rem;
}

/* Auth View */
#auth-view {
    max-width: 480px;
    margin: auto;
    padding: 2.5rem;
    background-color: #1a1a1e;
    border-radius: 12px;
    border: 1px solid #2a2a30;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

#auth-view h2 {
    color: #00adb5;
    font-size: 1.8rem;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    text-align: left;
}

.auth-form label {
    font-size: 0.9rem;
    color: #a0aec0;
}

.auth-form input[type="text"] {
    background-color: #121214;
    border: 2px solid #2a2a30;
    color: #fff;
    padding: 0.8rem 1rem;
    font-family: inherit;
    font-size: 1.1rem;
    border-radius: 6px;
    outline: none;
    transition: border-color 0.2s;
}

.auth-form input[type="text"]:focus {
    border-color: #00adb5;
}

.btn-primary {
    background-color: #00adb5;
    color: #121214;
    border: none;
    padding: 0.8rem 1.5rem;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 700;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-primary:hover {
    background-color: #00e676;
}

.error-message {
    color: #ff5252;
    font-size: 0.85rem;
    background: rgba(255, 82, 82, 0.1);
    padding: 0.6rem;
    border-radius: 4px;
    border-left: 3px solid #ff5252;
    display: none;
}

/* Game Area */
#game-view {
    display: none; /* toggled in JS */
    width: 100%;
}

.workspace-grid {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 2rem;
    width: 100%;
}

@media (max-width: 1000px) {
    .workspace-grid {
        grid-template-columns: 1fr;
    }
}

.game-card {
    background-color: #1a1a1e;
    border-radius: 12px;
    border: 1px solid #2a2a30;
    padding: 2.5rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 480px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.controls-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #2a2a30;
    padding-bottom: 1.5rem;
    margin-bottom: 1.5rem;
}

.lang-selector {
    display: flex;
    gap: 10px;
}

.lang-btn {
    background-color: #121214;
    border: 1px solid #3e3e4a;
    color: #a0aec0;
    padding: 0.5rem 1.2rem;
    border-radius: 6px;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.lang-btn.active {
    background-color: #00adb5;
    border-color: #00adb5;
    color: #121214;
    font-weight: 700;
}

.lang-btn:not(.active):hover {
    border-color: #a0aec0;
    color: #fff;
}

.timer-display {
    font-size: 2.2rem;
    font-weight: 700;
    color: #e2e8f0;
    font-variant-numeric: tabular-nums;
    background: #121214;
    padding: 0.2rem 1.2rem;
    border-radius: 8px;
    border: 1px solid #2a2a30;
    display: flex;
    align-items: center;
    gap: 10px;
}

.timer-display.warning {
    color: #ff5252;
    border-color: #ff5252;
}

.timer-display::before {
    content: "⏱";
    font-size: 1.5rem;
}

/* Typing Display box */
.typing-box {
    margin: auto 0;
    text-align: center;
    padding: 1.5rem 0;
}

.word-queue {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 12px;
    font-size: 1.8rem;
    line-height: 2.5rem;
    min-height: 120px;
    user-select: none;
}

.word-row {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: nowrap;
    gap: 15px;
    min-height: 2.5rem;
}

.word-queue .word {
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
    transition: all 0.15s ease-in-out;
}

.word-queue .word.completed {
    color: #a0aec0;
    text-decoration: line-through;
    opacity: 0.3;
}

.word-queue .word.current {
    font-size: 2.3rem;
    font-weight: 700;
    color: #ffffff;
    border-bottom: 3px solid #00adb5;
    background: rgba(0, 173, 181, 0.05);
}

.word-queue .word.current.error {
    color: #ff5252;
    border-bottom-color: #ff5252;
    background: rgba(255, 82, 82, 0.08);
}

.word-queue .word.upcoming {
    color: #ffffff;
}

/* Hidden but focused input */
.hidden-input {
    position: absolute;
    left: -9999px;
    opacity: 0;
}

.focus-banner {
    background: rgba(0, 173, 181, 0.1);
    color: #00adb5;
    border: 1px dashed #00adb5;
    padding: 0.8rem;
    border-radius: 6px;
    text-align: center;
    cursor: pointer;
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
    transition: all 0.2s;
    user-select: none;
}

.focus-banner:hover {
    background: rgba(0, 230, 118, 0.1);
    border-color: #00e676;
    color: #00e676;
}

/* Game Stats bottom-bar */
.game-stats-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid #2a2a30;
    padding-top: 1.5rem;
    margin-top: 1.5rem;
}

.stat-item {
    text-align: left;
}

.stat-item .label {
    font-size: 0.8rem;
    color: #718096;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-item .val {
    font-size: 1.8rem;
    font-weight: 700;
    color: #fff;
}

.btn-retry {
    background-color: #2a2a30;
    border: 1px solid #3e3e4a;
    color: #e2e8f0;
    padding: 0.8rem 1.5rem;
    font-family: inherit;
    font-weight: 700;
    font-size: 1rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-retry:hover {
    background-color: #ff5252;
    border-color: #ff5252;
    color: #fff;
}

/* Leaderboard Sidebar */
.leaderboard-card {
    background-color: #1a1a1e;
    border-radius: 12px;
    border: 1px solid #2a2a30;
    padding: 2rem;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    height: 100%;
}

.leaderboard-card h2 {
    color: #a0aec0;
    font-size: 1.2rem;
    font-weight: 700;
    border-bottom: 1px solid #2a2a30;
    padding-bottom: 1rem;
    margin-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.leaderboard-card h2::after {
    content: "LIVE";
    background-color: rgba(0, 230, 118, 0.1);
    color: #00e676;
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    border: 1px solid #00e676;
    animation: blink 2s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

.leaderboard-table-container {
    flex: 1;
    overflow-y: auto;
}

.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
}

.leaderboard-table th {
    text-align: left;
    font-size: 0.75rem;
    color: #718096;
    text-transform: uppercase;
    padding: 0.5rem 0.5rem 0.8rem;
    border-bottom: 1px solid #2a2a30;
}

.leaderboard-table td {
    padding: 0.8rem 0.5rem;
    border-bottom: 1px solid #1a1a1e;
    font-size: 0.95rem;
}

.leaderboard-table tr:hover td {
    background-color: rgba(255,255,255,0.02);
}

.rank-cell {
    font-weight: 700;
    width: 40px;
}

.rank-1 { color: #ffd700; } /* Gold */
.rank-2 { color: #c0c0c0; } /* Silver */
.rank-3 { color: #cd7f32; } /* Bronze */

.player-name-cell {
    font-weight: 500;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.player-name-cell.current-user {
    color: #00adb5;
    font-weight: 700;
}

.score-cell {
    font-weight: 700;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.lpm-cell {
    text-align: right;
    color: #718096;
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
}

.leaderboard-empty {
    text-align: center;
    color: #4e4e5a;
    padding: 3rem 0;
    font-style: italic;
    font-size: 0.9rem;
}

/* Finish overlay modal inside game card */
.finish-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(26, 26, 30, 0.98);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 1.5rem;
    padding: 2rem;
    border-radius: 12px;
    z-index: 10;
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.finish-overlay h3 {
    font-size: 2rem;
    color: #ff5252;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.finish-stats {
    display: flex;
    gap: 3rem;
    margin: 1rem 0;
}

.finish-stat-box {
    text-align: center;
}

.finish-stat-box .title {
    font-size: 0.85rem;
    color: #a0aec0;
    text-transform: uppercase;
}

.finish-stat-box .value {
    font-size: 3rem;
    font-weight: 700;
    color: #00adb5;
}

.finish-stat-box .value.record {
    color: #00e676;
    animation: bounce 0.6s ease infinite alternate;
}

@keyframes bounce {
    from { transform: translateY(0); }
    to { transform: translateY(-5px); }
}

.new-record-banner {
    color: #00e676;
    background: rgba(0, 230, 118, 0.1);
    border: 1px solid #00e676;
    padding: 0.5rem 2rem;
    border-radius: 20px;
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: 0.5px;
    animation: pulseBorder 1.5s infinite;
}

@keyframes pulseBorder {
    0% { box-shadow: 0 0 0 0 rgba(0, 230, 118, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(0, 230, 118, 0); }
    100% { box-shadow: 0 0 0 0 rgba(0, 230, 118, 0); }
}

footer {
    text-align: center;
    padding: 1.5rem;
    background-color: #121214;
    color: #4e4e5a;
    font-size: 0.8rem;
    border-top: 1px solid #1a1a1e;
    margin-top: auto;
}

footer a {
    color: #00adb5;
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

/* Utility layout helper */
.relative-container {
    position: relative;
    width: 100%;
}
