/* =========================================================================
   DSA Tracker stylesheet.

   Look: a paper notebook in light mode, warm charcoal in dark mode, one
   burnt-orange accent used sparingly (the "red pen"). Numbers and code are
   set in a monospace face so columns of counts line up.

   Theming: every colour is a CSS variable ("token"). Light values sit on
   :root; dark values override them when the device prefers dark (unless the
   user picked Light) or when the user picked Dark. See js/theme*.js.

   Mobile-first: base rules target phones; @media (min-width: ...) blocks
   add desktop tweaks on top.
   ========================================================================= */

@font-face { font-family: "Plex Sans"; src: url("/static/fonts/plex-sans-400.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Plex Sans"; src: url("/static/fonts/plex-sans-500.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Plex Sans"; src: url("/static/fonts/plex-sans-600.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Plex Sans"; src: url("/static/fonts/plex-sans-700.woff2") format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: "JetBrains Mono"; src: url("/static/fonts/jetbrains-mono-400.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "JetBrains Mono"; src: url("/static/fonts/jetbrains-mono-600.woff2") format("woff2"); font-weight: 600; font-display: swap; }

/* ---------- tokens: light (default) ---------- */
:root {
  --bg: #f5f3ee;
  --surface: #fffefb;
  --surface-2: #eeebe4;
  --border: #e3dfd5;
  --border-strong: #cdc7ba;
  --text: #1f1d1a;
  --muted: #6e695f;
  --faint: #a29c90;

  --accent: #c2410c;
  --accent-hover: #a8380a;
  --on-accent: #ffffff;
  --accent-soft: #fbe9df;

  --good: #1d7a47;
  --warn: #a15c07;
  --bad: #b42318;
  --easy: #0f766e;
  --medium: #a16207;
  --hard: #be123c;

  --heat-0: #ebe7df;
  --heat-1: #f5c9ad;
  --heat-2: #eb9563;
  --heat-3: #d4622a;
  --heat-4: #a8380a;

  --toast-bg: #1f1d1a;
  --toast-text: #f5f3ee;
  --shadow: 0 1px 2px rgba(31, 29, 26, 0.06), 0 4px 16px rgba(31, 29, 26, 0.06);

  --radius: 10px;
  --radius-sm: 6px;
  --nav-h: 62px;
  --font: "Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

/* ---------- tokens: dark ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141312;
    --surface: #1b1a18;
    --surface-2: #252320;
    --border: #2d2b28;
    --border-strong: #3e3b36;
    --text: #ece8e1;
    --muted: #a09a8f;
    --faint: #6c675f;
    --accent: #f08a4b;
    --accent-hover: #f5a06b;
    --on-accent: #1a0e06;
    --accent-soft: #3a2518;
    --good: #5cc28a;
    --warn: #e0a64a;
    --bad: #f27a6e;
    --easy: #4cc2b3;
    --medium: #d9ab4a;
    --hard: #f47a95;
    --heat-0: #232120;
    --heat-1: #4a2c1b;
    --heat-2: #7d4221;
    --heat-3: #c05f27;
    --heat-4: #f08a4b;
    --toast-bg: #ece8e1;
    --toast-text: #1b1a18;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141312;
  --surface: #1b1a18;
  --surface-2: #252320;
  --border: #2d2b28;
  --border-strong: #3e3b36;
  --text: #ece8e1;
  --muted: #a09a8f;
  --faint: #6c675f;
  --accent: #f08a4b;
  --accent-hover: #f5a06b;
  --on-accent: #1a0e06;
  --accent-soft: #3a2518;
  --good: #5cc28a;
  --warn: #e0a64a;
  --bad: #f27a6e;
  --easy: #4cc2b3;
  --medium: #d9ab4a;
  --hard: #f47a95;
  --heat-0: #232120;
  --heat-1: #4a2c1b;
  --heat-2: #7d4221;
  --heat-3: #c05f27;
  --heat-4: #f08a4b;
  --toast-bg: #ece8e1;
  --toast-text: #1b1a18;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.3);
  color-scheme: dark;
}

/* ---------- base ---------- */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px; /* 16px+ stops iOS from zooming into inputs */
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  /* room for the fixed bottom nav on phones (+ iPhone home bar) */
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 20px);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

h1, h2, h3 { line-height: 1.2; margin: 0 0 0.5rem; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; letter-spacing: -0.02em; }
h2 { font-size: 1.05rem; }
h3 { font-size: 1rem; }

.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.mono, .num { font-family: var(--mono); font-feature-settings: "zero" 0; }
.hidden { display: none !important; }
.i { flex: 0 0 auto; vertical-align: -0.2em; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- top bar & navigation ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: 920px;
  margin: 0 auto;
  padding: 10px 16px;
  min-height: 56px;
}

.brand {
  display: inline-flex;
  align-items: baseline;
  font-family: var(--mono);
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
  letter-spacing: -0.02em;
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand .slash { color: var(--accent); padding: 0 1px; }

.topbar-right { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.me-link { display: inline-flex; align-items: center; gap: 8px; color: var(--text); font-size: 0.9rem; }
.me-link:hover { text-decoration: none; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
}
.icon-btn:hover { color: var(--text); background: var(--surface-2); border-color: transparent; }

/* Phones: a bottom tab bar. */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 500;
  min-width: 0;
}
.tab:hover { text-decoration: none; color: var(--text); }
.tab .icon { position: relative; display: grid; place-items: center; }
.tab.active { color: var(--text); }
.tab.active .icon { color: var(--accent); }
.tab.primary .icon {
  width: 38px;
  height: 30px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--on-accent);
}
.tab.primary.active .icon { color: var(--on-accent); }

/* Wide screens: the same links sit inline in the top bar. */
@media (min-width: 760px) {
  body { padding-bottom: 48px; }
  .tabbar {
    position: static;
    height: auto;
    padding: 0;
    background: none;
    border: 0;
    gap: 2px;
  }
  .tab {
    flex: 0 0 auto;
    flex-direction: row;
    gap: 7px;
    padding: 7px 11px;
    border-radius: var(--radius-sm);
    font-size: 0.92rem;
  }
  .tab:hover { background: var(--surface-2); }
  .tab.active { background: var(--surface-2); }
  .tab.primary { order: 10; margin-left: 8px; background: var(--accent); color: var(--on-accent); padding: 7px 13px 7px 9px; }
  .tab.primary:hover, .tab.primary.active { background: var(--accent-hover); color: var(--on-accent); }
  .tab.primary .icon { width: auto; height: auto; background: none; }
}

.dot {
  position: absolute;
  top: -3px;
  right: -5px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2px var(--surface);
}
@media (min-width: 760px) { .dot { box-shadow: 0 0 0 2px var(--bg); } }

main {
  max-width: 920px;
  margin: 0 auto;
  padding: 20px 16px;
}
@media (min-width: 760px) { main { padding-top: 32px; } }

/* ---------- page structure ---------- */

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.page-head h1 { margin: 0; }
.eyebrow {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 4px;
}
.back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.875rem;
  color: var(--muted);
  margin-bottom: 6px;
}
.back:hover { color: var(--text); text-decoration: none; }

.section { margin-top: 32px; }
.section > h2 {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 12px;
}
.section-sub { margin: -6px 0 12px; }
.count-pill {
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--muted);
}

/* ---------- surfaces ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card + .card { margin-top: 10px; }
.stack > * + * { margin-top: 10px; }

/* A row of numbers in one bordered strip (instead of a grid of cards). */
.grid-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;                       /* the 1px gaps show the border colour */
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.grid-stats > * { background: var(--surface); padding: 14px 16px; min-width: 0; }
.grid-stats.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (min-width: 640px) {
  .grid-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .grid-stats.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.stat .value {
  font-family: var(--mono);
  font-size: 1.6rem;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.03em;
  display: flex;
  align-items: center;
  gap: 6px;
}
.stat .value .i { color: var(--accent); }
.stat .value.accent { color: var(--accent); }
.stat .label { color: var(--muted); font-size: 0.8rem; margin-top: 6px; }
.kv .k { color: var(--muted); font-size: 0.8rem; }
.kv .v { font-weight: 500; margin-top: 2px; }

/* Lists of problems: one bordered box, rows divided by hairlines. */
.rows {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.rows > .problem-card {
  border: 0;
  border-radius: 0;
  margin: 0;
  background: none;
}
.rows > .problem-card + .problem-card { border-top: 1px solid var(--border); }

.problem-card {
  display: block;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  transition: background 0.15s, opacity 0.25s, transform 0.25s;
}
.problem-card + .problem-card { margin-top: 10px; }
.rows > .problem-card:hover { background: color-mix(in srgb, var(--surface-2) 45%, transparent); }
.problem-card .title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.problem-card .title { font-weight: 500; overflow-wrap: anywhere; }
.problem-card .title a { color: var(--text); }
.problem-card .title .i { color: var(--accent); margin-right: 4px; }
.meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.84rem;
}
.problem-card.leaving { opacity: 0; transform: translateX(16px); }

/* ---------- tags ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.78rem;
  font-weight: 500;
  white-space: nowrap;
  line-height: 1.6;
}
/* Difficulty: coloured text with a small square, no pill. */
.diff-Easy, .diff-Medium, .diff-Hard { flex: 0 0 auto; }
.diff-Easy::before, .diff-Medium::before, .diff-Hard::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 2px;
  background: currentColor;
}
.diff-Easy { color: var(--easy); }
.diff-Medium { color: var(--medium); }
.diff-Hard { color: var(--hard); }
.badge.pattern {
  padding: 0 7px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 400;
}
.badge.due { padding: 0 7px; border-radius: 4px; background: var(--accent-soft); color: var(--accent); }
.badge.shared { padding: 0 7px; border-radius: 4px; background: var(--accent-soft); color: var(--accent); }
a.badge:hover { text-decoration: none; filter: brightness(0.97); }
.tag-quiet { padding: 0 7px; border-radius: 4px; border: 1px solid var(--border); color: var(--muted); font-size: 0.75rem; font-weight: 400; }

/* Confidence: five small bars, like a signal meter. */
.conf { display: inline-flex; align-items: flex-end; gap: 2px; height: 12px; vertical-align: -1px; }
.conf i { width: 4px; border-radius: 1px; background: var(--border-strong); }
.conf i:nth-child(1) { height: 5px; }
.conf i:nth-child(2) { height: 7px; }
.conf i:nth-child(3) { height: 9px; }
.conf i:nth-child(4) { height: 11px; }
.conf i:nth-child(5) { height: 12px; }
.conf.c1 i.on, .conf.c2 i.on { background: var(--bad); }
.conf.c3 i.on { background: var(--warn); }
.conf.c4 i.on, .conf.c5 i.on { background: var(--good); }

.good-text { color: var(--good); display: inline-flex; align-items: center; gap: 4px; }

/* ---------- rating (1-5) ---------- */

.rate {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  margin-top: 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.rate button {
  padding: 9px 0;
  border: 0;
  border-radius: 0;
  background: var(--surface);
  font-family: var(--mono);
  font-weight: 600;
  color: var(--text);
}
.rate button + button { border-left: 1px solid var(--border); }
.rate button:hover:not(:disabled) { color: var(--on-accent); background: var(--accent); }
.rate-hint { display: flex; justify-content: space-between; font-size: 0.72rem; color: var(--faint); margin-top: 5px; }

/* ---------- forms ---------- */

label { display: block; font-size: 0.85rem; font-weight: 500; color: var(--text); margin-bottom: 6px; }
label .muted { font-weight: 400; }
.field { margin-bottom: 18px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hint { color: var(--muted); font-size: 0.8rem; margin-top: 6px; }

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
textarea { min-height: 120px; resize: vertical; line-height: 1.55; }
input[type="checkbox"] { width: auto; }
code, .code, textarea.mono { font-family: var(--mono); }

.checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 400;
  font-size: 0.95rem;
  cursor: pointer;
}
.checkbox input { width: 18px; height: 18px; accent-color: var(--accent); }

/* Segmented control: joined buttons, one pressed. */
.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.segmented button {
  border: 0;
  border-radius: 0;
  background: var(--surface);
  font-weight: 500;
}
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button:hover { background: var(--surface-2); }
.segmented button[aria-pressed="true"] { background: var(--text); color: var(--bg); }
.segmented.mono button { font-family: var(--mono); }

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 15px;
  font: inherit;
  font-weight: 500;
  font-size: 0.92rem;
  line-height: 1.3;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  touch-action: manipulation;
}
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--bad); }
.btn-danger:hover { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 8%, transparent); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { padding: 5px 10px; font-size: 0.84rem; }
.btn-block { width: 100%; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

.filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}
.filters .search { grid-column: 1 / -1; position: relative; }
.filters .search .i { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.filters .search input { padding-left: 36px; }
@media (min-width: 760px) {
  .filters { grid-template-columns: 2fr 1fr 1fr 1fr 1fr; }
  .filters .search { grid-column: auto; }
}
.filters select, .filters input { padding: 9px 10px; font-size: 0.9rem; }

.form-error {
  background: color-mix(in srgb, var(--bad) 9%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--bad) 35%, transparent);
  color: var(--bad);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  font-size: 0.9rem;
}

/* ---------- notes ---------- */

.notes {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 0.95rem;
  line-height: 1.6;
}

/* ---------- states: loading / empty / error ---------- */

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 48px 0;
  color: var(--muted);
}
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid color-mix(in srgb, currentColor 25%, transparent);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  height: 64px;
  border-radius: var(--radius);
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
.skeleton + .skeleton { margin-top: 10px; }
@keyframes shimmer { to { background-position: -200% 0; } }

