:root {
    color-scheme: light;
    --bg-base: #0f172a;
    --bg-panel: rgba(15, 23, 42, 0.72);
    --bg-muted: rgba(148, 163, 184, 0.12);
    --bg-result: #111827;
    --accent: #38bdf8;
    --accent-strong: #0ea5e9;
    --success: #34d399;
    --danger: #f87171;
    --text-primary: #f8fafc;
    --text-muted: rgba(226, 232, 240, 0.74);
    --shadow-soft: 0 18px 40px rgba(15, 23, 42, 0.4);
    --radius-lg: 28px;
    --radius-md: 18px;
    --radius-sm: 12px;
    font-family: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body.app-body {
    margin: 0;
    min-height: 100vh;
    background: radial-gradient(circle at 20% 20%, rgba(56, 189, 248, 0.15), transparent 55%),
                radial-gradient(circle at 80% 10%, rgba(56, 189, 248, 0.12), transparent 60%),
                linear-gradient(160deg, #020617, #0f172a 55%, #020617);
    color: var(--text-primary);
}

.app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 32px clamp(24px, 6vw, 64px);
    gap: 32px;
}

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

.brand {
    display: flex;
    align-items: center;
    gap: 20px;
}

.brand__logo {
    width: 70px;
    height: 70px;
    border-radius: 18px;
    background: linear-gradient(135deg, rgba(56, 189, 248, 0.24), rgba(56, 189, 248, 0.08));
    display: grid;
    place-items: center;
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    border: 1px solid rgba(148, 163, 184, 0.3);
}

.brand__logo span {
    color: var(--accent);
}

.brand__meta {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.brand__title {
    margin: 0;
    font-size: clamp(22px, 2.5vw, 26px);
    font-weight: 600;
}

.brand__subtitle {
    margin: 0;
    color: var(--text-muted);
    font-size: 15px;
    letter-spacing: 0.4px;
}

.header-status {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    font-size: 14px;
    color: var(--text-muted);
}

.header-status__round {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.header-status__server {
    margin: 0;
    letter-spacing: 0.5px;
}

.header-status__player {
    margin: 0;
    letter-spacing: 0.5px;
}

.header-status__change-name {
    margin: 4px 0 0;
    padding: 4px 10px;
    font-size: 12px;
    background: rgba(56, 189, 248, 0.12);
    color: var(--accent);
    border: 1px solid rgba(56, 189, 248, 0.24);
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease;
    letter-spacing: 0.3px;
    font-weight: 500;
}

.header-status__change-name:hover {
    background: rgba(56, 189, 248, 0.2);
    border-color: rgba(56, 189, 248, 0.4);
}

.app-content {
    flex: 1;
    min-height: 0;
}

.view {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 200px);
    background: rgba(15, 23, 42, 0.4);
    border-radius: var(--radius-lg);
    backdrop-filter: blur(22px);
    padding: clamp(24px, 6vw, 64px);
    box-shadow: var(--shadow-soft);
}

.view.hidden {
    display: none;
}

.view__panel {
    max-width: 640px;
    text-align: center;
}

.view__title {
    font-size: clamp(36px, 4vw, 44px);
    font-weight: 700;
    margin-bottom: 16px;
}

.view__subtitle {
    margin: 0;
    color: var(--text-muted);
    font-size: 18px;
}

.view__highlight {
    margin: 40px auto 24px;
    padding: 18px 24px;
    display: inline-flex;
    align-items: center;
    gap: 12px;
    border-radius: 999px;
    font-weight: 600;
    font-size: 18px;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.view__highlight.waiting {
    background: rgba(248, 113, 113, 0.15);
    color: #fecaca;
}

.view__help {
    color: var(--text-muted);
    font-size: 15px;
    margin-top: 32px;
}

.dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: currentColor;
}

.dot--pulse {
    animation: pulse 1.6s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(0.9);
        opacity: 0.6;
    }
    50% {
        transform: scale(1.15);
        opacity: 1;
    }
}

.view--accent .view__panel {
    text-align: center;
}

.view__eyebrow {
    display: inline-block;
    padding: 10px 20px;
    background: rgba(56, 189, 248, 0.12);
    color: var(--accent);
    border-radius: 999px;
    letter-spacing: 0.4px;
    font-size: 13px;
    text-transform: uppercase;
    margin-bottom: 24px;
}

.view__timer {
    font-size: clamp(80px, 12vw, 140px);
    margin: 0;
    font-weight: 700;
    letter-spacing: -2px;
}

.view--play {
    flex-direction: column;
    align-items: stretch;
    gap: 28px;
}

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

.play-label {
    font-size: 15px;
    margin: 0;
    color: var(--text-muted);
}

.play-round {
    margin: 4px 0 0;
    font-size: clamp(28px, 4vw, 36px);
}

.play-metrics {
    display: flex;
    gap: 18px;
}

.metric {
    background: var(--bg-muted);
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    min-width: 120px;
}

.metric__label {
    display: block;
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 6px;
    letter-spacing: 0.8px;
}

.metric__value {
    font-size: 28px;
    font-weight: 600;
}

.typing-system {
    display: flex;
    flex-direction: column;
    gap: 24px;
    margin-top: 12px;
}

.preview-box {
    background: var(--bg-panel);
    border-radius: var(--radius-md);
    padding: 20px 24px;
    box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.18);
    border: 1px solid rgba(148, 163, 184, 0.2);
}

