/* =============================================================
   app.css: PrepSession application UI (dashboard, decks, create,
   study sessions, account). Builds on the tokens in theme.css.

   Pages opt in with <body class="app">. Landing pages (home/about)
   keep their original look; only shared bits (user menu, toasts,
   modal, auth extras) apply everywhere.
   ============================================================= */

/* Extra tokens for shared components on non-app pages (theme.css owns the rest). */
:root {
  --surface-2: #faf6e8;
  --surface-3: #efe8d2;
  --line-strong: rgba(60, 52, 28, 0.26);
  --brand-tint: #e8eee3;
  --btn-bg: #12302b;
  --btn-ink: #fdf9ec;
  --btn-bg-hover: #1d4239;
  --focus: rgba(47, 101, 89, 0.32);
  --ok: #2f7d3e; --ok-tint: #e2f1df;
  --bad: #b5401f; --bad-tint: #fbe8e1;
  --warn: #9a6a12; --warn-tint: #fcf0d6;
  --info: #3d6e5f; --info-tint: #e5efe9;
  --shadow-card: 0 1px 2px rgba(22, 30, 20, 0.05), 0 4px 16px rgba(22, 30, 20, 0.05);
}

/* ---------- App tokens (light): "reading room": cream paper, navy-green ink, tan ---------- */
body.app {
  --bg: #f3edd7;
  --surface: #fffdf6;
  --surface-2: #faf6e8;
  --surface-3: #efe8d2;
  --ink: #1b2a25;
  --ink-soft: #44544c;
  --ink-muted: #6e7461;
  --line: rgba(60, 52, 28, 0.15);
  --line-strong: rgba(60, 52, 28, 0.3);
  --brand: #2f6559;
  --brand-strong: #12302b;
  --brand-tint: #e8eee3;
  --btn-bg: #12302b;
  --btn-ink: #fdf9ec;
  --btn-bg-hover: #1d4239;
  --accent: #9f9773;
  --accent-tint: #efe9d3;
  --ok: #2e7d3f;
  --ok-tint: #e2efdc;
  --bad: #a5432f;
  --bad-tint: #f6e3dc;
  --warn: #8f6410;
  --warn-tint: #f8ecd0;
  --info: #3d6e5f;
  --info-tint: #e5efe9;
  --focus: rgba(47, 101, 89, 0.32);
  --header-bg: #f6efd6;
  --shadow-card: 0 1px 2px rgba(22, 30, 20, 0.06), 0 4px 14px rgba(22, 30, 20, 0.05);
  color-scheme: light;
}

