/* ── Reset & base ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #f8f8f6;
  --surface:     #ffffff;
  --surface2:    #f2f1ed;
  --border:      rgba(0,0,0,.10);
  --border-med:  rgba(0,0,0,.18);
  --text:        #1a1a18;
  --text-2:      #5a5a56;
  --text-3:      #8a8a84;
  --blue:        #185FA5;
  --blue-bg:     #E6F1FB;
  --green:       #3B6D11;
  --green-bg:    #EAF3DE;
  --green-mid:   #1D9E75;
  --red:         #A32D2D;
  --red-bg:      #FCEBEB;
  --amber:       #854F0B;
  --amber-bg:    #FAEEDA;
  --radius-sm:   6px;
  --radius-md:   10px;
  --radius-lg:   14px;
  --shadow:      0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --font:        -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:         #1a1a18;
    --surface:    #242420;
    --surface2:   #2e2e2a;
    --border:     rgba(255,255,255,.10);
    --border-med: rgba(255,255,255,.18);
    --text:       #f0f0ec;
    --text-2:     #a0a09a;
    --text-3:     #6a6a64;
    --blue:       #5BA3E8;
    --blue-bg:    #0d2a45;
    --green:      #7DC44A;
    --green-bg:   #1a2e0a;
    --green-mid:  #1D9E75;
    --red:        #E86868;
    --red-bg:     #3a1010;
    --amber:      #D4901A;
    --amber-bg:   #3a2200;
  }
}

html { font-size: 16px; overflow-x: hidden; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Fixed background canvas ─────────────────────────────────────────────── */
.bg-blobs {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}
.bg-blobs::before,
.bg-blobs::after {
  content: '';
  position: absolute;
  border-radius: 50%;
}
.bg-blobs::before {
  width: 520px; height: 520px;
  background: radial-gradient(circle, rgba(29,158,117,.22) 0%, transparent 68%);
  top: -200px; left: -200px;
}
.bg-blobs::after {
  width: 440px; height: 440px;
  background: radial-gradient(circle, rgba(24,95,165,.18) 0%, transparent 68%);
  bottom: -180px; right: -160px;
}
@media (prefers-color-scheme: dark) {
  .bg-blobs::before { background: radial-gradient(circle, rgba(29,158,117,.18) 0%, transparent 68%); }
  .bg-blobs::after  { background: radial-gradient(circle, rgba(24,95,165,.15) 0%, transparent 68%); }
}

/* ── Layout ───────────────────────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

header {
  background: var(--surface);
  border-bottom: 0.5px solid var(--border);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  position: sticky;
  top: 0;
  z-index: 10;
}

/* Centered deck name shown while studying */
.header-context {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 36%;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.header-context-visible {
  opacity: 1;
}

/* Quiz sticky footer */
.quiz-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--surface);
  border-top: 0.5px solid var(--border);
  box-shadow: 0 -6px 24px rgba(0,0,0,.07);
  z-index: 90;
  transform: translateY(0);
  transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}
.quiz-footer-hidden {
  transform: translateY(110%);
}
.quiz-footer .btn-primary { flex: 1; }
.quiz-footer .btn-back    { flex: 0 0 auto; }

.logo {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
.logo-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green-mid); }

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

nav { display: flex; gap: 4px; }
nav button {
  background: none;
  border: none;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-2);
  cursor: pointer;
  transition: background .15s, color .15s;
}
nav button:hover { background: var(--surface2); color: var(--text); }
nav button.active { background: var(--surface2); color: var(--text); font-weight: 500; }

/* ── Header menu ──────────────────────────────────────────────────────────── */
.menu-wrap { position: relative; }

.menu-btn {
  width: 32px; height: 32px;
  padding: 0;
  border-radius: var(--radius-sm);
  background: none;
  border: none;
  color: var(--text-3);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.menu-btn:hover { background: var(--surface2); color: var(--text); }
.menu-btn.open  { background: var(--surface2); color: var(--text); }

.menu-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface);
  border: 0.5px solid var(--border-med);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0,0,0,.12), 0 2px 6px rgba(0,0,0,.06);
  min-width: 188px;
  padding: 4px;
  z-index: 50;
}
.menu-dropdown.hidden { display: none !important; }

.menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-2);
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  transition: background .12s, color .12s;
}
.menu-item:hover:not(:disabled) { background: var(--surface2); color: var(--text); }
.menu-item:disabled { opacity: .38; cursor: not-allowed; }
.menu-item-danger { color: var(--red) !important; }
.menu-item-danger:hover:not(:disabled) { background: var(--red-bg) !important; color: var(--red) !important; }

.menu-divider { height: 0.5px; background: var(--border); margin: 4px 0; }

.menu-reset-confirm,
.menu-import-confirm {
  padding: 8px 10px 6px;
  border-radius: 6px;
  background: var(--surface2);
  margin-top: 2px;
}
.menu-reset-confirm p,
.menu-import-confirm p { font-size: 12px; color: var(--text-2); margin-bottom: 8px; }
.menu-confirm-btns { display: flex; gap: 6px; }
.menu-confirm-btns .btn { flex: 1; font-size: 12px; padding: 5px 10px; }
.menu-confirm-btns .btn:first-child { color: var(--red); border-color: currentColor; }

