/* Styles for /flashcards (moved out of the page so browsers can cache them) */
        :root { --color-success: #10b981; --color-warning: #f59e0b; --color-danger: #ef4444; }

        /* Dark mode support (same palette as the home page) */
        
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        [hidden] {
            display: none !important;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
            background-color: var(--color-light);
            color: var(--color-text);
            line-height: 1.6;
        }

        /* Header */
        header {
            background: var(--color-white);
            box-shadow: var(--shadow-sm);
            position: sticky;
            top: 0;
            z-index: 100;
        }

        nav {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 1.2rem 2rem;
            max-width: 1200px;
            margin: 0 auto;
            gap: 1rem;
        }

        .logo {
            display: flex;
            align-items: center;
            gap: 0.5rem;
            font-size: 1.5rem;
            font-weight: 700;
            color: var(--color-link);
            text-decoration: none;
            flex-shrink: 0;
        }

        .user-welcome {
            color: var(--color-gray);
            font-size: 0.95rem;
        }

        .nav-right {
            display: flex;
            gap: 1rem;
            align-items: center;
        }

        .btn {
            padding: 0.6rem 1.2rem;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            font-weight: 600;
            transition: all 0.3s ease;
            text-decoration: none;
            display: inline-block;
            white-space: nowrap;
        }

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

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

        .btn-secondary {
            background-color: var(--color-light);
            color: var(--color-text);
            box-shadow: inset 0 0 0 1px var(--color-border);
        }

        .btn-secondary:hover {
            background-color: #f4f1ea;
        }

        .btn-danger {
            background-color: #c81e1e;
            color: white;
        }

        .btn-sm {
            padding: 0.4rem 0.8rem;
            font-size: 0.875rem;
        }

        /* Hero banner (matches home page hero) */
        .page-hero {
            background: linear-gradient(135deg, #1a654c 0%, #1f6a50 100%);
            color: var(--color-white);
            padding: 3rem 2rem 5rem;
            text-align: center;
        }

        .page-hero h1 {
            font-size: 2.25rem;
            font-weight: 800;
            line-height: 1.3;
            margin-bottom: 0.5rem;
            color: #ffffff;
        }

        .page-hero p {
            font-size: 1.1rem;
            opacity: 0.95;
            color: #ffffff;
            max-width: 640px;
            margin: 0 auto;
        }

        /* Main Container */
        .container {
            max-width: 1200px;
            margin: 0 auto 3rem;
            padding: 0 2rem;
        }

        /* Stats Cards (overlap the hero slightly) */
        .stats-grid {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 1rem;
            margin: -3rem 0 2rem;
            position: relative;
        }

        .stat-card {
            background: var(--color-white);
            padding: 1.5rem;
            border-radius: 12px;
            box-shadow: var(--shadow-md);
            text-align: center;
        }

        .stat-card h3, .stat-card h2 {
            font-size: 0.875rem;
            color: var(--color-gray);
            margin-bottom: 0.5rem;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        .stat-card .stat-value {
            font-size: 2rem;
            font-weight: 700;
            color: var(--color-link);
        }

        .stat-card .stat-label {
            font-size: 0.875rem;
            color: var(--color-gray);
            margin-top: 0.25rem;
        }

        /* Tabs */
        .tabs {
            display: flex;
            gap: 0;
            border-bottom: 2px solid var(--color-border);
            margin-bottom: 2rem;
        }

        .tab {
            padding: 1rem 2rem;
            background: none;
            border: none;
            cursor: pointer;
            font-weight: 600;
            color: var(--color-gray);
            border-bottom: 3px solid transparent;
            transition: all 0.3s ease;
        }

        .tab.active {
            color: var(--color-link);
            border-bottom-color: var(--color-primary);
        }

        .tab-content {
            display: none;
        }

        .tab-content.active {
            display: block;
        }

        /* Decks Grid */
        .decks-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
            gap: 1.5rem;
        }

        /* Decks with a big subdeck tree take two columns, so nested rows have room */
        @media (min-width: 700px) { .deck-card.wide { grid-column: span 2; } }
        .deck-card.wide .sub-row { flex-direction: row; align-items: center; justify-content: space-between; flex-wrap: wrap; }

        .deck-card {
            background: var(--color-white);
            border-radius: 12px;
            padding: 1.5rem;
            box-shadow: var(--shadow-sm);
            transition: all 0.3s ease;
            cursor: pointer;
            border: 1px solid var(--color-border);
        }

        .deck-card:hover {
            box-shadow: var(--shadow-md);
        }

        .deck-header {
            display: flex;
            justify-content: space-between;
            align-items: start;
            margin-bottom: 1rem;
        }

        .deck-header h3 {
            color: var(--color-heading);
            font-size: 1.25rem;
        }

        .deck-description {
            color: var(--color-gray);
            font-size: 0.875rem;
            margin-bottom: 1rem;
        }

        .deck-stats {
            display: flex;
            gap: 1.5rem;
            font-size: 0.875rem;
        }

        .deck-stat {
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        .deck-stat .badge {
            background-color: var(--color-light);
            padding: 0.25rem 0.5rem;
            border-radius: 4px;
            font-weight: 600;
        }

        .deck-stat .badge.due {
            background-color: #fef3c7;
            color: #92400e;
        }

        .deck-stat .badge.new {
            background-color: #dbeafe;
            color: #1e40af;
        }

        .deck-actions {
            display: flex;
            gap: 0.5rem;
            margin-top: 1rem;
            flex-wrap: wrap;
        }

        /* Anki's colours: new = blue, learning = red, due reviews = green */
        :root { --q-new: #2563eb; --q-learn: #dc2626; --q-due: #15803d; }
        @media (prefers-color-scheme: dark) { :root { --q-new: #60a5fa; --q-learn: #f87171; --q-due: #4ade80; } }
        .q-counts { display: inline-flex; gap: 0.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }
        .q-counts span { padding-bottom: 1px; border-bottom: 2px solid transparent; }
        .q-counts .is-current { border-bottom-color: currentColor; }
        .q-new { color: var(--q-new); } .q-learn { color: var(--q-learn); } .q-due { color: var(--q-due); }
        /* Colour only marks a count when there's something there */
        .q-counts .zero { color: var(--color-gray); opacity: 0.7; }
        .deck-today { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; font-size: 0.875rem; }
        .deck-today .q-counts { gap: 0.9rem; font-size: 1.05rem; }
        .deck-today .q-counts small { display: block; font-size: 0.68rem; font-weight: 600; color: var(--color-gray); text-transform: uppercase; letter-spacing: 0.04em; }
        .deck-today .total { color: var(--color-gray); margin-left: auto; }
        .page-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
        .all-search { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; }
        .all-search input, .cards-toolbar input[type=search] { flex: 1; height: 42px; border: 1px solid var(--color-border, #dfdcd6); border-radius: 10px; padding: 0 0.9rem; font: inherit; background: var(--color-white); color: var(--color-text); }
        .search-results-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 0.75rem; flex-wrap: wrap; }
        .deck-path { display: inline-block; font-size: 0.75rem; font-weight: 700; color: var(--color-link); background: rgba(31, 106, 80, 0.1); padding: 0.1rem 0.5rem; border-radius: 999px; margin-bottom: 0.35rem; }
        mark { background: rgba(245, 158, 11, 0.35); color: inherit; border-radius: 2px; padding: 0 1px; }
        /* Subdecks inside a deck card */
        .subdecks { margin-top: 0.9rem; border-top: 1px solid var(--color-border, #e3dfd5); padding-top: 0.6rem; }
        .subdecks > summary { cursor: pointer; font-size: 0.8rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; color: var(--color-gray); list-style: none; padding: 0.2rem 0; }
        .subdecks > summary::-webkit-details-marker { display: none; }
        .subdecks > summary::before { content: '▸ '; }
        .subdecks[open] > summary::before { content: '▾ '; }
        .sub-row { display: flex; flex-direction: column; gap: 0.35rem; padding: 0.5rem 0.35rem; border-radius: 8px; }
        .sub-children { margin-left: 0.6rem; padding-left: 0.4rem; border-left: 2px solid var(--color-border, #e3dfd5); }
        .fold-btn { width: 22px; height: 22px; border: none; border-radius: 5px; background: var(--color-light); color: var(--color-gray); cursor: pointer; font-size: 0.75rem; line-height: 1; flex-shrink: 0; transition: transform 0.15s ease; }
        .fold-btn:hover { background: rgba(31, 106, 80, 0.12); color: var(--color-link); }
        .fold-btn.open { transform: rotate(90deg); }
        .fold-spacer { width: 22px; flex-shrink: 0; }
        .sub-row:hover { background: var(--color-light); }
        .sub-name { display: flex; align-items: center; gap: 0.4rem; min-width: 0; flex-wrap: wrap; font-weight: 600; font-size: 0.92rem; color: var(--color-heading, inherit); }
        .sub-name span.n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
        .sub-name .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
        .sub-counts { font-size: 0.78rem; font-weight: 800; display: inline-flex; gap: 0.45rem; margin-left: 0.4rem; }
        .sub-actions { display: flex; gap: 0.25rem; flex-wrap: wrap; padding-left: 1rem; }
        .icon-btn { height: 28px; min-width: 28px; padding: 0 0.45rem; border: none; border-radius: 6px; background: var(--color-light); color: var(--color-text); cursor: pointer; font: inherit; font-size: 0.78rem; font-weight: 600; }
        .icon-btn:hover { background: rgba(31, 106, 80, 0.12); color: var(--color-link); }
        .icon-btn.danger:hover { background: rgba(239, 68, 68, 0.12); color: var(--color-danger); }
        .cards-toolbar { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; margin-bottom: 0.75rem; }
        .cards-toolbar label { display: inline-flex; gap: 0.35rem; align-items: center; font-size: 0.88rem; font-weight: 600; }
        .cards-group-title { font-size: 0.8rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; color: var(--color-gray); margin: 1rem 0 0.5rem; }
        .cards-group-title:first-child { margin-top: 0; }
        details.cards-group { border-bottom: 1px solid var(--color-border, #e3dfd5); }
        details.cards-group > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 0.5rem; padding: 0.7rem 0.25rem; margin: 0; }
        details.cards-group > summary::-webkit-details-marker { display: none; }
        details.cards-group > summary::before { content: '▸'; font-size: 0.75rem; transition: transform 0.15s ease; }
        details.cards-group[open] > summary::before { transform: rotate(90deg); }
        details.cards-group > summary .n { margin-left: auto; font-weight: 600; text-transform: none; letter-spacing: 0; }
        details.cards-group > summary:hover { color: var(--color-link); }
        .cards-count { font-size: 0.85rem; color: var(--color-gray); margin-bottom: 0.5rem; }

        /* Study screen extras */
        .study-tools { display: flex; gap: 0.5rem; align-items: center; }
        .kbd-hint { font-size: 0.78rem; color: var(--color-gray); text-align: center; }
        .kbd { display: inline-block; min-width: 1.4em; padding: 0 0.3em; border-radius: 4px; border: 1px solid var(--color-border, #dfdcd6); border-bottom-width: 2px; font-size: 0.72rem; font-weight: 700; text-align: center; line-height: 1.5; }
        .card-content.long { font-size: 1.1rem; text-align: left; }
        .card-content.medium { font-size: 1.25rem; }
        .card-content strong { color: var(--color-link); }
        .state-pill { font-size: 0.7rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; padding: 0.1rem 0.45rem; border-radius: 999px; }
        .state-new { color: var(--q-new); background: rgba(37, 99, 235, 0.1); }
        .state-learning, .state-relearning { color: var(--q-learn); background: rgba(220, 38, 38, 0.1); }
        .state-review { color: var(--q-due); background: rgba(21, 128, 61, 0.1); }

        /* Import */
        .import-tabs { display: flex; gap: 0.35rem; margin-bottom: 1.1rem; flex-wrap: wrap; }
        .import-tab { border: none; background: var(--color-light); color: var(--color-text); padding: 0.5rem 0.9rem; border-radius: 999px; font: inherit; font-size: 0.9rem; font-weight: 600; cursor: pointer; }
        .import-tab.active { background: var(--color-primary); color: #fff; }
        .import-help { font-size: 0.88rem; color: var(--color-gray); margin-bottom: 0.8rem; }
        .import-help ol { margin: 0.35rem 0 0 1.2rem; }
        .drop-zone { display: block; border: 2px dashed var(--color-border, #d9d6cf); border-radius: 12px; padding: 1.5rem 1rem; text-align: center; cursor: pointer; color: var(--color-gray); }
        .drop-zone:hover, .drop-zone.over { border-color: var(--color-primary); background: rgba(31, 106, 80, 0.05); }
        .drop-zone strong { color: var(--color-link); }
        .sep-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; margin-top: 0.75rem; }
        .sep-row label { font-size: 0.85rem; font-weight: 600; display: block; margin-bottom: 0.25rem; }
        .sep-row select, .sep-row input, .import-target select, .import-target input { width: 100%; height: 38px; padding: 0 0.6rem; border-radius: 8px; border: 1px solid var(--color-border, #d9d6cf); background: var(--color-white); color: var(--color-text); font: inherit; font-size: 0.9rem; }
        .import-preview { margin-top: 1rem; border: 1px solid var(--color-border, #e3dfd5); border-radius: 12px; overflow: hidden; }
        .import-preview .head { display: flex; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; padding: 0.6rem 0.85rem; background: var(--color-light); font-size: 0.88rem; font-weight: 600; }
        .import-preview .rows { max-height: 240px; overflow-y: auto; }
        .import-preview .row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; padding: 0.55rem 0.85rem; border-top: 1px solid var(--color-border, #e3dfd5); font-size: 0.85rem; }
        .import-preview .row div { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 5.5em; overflow: hidden; }
        .import-preview .warn { padding: 0.55rem 0.85rem; font-size: 0.82rem; color: #92400e; background: #fef3c7; }
        .import-target { display: grid; gap: 0.75rem; margin-top: 1rem; }
        .import-target .opt { display: flex; gap: 0.5rem; align-items: flex-start; font-size: 0.9rem; }
        .import-target .opt input { width: auto; height: auto; margin-top: 0.25rem; }
        .import-progress { margin-top: 1rem; font-size: 0.9rem; }
        .import-progress .bar { height: 8px; border-radius: 999px; background: var(--color-light); overflow: hidden; margin-top: 0.4rem; }
        .import-progress .bar div { height: 100%; width: 0; background: var(--color-primary); transition: width 0.2s ease; }
        @media (max-width: 600px) { .sep-row, .import-preview .row { grid-template-columns: 1fr; } }


        /* ===== Focus study mode: the study screen takes over the page ===== */
        body.studying #site-header, body.studying .page-hero, body.studying #statsGrid, body.studying .tabs,
        body.studying #site-footer, body.studying .site-footer { display: none !important; }
        body.studying .container { max-width: none; padding: 0; margin: 0; }
        body.studying #studyTab { display: block; }
        body.studying .study-container { max-width: none; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
        .focus-bar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 0.75rem; padding: 0.6rem 1rem; background: var(--color-white); box-shadow: 0 1px 0 var(--color-border); flex-wrap: wrap; }
        .focus-bar .grow { flex: 1; min-width: 0; display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
        .focus-bar .tools { display: flex; gap: 0.35rem; align-items: center; flex-wrap: wrap; }
        .focus-bar .tools-more { display: none; }
        @media (max-width: 640px) {
            .focus-bar .tools-more { display: inline-block; }
            .focus-bar .tools { flex-basis: 100%; }
        }
        .icon-tool { border: 1px solid var(--color-border); background: var(--color-white); color: var(--color-heading); border-radius: 8px; padding: 0.35rem 0.55rem; font: inherit; font-size: 0.82rem; cursor: pointer; display: inline-flex; align-items: center; gap: 0.3rem; }
        .icon-tool:hover { border-color: var(--color-primary); color: var(--color-link); }
        .icon-tool.on { background: rgba(31, 106, 80, 0.12); border-color: var(--color-primary); color: var(--color-link); }
        .icon-tool .kbd { margin: 0; }
        .focus-progress { height: 4px; background: var(--color-light); }
        .focus-progress div { height: 100%; background: var(--color-primary); transition: width 0.3s ease; }
        .session-meta { font-size: 0.8rem; color: var(--color-gray); font-variant-numeric: tabular-nums; white-space: nowrap; }
        .practice-pill { font-size: 0.72rem; font-weight: 800; letter-spacing: 0.03em; padding: 0.15rem 0.55rem; border-radius: 999px; background: rgba(245, 158, 11, 0.15); color: #a16207; }
        @media (prefers-color-scheme: dark) { .practice-pill { color: #fbbf24; } }
        .focus-stage { flex: 1; display: flex; justify-content: center; padding: 1.5rem 1rem 1rem; overflow-y: auto; }
        .study-card { width: 100%; max-width: 820px; align-self: flex-start; margin-top: clamp(0px, 6vh, 4rem); background: var(--color-white); border-radius: 16px; box-shadow: inset 0 5px 0 var(--deck-color, var(--color-primary)), var(--shadow-md); padding: 2.25rem 2rem 2rem; position: relative; }
        .study-card .face-label { top: 0.95rem; }
        .study-card .card-tags { top: 0.95rem; }
        /* The study card is a ruled index card: a red rule under the label line, faint lines below */
        .study-card {
            background-image:
                linear-gradient(to bottom, var(--color-white) 2.35rem, rgba(220, 38, 38, 0.5) 2.35rem, rgba(220, 38, 38, 0.5) calc(2.35rem + 1px), transparent calc(2.35rem + 1px)),
                repeating-linear-gradient(to bottom, transparent 0 29px, rgba(31, 106, 80, 0.08) 29px 30px);
            background-position: 0 0, 0 calc(2.35rem + 1px);
            background-repeat: no-repeat, repeat;
        }
        @media (prefers-color-scheme: dark) {
            .study-card {
                background-image:
                    linear-gradient(to bottom, var(--color-white) 2.35rem, rgba(248, 113, 113, 0.45) 2.35rem, rgba(248, 113, 113, 0.45) calc(2.35rem + 1px), transparent calc(2.35rem + 1px)),
                    repeating-linear-gradient(to bottom, transparent 0 29px, rgba(255, 255, 255, 0.045) 29px 30px);
            }
        }
        .study-q, .study-a { text-align: center; }
        .study-q .card-content, .study-a .card-content { margin: 0 auto; }
        .answer-rule { border: 0; border-top: 2px dashed var(--color-border); margin: 1.5rem 0; }
        .study-a { animation: fadeUp 0.18s ease; }
        @keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
        .flag-mark { position: absolute; top: 0.75rem; right: 1rem; font-size: 1.1rem; }
        .focus-actions { position: sticky; bottom: 0; z-index: 20; background: var(--color-white); box-shadow: 0 -1px 0 var(--color-border); padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom)); }
        .focus-actions .inner { max-width: 820px; margin: 0 auto; display: flex; flex-direction: column; align-items: center; gap: 0.5rem; }
        .focus-actions .btn-reveal { width: 100%; max-width: 420px; }
        .focus-actions .rating-buttons { max-width: 820px; }
        .type-box { margin: 1.25rem auto 0; max-width: 520px; }
        .type-box input { width: 100%; padding: 0.7rem 0.9rem; font-size: 1.05rem; border-radius: 10px; border: 2px solid var(--color-border); background: var(--color-white); color: var(--color-text); text-align: center; }
        .type-box input:focus { outline: none; border-color: var(--color-primary); }
        .type-result { margin: 0 auto 1rem; max-width: 620px; font-size: 1.05rem; line-height: 1.7; display: grid; gap: 0.25rem; text-align: left; font-family: ui-monospace, Menlo, Consolas, monospace; }
        .type-result.type-correct { color: var(--color-success); font-weight: 700; text-align: center; font-family: inherit; }
        .type-label { font-family: inherit; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--color-gray); margin-right: 0.5rem; }
        .type-good { color: var(--color-success); }
        .type-bad { color: var(--color-danger); text-decoration: line-through; }
        .type-missed { color: var(--color-gray); background: rgba(245, 158, 11, 0.18); border-radius: 2px; }
        .cloze-blank { color: var(--color-link); font-weight: 800; }
        .cloze-answer { color: var(--color-link); font-weight: 800; background: rgba(31, 106, 80, 0.1); border-radius: 4px; padding: 0 0.15em; }
        .shortcut-list { display: grid; grid-template-columns: auto 1fr; gap: 0.4rem 1rem; font-size: 0.92rem; }
        @media (max-width: 640px) {
            .study-card { padding: 2.6rem 1.1rem 1.5rem; }
            .focus-bar .tools .wide-only { display: none; }
            .focus-stage { padding: 0.75rem 0.5rem; }
        }

        /* ===== Tabs: Browse and Statistics ===== */
        .browse-filters { display: grid; grid-template-columns: 2fr repeat(4, minmax(0, 1fr)); gap: 0.5rem; margin-bottom: 0.75rem; }
        .browse-filters input, .browse-filters select, .stats-toolbar select { padding: 0.55rem 0.7rem; border-radius: 8px; border: 1px solid var(--color-border); background: var(--color-white); color: var(--color-text); font: inherit; min-width: 0; }
        .browse-bulk { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; padding: 0.5rem 0.75rem; border-radius: 10px; background: var(--color-white); box-shadow: var(--shadow-sm); margin-bottom: 0.75rem; }
        .browse-bulk .bulk-actions { display: flex; gap: 0.35rem; flex-wrap: wrap; opacity: 0.45; pointer-events: none; }
        .browse-bulk.active .bulk-actions { opacity: 1; pointer-events: auto; }
        .browse-bulk:not(.active) .btn-danger { background: transparent; color: var(--color-danger); border: 1px solid currentColor; }
        .browse-bulk select { padding: 0.35rem 0.5rem; border-radius: 6px; border: 1px solid var(--color-border); background: var(--color-white); color: var(--color-text); font: inherit; font-size: 0.85rem; max-width: 180px; }
        .sel-all { display: flex; align-items: center; gap: 0.4rem; font-size: 0.88rem; font-weight: 600; white-space: nowrap; }
        .browse-table { background: var(--color-white); border-radius: 12px; box-shadow: var(--shadow-sm); overflow: hidden; }
        .br-row { display: grid; grid-template-columns: 32px minmax(0, 2.2fr) minmax(0, 1.5fr) minmax(0, 1.1fr) 90px 56px; gap: 0.6rem; align-items: center; padding: 0.55rem 0.75rem; border-top: 1px solid var(--color-border); font-size: 0.88rem; }
        .br-row:first-child { border-top: 0; }
        .br-head { font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; color: var(--color-gray); background: var(--color-light); }
        .br-row.sel { background: rgba(31, 106, 80, 0.07); }
        .br-front, .br-back { cursor: pointer; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
        .br-front { color: var(--color-heading); font-weight: 600; }
        .br-front:hover { color: var(--color-link); }
        .br-tags { display: block; font-size: 0.72rem; font-weight: 500; color: var(--color-gray); }
        .br-deck { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
        .num { text-align: right; font-variant-numeric: tabular-nums; }
        .muted { color: var(--color-gray); }
        .pill { display: inline-block; font-size: 0.7rem; font-weight: 700; padding: 0.05rem 0.45rem; border-radius: 999px; background: rgba(31, 106, 80, 0.12); color: var(--color-link); }
        .pill-muted { background: var(--color-light); color: var(--color-gray); }
        .pill-due { background: rgba(16, 185, 129, 0.15); color: var(--color-success); }
        .browse-pager { display: flex; gap: 0.75rem; align-items: center; justify-content: flex-end; margin-top: 0.75rem; font-size: 0.88rem; color: var(--color-gray); }
        .browse-pager > span:first-child { margin-right: auto; }
        @media (max-width: 760px) {
            .browse-filters { grid-template-columns: 1fr 1fr; }
            .browse-filters input { grid-column: 1 / -1; }
            .br-row { grid-template-columns: 28px minmax(0, 1fr) 76px; }
            .br-row > :nth-child(3), .br-row > :nth-child(4), .br-row > :nth-child(6) { display: none; }
        }

        /* Charts: categorical slots 1–4 and a one-hue sequential ramp, validated for both modes */
        :root { --viz-1: #2a78d6; --viz-2: #eb6834; --viz-3: #1baf7a; --viz-4: #eda100; --viz-bar: #2a78d6; --viz-grid: #e6e5e0; --viz-axis: #6b6a63; --heat-0: #ecebe6; --heat-1: #b7d3f6; --heat-2: #6da7ec; --heat-3: #2a78d6; --heat-4: #184f95; }
        @media (prefers-color-scheme: dark) {
            :root { --viz-1: #3987e5; --viz-2: #d95926; --viz-3: #199e70; --viz-4: #c98500; --viz-bar: #3987e5; --viz-grid: #34342f; --viz-axis: #a8a79e; --heat-0: #2a2a27; --heat-1: #184f95; --heat-2: #256abf; --heat-3: #3987e5; --heat-4: #86b6ef; }
        }
        .stats-toolbar { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
        .stats-note { font-size: 0.82rem; color: var(--color-gray); }
        .stat-tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
        .stat-tiles .tile { background: var(--color-white); border-radius: 12px; box-shadow: var(--shadow-sm); padding: 0.9rem 1rem; display: flex; flex-direction: column; gap: 0.15rem; }
        .stat-tiles .k { font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; color: var(--color-gray); }
        .stat-tiles .v { font-size: 1.7rem; font-weight: 800; color: var(--color-heading); font-variant-numeric: tabular-nums; }
        .stat-tiles .v small { font-size: 0.9rem; font-weight: 600; color: var(--color-gray); }
        .stat-tiles .s { font-size: 0.8rem; color: var(--color-gray); }
        .stats-card { background: var(--color-white); border-radius: 12px; box-shadow: var(--shadow-sm); padding: 1rem 1.1rem; margin-bottom: 1rem; }
        .stats-card header { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 0.6rem; }
        .stats-card h3 { font-size: 1rem; color: var(--color-heading); margin: 0; }
        .stats-card .chart { overflow-x: auto; }
        .seg { display: inline-flex; border: 1px solid var(--color-border); border-radius: 8px; overflow: hidden; }
        .seg button { border: 0; background: transparent; color: var(--color-gray); padding: 0.3rem 0.65rem; font: inherit; font-size: 0.8rem; cursor: pointer; }
        .seg button.on { background: var(--color-primary); color: #fff; }
        svg .grid { stroke: var(--viz-grid); stroke-width: 1; }
        svg .axis { fill: var(--viz-axis); font-size: 10px; font-family: inherit; }
        svg .bar { fill: var(--viz-bar); }
        svg [data-i]:hover.bar, svg .bar:hover { opacity: 0.8; }
        svg .heat.l0 { fill: var(--heat-0); } svg .heat.l1 { fill: var(--heat-1); } svg .heat.l2 { fill: var(--heat-2); } svg .heat.l3 { fill: var(--heat-3); } svg .heat.l4 { fill: var(--heat-4); }
        .heat-legend { display: flex; align-items: center; gap: 3px; font-size: 0.75rem; color: var(--color-gray); margin-top: 0.35rem; }
        .state-bar { display: flex; gap: 2px; height: 16px; border-radius: 4px; overflow: hidden; }
        .state-bar span, .state-legend i, .deck-progress span { display: block; }
        .seg-1 { background: var(--viz-1); } .seg-2 { background: var(--viz-2); } .seg-3 { background: var(--viz-3); } .seg-4 { background: var(--viz-4); }
        .state-legend { display: flex; flex-wrap: wrap; gap: 0.4rem 1.1rem; margin-top: 0.6rem; font-size: 0.85rem; color: var(--color-text); }
        .state-legend > span { display: inline-flex; align-items: center; gap: 0.35rem; }
        .state-legend i { width: 10px; height: 10px; border-radius: 2px; }
        .hard-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
        .hard-table th { text-align: left; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--color-gray); padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--color-border); }
        .hard-table td { padding: 0.45rem 0.5rem; border-bottom: 1px solid var(--color-border); vertical-align: top; }
        .hard-table a { color: var(--color-heading); text-decoration: none; font-weight: 600; }
        .hard-table a:hover { color: var(--color-link); }
        .table-view { margin-top: 0.5rem; font-size: 0.85rem; }
        .table-view summary { cursor: pointer; color: var(--color-gray); }
        .viz-tip { position: fixed; z-index: 3000; pointer-events: none; display: none; background: var(--color-heading); color: var(--color-white); font-size: 0.8rem; line-height: 1.45; padding: 0.45rem 0.65rem; border-radius: 8px; box-shadow: var(--shadow-md); max-width: 260px; }
        @media (max-width: 760px) { .stat-tiles { grid-template-columns: 1fr 1fr; } .hard-table td.muted, .hard-table th:nth-child(2) { display: none; } }

        /* Deck progress (new · learning · young · mature) and drag and drop */
        .deck-progress { display: flex; gap: 2px; height: 6px; border-radius: 3px; overflow: hidden; background: var(--color-light); margin: 0.35rem 0 0.6rem; }
        .sub-row .deck-progress { height: 3px; margin: 0.1rem 0 0; flex-basis: 100%; order: 3; }
        .deck-progress-legend { display: flex; flex-wrap: wrap; gap: 0.2rem 0.9rem; font-size: 0.75rem; color: var(--color-gray); margin-top: -0.25rem; margin-bottom: 0.7rem; font-variant-numeric: tabular-nums; }
        .deck-progress-legend span { display: inline-flex; align-items: center; gap: 0.35rem; white-space: nowrap; }
        .deck-progress-legend i { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }
        .deck-more { position: relative; display: inline-block; }
        .deck-more > summary { list-style: none; cursor: pointer; }
        .deck-more > summary::-webkit-details-marker { display: none; }
        .deck-more .menu { position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; min-width: 200px; background: var(--color-white); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 0.35rem; display: grid; }
        .deck-more .menu button { text-align: left; background: none; border: 0; padding: 0.5rem 0.65rem; border-radius: 6px; font: inherit; font-size: 0.88rem; color: var(--color-text); cursor: pointer; }
        .deck-more .menu button:hover, .deck-more .menu button:focus-visible { background: var(--color-light); outline: none; }
        .deck-more .menu hr { border: 0; border-top: 1px solid var(--color-border); margin: 0.3rem 0.2rem; }
        .deck-more .menu .danger { color: #b42318; }
        @media (prefers-color-scheme: dark) { .deck-more .menu .danger { color: #fca5a5; } }
        .deck-more[open] > summary { box-shadow: inset 0 0 0 2px var(--color-link); }
        .row-more > summary { display: inline-flex; align-items: center; justify-content: center; font-size: 1rem; letter-spacing: 0.05em; }
        .row-more .menu { left: auto; right: 0; }
        .tools-more > summary { font-size: 0.82rem; letter-spacing: 0; list-style: none; }
        .tools-more > summary::-webkit-details-marker { display: none; }
        .tools-more .menu { left: 0; right: auto; }
        [draggable="true"] { cursor: grab; }
        .drag-over { outline: 2px dashed var(--color-primary); outline-offset: 2px; background: rgba(31, 106, 80, 0.06); }
        .drop-top { display: none; border: 2px dashed var(--color-primary); border-radius: 12px; padding: 0.9rem; text-align: center; color: var(--color-link); font-weight: 700; margin-bottom: 1rem; }
        body.dragging-deck .drop-top { display: block; }
        .follow-pill { font-size: 0.7rem; font-weight: 700; color: var(--color-link, #1a654c); background: rgba(31, 106, 80, 0.1); border-radius: 999px; padding: 0.1rem 0.5rem; margin-left: 0.4rem; vertical-align: middle; }
        .settings-grid { display: grid; gap: 1rem; }
        .settings-grid label.row { display: flex; gap: 0.6rem; align-items: flex-start; font-weight: 500; }
        .settings-grid label.row input { width: auto; height: auto; margin-top: 0.3rem; }
        .choice-list { display: grid; gap: 0.5rem; }
        .choice-list label { display: flex; gap: 0.6rem; align-items: flex-start; padding: 0.6rem 0.75rem; border: 1px solid var(--color-border); border-radius: 10px; cursor: pointer; }
        .choice-list label:has(input:checked) { border-color: var(--color-primary); background: rgba(31, 106, 80, 0.06); }
        .choice-list input { width: auto; height: auto; margin-top: 0.25rem; }
        .form-group .choice-list label { display: flex !important; flex-direction: row; font-weight: 500; }
        .choice-list input[type="radio"] { width: auto !important; flex: none; }
        .choice-list small { display: block; color: var(--color-gray); font-size: 0.8rem; }
        .inline-num { width: 5.5rem !important; display: inline-block !important; padding: 0.25rem 0.4rem !important; }
        .choice-list input[type="number"], .choice-list select, #customDeck, #exportDeck, #setGoal, #setLeech, #deckNewOrder {
            background: var(--color-white); color: var(--color-text); border: 1px solid var(--color-border); border-radius: 6px; font: inherit; padding: 0.4rem 0.5rem; }

        /* Study Interface */
        .study-container {
            max-width: 760px;
            margin: 0 auto;
        }

        .study-topbar {
            display: flex;
            justify-content: space-between;
            align-items: center;
            gap: 1rem;
            margin-bottom: 0.75rem;
        }

        .study-meta {
            display: flex;
            align-items: center;
            gap: 0.75rem;
            flex-wrap: wrap;
            min-width: 0;
        }

        .card-from { font-size: 0.8rem; color: var(--color-gray); font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
        .pick-list { max-height: 55vh; overflow-y: auto; border: 1px solid var(--color-border, #e3dfd5); border-radius: 10px; padding: 0.35rem; margin: 0.75rem 0; }
        .pick-row { display: flex; align-items: center; gap: 0.55rem; padding: 0.45rem 0.5rem; border-radius: 7px; cursor: pointer; }
        .pick-row:hover { background: var(--color-light); }
        .pick-row input { width: 18px; height: 18px; accent-color: var(--color-primary); flex-shrink: 0; }
        .pick-row .n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; color: var(--color-heading); }
        .pick-row .c { font-size: 0.78rem; color: var(--color-gray); white-space: nowrap; }
        .pick-tools { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
        .pick-tools .sum { margin-left: auto; font-size: 0.85rem; color: var(--color-gray); }

        .deck-chip {
            display: inline-flex;
            align-items: center;
            gap: 0.5rem;
            background: var(--color-white);
            box-shadow: var(--shadow-sm);
            padding: 0.35rem 0.85rem;
            border-radius: 999px;
            font-weight: 600;
            font-size: 0.875rem;
            color: var(--color-heading);
            max-width: 100%;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .deck-chip .dot {
            width: 10px;
            height: 10px;
            border-radius: 50%;
            flex-shrink: 0;
        }

        .progress-text {
            color: var(--color-gray);
            font-size: 0.875rem;
            font-variant-numeric: tabular-nums;
        }

        .progress-bar {
            height: 8px;
            background: var(--color-white);
            box-shadow: inset 0 0 0 1px var(--color-border);
            border-radius: 999px;
            overflow: hidden;
            margin-bottom: 1.5rem;
        }

        .progress-fill {
            height: 100%;
            border-radius: 999px;
            background: var(--color-primary);
            transition: width 0.4s ease;
        }

        /* Flashcard: both faces share one grid cell so the card grows with its content */
        .flashcard-scene {
            perspective: 1600px;
            margin-bottom: 1.5rem;
        }

        .flashcard {
            display: grid;
            min-height: 340px;
            cursor: pointer;
            transform-style: preserve-3d;
            transition: transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
        }

        .flashcard.flipped {
            transform: rotateY(180deg);
        }

        .card-face {
            grid-area: 1 / 1;
            position: relative;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            text-align: center;
            padding: 3.25rem 2.5rem 2.5rem;
            background: var(--color-white);
            border-radius: 16px;
            box-shadow: inset 0 6px 0 var(--deck-color, var(--color-primary)), var(--shadow-md);
            -webkit-backface-visibility: hidden;
            backface-visibility: hidden;
        }

        .card-back {
            transform: rotateY(180deg);
        }

        /* Both faces are ruled index cards: a red rule under the label, faint lines below it */
        .card-face {
            background-color: var(--color-white);
            background-image:
                linear-gradient(to bottom, var(--color-white) 2.6rem, rgba(220, 38, 38, 0.5) 2.6rem, rgba(220, 38, 38, 0.5) calc(2.6rem + 1px), transparent calc(2.6rem + 1px)),
                repeating-linear-gradient(to bottom, transparent 0 29px, rgba(31, 106, 80, 0.09) 29px 30px);
            background-position: 0 0, 0 calc(2.6rem + 1px);
            background-repeat: no-repeat, repeat;
        }
        @media (prefers-color-scheme: dark) {
            .card-face {
                background-image:
                    linear-gradient(to bottom, var(--color-white) 2.6rem, rgba(248, 113, 113, 0.45) 2.6rem, rgba(248, 113, 113, 0.45) calc(2.6rem + 1px), transparent calc(2.6rem + 1px)),
                    repeating-linear-gradient(to bottom, transparent 0 29px, rgba(255, 255, 255, 0.05) 29px 30px);
            }
        }

        .face-label {
            position: absolute;
            top: 1.1rem;
            left: 1.5rem;
            font-size: 0.75rem;
            font-weight: 700;
            letter-spacing: 0.08em;
            text-transform: uppercase;
            color: var(--color-link);
        }

        .card-tags {
            position: absolute;
            top: 1.1rem;
            right: 1.5rem;
            font-size: 0.75rem;
            color: var(--color-gray);
            max-width: 50%;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .img-field { display: flex; align-items: center; gap: 0.6rem; margin-top: 0.5rem; flex-wrap: wrap; }
        .img-field img { max-height: 90px; max-width: 160px; border-radius: 8px; box-shadow: inset 0 0 0 1px var(--color-border); background: #fff; }
        .img-field .img-status { font-size: 0.82rem; color: var(--color-gray); }
        .img-hint { font-size: 0.8rem; color: var(--color-gray); margin: -0.25rem 0 1rem; }
        .card-image { display: block; max-width: 100%; max-height: 240px; margin: 0.75rem auto 0; border-radius: 10px; background: #fff; }
        .card-item-img { max-height: 54px; max-width: 90px; border-radius: 6px; margin-top: 0.35rem; display: block; background: #fff; }
        .occ-tag { font-size: 0.72rem; font-weight: 800; color: var(--color-link); }
        .card-content {
            font-size: 1.5rem;
            line-height: 1.6;
            color: var(--color-heading);
            max-width: 60ch;
            white-space: pre-wrap;
            overflow-wrap: anywhere;
        }

        .card-hint {
            margin-top: 1.5rem;
            color: var(--color-gray);
            font-size: 0.875rem;
        }

        .study-actions {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 0.75rem;
        }

        .btn-reveal {
            min-width: 220px;
            padding: 0.9rem 1.8rem;
            font-size: 1rem;
            border-radius: 8px;
            box-shadow: var(--shadow-sm);
        }

        .btn-reveal:hover {
            box-shadow: var(--shadow-md);
        }

        .rating-prompt {
            color: var(--color-gray);
            font-size: 0.875rem;
        }

        .rating-buttons {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 0.75rem;
            width: 100%;
        }

        .btn-rating {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 0.15rem;
            padding: 0.9rem 0.5rem;
            border: 2px solid var(--rating-color);
            border-radius: 12px;
            background: var(--rating-tint);
            color: var(--color-heading);
            font-family: inherit;
            font-size: 1rem;
            font-weight: 600;
            cursor: pointer;
            transition: background-color 0.2s ease, color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
        }

        .btn-rating:hover:not(:disabled) {
            /* A stronger tint of the rating's colour; the text stays dark (white on amber or green fails contrast) */
            background: color-mix(in srgb, var(--rating-color) 22%, var(--color-white));
            color: var(--color-heading);
            box-shadow: inset 0 0 0 1px var(--rating-color);
        }

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

        .rating-emoji {
            font-size: 1.35rem;
            line-height: 1.2;
        }

        .rating-interval {
            font-size: 0.75rem;
            font-weight: 500;
            opacity: 0.75;
        }

        .btn-again { --rating-color: var(--color-danger);  --rating-tint: rgba(239, 68, 68, 0.08); }
        .btn-hard  { --rating-color: var(--color-warning); --rating-tint: rgba(245, 158, 11, 0.08); }
        .btn-good  { --rating-color: var(--color-success); --rating-tint: rgba(16, 185, 129, 0.08); }
        .btn-easy  { --rating-color: var(--color-primary); --rating-tint: rgba(31, 106, 80, 0.08); }

        /* Study start / complete panels */
        .study-panel {
            background: var(--color-white);
            border-radius: 16px;
            box-shadow: var(--shadow-sm);
            padding: 3rem 2rem;
            text-align: center;
        }

        .study-panel-icon {
            width: 72px;
            height: 72px;
            margin: 0 auto 1.25rem;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 2rem;
            background: linear-gradient(135deg, #1a654c 0%, #1f6a50 100%);
            box-shadow: var(--shadow-md);
        }

        .study-panel h3 {
            font-size: 1.5rem;
            color: var(--color-heading);
            margin-bottom: 0.5rem;
        }

        .study-panel p {
            color: var(--color-gray);
            max-width: 460px;
            margin: 0 auto 1.75rem;
        }

        .session-summary {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 0.75rem;
            max-width: 520px;
            margin: 0 auto 1.75rem;
        }

        .summary-item {
            border-radius: 12px;
            padding: 0.75rem 0.5rem;
            background: var(--rating-tint);
            border: 1px solid var(--rating-color);
        }

        .summary-item strong {
            display: block;
            font-size: 1.5rem;
            color: var(--color-heading);
            font-variant-numeric: tabular-nums;
        }

        .summary-item span {
            font-size: 0.8rem;
            color: var(--color-gray);
        }

        .study-panel-actions {
            display: flex;
            gap: 0.75rem;
            justify-content: center;
            flex-wrap: wrap;
        }

        /* Modal */
        .modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.6);
            z-index: 1000;
            align-items: center;
            justify-content: center;
        }

        /* The card editor opens on top of the deck's card list, so it must sit above it */
        #cardModal {
            z-index: 1010;
        }

        .modal.active {
            display: flex;
        }

        .modal-content {
            background: var(--color-white);
            border-radius: 12px;
            padding: 2rem;
            max-width: 600px;
            width: 90%;
            max-height: 80vh;
            overflow-y: auto;
        }

        .modal-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 1.5rem;
        }

        .modal-header h2 {
            color: var(--color-heading);
        }

        .close-modal {
            font-size: 1.5rem;
            cursor: pointer;
            color: var(--color-gray);
            background: none;
            border: none;
        }

        .form-group {
            margin-bottom: 1.5rem;
        }

        .form-group label {
            display: block;
            margin-bottom: 0.5rem;
            font-weight: 600;
            color: var(--color-text);
        }

        .form-group input,
        .form-group textarea,
        .form-group select {
            width: 100%;
            padding: 0.75rem;
            border: 1px solid #ddd;
            border-radius: 6px;
            font-size: 1rem;
            font-family: inherit;
        }

        .form-group textarea {
            min-height: 120px;
            resize: vertical;
        }

        /* Colour picker: a visible swatch rather than a full-width bar squashed by the padding above */
        .form-group input[type="color"] {
            width: 72px; height: 42px; padding: 4px; cursor: pointer;
            border: 1px solid var(--color-border); border-radius: 8px; background: var(--color-white);
        }
        .form-group input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
        .form-group input[type="color"]::-webkit-color-swatch { border: none; border-radius: 5px; }
        .form-group input[type="color"]::-moz-color-swatch { border: none; border-radius: 5px; }

        /* Cards List */
        .cards-list {
            background: var(--color-white);
            border-radius: 12px;
            box-shadow: var(--shadow-sm);
        }

        .card-item {
            padding: 1.5rem;
            border-bottom: 1px solid #f0f0f0;
        }

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

        .card-item-header {
            display: flex;
            justify-content: space-between;
            align-items: start;
            margin-bottom: 0.5rem;
        }

        .card-item-front {
            font-weight: 600;
            color: var(--color-heading);
        }

        .card-item-back {
            color: var(--color-gray);
            font-size: 0.875rem;
        }

        .card-item-meta {
            display: flex;
            gap: 1rem;
            margin-top: 0.5rem;
            font-size: 0.75rem;
            color: var(--color-gray);
        }

        .empty-state {
            text-align: center;
            padding: 4rem 2rem;
        }

        .empty-state svg {
            width: 120px;
            height: 120px;
            margin-bottom: 1rem;
            opacity: 0.5;
        }

        .empty-state h3 {
            color: var(--color-heading);
            margin-bottom: 0.5rem;
        }

        .empty-state p {
            color: var(--color-gray);
            margin-bottom: 1.5rem;
        }

        /* Loading */
        .loading {
            text-align: center;
            padding: 3rem;
            color: var(--color-gray);
        }

        .spinner {
            border: 3px solid var(--color-light);
            border-top: 3px solid var(--color-primary);
            border-radius: 50%;
            width: 40px;
            height: 40px;
            animation: spin 1s linear infinite;
            margin: 0 auto 1rem;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }

        /* Responsive */
        @media (max-width: 768px) {
            nav {
                padding: 1rem;
            }

            .container {
                padding: 0 1rem;
            }

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

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

            .tab {
                padding: 0.75rem 1rem;
                font-size: 0.875rem;
            }

            .page-hero {
                padding: 2.5rem 1.5rem 4.5rem;
            }

            .page-hero h1 {
                font-size: 1.75rem;
            }

            .page-hero p {
                font-size: 1rem;
            }

            .user-welcome {
                display: none;
            }

            .logo {
                font-size: 1.25rem;
            }

            .logo svg {
                width: 32px;
                height: 32px;
            }

            .stat-card {
                padding: 1rem 0.75rem;
            }

            .stat-card h3, .stat-card h2 {
                font-size: 0.75rem;
            }

            .rating-buttons,
            .session-summary {
                grid-template-columns: repeat(2, 1fr);
            }

            .flashcard {
                min-height: 280px;
            }

            .card-face {
                padding: 3rem 1.25rem 2rem;
            }

            .card-content {
                font-size: 1.25rem;
            }

            .study-panel {
                padding: 2.5rem 1.25rem;
            }
        }

        /* ===== Decks tab: the Today panel beside the deck list ===== */
        .page-hero.compact ~ .container { margin-top: 1.25rem; }
        .fc-layout { display: grid; grid-template-columns: 290px minmax(0, 1fr); gap: 1.75rem; align-items: start; }
        .today { position: sticky; top: 88px; display: grid; gap: 1.1rem; padding: 1.25rem; border-radius: var(--pr-radius, 16px); background: var(--color-white); border: 1px solid var(--color-border); box-shadow: var(--shadow-sm); }
        .today h2 { font-size: 0.95rem; font-weight: 750; color: var(--color-heading); letter-spacing: 0; }
        .today-due { display: grid; gap: 0.85rem; padding: 1rem; margin: 0 -0.25rem; border-radius: 12px; background: var(--color-light); }
        .today-due.has-due { background: #fff3d6; border-radius: 3px 3px 12px 3px; transform: rotate(-0.8deg); box-shadow: 0 1px 1px rgba(18, 26, 22, 0.08), 0 12px 20px -14px rgba(18, 26, 22, 0.4); }
        .today-due.has-due .today-num { color: #2e2100; }
        .today-due.has-due p { color: #6b5208; }
        @media (prefers-color-scheme: dark) {
            .today-due.has-due { background: #f0c35e; box-shadow: 0 12px 20px -14px rgba(0, 0, 0, 0.85); }
            .today-due.has-due .today-num { color: #2a1d00; }
            .today-due.has-due p { color: #4f3a05; }
        }
        @media (prefers-reduced-motion: reduce) { .today-due.has-due { transform: none; } }
        .today-due p { display: flex; align-items: baseline; gap: 0.5rem; color: var(--color-gray); font-weight: 600; }
        .today-num { font-size: 2.6rem; line-height: 1; font-weight: 800; letter-spacing: -0.03em; color: var(--color-heading); font-variant-numeric: tabular-nums; }
        .today-study { width: 100%; justify-content: center; min-height: 44px; font-size: 1rem; }
        .today-row { display: flex; justify-content: space-between; gap: 0.5rem; font-size: 0.88rem; color: var(--color-gray); margin-bottom: 0.45rem; }
        .today-row strong { color: var(--color-heading); font-variant-numeric: tabular-nums; }
        .goal-bar { height: 8px; border-radius: 999px; background: var(--color-tint); overflow: hidden; }
        .goal-bar span { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--pr-accent, #f2b134); transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1); }
        .goal-bar.done span { background: var(--color-primary); }
        .today-facts { list-style: none; display: grid; gap: 0.55rem; padding: 0; margin: 0; font-size: 0.9rem; color: var(--color-text); }
        .today-facts li { display: flex; align-items: center; gap: 0.55rem; }
        .today-facts svg { color: var(--pr-accent-ink, #855700); flex-shrink: 0; }
        .today-facts li + li svg { color: var(--color-link); }
        .today-facts strong { font-variant-numeric: tabular-nums; color: var(--color-heading); }
        .today-tools.today-tools { display: grid; justify-content: stretch; align-items: stretch; gap: 0.15rem; max-width: none; margin: 0; padding: 0.9rem 0 0; border-top: 1px solid var(--color-border); }
        .today-tools button { display: flex; align-items: center; gap: 0.6rem; width: 100%; min-height: 40px; padding: 0.45rem 0.55rem; border: 0; border-radius: 8px; background: none;
            font: inherit; font-size: 0.9rem; font-weight: 600; color: var(--color-text); text-align: left; cursor: pointer; }
        .today-tools button svg { color: var(--color-link); flex-shrink: 0; align-self: flex-start; margin-top: 0.15rem; margin-top: calc((1lh - 18px) / 2); }   /* beside the first line when the label wraps */
        .today-tools button:hover { background: var(--color-tint); color: var(--color-heading); }
        .fc-toolbar { display: flex; gap: 0.6rem; margin-bottom: 1.25rem; }
        .fc-toolbar input { flex: 1; min-width: 0; height: 44px; border: 1px solid var(--color-border); border-radius: 10px; padding: 0 0.95rem; font: inherit; background: var(--color-white); color: var(--color-text); }
        .fc-new { display: inline-flex; align-items: center; gap: 0.4rem; min-height: 44px; white-space: nowrap; }
        /* Each deck's own colour runs as a band along the top of its card */
        .decks-grid .deck-card { box-shadow: inset 0 4px 0 var(--deck, var(--color-primary)), var(--shadow-sm); position: relative; }
        .decks-grid { isolation: isolate; }
        .decks-grid .deck-card::before { content: ''; position: absolute; inset: 0; z-index: -1; border-radius: inherit; background: var(--color-white); border: 1px solid var(--color-border);
            transform: translate(5px, 5px) rotate(1.2deg); box-shadow: var(--shadow-sm); pointer-events: none; }
        .decks-grid .deck-card:hover::before { transform: translate(7px, 7px) rotate(2deg); }
        @media (prefers-reduced-motion: no-preference) { .decks-grid .deck-card::before { transition: transform 0.2s ease; } }
        .decks-grid .deck-card:hover { box-shadow: inset 0 4px 0 var(--deck, var(--color-primary)), var(--shadow-md); }
        .fc-main .decks-grid { grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 1.25rem; }
        @media (max-width: 900px) {
            .fc-layout { grid-template-columns: 1fr; gap: 1.25rem; }
            .today { position: static; grid-template-columns: 1fr 1fr; align-items: start; }
            .today h2, .today-due, .today-tools { grid-column: 1 / -1; }
            .today-tools { grid-template-columns: 1fr 1fr; }
        }
        @media (max-width: 560px) {
            .today { grid-template-columns: 1fr; }
            .today-tools { grid-template-columns: 1fr; }
            .fc-main .decks-grid { grid-template-columns: 1fr; }
        }
    

        /* Offline study setting, under the study panel's buttons */
        .offline-opt { margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--color-border); text-align: left; }
        .offline-switch { display: flex; align-items: flex-start; gap: 0.6rem; font-weight: 600; font-size: 0.93rem; color: var(--color-heading); cursor: pointer; }
        .offline-switch input { width: 18px; height: 18px; margin-top: 0.15rem; flex-shrink: 0; accent-color: var(--pr-brand); }
        .offline-status { margin: 0.35rem 0 0 1.75rem; font-size: 0.85rem; line-height: 1.5; color: var(--color-gray); }

        /* After a session: the streak, then what to do next */
        .session-next { display: grid; gap: 0.7rem; max-width: 420px; margin: 1.1rem auto 0.4rem; text-align: left; }
        .session-next:empty { display: none; }
        .session-streak { display: flex; align-items: center; gap: 0.6rem; padding: 0.65rem 0.85rem; border-radius: 12px; background: #fff3d6; color: #3b2a00; font-size: 0.92rem; }
        .session-streak svg { color: #b45309; flex-shrink: 0; }
        .session-streak.celebrate { animation: pr-streak-pop 0.7s cubic-bezier(0.2, 0.9, 0.3, 1.3) both; }
        .session-streak.celebrate svg { animation: pr-flame 1.2s ease-in-out 0.3s 2; transform-origin: 50% 90%; }
        @keyframes pr-streak-pop { 0% { transform: scale(0.85); opacity: 0; } 60% { transform: scale(1.04); opacity: 1; } 100% { transform: scale(1); } }
        @keyframes pr-flame { 0%, 100% { transform: scale(1) rotate(0); } 50% { transform: scale(1.25) rotate(-6deg); } }
        .session-next-card { display: grid; gap: 0.15rem; width: 100%; padding: 0.85rem 1rem; border-radius: 12px; border: 1px solid var(--color-border); background: var(--color-white); color: var(--color-text); text-align: left; text-decoration: none; font: inherit; cursor: pointer; transition: border-color 0.15s ease, transform 0.15s ease; }
        .session-next-card:hover { border-color: var(--color-primary); transform: translateY(-1px); }
        .session-next-card.done { cursor: default; }
        .session-next-card.done:hover { transform: none; border-color: var(--color-border); }
        .session-next-card .label { font-size: 0.72rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--color-primary); }
        .session-next-card strong { font-size: 1rem; color: var(--color-heading); }
        .session-next-card span:last-child { font-size: 0.86rem; color: var(--color-gray); }
        @media (prefers-color-scheme: dark) { .session-streak { background: #3a2f12; color: #f7e3b0; } .session-streak svg { color: #f0c35e; } }
        @media (prefers-reduced-motion: reduce) { .session-streak.celebrate, .session-streak.celebrate svg { animation: none; } }

        /* Study settings: reminders */
        .reminder-set { border: 1px solid var(--color-border); border-radius: 12px; padding: 0.7rem 0.9rem 0.8rem; margin: 0.2rem 0 0.9rem; }
        .reminder-set legend { font-weight: 700; color: var(--color-heading); padding: 0 0.3rem; font-size: 0.92rem; }
        .reminder-time { display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem; margin: 0.4rem 0 0.6rem; font-size: 0.9rem; }
        .reminder-time select { padding: 0.35rem 0.5rem; border-radius: 8px; border: 1px solid var(--color-border); background: var(--color-white); color: var(--color-text); font: inherit; }
        .reminder-time .muted, .reminder-set .muted { font-size: 0.82rem; color: var(--color-gray); }
        .reminder-device { margin-top: 0.5rem; padding-top: 0.6rem; border-top: 1px dashed var(--color-border); font-size: 0.88rem; }
        .reminder-device p { margin: 0 0 0.45rem; }
        .reminder-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
        .reminder-note { color: var(--color-primary); font-weight: 600; }

        /* Signed out, or no connection: one calm card with a way forward */
        .fc-gate { max-width: 34rem; margin: 2rem auto; background: var(--color-white); border: 1px solid var(--color-border); border-radius: 16px; box-shadow: var(--shadow-sm); padding: 2.25rem 2rem; text-align: center; }
        .fc-gate h2 { font-family: var(--pr-serif, Georgia, serif); font-size: 1.5rem; color: var(--color-heading); margin-bottom: 0.5rem; }
        .fc-gate p { color: var(--color-gray); }
        .fc-gate-actions { display: flex; gap: 0.6rem; justify-content: center; flex-wrap: wrap; margin: 1.25rem 0 0.25rem; }
        .fc-gate-try { margin-top: 0.9rem; font-size: 0.92rem; }

        /* End of a session: one figure that matters, then the ratings split */
        .session-result { max-width: 28rem; margin: 0.5rem auto 1.25rem; }
        .sr-lead { font-size: 1.05rem; color: var(--color-gray); }
        .sr-lead strong { display: block; font-family: var(--pr-serif, Georgia, serif); font-size: 3rem; line-height: 1.05; letter-spacing: -0.03em; color: var(--color-heading); font-variant-numeric: tabular-nums; }
        .sr-meta { margin: 0.35rem 0 1rem; color: var(--color-gray); font-size: 0.92rem; }
        .sr-bar { display: flex; height: 12px; border-radius: 999px; overflow: hidden; background: var(--color-border); gap: 2px; }
        .sr-seg { background: var(--rating-color); min-width: 6px; }
        .sr-legend { list-style: none; display: flex; flex-wrap: wrap; justify-content: center; gap: 0.35rem 1rem; margin: 0.7rem 0 0; padding: 0; font-size: 0.9rem; color: var(--color-text); }
        .sr-legend li { display: inline-flex; align-items: center; gap: 0.35rem; }
        .sr-sw { width: 10px; height: 10px; border-radius: 3px; background: var(--rating-color); }
        @media (prefers-reduced-motion: no-preference) {
            .sr-seg { animation: sr-grow 0.6s cubic-bezier(0.16, 1, 0.3, 1) both; transform-origin: left center; }
        }
        @keyframes sr-grow { from { transform: scaleX(0); } }

        /* Study insights (Pro) in Statistics */
        .insights header { display: flex; justify-content: space-between; align-items: baseline; gap: 0.75rem; flex-wrap: wrap; }
        .insights .pro-chip { display: inline-block; margin-left: 0.4rem; padding: 0.05rem 0.45rem; border-radius: 6px; font-size: 0.72rem; font-weight: 800; letter-spacing: 0.04em; background: var(--color-tint, #e5eee8); color: var(--color-link, #1a654c); vertical-align: 0.15em; }
        .insights.locked p { max-width: 60ch; }
        .ins-focus { border: 1px solid var(--color-border); border-radius: 12px; padding: 0.8rem 1rem; margin: 0.6rem 0 1rem; background: color-mix(in srgb, #f2b134 9%, var(--color-white)); }
        .ins-focus h4, .ins-group h4 { font-size: 0.95rem; color: var(--color-heading); margin-bottom: 0.4rem; }
        .ins-focus ol { margin: 0; padding-left: 1.2rem; }
        .ins-focus li { margin-bottom: 0.25rem; }
        .ins-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); gap: 1rem 1.5rem; }
        .ins-group ul { list-style: none; margin: 0; padding: 0; }
        .ins-group li { display: grid; grid-template-columns: minmax(0, 1fr) 5.5rem 4.6rem; align-items: center; gap: 0.6rem; padding: 0.3rem 0; border-bottom: 1px solid var(--color-border); font-size: 0.92rem; }
        .ins-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
        .ins-bar { height: 8px; border-radius: 999px; background: var(--color-border); overflow: hidden; }
        .ins-bar i { display: block; height: 100%; border-radius: 999px; background: var(--color-primary); }
        .ins-val { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
        .ins-val small { display: block; font-weight: 500; font-size: 0.72rem; color: var(--color-gray); }
        .ins-weeks { display: flex !important; align-items: flex-end; gap: 0.35rem; height: 120px; }
        .ins-weeks li { flex: 1; display: flex !important; flex-direction: column; align-items: center; gap: 0.25rem; border: 0 !important; padding: 0 !important; height: 100%; grid-template-columns: none; }
        .ins-col { flex: 1; width: 100%; display: flex; align-items: flex-end; background: color-mix(in srgb, var(--color-border) 55%, transparent); border-radius: 6px 6px 2px 2px; overflow: hidden; }
        .ins-col i { display: block; width: 100%; background: var(--color-primary); border-radius: 6px 6px 2px 2px; }
        .ins-weeks small { font-size: 0.68rem; color: var(--color-gray); white-space: nowrap; }
        @media (max-width: 560px) { .ins-weeks small { display: none; } }
