:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --primary: #4f46e5;
  --primary-2: #6366f1;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --danger: #ef4444;
  --radius: 16px;
  --fscale: 1;
}

/* Font size preference */
[data-font="small"]   { --fscale: 0.85; }
[data-font="default"] { --fscale: 1; }
[data-font="large"]   { --fscale: 1.2; }
[data-font="xl"]      { --fscale: 1.45; }

/* ---- Theme modes ---- */
/* Dark palette (default, and applied when [data-theme="dark"]). */
:root,
[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
}
/* Light palette. */
[data-theme="light"] {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
}
/* System: follow the device when no explicit choice is stored. */
@media (prefers-color-scheme: light) {
  [data-theme="system"] {
    --bg: #f8fafc;
    --surface: #ffffff;
    --surface-2: #e2e8f0;
    --text: #0f172a;
    --muted: #64748b;
  }
}

/* ---- Accent colors (work in both light and dark) ---- */
[data-accent="indigo"] { --primary: #4f46e5; --primary-2: #6366f1; }
[data-accent="blue"]   { --primary: #2563eb; --primary-2: #3b82f6; }
[data-accent="teal"]   { --primary: #0d9488; --primary-2: #14b8a6; }
[data-accent="green"]  { --primary: #16a34a; --primary-2: #22c55e; }
[data-accent="purple"] { --primary: #7c3aed; --primary-2: #8b5cf6; }
[data-accent="rose"]   { --primary: #e11d48; --primary-2: #f43f5e; }
[data-accent="orange"] { --primary: #ea580c; --primary-2: #f97316; }
[data-accent="cranberry"] { --primary: #a4133c; --primary-2: #c9184a; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100%;
}

body {
  padding-bottom: env(safe-area-inset-bottom);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 12px) 16px 8px;
  border-bottom: 1px solid var(--surface-2);
}

.app-header h1 {
  margin: 0 0 10px;
  font-size: 22px;
  text-align: center;
}

.gear-btn {
  position: absolute;
  left: 12px;
  top: calc(env(safe-area-inset-top) + 8px);
  width: 40px;
  height: 40px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  border-radius: 10px;
}
.gear-btn:active { background: var(--surface-2); }

.bulb-btn {
  position: absolute;
  left: 52px;
  top: calc(env(safe-area-inset-top) + 8px);
  width: 40px;
  height: 40px;
  border: 0;
  background: transparent;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  border-radius: 10px;
}
.bulb-btn:active { background: var(--surface-2); }

/* Home startup-tip preference */
.home-tips-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 18px;
}
.see-all-btn { width: 100%; margin-bottom: 10px; }
.tips-startup-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--muted);
}
.tips-startup-row input { width: 18px; height: 18px; }

/* Tips modal — yellow thought bubbles */
.modal-bulb { font-size: 26px; flex: 0 0 auto; line-height: 1; }
.tips-list { list-style: none; margin: 0 0 6px; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.tip-item {
  position: relative;
  display: flex;
  gap: 10px;
  background: #fef3c7;
  color: #3a2f10;
  border: 1px solid #fcd34d;
  border-radius: 16px 16px 16px 4px;
  padding: 12px 14px;
}
.tip-item::before,
.tip-item::after {
  content: "";
  position: absolute;
  left: 6px;
  background: #fef3c7;
  border: 1px solid #fcd34d;
  border-radius: 50%;
}
.tip-item::before { bottom: -7px; width: 10px; height: 10px; }
.tip-item::after { bottom: -14px; left: 2px; width: 6px; height: 6px; }
.tip-ico { font-size: calc(20px * var(--fscale)); line-height: 1.3; flex: 0 0 auto; }
.tip-body { min-width: 0; }
.tip-title { font-weight: 700; font-size: calc(14.5px * var(--fscale)); margin: 0 0 2px; }
.tip-text { font-size: calc(13.5px * var(--fscale)); line-height: 1.5; margin: 0; }

/* Contextual tip toast (shown while navigating, if enabled) */
.tip-toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 18px);
  transform: translateX(-50%) translateY(12px);
  z-index: 40;
  max-width: min(92vw, 380px);
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: #fef3c7;
  color: #3a2f10;
  border: 1px solid #fcd34d;
  border-radius: 14px;
  padding: 10px 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
  font-size: calc(13.5px * var(--fscale));
  line-height: 1.45;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.tip-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
.tip-toast .tip-ico { font-size: calc(18px * var(--fscale)); }
.tip-toast-x {
  border: 0; background: transparent; color: #7c5b12;
  font-size: 18px; line-height: 1; cursor: pointer; padding: 0 2px; flex: 0 0 auto;
}

.avatar-btn {
  position: fixed;
  right: 12px;
  top: calc(env(safe-area-inset-top) + 8px);
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  z-index: 11;
}
.avatar-btn:active { transform: scale(0.95); }

/* Profiles modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.hidden { display: none; }
.modal-card {
  background: var(--bg);
  border: 1px solid var(--surface-2);
  border-radius: 16px;
  width: 100%;
  max-width: 380px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 18px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.4);
}
.modal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.modal-head h2 { margin: 0; font-size: 18px; flex: 1; }
.modal-flipper { width: 34px; height: 34px; flex: 0 0 auto; }
.modal-x {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}
.profile-list { list-style: none; margin: 0 0 12px; padding: 0; }
.profile-row { display: flex; align-items: center; gap: 6px; padding: 4px 0; }
.profile-pick {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
  color: var(--text);
  text-align: left;
}
.profile-row.active .profile-pick { border-color: var(--primary); }
.profile-row.active .pname { font-weight: 700; }
.avatar {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.active-check { color: var(--primary); font-weight: 700; flex: 0 0 auto; }
.row-act {
  flex: 0 0 auto;
  width: 34px;
  height: 38px;
  border: 1px solid var(--surface-2);
  background: var(--surface);
  color: var(--text);
  border-radius: 9px;
  cursor: pointer;
  font-size: 15px;
}
.row-act.color { font-size: 18px; }
.row-act:active { transform: scale(0.95); }
.modal-note { color: var(--muted); font-size: 12.5px; line-height: 1.5; margin: 4px 0 0; }
#add-profile-btn { width: 100%; }

.deck-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  align-items: stretch;
}

#deck-select {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--surface-2);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  font-weight: 600;
  appearance: none;
  -webkit-appearance: none;
}

.icon-btn {
  flex: 0 0 auto;
  width: 42px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--surface-2);
  border-radius: 10px;
  font-size: 17px;
  cursor: pointer;
}
.icon-btn:active { transform: scale(0.95); }

.tabs {
  display: flex;
  gap: 8px;
  background: var(--surface);
  border-radius: 12px;
  padding: 4px;
}

.tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 10px;
  font-size: 15px;
  font-weight: 600;
  border-radius: 9px;
  cursor: pointer;
}

.tab.active {
  background: var(--primary);
  color: #fff;
}

main {
  padding: 16px;
  max-width: 640px;
  margin: 0 auto;
}

.view { display: none; }
.view.active { display: block; }
.hidden { display: none !important; }

/* Home */
.welcome {
  text-align: center;
  padding: 24px 8px;
}
.welcome-icon { line-height: 0; margin-bottom: 8px; }
.welcome-icon svg { width: 156px; height: 156px; filter: drop-shadow(0 10px 22px rgba(0,0,0,.24)); }

/* Flipper mascot emblems */
.head-with-flipper { display: flex; align-items: center; gap: 10px; }
.flipper-emblem { width: 32px; height: 32px; flex: 0 0 auto; filter: drop-shadow(0 3px 6px rgba(0,0,0,.25)); }
.progress-line { display: flex; align-items: center; gap: 8px; }
.study-mascot { text-align: center; line-height: 0; margin: 2px 0 12px; }
.flipper-study { width: 68px; height: 68px; filter: drop-shadow(0 6px 14px rgba(0,0,0,.24)); }
.welcome h2 { margin: 8px 0; font-size: 24px; }
.welcome p { color: var(--muted); font-size: 16px; line-height: 1.5; }
.home-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 22px auto 0;
  max-width: 320px;
}
.home-actions .btn { padding: 15px; font-size: 16px; }
.home-tip {
  margin-top: 26px;
  font-size: 13px;
}
.home-tip code {
  background: var(--surface);
  padding: 2px 5px;
  border-radius: 5px;
  color: var(--text);
}

/* Appearance settings */
.appearance {
  margin-top: 30px;
  text-align: left;
  border-top: 1px solid var(--surface-2);
  padding-top: 18px;
}
.appearance h3 { margin: 0 0 14px; font-size: 15px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.setting-label { font-size: calc(16px * var(--fscale)); font-weight: 600; }

.segmented {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}
.seg {
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.seg.active { background: var(--primary); color: #fff; }

.font-preview {
  margin: 10px 0 0;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: 8px;
  color: var(--muted);
  font-size: calc(16px * var(--fscale));
  line-height: 1.35;
}

.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--sw);
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  position: relative;
}
.swatch.active {
  border-color: var(--text);
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--sw);
}
.swatch.active::after {
  content: "✓";
  color: #fff;
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
}

/* Study deck picker */
#deck-picker h2 { font-size: 20px; margin: 4px 0 6px; }

.resume-study-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 12px 0;
  padding: 12px;
  border: 1px solid var(--primary-2);
  border-radius: 14px;
  background: color-mix(in srgb, var(--primary) 9%, var(--surface));
}
.resume-study-panel strong { display: block; }
.resume-study-panel p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}
.resume-study-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 6px;
}