.empty {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 22px 20px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--muted);
}
.empty .empty-icon { color: var(--faint); margin-bottom: 10px; }
.empty h3 { color: var(--text); margin-bottom: 4px; font-weight: 500; }
.empty p { margin: 0 0 12px; max-width: 48ch; font-size: 0.92rem; }
.empty p:last-child { margin-bottom: 0; }
.error-state { border-color: color-mix(in srgb, var(--bad) 45%, transparent); }
.error-state .empty-icon { color: var(--bad); }

/* ---------- toast ---------- */

.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px);
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 400px);
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  background: var(--toast-bg);
  color: var(--toast-text);
  box-shadow: var(--shadow);
  font-size: 0.92rem;
  animation: toast-in 0.2s ease-out;
  pointer-events: auto;
}
.toast::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--faint); flex: 0 0 auto; }
.toast.good::before { background: var(--good); }
.toast.bad::before { background: var(--bad); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@media (min-width: 760px) { .toasts { bottom: 24px; } }

/* ---------- stats: bars & heatmap ---------- */

.bar-row { display: grid; grid-template-columns: minmax(0, 10rem) 1fr auto; gap: 12px; align-items: center; font-size: 0.9rem; }
.bar-row + .bar-row { margin-top: 10px; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .muted { font-family: var(--mono); font-size: 0.8rem; }
.bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: inherit; background: var(--text); opacity: 0.8; }
.bar.Easy > span { background: var(--easy); opacity: 1; }
.bar.Medium > span { background: var(--medium); opacity: 1; }
.bar.Hard > span { background: var(--hard); opacity: 1; }

.heatmap-wrap { overflow-x: auto; padding-bottom: 4px; }
.heatmap {
  display: grid;
  grid-template-rows: repeat(7, 11px);
  grid-auto-flow: column;
  grid-auto-columns: 11px;
  gap: 3px;
  width: max-content;
}
.heatmap .d, .heatmap-legend .d { border-radius: 2px; background: var(--heat-0); }
.heatmap .d.pad { background: transparent; }
.heatmap .l1, .heatmap-legend .l1 { background: var(--heat-1); }
.heatmap .l2, .heatmap-legend .l2 { background: var(--heat-2); }
.heatmap .l3, .heatmap-legend .l3 { background: var(--heat-3); }
.heatmap .l4, .heatmap-legend .l4 { background: var(--heat-4); }
.heatmap-legend { display: flex; align-items: center; gap: 4px; justify-content: flex-end; margin-top: 10px; font-size: 0.75rem; color: var(--muted); }
.heatmap-legend .d { width: 11px; height: 11px; }
.heatmap-legend .total { margin-right: auto; font-family: var(--mono); }

.callout { border-left: 3px solid var(--accent); }

/* ---------- auth pages ---------- */

.auth-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.auth-card { width: min(100%, 380px); }
.auth-card .brand { font-size: 1.15rem; margin-bottom: 28px; }
.auth-card h1 { font-size: 1.45rem; margin-bottom: 4px; }
.auth-card #form-sub { margin: 0 0 22px; }
.auth-card form.card { padding: 22px; }
.auth-switch { margin-top: 18px; color: var(--muted); font-size: 0.9rem; }
.auth-foot { margin-top: 36px; color: var(--faint); font-size: 0.8rem; }
.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  color: var(--faint);
  font-size: 0.8rem;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.btn-google { width: 100%; gap: 10px; }
.btn-google svg { width: 18px; height: 18px; }

/* ---------- people / social ---------- */

.person { display: flex; align-items: center; gap: 12px; }
/* Colour comes from --h (a hue picked from the username), tuned per theme. */
.avatar {
  --h: 30;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 0.9rem;
  font-weight: 600;
  text-transform: uppercase;
  background: hsl(var(--h) 45% 88%);
  color: hsl(var(--h) 55% 28%);
}
.avatar.sm { width: 26px; height: 26px; font-size: 0.75rem; border-radius: 6px; }
.avatar.lg { width: 48px; height: 48px; font-size: 1.2rem; border-radius: 11px; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .avatar { background: hsl(var(--h) 28% 22%); color: hsl(var(--h) 65% 78%); }
}
:root[data-theme="dark"] .avatar { background: hsl(var(--h) 28% 22%); color: hsl(var(--h) 65% 78%); }
.person .grow { flex: 1; min-width: 0; }
.person .name { font-weight: 500; overflow-wrap: anywhere; }

.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
}
.list-row:last-child { border-bottom: none; }
.list-row:first-child { padding-top: 0; }
.list-row:last-child { padding-bottom: 0; }
.list-row .grow { flex: 1; min-width: 0; }

