:root {
    --bg: #0f1419;
    --card: #1a2332;
    --text: #e7ecf3;
    --muted: #8b9cb3;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --border: #2d3a4f;
    --success: #22c55e;
    --error: #ef4444;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--card);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.top-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    width: 100%;
    max-width: 720px;
}

.nav-btn {
    flex: 1;
    max-width: 200px;
    padding: 0.6rem 1rem;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    font-family: inherit;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.nav-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.nav-btn--home {
    background: rgba(59, 130, 246, 0.15);
    border-color: rgba(59, 130, 246, 0.45);
    color: #93c5fd;
}

.nav-btn--home:hover {
    background: rgba(59, 130, 246, 0.25);
    color: #bfdbfe;
}

.nav-btn--back {
    background: transparent;
    color: var(--muted);
}

.nav-btn--back:hover {
    color: var(--text);
}

.container {
    max-width: 720px;
    margin: 0 auto;
    padding: 2rem 1rem 4rem;
}

.test-page-card {
    max-width: 100%;
}

.container:has(.test-page-card) {
    max-width: 960px;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.75rem;
}

h1 {
    margin: 0 0 0.5rem;
    font-size: 1.5rem;
}

.hint {
    color: var(--muted);
    font-size: 0.9rem;
}

.hint code {
    background: var(--bg);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
}

.upload-card {
    margin-bottom: 1.25rem;
}

.upload-title {
    margin: 0 0 1.25rem;
}

.format-guide {
    margin-bottom: 1.5rem;
    padding: 1rem 1.1rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg);
}

.format-guide__lead {
    margin: 0 0 0.65rem;
    font-weight: 600;
    color: var(--text);
}

.format-guide__list {
    margin: 0;
    padding: 0 0 0 1.15rem;
    list-style: none;
}

.format-guide__list li {
    position: relative;
    margin: 0 0 0.5rem;
    padding-left: 0.25rem;
    color: var(--muted);
    line-height: 1.55;
}

.format-guide__list li::before {
    content: '—';
    position: absolute;
    left: -1rem;
    color: var(--accent);
}

.format-guide__list code {
    display: inline-block;
    margin-top: 0.15rem;
    background: rgba(59, 130, 246, 0.12);
    border: 1px solid rgba(59, 130, 246, 0.25);
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
    color: #bfdbfe;
    font-size: 0.88rem;
}

.format-guide__note {
    margin: 0.85rem 0 0;
    padding-top: 0.85rem;
    border-top: 1px solid var(--border);
    font-size: 0.9rem;
    color: var(--muted);
}

.upload-form {
    margin: 0;
}

.upload-input-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.upload-dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.65rem;
    width: 100%;
    min-height: 140px;
    padding: 1.5rem 1rem;
    border: 2px dashed var(--border);
    border-radius: 12px;
    background: var(--bg);
    color: var(--text);
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s, transform 0.15s;
}

.upload-dropzone:hover:not(:disabled) {
    border-color: var(--accent);
    background: rgba(59, 130, 246, 0.08);
}

.upload-dropzone:active:not(:disabled) {
    transform: scale(0.99);
}

.upload-dropzone:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.upload-dropzone--loading {
    border-style: solid;
    border-color: rgba(59, 130, 246, 0.5);
}

.upload-dropzone__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 10px;
    background: rgba(59, 130, 246, 0.2);
    border: 1px solid rgba(59, 130, 246, 0.4);
    font-size: 2rem;
    font-weight: 300;
    line-height: 1;
    color: #93c5fd;
}

.upload-dropzone__text {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--muted);
    text-align: center;
    max-width: 100%;
    word-break: break-word;
}

.leaders-card {
    margin-top: 0;
}

.leaders-title {
    margin: 0 0 1rem;
    font-size: 1.1rem;
    font-weight: 700;
    text-align: center;
}

.leaders-frame {
    min-height: 200px;
    padding: 1rem;
    border: 2px solid var(--border);
    border-radius: 12px;
    background: var(--bg);
}

.leaders-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.leaders-item {
    display: grid;
    grid-template-columns: 2rem 1fr auto;
    align-items: center;
    gap: 0.65rem;
    padding: 0.65rem 0.5rem;
    border-bottom: 1px solid var(--border);
}

.leaders-item:last-child {
    border-bottom: none;
}

.leaders-item__rank {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: rgba(59, 130, 246, 0.2);
    border: 1px solid rgba(59, 130, 246, 0.45);
    font-weight: 700;
    font-size: 0.85rem;
    color: #93c5fd;
}

.leaders-item:nth-child(1) .leaders-item__rank {
    background: rgba(234, 179, 8, 0.25);
    border-color: rgba(234, 179, 8, 0.5);
    color: #fde047;
}

.leaders-item__name {
    font-weight: 600;
    color: var(--text);
    word-break: break-word;
}