.search-row {
  display: flex;
  gap: 8px;
  margin: 10px 0 4px;
}
#search-input {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--surface-2);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 15px;
}
.search-row .btn { flex: 0 0 auto; }
.search-status { color: var(--muted); font-size: 13px; min-height: 1em; margin: 2px 0 0; }

.backup-restore {
  margin: 14px 0;
  padding: 14px;
  border: 1px solid var(--surface-2);
  border-radius: 14px;
  background: var(--surface);
}
.backup-restore h3 { margin: 0 0 6px; font-size: 16px; }
.backup-restore .help { margin: 0 0 12px; }
.backup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.backup-actions .btn { flex: 1 1 180px; text-align: center; }
#backup-status { margin: 8px 0 0; min-height: 0; }

/* Auto-generate a deck */
.generator {
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 14px;
}
.generator h3 { margin: 0 0 10px; font-size: 16px; }
.gen-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
#gen-topic {
  flex: 1 1 180px;
  min-width: 0;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--surface-2);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
}
#gen-count {
  flex: 0 0 auto;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--surface-2);
  border-radius: 10px;
  padding: 10px 8px;
  font-size: 15px;
  font-weight: 600;
}
.deck-list-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
}
.deck-list-heading .help { margin: 0; }
.deck-list-heading .btn { white-space: nowrap; }
.study-mode-picker {
  display: grid;
  gap: 8px;
  margin: 14px 0;
}
.study-mode-option {
  width: 100%;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 11px 13px;
  border: 2px solid var(--surface-2);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.study-mode-option.active {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 12%, var(--surface));
}
.study-mode-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 18px;
  font-weight: 800;
}
.study-mode-option.active .study-mode-icon { background: var(--primary); color: #fff; }
.study-mode-option strong { display: block; font-size: 15px; }
.study-mode-option small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.25;
}
.deck-list {
  list-style: none;
  padding: 0;
  margin: 14px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.deck-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: 12px;
  padding: 8px 10px;
}
.deck-item.disabled { opacity: 0.5; cursor: default; }
.deck-select-label {
  min-width: 0;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 6px;
  cursor: pointer;
}
.deck-item input[type=checkbox] {
  width: 22px;
  height: 22px;
  accent-color: var(--primary);
  flex: 0 0 auto;
}
.deck-item-name { flex: 1; font-weight: 600; font-size: 16px; overflow-wrap: anywhere; }
.deck-item-count {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 13px;
  background: var(--surface-2);
  border-radius: 20px;
  padding: 2px 10px;
}
.deck-reorder-btn,
.deck-move-btn {
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  cursor: pointer;
}
.deck-reorder-btn {
  width: 30px;
  height: 36px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}
