* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg: #06030f;
    --bg-deep: #02010a;
    --panel: rgba(14, 10, 30, 0.82);
    --panel-strong: rgba(20, 14, 42, 0.94);
    --line: rgba(0, 255, 255, 0.18);
    --primary: #00f5ff;
    --primary-dark: #00a8ff;
    --secondary: #ff2bd6;
    --accent: #ffe45e;
    --success: #3cff8f;
    --danger: #ff4d6d;
    --text: #f6f6ff;
    --text-muted: #a9a2c4;
    --player1: #00f5ff;
    --player2: #ff2bd6;
    --glow-primary: 0 0 24px rgba(0, 245, 255, 0.38);
    --glow-secondary: 0 0 24px rgba(255, 43, 214, 0.32);
    --shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
}

body {
    position: relative;
    font-family: "Bahnschrift", "Trebuchet MS", "Segoe UI", sans-serif;
    background:
        radial-gradient(circle at top left, rgba(0, 245, 255, 0.14), transparent 30%),
        radial-gradient(circle at top right, rgba(255, 43, 214, 0.14), transparent 34%),
        radial-gradient(circle at bottom center, rgba(255, 228, 94, 0.08), transparent 42%),
        linear-gradient(145deg, var(--bg) 0%, #090415 48%, var(--bg-deep) 100%);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
    user-select: none;
}

body::before,
body::after {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
}

body::before {
    background:
        linear-gradient(90deg, transparent 0, rgba(0, 245, 255, 0.07) 48%, transparent 52%),
        linear-gradient(180deg, rgba(255, 255, 255, 0.04) 0, transparent 2px);
    background-size: 100% 100%, 100% 6px;
    opacity: 0.45;
}

body::after {
    background:
        linear-gradient(120deg, transparent 0 32%, rgba(0, 245, 255, 0.05) 50%, transparent 68%),
        linear-gradient(300deg, transparent 0 40%, rgba(255, 43, 214, 0.06) 60%, transparent 100%);
    mix-blend-mode: screen;
}

#app {
    position: relative;
    max-width: 1200px;
    margin: 0 auto;
    padding: 32px 20px 24px;
    min-height: 100vh;
}

#connection-status {
    position: fixed;
    top: 14px;
    right: 14px;
    padding: 8px 14px;
    border: 1px solid var(--line);
    border-radius: 999px;
    font-size: 0.85rem;
    background: rgba(7, 8, 20, 0.88);
    backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 100;
    box-shadow: var(--glow-primary);
}

#status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 12px currentColor;
}

#connection-status.status-offline #status-dot {
    background: var(--danger);
}

#connection-status.status-offline {
    color: var(--danger);
    box-shadow: 0 0 18px rgba(255, 77, 109, 0.28);
}

#queue-info {
    color: var(--accent);
    font-weight: 700;
}

.screen {
    display: none;
    animation: fadeIn 0.45s ease;
}

.screen.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#screen-intro,
#screen-result,
#screen-leaderboard {
    position: relative;
    text-align: center;
    padding: 40px 20px;
}

h1,
#screen-result h2,
#screen-leaderboard h2 {
    font-family: "Bahnschrift", "Arial Narrow", sans-serif;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

h1 {
    font-size: clamp(2.9rem, 7vw, 5rem);
    margin-bottom: 12px;
    color: transparent;
    background: linear-gradient(90deg, var(--primary) 0%, var(--accent) 45%, var(--secondary) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    text-shadow: 0 0 26px rgba(0, 245, 255, 0.22);
}

.subtitle {
    color: var(--text-muted);
    font-size: 1.05rem;
    text-transform: uppercase;
    letter-spacing: 0.28em;
    margin-bottom: 32px;
}

.rules,
.hud,
.result-time,
#leaderboard-content,
.player-side {
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent 36%),
        var(--panel);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    backdrop-filter: blur(14px);
}

.rules {
    position: relative;
    padding: 28px;
    border-radius: 22px;
    max-width: 660px;
    margin: 0 auto 30px;
    text-align: left;
}

.rules::before,
.result-time::before,
#leaderboard-content::before {
    content: "";
    position: absolute;
    inset: 1px;
    border-radius: inherit;
    border: 1px solid rgba(255, 255, 255, 0.04);
    pointer-events: none;
}

.rules h3 {
    margin-bottom: 16px;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.16em;
}