.rank { width: 1.6rem; text-align: right; font-family: var(--mono); color: var(--faint); }
.rank.r1 { color: var(--accent); font-weight: 600; }
.me-row { background: var(--accent-soft); margin: 0 -10px; padding-left: 10px; padding-right: 10px; border-radius: var(--radius-sm); border-bottom-color: transparent; }
.streak { display: inline-flex; align-items: center; gap: 3px; font-family: var(--mono); font-size: 0.82rem; color: var(--muted); }
.streak .i { color: var(--accent); }
.score { font-family: var(--mono); font-weight: 600; min-width: 2.5rem; text-align: right; }

.feed-item { display: flex; gap: 12px; }
.feed-item + .feed-item { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.feed-item .body { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.feed-item .who { color: var(--text); font-weight: 600; }
.feed-item .when { font-family: var(--mono); font-size: 0.78rem; color: var(--faint); margin-left: auto; white-space: nowrap; }
.feed-item .line { display: flex; gap: 8px; align-items: baseline; }

/* Sub-tabs (Feed / Friends / Groups): underlined text, not pills. */
.tabs-inline {
  display: inline-flex;
  gap: 18px;
  border-bottom: 1px solid var(--border);
}
.tabs-inline button {
  padding: 6px 0 8px;
  margin-bottom: -1px;
  font-size: 0.92rem;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--muted);
}
.tabs-inline button:hover { background: none; color: var(--text); }
.tabs-inline button[aria-pressed="true"] { color: var(--text); border-bottom-color: var(--accent); }
.page-head .tabs-inline { width: 100%; }

.toggle-sm { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.toggle-sm button { padding: 3px 10px; font-size: 0.8rem; border: 0; border-radius: 0; background: var(--surface); }
.toggle-sm button + button { border-left: 1px solid var(--border); }
.toggle-sm button[aria-pressed="true"] { background: var(--text); color: var(--bg); }

.inline-form { display: flex; gap: 8px; }
.inline-form input, .inline-form select { flex: 1; min-width: 0; }

.menu-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.menu-link:first-child { padding-top: 0; }
.menu-link:last-child { border-bottom: none; padding-bottom: 0; }
.menu-link:hover { text-decoration: none; }
.menu-link:hover strong { color: var(--accent); }
.menu-link .i { color: var(--faint); }

code, .code {
  font-size: 0.88em;
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 4px;
}

details summary { cursor: pointer; }

@media (max-width: 480px) { .hide-sm { display: none; } }
.filters label.search { margin: 0; font-weight: 400; }
.segmented button .i { margin-right: 2px; }

/* Desktop: the 1-5 rating sits to the right of the problem, not under it. */
@media (min-width: 760px) {
  .problem-card.has-rate {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 250px;
    grid-template-areas: "title rate" "meta hint";
    column-gap: 24px;
    align-items: center;
  }
  .problem-card.has-rate .title-row { grid-area: title; }
  .problem-card.has-rate .meta { grid-area: meta; }
  .problem-card.has-rate .rate { grid-area: rate; margin-top: 0; }
  .problem-card.has-rate .rate button { padding: 6px 0; }
  .problem-card.has-rate .rate-hint { grid-area: hint; margin-top: 0; }
}
.feed-item .line a:not(.who) { color: var(--text); font-weight: 500; }
.feed-item .line a:not(.who):hover { color: var(--accent); }
.feed-item .when { font-family: var(--font); }

/* ---------- admin: charts & tables ---------- */

.stat .delta { color: var(--good); font-family: var(--mono); font-size: 0.75rem; white-space: nowrap; }

.chart-grid { display: grid; gap: 10px; position: relative; }
@media (min-width: 760px) { .chart-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.chart-grid .card + .card { margin-top: 0; }
.chart { margin: 0; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 12px; }
.chart-title { font-weight: 500; font-size: 0.92rem; }
.chart-total { color: var(--muted); font-family: var(--mono); font-size: 0.75rem; white-space: nowrap; }
.chart-plot { position: relative; height: 110px; border-bottom: 1px solid var(--border-strong); }
.chart-max { position: absolute; top: -2px; left: 0; font-family: var(--mono); font-size: 0.68rem; color: var(--faint); }
/* A faint guide line at the max value, so bar heights have a reference. */
.chart-plot::before { content: ""; position: absolute; left: 18px; right: 0; top: 0; border-top: 1px dashed var(--border); }
.chart-cols { position: absolute; inset: 0 0 0 18px; display: flex; align-items: stretch; gap: 2px; }
.chart-cols .col { flex: 1; display: flex; align-items: flex-end; min-width: 0; cursor: default; outline-offset: 0; }
.chart-cols .col:hover .bar-v, .chart-cols .col:focus .bar-v { background: var(--accent-hover); }
.chart-cols .col:hover .bar-v.zero, .chart-cols .col:focus .bar-v.zero { background: var(--border-strong); }
.bar-v { width: 100%; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 0; }
.bar-v.zero { height: 2px !important; background: var(--border); border-radius: 1px; }
.chart-x { display: flex; justify-content: space-between; margin: 6px 0 0 18px; font-family: var(--mono); font-size: 0.68rem; color: var(--faint); }
.chart-tip {
  position: absolute;
  transform: translate(-50%, -100%);
  padding: 5px 9px;
  border-radius: var(--radius-sm);
  background: var(--toast-bg);
  color: var(--toast-text);
  font-size: 0.78rem;
  white-space: nowrap;
  pointer-events: none;
  z-index: 5;
  box-shadow: var(--shadow);
}

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table.data { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
table.data th, table.data td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data th { font-weight: 500; color: var(--muted); font-size: 0.78rem; background: color-mix(in srgb, var(--surface-2) 50%, transparent); white-space: nowrap; }
table.data .n { text-align: right; font-family: var(--mono); }
table.data .nowrap { white-space: nowrap; }
table.data .person { gap: 10px; min-width: 180px; }
table.data tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 40%, transparent); }
table.data th.n { font-family: var(--font); }

/* ---------- top bar: streak + solved ---------- */

.topstats {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
}
.topstats:hover { text-decoration: none; border-color: var(--border-strong); }
.topstat {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px 2px 6px;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 0.82rem;
  font-weight: 600;
}
.topstat .i { color: var(--good); }
.topstat.lit { background: var(--accent-soft); color: var(--accent); }
.topstat.lit .i { color: var(--accent); }
/* Streak not yet extended today: a grey flame nudges you to keep it going. */
.topstat.unlit { color: var(--muted); }
.topstat.unlit .i { color: var(--faint); }