.deck-reorder-controls {
  display: none;
  gap: 2px;
}
.deck-row.reordering .deck-reorder-btn { display: none; }
.deck-row.reordering .deck-reorder-controls { display: flex; }
.deck-move-btn {
  width: 30px;
  height: 36px;
  padding: 0;
  font-size: 18px;
  background: var(--surface-2);
}
.deck-move-btn:disabled { opacity: 0.35; cursor: default; }

/* Swipe-to-reveal deck actions (Edit / Share / Hide) */
.deck-row {
  position: relative;
  overflow: hidden;
  border-radius: 12px;
}
.deck-swipe {
  position: relative;
  z-index: 1;
  transition: transform 0.18s ease;
  will-change: transform;
}
.deck-actions {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  display: flex;
  z-index: 0;
}
.deck-actions button {
  width: 88px;
  border: 0;
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
}
.deck-actions:has(.deck-edit-btn) button { width: 78px; }
.deck-edit-btn { background: #0f766e; }
.deck-share-btn { background: var(--primary); }
.deck-hide-btn { background: var(--danger); }
.deck-row.revealed .deck-swipe { transform: translateX(-176px); }
.deck-row:has(.deck-edit-btn).revealed .deck-swipe { transform: translateX(-234px); }
@media (hover: hover) {
  .deck-row:hover .deck-swipe { transform: translateX(-176px); }
  .deck-row:has(.deck-edit-btn):hover .deck-swipe { transform: translateX(-234px); }
}

/* Individual card manager */
.card-manager-head { margin-bottom: 4px; }
.card-manager-head .btn { flex: 0 0 auto; }
.card-manager-help { margin: 4px 0 12px; }
.card-manager-search {
  display: flex;
  gap: 8px;
  margin-bottom: 4px;
}
#card-manager-search {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--surface-2);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
}
.card-manager-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}
.card-manager-row {
  width: 100%;
  border: 1px solid var(--surface-2);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  padding: 12px 14px;
  text-align: left;
  cursor: pointer;
}
.card-manager-row-question,
.card-manager-row-answer {
  display: block;
  overflow-wrap: anywhere;
}
.card-manager-row-question { font-weight: 700; }
.card-manager-row-answer {
  color: var(--muted);
  font-size: 13px;
  margin-top: 5px;
}
.card-manager-row-flag {
  color: #f59e0b;
  font-size: 12px;
  font-weight: 700;
  margin-left: 6px;
}
.field-label {
  display: block;
  margin: 10px 0 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.format-toolbar {
  display: flex;
  gap: 5px;
  margin-bottom: 5px;
}
.format-btn {
  min-width: 38px;
  height: 34px;
  padding: 0 9px;
  border: 1px solid var(--surface-2);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 15px;
}
.format-btn:active { transform: scale(0.96); }
.format-underline { text-decoration: underline; }
.format-list { margin-left: auto; min-width: 72px; }
.card-editor-actions,
.import-preview-actions,
.bullet-editor-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}
.card-editor-actions .btn,
.import-preview-actions .btn,
.bullet-editor-actions .btn { min-width: 0; }

