:root {
    --bg: #0b1220;
    --panel: rgba(19, 28, 46, 0.75);
    --panel-border: rgba(255, 255, 255, 0.08);
    --text: #e6edf6;
    --muted: #8fa3c7;
    --accent: #58f0ff;
    --accent-strong: #f9b05d;
    --surface: rgba(255, 255, 255, 0.04);
    --shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
    --radius: 18px;
    --font: 'Space Grotesk', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

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

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font);
    background: radial-gradient(circle at 20% 20%, rgba(88, 240, 255, 0.12), transparent 28%),
                radial-gradient(circle at 80% 0%, rgba(249, 176, 93, 0.12), transparent 30%),
                var(--bg);
    color: var(--text);
    padding: 28px 18px 60px;
}

.background-accent {
    position: fixed;
    inset: 0;
    pointer-events: none;
    background: radial-gradient(circle at 10% 80%, rgba(88, 240, 255, 0.08), transparent 30%),
                radial-gradient(circle at 80% 30%, rgba(249, 176, 93, 0.08), transparent 30%);
    filter: blur(60px);
    z-index: 0;
}

.topbar {
    position: relative;
    z-index: 2;
    max-width: 1200px;
    margin: 0 auto 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

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

.brand-mark {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    display: grid;
    place-items: center;
    font-weight: 700;
    color: #0b0f19;
    box-shadow: var(--shadow);
}

.brand-kicker {
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--muted);
    font-size: 12px;
}

.brand-title {
    margin: 2px 0 0;
    font-size: 26px;
    letter-spacing: 0.02em;
}

.lang-switcher {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    direction: ltr;
}

[dir="rtl"] .topbar {
    flex-direction: row-reverse;
}

[dir="rtl"] .brand {
    flex-direction: row-reverse;
    text-align: right;
}

[dir="rtl"] .lang-switcher {
    direction: rtl;
}

[dir="rtl"] .topbar-right {
    flex-direction: row-reverse;
}

.layout {
    position: relative;
    z-index: 2;
    max-width: 1200px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 16px;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.panel-header.spaced {
    margin-bottom: 12px;
}

.eyebrow {
    margin: 0;
    color: var(--muted);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    font-size: 12px;
}

h1, h2 {
    margin: 4px 0 0;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.search-row {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 12px;
}

.profile-row {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 12px;
}

input[type="text"] {
    flex: 1;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid var(--panel-border);
    background: var(--surface);
    color: var(--text);
    font-size: 16px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
}

input[type="text"]:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 10px 30px rgba(88, 240, 255, 0.25);
    transform: translateY(-1px);
}

#quiz-container button,
#quiz-container input[type="text"] {
    width: 100%;
    max-width: 460px;
    margin: 12px auto 0;
    display: block;
}

.profile-row button {
    width: auto;
    white-space: nowrap;
}

.quiz-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 10px;
}

.quiz-list li {
    padding: 14px 16px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
    border: 1px solid var(--panel-border);
    border-radius: 14px;
    color: var(--text);
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.quiz-list li:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.35);
}

.quiz-list li:active {
    transform: translateY(0);
}

.content-card {
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
    border-radius: 14px;
    border: 1px solid var(--panel-border);
    padding: 18px;
    box-shadow: var(--shadow);
    text-align: center;
}

#quiz-container h2 {
    margin-top: 0;
}

button {
    border: none;
    border-radius: 12px;
    padding: 12px 16px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.12s ease, box-shadow 0.2s ease, opacity 0.2s ease;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--panel-border);
    display: inline-flex;
    justify-content: center;
    align-items: center;
}

button:hover:not(:disabled) {
    transform: translateY(-1px);
}

button:active:not(:disabled) {
    transform: translateY(0);
}

button:disabled,
button[disabled] {
    opacity: 0.55;
    cursor: not-allowed;
    color: var(--muted);
}

.pill {
    padding: 10px 14px;
    background: var(--surface);
}

.pill.badge {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(88, 240, 255, 0.08);
    border: 1px solid var(--panel-border);
    color: var(--text);
    min-width: 140px;
}

.badge-name {
    font-weight: 600;
}

.badge-xp {
    color: var(--accent);
    font-weight: 600;
    letter-spacing: 0.01em;
}

.pill.active-lang {
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: 0 8px 20px rgba(88, 240, 255, 0.25);
}

.ghost {
    background: transparent;
    border: 1px solid var(--panel-border);
    color: var(--text);
}

.badge-disconnect {
    padding: 6px 10px;
    font-size: 13px;
    border-radius: 10px;
    color: #ff9a9a;
    border-color: rgba(255, 107, 107, 0.4);
}

.solid {
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: #0b0f19;
    border: none;
    box-shadow: 0 12px 30px rgba(88, 240, 255, 0.35);
}

.ghost {
    background: transparent;
    border: 1px solid var(--panel-border);
    color: var(--text);
}

.controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-top: 16px;
}

.control-right {
    display: flex;
    gap: 8px;
}

#score p {
    margin: 0;
    font-weight: 600;
    color: var(--accent);
}

.score-wrap {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    text-align: right;
}

.message {
    margin-top: 12px;
    padding: 12px 14px;
    border-radius: 12px;
    background: var(--surface);
    border: 1px solid var(--panel-border);
    min-height: 44px;
    text-align: center;
}

.correct-message {
    background: rgba(129, 199, 132, 0.1);
    border-color: rgba(129, 199, 132, 0.25);
    color: #8ddfa0;
}

.incorrect-message {
    background: rgba(255, 107, 107, 0.08);
    border-color: rgba(255, 107, 107, 0.25);
    color: #ff9a9a;
}

.text-black {
    color: var(--text);
}

.text-red {
    color: #ff9a9a;
}

.text-green {
    color: #8ddfa0;
}

.timer {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent-strong);
    text-align: right;
}

.loading {
    position: fixed;
    inset: 0;
    background: rgba(11, 18, 32, 0.85);
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 12px;
    z-index: 10;
    backdrop-filter: blur(6px);
}

.loading .spinner {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 5px solid rgba(255, 255, 255, 0.08);
    border-top-color: var(--accent);
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

#message-container p {
    margin: 0;
}

.site-footer {
    position: relative;
    z-index: 2;
    max-width: 1200px;
    margin: 24px auto 0;
    text-align: center;
    color: var(--muted);
    font-size: 14px;
}

@media (max-width: 768px) {
    body {
        padding: 18px 14px 36px;
    }

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

    .topbar-right {
        width: 100%;
        flex-wrap: wrap;
        justify-content: flex-start;
        gap: 8px;
    }

    .lang-switcher {
        width: 100%;
        justify-content: flex-start;
    }

    .layout {
        grid-template-columns: 1fr;
    }

    .controls {
        flex-direction: column;
        align-items: stretch;
    }

    .control-right {
        width: 100%;
        justify-content: flex-end;
    }
}