/* ---------- App tokens (dark): "library after hours": navy-green, cream ink, tan ---------- */
html[data-theme="dark"] body.app {
  --bg: #071512;
  --surface: #0e211c;
  --surface-2: #122822;
  --surface-3: #1a352d;
  --ink: #efe8d0;
  --ink-soft: #c9c1a2;
  --ink-muted: #969178;
  --line: rgba(207, 198, 162, 0.12);
  --line-strong: rgba(207, 198, 162, 0.24);
  --brand: #cfc39a;
  --brand-strong: #e6dbb2;
  --brand-tint: rgba(207, 195, 154, 0.12);
  --btn-bg: #c2b78e;
  --btn-ink: #0c1f1b;
  --btn-bg-hover: #d4c9a0;
  --accent: #c2b78e;
  --accent-tint: rgba(194, 183, 142, 0.14);
  --ok: #8fd19e;
  --ok-tint: rgba(143, 209, 158, 0.12);
  --bad: #f09a83;
  --bad-tint: rgba(240, 154, 131, 0.12);
  --warn: #e9c46a;
  --warn-tint: rgba(233, 196, 106, 0.12);
  --info: #a8cdb9;
  --info-tint: rgba(168, 205, 185, 0.12);
  --focus: rgba(207, 195, 154, 0.38);
  --header-bg: #0b1d19;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 14px 36px rgba(0, 0, 0, 0.45);
  --shadow-xl: 0 28px 70px rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  html[data-theme="system"] body.app {
    --bg: #071512;
    --surface: #0e211c;
    --surface-2: #122822;
    --surface-3: #1a352d;
    --ink: #efe8d0;
    --ink-soft: #c9c1a2;
    --ink-muted: #969178;
    --line: rgba(207, 198, 162, 0.12);
    --line-strong: rgba(207, 198, 162, 0.24);
    --brand: #cfc39a;
    --brand-strong: #e6dbb2;
    --brand-tint: rgba(207, 195, 154, 0.12);
    --btn-bg: #c2b78e;
    --btn-ink: #0c1f1b;
    --btn-bg-hover: #d4c9a0;
    --accent: #c2b78e;
    --accent-tint: rgba(194, 183, 142, 0.14);
    --ok: #8fd19e;
    --ok-tint: rgba(143, 209, 158, 0.12);
    --bad: #f09a83;
    --bad-tint: rgba(240, 154, 131, 0.12);
    --warn: #e9c46a;
    --warn-tint: rgba(233, 196, 106, 0.12);
    --info: #a8cdb9;
    --info-tint: rgba(168, 205, 185, 0.12);
    --focus: rgba(207, 195, 154, 0.38);
    --header-bg: #0b1d19;
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.25);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 14px 36px rgba(0, 0, 0, 0.45);
    --shadow-xl: 0 28px 70px rgba(0, 0, 0, 0.55);
    color-scheme: dark;
  }
}

/* The hidden attribute must win over component display rules (flex/grid). */
[hidden] { display: none !important; }

/* ---------- App shell ---------- */
body.app {
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  padding-top: var(--header-h);
  display: block;
}
main#main { display: block; flex: 1 0 auto; width: 100%; }

body.app .site-header { background: var(--header-bg); border-bottom-color: var(--line); box-shadow: none; }
body.app .nav-link { color: var(--ink-soft); }
body.app .nav-link:hover,
body.app .nav-link.current-page { color: var(--brand-strong); }
body.app .nav-link::after { background: var(--brand-strong); }
body.app .navigation .nav-study { color: var(--brand-strong); border-color: var(--brand-strong); }
body.app .navigation .nav-study:hover,
body.app .navigation .nav-study.current-page { background: var(--btn-bg); border-color: var(--btn-bg); color: var(--btn-ink); }

.nav-link ion-icon { vertical-align: -2px; font-size: 1.05em; }

.skip-link {
  position: absolute; left: 12px; top: -48px; z-index: 100000000;
  padding: 8px 14px; border-radius: var(--r-sm);
  background: var(--brand-strong); color: #fff; font-weight: 600; text-decoration: none;
}
.skip-link:focus { top: 12px; }