/* Structured bulleted-list editor */
.bullet-editor-card { max-width: 520px; }
.bullet-editor-list {
  display: grid;
  gap: 8px;
  margin: 12px 0;
}
.bullet-editor-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto auto;
  gap: 5px;
  align-items: center;
}
.bullet-editor-marker {
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}
.bullet-editor-input {
  width: 100%;
  min-width: 0;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--surface-2);
  border-radius: 9px;
  padding: 9px 10px;
  font-size: 15px;
}
.bullet-editor-move,
.bullet-editor-delete {
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--surface-2);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.bullet-editor-delete { color: var(--danger); }
.bullet-editor-move:disabled { opacity: 0.35; cursor: default; }
@media (max-width: 430px) {
  .bullet-editor-row {
    grid-template-columns: auto minmax(0, 1fr) auto auto;
  }
  .bullet-editor-delete {
    grid-column: 2 / 5;
    justify-self: end;
    width: auto;
    padding: 0 10px;
  }
}

/* Import preview */
.import-preview-card { max-width: 520px; }
.import-preview-summary {
  margin: 0 0 10px;
  font-weight: 700;
}
.import-preview-warnings {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
}
.import-warning {
  margin: 0;
  padding: 8px 10px;
  border-radius: 9px;
  background: color-mix(in srgb, #f59e0b 15%, var(--surface));
  color: var(--text);
  font-size: 13px;
  line-height: 1.35;
}
.import-preview-list {
  margin: 0;
  padding-left: 24px;
  display: grid;
  gap: 7px;
}
.import-preview-item {
  padding: 8px 10px;
  border: 1px solid var(--surface-2);
  border-radius: 9px;
  background: var(--surface);
  font-size: 13px;
}
.import-preview-item strong,
.import-preview-item span { display: block; overflow-wrap: anywhere; }
.import-preview-item span { color: var(--muted); margin-top: 3px; }
.import-preview-item.duplicate { border-color: #f59e0b; }
.import-preview-card select,
.import-preview-card input[type=text] {
  width: 100%;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--surface-2);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 15px;
}
.import-skip-row { margin-top: 14px; }

.restore-preview-card { max-width: 520px; }
.restore-preview-summary { margin: 0 0 4px; font-weight: 700; }
.restore-options {
  display: grid;
  gap: 8px;
  margin: 16px 0 8px;
  padding: 0;
  border: 0;
}
.restore-options legend {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.restore-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 12px;
  border: 1px solid var(--surface-2);
  border-radius: 12px;
  background: var(--surface);
  cursor: pointer;
}
.restore-option:has(input:checked) {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 9%, var(--surface));
}
.restore-option input { margin-top: 3px; accent-color: var(--primary); }
.restore-option span,
.restore-option strong,
.restore-option small { display: block; }
.restore-option small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.35;
}