main { padding: 2rem 1rem; max-width: 680px; margin: 0 auto; width: 100%; overflow-x: hidden; box-sizing: border-box; }

/* ── Cards ────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 1rem; }

/* ── Buttons ──────────────────────────────────────────────────────────── */
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-md);
  border: 0.5px solid var(--border-med);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
  text-decoration: none;
  line-height: 1.4;
}
button:hover:not(:disabled), .btn:hover { background: var(--surface2); border-color: var(--border-med); }
button:active:not(:disabled) { transform: scale(.97); opacity: .82; }
button:disabled { opacity: .4; cursor: not-allowed; }
/* Suppress native mobile highlight so our active state shows cleanly */
button, .btn, a { -webkit-tap-highlight-color: transparent; }

.btn-primary {
  background: var(--text);
  color: var(--surface);
  border-color: transparent;
  font-weight: 500;
}
.btn-primary:hover:not(:disabled) { background: var(--text-2); color: var(--surface); border-color: transparent; }
.btn-primary:active:not(:disabled) { background: var(--text); color: var(--surface); opacity: .8; transform: scale(.97); }

.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* ── Module selector ──────────────────────────────────────────────────── */
.mod-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  margin: 1rem 0;
}
.mod-card {
  background: var(--surface);
  border: 0.5px solid var(--border-med);
  border-radius: var(--radius-md);
  padding: 14px 12px;
  cursor: pointer;
  transition: background .15s, border-color .15s, border-width .1s;
  text-align: left;
}
.mod-card:hover { background: var(--surface2); }
.mod-card.selected {
  border: 2px solid var(--blue);
  background: var(--blue-bg);
}
.mod-card .mod-num  { font-size: 11px; font-weight: 600; color: var(--blue); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .04em; }
.mod-card .mod-name { font-size: 13px; font-weight: 500; color: var(--text); line-height: 1.3; }
.mod-card .mod-cnt  { font-size: 11px; color: var(--text-3); margin-top: 4px; }
.mod-card.selected .mod-num  { color: var(--blue); }

/* ── Progress bar ─────────────────────────────────────────────────────── */
.pbar-wrap { height: 3px; background: var(--surface2); border-radius: 2px; margin-bottom: 1.25rem; overflow: hidden; }
.pbar-fill { height: 100%; background: var(--green-mid); border-radius: 2px; transition: width .4s ease; }

/* ── Meta row ─────────────────────────────────────────────────────────── */
.meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 1rem;
}
.badge {
  font-size: 12px;
  color: var(--text-2);
  background: var(--surface2);
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  border: 0.5px solid var(--border);
}
.mod-tag {
  font-size: 11px;
  font-weight: 600;
  color: var(--blue);
  background: var(--blue-bg);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.round-tag { font-size: 11px; color: var(--text-3); }

/* ── Question ─────────────────────────────────────────────────────────── */
.q-text { font-size: 17px; font-weight: 500; color: var(--text); line-height: 1.55; margin-bottom: 1.25rem; }

.opts { display: grid; gap: 8px; }
.opt {
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 0.5px solid var(--border-med);
  border-radius: var(--radius-md);
  padding: 11px 14px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  transition: background .15s, border-color .15s;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.opt:hover:not(:disabled) { background: var(--surface2); border-color: var(--border-med); }
.opt.correct  { background: var(--green-bg);  border-color: var(--green);  color: var(--green); }
.opt.wrong    { background: var(--red-bg);    border-color: var(--red);    color: var(--red);   }

.opt-ltr {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--surface2);
  border: 0.5px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600;
  flex-shrink: 0;
  margin-top: 1px;
}
.opt.correct .opt-ltr { background: #C0DD97; border-color: var(--green); color: #173404; }
.opt.wrong   .opt-ltr { background: #F7C1C1; border-color: var(--red);   color: #501313; }

/* ── Feedback box ─────────────────────────────────────────────────────── */
.fb {
  margin-top: 1rem;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-size: 14px;
  line-height: 1.6;
  display: none;
}
.fb.ok  { background: var(--green-bg); border: 0.5px solid var(--green); color: var(--green); }
.fb.bad { background: var(--red-bg);   border: 0.5px solid var(--red);   color: var(--red);   }

.fb-label { font-weight: 600; margin-bottom: 6px; }
.fb-explain {
  color: var(--text-2);
  margin-top: 8px;
  padding-top: 8px;
  border-top: 0.5px solid var(--border);
  font-size: 13px;
  line-height: 1.65;
}

/* ── Next / actions row ───────────────────────────────────────────────── */
.action-row {
  display: flex;
  gap: 10px;
  margin-top: 1rem;
}
.action-row .btn-primary { flex: 1; }
.action-row .btn-back    { flex: 0 0 auto; color: var(--text-3); }

/* ── Session counter ──────────────────────────────────────────────────── */
.session-counter {
  font-size: 12px;
  color: var(--text-3);
  text-align: right;
  padding: 4px 2px 0;
}

/* ── Results ──────────────────────────────────────────────────────────── */
.results-center { text-align: center; padding: 0.5rem 0; }

.score-ring { width: 108px; height: 108px; margin: 0 auto 1.25rem; position: relative; }
.score-ring svg { transform: rotate(-90deg); }
.score-pct {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 22px; font-weight: 600;
  color: var(--text);
}
.result-grade { font-size: 18px; font-weight: 600; margin-bottom: 4px; }
.result-sub   { font-size: 14px; color: var(--text-2); margin-bottom: 1.5rem; }

.stats-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; margin-bottom: 1.5rem; }
.stat-box { background: var(--surface2); border-radius: var(--radius-md); padding: 14px; text-align: center; }
.stat-val { font-size: 22px; font-weight: 600; }
.stat-lbl { font-size: 11px; color: var(--text-3); margin-top: 2px; }

.mod-breakdown { text-align: left; margin-bottom: 1.5rem; }
.mod-breakdown h4 { font-size: 12px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 10px; }
.mod-row { display: flex; justify-content: space-between; align-items: center; font-size: 13px; padding: 5px 0; border-bottom: 0.5px solid var(--border); }
.mod-row:last-child { border-bottom: none; }
.mod-row-name { color: var(--text-2); }
.mod-row-score { font-weight: 600; }

.result-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ── Stats page ───────────────────────────────────────────────────────── */
.stats-page h2 { font-size: 18px; font-weight: 600; margin-bottom: 0; }

.stats-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.stats-deck-select {
  background: var(--surface2);
  border: 0.5px solid var(--border-med);
  border-radius: var(--radius-md);
  padding: 6px 10px;
  font-size: 13px;
  color: var(--text);
  font-family: var(--font);
  cursor: pointer;
  max-width: 220px;
}
.stats-deck-select:focus { outline: none; border-color: var(--blue); }

.overview-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px,1fr)); gap: 10px; margin-bottom: 1.5rem; }

