:root {
    --bg: #fff8ec;
    --bg-soft: #ffeccd;
    --panel: rgba(255, 255, 255, 0.78);
    --panel-strong: rgba(255, 252, 245, 0.94);
    --ink: #222034;
    --muted: #6f6b7b;
    --line: rgba(34, 32, 52, 0.1);
    --accent: #ff7a59;
    --accent-strong: #e25535;
    --secondary: #18a999;
    --secondary-strong: #0d7b70;
    --highlight: #ffd166;
    --shadow: 0 28px 70px rgba(226, 120, 74, 0.16);
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Space Grotesk', sans-serif;
    min-height: 100vh;
    color: var(--ink);
    background:
        radial-gradient(circle at 12% 18%, rgba(255, 209, 102, 0.55), transparent 24%),
        radial-gradient(circle at 88% 10%, rgba(24, 169, 153, 0.18), transparent 20%),
        radial-gradient(circle at 82% 80%, rgba(255, 122, 89, 0.15), transparent 22%),
        linear-gradient(180deg, #fffdf9 0%, #fff6e9 48%, #ffe8c6 100%);
    display: flex;
    justify-content: center;
    padding: 24px;
    position: relative;
    overflow-x: hidden;
}

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

body::before {
    inset: auto auto 10% -8%;
    width: 22rem;
    height: 22rem;
    background: rgba(255, 122, 89, 0.12);
    border-radius: 54% 46% 42% 58% / 42% 60% 40% 58%;
    filter: blur(24px);
}

body::after {
    inset: 4% -6% auto auto;
    width: 24rem;
    height: 24rem;
    background: rgba(24, 169, 153, 0.12);
    border-radius: 61% 39% 65% 35% / 44% 57% 43% 56%;
    filter: blur(28px);
}

.page-shell {
    background-image:
        linear-gradient(rgba(34, 32, 52, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(34, 32, 52, 0.03) 1px, transparent 1px);
    background-size: 32px 32px;
    mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.35), transparent 92%);
}

.container {
    width: min(1180px, 100%);
    position: relative;
    z-index: 1;
    display: grid;
    gap: 18px;
}

.panel {
    background: var(--panel);
    border: 1px solid rgba(255, 255, 255, 0.55);
    border-radius: 28px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
}

.hidden {
    display: none !important;
}

.dashboard {
    display: grid;
    gap: 18px;
}

.hero-card {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
    gap: 18px;
    padding: 24px;
    overflow: hidden;
    position: relative;
}

.hero-card::after {
    content: "";
    position: absolute;
    right: -40px;
    top: -30px;
    width: 220px;
    height: 220px;
    border-radius: 999px;
    background: radial-gradient(circle, rgba(255, 209, 102, 0.42), rgba(255, 209, 102, 0));
}

.hero-copy {
    position: relative;
    z-index: 1;
    display: grid;
    gap: 12px;
    align-content: start;
}

.eyebrow {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    padding: 7px 12px;
    border-radius: 999px;
    background: rgba(24, 169, 153, 0.11);
    color: var(--secondary-strong);
    font-family: 'IBM Plex Mono', monospace;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    font-size: 0.72rem;
}

.hero-copy h1 {
    font-size: clamp(2.5rem, 5vw, 4.8rem);
    line-height: 0.95;
    letter-spacing: -0.07em;
    max-width: 10ch;
}

.hero-subtitle,
.section-copy,
.results-copy,
.topbar-note,
.player-meta small,
.track-meta small {
    color: var(--muted);
    line-height: 1.6;
}

.hero-subtitle {
    max-width: 48ch;
    font-size: 1.04rem;
}

.control-deck {
    position: relative;
    z-index: 1;
    display: grid;
    gap: 14px;
    align-content: start;
}

.mode-selector {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    padding: 10px;
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.62);
    border: 1px solid var(--line);
}