/* Update-ready notification */
.update-ready-banner {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(env(safe-area-inset-bottom) + 12px);
  z-index: 70;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 620px;
  margin: 0 auto;
  padding: 12px;
  border: 1px solid var(--primary-2);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 12px 36px rgba(0,0,0,0.35);
}
.update-ready-message { flex: 1; font-size: 14px; line-height: 1.35; }
.update-ready-banner .btn { flex: 0 0 auto; padding: 10px 12px; }
.update-ready-later {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 8px;
}

/* Hidden decks manager */
.hidden-decks { margin-top: 8px; }
.hidden-decks-box {
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: 12px;
  padding: 4px 14px;
}
.hidden-decks-box summary {
  cursor: pointer;
  padding: 10px 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  list-style: none;
}
.hidden-decks-box summary::-webkit-details-marker { display: none; }
.hidden-decks-box summary::before { content: "▸ "; }
.hidden-decks-box[open] summary::before { content: "▾ "; }
.hidden-deck-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--surface-2);
}
.hidden-deck-name { overflow-wrap: anywhere; font-size: 15px; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  transform: translate(-50%, 20px);
  max-width: 90%;
  background: var(--text);
  color: var(--bg);
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.4;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.study-top {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.study-deck-label { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.study-top .study-deck-label { flex: 1; min-width: 0; }
.btn.small { flex: 0 0 auto; padding: 8px 12px; font-size: 14px; }

@media (max-width: 430px) {
  .resume-study-panel { align-items: stretch; flex-direction: column; }
  .resume-study-actions .btn { flex: 1; }
  #study-edit-card { padding-left: 9px; padding-right: 9px; }
}

/* Flag for review */
.flag-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 0 0 16px;
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
}
.flag-row input[type=checkbox] {
  width: 22px;
  height: 22px;
  accent-color: #f59e0b;
}

.controls-stack { display: flex; flex-direction: column; gap: 12px; }
.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 15px;
  cursor: pointer;
}
.toggle-row input[type=checkbox] { width: 20px; height: 20px; accent-color: #f59e0b; flex: 0 0 auto; }
.toggle-row span:first-of-type { flex: 1; }
.toggle-row.disabled { opacity: 0.5; cursor: default; }
.picker-note {
  margin: -5px 2px 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.deck-item-flag {
  flex: 0 0 auto;
  color: #f59e0b;
  font-size: 13px;
  font-weight: 600;
}

/* Study */
.empty {
  text-align: center;
  margin-top: 12vh;
  color: var(--muted);
}

.progress {
  margin-bottom: 16px;
}

.progress-text { font-size: 14px; color: var(--muted); }

.progress-bar {
  margin-top: 6px;
  height: 6px;
  background: var(--surface-2);
  border-radius: 3px;
  overflow: hidden;
}

#progress-fill {
  height: 100%;
  width: 0%;
  background: var(--primary);
  transition: width 0.25s ease;
}

.card {
  perspective: 1200px;
  width: 100%;
  height: calc(340px * var(--fscale));
  max-height: 62vh;
  cursor: pointer;
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.5s;
  transform-style: preserve-3d;
}

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

.card-face {
  position: absolute;
  inset: 0;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  border-radius: var(--radius);
  padding: 40px 20px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}
.card-face::-webkit-scrollbar { width: 6px; }
.card-face::-webkit-scrollbar-thumb {
  background: rgba(127,127,127,0.4);
  border-radius: 3px;
}
.card-back::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.5); }