/* ---------- User menu (header) ---------- */
.user-menu { position: relative; }
.avatar-btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px 3px 3px; border-radius: var(--r-pill);
  background: transparent; border: 1.5px solid var(--line); cursor: pointer; color: var(--ink-soft);
  font: inherit; transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.avatar-btn:hover { border-color: var(--brand-strong); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: inline-grid; place-items: center;
  background: linear-gradient(140deg, #4d8273, #12302b); color: #fdf9ec;
  font-weight: 700; font-size: 0.95rem;
}
.menu {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 240px; z-index: 50;
  background: var(--surface, #fff); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r-md);
  box-shadow: var(--shadow-lg); padding: 6px;
}
.menu[hidden] { display: none; }
.menu-head { display: flex; flex-direction: column; padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu-head strong { font-size: 0.95rem; }
.menu-head span { font-size: 0.8rem; color: var(--ink-muted); overflow: hidden; text-overflow: ellipsis; }
.menu a, .menu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 10px; border-radius: var(--r-sm);
  background: none; border: 0; cursor: pointer; text-align: left;
  font: inherit; font-size: 0.9rem; color: var(--ink); text-decoration: none;
}
.menu a:hover, .menu button:hover, .menu a:focus-visible, .menu button:focus-visible { background: var(--brand-tint, #e8eee3); outline: none; }
.menu ion-icon { font-size: 1.1rem; color: var(--ink-muted); }

/* ---------- Auth modal extras ---------- */
.auth-backdrop {
  position: fixed; inset: 0; z-index: 999999;
  background: rgba(20, 28, 12, 0.5);
}
.auth-sub { text-align: center; color: var(--ink-soft); font-size: var(--fs-sm); margin-bottom: var(--sp-3); }
.auth-ok {
  display: none; color: #2f6b2c; background: rgba(63, 138, 74, 0.1);
  border: 1px solid rgba(63, 138, 74, 0.25); border-radius: var(--r-sm);
  padding: 9px 12px; margin-bottom: var(--sp-3); font-size: var(--fs-sm); text-align: center;
}
.wrapper .icon-close { background: none; border: 0; }
.wrapper .btn:disabled { opacity: 0.7; cursor: wait; }

/* ---------- Layout ---------- */
.container { width: min(1180px, 100% - 32px); margin-inline: auto; }
.container.narrow { width: min(860px, 100% - 32px); }
.page { padding-block: clamp(20px, 4vw, 40px) 64px; }
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  margin-bottom: 24px;
}
.page-head h1 { font-size: clamp(1.6rem, 3vw, 2.2rem); line-height: 1.15; letter-spacing: -0.02em; }
.page-head p { color: var(--ink-soft); margin-top: 4px; }
.eyebrow { font-size: 0.78rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--brand); }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack.lg { gap: 20px; }
.grow { flex: 1 1 auto; min-width: 0; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.muted { color: var(--ink-muted); }
.soft { color: var(--ink-soft); }
.small { font-size: var(--fs-sm); }
.tiny { font-size: 0.75rem; }
.center { text-align: center; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.mt-1 { margin-top: 4px; } .mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; } .mt-5 { margin-top: 24px; } .mt-6 { margin-top: 32px; }

/* ---------- Buttons ---------- */
.ui-btn {
  --b-bg: var(--surface); --b-ink: var(--ink); --b-line: var(--line-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 8px 16px;
  font: 600 0.92rem/1.2 var(--font); letter-spacing: 0.005em;
  color: var(--b-ink); background: var(--b-bg);
  border: 1.5px solid var(--b-line); border-radius: var(--r-md);
  cursor: pointer; text-decoration: none; white-space: nowrap; user-select: none;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease), transform 0.12s var(--ease), box-shadow var(--dur) var(--ease);
}
.ui-btn:hover { border-color: var(--brand); }
.ui-btn:active { transform: translateY(1px); }
.ui-btn:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--focus); }
.ui-btn[disabled], .ui-btn.is-loading { opacity: 0.6; cursor: not-allowed; pointer-events: none; }
.ui-btn ion-icon { font-size: 1.15em; flex-shrink: 0; }
.ui-btn.primary { --b-bg: var(--btn-bg); --b-ink: var(--btn-ink); --b-line: var(--btn-bg); box-shadow: 0 1px 2px rgba(22, 30, 20, 0.15); }
.ui-btn.primary:hover { --b-bg: var(--btn-bg-hover); --b-line: var(--btn-bg-hover); }
.ui-btn.soft { --b-bg: var(--brand-tint); --b-ink: var(--brand-strong); --b-line: transparent; }
.ui-btn.soft:hover { --b-line: var(--brand); }
.ui-btn.ghost { --b-bg: transparent; --b-line: transparent; --b-ink: var(--ink-soft); }
.ui-btn.ghost:hover { --b-bg: var(--surface-3); --b-ink: var(--ink); }
.ui-btn.danger { --b-bg: var(--bad); --b-ink: #fff; --b-line: var(--bad); }
.ui-btn.danger-ghost { --b-bg: transparent; --b-ink: var(--bad); --b-line: transparent; }
.ui-btn.danger-ghost:hover { --b-bg: var(--bad-tint); }
.ui-btn.ai { --b-bg: linear-gradient(120deg, #12302b, #7d7650); --b-ink: #fff; --b-line: transparent; background: linear-gradient(120deg, #12302b, #7d7650); }
.ui-btn.ai:hover { filter: brightness(1.08); }
.ui-btn.sm { min-height: 32px; padding: 5px 11px; font-size: 0.84rem; border-radius: var(--r-sm); }
.ui-btn.lg { min-height: 50px; padding: 12px 24px; font-size: 1rem; border-radius: var(--r-md); }
.ui-btn.xl { min-height: 58px; padding: 14px 30px; font-size: 1.08rem; border-radius: var(--r-lg); }
.ui-btn.block { width: 100%; }
.ui-btn.icon { min-width: 40px; padding: 8px; }
.ui-btn.icon.sm { min-width: 32px; padding: 5px; }
.ui-btn.is-loading::before {
  content: ""; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .label { font-size: 0.86rem; font-weight: 600; color: var(--ink); }
.hint { font-size: 0.8rem; color: var(--ink-muted); }
.input, .textarea, .select {
  width: 100%; padding: 10px 12px;
  font: 400 0.95rem/1.5 var(--font); color: var(--ink);
  background: var(--surface); border: 1.5px solid var(--line-strong); border-radius: var(--r-md);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--ink-muted); }
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--focus); }
.textarea { resize: vertical; min-height: 110px; }
.select { appearance: none; padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%237a876c' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }
.input.lg { padding: 13px 14px; font-size: 1.05rem; }
.input.title-input { font-size: 1.4rem; font-weight: 700; border-color: transparent; background: transparent; padding-inline: 6px; }
.input.title-input:hover { border-color: var(--line); }
.input.title-input:focus { border-color: var(--brand); background: var(--surface); }

/* Toggle switch */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: 0.92rem; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track {
  position: relative; width: 40px; height: 23px; border-radius: 999px; flex-shrink: 0;
  background: var(--line-strong); transition: background var(--dur) var(--ease);
}
.switch .track::after {
  content: ""; position: absolute; left: 3px; top: 3px; width: 17px; height: 17px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); transition: transform var(--dur) var(--ease);
}
.switch input:checked + .track { background: var(--brand); }
.switch input:checked + .track::after { transform: translateX(17px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 4px var(--focus); }

/* Selectable chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  position: relative; display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 14px; border-radius: var(--r-pill);
  border: 1.5px solid var(--line-strong); background: var(--surface);
  font: 500 0.88rem var(--font); color: var(--ink-soft); cursor: pointer; user-select: none;
  transition: all var(--dur) var(--ease);
}
.chip:hover { border-color: var(--brand); color: var(--ink); }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip:has(input:checked), .chip.on { background: var(--brand-tint); border-color: var(--brand); color: var(--brand-strong); font-weight: 600; }
.chip:has(input:focus-visible) { box-shadow: 0 0 0 4px var(--focus); }
.chip ion-icon { font-size: 1.05rem; }

/* Segmented control */
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: var(--r-md); background: var(--surface-3); border: 1px solid var(--line); }
.seg label, .seg button {
  position: relative; padding: 7px 14px; border-radius: 9px; border: 0; background: transparent;
  font: 500 0.88rem var(--font); color: var(--ink-soft); cursor: pointer; white-space: nowrap;
}
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked), .seg button.on { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(22, 30, 20, 0.12); }
.seg label:has(input:focus-visible) { box-shadow: 0 0 0 3px var(--focus); }

/* ---------- Surfaces ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
}
.panel.pad { padding: clamp(16px, 2.6vw, 24px); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.panel-head h2, .panel-head h3 { font-size: 1.05rem; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.panel-head h2 ion-icon, .panel-head h3 ion-icon { color: var(--brand); font-size: 1.2rem; }
.panel-body { padding: 16px 20px; }
.section-title { font-size: 1.1rem; font-weight: 700; display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }

.callout {
  display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r-md);
  background: var(--info-tint); color: var(--ink); border: 1px solid transparent; font-size: 0.9rem;
}
.callout ion-icon { font-size: 1.25rem; color: var(--info); flex-shrink: 0; margin-top: 1px; }
.callout.warn { background: var(--warn-tint); } .callout.warn ion-icon { color: var(--warn); }
.callout.ok { background: var(--ok-tint); } .callout.ok ion-icon { color: var(--ok); }
.callout.bad { background: var(--bad-tint); } .callout.bad ion-icon { color: var(--bad); }
.callout code { font-size: 0.85em; background: rgba(0, 0, 0, 0.06); padding: 1px 5px; border-radius: 4px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: var(--r-pill);
  font-size: 0.74rem; font-weight: 600; letter-spacing: 0.01em; white-space: nowrap;
  background: var(--surface-3); color: var(--ink-soft);
}
.badge ion-icon { font-size: 0.95em; }
.badge.brand { background: var(--brand-tint); color: var(--brand-strong); }
.badge.ok { background: var(--ok-tint); color: var(--ok); }
.badge.bad { background: var(--bad-tint); color: var(--bad); }
.badge.warn { background: var(--warn-tint); color: var(--warn); }
.badge.info { background: var(--info-tint); color: var(--info); }
.kbd { display: inline-block; min-width: 20px; padding: 0 5px; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 5px; font: 600 0.72rem/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; text-align: center; color: var(--ink-soft); background: var(--surface); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex; align-items: center; gap: 7px; padding: 11px 14px; margin-bottom: -1px;
  border: 0; border-bottom: 2.5px solid transparent; background: none; cursor: pointer;
  font: 600 0.92rem var(--font); color: var(--ink-muted); white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--brand-strong); border-bottom-color: var(--brand-strong); }
.tab .count { font-size: 0.74rem; padding: 1px 7px; border-radius: 999px; background: var(--surface-3); color: var(--ink-soft); }
.tab:focus-visible { outline: none; box-shadow: inset 0 0 0 3px var(--focus); border-radius: 8px 8px 0 0; }

/* ---------- Progress ---------- */
.bar { position: relative; height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.bar > span { position: absolute; inset: 0 auto 0 0; border-radius: inherit; background: var(--brand); transition: width 0.5s var(--ease); }
.bar.thin { height: 5px; }
.ring { --size: 120px; --stroke: 10px; position: relative; width: var(--size); height: var(--size); }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: var(--stroke); }
.ring .ring-track { stroke: var(--surface-3); }
.ring .ring-fill { stroke: var(--brand); stroke-linecap: round; transition: stroke-dashoffset 0.8s var(--ease); }
.ring .ring-label { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; line-height: 1.1; }
.ring .ring-label strong { font-size: 1.5rem; font-weight: 700; }
.ring .ring-label span { font-size: 0.75rem; color: var(--ink-muted); }

/* ---------- Stats ---------- */
.stat { padding: 16px 18px; display: flex; flex-direction: column; gap: 2px; }
.stat .stat-label { font-size: 0.8rem; color: var(--ink-muted); font-weight: 500; display: flex; align-items: center; gap: 6px; }
.stat .stat-label ion-icon { font-size: 1.05rem; color: var(--brand); }
.stat .stat-value { font-size: 1.65rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; }
.stat .stat-sub { font-size: 0.78rem; color: var(--ink-muted); }

/* ---------- Deck tiles ---------- */
.deck-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.deck-tile {
  --deck: #2f6559;
  position: relative; display: flex; flex-direction: column; gap: 10px;
  padding: 18px 18px 16px; border-radius: var(--r-lg); overflow: hidden;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-card);
  color: var(--ink); text-decoration: none;
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.deck-tile::before { content: ""; position: absolute; inset: 0 0 auto; height: 4px; background: var(--deck); }
.deck-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: color-mix(in srgb, var(--deck) 45%, transparent); }
.deck-tile:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--focus); }
.deck-tile h3 { font-size: 1.05rem; font-weight: 700; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.deck-tile .deck-subject { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--deck); }
.deck-tile .deck-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.deck-tile .deck-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: auto; font-size: 0.78rem; color: var(--ink-muted); }
.deck-tile .bar > span { background: var(--deck); }
.deck-new {
  display: grid; place-content: center; text-align: center; gap: 6px; min-height: 170px;
  border: 2px dashed var(--line-strong); background: transparent; box-shadow: none; color: var(--ink-soft);
}
.deck-new::before { display: none; }
.deck-new ion-icon { font-size: 1.8rem; margin-inline: auto; color: var(--brand); }
.deck-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--deck, #2f6559); display: inline-block; flex-shrink: 0; }