.leaders-item__score {
    font-size: 0.9rem;
    font-weight: 700;
    color: #86efac;
    white-space: nowrap;
}

.result-performance {
    margin: 0 0 1rem;
    padding: 0.85rem 1rem;
    border-radius: 10px;
    text-align: center;
    font-size: 1.1rem;
    font-weight: 600;
}

.result-performance--low,
.result-performance--poor {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.35);
    color: #fca5a5;
}

.result-performance--fair,
.result-performance--good {
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.35);
    color: #93c5fd;
}

.result-performance--great {
    background: rgba(34, 197, 94, 0.15);
    border: 1px solid rgba(34, 197, 94, 0.35);
    color: #86efac;
}

.result-performance--super {
    background: rgba(234, 179, 8, 0.12);
    border: 1px solid rgba(234, 179, 8, 0.35);
    color: #fde047;
    font-size: 1.15rem;
}

.result-leaderboard-badge {
    margin: 0 0 1rem;
    padding: 0.75rem 1rem;
    border-radius: 10px;
    background: rgba(34, 197, 94, 0.12);
    border: 1px solid rgba(34, 197, 94, 0.35);
    text-align: center;
    font-size: 0.92rem;
    color: #86efac;
}

.btn {
    border: none;
    border-radius: 8px;
    padding: 0.75rem 1.25rem;
    font-size: 1rem;
    cursor: pointer;
    font-weight: 600;
}

.btn.primary {
    background: var(--accent);
    color: #fff;
}

.btn.primary:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn.primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn.secondary {
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--accent);
}

.status {
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.95rem;
}

.status.error {
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
}

.status.success {
    background: rgba(34, 197, 94, 0.15);
    color: #86efac;
}

.status.info {
    background: rgba(59, 130, 246, 0.15);
    color: #93c5fd;
}

.test-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.test-header h1 {
    margin: 0;
    flex: 1;
}

.meta {
    color: var(--muted);
    margin: 0;
}

.question-block {
    border-top: 1px solid var(--border);
    padding: 1.25rem 0;
}

.question-block h2 {
    font-size: 1.05rem;
    font-weight: 600;
    margin: 0 0 0.75rem;
}

.options {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.option {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.15s;
}

.option:hover {
    border-color: var(--accent);
}

.option input {
    margin-top: 0.2rem;
}

.option-key {
    font-weight: 700;
    color: var(--accent);
    min-width: 1.25rem;
}

.option-text {
    flex: 1;
}

.test-setup {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.setup-title {
    margin: 0 0 0.35rem;
    font-size: 1.15rem;
}

.mode-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin: 1.25rem 0;
}

@media (max-width: 520px) {
    .mode-buttons {
        grid-template-columns: 1fr;
    }
}

.mode-btn {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
    padding: 1rem 1.1rem;
    border: 2px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
    text-align: left;
    transition: border-color 0.15s, background 0.15s;
}

.mode-btn:hover {
    border-color: var(--accent);
}

.mode-btn--selected {
    border-color: var(--accent);
    background: rgba(59, 130, 246, 0.12);
}

.mode-btn-title {
    font-size: 1.05rem;
    font-weight: 700;
}

.mode-btn-desc {
    font-size: 0.85rem;
    color: var(--muted);
}

.btn-start {
    width: 100%;
    margin-bottom: 0.75rem;
}

.btn-start:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.test-active {
    margin-top: 0.5rem;
}

.test-layout {
    display: flex;
    gap: 1.25rem;
    align-items: flex-start;
}

.test-layout__main {
    flex: 1;
    min-width: 0;
}

.question-nav {
    --nav-dot: 1.75rem;
    --nav-gap: 0.3rem;
    flex-shrink: 0;
    display: grid;
    grid-template-columns: repeat(5, var(--nav-dot));
    grid-template-rows: repeat(5, var(--nav-dot));
    gap: var(--nav-gap);
    width: calc(5 * var(--nav-dot) + 4 * var(--nav-gap) + 1rem);
    padding: 0.5rem;
    box-sizing: border-box;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg);
    position: sticky;
    top: 4.5rem;
    z-index: 20;
    overflow: hidden;
}

.question-nav[hidden] {
    display: none !important;
}

.question-nav__dot {
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--nav-dot);
    height: var(--nav-dot);
    min-width: 0;
    min-height: 0;
    margin: 0;
    padding: 0;
    border: 2px solid var(--border);
    border-radius: 50%;
    background: transparent;
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 700;
    font-family: inherit;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.question-nav__dot:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.question-nav__dot--answered {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

.question-nav__dot--answered:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    color: #fff;
}