.card-front {
  background: linear-gradient(160deg, var(--surface), var(--surface-2));
}

.card-back {
  background: linear-gradient(160deg, var(--primary), var(--primary-2));
  transform: rotateY(180deg);
  color: #fff;
}

.card-label {
  position: absolute;
  top: 16px;
  left: 16px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.card-back .card-label { color: rgba(255,255,255,0.75); }

.card-face p {
  font-size: calc(24px * var(--fscale));
  line-height: 1.35;
  margin: auto 0;
  overflow-wrap: anywhere;
}
.card-shape {
  display: inline-block;
  vertical-align: middle;
  margin: 6px auto;
  max-width: min(70vw, 260px);
  height: auto;
}
.card-flag {
  display: inline-block;
  max-width: min(70vw, 180px);
  font-size: clamp(72px, 28vw, 150px);
  line-height: 1;
}
.card-flag-image {
  width: min(70vw, 180px);
  height: auto;
  max-height: 150px;
  object-fit: contain;
}
.card-list { display: inline-block; text-align: left; margin: 0 auto; }
.card-li { display: block; position: relative; padding-left: 1.15em; }
.card-li + .card-li { margin-top: 0.28em; }
.card-li::before {
  content: "\2022";
  position: absolute;
  left: 0.1em;
  top: 0;
  color: var(--primary);
  font-weight: 700;
}
.card-back .card-li::before { color: rgba(255,255,255,0.9); }

.hint {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin: 10px 0 20px;
}

.controls {
  display: flex;
  gap: 10px;
}

.btn {
  flex: 1;
  border: none;
  background: var(--surface-2);
  color: var(--text);
  padding: 14px;
  font-size: 15px;
  font-weight: 600;
  border-radius: 12px;
  cursor: pointer;
}

.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--primary); color: #fff; }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn:disabled { opacity: 0.48; cursor: not-allowed; transform: none; }

/* Study games */
.study-actions .btn { min-width: 0; padding-left: 9px; padding-right: 9px; }
.match-start-btn {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff;
}
.match-eligibility {
  min-height: 1.2em;
  margin: -4px 2px 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}
.start-mode-btn { width: 100%; flex: none; }
.mode-eligibility {
  min-height: 1.2em;
  margin: -4px 2px 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}