.section-title {
  font-size: 12px; font-weight: 600; color: var(--text-3);
  text-transform: uppercase; letter-spacing: .05em;
  margin-bottom: 10px; margin-top: 1.5rem;
}

/* Weak questions list */
.weak-list { display: grid; gap: 8px; }
.weak-item {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  border-left: 3px solid var(--red);
}
.weak-q    { font-size: 13px; font-weight: 500; color: var(--text); margin-bottom: 4px; }
.weak-meta { font-size: 12px; color: var(--text-3); display: flex; gap: 12px; }
.weak-pct  { color: var(--red); font-weight: 600; }

/* Session history table */
.session-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.session-table th { text-align: left; padding: 6px 8px; font-size: 11px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; border-bottom: 0.5px solid var(--border); }
.session-table td { padding: 8px 8px; border-bottom: 0.5px solid var(--border); color: var(--text-2); }
.session-table tr:last-child td { border-bottom: none; }
.pct-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.pct-pill.good   { background: var(--green-bg); color: var(--green); }
.pct-pill.mid    { background: var(--amber-bg); color: var(--amber); }
.pct-pill.low    { background: var(--red-bg);   color: var(--red);   }

/* ── Empty / error states ─────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-3);
  font-size: 14px;
  line-height: 1.7;
}
.empty-state h3 { font-size: 16px; color: var(--text-2); margin-bottom: 8px; }

/* ── Loading ──────────────────────────────────────────────────────────── */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--text-2);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 3rem auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Keyboard hint ────────────────────────────────────────────────────── */
.kbd-hint {
  text-align: center;
  font-size: 12px;
  color: var(--text-3);
  margin-top: 10px;
  line-height: 1.8;
}
.kbd-hint kbd, kbd {
  display: inline-block;
  background: var(--surface);
  border: 0.5px solid var(--border-med);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 11px;
  font-family: -apple-system, BlinkMacSystemFont, monospace;
  color: var(--text-2);
  line-height: 1.6;
}

/* ── File loader polish ───────────────────────────────────────────────── */
#file-loader .file-inner {
  border: 1.5px dashed var(--border-med);
  border-radius: var(--radius-md);
  padding: 28px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  margin-bottom: 10px;
}
#file-loader .file-inner:hover {
  border-color: var(--green-mid);
  background: var(--surface2);
}
#file-loader .file-icon { font-size: 30px; margin-bottom: 10px; }
#file-loader .file-title { font-size: 15px; font-weight: 500; margin-bottom: 4px; }
#file-loader .file-sub { font-size: 13px; color: var(--text-2); margin-bottom: 12px; }

/* ── Misc ─────────────────────────────────────────────────────────────── */
.text-muted  { color: var(--text-3); font-size: 13px; }
.mt-1  { margin-top: 0.5rem; }
.mt-2  { margin-top: 1rem; }
.mb-1  { margin-bottom: 0.5rem; }
.mb-2  { margin-bottom: 1rem; }
.hidden { display: none !important; }