.c-sage { --deck: #2f6559; } .c-ocean { --deck: #2f5f8a; } .c-plum { --deck: #6a4c93; } .c-amber { --deck: #b08a1e; }
.c-rose { --deck: #a5432f; } .c-teal { --deck: #3d8a7a; } .c-slate { --deck: #5b6b7c; } .c-sand { --deck: #8a7f55; }

/* ---------- Lists ---------- */
.list { display: flex; flex-direction: column; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.list-icon { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--brand-tint); color: var(--brand-strong); flex-shrink: 0; font-size: 1.15rem; }
.list-row .list-title { font-weight: 600; font-size: 0.93rem; }
.list-row .list-sub { font-size: 0.8rem; color: var(--ink-muted); }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 36px 20px; color: var(--ink-soft); }
.empty ion-icon { font-size: 2.4rem; color: var(--brand); opacity: 0.8; }
.empty h3 { font-size: 1.05rem; color: var(--ink); margin: 8px 0 4px; }
.empty p { font-size: 0.9rem; max-width: 420px; margin: 0 auto 14px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100000001; display: grid; place-items: center; padding: 16px;
  background: rgba(8, 20, 16, 0.5);
  opacity: 0; transition: opacity 0.18s var(--ease);
}
.modal-backdrop.show { opacity: 1; }
.modal {
  width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto;
  background: var(--surface, #fff); color: var(--ink); border-radius: var(--r-lg); box-shadow: var(--shadow-xl);
  transform: translateY(8px) scale(0.98); transition: transform 0.2s var(--ease);
  font-family: var(--font);
}
.modal-backdrop.show .modal { transform: none; }
.modal--sm { width: min(420px, 100%); }
.modal--lg { width: min(780px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 18px 20px 6px; }
.modal-head h2 { font-size: 1.15rem; font-weight: 700; }
.modal-body { padding: 8px 20px 18px; color: var(--ink-soft); font-size: 0.95rem; }
.modal-body p + p { margin-top: 8px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 18px; border-top: 1px solid var(--line); }
body.modal-open { overflow: hidden; }

/* ---------- Toasts ---------- */
.toast-stack { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100000002; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: min(440px, calc(100vw - 24px)); }
.toast {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 11px 14px; border-radius: var(--r-md);
  background: #0f2621; color: #f6f0dc; box-shadow: inset 0 0 0 1px rgba(201, 188, 138, 0.22), 4px 4px 0 rgba(0, 0, 0, 0.35);
  font: 500 0.9rem/1.4 var(--font); pointer-events: auto;
  opacity: 0; transform: translateY(10px); transition: opacity 0.2s var(--ease), transform 0.2s var(--ease);
}
.toast.show { opacity: 1; transform: none; }
.toast ion-icon { font-size: 1.25rem; flex-shrink: 0; color: #e2d6a8; }
.toast--error ion-icon { color: #f39a7f; }
.toast--warn ion-icon { color: #f1c766; }
.toast .toast-msg { flex: 1; }
.toast-action { background: none; border: 0; color: #e2d6a8; font: 700 0.85rem var(--font); cursor: pointer; padding: 4px 6px; border-radius: 6px; }
.toast-action:hover { background: rgba(255, 255, 255, 0.08); }

/* ---------- Loading ---------- */
.skeleton { background: linear-gradient(90deg, var(--surface-3) 0%, var(--surface-2) 50%, var(--surface-3) 100%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 10px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--surface-3); border-top-color: var(--brand); animation: spin 0.8s linear infinite; }

/* ---------- Heatmap ---------- */
.heatmap { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 15px); grid-auto-columns: 15px; gap: 3px; overflow-x: auto; padding: 3px 3px 6px; }
.hm { display: inline-block; width: 15px; height: 15px; border-radius: 4px; background: var(--surface-3); }
.hm.l1 { background: color-mix(in srgb, var(--brand) 30%, var(--surface-3)); }
.hm.l2 { background: color-mix(in srgb, var(--brand) 55%, var(--surface-3)); }
.hm.l3 { background: color-mix(in srgb, var(--brand) 80%, var(--surface-3)); }
.hm.l4 { background: var(--brand-strong); }
.hm.future { background: transparent; }
.hm.today { outline: 2px solid var(--ink-muted); outline-offset: 1px; }
.hm-legend { display: flex; align-items: center; gap: 4px; font-size: 0.72rem; color: var(--ink-muted); }
.hm-legend .hm { width: 11px; height: 11px; }

/* ---------- Content ---------- */
.bullets { padding-left: 1.15em; display: flex; flex-direction: column; gap: 5px; }
.bullets li::marker { color: var(--brand); }
.prose { white-space: pre-wrap; line-height: 1.7; font-size: 0.95rem; }

/* ---------- Dropzone ---------- */
.dropzone {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  padding: 28px 18px; border: 2px dashed var(--line-strong); border-radius: var(--r-lg);
  background: var(--surface-2); text-align: center; color: var(--ink-soft); cursor: pointer;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.dropzone:hover, .dropzone.drag { border-color: var(--brand); background: var(--brand-tint); }
.dropzone ion-icon { font-size: 2.2rem; color: var(--brand); }
.dropzone strong { color: var(--ink); }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.file-list { display: flex; flex-direction: column; gap: 6px; }
.file-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 12px; border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--line); font-size: 0.88rem; }
.file-item ion-icon { font-size: 1.25rem; color: var(--brand); }
.file-item .grow { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  body.app { padding-top: 0; }
  .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; }
  .page-head { align-items: flex-start; }
  .panel-head, .panel-body, .list-row { padding-inline: 14px; }
  .nav-link ion-icon { display: none; }
}
@media (max-width: 440px) {
  .grid.cols-4 { grid-template-columns: 1fr 1fr; }
  .stat .stat-value { font-size: 1.35rem; }
}
.link-btn { padding: 0; border: 0; background: none; color: var(--brand-strong); font: inherit; font-weight: 600; text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }

/* ---- Math (LaTeX typeset by KaTeX, see PS.math in core.js) ---- */
.math .katex { font-size: 1.06em; }
.math-display { display: block; margin: 0.45em 0; max-width: 100%; overflow-x: auto; overflow-y: hidden; text-align: center; }
.math-display .katex-display { margin: 0; }
.math-sup { font-size: 0.72em; line-height: 0; }

/* ---- Friends link: count of new friend requests and room invites ---- */
.nav-badge { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; margin-left: 5px; border-radius: 999px;
  background: var(--bad); color: #fff; font-size: 0.7rem; font-weight: 700; line-height: 1; vertical-align: 1px; }
.nav-badge[hidden] { display: none; }
