:root {
  --bg: #ffffff;
  --bg-soft: #f7f7f5;
  --bg-hover: #efefed;
  --border: #e9e9e7;
  --border-strong: #d3d3cf;
  --text: #37352f;
  --text-soft: #73726e;
  --text-faint: #a3a29e;
  --accent: #2383e2;
  --accent-soft: #e8f2fc;

  /* the rating scale: red -> amber -> light green -> green */
  --again: #e5484d;  --again-bg: #fdecec;  --again-ink: #c2282d;
  --hard: #f5a524;   --hard-bg: #fef4e0;   --hard-ink: #a35a00;
  --good: #8bc34a;   --good-bg: #f0f8e4;   --good-ink: #4a7a12;
  --easy: #2e9e5b;   --easy-bg: #e3f4ea;   --easy-ink: #1a7443;
  --new: #d9d9d6;
  --on-primary: #ffffff;
  --primary-hover: #1f1e1b;
  --info-ink: #1a5fa8;
  --topbar-bg: rgba(247, 247, 245, 0.92);
  --tag-bg: #eeeeec;
  --scrim: rgba(15, 15, 15, 0.45);
  color-scheme: light;

  --radius: 6px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(15, 15, 15, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 15, 15, 0.08), 0 1px 2px rgba(15, 15, 15, 0.06);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

/* Dark mode: follows the device unless chosen in Settings (stored as data-theme). */
:root[data-theme="dark"] {
  --bg: #191918;
  --bg-soft: #202020;
  --bg-hover: #2c2c2b;
  --border: #2f2f2e;
  --border-strong: #3d3d3b;
  --text: #ebebea;
  --text-soft: #a5a5a2;
  --text-faint: #6f6f6c;
  --accent: #4a9eed;
  --accent-soft: #1d2d3d;
  --again-bg: #3a1f20;  --again-ink: #ff8b8e;
  --hard-bg: #3a2c14;   --hard-ink: #f7b955;
  --good-bg: #24331a;   --good-ink: #a8d878;
  --easy-bg: #163024;   --easy-ink: #62d091;
  --new: #464644;
  --on-primary: #191918;
  --primary-hover: #ffffff;
  --info-ink: #8cc4ff;
  --topbar-bg: rgba(32, 32, 32, 0.92);
  --tag-bg: #2c2c2b;
  --scrim: rgba(0, 0, 0, 0.6);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45), 0 1px 2px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #191918;
    --bg-soft: #202020;
    --bg-hover: #2c2c2b;
    --border: #2f2f2e;
    --border-strong: #3d3d3b;
    --text: #ebebea;
    --text-soft: #a5a5a2;
    --text-faint: #6f6f6c;
    --accent: #4a9eed;
    --accent-soft: #1d2d3d;
    --again-bg: #3a1f20;  --again-ink: #ff8b8e;
    --hard-bg: #3a2c14;   --hard-ink: #f7b955;
    --good-bg: #24331a;   --good-ink: #a8d878;
    --easy-bg: #163024;   --easy-ink: #62d091;
    --new: #464644;
    --on-primary: #191918;
    --primary-hover: #ffffff;
    --info-ink: #8cc4ff;
    --topbar-bg: rgba(32, 32, 32, 0.92);
    --tag-bg: #2c2c2b;
    --scrim: rgba(0, 0, 0, 0.6);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45), 0 1px 2px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
/* Never let anything make the page wider than the screen; keep iPhones from enlarging text on their own. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { overflow-x: hidden; overflow-x: clip; }
h1, h2, h3, h4, p, li { overflow-wrap: break-word; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, p { margin: 0; }
code { background: var(--bg-soft); border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; font-size: 13px; }
.muted { color: var(--text-soft); }
.small-text { font-size: 13px; }
.clip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ========== BUTTONS ========== */
button {
  font: inherit;
  font-weight: 500;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 7px 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
}
button:hover { background: var(--bg-hover); }
.tap { cursor: pointer; color: var(--text); font-size: 14px; }
.tap:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.with-icon { display: inline-flex; align-items: center; gap: 6px; }
.icon { display: inline-flex; flex: none; }
.nav-item .icon { opacity: 0.8; }
button:focus-visible, .scene:focus-visible, .sheet:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--text); border-color: var(--text); color: var(--on-primary); }
button.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
button.ghost { border-color: transparent; background: transparent; color: var(--text-soft); }
button.ghost:hover { background: var(--bg-hover); color: var(--text); }
button.danger { color: var(--again-ink); }
button.danger:hover { background: var(--again-bg); }
button.danger-solid { background: var(--again); border-color: var(--again); color: #fff; }
button.danger-solid:hover { background: var(--again-ink); }
button.small { padding: 4px 10px; font-size: 13px; }
button.block { width: 100%; padding: 10px 14px; }

/* ========== FIELDS ========== */
input, textarea, select {
  font: inherit;
  width: 100%;
  padding: 8px 10px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input::placeholder, textarea::placeholder { color: var(--text-faint); }
textarea { resize: vertical; }
select { width: auto; padding: 5px 8px; font-size: 13px; cursor: pointer; }
label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 500; color: var(--text-soft); }
.field { margin-bottom: 14px; }

.segmented { display: flex; gap: 2px; padding: 3px; background: var(--bg-hover); border-radius: 8px; }
.segmented button { flex: 1; border: none; background: transparent; color: var(--text-soft); padding: 6px 12px; border-radius: 6px; }
.segmented button.active { background: var(--bg); color: var(--text); box-shadow: var(--shadow-sm); }
.segmented.compact button { padding: 3px 12px; font-size: 13px; }

.notice { padding: 9px 12px; border-radius: var(--radius); font-size: 13px; margin-bottom: 14px; }
.notice.error { background: var(--again-bg); color: var(--again-ink); }
.notice.info { background: var(--accent-soft); color: var(--info-ink); }

.pill { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 12px; font-weight: 500; white-space: nowrap; background: var(--bg-hover); color: var(--text-soft); }
.pill.pending { background: var(--hard-bg); color: var(--hard-ink); }
.pill.team { background: var(--accent-soft); color: var(--info-ink); }
.pill.admin { background: var(--easy-bg); color: var(--easy-ink); }

/* ========== CENTERED SCREENS (login, pending) ========== */
.center-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--bg-soft); }
.center-card { width: 100%; max-width: 380px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 32px; box-shadow: var(--shadow-md); }
.center-card h1 { font-size: 20px; margin-bottom: 6px; }
.center-card > .muted { font-size: 14px; margin-bottom: 20px; }
.center-card .brand { margin-bottom: 14px; padding: 0; }
.center-card .segmented { margin-bottom: 18px; }
.stack { display: flex; flex-direction: column; gap: 8px; }