@media (max-width: 480px) {
  main { padding: 1rem 0.75rem; }
  #page-home { margin: -1rem -0.75rem; padding: 1rem 0.75rem; }
  .mod-grid { grid-template-columns: 1fr 1fr; }
  .q-text { font-size: 15px; }
  header { padding: 0 1rem; }
  .deck-entry { overflow: hidden; min-width: 0; }
  .deck-entry-btns { flex-shrink: 0; gap: 6px; }
  .deck-study-btn { font-size: 13px; padding: 7px 12px; }
  .cards-filter-btn { font-size: 11px; padding: 4px 9px; }
  .mode-toggle-btn { font-size: 12px; padding: 8px 8px; }
  .card-row-mod { display: none; }
  .state-badge { font-size: 9px; padding: 2px 5px; }
  /* Cards page: tighter padding on very small screens */
  #page-cards { padding: 1rem 0.75rem 2rem; }
  .cards-header { flex-direction: row; align-items: center; }
  .cards-search { max-width: 180px; }
}

/* ── Home page layout ─────────────────────────────────────────────────── */
#page-home {
  height: calc(100vh - 52px);
  height: calc(100dvh - 52px); /* dynamic viewport — iOS Safari fix */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  position: relative;
  /* escape main's padding so cards go edge-to-edge */
  margin: -2rem -1rem;
  padding: 2rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Scroll-lock when home is active (position:fixed required for iOS rubber-band) */
body.view-home {
  overflow: hidden;
  position: fixed;
  width: 100%;
}

/* ── Home content wrapper ─────────────────────────────────────────────── */
.home-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: 580px;
  position: relative;
  z-index: 1;
  /* push content down so it's roughly centered when the deck list is short */
  margin-top: auto;
  margin-bottom: auto;
}

/* ── Home footer link ─────────────────────────────────────────────────── */
.home-footer-link {
  /* no longer absolute — sits below .home-content in the flex column */
  flex-shrink: 0;
  margin-top: 1.25rem;
  padding-bottom: 0.25rem;
  font-size: 12px;
  color: var(--text-3);
  text-decoration: none;
  white-space: nowrap;
  letter-spacing: .01em;
  transition: color .15s;
  z-index: 1;
}
.home-footer-link:hover { color: var(--text-2); }

/* ── Resume banner ────────────────────────────────────────────────────── */
#resume-card {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 18px;
  background: rgba(29, 158, 117, 0.10);
  backdrop-filter: blur(28px) saturate(180%);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
  border: 1px solid rgba(29, 158, 117, 0.28);
  border-radius: 16px;
  box-shadow: 0 4px 16px rgba(29, 158, 117, .08), inset 0 1px 0 rgba(255,255,255,.6);
  cursor: pointer;
  transition: transform .2s cubic-bezier(.34,1.56,.64,1), box-shadow .2s, background .15s;
  user-select: none;
  -webkit-user-select: none;
  outline: none;
}
#resume-card:hover {
  transform: translateY(-2px) scale(1.01);
  background: rgba(29, 158, 117, 0.15);
  box-shadow: 0 10px 28px rgba(29, 158, 117, .14), inset 0 1px 0 rgba(255,255,255,.7);
}
#resume-card:active        { transform: scale(.98); transition-duration: .08s; }
#resume-card:focus-visible { outline: 2px solid var(--green-mid); outline-offset: 3px; }
#resume-card.hidden        { display: none !important; }

.resume-icon  { color: var(--green-mid); flex-shrink: 0; display: flex; }
.resume-info  { flex: 1; min-width: 0; }
.resume-title { font-size: 14px; font-weight: 600; color: var(--text); }
.resume-sub   { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.resume-arrow { color: var(--green-mid); flex-shrink: 0; display: flex; align-items: center; }

@media (prefers-color-scheme: dark) {
  #resume-card {
    background: rgba(29, 158, 117, 0.12);
    border-color: rgba(29, 158, 117, 0.22);
    box-shadow: 0 4px 16px rgba(0,0,0,.3), inset 0 1px 0 rgba(255,255,255,.06);
  }
  #resume-card:hover {
    background: rgba(29, 158, 117, 0.18);
    box-shadow: 0 10px 28px rgba(0,0,0,.4), inset 0 1px 0 rgba(255,255,255,.08);
  }
}

/* ── Mode grid ────────────────────────────────────────────────────────── */
.mode-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  width: 100%;
  max-width: 580px;
}