.mode-chip {
    appearance: none;
    border: 0;
    border-radius: 18px;
    padding: 14px 12px;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.18s ease, background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

.mode-chip:hover {
    transform: translateY(-1px);
    background: rgba(255, 255, 255, 0.75);
    color: var(--ink);
}

.mode-chip.is-active {
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: #fff;
    box-shadow: 0 12px 24px rgba(226, 85, 53, 0.24);
}

.status-band {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 16px 18px;
    border-radius: 24px;
    background: linear-gradient(135deg, rgba(255, 209, 102, 0.25), rgba(255, 255, 255, 0.85));
    border: 1px solid rgba(255, 209, 102, 0.3);
}

.status-copy {
    min-width: 0;
}

.status-label,
.typing-label,
.input-state,
.stat-label {
    font-family: 'IBM Plex Mono', monospace;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 0.72rem;
}

.status-label,
.stat-label,
.typing-label,
.input-state {
    color: var(--muted);
}

.status-band strong {
    display: block;
    margin-top: 4px;
    font-size: 1.1rem;
    letter-spacing: -0.03em;
}

.countdown-chip {
    min-width: 108px;
    padding: 16px 18px;
    border-radius: 22px;
    text-align: center;
    background: var(--ink);
    color: #fff;
    font-weight: 700;
    font-size: clamp(1.2rem, 2vw, 1.7rem);
    line-height: 1;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.start-signal {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 14px;
    border-radius: 24px;
    background: rgba(34, 32, 52, 0.94);
    box-shadow: 0 18px 36px rgba(34, 32, 52, 0.16);
}

.traffic-lights {
    display: flex;
    gap: 10px;
}

.traffic-light {
    width: 18px;
    height: 18px;
    border-radius: 999px;
    opacity: 0.28;
    transition: opacity 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.light-red {
    background: #ff5a52;
}

.light-yellow {
    background: #ffc53d;
}

.light-green {
    background: #2ecf6e;
}

.countdown-stack {
    display: grid;
    gap: 6px;
}

.countdown-label {
    color: rgba(255, 255, 255, 0.72);
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.68rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
}

.start-signal[data-stage="red"] .light-red,
.start-signal[data-stage="yellow"] .light-yellow,
.start-signal[data-stage="green"] .light-green,
.start-signal[data-stage="live"] .light-green,
.start-signal[data-stage="complete"] .light-green {
    opacity: 1;
    transform: scale(1.06);
}

.start-signal[data-stage="red"] .light-red {
    box-shadow: 0 0 0 8px rgba(255, 90, 82, 0.18);
}

.start-signal[data-stage="yellow"] .light-yellow {
    box-shadow: 0 0 0 8px rgba(255, 197, 61, 0.18);
}

.start-signal[data-stage="green"] .light-green,
.start-signal[data-stage="live"] .light-green,
.start-signal[data-stage="complete"] .light-green {
    box-shadow: 0 0 0 8px rgba(46, 207, 110, 0.18);
}

.start-signal[data-stage="yellow"] .countdown-chip {
    background: #5b4208;
}

.start-signal[data-stage="green"] .countdown-chip,
.start-signal[data-stage="live"] .countdown-chip,
.start-signal[data-stage="complete"] .countdown-chip {
    background: #10492d;
}

.stats-panel {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.stat-box {
    padding: 16px;
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.68);
    border: 1px solid var(--line);
    display: grid;
    gap: 4px;
}

.timer-stat {
    background: linear-gradient(135deg, rgba(255, 122, 89, 0.16), rgba(255, 255, 255, 0.92));
    border-color: rgba(255, 122, 89, 0.2);
}

.timer-stat .stat-value {
    font-size: clamp(1.9rem, 2.6vw, 2.6rem);
    color: var(--accent-strong);
}

.stat-value {
    font-size: clamp(1.4rem, 2vw, 1.85rem);
    font-weight: 700;
    letter-spacing: -0.05em;
    color: var(--ink);
}

.board-grid {
    display: grid;
    grid-template-columns: minmax(340px, 0.95fr) minmax(0, 1.05fr);
    gap: 18px;
    align-items: start;
}

.race-panel,
.typing-panel,
.results-card {
    padding: 22px;
}

.panel-heading {
    display: grid;
    gap: 10px;
}

.players-list {
    list-style: none;
    display: grid;
    gap: 10px;
    margin-top: 18px;
}

.compact-players {
    display: none;
}

.player-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    background: rgba(255, 255, 255, 0.72);
    border-radius: 20px;
    border: 1px solid var(--line);
    animation: slideIn 0.25s ease-out forwards;
}

.player-item.you {
    background: linear-gradient(135deg, rgba(24, 169, 153, 0.18), rgba(255, 255, 255, 0.88));
}

.player-badge {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 209, 102, 0.25);
    font-size: 1.45rem;
    flex: 0 0 auto;
}

.player-meta {
    display: grid;
    gap: 2px;
}

.race-panel {
    display: grid;
    gap: 14px;
}

.race-heading {
    padding-bottom: 4px;
}

.tracks-container {
    display: grid;
    gap: 10px;
}

.track-row {
    display: grid;
    grid-template-columns: 116px minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.68);
    border-radius: 18px;
    border: 1px solid var(--line);
}

.track-row.is-user {
    background: linear-gradient(135deg, rgba(255, 122, 89, 0.14), rgba(255, 255, 255, 0.9));
}

.track-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.track-animal {
    width: 28px;
    height: 28px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(24, 169, 153, 0.12);
    font-size: 1rem;
}

.track-meta strong {
    display: block;
    font-size: 0.92rem;
    line-height: 1.1;
}

.track-meta small {
    font-size: 0.73rem;
}

.track-lane {
    position: relative;
    height: 18px;
    border-radius: 999px;
    overflow: hidden;
    background: linear-gradient(90deg, rgba(34, 32, 52, 0.05), rgba(34, 32, 52, 0.1));
    border: 1px solid rgba(34, 32, 52, 0.08);
}

.track-fill {
    position: absolute;
    inset: 0 auto 0 0;
    width: 0;
    border-radius: inherit;
    background: linear-gradient(90deg, rgba(255, 122, 89, 0.85), rgba(255, 209, 102, 0.9));
    transition: width 0.22s ease-out;
}