.rules ul {
    list-style: none;
}

.rules li {
    padding: 10px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    color: #e7e1ff;
}

.rules li:last-child {
    border-bottom: none;
}

form#form-names {
    max-width: 420px;
    margin: 0 auto 15px;
}

.mode-picker {
    max-width: 760px;
    margin: 0 auto 28px;
    padding: 22px;
    border-radius: 22px;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent 36%),
        rgba(10, 8, 24, 0.9);
    border: 1px solid rgba(255, 43, 214, 0.18);
    box-shadow: var(--shadow);
}

.mode-picker-title,
.mode-option-title {
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

.mode-picker-title {
    color: var(--secondary);
    font-size: 0.9rem;
    margin-bottom: 14px;
}

.mode-options {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.mode-option {
    display: block;
    padding: 18px;
    border-radius: 18px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(13, 10, 28, 0.85);
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.mode-option:hover {
    transform: translateY(-2px);
    border-color: rgba(0, 245, 255, 0.24);
}

.mode-option.active {
    border-color: rgba(0, 245, 255, 0.42);
    background: rgba(0, 245, 255, 0.08);
    box-shadow: 0 0 28px rgba(0, 245, 255, 0.18);
}

.mode-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.mode-option-title {
    display: block;
    color: var(--text);
    font-weight: 700;
    margin-bottom: 8px;
}

.mode-option-text,
.mode-description,
.mode-caption {
    color: var(--text-muted);
}

.mode-option-text {
    display: block;
    line-height: 1.5;
    font-size: 0.95rem;
}

.mode-description {
    margin-top: 14px;
    font-size: 0.95rem;
}

form label {
    display: block;
    margin-bottom: 15px;
    text-align: left;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.88rem;
}

form input {
    width: 100%;
    padding: 14px 16px;
    margin-top: 8px;
    border-radius: 14px;
    border: 1px solid rgba(0, 245, 255, 0.26);
    background: rgba(8, 9, 22, 0.9);
    color: var(--text);
    font-size: 1rem;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}

form input::placeholder {
    color: rgba(169, 162, 196, 0.72);
}

form input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(0, 245, 255, 0.12), var(--glow-primary);
}

.btn-primary,
.btn-secondary {
    padding: 13px 30px;
    border-radius: 14px;
    font-size: 0.96rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease, background 0.18s ease;
    margin: 8px 5px;
}

.btn-primary {
    border: 1px solid rgba(0, 245, 255, 0.4);
    color: #061018;
    background: linear-gradient(135deg, var(--primary), #7cfbff 55%, var(--accent));
    box-shadow: 0 14px 34px rgba(0, 245, 255, 0.24);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 18px 40px rgba(0, 245, 255, 0.32);
}

.btn-secondary {
    border: 1px solid rgba(255, 43, 214, 0.38);
    color: var(--secondary);
    background: rgba(17, 9, 33, 0.9);
    box-shadow: 0 12px 28px rgba(255, 43, 214, 0.16);
}

.btn-secondary:hover {
    transform: translateY(-2px);
    background: rgba(255, 43, 214, 0.12);
    box-shadow: 0 18px 36px rgba(255, 43, 214, 0.24);
}

.hud {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 24px;
    border-radius: 18px;
    margin-bottom: 22px;
    font-size: 1.3rem;
}

.hud-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 110px;
}

.hud-label {
    font-size: 0.76rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.2em;
}

#packets {
    color: var(--accent);
    font-weight: 700;
}

#timer {
    color: var(--primary);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    text-shadow: 0 0 18px rgba(0, 245, 255, 0.3);
}

#mode-label {
    color: var(--secondary);
    font-weight: 700;
}

#score {
    color: var(--accent);
    font-weight: 800;
    text-shadow: 0 0 18px rgba(255, 228, 94, 0.24);
}

#streak {
    color: var(--success);
    font-weight: 800;
    text-shadow: 0 0 18px rgba(60, 255, 143, 0.24);
}

.mode-banner {
    margin-bottom: 18px;
    padding: 14px 18px;
    border-radius: 16px;
    background: rgba(255, 43, 214, 0.12);
    border: 1px solid rgba(255, 43, 214, 0.22);
    color: #ffd7f6;
    text-align: center;
    letter-spacing: 0.04em;
    box-shadow: 0 0 24px rgba(255, 43, 214, 0.12);
}