.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; }
.brand-btn { border: none; background: transparent; padding: 4px 10px; color: var(--text); }
.brand-btn:hover { background: transparent; }
.topbar { display: flex; align-items: center; justify-content: space-between; }
.menu-wrap { position: relative; display: none; }
.menu-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; padding: 0; color: var(--text); }
.menu-dot { position: absolute; top: 8px; right: 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--again); border: 2px solid var(--bg-soft); pointer-events: none; }
.logo { display: inline-flex; color: var(--text); }

/* ========== APP SHELL ========== */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 18px; padding: 16px 10px; background: var(--bg-soft); border-right: 1px solid var(--border); }
.sidebar .brand { padding: 4px 10px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; padding: 6px 10px; border: none; background: transparent; color: var(--text-soft); font-weight: 500; }
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--bg-hover); color: var(--text); }
.nav-item .count { margin-left: auto; min-width: 20px; text-align: center; padding: 0 6px; border-radius: 10px; font-size: 12px; background: var(--again); color: #fff; }
.account { margin-top: auto; padding: 12px 10px 2px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.account .who { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; max-width: 100%; }
.account .email { font-size: 13px; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account button { margin-left: -10px; }

.main { min-width: 0; padding: 44px 48px 80px; }
.container { max-width: 920px; margin: 0 auto; }

.page-header { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 16px; margin-bottom: 28px; }
button.back { margin: 0 0 8px -10px; }
.page-header .titles { flex: 1; min-width: 200px; }
.page-header h1 { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; }
.page-header .titles p { margin-top: 4px; }
.page-header .actions { display: flex; flex-wrap: wrap; gap: 8px; }

.empty { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; padding: 56px 20px; background: var(--bg-soft); border: 1px dashed var(--border-strong); border-radius: var(--radius-lg); color: var(--text-soft); }
.empty h3 { color: var(--text); font-size: 16px; }
.empty button { margin-top: 12px; }

/* ========== MASTERY COLORS ========== */
.dot { display: inline-block; flex: none; width: 9px; height: 9px; border-radius: 50%; background: var(--new); }
.dot.again, .seg.again { background: var(--again); }
.dot.hard, .seg.hard { background: var(--hard); }
.dot.good, .seg.good { background: var(--good); }
.dot.easy, .seg.easy { background: var(--easy); }
.seg.new { background: var(--new); }
.mastery-bar { display: flex; gap: 2px; height: 6px; border-radius: 3px; overflow: hidden; }
.mastery-bar .seg { flex: 1 0 0; min-width: 3px; }

/* ========== DECK GRID ========== */
.deck-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.deck-card { display: flex; flex-direction: column; gap: 10px; text-align: left; white-space: normal; padding: 18px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--bg); box-shadow: var(--shadow-sm); font-weight: 400; }
.deck-card:hover { background: var(--bg); border-color: var(--border-strong); box-shadow: var(--shadow-md); }
.deck-card h3 { font-size: 16px; font-weight: 600; }
.deck-card h3 { line-height: 1.3; }
.deck-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: -4px; }
.deck-meta .desc { flex: 1 1 120px; min-width: 0; }
.deck-card .mastery-bar { flex: none; height: 6px; }
.mastery-bar.none { background: var(--bg-hover); }
.deck-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: auto; min-height: 28px; }
.deck-foot button { flex: none; }
.pill.exam { display: inline-flex; align-items: center; gap: 4px; background: var(--hard-bg); color: var(--hard-ink); }
.deck-card .desc { color: var(--text-soft); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.deck-card .stats { display: flex; gap: 12px; font-size: 13px; color: var(--text-soft); }
.deck-card .stats .due { color: var(--hard-ink); font-weight: 600; }
.deck-card .stats .fresh { color: var(--text); font-weight: 600; }

/* ========== CARD LIST ========== */
.list-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 16px; margin-bottom: 10px; font-size: 13px; color: var(--text-soft); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.legend > span { display: inline-flex; align-items: center; gap: 6px; }
.card-list { display: grid; grid-template-columns: 23px minmax(0, 1fr) minmax(0, 1fr) auto; border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.card-row { display: grid; grid-column: 1 / -1; grid-template-columns: subgrid; gap: 14px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
.card-row:last-child { border-bottom: none; }
.card-row:not(.head):hover { background: var(--bg-soft); }
.card-row.head, .table-row.head { background: var(--bg-soft); font-size: 12px; font-weight: 600; color: var(--text-soft); text-transform: uppercase; letter-spacing: 0.04em; }
.preview { display: flex; align-items: center; gap: 8px; min-width: 0; }
.thumb { width: 34px; height: 34px; object-fit: cover; border-radius: 4px; border: 1px solid var(--border); flex: none; }
.row-actions { display: flex; align-items: center; justify-content: flex-end; gap: 6px; }

/* ========== EDITOR: left page / right page ========== */
.spread { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; }
.page { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.page-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.page-top h4 { font-size: 15px; font-weight: 600; line-height: 1.2; }
.side-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.side-num { flex: none; display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--bg-hover); color: var(--text-soft); font-size: 12px; font-weight: 600; }

/* Text / Photo switch */
.mode-switch { display: flex; gap: 2px; padding: 3px; background: var(--bg-hover); border-radius: 8px; flex: none; }
.mode-switch button { display: inline-flex; align-items: center; gap: 6px; border: none; background: transparent; color: var(--text-soft); padding: 4px 10px; border-radius: 6px; font-size: 13px; }
.mode-switch button:hover { color: var(--text); background: transparent; }
.mode-switch button.active { background: var(--bg); color: var(--text); box-shadow: var(--shadow-sm); }

/* Formatting toolbar */
.toolbar { display: flex; align-items: center; gap: 2px; min-height: 36px; padding: 3px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-soft); }
.toolbar.photo { padding: 3px 3px 3px 10px; }
.tool { display: inline-grid; place-items: center; width: 30px; height: 28px; padding: 0; border: none; border-radius: 6px; background: transparent; color: var(--text-soft); }
.tool:hover { background: var(--bg-hover); color: var(--text); }
.tool.active { background: var(--accent-soft); color: var(--accent); }
.tool.wide { display: inline-flex; gap: 6px; width: auto; padding: 0 10px; font-size: 13px; }
.tool.danger:hover { background: var(--again-bg); color: var(--again-ink); }
.tool-sep { width: 1px; height: 18px; margin: 0 5px; background: var(--border-strong); }

.sheet { position: relative; width: 100%; aspect-ratio: 3 / 2; display: flex; flex-direction: column; gap: 10px; padding: 18px 22px; background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); cursor: text; overflow: hidden; transition: border-color 0.12s, box-shadow 0.12s, background 0.12s; }
.sheet:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.sheet.drag { background: var(--accent-soft); border-color: var(--accent); border-style: dashed; }
.sheet-photo { position: relative; flex: 0 1 auto; align-self: center; max-width: 100%; min-height: 0; max-height: 58%; display: flex; justify-content: center; }
.sheet-photo img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; }
.photo-remove { position: absolute; top: 4px; right: 4px; display: grid; place-items: center; width: 26px; height: 26px; padding: 0; border: none; border-radius: 50%; background: rgba(0, 0, 0, 0.6); color: #fff; opacity: 0.85; }
.photo-remove:hover { background: rgba(0, 0, 0, 0.8); opacity: 1; }
.sheet-textbox { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.sheet-textbox.overflowing { align-items: flex-start; }
.sheet-text { width: 100%; outline: none; }
.sheet-textbox.overflowing .sheet-text { max-height: 100%; overflow-y: auto; }
.sheet-text:empty::before { content: attr(data-placeholder); color: var(--text-faint); pointer-events: none; }
.sheet.has-photo .sheet-text:empty::before { font-size: 14px; }
.tool-spacer { flex: 1; }
.drop-hint { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; color: var(--text-soft); font-size: 13px; padding: 0 12px; }
.drop-hint .icon { color: var(--text-faint); margin-bottom: 4px; }
.drop-hint strong { color: var(--text); font-size: 15px; }
.sheet.drop:hover .drop-hint .icon { color: var(--accent); }

/* Formatted card text: used in the editor and on the study card, so both look the same */
.rich { text-align: center; font-weight: 500; line-height: 1.35; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.rich b, .rich strong { font-weight: 700; }
.rich p { margin: 0; }
.rich ul, .rich ol { width: fit-content; max-width: 100%; margin: 0.3em auto; padding-left: 1.3em; text-align: left; }
.rich li { margin: 0.15em 0; padding-left: 0.15em; }
.rich li::marker { color: var(--text-soft); font-weight: 600; }

.editor-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 24px; }
.editor-actions > span { margin-right: auto; }
.editor-actions .muted { max-width: 420px; }

/* ========== STUDY ========== */
.study { max-width: 720px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.study-top { display: flex; align-items: center; gap: 14px; }
.study-top button { margin-left: -10px; }
.progress { flex: 1; height: 6px; background: var(--bg-hover); border-radius: 3px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--text); border-radius: 3px; transition: width 0.3s; }

/* The flipping card. Safari needs the -webkit- versions and an explicit starting rotation, and must not
   slide the card in with a transform (it can then keep showing the previous card), so new cards only fade in. */
.scene { position: relative; flex-shrink: 0; -webkit-perspective: 1600px; perspective: 1600px; aspect-ratio: 3 / 2; max-height: calc(100vh - 300px); min-height: 280px; width: 100%; cursor: pointer; border-radius: var(--radius-lg); animation: fade-in 0.2s ease-out; }
.flipper { position: absolute; inset: 0; -webkit-transform-style: preserve-3d; transform-style: preserve-3d; transform: rotateY(0deg); transition: transform 0.45s cubic-bezier(0.3, 0.9, 0.3, 1); }
.flipper.flipped { transform: rotateY(180deg); }
.face.front { transform: rotateY(0deg); }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
/* Typing mode: a flat card that switches sides without 3D, so it can never cover the answer box. */
.scene.flat { -webkit-perspective: none; perspective: none; }
.scene.flat .flipper, .scene.flat .flipper.flipped, .scene.flat .face { transform: none; transition: none; -webkit-transform-style: flat; transform-style: flat; }
.scene.flat .face.back { display: none; }
.scene.flat.revealed .face.front { display: none; }
.scene.flat.revealed .face.back { display: flex; animation: fade-in 0.2s ease-out; }
.type-row { position: relative; z-index: 2; }
.face { position: absolute; inset: 0; display: flex; flex-direction: column; padding: 22px 28px 28px; background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.face.back { transform: rotateY(180deg); }
.face-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-faint); margin-bottom: 10px; }
.face.back .face-label { color: var(--easy-ink); }
.face-body { flex: 1; min-height: 0; display: flex; flex-direction: column; justify-content: center; gap: 12px; overflow: hidden; }
.face-img { flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; }
.face-body.both .face-img { flex: 0 1 auto; max-height: 60%; }
.face-img img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; }
.face-textbox { flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.face-textbox.overflowing { align-items: flex-start; overflow-y: auto; }
.face-text { width: 100%; }
.face-text.multi { width: fit-content; max-width: 100%; margin: 0 auto; text-align: left; }
.face-text.multi ul, .face-text.multi ol { margin-left: 0; margin-right: 0; }
@keyframes card-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.hint { text-align: center; font-size: 13px; color: var(--text-faint); }

.rate-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; animation: card-in 0.2s ease-out; }
.rate-row.busy { opacity: 0.5; pointer-events: none; }
.rate { position: relative; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 13px 8px 11px; border: none; border-radius: 10px; color: #fff; white-space: normal; box-shadow: 0 1px 2px rgba(15, 15, 15, 0.12); transition: filter 0.12s, transform 0.08s; }
.rate-label { font-size: 15px; font-weight: 700; }
.rate-when { font-size: 12px; font-weight: 500; opacity: 0.9; }
.rate kbd { position: absolute; top: 6px; right: 8px; font: 600 11px var(--font); opacity: 0.7; }
.rate.again { background: #e5484d; }
.rate.hard { background: #ee8a12; }
.rate.good { background: #5fa83a; }
.rate.easy { background: #2e9e5b; }
.rate:hover { filter: brightness(0.93); }
.rate.again:hover { background: #e5484d; }
.rate.hard:hover { background: #ee8a12; }
.rate.good:hover { background: #5fa83a; }
.rate.easy:hover { background: #2e9e5b; }
.rate:active { transform: scale(0.97); }
.rate:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

.study-done { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; padding: 72px 20px; }
.study-done h2 { font-size: 24px; letter-spacing: -0.02em; }
.study-done .row { display: flex; gap: 8px; margin-top: 14px; }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 6px; }
.chip { padding: 3px 10px; border-radius: 20px; font-size: 13px; font-weight: 600; }
.chip.again { background: var(--again-bg); color: var(--again-ink); }
.chip.hard { background: var(--hard-bg); color: var(--hard-ink); }
.chip.good { background: var(--good-bg); color: var(--good-ink); }
.chip.easy { background: var(--easy-bg); color: var(--easy-ink); }

/* ========== TABLES ========== */
.table { border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.table-row { display: grid; gap: 14px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
.table-row:last-child { border-bottom: none; }
.table-row.members { grid-template-columns: minmax(0, 1fr) 120px 100px 210px; }
.table-row.highlight { background: var(--hard-bg); }
.role-help { margin-top: 18px; display: grid; gap: 4px; font-size: 13px; color: var(--text-soft); }
.role-help strong { color: var(--text); }

.request-list { display: flex; flex-direction: column; gap: 10px; }
.request { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px 16px; align-items: center; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius-lg); }
.request-card { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; grid-column: 1 / -1; font-size: 14px; font-weight: 500; }
.request-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; font-size: 13px; }
.request-meta .reason { flex-basis: 100%; color: var(--text-soft); font-style: italic; }

/* ========== STATISTICS ========== */
.nav-label { margin: 14px 10px 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-faint); }
.exam-banner { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 16px; padding: 12px 16px; border: 1px solid var(--border); border-left: 4px solid var(--hard); border-radius: var(--radius-lg); background: var(--hard-bg); font-size: 14px; }
.exam-banner strong { color: var(--hard-ink); }
.exam-banner > .icon { color: var(--hard-ink); margin-top: 2px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 36px; }
.tile { display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--bg); }
.tile-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-soft); }
.tile-value { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.25; font-variant-numeric: tabular-nums; }
.tile-sub { font-size: 12px; color: var(--text-faint); }
.tile.warn .tile-value { color: var(--hard-ink); }

.stat-section { margin-bottom: 36px; }
.section-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin-bottom: 12px; }
.section-head h2, .settings-group h2 { font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }

.chart { position: relative; padding: 16px 16px 10px; border: 1px solid var(--border); border-radius: var(--radius-lg); }
.chart-max { position: absolute; top: 8px; left: 12px; font-size: 11px; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 150px; padding-top: 14px; border-bottom: 1px solid var(--border); }
.bar-col { flex: 1; height: 100%; display: flex; align-items: flex-end; border-radius: 3px 3px 0 0; }
.bar-col:hover { background: var(--bg-soft); }
.bar { width: 100%; display: flex; flex-direction: column-reverse; gap: 1px; border-radius: 3px 3px 0 0; overflow: hidden; }
.bar .seg { flex: 1 0 0; min-height: 2px; }
.chart-axis { display: flex; justify-content: space-between; margin-top: 6px; font-size: 11px; }

.forecast { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius-lg); }
.fc-col { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.fc-num { height: 16px; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.fc-track { width: 100%; max-width: 44px; height: 80px; display: flex; align-items: flex-end; }
.fc-bar { width: 100%; background: var(--border-strong); border-radius: 4px 4px 0 0; }
.fc-col:first-child .fc-bar { background: var(--hard); }
.fc-label { font-size: 12px; white-space: nowrap; }

.num { text-align: right; font-variant-numeric: tabular-nums; }
.warn-text { color: var(--hard-ink); font-weight: 600; }
.table-row.deckstats { grid-template-columns: minmax(0, 1fr) minmax(120px, 1.4fr) 70px 80px; }
.table-row.team { grid-template-columns: minmax(0, 1fr) 60px 64px 100px 96px 90px 50px; }
.table-row.clickable { cursor: pointer; }
.table-row.clickable:hover { background: var(--bg-soft); }
.table-row.clickable:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.who-cell { display: flex; flex-direction: column; min-width: 0; }

.hard-list { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.hard-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 14px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
.hard-row:last-child { border-bottom: none; }

/* ========== SETTINGS ========== */
.settings-group { margin-bottom: 28px; }
.settings-group h2 { margin-bottom: 6px; }
.setting { display: grid; grid-template-columns: minmax(0, 1fr) 210px; gap: 16px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); }
.setting label { margin: 0; color: var(--text); font-size: 14px; }
.setting p { margin-top: 2px; }
.setting-input { display: flex; align-items: center; gap: 8px; }
.setting-input input { width: 110px; }
.gap-preview { display: flex; flex-direction: column; gap: 6px; margin: -12px 0 28px; padding: 14px 16px; border-radius: var(--radius-lg); background: var(--bg-soft); font-size: 13px; }
.gap-line { display: flex; align-items: center; gap: 10px; font-variant-numeric: tabular-nums; }
.gap-line .chip { min-width: 54px; text-align: center; }

/* ========== DECKS: goal, search ========== */
.decks-top { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 12px; margin-bottom: 18px; align-items: start; }
.decks-top > :only-child { grid-column: 1 / -1; }
.goal-card { display: flex; flex-direction: column; gap: 8px; padding: 12px 16px; text-align: left; white-space: normal; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--bg); font-weight: 400; }
.goal-card:hover { background: var(--bg-soft); }
.goal-text { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.goal-label { font-size: 13px; color: var(--text-soft); }
.goal-text strong { font-variant-numeric: tabular-nums; }
.goal-track { height: 8px; border-radius: 4px; background: var(--bg-hover); overflow: hidden; }
.goal-fill { height: 100%; border-radius: 4px; background: var(--good); transition: width 0.4s; }
.goal-card.reached .goal-label { color: var(--easy-ink); font-weight: 600; }
.goal-card.reached .goal-fill { background: var(--easy); }

.search-box { position: relative; }
.search-field { position: relative; display: flex; align-items: center; }
.search-field > .icon { position: absolute; left: 11px; color: var(--text-faint); pointer-events: none; }
.search-input { padding-left: 34px; height: 40px; }
.search-results { position: absolute; z-index: 30; top: calc(100% + 6px); left: 0; right: 0; max-height: 380px; overflow-y: auto; padding: 4px; background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); }
.search-hit { display: flex; flex-direction: column; align-items: stretch; gap: 1px; width: 100%; text-align: left; padding: 8px 10px; border-radius: var(--radius); }
.search-hit:hover { background: var(--bg-hover); }
.search-hit .preview { font-weight: 500; }
.search-empty { padding: 10px; }

/* ========== DECK PAGE: practice, filters, tags ========== */
.practice-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 18px; }
.list-tools { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.list-tools .search-field { flex: 1; max-width: 360px; }
.list-count { font-size: 13px; color: var(--text-soft); white-space: nowrap; }
.tag-chips { margin-bottom: 12px; }
.tag-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-chips:empty { display: none; }
.chip-btn { display: inline-flex; align-items: center; gap: 5px; padding: 4px 11px; border-radius: 20px; font-size: 13px; border-color: var(--border); background: var(--bg); color: var(--text-soft); }
.chip-btn.active { background: var(--text); border-color: var(--text); color: var(--on-primary); }
.chip-btn.active:hover { background: var(--primary-hover); }
.q-cell { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.row-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.tag { display: inline-flex; align-items: center; gap: 3px; padding: 1px 8px; border-radius: 20px; font-size: 12px; background: var(--tag-bg); color: var(--text-soft); white-space: nowrap; }
.filter-empty { padding: 16px 4px; }
button.icon-only { display: inline-grid; place-items: center; padding: 0; width: 30px; height: 30px; }
.flag-btn { color: var(--text-faint); }
.flag-btn.on { color: var(--hard-ink); background: var(--hard-bg); border-color: var(--hard); }
.row-actions.center { justify-content: center; }
.field-help { margin-top: 6px; }
.label-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.label-row label { margin: 0; }

/* ========== EDITOR: tags ========== */
.tags-row { display: flex; align-items: center; gap: 12px; margin-top: 20px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-lg); }
.tags-label { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 500; color: var(--text-soft); flex: none; }
.tag-input { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; flex: 1; min-width: 0; }
.tag-input input { flex: 1; min-width: 160px; border: none; box-shadow: none !important; padding: 4px 2px; background: transparent; }
.tag.removable { padding-right: 3px; font-size: 13px; }
.tag.removable button { display: inline-grid; place-items: center; width: 18px; height: 18px; padding: 0; border: none; border-radius: 50%; background: transparent; color: inherit; }
.tag.removable button:hover { background: var(--bg-hover); }

/* ========== IMPORT ========== */
.modal:has(.import) { max-width: 620px; }
.import-area { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; white-space: pre; }
.import-options { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.import-options select { width: 100%; padding: 8px 10px; font-size: 14px; }
.import-sample { display: flex; flex-direction: column; margin-top: 8px; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.sample-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 6px 10px; font-size: 13px; border-bottom: 1px solid var(--border); }
.sample-row:last-child { border-bottom: none; }

/* ========== STUDY: tools, typing ========== */
.study-tools { display: flex; align-items: center; gap: 4px; margin: -6px 0 -4px; min-height: 30px; }
.study-tools button.on { color: var(--accent); background: var(--accent-soft); }
.study-tools .flag-btn.on { color: var(--hard-ink); background: var(--hard-bg); border-color: transparent; }
.study-exit { max-width: 45%; overflow: hidden; text-overflow: ellipsis; }
.type-row { display: flex; gap: 8px; }
/* Typing mode: the card gets a fixed height (no aspect ratio) so it can never grow over the answer box below it. */
.study.typing .scene { aspect-ratio: auto; height: clamp(200px, calc(100vh - 420px), 460px); min-height: 0; max-height: none; }
.study.typing .type-row { margin-top: 6px; }
.type-answer { height: 46px; font-size: 16px; }
.typed { display: flex; flex-direction: column; gap: 2px; padding: 10px 14px; border-radius: var(--radius-lg); background: var(--bg-soft); border: 1px solid var(--border); }
.typed.match { background: var(--easy-bg); border-color: var(--easy); }
.typed-label { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; color: var(--text-soft); text-transform: uppercase; letter-spacing: 0.04em; }
.typed.match .typed-label { color: var(--easy-ink); }
.typed-text { font-size: 16px; font-weight: 500; overflow-wrap: anywhere; }
.tile.good .tile-value { color: var(--easy-ink); }

/* ========== SETTINGS: sliders, presets, switches ========== */
.scope-tabs { max-width: 320px; margin: -10px 0 24px; }
.settings-group { margin-bottom: 32px; }
.group-help { margin: 2px 0 14px; }
.presets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 18px; }
.preset { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 10px 12px; text-align: left; border: 1px solid var(--border-strong); border-radius: var(--radius-lg); background: var(--bg); }
.preset:hover { background: var(--bg-hover); }
.preset strong { font-size: 14px; }
.preset span { font-size: 12px; color: var(--text-soft); }
.preset.active { border-color: var(--text); box-shadow: inset 0 0 0 1px var(--text); }
.range-setting { padding: 12px 0 14px; border-bottom: 1px solid var(--border); }
.range-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 8px; }
.range-head label { margin: 0; color: var(--text); font-size: 14px; }
.range-value { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.range-setting p { margin-top: 6px; }
input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 22px; padding: 0; border: none; background: transparent; box-shadow: none !important; cursor: pointer; }
input[type="range"]::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: linear-gradient(to right, var(--text) var(--fill, 0%), var(--bg-hover) var(--fill, 0%)); }
input[type="range"]::-moz-range-track { height: 6px; border-radius: 3px; background: var(--bg-hover); }
input[type="range"]::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--text); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; margin-top: -7px; border-radius: 50%; background: var(--bg); border: 2px solid var(--text); box-shadow: var(--shadow-sm); }
input[type="range"]::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: var(--bg); border: 2px solid var(--text); }
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px var(--accent-soft); }
details.more { margin-top: 4px; }
details.more summary { padding: 12px 0; cursor: pointer; font-size: 14px; font-weight: 500; color: var(--text-soft); }
details.more summary:hover { color: var(--text); }
details.more[open] summary { border-bottom: 1px solid var(--border); }
.gap-preview { margin: 16px 0 0; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.switch-row label { margin: 0; color: var(--text); font-size: 14px; }
.switch { position: relative; flex: none; width: 44px; height: 26px; padding: 0; border: none; border-radius: 13px; background: var(--border-strong); transition: background 0.15s; }
.switch:hover { background: var(--border-strong); }
.switch .knob { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); transition: transform 0.15s; }
.switch.on, .switch.on:hover { background: var(--easy); }
.switch.on .knob { transform: translateX(18px); }
.theme-seg { flex: none; }
.install-steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.save-bar { position: sticky; bottom: 0; z-index: 20; display: flex; justify-content: flex-end; gap: 8px; margin: 0 -8px; padding: 12px 8px; background: var(--bg); border-top: 1px solid var(--border); }