.preview-content {
    font-family: Monospace;
    font-size: 18px;
    line-height: 1.6;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-wrap: break-word;
}


.typing-box-wrapper {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.input-label {
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 1.4px;
    color: var(--text-muted);
    margin: 0;
}

.typing-box-container {
    position: relative;
    background: var(--bg-panel);
    border-radius: var(--radius-md);
    border: 1px solid rgba(148, 163, 184, 0.2);
    overflow: hidden;
    height: calc(2 * 1.6em + 40px);
}

.typing-display {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 20px 24px;
    font-family: Monospace;
    font-size: 18px;
    line-height: 1.6;
    letter-spacing: 0.8px;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-y: auto;
    overflow-x: hidden;
    pointer-events: none;
    z-index: 3;
}

.typing-box-input {
    position: relative;
    width: 100%;
    height: 100%;
    padding: 20px 24px;
    font-family: Monospace;
    font-size: 18px;
    line-height: 1.6;
    letter-spacing: 0.8px;
    background: transparent;
    color: transparent;
    border: none;
    resize: none;
    overflow-y: auto;
    overflow-x: hidden;
    caret-color: var(--text-primary);
    z-index: 2;
    transition: border 0.2s ease, box-shadow 0.2s ease;
}

.typing-box-input:focus {
    outline: none;
}

.typing-box-container:focus-within {
    border-color: rgba(56, 189, 248, 0.6);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.18);
}

.typed-char--correct {
    color: var(--success);
    font-weight: 500;
}

.typed-char--incorrect {
    color: var(--danger);
    font-weight: 500;
    text-decoration: underline;
    text-decoration-thickness: 2px;
    background-color: rgba(248, 113, 113, 0.15);
}

.play-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
}

.btn-link {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.btn-link:hover {
    color: var(--accent-strong);
}

.status-pill {
    padding: 8px 16px;
    border-radius: 999px;
    background: rgba(56, 189, 248, 0.12);
    color: var(--accent);
    font-weight: 600;
    letter-spacing: 0.8px;
    text-transform: uppercase;
}

.status-pill--error {
    background: rgba(248, 113, 113, 0.15);
    color: #fca5a5;
}

.view--result {
    background: rgba(15, 23, 42, 0.65);
}

.result-card {
    max-width: 520px;
    background: var(--bg-result);
    padding: clamp(28px, 4vw, 48px);
    border-radius: var(--radius-lg);
    text-align: center;
    box-shadow: var(--shadow-soft);
    border: 1px solid rgba(148, 163, 184, 0.18);
}

.result-eyebrow {
    margin: 0;
    color: var(--accent);
    letter-spacing: 1.2px;
    text-transform: uppercase;
    font-size: 13px;
}

.result-title {
    margin: 12px 0 0;
    font-size: clamp(28px, 4vw, 34px);
}

.result-round {
    margin: 12px 0;
    color: var(--text-muted);
}

.result-stats {
    display: grid;
    gap: 18px;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    margin: 28px 0 36px;
}

.result-stat {
    background: var(--bg-muted);
    padding: 16px;
    border-radius: var(--radius-md);
    border: 1px solid rgba(148, 163, 184, 0.16);
}

.result-stat__label {
    display: block;
    font-size: 13px;
    letter-spacing: 0.4px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.result-stat__value {
    font-size: 30px;
    font-weight: 600;
}

.result-note {
    margin: 0;
    color: var(--text-muted);
    font-size: 15px;
}

.result-actions {
    margin-top: 32px;
    display: flex;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
}

.btn-primary,
.btn-secondary {
    border: none;
    border-radius: 999px;
    padding: 12px 28px;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: #0b1120;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 16px 24px rgba(14, 165, 233, 0.35);
}

.btn-secondary {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid rgba(148, 163, 184, 0.3);
}

.btn-secondary:hover {
    border-color: rgba(56, 189, 248, 0.6);
    color: var(--accent);
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.86);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: 999;
}

.modal--visible {
    visibility: visible;
    opacity: 1;
}

.modal__box {
    background: rgba(15, 23, 42, 0.92);
    border-radius: var(--radius-lg);
    padding: clamp(28px, 4vw, 42px);
    width: min(420px, 100%);
    display: flex;
    flex-direction: column;
    gap: 18px;
    box-shadow: var(--shadow-soft);
    border: 1px solid rgba(56, 189, 248, 0.18);
}

.modal__title {
    margin: 0;
    font-size: 26px;
}

.modal__subtitle {
    margin: 0;
    color: var(--text-muted);
    font-size: 15px;
}

.modal__label {
    font-size: 13px;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    color: var(--text-muted);
}

.modal__input {
    border-radius: 14px;
    padding: 14px 16px;
    border: 1px solid rgba(148, 163, 184, 0.24);
    background: rgba(15, 23, 42, 0.6);
    color: var(--text-primary);
    font-size: 16px;
}

.modal__input:focus {
    outline: none;
    border-color: rgba(56, 189, 248, 0.6);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2);
}

@media (max-width: 900px) {
    .app {
        padding: 20px;
    }

    .app-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .view {
        min-height: calc(100vh - 160px);
    }

    .play-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .play-metrics {
        width: 100%;
    }

    .play-footer {
        flex-direction: column;
        gap: 12px;
        align-items: flex-start;
    }
}