.game-area {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 22px;
    min-height: 430px;
    align-items: center;
}

.player-side {
    border-radius: 24px;
    padding: 34px 28px;
    text-align: center;
    border: 1px solid transparent;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease, background 0.2s ease;
    min-height: 360px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.player-side::before {
    content: "";
    position: absolute;
    inset: auto -20% 16% -20%;
    height: 1px;
    background: linear-gradient(90deg, transparent, currentColor, transparent);
    opacity: 0.3;
}

.player-left {
    color: var(--player1);
    border-color: rgba(0, 245, 255, 0.34);
    box-shadow: var(--shadow), var(--glow-primary);
}

.player-right {
    color: var(--player2);
    border-color: rgba(255, 43, 214, 0.3);
    box-shadow: var(--shadow), var(--glow-secondary);
}

.player-label {
    font-size: 0.88rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.28em;
    margin-bottom: 12px;
}

.player-left .player-label {
    color: var(--player1);
}

.player-right .player-label {
    color: var(--player2);
}

.letter {
    font-size: clamp(5rem, 16vw, 8.5rem);
    font-weight: 800;
    margin: 18px 0;
    font-family: "Consolas", "Lucida Console", monospace;
    text-shadow: 0 0 16px currentColor, 0 0 40px currentColor;
}

.player-key-hint {
    color: var(--text-muted);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

.player-side.pressed {
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent 40%),
        rgba(22, 56, 51, 0.72);
    border-color: rgba(60, 255, 143, 0.44);
    box-shadow: var(--shadow), 0 0 32px rgba(60, 255, 143, 0.24);
    transform: scale(0.985);
}

.player-side.success {
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.05), transparent 42%),
        rgba(15, 70, 38, 0.72);
    border-color: rgba(60, 255, 143, 0.56);
    animation: successFlash 0.4s;
}

.player-side.error {
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent 40%),
        rgba(66, 12, 30, 0.78);
    border-color: rgba(255, 77, 109, 0.56);
    animation: errorShake 0.4s;
}

@keyframes successFlash {
    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.03);
    }
}

@keyframes errorShake {
    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-8px);
    }

    75% {
        transform: translateX(8px);
    }
}

.link-line {
    width: 120px;
    height: 6px;
    background: linear-gradient(90deg, rgba(0, 245, 255, 0.14), rgba(255, 43, 214, 0.14));
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 999px;
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 0 16px rgba(0, 0, 0, 0.45), 0 0 24px rgba(0, 245, 255, 0.12);
}

.link-pulse {
    position: absolute;
    top: -1px;
    left: -28%;
    width: 28%;
    height: calc(100% + 2px);
    background: linear-gradient(90deg, transparent, var(--primary), var(--secondary), transparent);
    filter: blur(0.3px);
    animation: pulse 1.35s infinite;
}

@keyframes pulse {
    0% {
        left: -28%;
    }

    100% {
        left: 100%;
    }
}

.link-line.success {
    box-shadow: inset 0 0 16px rgba(0, 0, 0, 0.45), 0 0 24px rgba(60, 255, 143, 0.35);
}

.link-line.success .link-pulse {
    background: linear-gradient(90deg, transparent, var(--success), transparent);
    animation-duration: 0.45s;
}

.link-line.error {
    box-shadow: inset 0 0 16px rgba(0, 0, 0, 0.45), 0 0 24px rgba(255, 77, 109, 0.28);
}

.link-line.error .link-pulse {
    background: linear-gradient(90deg, transparent, var(--danger), transparent);
    animation-duration: 0.6s;
}

.game-message {
    text-align: center;
    margin-top: 20px;
    min-height: 40px;
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.game-message.success {
    color: var(--success);
    text-shadow: 0 0 14px rgba(60, 255, 143, 0.34);
}

.game-message.error {
    color: var(--danger);
    text-shadow: 0 0 14px rgba(255, 77, 109, 0.28);
}

#screen-result h2,
#screen-leaderboard h2 {
    margin-bottom: 30px;
    font-size: clamp(1.9rem, 5vw, 3rem);
}

.mode-caption {
    margin: -14px 0 24px;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    font-size: 0.84rem;
}

.leaderboard-switch {
    display: inline-flex;
    gap: 10px;
    margin-bottom: 10px;
    padding: 8px;
    border-radius: 18px;
    background: rgba(12, 10, 24, 0.72);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: var(--shadow);
}