/* div-based cards (avoids all the global `button` rule conflicts) */
.mode-card {
  background: rgba(255, 255, 255, 0.68);
  backdrop-filter: blur(28px) saturate(180%);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 20px;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, .08),
    0 2px 8px rgba(0, 0, 0, .04),
    inset 0 1.5px 0 rgba(255, 255, 255, .92);
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  cursor: pointer;
  text-align: center;
  padding: 1.25rem;
  transition: transform .22s cubic-bezier(.34,1.56,.64,1), box-shadow .22s;
  user-select: none;
  -webkit-user-select: none;
  outline: none;
}
.mode-card:hover {
  transform: translateY(-5px) scale(1.025);
  box-shadow:
    0 20px 56px rgba(0, 0, 0, .13),
    0 6px 16px rgba(0, 0, 0, .06),
    inset 0 1.5px 0 rgba(255, 255, 255, .95);
}
.mode-card:active {
  transform: scale(.96);
  transition-duration: .08s;
}
.mode-card:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 3px;
}

@media (prefers-color-scheme: dark) {
  .mode-card {
    background: rgba(36, 36, 32, 0.72);
    border-color: rgba(255, 255, 255, .10);
    box-shadow:
      0 8px 32px rgba(0, 0, 0, .38),
      inset 0 1px 0 rgba(255, 255, 255, .06);
  }
  .mode-card:hover {
    box-shadow:
      0 20px 56px rgba(0, 0, 0, .55),
      inset 0 1px 0 rgba(255, 255, 255, .08);
  }
  .mode-icon-wrap {
    background: rgba(255,255,255,.07) !important;
    border-color: rgba(255,255,255,.12) !important;
  }
}

.mode-icon-wrap {
  width: 54px; height: 54px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  box-shadow: 0 2px 8px rgba(0,0,0,.06), inset 0 1px 0 rgba(255,255,255,.85);
}

.mode-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -.01em;
}
.mode-sub {
  font-size: 11px;
  color: var(--text-3);
  line-height: 1.45;
  max-width: 120px;
}

/* ── Upload card — dashed drop-target style ───────────────────────────── */
#card-upload {
  border: 1.5px dashed var(--border-med) !important;
}
#card-upload:hover {
  border-color: var(--blue) !important;
}
#card-upload.drag-over {
  border-color: var(--green-mid) !important;
  border-width: 2px !important;
  background: rgba(29, 158, 117, 0.06) !important;
  transform: translateY(-5px) scale(1.025);
  box-shadow:
    0 20px 56px rgba(29, 158, 117, .15),
    0 6px 16px rgba(0, 0, 0, .06),
    inset 0 1.5px 0 rgba(255, 255, 255, .95) !important;
}
@media (prefers-color-scheme: dark) {
  #card-upload {
    border-color: rgba(255,255,255,0.22) !important;
  }
  #card-upload.drag-over {
    background: rgba(29, 158, 117, 0.10) !important;
  }
}

@media (max-width: 520px) {
  .home-content { gap: 10px; }

  /* Single column, cards fill the content width */
  .mode-grid {
    grid-template-columns: 1fr;
    gap: 10px;
    max-width: 340px;
    margin: 0 auto;
  }

  /* Horizontal strip: icon left, text right */
  .mode-card {
    aspect-ratio: unset;
    flex-direction: row;
    justify-content: flex-start;
    text-align: left;
    padding: 14px 18px;
    gap: 14px;
    border-radius: 14px;
  }

  .mode-icon-wrap {
    width: 42px; height: 42px;
    border-radius: 11px;
    flex-shrink: 0;
  }
  .mode-icon-wrap svg { width: 20px; height: 20px; }
  .mode-title { font-size: 14px; }
  .mode-sub   { font-size: 12px; max-width: none; }
}

/* ── Modal overlay ────────────────────────────────────────────────────── */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
#modal-overlay.hidden { display: none !important; }

#modal-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 0.5px solid var(--border);
  box-shadow: 0 24px 64px rgba(0, 0, 0, .28);
  width: 100%;
  max-width: 680px;
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
}

/* Bottom-sheet modal on mobile */
@media (max-width: 540px) {
  #modal-overlay {
    align-items: flex-end;
    padding: 0;
  }
  #modal-box {
    border-radius: 20px 20px 0 0;
    max-height: 88dvh;
    width: 100%;
    max-width: 100%;
    border-bottom: none;
  }
}

#modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 0.5px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}
#modal-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
#modal-close {
  width: 28px; height: 28px;
  padding: 0;
  border-radius: 50%;
  background: var(--surface2);
  border: 0.5px solid transparent;
  font-size: 13px;
  color: var(--text-3);
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
#modal-close:hover { background: var(--border-med); color: var(--text); }

#modal-content { padding: 1.25rem; }

/* ── Drop zone (upload modal) ─────────────────────────────────────────── */
#drop-zone {
  border: 2px dashed var(--border-med);
  border-radius: var(--radius-md);
  padding: 2.5rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  user-select: none;
}
#drop-zone:hover,
#drop-zone.drag-over {
  border-color: var(--green-mid);
  background: var(--surface2);
}

.dz-icon  { font-size: 36px; margin-bottom: 10px; }
.dz-title { font-size: 15px; font-weight: 500; color: var(--text); margin-bottom: 4px; }
.dz-sub   { font-size: 13px; color: var(--text-3); margin-bottom: 16px; }