.finish-line {
    position: absolute;
    top: -1px;
    bottom: -1px;
    right: 14px;
    width: 8px;
    background: repeating-linear-gradient(
        45deg,
        rgba(34, 32, 52, 0.92),
        rgba(34, 32, 52, 0.92) 3px,
        rgba(255, 255, 255, 0.92) 3px,
        rgba(255, 255, 255, 0.92) 6px
    );
    border-radius: 3px;
}

.avatar {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translate(-50%, -50%);
    transition: left 0.22s ease-out;
    z-index: 1;
}

.avatar-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 11px;
    background: #fff;
    border: 1px solid rgba(34, 32, 52, 0.08);
    box-shadow: 0 10px 18px rgba(34, 32, 52, 0.12);
    font-size: 1rem;
}

.typing-area {
    display: grid;
    gap: 12px;
    padding: 0;
    border-radius: 0;
    background: transparent;
    border: 0;
}

.typing-panel {
    padding: 22px;
}

.typing-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.input-state {
    padding: 8px 10px;
    border-radius: 999px;
    background: rgba(24, 169, 153, 0.11);
}

.text-display {
    min-height: 168px;
    padding: 18px;
    border-radius: 22px;
    background: #fff;
    border: 1px solid rgba(34, 32, 52, 0.08);
    font-family: 'IBM Plex Mono', monospace;
    font-size: clamp(0.98rem, 1.45vw, 1.08rem);
    line-height: 1.75;
    color: var(--muted);
    user-select: none;
}

.char.correct {
    color: var(--secondary-strong);
}

.char.incorrect {
    color: var(--accent-strong);
    background: rgba(255, 122, 89, 0.16);
    border-radius: 4px;
}

.char.current {
    color: var(--ink);
    text-decoration: underline;
    text-decoration-color: var(--highlight);
    text-decoration-thickness: 4px;
}

.typing-input {
    width: 100%;
    padding: 16px 18px;
    border-radius: 20px;
    border: 1px solid rgba(34, 32, 52, 0.12);
    background: rgba(255, 255, 255, 0.95);
    font: inherit;
    font-size: 1rem;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.typing-input:focus {
    outline: none;
    border-color: rgba(24, 169, 153, 0.45);
    box-shadow: 0 0 0 5px rgba(24, 169, 153, 0.12);
}

.typing-input:disabled {
    background: rgba(247, 243, 234, 0.95);
    color: var(--muted);
}

.results-modal {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 24px;
    background: rgba(34, 32, 52, 0.18);
    backdrop-filter: blur(12px);
    z-index: 3;
}

.results-card {
    width: min(560px, 100%);
}

.results-card h2 {
    font-size: clamp(2rem, 4vw, 2.8rem);
    line-height: 1;
    letter-spacing: -0.06em;
}

.results-copy {
    margin-top: 10px;
}

.leaderboard {
    list-style: none;
    display: grid;
    gap: 10px;
    margin-top: 20px;
}

.leaderboard li {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.82);
    border: 1px solid var(--line);
    font-weight: 600;
}

.leaderboard li.is-user {
    background: linear-gradient(135deg, rgba(24, 169, 153, 0.16), rgba(255, 255, 255, 0.92));
}

.rank {
    display: inline-block;
    min-width: 36px;
    color: var(--muted);
}

.result-actions {
    margin-top: 18px;
}

.primary-action {
    appearance: none;
    border: 0;
    border-radius: 999px;
    padding: 15px 22px;
    background: linear-gradient(135deg, var(--secondary), var(--secondary-strong));
    color: #fff;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 14px 28px rgba(13, 123, 112, 0.24);
}

.faq-section {
    padding: 22px;
}

.faq-heading h2 {
    font-size: clamp(1.8rem, 3vw, 2.5rem);
    line-height: 1;
    letter-spacing: -0.05em;
}

.faq-list {
    display: grid;
    gap: 10px;
    margin-top: 18px;
}

.faq-item {
    border: 1px solid var(--line);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.72);
    padding: 16px 18px;
}

.faq-item summary {
    cursor: pointer;
    list-style: none;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.faq-item summary::-webkit-details-marker {
    display: none;
}

.faq-item p {
    margin-top: 12px;
    color: var(--muted);
    line-height: 1.7;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 980px) {
    .hero-card,
    .board-grid {
        grid-template-columns: 1fr;
    }

    .hero-copy h1 {
        max-width: 12ch;
    }
}

@media (max-width: 720px) {
    body {
        padding: 14px;
    }

    .hero-card,
    .race-panel,
    .typing-panel,
    .results-card {
        padding: 18px;
    }

    .status-band,
    .typing-header,
    .leaderboard li {
        flex-direction: column;
        align-items: flex-start;
    }

    .start-signal {
        width: 100%;
        justify-content: space-between;
    }

    .mode-selector,
    .stats-panel {
        grid-template-columns: 1fr;
    }

    .track-row {
        grid-template-columns: 1fr;
    }

    .text-display {
        min-height: 210px;
    }
}