.match-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 6px 0 2px;
}
.match-heading h2 { margin: 0; font-size: calc(21px * var(--fscale)); }
.match-progress { color: var(--muted); font-size: 13px; white-space: nowrap; }
.match-status {
  min-height: 1.4em;
  margin: 6px 0 12px;
  color: var(--muted);
  font-size: 14px;
}
.match-board {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}
.match-column-head {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .06em;
  text-align: center;
  text-transform: uppercase;
}
.match-tile {
  min-width: 0;
  height: 76px;
  padding: 7px 9px;
  border: 2px solid var(--surface-2);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: calc(15px * var(--fscale));
  font-weight: 600;
  line-height: 1.18;
  overflow: hidden;
  overflow-wrap: anywhere;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, opacity .2s ease, transform .15s ease;
}
.match-tile:disabled { color: var(--text); }
.match-tile .card-shape { max-width: 58px; max-height: 58px; margin: 0 auto; }
.match-tile .card-flag-emoji { font-size: 42px; }
.match-tile .card-flag-image { width: 58px; max-height: 44px; }
.match-tile.selected {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 18%, var(--surface));
  transform: scale(1.02);
}
.match-tile.wrong {
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 18%, var(--surface));
  animation: match-shake .28s ease;
}
.match-tile.matched {
  border-color: #22c55e;
  background: color-mix(in srgb, #22c55e 20%, var(--surface));
  opacity: 0.48;
  filter: saturate(0.65);
  pointer-events: none;
}
.match-complete {
  grid-column: 1 / -1;
  padding: 36px 18px;
  border: 1px solid var(--surface-2);
  border-radius: 16px;
  background: var(--surface);
  text-align: center;
}
.match-complete h3 { margin: 0 0 8px; font-size: calc(24px * var(--fscale)); }
.match-complete p { color: var(--muted); }
.match-complete .btn { width: 100%; margin-top: 10px; }
.match-measurer {
  position: fixed;
  left: -10000px;
  top: 0;
  visibility: hidden;
  pointer-events: none;
}
@keyframes match-shake {
  25% { transform: translateX(-5px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}

/* Multiple-choice game */
.choice-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 6px 0 2px;
}
.choice-heading h2 { margin: 0; font-size: calc(21px * var(--fscale)); }
.choice-progress { color: var(--muted); font-size: 13px; white-space: nowrap; }
.choice-instruction {
  margin: 6px 0 10px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}
.choice-question {
  min-height: 112px;
  max-height: 160px;
  display: grid;
  place-items: center;
  overflow: hidden;
  overflow-wrap: anywhere;
  padding: 18px;
  border: 1px solid var(--surface-2);
  border-radius: 14px;
  background: linear-gradient(160deg, var(--surface), var(--surface-2));
  text-align: center;
  font-size: calc(21px * var(--fscale));
  font-weight: 700;
  line-height: 1.3;
}
.choice-question .card-shape { max-width: 100px; max-height: 100px; margin: 0 auto; }
.choice-question .card-flag-emoji { font-size: 76px; }
.choice-question .card-flag-image { width: 100px; max-height: 75px; }
.choice-options {
  display: grid;
  gap: 9px;
  margin-top: 13px;
}
.choice-option {
  min-height: 56px;
  max-height: 76px;
  width: 100%;
  overflow: hidden;
  overflow-wrap: anywhere;
  padding: 10px 13px;
  border: 2px solid var(--surface-2);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: calc(15px * var(--fscale));
  font-weight: 600;
  line-height: 1.2;
  text-align: left;
  cursor: pointer;
}
.choice-option .card-shape { max-width: 52px; max-height: 52px; margin: 0 auto; }
.choice-option .card-flag-emoji { font-size: 40px; }
.choice-option .card-flag-image { width: 52px; max-height: 39px; }
.choice-option.selected {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 18%, var(--surface));
}
.choice-option.correct {
  border-color: #22c55e;
  background: color-mix(in srgb, #22c55e 20%, var(--surface));
}
.choice-option.incorrect {
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 18%, var(--surface));
  animation: match-shake .28s ease;
}
.choice-option.missed { border-color: #22c55e; border-style: dashed; }
.choice-option:disabled { color: var(--text); cursor: default; opacity: 1; }
.choice-status {
  min-height: 1.4em;
  margin: 10px 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}
.choice-status.success { color: #22c55e; }
.choice-status.error { color: var(--danger); }
.choice-action { width: 100%; }
.choice-complete {
  padding: 28px 18px;
  border: 1px solid var(--surface-2);
  border-radius: 16px;
  background: var(--surface);
  text-align: center;
}
.choice-complete h3 { margin: 0 0 8px; font-size: calc(24px * var(--fscale)); }
.choice-score {
  margin: 10px 0 2px;
  color: var(--primary-2);
  font-size: calc(34px * var(--fscale));
  font-weight: 800;
}
.choice-complete p { color: var(--muted); }
.choice-complete-actions { display: grid; gap: 9px; margin-top: 18px; }
.choice-measurer {
  position: fixed;
  left: -10000px;
  top: 0;
  visibility: hidden;
  pointer-events: none;
}

/* Edit */
.help, .help code {
  color: var(--muted);
  font-size: 14px;
}
.help code {
  background: var(--surface);
  padding: 2px 5px;
  border-radius: 5px;
  color: var(--text);
}

textarea {
  width: 100%;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--surface-2);
  border-radius: 12px;
  padding: 14px;
  font-size: 16px;
  font-family: inherit;
  resize: vertical;
  margin: 12px 0;
}

.edit-actions {
  display: flex;
  gap: 10px;
}

.import-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 8px;
}
.import-row .btn { flex: 0 0 auto; }
.import-hint { color: var(--muted); font-size: 13px; }
#gen-status { margin: 8px 0 0; }
#gen-status:empty,
#edit-status:empty { display: none; }

.manual-editor-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
  text-align: left;
}
.manual-editor-chevron {
  font-size: 20px;
  line-height: 1;
  transition: transform .2s ease;
}
.manual-editor-toggle[aria-expanded="true"] .manual-editor-chevron {
  transform: rotate(180deg);
}
.manual-editor {
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: 14px;
  padding: 14px;
  margin-top: 8px;
}
.manual-editor .help:first-child { margin-top: 0; }
.manual-editor .count { margin-bottom: 0; }