.leaderboard-tab {
    min-width: 140px;
    padding: 10px 18px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-muted);
    font: inherit;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease, color 0.18s ease, background 0.18s ease;
}

.leaderboard-tab:hover {
    transform: translateY(-1px);
    border-color: rgba(0, 245, 255, 0.2);
    color: var(--text);
}

.leaderboard-tab.active {
    color: #061018;
    background: linear-gradient(135deg, var(--primary), #7cfbff 55%, var(--accent));
    border-color: rgba(0, 245, 255, 0.4);
    box-shadow: 0 12px 28px rgba(0, 245, 255, 0.24);
}

.result-time {
    position: relative;
    padding: 40px;
    border-radius: 22px;
    max-width: 440px;
    margin: 0 auto 20px;
}

#result-time-value {
    font-size: clamp(3rem, 8vw, 4.6rem);
    font-weight: 800;
    color: var(--primary);
    font-variant-numeric: tabular-nums;
    margin-top: 12px;
    text-shadow: 0 0 24px rgba(0, 245, 255, 0.38);
}

.sync-status {
    margin: 20px auto;
    padding: 13px 14px;
    border-radius: 14px;
    max-width: 420px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(12, 10, 24, 0.7);
}

.sync-status.synced {
    background: rgba(11, 63, 35, 0.5);
    color: var(--success);
    border-color: rgba(60, 255, 143, 0.28);
}

.sync-status.queued {
    background: rgba(78, 59, 10, 0.42);
    color: var(--accent);
    border-color: rgba(255, 228, 94, 0.26);
}

.result-stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    max-width: 440px;
    margin: 0 auto 20px;
}

.result-stat {
    padding: 18px;
    border-radius: 18px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent 40%),
        rgba(12, 10, 24, 0.82);
    box-shadow: var(--shadow);
}

.result-stat strong {
    display: block;
    margin-top: 8px;
    font-size: 1.8rem;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}

#leaderboard-content {
    position: relative;
    max-width: 660px;
    margin: 0 auto 25px;
    border-radius: 22px;
    overflow: hidden;
}

.lb-row {
    display: grid;
    grid-template-columns: 60px 1fr 120px;
    gap: 12px;
    padding: 14px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    align-items: center;
}

.lb-row.lb-header {
    background: linear-gradient(90deg, rgba(0, 245, 255, 0.12), rgba(255, 43, 214, 0.12));
    color: var(--primary);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.82rem;
    letter-spacing: 0.12em;
}

.lb-row:last-child {
    border-bottom: none;
}

.lb-row .lb-rank {
    font-weight: 800;
}

.lb-row:nth-child(2) .lb-rank {
    color: var(--accent);
    font-size: 1.3rem;
}

.lb-row:nth-child(3) .lb-rank {
    color: #d7ebff;
    font-size: 1.2rem;
}

.lb-row:nth-child(4) .lb-rank {
    color: #ff9d76;
    font-size: 1.1rem;
}

.lb-time {
    text-align: right;
    font-variant-numeric: tabular-nums;
    color: var(--primary);
    font-weight: 700;
}

.loading,
.empty {
    padding: 40px;
    text-align: center;
    color: var(--text-muted);
}

#screen-leaderboard button {
    display: block;
    margin: 0 auto;
}

@media (max-width: 768px) {
    #app {
        padding-top: 72px;
    }

    h1 {
        font-size: 2.5rem;
    }

    .game-area {
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }

    .mode-options {
        grid-template-columns: 1fr;
    }

    .leaderboard-switch {
        display: flex;
        width: 100%;
        max-width: 420px;
        margin: 0 auto 10px;
    }

    .leaderboard-tab {
        flex: 1;
        min-width: 0;
    }

    .link-line {
        grid-column: 1 / -1;
        width: 100%;
        order: 3;
    }

    .player-side {
        min-height: 260px;
        padding: 20px 16px;
    }

    .hud {
        font-size: 1rem;
        padding: 14px 16px;
    }

    .hud-item {
        min-width: calc(50% - 8px);
    }

    .result-stats {
        grid-template-columns: 1fr;
    }

    .rules,
    .result-time,
    #leaderboard-content {
        border-radius: 18px;
    }

    #connection-status {
        right: 10px;
        left: 10px;
        justify-content: center;
    }
}
