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

        :root {
            --bg-primary: #ffffff;
            --bg-secondary: #f7f7f8;
            --bg-card: #ffffff;
            --bg-card-hover: #fafafa;
            --glass: #ffffff;
            --glass-border: #e4e4e9;
            --text-primary: #16161a;
            --text-secondary: #5a5a66;
            --text-muted: #727280;
            --accent: #001e3f;
            --accent-glow: rgba(0, 30, 63, 0.08);
            --accent-light: #143c64;
            /* Text drawn on top of --accent / --accent-light fills. The accent is
               near-black in light theme and near-white in dark, so the readable
               foreground flips with it. */
            --on-accent: #ffffff;
            --accent-2: #fe6909;
            --accent-2-glow: rgba(254, 105, 9, 0.12);
            --danger: #dc2626;
            --success: #16a34a;
            --warning: #d97706;
            --warning-tint: rgba(217, 119, 6, 0.07);
            --mark-ink: #001e3f;
            --mark-back: #001e3f;
            --mark-card: #ffffff;
            /* Two voices: a high-contrast serif for the wordmark and the headings
               that name a screen, a grotesque for everything functional. Card text
               is UI, not display, so it stays in the sans. */
            --font-ui: 'Schibsted Grotesk', -apple-system, BlinkMacSystemFont, sans-serif;
            --font-display: 'Newsreader', Georgia, 'Times New Roman', serif;
            --radius: 12px;
            --radius-sm: 8px;
            --radius-xs: 6px;
            --shadow: 0 1px 2px rgba(16,16,20,0.04), 0 6px 20px rgba(16,16,20,0.06);
            --transition: 0.15s ease;
            color-scheme: light;
        }

        @media (prefers-color-scheme: dark) {
            :root:not([data-theme="light"]) {
                --bg-primary: #0b0f14;
                --bg-secondary: #12171e;
                --bg-card: #12171e;
                --bg-card-hover: #1a212b;
                --glass: #12171e;
                --glass-border: #262d38;
                --text-primary: #f1f3f5;
                --text-secondary: #a3adb8;
                --text-muted: #7b8695;
                --accent: #5b8fd9;
                --accent-glow: rgba(91, 143, 217, 0.15);
                --accent-light: #7fa8e3;
                --on-accent: #0b0f14;
                --accent-2: #ff7a1f;
                --accent-2-glow: rgba(255, 122, 31, 0.18);
                --danger: #ef4444;
                --success: #22c55e;
                --warning: #f59e0b;
                --warning-tint: rgba(245, 158, 11, 0.10);
                --mark-ink: #e8eef6;
                --mark-back: #2a3f5c;
                --mark-card: #12171e;
                --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px rgba(0,0,0,0.5);
                color-scheme: dark;
            }
        }

        :root[data-theme="dark"] {
            --bg-primary: #0b0f14;
            --bg-secondary: #12171e;
            --bg-card: #12171e;
            --bg-card-hover: #1a212b;
            --glass: #12171e;
            --glass-border: #262d38;
            --text-primary: #f1f3f5;
            --text-secondary: #a3adb8;
            --text-muted: #7b8695;
            --accent: #5b8fd9;
            --accent-glow: rgba(91, 143, 217, 0.15);
            --accent-light: #7fa8e3;
            --on-accent: #0b0f14;
            --accent-2: #ff7a1f;
            --accent-2-glow: rgba(255, 122, 31, 0.18);
            --danger: #ef4444;
            --success: #22c55e;
            --warning: #f59e0b;
            --warning-tint: rgba(245, 158, 11, 0.10);
            --mark-ink: #e8eef6;
            --mark-back: #2a3f5c;
            --mark-card: #12171e;
            --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px rgba(0,0,0,0.5);
            color-scheme: dark;
        }

        body {
            font-family: var(--font-ui);
            background: var(--bg-primary);
            color: var(--text-primary);
            min-height: 100vh;
            overflow-x: hidden;
        }

        /* ── Login Screen ── */
        #login-screen {
            position: fixed;
            inset: 0;
            z-index: 100;
            display: flex;
            align-items: center;
            justify-content: flex-start;
            padding: 24px;
            overflow-y: auto;
            background: var(--bg-primary);
            transition: opacity 0.4s ease, visibility 0.4s ease;
        }

        #login-screen.hidden {
            opacity: 0;
            visibility: hidden;
            pointer-events: none;
        }

        .login-card {
            background: var(--glass);
            border: 1px solid var(--glass-border);
            border-radius: 16px;
            padding: 44px 40px 40px;
            text-align: left;
            max-width: 440px;
            width: 100%;
            margin: auto auto auto 8vw;
            box-shadow: var(--shadow);
            animation: fadeInUp 0.6s ease-out;
        }

        .login-brand {
            justify-content: flex-start;
            gap: 14px;
            margin-bottom: 14px;
        }

        .login-brand .header-logo {
            height: 51px;
            width: 60px;
        }

        .login-brand .logo-text {
            font-size: 36px;
        }

        .login-card .login-tagline {
            font-size: 11px;
            font-weight: 700;
            letter-spacing: 0.13em;
            line-height: 1.5;
            text-transform: uppercase;
            color: var(--accent-2);
            margin-bottom: 22px;
        }

        .login-card p:not(.login-tagline):not(.login-legal) {
            color: var(--text-secondary);
            font-size: 14px;
            max-width: 34ch;
            margin-bottom: 28px;
            line-height: 1.55;
        }

        .btn-google {
            display: inline-flex;
            align-items: center;
            gap: 12px;
            background: #fff;
            color: #333;
            border: none;
            padding: 14px 32px;
            border-radius: 12px;
            font-size: 15px;
            font-weight: 600;
            font-family: inherit;
            cursor: pointer;
            transition: var(--transition);
            box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
        }

        .btn-google:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
        }

        .btn-google:active {
            transform: translateY(0);
        }

        .btn-google svg {
            width: 20px;
            height: 20px;
            flex-shrink: 0;
        }

        .btn-google:disabled {
            opacity: 0.6;
            cursor: wait;
        }

        /* Same control as the header's theme toggle: the chrome comes from
           .btn .btn-sm, so this rule only places it. Nothing here may restate a
           .btn property, or the two toggles drift apart again. */
        .theme-toggle-login {
            /* fixed, not absolute: #login-screen carries the card's gutter as
               padding, and an absolute child would be inset by it. */
            position: fixed;
            top: 20px;
            right: 20px;
        }

        .feedback-link {
            display: inline-block;
            margin-top: 18px;
            font-size: 12px;
            color: var(--text-muted);
            text-decoration: underline;
        }

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

        /* ── Maintenance Screen ── */
        .maintenance-screen {
            display: none;
            position: fixed;
            inset: 0;
            z-index: 1000;
            flex-direction: column;
            background: var(--bg-primary);
            overflow: hidden;
            padding: 28px 40px 64px;
        }

        .maintenance-screen.visible {
            display: flex;
        }

        .maintenance-watermark {
            position: absolute;
            width: 620px;
            height: 620px;
            right: -140px;
            bottom: -160px;
            color: var(--accent);
            opacity: 0.06;
            pointer-events: none;
        }

        .maintenance-watermark polygon {
            fill: currentColor;
        }

        .maintenance-header {
            display: flex;
            align-items: center;
            gap: 10px;
            position: relative;
            z-index: 1;
        }

        .maintenance-content {
            position: relative;
            z-index: 1;
            max-width: 480px;
            margin-top: auto;
            animation: fadeInUp 0.6s ease-out;
        }

        .maintenance-content h1 {
            font-size: 40px;
            font-weight: 800;
            line-height: 1.15;
            color: var(--text-primary);
            margin-bottom: 16px;
        }

        .maintenance-content p {
            color: var(--text-secondary);
            font-size: 15px;
            line-height: 1.6;
            margin-bottom: 28px;
        }

        /* ── App Shell ── */
        #app {
            display: none;
            position: relative;
            z-index: 1;
        }

        #app.visible {
            display: block;
            animation: fadeInUp 0.5s ease-out;
        }

        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(20px);
            }

            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        /* ── Header ── */
        header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 20px 32px;
            background: var(--bg-primary);
            border-bottom: 1px solid var(--glass-border);
            position: sticky;
            top: 0;
            z-index: 95;
        }

        .header-left {
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .header-logo {
            height: 30px;
            width: 35px;
            display: block;
            color: var(--accent);
            flex-shrink: 0;
        }

        .brand-sprite {
            position: absolute;
            width: 0;
            height: 0;
            overflow: hidden;
        }

        /* -- Brand lockup (hexagon mark + wordmark) -- */
        .brand-lockup {
            display: inline-flex;
            align-items: center;
            gap: 10px;
            text-decoration: none;
        }

        .logo-text {
            font-family: var(--font-display);
            font-size: 23px;
            font-weight: 600;
            letter-spacing: -0.01em;
            line-height: 1;
            color: var(--accent);
        }

        .header-right {
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .user-avatar {
            width: 32px;
            height: 32px;
            border-radius: 50%;
            border: 2px solid var(--accent);
            object-fit: cover;
        }

        .user-name {
            font-size: 13px;
            font-weight: 500;
            color: var(--text-secondary);
            max-width: 120px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        /* ── Buttons ── */
        .btn {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            padding: 10px 16px;
            border-radius: var(--radius-sm);
            font-size: 12px;
            font-weight: 600;
            font-family: inherit;
            border: 1px solid var(--glass-border);
            background: var(--glass);
            color: var(--text-primary);
            cursor: pointer;
            transition: var(--transition);
            white-space: nowrap;
            user-select: none;
            flex-shrink: 0;
            text-decoration: none;
        }

        .btn:hover {
            background: var(--bg-card-hover);
            border-color: rgba(255, 255, 255, 0.18);
            transform: translateY(-1px);
        }

        .btn:active {
            transform: translateY(0);
        }

        .btn-accent {
            background: var(--accent);
            border-color: transparent;
            color: var(--on-accent);
        }

        .btn-accent:hover {
            background: var(--accent-light);
            border-color: transparent;
        }

        .btn-danger {
            border-color: rgba(244, 63, 94, 0.3);
            color: var(--danger);
        }

        .btn-danger:hover {
            background: rgba(244, 63, 94, 0.1);
            border-color: rgba(244, 63, 94, 0.4);
        }

        .btn-sm {
            padding: 6px 12px;
            font-size: 11px;
            border-radius: var(--radius-xs);
        }

        .btn-active {
            border-color: var(--accent) !important;
            background: var(--accent-glow) !important;
            color: var(--accent) !important;
        }

        /* ── Toolbar — FIX: wrap nicely, all buttons same row, scroll on overflow ── */
        .toolbar {
            display: flex;
            align-items: center;
            gap: 8px;
            padding: 14px 32px;
            flex-wrap: nowrap;
            overflow-x: auto;
            scrollbar-width: none;
            border-bottom: 1px solid var(--glass-border);
            background: var(--bg-primary);
        }

        .toolbar::-webkit-scrollbar {
            display: none;
        }

        .toolbar .spacer {
            flex: 1;
            min-width: 8px;
        }

        .card-counter {
            font-size: 12px;
            color: var(--text-secondary);
            font-weight: 500;
            background: var(--glass);
            padding: 5px 12px;
            border-radius: 20px;
            border: 1px solid var(--glass-border);
            white-space: nowrap;
            flex-shrink: 0;
        }

        /* ── Card Stage ── */
        .card-stage {
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 32px 40px 52px;
            min-height: 480px;
            perspective: 1200px;
            background: var(--bg-primary);
        }

        .card-nav-btn {
            width: 44px;
            height: 44px;
            border-radius: 50%;
            border: 1px solid var(--glass-border);
            background: var(--glass);
            color: var(--text-primary);
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            transition: var(--transition);
            flex-shrink: 0;
            font-size: 20px;
        }

        .card-nav-btn:hover {
            background: var(--bg-card-hover);
            transform: scale(1.08);
        }

        .card-nav-btn:disabled {
            opacity: 0.3;
            cursor: not-allowed;
            transform: none;
        }

        /* ── Mobile Controls ── */
        .mobile-controls {
            display: none;
            width: 100%;
            max-width: 400px;
            margin: 16px auto 0;
            gap: 12px;
            justify-content: center;
            align-items: center;
        }

        .mobile-btn {
            background: var(--glass);
            border: 1px solid var(--glass-border);
            color: var(--text-primary);
            border-radius: 8px;
            padding: 12px 18px;
            font-size: 14px;
            font-weight: 600;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 6px;
            cursor: pointer;
            transition: var(--transition);
        }

        .mobile-btn:hover {
            background: var(--bg-card-hover);
            transform: translateY(-2px);
        }

        .mobile-btn:active {
            transform: translateY(0);
        }

        .mobile-btn:disabled {
            opacity: 0.3;
            cursor: not-allowed;
            transform: none;
        }

        .mobile-btn.flip-btn {
            flex: 1;
            background: var(--accent-glow);
            border-color: var(--accent);
            color: var(--text-primary);
        }

        .mobile-btn.flip-btn:hover {
            background: rgba(0, 30, 63, 0.16);
        }

        /* ── Flashcard ── */
        .card-container {
            width: 580px;
            max-width: calc(100vw - 160px);
            height: 360px;
            margin: 0 20px;
            position: relative;
            /* FIX: disable long-press text selection */
            -webkit-user-select: none;
            user-select: none;
            -webkit-touch-callout: none;
        }

        .card-inner {
            width: 100%;
            height: 100%;
            position: relative;
            transform-style: preserve-3d;
            transition: transform 0.7s cubic-bezier(0.4, 0, 0.2, 1);
        }

        .card-container.flipped .card-inner {
            transform: rotateY(180deg);
        }

        .card-face {
            position: absolute;
            inset: 0;
            backface-visibility: hidden;
            border-radius: 16px;
            border: 1px solid var(--glass-border);
            background: var(--bg-card);
            box-shadow: var(--shadow);
            display: flex;
            flex-direction: column;
            overflow: hidden;
        }

        .card-face.back {
            transform: rotateY(180deg);
            pointer-events: none;
        }

        /* Let the draw toolbar be dragged past the card's own edge */
        body.draw-mode .card-face {
            overflow: visible;
        }

        .card-container.flipped .card-face.front {
            pointer-events: none;
        }

        .card-container.flipped .card-face.back {
            pointer-events: auto;
        }

        .card-face-label {
            font-size: 11px;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 2px;
            color: var(--text-muted);
            padding: 14px 20px 0;
            display: flex;
            align-items: center;
            justify-content: space-between;
            flex-shrink: 0;
            /* FIX: no text selection on labels */
            -webkit-user-select: none;
            user-select: none;
        }

        .card-face-label .side-badge {
            background: var(--accent);
            color: var(--on-accent);
            padding: 3px 10px;
            border-radius: 20px;
            font-size: 11px;
            letter-spacing: 1.5px;
        }

        .card-face.back .card-face-label .side-badge {
            background: var(--accent-2);
        }

        .card-text {
            flex: 1;
            padding: 12px 24px 16px;
            font-size: 18px;
            line-height: 1.6;
            font-weight: 400;
            color: var(--text-primary);
            overflow-y: auto;
            outline: none;
            display: flex;
            align-items: center;
            justify-content: center;
            text-align: center;
            word-break: break-word;
            cursor: text;
            position: relative;
            z-index: 2;
            /* Allow text selection only when contenteditable */
            -webkit-user-select: text;
            user-select: text;
        }

        .card-text:empty::before {
            content: attr(data-placeholder);
            color: var(--text-muted);
            font-style: italic;
            pointer-events: none;
        }

        body.draw-mode .card-text:empty::before,
        .card-text.has-drawing:empty:not(:focus)::before {
            display: none;
        }

        body.draw-mode .card-flip-hint {
            opacity: 0.3;
        }

        body.draw-mode .card-face-label {
            opacity: 0.3;
        }

        .card-text:focus {
            background: var(--accent-glow);
            border-radius: 8px;
        }

        .card-flip-hint {
            font-size: 11px;
            color: var(--text-muted);
            text-align: center;
            padding: 0 20px 10px;
            flex-shrink: 0;
            letter-spacing: 0.5px;
            /* FIX: no selection */
            -webkit-user-select: none;
            user-select: none;
            pointer-events: none;
        }

        .flip-zone {
            position: absolute;
            inset: 0;
            z-index: 1;
            cursor: pointer;
            /* FIX: prevent long-press callout */
            -webkit-user-select: none;
            user-select: none;
            -webkit-touch-callout: none;
        }

        /* ── Drawing Canvas ── */
        /* Zoom scales the canvas element, which would otherwise let ink paint
           across the whole page. This box clips it back to the card. The draw
           toolbar is a sibling of this box, so it can still be dragged outside. */
        .canvas-clip {
            position: absolute;
            inset: 0;
            overflow: hidden;
            border-radius: 20px;
            z-index: 10;
            pointer-events: none;
        }

        .canvas-clip.pad {
            border-radius: 0 0 16px 16px;
        }

        .canvas-layer {
            position: absolute;
            inset: 0;
            border-radius: 20px;
            z-index: 10;
            pointer-events: none;
            cursor: crosshair;
            touch-action: none;
            /* FIX: overflow visible for zoom */
            transform-origin: 0 0;
        }

        .canvas-layer.active {
            pointer-events: auto;
        }

        /* ── Draw Toolbar — FIX: compact, draggable, small ── */
        .draw-toolbar {
            position: absolute;
            z-index: 20;
            display: none;
            background: var(--bg-card);
            border: 1px solid var(--glass-border);
            border-radius: 12px;
            padding: 6px 10px;
            gap: 6px;
            align-items: center;
            flex-wrap: nowrap;
            overflow-x: auto;
            scrollbar-width: none;
            max-width: calc(100% - 16px);
            box-shadow: var(--shadow);
            /* Start at top-right so it doesn't block the card center */
            bottom: auto;
            top: 12px;
            left: 50%;
            transform: translateX(-50%);
            cursor: grab;
            /* Compact height */
            min-height: 36px;
        }

        .draw-toolbar::-webkit-scrollbar {
            display: none;
        }

        /* Reflows to a vertical strip when dragged somewhere too narrow
           to fit the toolbar horizontally, or when manually locked. */
        .draw-toolbar.vertical {
            flex-direction: column;
            flex-wrap: nowrap;
            width: auto;
            max-width: none;
            max-height: calc(100vh - 24px);
            overflow-x: visible;
            overflow-y: auto;
        }

        .draw-toolbar.vertical .drag-handle {
            padding: 0 0 4px 0;
        }

        .draw-toolbar.vertical .sep {
            width: 14px;
            height: 1px;
            margin: 2px 0;
        }

        .draw-toolbar .orient-lock-btn {
            font-size: 12px;
        }

        .draw-toolbar.dragging {
            cursor: grabbing;
        }

        .draw-toolbar.active {
            display: flex;
        }

        .draw-toolbar .drag-handle {
            font-size: 11px;
            color: var(--text-muted);
            cursor: grab;
            padding: 0 4px 0 0;
            flex-shrink: 0;
            letter-spacing: 1px;
        }

        .color-swatch {
            width: 18px;
            height: 18px;
            border-radius: 50%;
            border: 2px solid transparent;
            cursor: pointer;
            transition: var(--transition);
            flex-shrink: 0;
        }

        .color-swatch:hover,
        .color-swatch.active {
            border-color: #fff;
            transform: scale(1.15);
        }

        .eraser-btn {
            display: flex;
            align-items: center;
            gap: 3px;
            padding: 3px 6px;
            border-radius: 6px;
            border: 2px solid transparent;
            background: rgba(255, 255, 255, 0.08);
            color: var(--text-secondary);
            cursor: pointer;
            transition: var(--transition);
            font-size: 11px;
            font-weight: 600;
            font-family: inherit;
            flex-shrink: 0;
            white-space: nowrap;
        }

        .eraser-btn:hover {
            background: rgba(255, 255, 255, 0.14);
            color: var(--text-primary);
        }

        .eraser-btn.active {
            border-color: var(--danger);
            background: rgba(244, 63, 94, 0.15);
            color: #fff;
        }

        .eraser-btn svg {
            width: 11px;
            height: 11px;
            fill: currentColor;
        }

        .draw-size {
            width: 40px;
            accent-color: var(--accent);
        }

        .draw-toolbar .sep {
            width: 1px;
            height: 14px;
            background: var(--glass-border);
            margin: 0 2px;
            flex-shrink: 0;
        }

        .undo-redo-btn {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 22px;
            height: 22px;
            border-radius: 5px;
            border: 1px solid rgba(255, 255, 255, 0.12);
            background: rgba(255, 255, 255, 0.06);
            color: var(--text-secondary);
            cursor: pointer;
            transition: var(--transition);
            font-size: 11px;
            flex-shrink: 0;
            padding: 0;
            font-family: inherit;
        }

        .undo-redo-btn:hover:not(:disabled) {
            background: rgba(255, 255, 255, 0.14);
            color: var(--text-primary);
        }

        .undo-redo-btn:disabled {
            opacity: 0.25;
            cursor: not-allowed;
        }

        /* ── Highlighter button ── */
        .highlighter-btn {
            display: flex;
            align-items: center;
            gap: 3px;
            padding: 3px 6px;
            border-radius: 6px;
            border: 2px solid transparent;
            background: rgba(255, 255, 255, 0.08);
            color: var(--text-secondary);
            cursor: pointer;
            transition: var(--transition);
            font-size: 11px;
            font-weight: 600;
            font-family: inherit;
            flex-shrink: 0;
            white-space: nowrap;
        }

        .highlighter-btn:hover {
            background: rgba(255, 255, 255, 0.14);
            color: var(--text-primary);
        }

        .highlighter-btn.active {
            border-color: var(--warning);
            background: rgba(245, 158, 11, 0.15);
            color: #fff;
        }

        .highlighter-btn svg {
            width: 12px;
            height: 12px;
            fill: currentColor;
        }

        /* ── Scratchpad ── */
        .scratchpad-container {
            display: none;
            flex-direction: column;
            width: 340px;
            height: 380px;
            background: var(--bg-card);
            border: 1px solid var(--glass-border);
            border-radius: 16px;
            box-shadow: var(--shadow);
            position: relative;
            flex-shrink: 0;
            margin-left: 24px;
        }

        body.scratchpad-open .scratchpad-container {
            display: flex;
            animation: fadeInRight 0.3s ease-out;
        }

        @keyframes fadeInRight {
            from {
                opacity: 0;
                transform: translateX(20px);
            }

            to {
                opacity: 1;
                transform: translateX(0);
            }
        }

        .scratchpad-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 14px 18px;
            border-bottom: 1px solid var(--glass-border);
            background: var(--bg-secondary);
            border-radius: 16px 16px 0 0;
        }

        .scratchpad-header span {
            font-size: 13px;
            font-weight: 700;
            color: var(--text-secondary);
            text-transform: uppercase;
            letter-spacing: 1px;
            display: flex;
            align-items: center;
            gap: 6px;
        }

        .scratchpad-body {
            flex: 1;
            position: relative;
            border-radius: 0 0 16px 16px;
            overflow: hidden;
            background: var(--bg-primary);
        }

        /* Let the scratchpad's draw toolbar be dragged past its own edge */
        body.scratchpad-open .scratchpad-body {
            overflow: visible;
        }

        .scratchpad-canvas {
            position: absolute;
            inset: 0;
            /* pointer-events inherits, and .canvas-clip sets none */
            pointer-events: auto;
            width: 100%;
            height: 100%;
            border-radius: 0 0 16px 16px;
            cursor: crosshair;
            touch-action: none;
            z-index: 10;
        }

        /* ── Card Grid ── */
        .card-grid-section {
            padding: 0 32px 60px;
            background: var(--bg-primary);
        }

        .section-header {
            font-size: 13px;
            font-weight: 700;
            color: var(--text-secondary);
            text-transform: uppercase;
            letter-spacing: 1.5px;
            margin-bottom: 14px;
            padding-left: 4px;
        }

        .card-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
            gap: 16px;
        }

        .grid-card {
            background: var(--bg-card);
            border: 1px solid var(--glass-border);
            border-radius: var(--radius-sm);
            padding: 20px;
            cursor: pointer;
            transition: var(--transition);
            position: relative;
            min-height: 110px;
            display: flex;
            flex-direction: column;
            justify-content: center;
        }

        .grid-card:hover {
            background: var(--bg-card-hover);
            box-shadow: var(--shadow);
            border-color: var(--accent);
        }

        .grid-card.active {
            border-color: var(--accent);
            background: var(--accent-glow);
        }

        .grid-card-drawing-preview {
            width: 100%;
            height: auto;
            max-height: 60px;
            object-fit: contain;
            margin-bottom: 8px;
            border-radius: 6px;
            pointer-events: none;
            background: var(--bg-secondary);
        }

        .grid-card .gc-front {
            font-size: 13px;
            font-weight: 600;
            color: var(--text-primary);
            margin-bottom: 4px;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            line-clamp: 2;
            -webkit-box-orient: vertical;
        }

        .grid-card .gc-back {
            font-size: 11px;
            color: var(--text-muted);
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 1;
            line-clamp: 1;
            -webkit-box-orient: vertical;
        }

        .grid-card .gc-num {
            position: absolute;
            top: 8px;
            right: 10px;
            font-size: 11px;
            font-weight: 700;
            color: var(--text-muted);
        }

        .grid-card .gc-delete {
            position: absolute;
            bottom: 8px;
            right: 8px;
            width: 24px;
            height: 24px;
            border-radius: 6px;
            border: none;
            background: transparent;
            color: var(--text-muted);
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 14px;
            transition: var(--transition);
            opacity: 0;
        }

        .grid-card:hover .gc-delete {
            opacity: 1;
        }

        .grid-card .gc-delete:hover {
            color: var(--danger);
            background: rgba(244, 63, 94, 0.1);
        }

        .grid-card.add-card {
            border-style: dashed;
            border-color: var(--glass-border);
            align-items: center;
            color: var(--text-secondary);
            font-size: 13px;
            font-weight: 600;
            gap: 4px;
            flex-direction: column;
            background: var(--bg-primary);
        }

        .grid-card.add-card:hover {
            border-color: var(--accent);
            color: var(--accent);
            background: var(--accent-glow);
        }

        .grid-card.add-card .plus {
            font-size: 28px;
            line-height: 1;
        }

        /* ── Empty State ── */
        .empty-state {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            padding: 60px 20px;
            text-align: center;
            animation: fadeInUp 0.6s ease-out;
        }

        .empty-state h2 {
            font-family: var(--font-display);
            font-size: 27px;
            font-weight: 500;
            letter-spacing: -0.01em;
            line-height: 1.15;
            margin-bottom: 8px;
        }

        .empty-state p {
            color: var(--text-secondary);
            font-size: 14px;
            margin-bottom: 24px;
            max-width: 360px;
            line-height: 1.5;
        }

        /* ── Confirm Modal ── */
        .modal-overlay {
            position: fixed;
            inset: 0;
            z-index: 200;
            background: rgba(0, 0, 0, 0.4);
            display: flex;
            align-items: center;
            justify-content: center;
            animation: modalFadeIn 0.2s ease;
        }

        .modal-box {
            background: var(--bg-card);
            border: 1px solid var(--glass-border);
            border-radius: var(--radius);
            padding: 32px 36px;
            max-width: 400px;
            width: 90%;
            box-shadow: var(--shadow);
            animation: fadeInUp 0.25s ease-out;
        }

        .modal-box h3 {
            font-size: 16px;
            font-weight: 700;
            margin-bottom: 8px;
        }

        .modal-box p {
            font-size: 13px;
            color: var(--text-secondary);
            margin-bottom: 20px;
            line-height: 1.5;
        }

        .modal-actions {
            display: flex;
            gap: 10px;
            justify-content: flex-end;
        }

        @keyframes modalFadeIn {
            from {
                opacity: 0;
            }

            to {
                opacity: 1;
            }
        }

        /* ── Toast ── */
        .toast-container {
            position: fixed;
            bottom: 28px;
            right: 28px;
            z-index: 9999;
            display: flex;
            flex-direction: column;
            gap: 10px;
        }

        .toast {
            background: var(--bg-secondary);
            border: 1px solid var(--glass-border);
            border-radius: var(--radius-sm);
            padding: 14px 22px;
            font-size: 13px;
            font-weight: 500;
            color: var(--text-primary);
            box-shadow: var(--shadow);
            animation: toastIn 0.3s ease-out;
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .toast.success {
            border-color: var(--success);
        }

        .toast.error {
            border-color: var(--danger);
        }

        .toast.info {
            border-color: var(--accent-2);
        }

        @keyframes toastIn {
            from {
                opacity: 0;
                transform: translateX(40px);
            }

            to {
                opacity: 1;
                transform: translateX(0);
            }
        }

        /* ── Sync indicator ── */
        .sync-indicator {
            display: flex;
            align-items: center;
            gap: 6px;
            font-size: 11px;
            color: var(--text-muted);
        }

        .sync-dot {
            width: 6px;
            height: 6px;
            border-radius: 50%;
            background: var(--success);
            flex-shrink: 0;
        }

        .sync-dot.syncing {
            background: var(--warning);
            animation: pulse 1s ease infinite;
        }

        @keyframes pulse {

            0%,
            100% {
                opacity: 1;
            }

            50% {
                opacity: 0.4;
            }
        }

        /* ── Loading spinner ── */
        .spinner {
            width: 18px;
            height: 18px;
            border: 2px solid rgba(255, 255, 255, 0.2);
            border-top-color: #fff;
            border-radius: 50%;
            animation: spin 0.6s linear infinite;
            display: inline-block;
        }

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

        /* ── Deck Bar ── */
        /* ── Sidebar toggle (header) ── */
        .sidebar-toggle-btn {
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 7px 8px;
        }

        .sidebar-toggle-btn svg {
            width: 16px;
            height: 16px;
            fill: none;
            stroke: currentColor;
            stroke-width: 1.8;
            stroke-linecap: round;
        }

        /* ── App body / Sidebar ── */
        .app-body {
            display: flex;
            align-items: stretch;
        }

        .sidebar {
            width: 260px;
            flex-shrink: 0;
            display: flex;
            flex-direction: column;
            background: var(--bg-secondary);
            border-right: 1px solid var(--glass-border);
            overflow: hidden;
            transition: width 0.2s ease, opacity 0.2s ease;
        }

        body:not(.sidebar-open) .sidebar {
            width: 0;
            opacity: 0;
            border-right-color: transparent;
        }

        .main-content {
            flex: 1;
            min-width: 0;
            display: flex;
            flex-direction: column;
        }

        .sidebar-header {
            padding: 18px 18px 8px;
            font-size: 11px;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 1.5px;
            color: var(--text-muted);
            flex-shrink: 0;
            white-space: nowrap;
        }

        .sidebar-actions {
            display: flex;
            flex-direction: column;
            gap: 6px;
            padding: 4px 12px 12px;
            flex-shrink: 0;
        }

        .sidebar-action-btn {
            display: flex;
            align-items: center;
            gap: 8px;
            padding: 8px 10px;
            border-radius: 8px;
            border: 1px dashed var(--glass-border);
            background: var(--bg-primary);
            color: var(--text-secondary);
            font-size: 13px;
            font-weight: 600;
            font-family: inherit;
            cursor: pointer;
            transition: var(--transition);
            white-space: nowrap;
        }

        .sidebar-action-btn:hover {
            border-color: var(--accent);
            color: var(--accent);
            background: var(--accent-glow);
        }

        .sidebar-list {
            flex: 1;
            overflow-y: auto;
            padding: 4px 10px 16px;
        }

        .sidebar-row {
            display: flex;
            align-items: center;
            gap: 7px;
            padding: 7px 8px;
            border-radius: 8px;
            cursor: pointer;
            color: var(--text-secondary);
            font-size: 13px;
            font-weight: 600;
            white-space: nowrap;
            transition: var(--transition);
        }

        .sidebar-row:hover {
            background: var(--bg-card-hover);
        }

        .sidebar-row.active {
            background: var(--accent-glow);
            color: var(--accent);
        }

        .sidebar-row.nested {
            padding-left: 28px;
        }

        .sidebar-row.dragging {
            opacity: 0.4;
        }

        .sidebar-row.drop-target {
            background: var(--accent-2-glow);
            outline: 1.5px dashed var(--accent-2);
            outline-offset: -1.5px;
        }

        .node-icon {
            width: 15px;
            height: 15px;
            flex-shrink: 0;
            fill: none;
            stroke: currentColor;
            stroke-width: 1.6;
            stroke-linejoin: round;
            color: var(--text-muted);
        }

        .sidebar-row.active .node-icon {
            color: var(--accent);
        }

        .node-name {
            flex: 1;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .node-actions {
            display: none;
            gap: 2px;
            flex-shrink: 0;
        }

        .sidebar-row:hover .node-actions {
            display: flex;
        }

        .node-action-btn {
            background: none;
            border: none;
            color: inherit;
            cursor: pointer;
            font-size: 11px;
            padding: 2px 3px;
            opacity: 0.6;
            border-radius: 4px;
            font-family: inherit;
        }

        .node-action-btn:hover {
            opacity: 1;
            background: rgba(255, 255, 255, 0.08);
        }

        .folder-caret {
            width: 10px;
            flex-shrink: 0;
            font-size: 11px;
            color: var(--text-muted);
            display: inline-block;
            transition: transform 0.15s ease;
        }

        .sidebar-folder.expanded .folder-caret {
            transform: rotate(90deg);
        }

        .sidebar-folder-decks {
            display: none;
        }

        .sidebar-folder.expanded .sidebar-folder-decks {
            display: block;
        }

        .sidebar-top-decks {
            margin-top: 4px;
        }

        /* ── Deck Modal ── */
        .deck-modal-overlay {
            position: fixed;
            inset: 0;
            z-index: 200;
            background: rgba(0, 0, 0, 0.4);
            display: flex;
            align-items: center;
            justify-content: center;
            animation: modalFadeIn 0.2s ease;
        }

        .deck-modal {
            background: var(--bg-card);
            border: 1px solid var(--glass-border);
            border-radius: var(--radius);
            padding: 32px 36px;
            max-width: 420px;
            width: 90%;
            box-shadow: var(--shadow);
            animation: fadeInUp 0.25s ease-out;
        }

        .deck-modal h3 {
            font-size: 16px;
            font-weight: 700;
            margin-bottom: 16px;
        }

        .deck-modal input {
            width: 100%;
            padding: 10px 14px;
            border-radius: var(--radius-xs);
            border: 1px solid var(--glass-border);
            background: var(--bg-primary);
            color: var(--text-primary);
            font-size: 14px;
            font-family: inherit;
            outline: none;
            margin-bottom: 16px;
        }

        .deck-modal input:focus {
            border-color: var(--accent);
        }

        .deck-modal .modal-actions {
            display: flex;
            gap: 10px;
            justify-content: flex-end;
        }

        /* ── Responsive ── */
        @media (max-width: 768px) {
            .maintenance-screen {
                padding: 20px 24px 48px;
            }

            .maintenance-watermark {
                width: 420px;
                height: 420px;
                right: -110px;
                bottom: -110px;
            }

            .maintenance-content h1 {
                font-size: 30px;
            }

            header {
                padding: 14px 20px;
            }

            .toolbar {
                padding: 10px 16px;
                gap: 6px;
            }

            .card-stage {
                padding: 24px 12px 40px;
                min-height: 400px;
                flex-wrap: wrap;
                gap: 16px;
            }

            .card-container {
                width: 100%;
                max-width: calc(100vw - 32px);
                height: 320px;
                margin: 0;
            }

            .card-nav-btn {
                display: none;
            }

            .mobile-controls {
                display: flex;
            }

            .scratchpad-container {
                margin-left: 0;
                width: 100%;
                max-width: calc(100vw - 100px);
            }

            .card-text {
                font-size: 16px;
                padding: 10px 18px 14px;
            }

            .card-grid-section {
                padding: 0 20px 44px;
            }

            .card-grid {
                grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
                gap: 12px;
            }

            .user-name {
                display: none;
            }

            .app-body {
                position: relative;
            }

            .sidebar {
                position: fixed;
                top: 0;
                left: 0;
                height: 100vh;
                padding-top: 60px;
                z-index: 90;
                width: 260px !important;
                opacity: 1 !important;
                border-right-color: var(--glass-border) !important;
                box-shadow: var(--shadow);
                transform: translateX(-100%);
                transition: transform 0.25s ease;
            }

            body.sidebar-open .sidebar {
                transform: translateX(0);
            }

            .login-card {
                padding: 36px 28px;
            }
        }

        @media (max-width: 480px) {
            header {
                padding: 12px 14px;
                gap: 8px;
            }

            header .logo-text {
                font-size: 18px;
            }

            .header-logo {
                height: 25px;
                width: 29px;
            }

            .header-right {
                gap: 6px;
            }

            .sync-indicator {
                display: none;
            }

            .user-avatar {
                width: 32px;
                height: 32px;
            }

            .toolbar {
                padding: 8px 12px;
                gap: 5px;
            }

            .btn {
                padding: 8px 12px;
                font-size: 12px;
                gap: 4px;
                border-radius: 8px;
            }

            .card-counter {
                font-size: 12px;
                padding: 6px 12px;
            }

            .card-stage {
                padding: 16px 8px 32px;
                min-height: 340px;
            }

            .card-container {
                height: 260px;
                margin: 0;
                max-width: calc(100vw - 24px);
            }

            .card-face-label {
                padding: 10px 14px 0;
                font-size: 11px;
            }

            .card-face-label .side-badge {
                font-size: 11px;
                padding: 2px 8px;
            }

            .card-text {
                font-size: 14px;
                padding: 8px 14px 10px;
                line-height: 1.5;
            }

            .card-flip-hint {
                font-size: 11px;
                padding: 0 14px 6px;
            }

            .card-face {
                border-radius: 14px;
            }

            .canvas-layer {
                border-radius: 14px;
            }

            .card-grid-section {
                padding: 0 14px 40px;
            }

            .section-header {
                font-size: 12px;
                margin-bottom: 12px;
            }

            .card-grid {
                grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
                gap: 10px;
            }

            .grid-card {
                padding: 14px;
                min-height: 90px;
                border-radius: 8px;
            }

            .grid-card .gc-front {
                font-size: 12px;
            }

            .grid-card .gc-back {
                font-size: 11px;
            }

            .login-card {
                padding: 36px 28px;
                border-radius: 14px;
                margin: auto;
            }

            .login-brand .header-logo {
                height: 41px;
                width: 48px;
            }

            .login-brand .logo-text {
                font-size: 29px;
            }

            .login-card p {
                font-size: 14px;
                margin-bottom: 28px;
            }

            .btn-google {
                padding: 12px 28px;
                font-size: 14px;
            }

            .toast-container {
                bottom: 14px;
                right: 14px;
                left: 14px;
            }

            .toast {
                font-size: 13px;
                padding: 12px 16px;
            }

            .empty-state {
                padding: 48px 18px;
            }

            .empty-state h2 {
                font-size: 20px;
            }

            .empty-state p {
                font-size: 14px;
            }

            .modal-box {
                padding: 26px 28px;
            }
        }

        @media (pointer: coarse) {
            .card-nav-btn {
                width: 44px;
                height: 44px;
            }

            .btn {
                min-height: 38px;
            }

            .gc-delete {
                width: 32px;
                height: 32px;
                opacity: 1 !important;
            }

            .color-swatch {
                width: 24px;
                height: 24px;
            }

            .eraser-btn {
                min-height: 26px;
            }
        }

        ::-webkit-scrollbar {
            width: 8px;
        }

        ::-webkit-scrollbar-track {
            background: transparent;
        }

        ::-webkit-scrollbar-thumb {
            background: rgba(107, 107, 118, 0.2);
            border-radius: 4px;
        }

        ::-webkit-scrollbar-thumb:hover {
            background: rgba(107, 107, 118, 0.35);
        }

        ::selection {
            background: var(--accent-glow);
            color: var(--text-primary);
        }

        /* -- Study / Quiz tabs -- */
        .mode-tabs {
            display: flex;
            gap: 4px;
            padding: 12px 32px 0;
            border-bottom: 1px solid var(--glass-border);
        }

        .mode-tab {
            font: inherit;
            font-size: 13px;
            font-weight: 600;
            color: var(--text-secondary);
            background: transparent;
            border: none;
            border-bottom: 2px solid transparent;
            padding: 8px 14px 10px;
            margin-bottom: -1px;
            cursor: pointer;
            transition: color var(--transition), border-color var(--transition);
        }

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

        .mode-tab.active {
            color: var(--accent);
            border-bottom-color: var(--accent-2);
        }

        /* -- Quiz -- */
        .quiz-screen {
            display: none;
            padding: 30px 32px 70px;
            max-width: 740px;
        }

        body.quiz-mode .quiz-screen {
            display: block;
            animation: fadeInUp 0.35s ease-out;
        }

        /* The study views set display inline, so these have to win outright. */
        body.quiz-mode .toolbar,
        body.quiz-mode .card-stage,
        body.quiz-mode .empty-state,
        body.quiz-mode .card-grid-section {
            display: none !important;
        }

        .quiz-run,
        .quiz-results {
            display: none;
        }

        .quiz-screen.run .quiz-setup,
        .quiz-screen.done .quiz-setup {
            display: none;
        }

        .quiz-screen.run .quiz-run,
        .quiz-screen.done .quiz-results {
            display: block;
        }

        .quiz-screen h2 {
            font-family: var(--font-display);
            font-size: 32px;
            font-weight: 500;
            letter-spacing: -0.012em;
            line-height: 1.12;
            color: var(--text-primary);
            margin-bottom: 9px;
        }

        .quiz-setup p,
        .quiz-results p {
            color: var(--text-secondary);
            font-size: 14px;
            line-height: 1.6;
            margin-bottom: 26px;
            max-width: 500px;
        }

        .quiz-modes {
            display: flex;
            gap: 14px;
            flex-wrap: wrap;
        }

        .quiz-mode-card {
            flex: 1 1 250px;
            display: flex;
            flex-direction: column;
            gap: 6px;
            text-align: left;
            font: inherit;
            background: var(--bg-card);
            border: 1px solid var(--glass-border);
            border-radius: var(--radius);
            padding: 18px 20px 17px;
            cursor: pointer;
            transition: var(--transition);
        }

        .quiz-mode-card:hover:not(:disabled) {
            border-color: var(--accent);
            border-left-color: var(--accent-2);
            box-shadow: var(--shadow);
        }

        .quiz-mode-card:disabled {
            opacity: 0.55;
            cursor: not-allowed;
            border-left-color: var(--glass-border);
        }

        .qm-name {
            font-size: 15px;
            font-weight: 700;
            color: var(--text-primary);
        }

        .qm-desc {
            font-size: 13px;
            line-height: 1.5;
            color: var(--text-secondary);
        }

        .qm-note {
            font-size: 11px;
            font-weight: 700;
            letter-spacing: 0.06em;
            text-transform: uppercase;
            color: var(--text-muted);
            margin-top: 2px;
        }

        .quiz-progress {
            display: flex;
            align-items: center;
            gap: 14px;
            margin-bottom: 20px;
        }

        .quiz-progress-bar {
            flex: 1;
            height: 4px;
            border-radius: 999px;
            background: var(--bg-secondary);
            border: 1px solid var(--glass-border);
            overflow: hidden;
        }

        .quiz-progress-bar span {
            display: block;
            height: 100%;
            width: 0;
            background: var(--accent-2);
            transition: width 0.25s ease;
        }

        .quiz-count,
        .quiz-score {
            font-size: 11px;
            font-weight: 700;
            letter-spacing: 0.07em;
            text-transform: uppercase;
            color: var(--text-muted);
            flex-shrink: 0;
        }

        .quiz-card {
            background: var(--bg-card);
            border: 1px solid var(--glass-border);
            border-radius: var(--radius);
            box-shadow: var(--shadow);
            padding: 22px 24px 24px;
            margin-bottom: 18px;
        }

        .quiz-card-label {
            display: block;
            font-size: 11px;
            font-weight: 700;
            letter-spacing: 0.1em;
            text-transform: uppercase;
            color: var(--text-muted);
            margin-bottom: 10px;
        }

        .quiz-prompt {
            font-size: 19px;
            font-weight: 600;
            line-height: 1.45;
            color: var(--text-primary);
            white-space: pre-wrap;
        }

        /* display:block beats the UA stylesheet's [hidden] rule, so restore it */
        .quiz-drawing[hidden] {
            display: none;
        }

        .quiz-drawing {
            display: block;
            max-width: 100%;
            max-height: 230px;
            margin-top: 14px;
            border: 1px solid var(--glass-border);
            border-radius: var(--radius-sm);
            background: var(--bg-primary);
        }

        .quiz-answers {
            display: flex;
            flex-direction: column;
            gap: 9px;
        }

        .quiz-option {
            display: flex;
            align-items: flex-start;
            gap: 12px;
            font: inherit;
            font-size: 14px;
            line-height: 1.5;
            text-align: left;
            white-space: pre-wrap;
            color: var(--text-primary);
            background: var(--bg-card);
            border: 1px solid var(--glass-border);
            border-radius: var(--radius-sm);
            padding: 13px 16px;
            cursor: pointer;
            transition: var(--transition);
        }

        .quiz-option:hover:not(:disabled) {
            border-color: var(--accent);
            background: var(--bg-card-hover);
        }

        .quiz-option:disabled {
            cursor: default;
        }

        .opt-key {
            font-size: 11px;
            font-weight: 800;
            letter-spacing: 0.06em;
            color: var(--text-muted);
            flex-shrink: 0;
            padding-top: 3px;
        }

        .quiz-option.right {
            border-color: var(--success);
        }

        .quiz-option.right .opt-key {
            color: var(--success);
        }

        .quiz-option.wrong {
            border-color: var(--danger);
        }

        .quiz-option.wrong .opt-key {
            color: var(--danger);
        }

        .quiz-reveal {
            background: var(--bg-secondary);
            border: 1px solid var(--glass-border);
            border-radius: var(--radius);
            padding: 20px 22px;
        }

        .quiz-answer-text {
            font-size: 16px;
            line-height: 1.5;
            color: var(--text-primary);
            white-space: pre-wrap;
        }

        .quiz-actions {
            display: flex;
            gap: 10px;
            flex-wrap: wrap;
            margin-top: 20px;
        }

        .quiz-quit {
            font: inherit;
            font-size: 12px;
            color: var(--text-muted);
            background: none;
            border: none;
            padding: 0;
            margin-top: 18px;
            cursor: pointer;
            text-decoration: underline;
        }

        .quiz-quit:hover {
            color: var(--danger);
        }

        .quiz-scoreline {
            font-size: 38px;
            font-weight: 800;
            letter-spacing: -0.02em;
            color: var(--accent);
            margin-bottom: 4px;
        }

        .quiz-missed {
            margin-top: 24px;
        }

        .quiz-missed h3 {
            font-size: 11px;
            font-weight: 700;
            letter-spacing: 0.08em;
            text-transform: uppercase;
            color: var(--text-muted);
            margin-bottom: 11px;
        }

        .quiz-missed ul {
            list-style: none;
            margin: 0;
            padding: 0;
            display: flex;
            flex-direction: column;
            gap: 8px;
        }

        .quiz-missed li {
            border: 1px solid var(--glass-border);
            border-radius: var(--radius-sm);
            padding: 11px 15px;
            font-size: 13.5px;
            line-height: 1.5;
            color: var(--text-secondary);
        }

        .quiz-missed li strong {
            display: block;
            font-weight: 600;
            color: var(--text-primary);
            margin-bottom: 2px;
        }

        @media (max-width: 720px) {
            .mode-tabs {
                padding: 10px 14px 0;
            }

            .quiz-screen {
                padding: 22px 16px 60px;
            }

            .quiz-screen h2 {
                font-size: 22px;
            }

            .quiz-prompt {
                font-size: 17px;
            }

            .quiz-scoreline {
                font-size: 31px;
            }

            .quiz-actions .btn {
                flex: 1 1 auto;
            }
        }

        /* ── Consent screens (cookies, terms, account confirmation) ── */
        .consent-overlay {
            display: none;
            position: fixed;
            inset: 0;
            z-index: 900;
            background: var(--bg-primary);
            padding: 32px 24px;
            overflow-y: auto;
            align-items: center;
        }

        .consent-overlay.visible {
            display: flex;
        }

        .consent-card {
            background: var(--glass);
            border: 1px solid var(--glass-border);
            border-radius: 16px;
            box-shadow: var(--shadow);
            padding: 36px 36px 32px;
            width: 100%;
            max-width: 520px;
            margin: auto auto auto 8vw;
            animation: fadeInUp 0.45s ease-out;
        }

        .consent-brand {
            margin-bottom: 22px;
        }

        .consent-brand .header-logo {
            height: 26px;
            width: 31px;
        }

        .consent-brand .logo-text {
            font-size: 17px;
        }

        .consent-eyebrow {
            display: block;
            font-size: 11px;
            font-weight: 700;
            letter-spacing: 0.09em;
            text-transform: uppercase;
            color: var(--accent-2);
            margin-bottom: 10px;
        }

        .consent-card h2 {
            font-size: 27px;
            font-weight: 800;
            line-height: 1.2;
            color: var(--text-primary);
            margin-bottom: 14px;
        }

        .consent-card p {
            color: var(--text-secondary);
            font-size: 14px;
            line-height: 1.6;
            margin-bottom: 18px;
        }

        .consent-card a {
            color: var(--accent);
            font-weight: 600;
        }

        .consent-list {
            list-style: none;
            margin: 0 0 20px;
            padding: 0;
            border-top: 1px solid var(--glass-border);
        }

        .consent-list li {
            position: relative;
            padding: 11px 0 11px 22px;
            border-bottom: 1px solid var(--glass-border);
            font-size: 13px;
            line-height: 1.55;
            color: var(--text-secondary);
        }

        .consent-list li::before {
            content: '›';
            position: absolute;
            left: 2px;
            top: 10px;
            color: var(--accent-2);
            font-weight: 700;
        }

        .consent-list strong {
            color: var(--text-primary);
            font-weight: 600;
        }

        .consent-fineprint {
            font-size: 12.5px;
            color: var(--text-muted);
        }

        .consent-actions {
            display: flex;
            flex-wrap: wrap;
            gap: 10px;
            align-items: center;
            margin-top: 4px;
        }

        .consent-actions .btn {
            padding: 12px 20px;
            font-size: 13px;
        }

        .consent-actions .btn:disabled {
            opacity: 0.45;
            cursor: not-allowed;
            transform: none;
        }

        /* Account confirmation */
        .gate-identity {
            display: flex;
            align-items: center;
            gap: 14px;
            padding: 16px 18px;
            margin-bottom: 20px;
            background: var(--bg-secondary);
            border: 1px solid var(--glass-border);
            border-radius: var(--radius);
        }

        .gate-avatar {
            width: 44px;
            height: 44px;
            border-radius: 50%;
            flex-shrink: 0;
            object-fit: cover;
            border: 1px solid var(--glass-border);
        }

        .gate-identity-text {
            display: flex;
            flex-direction: column;
            gap: 3px;
            min-width: 0;
        }

        .gate-name {
            font-size: 13px;
            font-weight: 600;
            color: var(--text-secondary);
        }

        .gate-email {
            font-size: 16px;
            font-weight: 700;
            color: var(--text-primary);
            word-break: break-all;
            line-height: 1.3;
        }

        .gate-terms {
            margin-bottom: 22px;
        }

        .gate-terms-label {
            display: flex;
            align-items: flex-start;
            gap: 11px;
            font-size: 13px;
            line-height: 1.55;
            color: var(--text-secondary);
            cursor: pointer;
        }

        .gate-terms-label input[type="checkbox"] {
            margin-top: 2px;
            width: 17px;
            height: 17px;
            flex-shrink: 0;
            accent-color: var(--accent);
            cursor: pointer;
        }

        .login-legal {
            font-size: 11.5px;
            color: var(--text-muted);
            line-height: 1.5;
            margin: 14px 0 0;
        }

        .login-legal a {
            color: var(--text-muted);
            text-decoration: underline;
        }

        .login-legal a:hover {
            color: var(--accent);
        }

        @media (max-width: 720px) {
            .consent-card {
                margin: auto;
                padding: 28px 22px 26px;
            }

            .consent-card h2 {
                font-size: 22px;
            }

            .consent-actions .btn {
                width: 100%;
                justify-content: center;
            }
        }

        /* ── Terms and Conditions page ── */
        .legal-page {
            position: relative;
            z-index: 1;
            max-width: 780px;
            margin: 0 auto;
            padding: 28px 24px 90px;
        }

        .legal-header {
            position: sticky;
            top: 0;
            z-index: 5;
            background: var(--bg-primary);
            padding-top: 18px;
            margin-top: -28px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 16px;
            flex-wrap: wrap;
            padding-bottom: 22px;
            border-bottom: 1px solid var(--glass-border);
        }

        .legal-watermark {
            position: fixed;
            width: 560px;
            height: 560px;
            right: -240px;
            bottom: -250px;
            color: var(--accent);
            opacity: 0.04;
            pointer-events: none;
            z-index: 0;
        }

        .legal-watermark polygon {
            fill: currentColor;
        }

        .legal-brand .header-logo,
        .legal-brand .logo-text {
            transition: color var(--transition);
        }

        .legal-brand:hover .header-logo,
        .legal-brand:hover .logo-text {
            color: var(--accent-2);
        }

        .legal-hero {
            padding: 46px 0 34px;
            max-width: 620px;
        }

        .legal-hero h1 {
            font-family: var(--font-display);
            font-size: 44px;
            font-weight: 500;
            letter-spacing: -0.014em;
            line-height: 1.08;
            color: var(--text-primary);
            margin-bottom: 14px;
        }

        .legal-hero p {
            color: var(--text-secondary);
            font-size: 15px;
            line-height: 1.6;
            max-width: 56ch;
        }

        .legal-meta {
            display: flex;
            gap: 10px;
            flex-wrap: wrap;
            margin-top: 18px;
            font-size: 11px;
            font-weight: 700;
            letter-spacing: 0.07em;
            text-transform: uppercase;
            color: var(--text-muted);
        }

        .legal-meta span {
            border: 1px solid var(--glass-border);
            border-radius: 999px;
            padding: 5px 12px;
        }

        .legal-toc {
            border: 1px solid var(--glass-border);
            border-radius: var(--radius);
            background: var(--bg-secondary);
            padding: 18px 22px;
            margin-bottom: 40px;
        }

        .legal-toc h2 {
            font-size: 11px;
            font-weight: 700;
            letter-spacing: 0.09em;
            text-transform: uppercase;
            color: var(--text-muted);
            margin-bottom: 10px;
        }

        .legal-toc ol {
            columns: 2;
            column-gap: 30px;
            margin: 0;
            padding-left: 18px;
        }

        .legal-toc li {
            font-size: 13px;
            line-height: 1.9;
            break-inside: avoid;
        }

        .legal-toc a {
            color: var(--text-secondary);
            text-decoration: none;
        }

        .legal-toc a:hover {
            color: var(--accent);
            text-decoration: underline;
        }

        .legal-section {
            padding-top: 34px;
            scroll-margin-top: 20px;
        }

        .legal-num {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 28px;
            height: 28px;
            margin-right: 11px;
            flex-shrink: 0;
            font-size: 12px;
            font-weight: 800;
            color: var(--bg-primary);
            background: var(--accent);
            clip-path: polygon(100% 50%, 75% 93.3%, 25% 93.3%, 0 50%, 25% 6.7%, 75% 6.7%);
        }

        .legal-section h2 {
            display: flex;
            align-items: center;
            font-size: 20px;
            font-weight: 700;
            color: var(--text-primary);
            margin-bottom: 12px;
        }

        .legal-section h3 {
            font-size: 14px;
            font-weight: 700;
            color: var(--text-primary);
            margin: 20px 0 8px;
        }

        /* The page stays 780px wide for the header, TOC and callouts, but running
           prose is capped to a readable measure instead of filling it. */
        .legal-section p,
        .legal-section li {
            color: var(--text-secondary);
            font-size: 14.5px;
            line-height: 1.68;
            max-width: 58ch;
        }

        .legal-section p {
            margin-bottom: 13px;
        }

        .legal-section ul,
        .legal-section ol {
            margin: 0 0 14px;
            padding-left: 20px;
        }

        .legal-section li {
            margin-bottom: 7px;
        }

        .legal-section a {
            color: var(--accent);
            font-weight: 600;
        }

        .legal-section strong {
            color: var(--text-primary);
            font-weight: 600;
        }

        .legal-callout {
            border: 1px solid var(--warning);
            border-radius: var(--radius-sm);
            background: var(--warning-tint);
            padding: 15px 18px;
            margin: 16px 0 6px;
        }

        .legal-callout p:last-child {
            margin-bottom: 0;
        }

        .legal-footer .header-logo {
            height: 21px;
            width: 25px;
            color: var(--text-muted);
            margin-right: 8px;
        }

        .legal-footer-brand {
            display: flex;
            align-items: center;
        }

        .legal-footer {
            margin-top: 56px;
            padding-top: 22px;
            border-top: 1px solid var(--glass-border);
            display: flex;
            justify-content: space-between;
            align-items: center;
            gap: 16px;
            flex-wrap: wrap;
            font-size: 12px;
            color: var(--text-muted);
        }

        .legal-footer a {
            color: var(--text-muted);
            text-decoration: underline;
        }

        .legal-footer a:hover {
            color: var(--accent);
        }

        @media (max-width: 720px) {
            .legal-hero h1 {
                font-size: 28px;
            }

            .legal-toc ol {
                columns: 1;
            }

            .legal-page {
                padding: 22px 18px 70px;
            }

            .legal-header {
                margin-top: -22px;
            }

            .legal-watermark {
                width: 360px;
                height: 360px;
                right: -120px;
                bottom: -130px;
            }
        }