.status {
  min-height: 20px;
  color: #4ade80;
  font-size: 14px;
}

.count {
  color: var(--muted);
  font-size: 14px;
}

.install-banner {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(env(safe-area-inset-bottom) + 12px);
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: 12px;
  padding: 14px 40px 14px 14px;
  font-size: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}

.install-banner button {
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 22px;
  cursor: pointer;
}

/* ---- Timer ---- */
.timer {
  flex: 0 0 auto;
  margin-left: auto;
  background: var(--surface);
  border: 1px solid var(--surface-2);
  color: var(--text);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  cursor: pointer;
}
.timer.paused { color: var(--muted); border-style: dashed; }

/* ---- Settings screen ---- */
.settings-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.settings-head h2 { margin: 0; font-size: 22px; }

.settings-group {
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 16px;
}
.settings-group > h3 {
  margin: 0 0 12px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.settings-note { color: var(--muted); font-size: 14px; margin: 0 0 12px; }
.settings-version { text-align: center; color: var(--muted); font-size: 12px; margin: 24px 0; }

/* Collapsible settings sections (Help Center, Privacy Policy) */
.collapsible { padding: 0; }
.group-summary {
  list-style: none;
  cursor: pointer;
  padding: 16px;
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.group-summary::-webkit-details-marker { display: none; }
.group-summary::after {
  content: "⌄";
  font-size: 18px;
  line-height: 1;
  transition: transform 0.2s ease;
}
.collapsible[open] .group-summary::after { transform: rotate(180deg); }
.collapsible > :not(summary) { padding: 0 16px 16px; }
.settings-group .setting { margin-bottom: 14px; }
.settings-group .setting:last-child { margin-bottom: 0; }
.settings-group .toggle-row { margin-bottom: 10px; }
#feedback-link { display: inline-block; text-decoration: none; }

/* FAQ accordion */
.faq-item {
  border-bottom: 1px solid var(--surface-2);
  padding: 4px 0;
}
.faq-item:last-child { border-bottom: 0; }
.faq-item summary {
  cursor: pointer;
  padding: 10px 4px;
  font-weight: 600;
  font-size: calc(15px * var(--fscale));
  list-style: none;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::before { content: "＋ "; color: var(--primary); font-weight: 700; }
.faq-item[open] summary::before { content: "－ "; }
.faq-item p {
  margin: 0 4px 12px;
  color: var(--muted);
  font-size: calc(14px * var(--fscale));
  line-height: 1.5;
}

/* Privacy */
.privacy p { font-size: calc(14px * var(--fscale)); line-height: 1.5; }
.privacy ul { padding-left: 18px; margin: 10px 0; }
.privacy li { font-size: calc(14px * var(--fscale)); line-height: 1.5; margin-bottom: 8px; }
.privacy .privacy-foot { color: var(--muted); }

/* Font scale applied to a few more reading surfaces */
.welcome p { font-size: calc(16px * var(--fscale)); }
.deck-item-name { font-size: calc(16px * var(--fscale)); }