@media (max-width: 800px) {
    .test-layout {
        flex-direction: column;
    }

    .question-nav {
        --nav-dot: 1.55rem;
        --nav-gap: 0.25rem;
        width: calc(5 * var(--nav-dot) + 4 * var(--nav-gap) + 1rem);
        max-width: 100%;
        margin: 0 auto;
        position: sticky;
        top: 3.5rem;
    }

    .question-nav__dot {
        font-size: 0.62rem;
    }
}

.result-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 1.5rem;
}

.result-actions .btn {
    text-align: center;
    text-decoration: none;
}

.mode-badge {
    display: inline-block;
    margin: 0 0 1rem;
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
}

.mode-badge--timed {
    background: rgba(234, 179, 8, 0.2);
    color: #fde047;
}

.mode-badge--untimed {
    background: rgba(34, 197, 94, 0.2);
    color: #86efac;
}

.timer-bar.is-hidden,
.timer-bar[hidden] {
    display: none !important;
}

.timer-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin: 0 0 1.25rem;
    padding: 0.85rem 1rem;
    border-radius: 10px;
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.35);
    position: sticky;
    top: 0.5rem;
    z-index: 10;
}

.timer-bar--warning {
    background: rgba(234, 179, 8, 0.2);
    border-color: rgba(234, 179, 8, 0.45);
}

.timer-bar--warning .timer-display {
    color: #fde047;
}

.timer-bar--ended {
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.45);
}

.timer-label {
    font-size: 0.9rem;
    color: var(--muted);
}

.timer-display {
    font-size: 1.5rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: #93c5fd;
}

.timer-ended {
    margin-top: 1.5rem;
    padding: 1.25rem;
    border-radius: 10px;
    border: 1px solid rgba(239, 68, 68, 0.4);
    background: rgba(239, 68, 68, 0.1);
    text-align: center;
}

.timer-ended h2 {
    margin: 0 0 0.5rem;
    color: #fca5a5;
}

.test-form--locked {
    opacity: 0.55;
    pointer-events: none;
}

.test-finish-wrap {
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
}

.btn-finish {
    width: 100%;
}

.test-results {
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
}

.results-title {
    margin: 0 0 1rem;
    font-size: 1.2rem;
}

.results-summary {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    margin-bottom: 1rem;
}

.result-stat {
    margin: 0;
    padding: 0.85rem 1rem;
    border-radius: 10px;
    font-size: 1rem;
}

.result-stat strong {
    font-size: 1.15rem;
}

.result-stat--correct {
    background: rgba(34, 197, 94, 0.15);
    border: 1px solid rgba(34, 197, 94, 0.35);
    color: #86efac;
}

.result-stat--wrong {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.35);
    color: #fca5a5;
}

#show-mistakes-btn {
    width: 100%;
    margin-bottom: 0.75rem;
}

.mistakes-panel {
    margin-top: 0.5rem;
}

.mistake-item {
    margin-bottom: 1rem;
    padding: 1rem;
    border-radius: 10px;
    border: 1px solid rgba(239, 68, 68, 0.35);
    background: rgba(239, 68, 68, 0.08);
}

.mistake-item h3 {
    margin: 0 0 0.75rem;
    font-size: 1rem;
    color: #fca5a5;
}

.mistake-item p {
    margin: 0 0 0.4rem;
    font-size: 0.92rem;
    color: var(--text);
}

.mistake-item .mistake-label {
    color: var(--muted);
    font-size: 0.85rem;
}

.mistake-item .mistake-wrong {
    color: #fca5a5;
}

.mistake-item .mistake-right {
    color: #86efac;
}

body.modal-open {
    overflow: hidden;
}

.name-modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.name-modal[hidden] {
    display: none !important;
}

.name-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
}

.name-modal__dialog {
    position: relative;
    width: 100%;
    max-width: 400px;
    padding: 1.75rem 1.5rem;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--card);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.name-modal__title {
    margin: 0 0 0.35rem;
    font-size: 1.35rem;
    text-align: center;
}

.name-modal__subtitle {
    margin: 0 0 1.25rem;
    text-align: center;
    color: var(--muted);
    font-size: 0.92rem;
    line-height: 1.5;
}

.name-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.name-field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.name-field label {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--muted);
}

.name-field input {
    width: 100%;
    padding: 0.75rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font-size: 1rem;
    font-family: inherit;
}

.name-field input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

.name-field input::placeholder {
    color: #5c6b82;
}

.name-form-error {
    margin: 0;
    padding: 0.6rem 0.75rem;
    border-radius: 8px;
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
    font-size: 0.88rem;
}

.name-form-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.25rem;
}

.name-form-actions .btn {
    width: 100%;
}

.result-greeting {
    margin: 0 0 1rem;
    padding: 0.75rem 1rem;
    border-radius: 10px;
    background: rgba(59, 130, 246, 0.12);
    border: 1px solid rgba(59, 130, 246, 0.3);
    text-align: center;
    font-size: 1.05rem;
    font-weight: 600;
    color: #bfdbfe;
}