/* ── Create form ──────────────────────────────────────────────────────── */
.create-form { margin-bottom: 4px; }

.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 6px;
}
.form-optional {
  font-weight: 400;
  text-transform: none;
  font-size: 11px;
  color: var(--text-3);
}
.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  background: var(--surface2);
  border: 0.5px solid var(--border-med);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 14px;
  font-family: var(--font);
  color: var(--text);
  resize: vertical;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--blue);
  background: var(--surface);
}
.create-opts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* Create card list */
.section-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 10px;
}
.create-card-list { display: grid; gap: 8px; margin-bottom: 16px; }

.create-card-item {
  background: var(--surface2);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.create-card-num {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-3);
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 50%;
  width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}
.create-card-body { flex: 1; min-width: 0; }
.create-card-q {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 3px;
  overflow-wrap: break-word;
  word-break: break-word;
}
.create-card-ans { font-size: 12px; color: var(--green-mid); }
.create-card-del,
.create-card-edit {
  background: none;
  border: none;
  padding: 2px 5px;
  font-size: 13px;
  cursor: pointer;
  flex-shrink: 0;
  border-radius: 4px;
  color: var(--text-3);
  display: flex; align-items: center; justify-content: center;
}
.create-card-del:hover  { color: var(--red);  background: var(--red-bg);  }
.create-card-edit:hover { color: var(--blue); background: var(--blue-bg); }

/* ── Create-deck option rows ──────────────────────────────────────────── */
.cr-opt-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 7px;
}
.cr-opt-row:last-of-type { margin-bottom: 0; }

/* Numbered circle — click to pick correct answer */
.cr-opt-num {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1.5px solid var(--border-med);
  background: var(--surface);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
  flex-shrink: 0;
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
}
.cr-opt-num:hover:not(.correct) {
  border-color: var(--green-mid);
  color: var(--green-mid);
}
.cr-opt-num.correct {
  border-color: var(--green-mid);
  background: var(--green-mid);
  color: #fff;
}

/* Option text input */
.create-opt-input {
  flex: 1;
  background: var(--surface2);
  border: 0.5px solid var(--border-med);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 14px;
  font-family: var(--font);
  color: var(--text);
  min-width: 0;
  transition: border-color .15s, background .15s;
}
.create-opt-input:focus {
  outline: none;
  border-color: var(--blue);
  background: var(--surface);
}
/* Highlight the correct-answer row's input */
.cr-opt-row.is-correct .create-opt-input {
  border-color: rgba(29, 158, 117, 0.45);
  background: var(--green-bg);
}

/* Remove-option button */
.cr-opt-del {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  border: none;
  background: none;
  color: var(--text-3);
  cursor: pointer;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
  transition: background .12s, color .12s;
}
.cr-opt-del:hover { background: var(--red-bg); color: var(--red); }

/* Add option dashed button */
.cr-add-opt {
  width: 100%;
  padding: 7px;
  border: 1.5px dashed var(--border-med);
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-3);
  font-size: 13px;
  cursor: pointer;
  margin-top: 8px;
  transition: border-color .15s, color .15s, background .15s;
}
.cr-add-opt:hover {
  border-color: var(--green-mid);
  color: var(--green-mid);
  background: var(--green-bg);
}

/* Create footer */
.create-footer {
  display: flex;
  gap: 10px;
  padding-top: 14px;
  border-top: 0.5px solid var(--border);
  margin-top: 4px;
}
.create-footer button { flex: 1; }

/* ── Home section labels ──────────────────────────────────────────────── */
.home-section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 8px;
}
.home-section-label.hidden { display: none !important; }

/* ── Deck Switcher ────────────────────────────────────────────────────── */
#deck-switcher { width: 100%; }
#deck-switcher.hidden { display: none !important; }
#deck-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 24px; }

