  :root {
    color-scheme: light;
    --surface-1:      #fcfcfb;
    --page:           #f9f9f7;
    --surface-2:      #ffffff;
    --text-primary:   #0b0b0b;
    --text-secondary: #52514e;
    --text-muted:     #898781;
    --gridline:       #e1e0d9;
    --border:         rgba(11,11,11,0.10);
    --border-strong:  rgba(11,11,11,0.18);
    --blue:           #2a78d6;
    --blue-tint:      rgba(42,120,214,0.13);
    --good:           #0ca30c;
    --good-text:      #006300;
    --warning:        #fab219;
    --serious:        #ec835a;
    --critical:       #d03b3b;
    --unseen:         #c3c2b7;
    /* categorical series (fixed order — never reassigned/cycled), for the Insights deck-breakdown chart */
    --cat-1: #2a78d6; --cat-2: #eb6834; --cat-3: #1baf7a; --cat-4: #eda100;
    --cat-5: #e87ba4; --cat-6: #008300; --cat-7: #4a3aa7; --cat-8: #e34948;
    --cat-other: #9a9890;
  }
  @media (prefers-color-scheme: dark) {
    :root {
      color-scheme: dark;
      --surface-1:      #1a1a19;
      --page:           #0d0d0d;
      --surface-2:      #232322;
      --text-primary:   #ffffff;
      --text-secondary: #c3c2b7;
      --text-muted:     #898781;
      --gridline:       #2c2c2a;
      --border:         rgba(255,255,255,0.10);
      --border-strong:  rgba(255,255,255,0.20);
      --blue:           #3987e5;
      --blue-tint:      rgba(57,135,229,0.18);
      --good:           #0ca30c;
      --good-text:      #0ca30c;
      --warning:        #fab219;
      --serious:        #ec835a;
      --critical:       #e66767;
      --unseen:         #52514e;
      --cat-1: #3987e5; --cat-2: #d95926; --cat-3: #199e70; --cat-4: #c98500;
      --cat-5: #d55181; --cat-6: #008300; --cat-7: #9085e9; --cat-8: #e66767;
      --cat-other: #6b6a64;
    }
  }

  * { box-sizing: border-box; }
  html, body { margin: 0; padding: 0; }
  body {
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--page);
    color: var(--text-primary);
    min-height: 100vh;
  }
  #app { max-width: 900px; margin: 0 auto; padding: 20px 20px 80px; }

  h1, h2, h3 { font-weight: 700; letter-spacing: -0.01em; }
  .topbar {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 24px; gap: 12px; flex-wrap: wrap;
  }
  .topbar h1 { font-size: 22px; margin: 0; }
  .topbar .subtitle { color: var(--text-secondary); font-size: 13px; margin-top: 2px; }

  button {
    font-family: inherit; font-size: 14px; font-weight: 600;
    border-radius: 10px; border: 1px solid var(--border-strong);
    padding: 9px 16px; cursor: pointer; background: var(--surface-2);
    color: var(--text-primary); transition: background 0.15s, transform 0.05s;
  }
  button:hover { background: var(--gridline); }
  button:active { transform: scale(0.98); }
  button:disabled { opacity: 0.4; cursor: default; }
  button.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
  button.primary:hover { filter: brightness(1.08); }
  button.good { background: var(--good); border-color: var(--good); color: #fff; }
  button.good:hover { filter: brightness(1.08); }
  button.serious { background: var(--serious); border-color: var(--serious); color: #1a1200; }
  button.serious:hover { filter: brightness(1.05); }
  button.ghost { background: transparent; border-color: transparent; color: var(--text-secondary); }
  button.ghost:hover { background: var(--gridline); }
  button.danger { color: var(--critical); }
  button.small { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }
  button.icon-btn { padding: 6px 9px; }

  .deck-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
  .deck-card {
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: 14px; padding: 16px 18px; display: flex; flex-direction: column; gap: 10px;
  }
  .deck-card h3 { margin: 0; font-size: 16px; }
  .deck-card .count { color: var(--text-secondary); font-size: 12.5px; }
  .deck-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }

  .reverse-toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; margin-top: 2px; user-select: none; }
  .reverse-toggle-switch {
    position: relative; width: 32px; height: 18px; border-radius: 10px; background: var(--gridline);
    border: 1px solid var(--border-strong); flex-shrink: 0; transition: background 0.15s;
  }
  .reverse-toggle-knob {
    position: absolute; top: 1px; left: 1px; width: 14px; height: 14px; border-radius: 50%;
    background: var(--surface-2); box-shadow: 0 1px 2px rgba(0,0,0,0.25); transition: transform 0.15s;
  }
  .reverse-toggle.active .reverse-toggle-switch { background: var(--blue); border-color: var(--blue); }
  .reverse-toggle.active .reverse-toggle-knob { transform: translateX(14px); background: #fff; }
  .reverse-toggle-label { font-size: 12px; color: var(--text-secondary); }
  .reverse-toggle.active .reverse-toggle-label { color: var(--blue); font-weight: 600; }
  .quiz-mode-badge {
    display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 700;
    color: var(--blue); background: var(--blue-tint);
    border-radius: 999px; padding: 3px 10px; margin-bottom: 4px;
  }

  .mastery-bar { display: flex; height: 8px; border-radius: 5px; overflow: hidden; background: var(--gridline); gap: 2px; }
  .mastery-bar > div { height: 100%; }
  .mastery-bar .seg-know { background: var(--good); }
  .mastery-bar .seg-learning { background: var(--warning); }
  .mastery-bar .seg-unseen { background: var(--unseen); }
  .mastery-legend { display: flex; gap: 12px; font-size: 12px; color: var(--text-secondary); flex-wrap: wrap; }
  .mastery-legend .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }

  .empty-state { text-align: center; padding: 60px 20px; color: var(--text-secondary); }

  /* Deck editor */
  .card-row {
    display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; align-items: start;
    padding: 10px; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; background: var(--surface-2);
  }
  .card-row input, .card-row textarea, .add-card-form input {
    font-family: inherit; font-size: 13.5px; padding: 7px 9px; border-radius: 7px;
    border: 1px solid var(--border-strong); background: var(--surface-1); color: var(--text-primary); width: 100%;
  }
  .add-card-form { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; margin-bottom: 18px; align-items: center; }
  .stat-badge { font-size: 11px; color: var(--text-muted); }

  /* Quiz */
  .quiz-wrap { display: flex; flex-direction: column; align-items: center; gap: 20px; }
  .progress-row { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
  .progress-track { flex: 1; height: 6px; background: var(--gridline); border-radius: 4px; overflow: hidden; }
  .progress-fill { height: 100%; background: var(--blue); border-radius: 4px; transition: width 0.2s; }
  .progress-label { font-size: 12.5px; color: var(--text-secondary); white-space: nowrap; }

  .flashcard-scene { width: 100%; max-width: 520px; height: 340px; perspective: 1400px; transition: max-width 0.2s, height 0.2s; }
  .flashcard-scene.image-mode { max-width: 620px; height: 460px; }
  .flashcard {
    width: 100%; height: 100%; position: relative; cursor: pointer;
    transform-style: preserve-3d; transition: transform 0.45s cubic-bezier(.4,.2,.2,1);
  }
  .flashcard.flipped { transform: rotateY(180deg); }
  .flashcard-face {
    position: absolute; inset: 0; backface-visibility: hidden;
    border-radius: 18px; border: 1px solid var(--border);
    display: flex; align-items: center; justify-content: center; flex-direction: column;
    padding: 34px 26px 20px; text-align: center; background: var(--surface-2);
    box-shadow: 0 1px 2px rgba(0,0,0,0.04), 0 8px 24px rgba(0,0,0,0.06);
    overflow-y: auto;
  }
  .flashcard-face.back { transform: rotateY(180deg); }
  .face-label { position: absolute; top: 14px; left: 16px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); }
  .face-text { font-size: 28px; font-weight: 700; line-height: 1.3; max-width: 100%; }
  .face-text.len-m { font-size: 21px; }
  .face-text.len-l { font-size: 17px; font-weight: 650; }
  .face-text.len-xl { font-size: 15px; font-weight: 600; line-height: 1.4; }
  .face-note { margin-top: 14px; font-size: 13px; color: var(--text-secondary); max-width: 400px; line-height: 1.4; }
  .flip-hint { font-size: 12.5px; color: var(--text-muted); margin-top: 4px; }

  .face-image-wrap { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
  .face-image { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 10px; box-shadow: 0 2px 10px rgba(0,0,0,0.15); }

  .mark-buttons { display: flex; gap: 12px; width: 100%; max-width: 520px; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
  .mark-buttons.visible { opacity: 1; pointer-events: auto; }
  .mark-buttons button { flex: 1; padding: 13px; font-size: 14.5px; border-radius: 12px; }

  .quiz-footer { display: flex; gap: 8px; }

  .session-summary { text-align: center; max-width: 420px; margin: 40px auto; }
  .summary-stats { display: flex; gap: 16px; justify-content: center; margin: 20px 0; }
  .stat-tile { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 14px 22px; min-width: 100px; }
  .stat-tile .value { font-size: 26px; font-weight: 700; }
  .stat-tile .label { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
  .stat-tile.know .value { color: var(--good-text); }
  .stat-tile.learning .value { color: #8a5a00; }
  @media (prefers-color-scheme: dark) { .stat-tile.learning .value { color: var(--warning); } }

  /* Stats view */
  .weak-list { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
  .weak-item { display: flex; justify-content: space-between; padding: 8px 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; font-size: 13.5px; }
  .weak-item .b { color: var(--text-secondary); }

  .review-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
  .review-card { border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); overflow: hidden; }
  .review-card summary {
    padding: 11px 14px; cursor: pointer; font-size: 13.5px; font-weight: 600;
    list-style: none; display: flex; justify-content: space-between; align-items: center; gap: 10px;
  }
  .review-card summary::-webkit-details-marker { display: none; }
  .review-card summary .chevron { color: var(--text-muted); font-size: 11px; transition: transform 0.15s; flex-shrink: 0; }
  .review-card[open] summary .chevron { transform: rotate(90deg); }
  .review-card-body { padding: 0 14px 14px; border-top: 1px solid var(--gridline); }
  .review-card-answer { font-size: 13.5px; color: var(--text-secondary); padding-top: 10px; line-height: 1.45; }
  .review-card-note { font-size: 12px; color: var(--text-muted); margin-top: 6px; line-height: 1.4; }
  .review-card-actions { margin-top: 12px; display: flex; gap: 8px; }
  .review-section-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 26px; flex-wrap: wrap; }
  .mini-thumb { height: 32px; width: 48px; object-fit: cover; border-radius: 5px; vertical-align: middle; }
  .review-section-header h3 { margin: 0; }

  .breadcrumb { font-size: 13px; color: var(--text-secondary); margin-bottom: 6px; cursor: pointer; }
  .breadcrumb:hover { text-decoration: underline; }

  .modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
  .modal { background: var(--surface-2); border-radius: 14px; padding: 22px; max-width: 380px; width: 100%; border: 1px solid var(--border); }
  .modal h3 { margin-top: 0; }
  .modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
  .modal.modal-wide { max-width: 560px; }
  .modal label { font-size: 12.5px; font-weight: 600; color: var(--text-secondary); display: block; margin: 12px 0 5px; }
  .modal label:first-of-type { margin-top: 0; }
  .modal input[type="text"] {
    width: 100%; font-family: inherit; font-size: 14px; padding: 8px 10px; border-radius: 8px;
    border: 1px solid var(--border-strong); background: var(--surface-1); color: var(--text-primary);
  }
  .modal textarea {
    width: 100%; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px;
    padding: 10px; border-radius: 8px; border: 1px solid var(--border-strong);
    background: var(--surface-1); color: var(--text-primary); resize: vertical; min-height: 140px; line-height: 1.5;
  }
  .modal .format-help { font-size: 12px; color: var(--text-muted); line-height: 1.5; margin-bottom: 4px; }
  .modal .format-help code { background: var(--gridline); border-radius: 4px; padding: 1px 5px; font-family: ui-monospace, monospace; }
  .import-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
  .import-preview { margin-top: 10px; font-size: 12.5px; color: var(--text-secondary); }
  .import-preview.ok { color: var(--good-text); }
  @media (prefers-color-scheme: dark) { .import-preview.ok { color: var(--good); } }
  .import-preview-table { margin-top: 8px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
  .import-preview-table .row { display: grid; grid-template-columns: 1fr 1fr; gap: 0; border-bottom: 1px solid var(--gridline); font-size: 12.5px; }
  .import-preview-table .row:last-child { border-bottom: none; }
  .import-preview-table .cell { padding: 6px 9px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .import-preview-table .cell:first-child { border-right: 1px solid var(--gridline); color: var(--text-primary); }
  .import-preview-table .cell:last-child { color: var(--text-secondary); }

  .modal-select-links { display: flex; justify-content: flex-end; gap: 10px; font-size: 12px; margin-bottom: 4px; }
  .modal-select-links a { color: var(--text-secondary); cursor: pointer; text-decoration: underline; }
  .modal-deck-list { max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 4px 10px; }
  .modal-deck-row { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--gridline); font-size: 13.5px; }
  .modal-deck-row:last-child { border-bottom: none; }
  .modal-deck-row input[type="checkbox"] { width: 16px; height: 16px; flex: none; }
  .modal-deck-row .deck-row-name { flex: 1; color: var(--text-primary); }
  .modal-deck-row .deck-row-count { color: var(--text-muted); font-size: 12px; }
  .modal-count-row { display: flex; align-items: center; gap: 10px; }
  .modal-count-row input[type="number"] {
    width: 90px; font-family: inherit; font-size: 14px; padding: 8px 10px; border-radius: 8px;
    border: 1px solid var(--border-strong); background: var(--surface-1); color: var(--text-primary);
  }
  .modal-pool-note { font-size: 12px; color: var(--text-muted); margin-top: 6px; }
  .file-label {
    font-size: 12.5px; padding: 6px 12px; border-radius: 8px; border: 1px dashed var(--border-strong);
    color: var(--text-secondary); cursor: pointer; display: inline-block;
  }
  .file-label:hover { background: var(--gridline); }

  .toast {
    position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
    background: var(--text-primary); color: var(--page); padding: 10px 18px;
    border-radius: 10px; font-size: 13.5px; opacity: 0; pointer-events: none; transition: opacity 0.25s;
    z-index: 60;
  }
  .toast.show { opacity: 0.95; }

  .section-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
  .kbd { font-family: monospace; background: var(--gridline); border-radius: 4px; padding: 1px 5px; font-size: 11px; }
  .hint-row { font-size: 12px; color: var(--text-muted); text-align: center; }

/* ---- auth pages ---- */
.auth-wrap { max-width: 380px; margin: 60px auto; padding: 0 16px; }
.auth-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: 28px; }
.auth-card h1 { font-size: 22px; margin: 0 0 4px; }
.auth-card .sub { color: var(--text-secondary); font-size: 14px; margin: 0 0 20px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.field input { width: 100%; box-sizing: border-box; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-1); color: var(--text-primary); font-size: 14px; }
.field input:focus { outline: 2px solid var(--blue); outline-offset: 1px; }
.auth-error { background: rgba(211,59,59,0.1); color: var(--critical, #d03b3b); border-radius: 8px; padding: 8px 12px; font-size: 13px; margin-bottom: 14px; }
.auth-note { background: var(--blue-tint); color: var(--blue); border-radius: 8px; padding: 8px 12px; font-size: 13px; margin-bottom: 14px; line-height: 1.45; }
.auth-submit { width: 100%; padding: 11px; border-radius: 8px; border: none; background: var(--blue); color: #fff; font-size: 15px; font-weight: 600; cursor: pointer; }
.auth-submit:hover { filter: brightness(1.06); }
.auth-switch { text-align: center; font-size: 13px; color: var(--text-secondary); margin-top: 18px; }
.auth-switch a { color: var(--blue); cursor: pointer; text-decoration: none; }
.auth-switch a:hover { text-decoration: underline; }
.auth-forgot-row { text-align: right; margin: -8px 0 16px; font-size: 12.5px; }
.auth-forgot-row a { color: var(--blue); cursor: pointer; text-decoration: none; }
.auth-forgot-row a:hover { text-decoration: underline; }

/* ---- premium / paywall ---- */
.deck-card.locked { opacity: 0.7; }
.tier-badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; letter-spacing: 0.02em; }
.tier-badge.premium { background: rgba(250,178,25,0.18); color: #9a6a00; }
.tier-badge.trial { background: var(--blue-tint); color: var(--blue); }
@media (prefers-color-scheme: dark) { .tier-badge.premium { color: var(--warning); } }
.quiz-mode-badge.trial { color: var(--blue); background: var(--blue-tint); }
.quiz-mode-badge.trial a { color: inherit; text-decoration: underline; cursor: pointer; margin-left: 2px; }
.lock-overlay { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 10px; background: var(--page); border-radius: 8px; font-size: 13px; color: var(--text-secondary); margin-top: 8px; }
.upgrade-banner { background: linear-gradient(135deg, rgba(42,120,214,0.12), rgba(250,178,25,0.12)); border: 1px solid var(--border); border-radius: 12px; padding: 16px 20px; display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.upgrade-banner .msg strong { display: block; font-size: 15px; margin-bottom: 2px; }
.upgrade-banner .msg span { font-size: 13px; color: var(--text-secondary); }
.topbar-user {
  display: flex; align-items: center; gap: 8px 10px; font-size: 13px; color: var(--text-secondary);
  flex-wrap: wrap; justify-content: flex-end; width: 100%;
}
.topbar-user button { flex-shrink: 0; }
.topnav-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.topbar-user .plan-pill { font-weight: 700; padding: 2px 9px; border-radius: 999px; font-size: 11px; }
.plan-pill.free { background: var(--gridline); color: var(--text-secondary); }
.plan-pill.premium { background: rgba(250,178,25,0.2); color: #9a6a00; }
@media (prefers-color-scheme: dark) { .plan-pill.premium { color: var(--warning); } }

/* ---- persistent top nav (visible from every view, not just home) ---- */
#topnav { display: flex; justify-content: flex-end; padding: 10px 20px 0; max-width: 900px; margin: 0 auto; }

/* ---- insights page ---- */
.insights-locked { text-align: center; padding: 70px 20px; }
.insights-locked .icon { font-size: 40px; margin-bottom: 10px; }
.insights-locked h2 { margin: 0 0 8px; }
.insights-locked p { color: var(--text-secondary); max-width: 420px; margin: 0 auto 20px; }
.insights-grid { display: grid; grid-template-columns: 1fr; gap: 20px; margin-top: 18px; }
@media (min-width: 800px) { .insights-grid { grid-template-columns: 1.3fr 1fr; } }
.insight-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: 18px 20px; }
.insight-card h3 { margin: 0 0 4px; font-size: 15px; }
.insight-card .insight-sub { color: var(--text-secondary); font-size: 12.5px; margin-bottom: 14px; }
.settings-card { max-width: 480px; }
.insight-empty { color: var(--text-secondary); font-size: 13px; text-align: center; padding: 30px 10px; }

/* ---- insights: per-deck cards (pie + known-over-time chart + toughest cards) ---- */
.deck-insight-card { }
.deck-insight-header { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.deck-insight-pie { background: none; border: none; padding: 0; cursor: pointer; border-radius: 10px; flex-shrink: 0; }
.deck-insight-pie:hover { background: var(--gridline); }
.deck-insight-title h3 { margin: 0 0 2px; font-size: 15px; }
.deck-insight-title .insight-sub { margin: 0; font-size: 12.5px; }
.deck-insight-label { font-size: 12px; font-weight: 700; color: var(--text-secondary); margin-bottom: 8px; }

.top-missed-list { display: flex; flex-direction: column; gap: 6px; }
.top-missed-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%;
  padding: 8px 12px; background: var(--page); border: 1px solid var(--border); border-radius: 8px; font-size: 13px;
  font-family: inherit; color: inherit; text-align: left; cursor: pointer;
}
.top-missed-item:hover { border-color: var(--border-strong); background: var(--surface-2); }
.top-missed-item .tm-front { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-missed-item .tm-count {
  flex-shrink: 0; font-size: 11px; font-weight: 700; color: var(--serious);
  background: rgba(236,131,90,0.14); border-radius: 999px; padding: 2px 9px;
}

.uq-history-list { display: flex; flex-direction: column; gap: 8px; }
.uq-history-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%;
  padding: 10px 12px; background: var(--page); border: 1px solid var(--border); border-radius: 8px;
  font-family: inherit; color: inherit; text-align: left; cursor: pointer;
}
.uq-history-row:hover { border-color: var(--border-strong); background: var(--surface-2); }
.uq-history-row.expanded { border-color: var(--blue); border-radius: 8px 8px 0 0; }
.uq-history-main { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; }
.uq-history-pct {
  flex-shrink: 0; font-size: 14px; font-weight: 800; border-radius: 999px; padding: 6px 11px; min-width: 44px; text-align: center;
}
.uq-history-pct.good { color: var(--good-text); background: rgba(12,163,12,0.13); }
.uq-history-pct.warning { color: var(--serious); background: rgba(250,178,25,0.16); }
.uq-history-pct.serious { color: var(--critical); background: rgba(208,59,59,0.13); }
.uq-history-detail { min-width: 0; }
.uq-history-line { font-size: 13px; font-weight: 600; }
.uq-history-decks { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uq-history-when { flex-shrink: 0; font-size: 11.5px; color: var(--text-muted); text-align: right; line-height: 1.4; }
.uq-history-chevron { flex-shrink: 0; font-size: 12px; color: var(--text-muted); margin: 0 2px; }

.uq-run-detail {
  margin: -2px 0 8px; padding: 4px 12px 12px; background: var(--page);
  border: 1px solid var(--blue); border-top: none; border-radius: 0 0 8px 8px;
}
.uq-run-card-list { display: flex; flex-direction: column; gap: 5px; max-height: 340px; overflow-y: auto; }
.uq-run-card {
  display: flex; align-items: flex-start; gap: 9px; padding: 7px 9px;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 7px; font-size: 12.5px;
}
.uq-run-card-mark { flex-shrink: 0; font-weight: 800; font-size: 13px; width: 16px; text-align: center; line-height: 1.4; }
.uq-run-card-mark.good { color: var(--good-text); }
.uq-run-card-mark.serious { color: var(--critical); }
.uq-run-card-text { min-width: 0; flex: 1; }
.uq-run-card-front { color: var(--text-primary); }
.uq-run-card-back { color: var(--text-secondary); font-size: 12px; margin-top: 2px; }
.uq-run-card-deck { flex-shrink: 0; font-size: 11px; color: var(--text-muted); max-width: 130px; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.review-card-flash {
  animation: reviewCardFlash 1.8s ease-out 1;
}
@keyframes reviewCardFlash {
  0% { box-shadow: 0 0 0 3px var(--blue); background: var(--blue-tint); }
  100% { box-shadow: 0 0 0 0 rgba(0,0,0,0); background: none; }
}

.chart-legend { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-top: 12px; font-size: 12px; color: var(--text-secondary); }
.chart-legend .item { display: flex; align-items: center; gap: 6px; }
.chart-legend .swatch { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.chart-legend .swatch.round { border-radius: 50%; }
.chart-tooltip-label { font-size: 11px; }

.stat-tile-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.stat-tile-row .stat-tile { flex: 1; min-width: 120px; }

/* ---- ultimate quiz ---- */
.ultimate-banner {
  background: linear-gradient(135deg, rgba(74,58,167,0.10), rgba(42,120,214,0.10));
  border: 1px solid var(--border); border-radius: 12px; padding: 16px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  margin-bottom: 18px; flex-wrap: wrap;
}
.ultimate-banner .msg strong { display: block; font-size: 15px; margin-bottom: 2px; }
.ultimate-banner .msg span { font-size: 13px; color: var(--text-secondary); }
.deck-origin-badge {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 700;
  color: var(--text-secondary); background: var(--gridline);
  border-radius: 999px; padding: 3px 10px; margin-bottom: 4px;
}

/* ---- insights: recommendation banner + right/wrong mini charts ---- */
.recommendation-banner {
  display: flex; align-items: flex-start; gap: 12px;
  border-radius: 12px; padding: 14px 18px; margin: 4px 0 18px; font-size: 13.5px;
  border: 1px solid var(--border);
}
.recommendation-banner .icon { font-size: 20px; line-height: 1; }
.recommendation-banner strong { font-weight: 700; }
.recommendation-banner.weak { background: rgba(250,178,25,0.10); }
.recommendation-banner.new { background: var(--blue-tint); }
.recommendation-banner.good { background: rgba(12,163,12,0.10); }
.rec-link { color: var(--blue); font-weight: 700; text-decoration: none; }
.rec-link:hover { text-decoration: underline; }

.right-wrong-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 14px; margin-top: 14px; }
.right-wrong-tile {
  text-align: center; background: none; border: 1px solid transparent; border-radius: 10px;
  padding: 8px 4px; cursor: pointer; font: inherit; color: inherit; transition: background 0.15s, border-color 0.15s;
}
.right-wrong-tile:hover { background: var(--card-bg-hover, var(--gridline)); border-color: var(--border); }
.rw-name { font-size: 11.5px; color: var(--text-secondary); margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- landing page ---- */
.landing-nav {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 1000px; margin: 0 auto; padding: 20px 20px 0; flex-wrap: wrap; row-gap: 10px;
}
.landing-wordmark { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; color: var(--text-primary); text-decoration: none; }
.landing-nav-actions { display: flex; align-items: center; gap: 10px; }

.landing-hero {
  max-width: 720px; margin: 0 auto; padding: 88px 20px 40px; text-align: center;
}
.landing-hero h1 {
  font-size: 40px; line-height: 1.15; margin: 0 0 16px;
}
.landing-hero p.landing-sub {
  font-size: 17px; color: var(--text-secondary); line-height: 1.55; margin: 0 auto 30px; max-width: 560px;
}
.landing-cta-row { display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap; }
.landing-cta-row button { padding: 11px 22px; font-size: 15px; }

.landing-features {
  max-width: 1000px; margin: 20px auto 0; padding: 40px 20px 20px;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px;
}
.landing-feature-card {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: 22px;
}
.landing-feature-card .landing-feature-icon { font-size: 22px; margin-bottom: 10px; }
.landing-feature-card h3 { font-size: 15.5px; margin: 0 0 8px; }
.landing-feature-card p { font-size: 13.5px; color: var(--text-secondary); line-height: 1.55; margin: 0; }

.landing-decks {
  max-width: 720px; margin: 10px auto 0; padding: 20px 20px 0; text-align: center;
}
.landing-decks h2 { font-size: 20px; margin: 0 0 14px; }
.landing-deck-chip-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.landing-deck-chip {
  font-size: 12.5px; color: var(--text-secondary); background: var(--gridline);
  border-radius: 999px; padding: 6px 14px;
}

.landing-footer-cta {
  max-width: 560px; margin: 60px auto 0; padding: 40px 20px 90px; text-align: center;
}
.landing-footer-cta h2 { font-size: 22px; margin: 0 0 10px; }
.landing-footer-cta p { color: var(--text-secondary); font-size: 14px; margin: 0 0 22px; }

.landing-footer {
  border-top: 1px solid var(--border); padding: 20px; text-align: center;
  font-size: 12.5px; color: var(--text-muted);
}
.rw-pct { font-size: 11px; font-weight: 700; color: var(--text-primary); margin-top: 4px; }

/* ---- email verification gate ---- */
.verify-gate {
  max-width: 440px; margin: 90px auto 0; padding: 0 20px; text-align: center;
}
.verify-gate h1 { font-size: 24px; margin: 0 0 14px; }
.verify-gate p { color: var(--text-secondary); font-size: 14px; line-height: 1.55; margin: 0 0 24px; }
.verify-gate button { margin: 0 6px; }

/* ---- mobile phones ---- */
@media (max-width: 480px) {
  #app { padding: 14px 14px 70px; }
  #topnav { padding: 8px 14px 0; }
  .topbar-user { justify-content: center; }
  .topnav-email { max-width: 150px; }

  .landing-nav { padding: 16px 16px 0; }
  .landing-wordmark { font-size: 15px; }
  .landing-hero { padding: 48px 16px 30px; }
  .landing-hero h1 { font-size: 30px; }
  .landing-hero p.landing-sub { font-size: 15px; }
  .landing-features { padding: 30px 16px 20px; }
  .landing-footer-cta { margin-top: 40px; padding: 30px 16px 70px; }

  .verify-gate { margin-top: 50px; }

  .card-row, .add-card-form { grid-template-columns: 1fr; }
  .card-row textarea, .card-row input { width: 100%; }

  .auth-wrap { margin: 30px auto; }
}
