:root {
    --bg: #080a0e;
    --bg-lift: #11151c;
    --bg-card: #161b24;
    --bg-soft: #1b212c;
    --line: rgba(255, 255, 255, 0.065);
    --line-strong: rgba(255, 255, 255, 0.13);
    --text: #f3f5f9;
    --muted: #7e8799;
    --dim: #3d4556;
    --correct: #e9edf5;
    --accent: #3dffb5;
    --accent-2: #8af5c8;
    --accent-ink: #04180f;
    --accent-dim: rgba(61, 255, 181, 0.13);
    --accent-glow: rgba(61, 255, 181, 0.28);
    --warn: #ffb020;
    --error: #ff5c7a;
    --error-dim: rgba(255, 92, 122, 0.16);
    --ease: cubic-bezier(0.22, 1, 0.36, 1);
    --ease-snap: cubic-bezier(0.34, 1.4, 0.64, 1);
    --font-display: "Syne", ui-sans-serif, system-ui, sans-serif;
    --font-ui: "Manrope", ui-sans-serif, system-ui, sans-serif;
    --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    --race-size: clamp(1.45rem, 2.5vw, 1.9rem);
    --race-lh: 2.15;
    --radius: 20px;
    --radius-lg: 26px;
    --shadow: 0 20px 50px rgba(0, 0, 0, 0.42);
    --shadow-soft: 0 10px 28px rgba(0, 0, 0, 0.28);
}

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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-ui);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

body {
    display: grid;
    place-items: center;
}

::selection {
    background: rgba(61, 255, 181, 0.28);
    color: var(--text);
}

:focus { outline: none; }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

button {
    font: inherit;
    color: inherit;
    border: 0;
    background: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

button:active:not(.top-tab):not(.mode-card):not(.lesson-card):not(.btn) {
    transform: translateY(1px);
}

kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.5em;
    padding: 0.14em 0.42em;
    border: 1px solid var(--line-strong);
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.045);
    font-family: var(--font-mono);
    font-size: 0.74em;
    color: var(--text);
    box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.35);
}

.atmosphere {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
    background:
        radial-gradient(ellipse 75% 50% at 50% -18%, rgba(61, 255, 181, 0.1), transparent 58%),
        radial-gradient(ellipse 45% 38% at 100% 100%, rgba(96, 140, 255, 0.07), transparent 52%),
        radial-gradient(ellipse 35% 30% at 0% 80%, rgba(61, 255, 181, 0.04), transparent 50%),
        var(--bg);
}

.orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(72px);
    opacity: 0.5;
    animation: drift 22s var(--ease) infinite alternate;
    will-change: transform;
}

.orb-a {
    width: 46vw;
    height: 46vw;
    top: -14%;
    left: 18%;
    background: rgba(61, 255, 181, 0.14);
}

.orb-b {
    width: 36vw;
    height: 36vw;
    right: -10%;
    bottom: -12%;
    background: rgba(110, 150, 255, 0.11);
    animation-delay: -8s;
}

.grid-fade {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.022) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.022) 1px, transparent 1px);
    background-size: 52px 52px;
    mask-image: radial-gradient(ellipse 65% 55% at 50% 38%, #000 8%, transparent 72%);
    -webkit-mask-image: radial-gradient(ellipse 65% 55% at 50% 38%, #000 8%, transparent 72%);
    opacity: 0.65;
}

.fx-layer {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 50;
    overflow: hidden;
}

.screen {
    position: relative;
    z-index: 1;
    width: 100%;
}

.screen[hidden] { display: none !important; }

.app-shell {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    width: min(1020px, calc(100% - 32px));
    height: min(940px, calc(100% - 24px));
    max-height: 96vh;
}

/* —— Top nav —— */
.topnav {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    margin-bottom: 16px;
    padding: 7px 8px;
    border-radius: 18px;
    border: 1px solid var(--line);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent 60%),
        rgba(17, 21, 28, 0.88);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), var(--shadow-soft);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

.topnav[hidden] { display: none !important; }

.topnav-brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding-left: 6px;
    min-width: 0;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    border-radius: 15px;
    background: linear-gradient(145deg, #5fffc4, #1fd98f 55%, #14c47a);
    color: var(--accent-ink);
    font-family: var(--font-display);
    font-size: 1.05rem;
    font-weight: 800;
    letter-spacing: -0.04em;
    box-shadow:
        0 10px 24px rgba(61, 255, 181, 0.28),
        inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.brand-mark.sm {
    width: 34px;
    height: 34px;
    border-radius: 11px;
    font-size: 0.72rem;
    box-shadow:
        0 8px 18px rgba(61, 255, 181, 0.22),
        inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.topnav-title {
    font-family: var(--font-display);
    font-size: 1.02rem;
    font-weight: 800;
    letter-spacing: -0.035em;
}

.topnav-tabs {
    position: relative;
    display: inline-grid;
    grid-template-columns: 1fr 1fr;
    padding: 4px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.38);
    border: 1px solid var(--line);
    gap: 0;
}

.topnav-tabs::before {
    content: "";
    position: absolute;
    top: 4px;
    left: 4px;
    width: calc(50% - 4px);
    height: calc(100% - 8px);
    border-radius: 999px;
    background: var(--accent);
    box-shadow: 0 8px 18px rgba(61, 255, 181, 0.28);
    transition: transform 280ms var(--ease);
    z-index: 0;
}

.topnav-tabs[data-active="lessons"]::before {
    transform: translateX(100%);
}

.top-tab {
    position: relative;
    z-index: 1;
    min-width: 108px;
    padding: 9px 20px;
    border-radius: 999px;
    color: var(--muted);
    font-size: 0.84rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    transition: color 200ms ease;
}

.top-tab:hover { color: var(--text); }

.top-tab.active {
    color: var(--accent-ink);
}

.top-tab:active { transform: none; }

.topnav-spacer { min-height: 1px; }

.tab-panel[hidden] { display: none !important; }

.tab-panel {
    display: flex;
    flex-direction: column;
    gap: clamp(18px, 2.6vh, 26px);
    animation: fadeUp 340ms var(--ease) both;
}

.eyebrow,
.panel-title {
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

@keyframes drift {
    from { transform: translate3d(0, 0, 0) scale(1); }
    to { transform: translate3d(2.5%, 3.5%, 0) scale(1.05); }
}

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

@keyframes cardIn {
    from { opacity: 0; transform: translateY(10px) scale(0.985); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    .orb { animation: none; }
    .topnav-tabs::before { transition: none; }
}

@media (max-width: 640px) {
    .app-shell {
        width: calc(100% - 20px);
        height: calc(100% - 16px);
    }

    .topnav {
        grid-template-columns: 1fr;
        justify-items: stretch;
        gap: 10px;
        padding: 10px;
        margin-bottom: 12px;
    }

    .topnav-brand { width: 100%; }
    .topnav-spacer { display: none; }
    .topnav-tabs { width: 100%; }
    .top-tab { min-width: 0; }
}