/* ========== MODAL + TOAST ========== */
.modal-overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; background: var(--scrim); overflow-y: auto; }
.modal { width: 100%; max-width: 460px; padding: 24px; background: var(--bg); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); animation: card-in 0.15s ease-out; }
.modal h3 { font-size: 17px; margin-bottom: 12px; }
.modal p { margin-bottom: 14px; font-size: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

.toast-wrap { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.toast { padding: 9px 16px; border-radius: 8px; background: var(--text); color: var(--on-primary); font-size: 14px; box-shadow: var(--shadow-md); animation: card-in 0.2s ease-out; }
.toast.error { background: var(--again-ink); }

/* ========== SMALL SCREENS ========== */
@media (max-width: 820px) {
  /* Sidebar becomes a slim top bar with a menu button */
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { position: sticky; top: 0; z-index: 50; height: auto; gap: 0; padding: 6px 8px 6px 6px; border-right: none; border-bottom: 1px solid var(--border); background: var(--topbar-bg); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
  .sidebar .brand { padding: 4px 10px; }
  .menu-wrap { display: block; }
  .sidebar .nav, .sidebar .account { display: none; }
  .sidebar.open { max-height: 100vh; overflow-y: auto; box-shadow: var(--shadow-md); }
  .sidebar.open .nav { display: flex; padding: 8px 0 4px; }
  .sidebar.open .account { display: flex; flex-direction: row; align-items: center; justify-content: space-between; margin: 0; padding: 12px 10px 6px; }
  .sidebar.open .account .who { flex-direction: row; align-items: center; gap: 8px; min-width: 0; }
  .sidebar.open .account button { margin: 0; }
  .nav-item { padding: 11px 12px; font-size: 15px; }
  .nav-label { margin-top: 10px; }

  .main { padding: 20px 16px 48px; }

  /* Page titles: title on its own row, buttons below and easy to tap */
  .page-header { flex-direction: column; align-items: stretch; gap: 14px; margin-bottom: 22px; }
  .page-header .titles { min-width: 0; }
  .page-header h1 { font-size: 26px; }
  .page-header .actions { gap: 8px; }
  .page-header .actions:empty { display: none; }
  .page-header .actions > button { flex: 1 1 auto; justify-content: center; padding: 10px 14px; }
  .page-header .actions > button.primary { order: -1; flex-basis: 100%; }
  .page-header .actions > button.ghost { flex: 0 1 auto; }
  button.back { margin-bottom: 4px; }

  /* Deck page card list: question over answer, small icon buttons on the right */
  .list-head { flex-direction: column; }
  .card-list { display: block; }
  .card-row { display: grid; grid-template-columns: 14px minmax(0, 1fr) auto; grid-template-rows: auto auto; column-gap: 10px; row-gap: 2px; padding: 12px 12px 12px 14px; }
  .card-row.head { display: none; }
  .card-row .dot { grid-row: 1; align-self: center; }
  .card-row > .preview:nth-child(2) { grid-column: 2; grid-row: 1; font-weight: 500; }
  .card-row .row-actions { flex-wrap: nowrap; }
  .card-row > .preview:nth-child(3) { grid-column: 2; grid-row: 2; color: var(--text-soft); font-size: 13px; }
  .card-row .row-actions { grid-column: 3; grid-row: 1 / span 2; gap: 4px; }
  .card-row .row-actions button { width: 36px; height: 36px; padding: 0; justify-content: center; }
  .card-row .btn-label { display: none; }
  .card-row .pill { font-size: 11px; }

  /* Study: taller card, big colored buttons */
  .study { gap: 12px; }
  .scene { aspect-ratio: auto; height: calc(100svh - 290px); min-height: 300px; max-height: 560px; }
  .face { padding: 16px 18px 20px; }
  .hint { font-size: 12px; }
  .rate-row { gap: 6px; }
  .rate { padding: 14px 4px 12px; }
  .rate-label { font-size: 14px; }
  .rate kbd { display: none; }
  .study-done { padding: 48px 8px; }
  .study-done .row { flex-direction: column; width: 100%; max-width: 320px; }
  .study-done .row button { padding: 11px 14px; }

  .deck-grid { grid-template-columns: 1fr; gap: 10px; }
  .deck-card .desc:empty { display: none; }
  .deck-card .desc { min-height: 0; }

  .spread { grid-template-columns: 1fr; gap: 24px; }
  .editor-actions { flex-direction: column; align-items: stretch; }
  .editor-actions > span { display: none; }
  .editor-actions button:first-of-type { order: 3; }
  .editor-actions button { padding: 11px 14px; }
  .editor-actions button.primary { order: -1; }

  .table-row.members { grid-template-columns: minmax(0, 1fr) auto; row-gap: 8px; }
  .table-row.members > :nth-child(2), .table-row.members > :nth-child(3) { display: none; }
  .table-row.members.head { display: none; }
  .request { grid-template-columns: 1fr; }
  .request-card { grid-template-columns: 1fr; gap: 4px; }
  .request .row-actions { justify-content: stretch; }
  .request .row-actions button { flex: 1; padding: 9px 12px; }

  .tiles { grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 28px; }
  .tile { padding: 12px 14px; }
  .tile:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .tile-value { font-size: 22px; }
  .bars { gap: 1px; height: 120px; }
  .forecast { gap: 4px; padding: 12px 8px; }
  .table-row.team { grid-template-columns: minmax(0, 1fr) 50px 56px 44px; }
  .table-row.team > :nth-child(4), .table-row.team > :nth-child(5), .table-row.team > :nth-child(6) { display: none; }
  .table-row.deckstats { grid-template-columns: minmax(0, 1fr) 80px 48px; }
  .table-row.deckstats > :nth-child(4) { display: none; }
  .hard-row { grid-template-columns: minmax(0, 1fr) auto; }
  .hard-row > :nth-child(2) { display: none; }
  .setting { grid-template-columns: 1fr; gap: 8px; }
  .modal { padding: 20px; }
  .decks-top { grid-template-columns: 1fr; }
  .practice-row { margin-bottom: 14px; }
  .practice-row button { flex: 1; justify-content: center; padding: 8px 10px; }
  .list-tools .search-field { max-width: none; }
  .tag-chips { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px; padding: 0 16px 2px; scrollbar-width: none; }
  .chip-btn { flex: none; }
  .card-row > .q-cell { grid-column: 2; grid-row: 1; }
  .card-row > .q-cell .preview { font-weight: 500; }
  .card-row .row-actions button.icon-only { width: 36px; height: 36px; }
  .tags-row { flex-direction: column; align-items: stretch; gap: 8px; }
  .presets { grid-template-columns: 1fr; gap: 6px; }
  .preset { flex-direction: row; align-items: baseline; justify-content: space-between; }
  .import-options { grid-template-columns: 1fr; gap: 0; }
  .save-bar { margin: 0 -16px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
  .save-bar button { flex: 1; padding: 11px 12px; }
  .switch-row { align-items: flex-start; }
  .study-tools .btn-label { display: none; }
  .study.typing .scene { height: 40svh; min-height: 200px; max-height: 420px; }
  .type-answer { font-size: 16px; }
  .modal-actions button { flex: 1; padding: 10px 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ========== EXPORT ========== */
.export-choices { display: flex; flex-direction: column; gap: 10px; }
.export-choice { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; border: 1px solid var(--border-strong); border-radius: var(--radius-lg); background: var(--bg); text-align: left; }
.export-choice:hover { background: var(--bg-soft); }
.export-choice svg { flex-shrink: 0; margin-top: 2px; color: var(--text-soft); }
.export-choice p { margin: 2px 0 0; }
.export-choice.busy { opacity: 0.55; pointer-events: none; }
#print-root { display: none; }
@media print {
  body.printing > *:not(#print-root) { display: none !important; }
  body.printing { background: #fff !important; color: #000 !important; }
  body.printing #print-root { display: block; font-size: 11pt; line-height: 1.45; color: #000; }
  #print-root h1 { font-size: 20pt; margin: 0 0 2pt; }
  #print-root .pc-meta { color: #555; margin: 0 0 14pt; }
  #print-root .pc-card { break-inside: avoid; page-break-inside: avoid; border: 1px solid #ccc; border-radius: 6pt; padding: 10pt 12pt; margin-bottom: 10pt; }
  #print-root .pc-num { font-size: 9pt; color: #666; margin-bottom: 6pt; }
  #print-root .pc-side + .pc-side { margin-top: 8pt; padding-top: 8pt; border-top: 1px dashed #ccc; }
  #print-root .pc-label { font-size: 8pt; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: #666; margin-bottom: 2pt; }
  #print-root .pc-text ul, #print-root .pc-text ol { margin: 2pt 0; padding-left: 18pt; }
  #print-root img { display: block; max-width: 100%; max-height: 9cm; margin-top: 6pt; border-radius: 4pt; }
}

/* ========== DECK PAGE ========== */
/* Overview + study controls in one panel; Study sits on the right. */
.study-panel { display: flex; align-items: center; gap: 20px 32px; margin-bottom: 26px; padding: 18px 20px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--bg-soft); }
.sp-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.sp-stats { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 18px; font-size: 14px; color: var(--text-soft); }
.sp-stats strong { color: var(--text); font-weight: 650; }
.sp-exam { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 20px; background: var(--hard-bg); color: var(--hard-ink); font-weight: 600; font-size: 13px; }
.study-panel .mastery-bar { height: 8px; border-radius: 4px; }
.legend-filters { display: flex; flex-wrap: wrap; gap: 2px 4px; margin-left: -8px; }
.legend-btn { display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px; border: 1px solid transparent; background: transparent; border-radius: 20px; font-size: 13px; color: var(--text-soft); }
.legend-btn:hover { background: var(--bg-hover); color: var(--text); }
.legend-btn.active { background: var(--bg); border-color: var(--border-strong); color: var(--text); }
.legend-btn:disabled { opacity: 0.45; }
.legend-n { color: var(--text-faint); font-variant-numeric: tabular-nums; }
.legend-btn.active .legend-n { color: var(--text-soft); }
.sp-actions { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.study-group { display: flex; gap: 6px; align-items: stretch; }
.size-select { font-size: 14px; padding: 0 8px; border-radius: var(--radius); background: var(--bg); }
.study-btn { padding: 9px 22px; font-size: 15px; font-weight: 600; }
.sp-practice { display: flex; gap: 4px; margin-right: -8px; }

/* Card list: quiet icon buttons, the row itself opens the editor. */
.card-row.clickable { cursor: pointer; }
.row-actions { gap: 2px; }
button.icon-btn { display: inline-grid; place-items: center; width: 32px; height: 32px; padding: 0; border-color: transparent; background: transparent; color: var(--text-faint); }
button.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
button.icon-btn.danger:hover { background: var(--again-bg); color: var(--again-ink); }
button.icon-btn.flag-btn.on { color: var(--hard-ink); }
@media (hover: hover) {
  .card-row:not(:hover):not(:focus-within) .icon-btn:not(.on) { opacity: 0.55; }
}

/* "More" menu */
.more-wrap { position: relative; }
button.more-btn { width: 36px; height: 36px; }
.more-pop { position: absolute; right: 0; top: calc(100% + 6px); z-index: 40; min-width: 190px; padding: 4px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); display: flex; flex-direction: column; animation: fade-in 0.12s ease-out; }
.more-pop button { justify-content: flex-start; width: 100%; padding: 8px 10px; border: none; background: transparent; font-size: 14px; color: var(--text); }
.more-pop button:hover, .more-pop button:focus-visible { background: var(--bg-hover); }
.more-pop button.danger { color: var(--again-ink); }
.more-pop button.danger:hover { background: var(--again-bg); }
.more-pop .icon { color: var(--text-soft); }
.more-pop button.danger .icon { color: inherit; }

@media (max-width: 820px) {
  .study-panel { flex-direction: column; align-items: stretch; padding: 16px; margin-bottom: 20px; }
  .sp-actions { align-items: stretch; }
  .study-group > .study-btn { flex: 1; justify-content: center; }
  .sp-practice { margin-right: 0; }
  .sp-practice button { flex: 1; justify-content: center; }
  .page-header .actions { flex-wrap: nowrap; }
  .page-header .actions > .more-wrap { flex: none; }
  button.more-btn { width: 42px; height: 42px; }
  .card-row .row-actions button.icon-btn { width: 36px; height: 36px; }
  .list-tools .search-field { max-width: none; }
  .tag-chips { margin-bottom: 10px; }
}

/* ========== DECKS OVERVIEW ========== */
.header-search { width: 300px; }
.header-search .search-results { left: auto; width: min(460px, 90vw); }
.today-strip { display: flex; align-items: center; gap: 28px; margin-bottom: 22px; padding: 14px 20px; text-align: left; white-space: normal; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--bg-soft); font-weight: 400; }
.today-strip:hover { border-color: var(--border-strong); }
.today-goal { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.today-goal .goal-label { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; font-weight: 600; color: var(--text-soft); }
.goal-count { font-size: 13px; color: var(--text-soft); font-variant-numeric: tabular-nums; }
.goal-count strong { font-size: 15px; color: var(--text); }
.today-strip.reached .goal-label { color: var(--easy-ink); }
.today-strip.reached .goal-fill { background: var(--easy); }
.today-stats { display: flex; gap: 28px; flex: none; }
.today-stat { display: flex; flex-direction: column; line-height: 1.25; }
.today-stat strong { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.today-stat span { font-size: 12px; color: var(--text-soft); }
.today-stat.due strong { color: var(--hard-ink); }
@media (max-width: 820px) {
  .header-search { width: 100%; }
  .page-header .actions:has(.header-search) { flex-wrap: wrap; }
  .header-search .search-results { left: 0; width: auto; }
  .today-strip { gap: 18px; padding: 14px 16px; }
  .today-stats { gap: 16px; }
  .today-stat strong { font-size: 17px; }
}

/* ========== STUDY MODES ========== */
.mode-btn { gap: 4px; padding-right: 8px; font-weight: 500; background: var(--bg); }
.mode-btn .icon { color: var(--text-soft); }
.mode-pop { width: min(380px, calc(100vw - 32px)); padding: 6px; gap: 2px; }
.mode-pop-title { padding: 6px 10px 8px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-faint); }
.mode-row { display: flex; align-items: flex-start; gap: 2px; }
.mode-pick { flex: 1; min-width: 0; display: flex; align-items: flex-start; gap: 8px; padding: 8px 10px; border-radius: var(--radius); text-align: left; }
.mode-pick:hover { background: var(--bg-hover); }
.mode-pick.selected { background: var(--bg-soft); }
.mode-pick.disabled { opacity: 0.45; cursor: default; }
.mode-pick.disabled:hover { background: transparent; }
.mode-check { flex: none; width: 16px; height: 20px; display: grid; place-items: center; color: var(--easy-ink); }
.mode-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.mode-name { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-weight: 600; font-size: 14px; }
.mode-badge { background: var(--easy-bg); color: var(--easy-ink); font-size: 11px; padding: 1px 7px; }
.mode-count { font-weight: 500; font-size: 12px; color: var(--text-soft); background: var(--bg-hover); border-radius: 10px; padding: 0 7px; font-variant-numeric: tabular-nums; }
.mode-short { font-size: 13px; color: var(--text-soft); line-height: 1.35; }
.more-pop button.mode-help { width: 32px; height: 32px; padding: 0; justify-content: center; margin-top: 4px; color: var(--text-faint); }
.more-pop button.mode-help:hover, .more-pop button.mode-help.on { color: var(--accent); background: var(--accent-soft); }
.mode-info { margin: 2px 10px 8px 34px; padding: 8px 10px; border-radius: var(--radius); background: var(--accent-soft); color: var(--text); font-size: 13px; line-height: 1.45; }

/* ========== GUIDES ========== */
.title-row { display: flex; align-items: center; gap: 6px; }
button.help-btn { width: 30px; height: 30px; color: var(--text-faint); }
button.help-btn:hover { color: var(--accent); background: var(--accent-soft); }
.study-tools button.help-btn { width: 30px; height: 30px; }
.guide { display: flex; flex-direction: column; gap: 14px; max-height: 60vh; overflow-y: auto; margin-bottom: 4px; }
.guide h4 { font-size: 14px; font-weight: 650; margin: 0 0 4px; }
.guide ul { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--text-soft); line-height: 1.45; }

@media (max-width: 820px) {
  .study-group { flex-wrap: wrap; }
  .study-group > .mode-wrap { flex: 1 1 auto; }
  .study-group > .mode-wrap > .mode-btn { width: 100%; justify-content: space-between; padding: 10px 12px; }
  .study-group > .size-select { flex: 1 1 auto; }
  .study-group > .study-btn { flex: 1 1 100%; }
  .mode-pop { right: auto; left: 0; }
}

/* ========== PHONES (all pages) ==========
   iPhone Safari zooms in when you tap a field with text smaller than 16px and often stays zoomed,
   which makes the page stick out on both sides. 16px on touch screens prevents that everywhere. */
@media (pointer: coarse), (max-width: 820px) {
  input:not([type="range"]):not([type="checkbox"]):not([type="radio"]), select, textarea { font-size: 16px !important; }
  [contenteditable="true"] { font-size: 16px; }
}
@media (max-width: 820px) {
  /* Keep content clear of the notch and the rounded screen corners (landscape, home-screen app). */
  .sidebar { padding-left: max(6px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); padding-top: max(6px, env(safe-area-inset-top)); }
  .main { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); padding-bottom: calc(48px + env(safe-area-inset-bottom)); }
  .modal-overlay { padding: 16px max(12px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
  .modal { max-width: 100%; }
  .tag-chips { margin-left: calc(-1 * max(16px, env(safe-area-inset-left))); margin-right: calc(-1 * max(16px, env(safe-area-inset-right))); padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  .deck-card h3, .page-header h1, .study-exit { overflow-wrap: anywhere; }
}

@media (max-width: 820px) {
  /* Card list: show more of each question instead of cutting it after one line. */
  .card-row .q-cell .clip, .card-row > .preview .clip { white-space: normal; display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; }
  .card-row .q-cell .clip { -webkit-line-clamp: 3; }
  .card-row > .preview .clip { -webkit-line-clamp: 2; }
  .card-row .row-tags { min-width: 0; }
  .card-row .row-tags .tag { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .chip-btn { max-width: 75vw; }
  .chip-btn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