.deck-entry {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  overflow: hidden;
  background: rgba(255,255,255,0.72);
  backdrop-filter: blur(28px) saturate(180%);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
  border: 0.5px solid rgba(255,255,255,0.55);
  border-radius: 16px;
  box-shadow: 0 4px 16px rgba(0,0,0,.07), inset 0 1px 0 rgba(255,255,255,.9);
  transition: box-shadow .2s, transform .2s;
}
.deck-entry.is-active {
  border-color: rgba(24,95,165,0.3);
  background: rgba(24,95,165,0.06);
  box-shadow: 0 4px 16px rgba(24,95,165,.08), inset 0 1px 0 rgba(255,255,255,.9);
}
.deck-entry-main {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  flex: 1;
  min-width: 0;
}
.deck-entry-icon {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: var(--surface2);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-2);
  flex-shrink: 0;
}
.deck-entry-info { flex: 1; min-width: 0; }
.deck-entry-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.deck-entry-desc {
  font-size: 12px;
  color: var(--text-2);
  margin-top: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.deck-entry-meta {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 5px;
}
.deck-entry-btns {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.deck-study-btn { white-space: nowrap; }

/* Per-deck ⋯ dropdown */
.deck-menu-wrap { position: relative; }
.deck-menu-btn {
  width: 32px; height: 32px;
  padding: 0;
  border-radius: var(--radius-sm);
  background: none;
  border: 0.5px solid var(--border);
  color: var(--text-3);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background .15s, color .15s;
  flex-shrink: 0;
}
.deck-menu-btn:hover { background: var(--surface2); color: var(--text); border-color: var(--border-med); }
.deck-menu {
  /* Position and z-index are set inline by the portal JS */
  background: var(--surface);
  border: 0.5px solid var(--border-med);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0,0,0,.12), 0 2px 6px rgba(0,0,0,.06);
  min-width: 180px;
  padding: 4px;
}

@media (prefers-color-scheme: dark) {
  .deck-entry {
    background: rgba(255,255,255,0.04);
    border-color: rgba(255,255,255,0.10);
    box-shadow: 0 4px 16px rgba(0,0,0,.3), inset 0 1px 0 rgba(255,255,255,.03);
  }
  .deck-entry.is-active {
    background: rgba(24,95,165,0.15);
    border-color: rgba(91,163,232,0.25);
  }
}

@media (max-width: 600px) {
  .deck-entry { flex-direction: column; gap: 12px; }
  .deck-entry-btns { width: 100%; }
  .deck-study-btn { flex: 1; }
}

/* ── Streak badge ─────────────────────────────────────────────────────── */
.streak-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  color: white;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .02em;
  padding: 3px 10px 3px 8px;
  border-radius: 99px;
  margin: 6px 0 2px;
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
  animation: streak-pop 0.25s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes streak-pop {
  from { transform: scale(0.7); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

/* ── Result streak line ───────────────────────────────────────────────── */
.result-streak {
  font-size: 0.9rem;
  font-weight: 600;
  color: #ff6b35;
  margin: 4px 0 8px;
}

/* ── Confidence tap buttons ───────────────────────────────────────────── */
.conf-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 10px;
  flex-wrap: wrap;
}
.conf-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  text-align: center;
  margin-bottom: 4px;
}
.conf-btn {
  flex: 1;
  min-width: 120px;
  max-width: 180px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 0.83rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.conf-btn:hover { background: var(--surface3); }
.conf-btn:active { transform: scale(0.97); }
.conf-got-it.conf-selected {
  background: rgba(52, 199, 89, 0.18);
  border-color: var(--green);
  color: var(--green);
}
.conf-shaky.conf-selected {
  background: rgba(255, 159, 10, 0.15);
  border-color: var(--amber);
  color: var(--amber);
}

/* ── Shuffle toggle in module selector ───────────────────────────────── */
.shuffle-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text);
  user-select: none;
  margin-top: 4px;
}
.shuffle-toggle input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}
.shuffle-toggle:hover { background: var(--surface3); }

/* ── Deck meta fields (Edit deck / Create deck modals) ───────────────── */
.deck-meta-fields {
  padding-bottom: 4px;
}
.deck-meta-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 0 16px;
}

/* ── Accuracy chart ───────────────────────────────────────────────────── */
.chart-card {
  padding: 12px 16px 8px;
  overflow: visible;
}
.accuracy-chart {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}
.chart-label {
  font-size: 10px;
  fill: var(--text-3);
  font-family: inherit;
}
.chart-grid {
  stroke: var(--border);
  stroke-width: 1;
  stroke-dasharray: 3 3;
}
.chart-dot {
  stroke: var(--surface);
  stroke-width: 1.5;
}
.dot-good { fill: var(--green); }
.dot-mid  { fill: #f5a623; }
.dot-low  { fill: var(--red); }

/* Pad page-quiz so content clears the sticky footer when it slides up */
#page-quiz { padding-bottom: 90px; }

/* ── Mobile ───────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  /* Hide keyboard shortcut hints — not relevant on touch */
  .kbd-hint { display: none !important; }
  /* Shrink the centered header context on small screens */
  .header-context { max-width: 28%; font-size: 0.72rem; }
}

/* ── SRS / Mastery state badges ────────────────────────────────────────── */
.state-badge {
  display: inline-flex; align-items: center;
  font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  padding: 2px 7px; border-radius: 99px; flex-shrink: 0;
}
.state-new      { background: rgba(120,120,130,.12); color: var(--text-3); }
.state-learning { background: rgba(234,179,8,.18);   color: #92400e; }
.state-review   { background: rgba(59,130,246,.14);  color: #1e40af; }
.state-known    { background: rgba(34,197,94,.14);   color: #166534; }

/* ── Flag button (in quiz meta-row) ───────────────────────────────────── */
.flag-btn {
  margin-left: auto; background: none; border: none; cursor: pointer;
  color: var(--text-3); padding: 5px 7px;
  border-radius: 8px; line-height: 1; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  transition: color .15s, background .15s;
}
.flag-btn:hover    { background: rgba(239,68,68,.1); color: #ef4444; }
.flag-btn.is-flagged { background: rgba(239,68,68,.12); color: #ef4444; border-radius: 8px; }

/* ── Study mode toggle ────────────────────────────────────────────────── */
.mode-toggle {
  display: flex; gap: 6px;
}
.mode-toggle-btn {
  flex: 1; padding: 9px 10px; border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.5); backdrop-filter: blur(8px);
  color: var(--text-2); font-size: 13px; font-weight: 500;
  cursor: pointer; transition: all .15s;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.mode-toggle-btn.active {
  background: var(--green-mid); color: #fff; border-color: transparent;
  box-shadow: 0 2px 8px rgba(29,158,117,.3);
}
.mode-toggle-btn:not(.active):hover { background: rgba(255,255,255,.8); color: var(--text); }

/* ── Mastery bar (on deck cards) ──────────────────────────────────────── */
.mastery-bar {
  display: flex; height: 4px; border-radius: 2px; overflow: hidden;
  margin-top: 8px; width: 100%;
}
.mastery-seg          { height: 100%; min-width: 0; flex-shrink: 1; }
.mastery-seg.new      { background: rgba(120,120,130,.2); }
.mastery-seg.learning { background: #eab308; }
.mastery-seg.review   { background: #3b82f6; }
.mastery-seg.known    { background: #22c55e; }

/* ── Exam countdown line ──────────────────────────────────────────────── */
.exam-countdown {
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
  font-size: 11px; color: var(--text-3); margin-top: 5px; font-weight: 500;
}
.exam-countdown.urgent { color: #ef4444; }

/* ── Cards view ───────────────────────────────────────────────────────── */
#page-cards {
  overflow-x: hidden;
  box-sizing: border-box;
  padding: 1.5rem 1.25rem 2rem;
  min-width: 0;
  width: 100%;
}

#cards-rows { width: 100%; min-width: 0; }

.cards-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px; gap: 10px; flex-wrap: wrap;
  min-width: 0; width: 100%;
}
.cards-title { font-size: 17px; font-weight: 700; color: var(--text); flex-shrink: 0; }
.cards-search {
  flex: 1; min-width: 0; max-width: 260px; width: 100%;
  box-sizing: border-box;
  padding: 8px 12px; border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.75); backdrop-filter: blur(8px);
  font-size: 13px; color: var(--text); outline: none;
  transition: border-color .15s;
  /* Prevent iOS zoom on focus */
  font-size: max(16px, 13px);
}
.cards-search:focus { border-color: var(--green-mid); }
.cards-filter-bar {
  display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px;
  margin-bottom: 12px; scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  /* Never allow this bar to cause horizontal page overflow */
  max-width: 100%; box-sizing: border-box;
}
.cards-filter-bar::-webkit-scrollbar { display: none; }
.cards-filter-btn {
  flex-shrink: 0; padding: 5px 12px; border-radius: 99px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.6);
  font-size: 12px; font-weight: 500; color: var(--text-2);
  cursor: pointer; transition: background .15s, color .15s, border-color .15s; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 5px;
}
.cards-filter-btn.active { background: var(--green-mid); color: #fff; border-color: transparent; }
.cards-filter-btn:not(.active):hover { background: rgba(255,255,255,.9); color: var(--text); }
.cards-filter-btn:active { transform: scale(.96); opacity: .85; }
.filter-count { opacity: .7; }

.card-row {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; border-radius: 12px;
  background: rgba(255,255,255,.68);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgba(255,255,255,.55);
  margin-bottom: 6px; transition: box-shadow .15s;
  overflow: hidden; max-width: 100%; box-sizing: border-box;
  min-width: 0;
}
.card-row:hover { box-shadow: 0 4px 14px rgba(0,0,0,.07); }
.card-row-q {
  flex: 1; font-size: 13px; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}
.card-row-mod {
  font-size: 11px; color: var(--text-3);
  background: rgba(0,0,0,.05); padding: 2px 6px; border-radius: 6px;
  white-space: nowrap; flex-shrink: 0;
}
.card-row-flag {
  background: none; border: none; cursor: pointer;
  color: var(--text-3); padding: 4px 5px;
  border-radius: 6px; flex-shrink: 0; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  transition: color .15s, background .15s;
}
.card-row-flag:hover   { background: rgba(239,68,68,.1); color: #ef4444; }
.card-row-flag:active  { background: rgba(239,68,68,.18); color: #ef4444; transform: scale(.92); }
.card-row-flag.is-flagged { color: #ef4444; }
.cards-empty {
  text-align: center; padding: 3rem 1rem;
  color: var(--text-3); font-size: 14px;
}

@media (prefers-color-scheme: dark) {
  .state-learning { color: #fbbf24; }
  .state-review   { color: #60a5fa; }
  .state-known    { color: #4ade80; }
  .cards-search   { background: rgba(255,255,255,.08); }
  .cards-filter-btn { background: rgba(255,255,255,.07); }
  .card-row       { background: rgba(255,255,255,.07); border-color: rgba(255,255,255,.1); }
  .mode-toggle-btn { background: rgba(255,255,255,.07); }
}
