.brand-mark {
  display: block;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--text) 12%, transparent);
}

.brand-name {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.015em;
  font-variation-settings: "opsz" 48;
}

.brand-dot {
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-left: 2px;
  border-radius: 50%;
  background: var(--brand, #e4572e);
}

.auth-brand .brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 11px;
}

.auth-brand .brand-name {
  font-size: 24px;
}

/* ===== Fonts (self-hosted, SIL OFL — see fonts/*-OFL.txt) ===== */
@font-face {
  font-family: "Inter";
  src: url("../fonts/inter-latin-wght.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Fraunces";
  src: url("../fonts/fraunces-latin-wght-normal.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Fraunces";
  src: url("../fonts/fraunces-latin-wght-italic.woff2") format("woff2");
  font-weight: 100 900;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: "JetBrains Mono";
  src: url("../fonts/jetbrains-mono-latin-wght.woff2") format("woff2");
  font-weight: 100 800;
  font-style: normal;
  font-display: swap;
}

/* ===== Theme ===== */
:root {
  /* Default theme "Ink": editorial, monochrome; vermilion is the brand dot only. */
  --bg: #111216;
  --surface: #18191e;
  --surface-hover: #202128;
  --border: #2b2c34;
  --grid: #222329;
  --text: #f2efe9;
  --text-muted: #9b978f;
  --accent: #f2efe9;
  --accent-hover: #ffffff;
  --accent-soft: rgba(242, 239, 233, 0.08);
  --brand: #e4572e;

  --mastery-0: #ef4444;
  --mastery-1: #f97316;
  --mastery-2: #eab308;
  --mastery-3: #22c55e;

  --up: #22c55e;
  --down: #ef4444;

  --accent-2: #38bdf8; /* secondary glow */
  --them: #2dd4bf; /* duo partner color */
  --on-accent: #14161c; /* text on accent buttons */
  --on-mastery: rgba(15, 17, 21, 0.88); /* glyphs on colored dots */
  --shadow: #000000;
  color-scheme: dark;

  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --fs-small: 13px;
  --fs-text: 15px;
  --fs-title: 20px;
  --fs-key: 40px;
  --fs-timer: 96px;

  --radius: 10px;
  --gap: 16px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}


/* ===== Themes (Settings → Theme). Only variables change; everything else follows. ===== */
:root[data-theme="violet"] {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-hover: #1f232c;
  --border: #2a2f3a;
  --grid: #222731;
  --text: #e6e8ee;
  --text-muted: #8b93a7;
  --accent: #8b5cf6;
  --accent-hover: #7c4ee4;
  --accent-soft: rgba(139, 92, 246, 0.14);
  --on-accent: #ffffff;
}

:root[data-theme="midnight"] {
  --bg: #0b1020;
  --surface: #121a2e;
  --surface-hover: #1a2440;
  --border: #253255;
  --grid: #1b2643;
  --text: #e4e9f7;
  --text-muted: #8a97b8;
  --accent: #60a5fa;
  --accent-hover: #3b82f6;
  --accent-soft: rgba(96, 165, 250, 0.15);
  --accent-2: #a78bfa;
  --on-accent: #0b1020;
}

:root[data-theme="forest"] {
  --bg: #0d1411;
  --surface: #141e19;
  --surface-hover: #1b2822;
  --border: #26372e;
  --grid: #1c2a23;
  --text: #e3ece6;
  --text-muted: #8aa093;
  --accent: #34d399;
  --accent-hover: #10b981;
  --accent-soft: rgba(52, 211, 153, 0.14);
  --accent-2: #a3e635;
  --them: #f0abfc;
  --on-accent: #0d1411;
}

:root[data-theme="rose"] {
  --bg: #141015;
  --surface: #1d171f;
  --surface-hover: #261e29;
  --border: #382c3c;
  --grid: #2a212d;
  --text: #f1e7ef;
  --text-muted: #a693a3;
  --accent: #f472b6;
  --accent-hover: #ec4899;
  --accent-soft: rgba(244, 114, 182, 0.14);
  --accent-2: #fb923c;
  --them: #67e8f9;
  --on-accent: #1a0f17;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-hover: #f0f1f5;
  --border: #e1e4ea;
  --grid: #eceef2;
  --text: #171a21;
  --text-muted: #5f6878;
  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --accent-soft: rgba(124, 58, 237, 0.1);
  --accent-2: #0ea5e9;
  --mastery-0: #dc2626;
  --mastery-1: #ea580c;
  --mastery-2: #ca8a04;
  --mastery-3: #16a34a;
  --up: #16a34a;
  --down: #dc2626;
  --them: #0d9488;
  --on-accent: #ffffff;
  --on-mastery: rgba(255, 255, 255, 0.95);
  --shadow: #1e2433;
}

:root[data-theme="paper"] {
  color-scheme: light;
  --bg: #f4efe6;
  --surface: #fbf8f2;
  --surface-hover: #f1eadf;
  --border: #e2d8c8;
  --grid: #ebe3d6;
  --text: #2b2520;
  --text-muted: #7a6e60;
  --accent: #b45309;
  --accent-hover: #92400e;
  --accent-soft: rgba(180, 83, 9, 0.1);
  --accent-2: #0f766e;
  --mastery-0: #c2410c;
  --mastery-1: #d97706;
  --mastery-2: #a16207;
  --mastery-3: #15803d;
  --up: #15803d;
  --down: #c2410c;
  --them: #0f766e;
  --on-accent: #fffaf2;
  --on-mastery: rgba(255, 255, 255, 0.95);
  --shadow: #3b2f22;
}

/* ===== Base ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--fs-text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv11", "ss01";
  letter-spacing: -0.006em;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

h1 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.02em;
  font-size: 30px;
  margin: 0 0 var(--gap);
}

h2 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}

h3 {
  font-size: 14px;
  font-weight: 600;
  margin: 20px 0 8px;
  color: var(--text);
}

p {
  margin: 0 0 8px;
}

button {
  font: inherit;
  color: inherit;
}

/* Numbers: Inter with tabular figures (aligned, but not "terminal" looking). */
.mono {
  font-family: var(--font-ui);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum", "cv11";
}

.muted {
  color: var(--text-muted);
}

.small {
  font-size: var(--fs-small);
}

[hidden] {
  display: none !important;
}

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

::selection {
  background: var(--accent-soft);
}

.link {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-align: left;
}

.link:hover {
  text-decoration: underline;
}

/* ===== Top bar ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 32px;
  padding: 12px 32px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.01em;
}

.tabs {
  display: flex;
  gap: 4px;
}

.tab {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
}

.tab:hover {
  color: var(--text);
  background: var(--surface);
}

.tab[aria-selected="true"] {
  color: var(--text);
  background: var(--surface-hover);
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 20px;
}

.streak {
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: default;
}

.streak-off .flame {
  filter: grayscale(1);
  opacity: 0.5;
}

.flame {
  display: inline-block;
}

.streak.pulse .flame {
  animation: flame-pulse 600ms var(--ease);
}

@keyframes flame-pulse {
  40% {
    transform: scale(1.6);
  }
}

.goal {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: var(--fs-small);
}

.goal-bar {
  width: 64px;
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.goal-fill {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 400ms var(--ease);
}

.goal-done .goal-fill {
  background: var(--mastery-3);
}

.goal-done {
  color: var(--mastery-3);
}

#btn-pomodoro {
  min-width: 128px;
  font-variant-numeric: tabular-nums;
}

#btn-pomodoro.running {
  background: var(--surface-hover);
  border-color: var(--accent);
  color: var(--text);
}

/* ===== Layout ===== */
main {
  max-width: 1360px;
  margin: 0 auto;
  padding: 24px 32px 64px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: var(--gap);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.placeholder {
  color: var(--text-muted);
  text-align: center;
  padding: 48px;
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.split {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: var(--gap);
  align-items: start;
}

.split.split-right {
  grid-template-columns: 1fr 380px;
}

.split.split-right:has(#task-detail[hidden]) {
  grid-template-columns: 1fr;
}

.side {
  position: sticky;
  top: 80px;
}

/* ===== Controls ===== */
.btn {
  font-size: 14px;
  color: var(--text);
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 150ms, border-color 150ms;
}

.btn:hover {
  border-color: var(--text-muted);
}

.btn-small {
  padding: 4px 10px;
  font-size: var(--fs-small);
}

.btn-big {
  padding: 12px 28px;
  font-size: 16px;
}

.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-ghost {
  background: none;
  border-color: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover {
  color: var(--text);
  border-color: var(--border);
}

.btn-danger {
  color: var(--mastery-0);
}

.btn-danger:hover {
  border-color: var(--mastery-0);
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  width: 26px;
  height: 26px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
}

.icon-btn:hover:not(:disabled) {
  background: var(--surface-hover);
  color: var(--text);
}

.icon-btn:disabled {
  opacity: 0.25;
  cursor: default;
}

.icon-btn.danger:hover {
  color: var(--mastery-0);
}

.icon-btn.has-notes {
  color: var(--accent);
}

select,
textarea,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"] {
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
}

input[type="date"] {
  color-scheme: inherit;
}

input[type="number"] {
  width: 80px;
}

textarea {
  resize: vertical;
  width: 100%;
}

select:focus,
textarea:focus,
input:focus {
  outline: none;
  border-color: var(--accent);
}

input.inline-input,
textarea.inline-input {
  background: transparent;
  border-color: transparent;
  width: 100%;
  padding: 4px 6px;
}

input.inline-input:hover,
textarea.inline-input:hover {
  border-color: var(--border);
}

input.inline-input:focus,
textarea.inline-input:focus {
  background: var(--bg);
  border-color: var(--accent);
}

.card-head h3 {
  margin: 0;
}

.title-input {
  font-size: 18px;
  font-weight: 600;
  resize: none;
}

.color-input {
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  flex-shrink: 0;
}

.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
}

.field > span:first-child {
  color: var(--text-muted);
  font-size: 14px;
}

.field.compact {
  padding: 0;
  justify-content: flex-start;
}

.check {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
}

.chip input {
  accent-color: var(--accent);
}

.seg {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
}

.seg-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: var(--fs-small);
  padding: 3px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.seg-btn[aria-pressed="true"] {
  background: var(--surface-hover);
  color: var(--text);
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 14px;
  margin-right: 12px;
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-ui {
  width: 32px;
  height: 18px;
  border-radius: 999px;
  background: var(--border);
  position: relative;
  transition: background 150ms;
}

.switch-ui::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text);
  transition: transform 150ms var(--ease);
}

.switch input:checked + .switch-ui {
  background: var(--accent);
}

.switch input:checked + .switch-ui::after {
  transform: translateX(14px);
}

.switch input:focus-visible + .switch-ui {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ===== Badges, dots, bars ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--surface-hover);
  border: 1px solid var(--border);
  color: var(--text-muted);
  white-space: nowrap;
}

.badge-danger {
  color: var(--mastery-0);
  border-color: color-mix(in srgb, var(--mastery-0) 45%, transparent);
}

.badge-ok {
  color: var(--mastery-3);
}

.due-overdue {
  color: var(--mastery-0);
  border-color: color-mix(in srgb, var(--mastery-0) 45%, transparent);
}

.due-today {
  color: var(--mastery-1);
  border-color: color-mix(in srgb, var(--mastery-1) 45%, transparent);
}

.due-soon {
  color: var(--mastery-2);
}

.cdot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Mastery dot: color + glyph (never color alone). */
.mdot,
.mdot-static {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  padding: 0;
  font-size: 11px;
  font-weight: 700;
  color: var(--on-mastery);
  flex-shrink: 0;
  line-height: 1;
}

.mdot {
  cursor: pointer;
  -webkit-touch-callout: none;
  user-select: none;
  touch-action: manipulation;
  transition: transform 120ms var(--ease), box-shadow 120ms;
}

.mdot:hover {
  transform: scale(1.15);
  box-shadow: 0 0 0 3px var(--surface-hover);
}

.mdot.sm {
  width: 16px;
  height: 16px;
  font-size: 9px;
}

.m0 {
  background: var(--mastery-0);
}
.m1 {
  background: var(--mastery-1);
}
.m2 {
  background: var(--mastery-2);
}
.m3 {
  background: var(--mastery-3);
}
.m0-text {
  color: var(--mastery-0);
}
.m1-text {
  color: var(--mastery-1);
}
.m2-text {
  color: var(--mastery-2);
}
.m3-text {
  color: var(--mastery-3);
}

.pbar {
  display: inline-block;
  height: 6px;
  flex: 1;
  min-width: 60px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.pbar-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  transition: width 600ms var(--ease);
}

/* ===== Dashboard ===== */
.countdowns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: var(--gap);
}

.countdown {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 14px;
  font-size: 14px;
  cursor: pointer;
}

.countdown:hover {
  border-color: var(--text-muted);
}

.countdown-hot {
  border-color: color-mix(in srgb, var(--mastery-0) 55%, transparent);
}

.countdown-hot .mono {
  color: var(--mastery-0);
}

.kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap);
}

.kpi {
  padding: 18px 20px;
}

.kpi-label {
  font-size: var(--fs-small);
  color: var(--text-muted);
}

.kpi-value {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 34px;
  font-weight: 600;
  letter-spacing: -0.035em;
  line-height: 1.15;
  margin: 6px 0 4px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.kpi-icon {
  width: 26px;
  height: 26px;
}

.kpi-flame {
  color: var(--mastery-1);
  fill: currentColor;
  fill-opacity: 0.25;
}

.kpi-flame.off {
  color: var(--text-muted);
}

.kpi-sub {
  font-size: var(--fs-small);
}

.delta {
  flex-wrap: wrap;
  white-space: nowrap;
  column-gap: 6px;
  row-gap: 0;
}

.delta.up {
  color: var(--up);
}

.delta.down {
  color: var(--down);
}

.dash-grid {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  grid-template-rows: auto auto;
  gap: 0 var(--gap);
}

.matrix-card {
  grid-row: span 2;
  display: flex;
  flex-direction: column;
}

.matrix-card #dash-matrix {
  flex: 1;
  display: flex;
}

.dash-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 var(--gap);
}

.chart-box {
  position: relative;
  height: 220px;
}

.chart-box-sm {
  height: 170px;
}

.chart-box.empty canvas {
  opacity: 0.25;
}

.chart-box.empty::after {
  content: attr(data-empty);
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 0 32px;
  color: var(--text-muted);
  font-size: 14px;
}

.heatmap {
  display: grid;
  grid-template-rows: repeat(7, 14px);
  grid-auto-flow: column;
  grid-auto-columns: 14px;
  gap: 4px;
  margin: 8px 0 12px;
}

.hm-cell {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
}

.hm-0 {
  background: var(--surface-hover);
}
.hm-1 {
  background: color-mix(in srgb, var(--accent) 35%, transparent);
}
.hm-2 {
  background: color-mix(in srgb, var(--accent) 70%, transparent);
}
.hm-3 {
  background: var(--accent);
}
.hm-future {
  background: transparent;
  border: 1px dashed var(--grid);
}

.hm-legend {
  display: flex;
  align-items: center;
  gap: 4px;
}

.hm-legend .hm-cell {
  width: 11px;
  height: 11px;
}

.hm-hint {
  margin-left: auto;
}

.course-rows {
  display: flex;
  flex-direction: column;
}

.course-row {
  display: grid;
  grid-template-columns: 200px 80px 220px 1fr;
  align-items: center;
  gap: 16px;
  padding: 10px 0;
  border-top: 1px solid var(--grid);
}

.course-row:first-child {
  border-top: none;
}

.course-name {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.course-progress {
  display: flex;
  align-items: center;
  gap: 10px;
}

.course-progress .mono {
  width: 44px;
  text-align: right;
}

.dots {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

/* ===== Eisenhower matrix ===== */
.matrix {
  display: grid;
  grid-template-columns: 22px 1fr;
  grid-template-rows: auto 1fr;
  gap: 6px;
  width: 100%;
}

.matrix-axis {
  display: flex;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.matrix-axis span {
  flex: 1;
  text-align: center;
}

.matrix-axis.top {
  grid-column: 2;
}

.matrix-axis.side {
  grid-column: 1;
  grid-row: 2;
  flex-direction: column;
  gap: 8px;
}

.matrix-axis.side span {
  display: flex;
  align-items: center;
  justify-content: center;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}

.matrix-grid {
  grid-column: 2;
  grid-row: 2;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 8px;
  min-height: 420px;
}

.matrix.compact .matrix-grid {
  min-height: 0;
}

.quadrant {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  display: flex;
  flex-direction: column;
  min-height: 140px;
  min-width: 0;
  transition: border-color 120ms, background 120ms;
}

.quadrant.drop-target {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.q-do {
  border-top: 2px solid var(--mastery-0);
}
.q-plan {
  border-top: 2px solid var(--accent);
}
.q-delegate {
  border-top: 2px solid var(--mastery-2);
}
.q-later {
  border-top: 2px solid var(--text-muted);
}

.quadrant-head {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
}

.quadrant-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  max-height: 300px;
}

.matrix.compact .quadrant-body {
  max-height: 210px;
}

.quadrant-empty {
  padding: 8px 2px;
}

.mcard {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  cursor: grab;
  font-size: 14px;
}

.mcard:hover {
  background: var(--surface-hover);
}

.mcard.dragging {
  opacity: 0.4;
}

.mcard-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mcard-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}

.mcard-meta .small {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.auto-urgent {
  font-size: 12px;
  cursor: help;
}

/* ===== Lists (courses, chapters, tasks) ===== */
.list-item {
  display: flex;
  align-items: center;
  border-radius: 8px;
  margin: 2px -8px;
}

.list-item:hover {
  background: var(--surface-hover);
}

.list-item.selected {
  background: var(--surface-hover);
  box-shadow: inset 2px 0 0 var(--accent);
}

.list-main {
  flex: 1;
  background: none;
  border: none;
  text-align: left;
  padding: 8px;
  cursor: pointer;
  min-width: 0;
}

.list-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.list-title .badge {
  margin-left: auto;
}

.list-sub {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.reorder {
  display: flex;
  flex-direction: column;
  opacity: 0;
  padding-right: 4px;
}

.list-item:hover .reorder,
.list-item:focus-within .reorder {
  opacity: 1;
}

.reorder .icon-btn {
  height: 18px;
}

.add-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.add-row input,
.add-row textarea {
  flex: 1;
}

.add-chapters {
  resize: none;
  min-height: 36px;
}

.detail-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.detail-head .title-input {
  flex: 1;
}

.detail-progress {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
}

.count-pills {
  display: flex;
  gap: 10px;
  margin-left: 8px;
}

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

.count-pill .mdot-static {
  width: 16px;
  height: 16px;
  font-size: 9px;
}

.chapters {
  list-style: none;
  margin: 0;
  padding: 0;
}

.chapter {
  border-top: 1px solid var(--grid);
  padding: 6px 0;
}

.chapter:first-child {
  border-top: none;
}

.chapter-main {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chapter-main .inline-input {
  flex: 1;
}

.mastery-label {
  width: 110px;
  flex-shrink: 0;
}

.row-actions {
  display: flex;
  gap: 2px;
  opacity: 0.35;
  transition: opacity 120ms;
}

.chapter:hover .row-actions,
.chapter:focus-within .row-actions {
  opacity: 1;
}

.chapter-notes-preview {
  padding: 0 0 2px 6px;
  white-space: pre-wrap;
}

.notes {
  margin: 6px 0 4px;
  width: 100%;
}

.hint {
  margin-top: 12px;
}

.quick-add {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
}

.quick-add #quick-task {
  flex: 1;
  font-size: 15px;
  padding: 8px 12px;
}

.toolbar {
  margin-bottom: 12px;
}

.task-section {
  padding: 14px 18px;
}

.section-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.section-head h3 {
  margin: 0;
}

.task-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.task {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  margin: 0 -8px;
  border-radius: 8px;
  transition: opacity 300ms, background 120ms;
}

.task:hover {
  background: var(--surface-hover);
}

.task.selected {
  background: var(--surface-hover);
  box-shadow: inset 2px 0 0 var(--accent);
}

.task-title {
  flex: 1;
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  padding: 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.task-text {
  background-image: linear-gradient(currentColor, currentColor);
  background-repeat: no-repeat;
  background-position: 0 55%;
  background-size: 0 1px;
  transition: background-size 300ms var(--ease);
}

.task.done .task-text,
.task.completing .task-text {
  background-size: 100% 1px;
}

.task.done {
  opacity: 0.55;
}

.task.completing {
  opacity: 0.4;
}

.task-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.q-icon {
  font-size: 13px;
  cursor: help;
}

.done-section summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
}

.done-section[open] summary {
  margin-bottom: 8px;
}

#task-detail {
  position: sticky;
  top: 80px;
}

.detail-top {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
}

.detail-top .check {
  margin-top: 9px;
}

.detail .field select,
.detail .field input[type="date"] {
  width: 200px;
}

.detail .row {
  margin: 8px 0;
}

.subtasks {
  list-style: none;
  margin: 0 0 6px;
  padding: 0;
}

.subtask {
  display: flex;
  align-items: center;
  gap: 6px;
}

.subtask.done .inline-input {
  text-decoration: line-through;
  color: var(--text-muted);
}

.detail-foot {
  margin-top: 16px;
  justify-content: flex-end;
}

/* ===== Settings ===== */
.settings-grid {
  display: grid;
  grid-auto-flow: row dense;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--gap);
  align-items: start;
}

.settings-grid h2 {
  margin-bottom: 8px;
}

/* ===== Pomodoro overlay ===== */
.pomo {
  --pomo-color: var(--accent);
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: 50;
  background: radial-gradient(ellipse at center, color-mix(in srgb, var(--pomo-color) 8%, var(--bg)) 0%, var(--bg) 70%);
  display: grid;
  place-items: center;
  animation: fade-in 200ms var(--ease);
}

.pomo-close {
  position: absolute;
  top: 20px;
  right: 24px;
  font-size: 18px;
}

.pomo-setup,
.pomo-run {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}

.pomo-setup select {
  width: 320px;
  font-size: 15px;
  padding: 8px 12px;
}

.pomo-label {
  font-size: 18px;
  color: var(--text-muted);
}

.pomo-phase {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--pomo-color);
}

.pomo[data-phase="shortBreak"] .pomo-phase,
.pomo[data-phase="longBreak"] .pomo-phase {
  color: var(--mastery-3);
}

.pomo-time {
  font-family: var(--font-mono);
  font-size: 76px;
  font-weight: 300;
  letter-spacing: -0.04em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.pomo-cycles {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cycle-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--pomo-color);
}

.cycle-dot.filled {
  background: var(--pomo-color);
}

.pomo-actions {
  justify-content: center;
  margin-top: 16px;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

/* ===== Banners, toasts, confetti ===== */
.banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 32px;
  font-size: var(--fs-small);
}

.banner-warn {
  background: color-mix(in srgb, var(--mastery-1) 12%, transparent);
  color: var(--mastery-1);
  border-bottom: 1px solid color-mix(in srgb, var(--mastery-1) 30%, transparent);
}

.banner-info {
  background: var(--accent-soft);
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
}

.toasts {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
}

.toast {
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  box-shadow: 0 8px 24px color-mix(in srgb, var(--shadow) 40%, transparent);
  animation: toast-in 250ms var(--ease);
}

.toast.leaving {
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 200ms, transform 200ms;
}

.toast-error {
  border-color: var(--mastery-0);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

.confetti {
  position: fixed;
  width: 7px;
  height: 7px;
  border-radius: 2px;
  pointer-events: none;
  z-index: 200;
}

/* ===== Icons ===== */
.icon {
  width: 1.1em;
  height: 1.1em;
  flex-shrink: 0;
  vertical-align: -0.18em;
}

.with-icon,
#account-sync,
.btn,
.badge,
.link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn {
  justify-content: center;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
}

.icon-btn .icon {
  width: 16px;
  height: 16px;
}

.badge .icon {
  width: 13px;
  height: 13px;
}

.brand,
.auth-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
}

.brand-mark .icon {
  width: 17px;
  height: 17px;
}

.flame {
  color: var(--mastery-1);
  display: inline-grid;
  place-items: center;
}

.flame .icon {
  width: 18px;
  height: 18px;
  fill: currentColor;
  fill-opacity: 0.25;
}

.streak-off .flame {
  color: var(--text-muted);
}

.kpi-streak {
  gap: 10px;
}

.kpi-streak .icon {
  color: var(--mastery-1);
  fill: currentColor;
  fill-opacity: 0.25;
}

.kpi-streak.off .icon {
  color: var(--text-muted);
}

.ok-icon {
  color: var(--mastery-3);
  display: inline-grid;
}

.q-do-icon {
  color: var(--mastery-0);
}
.q-plan-icon {
  color: var(--accent);
}
.q-delegate-icon {
  color: var(--mastery-2);
}
.q-later-icon {
  color: var(--text-muted);
}

.q-icon,
.auto-urgent {
  display: inline-grid;
  place-items: center;
}

.auto-urgent {
  color: var(--mastery-1);
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toast-icon {
  width: 18px;
  height: 18px;
  color: var(--accent);
}

.toast-icon-flame {
  color: var(--mastery-1);
  fill: currentColor;
  fill-opacity: 0.25;
}

.toast-icon-check {
  color: var(--mastery-3);
}

.toast-icon-sparkles {
  color: var(--mastery-2);
}

#btn-pomodoro .icon {
  width: 15px;
  height: 15px;
}

.mdot .icon,
.mdot-static .icon {
  width: 70%;
  height: 70%;
  stroke-width: 3;
}

.mdot-static {
  color: var(--on-mastery);
}

/* Direct mastery picker: 4 states, the chosen one is filled. */
.mpicker {
  display: inline-flex;
  gap: 4px;
  padding: 3px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.mopt {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 50%;
  border: 1.5px solid transparent;
  background: none;
  cursor: pointer;
  color: var(--text-muted);
  opacity: 0.55;
  transition: opacity 120ms, transform 120ms var(--ease), background 120ms;
}

.mopt .icon {
  width: 15px;
  height: 15px;
  stroke-width: 2.6;
}

.mopt:hover {
  opacity: 1;
  transform: scale(1.08);
}

.m0-opt:hover { color: var(--mastery-0); border-color: var(--mastery-0); }
.m1-opt:hover { color: var(--mastery-1); border-color: var(--mastery-1); }
.m2-opt:hover { color: var(--mastery-2); border-color: var(--mastery-2); }
.m3-opt:hover { color: var(--mastery-3); border-color: var(--mastery-3); }

.mopt.checked {
  opacity: 1;
  color: var(--on-mastery);
}

.m0-opt.checked { background: var(--mastery-0); border-color: var(--mastery-0); }
.m1-opt.checked { background: var(--mastery-1); border-color: var(--mastery-1); }
.m2-opt.checked { background: var(--mastery-2); border-color: var(--mastery-2); }
.m3-opt.checked { background: var(--mastery-3); border-color: var(--mastery-3); }

/* ===== Today (hero card) ===== */
.today {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 28px;
  padding: 24px 28px;
  margin-bottom: var(--gap);
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
  background:
    radial-gradient(ellipse 60% 120% at 0% 0%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 60%),
    radial-gradient(ellipse 40% 100% at 100% 100%, color-mix(in srgb, var(--accent-2) 7%, transparent), transparent 60%),
    var(--surface);
}

.today-ring {
  position: relative;
  width: 132px;
  height: 132px;
}

.today-ring .ring {
  width: 100%;
  height: 100%;
}

.today-ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.1;
}

.today-count {
  font-size: 30px;
  font-weight: 650;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}

.today-unit {
  font-size: 12px;
  color: var(--text-muted);
}

.today-check {
  width: 18px;
  height: 18px;
  color: var(--mastery-3);
  stroke-width: 3;
  margin-bottom: 2px;
}

.today-greet {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variation-settings: "opsz" 96;
  line-height: 1.2;
}

.today-date {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 4px;
}

.today-date::first-letter {
  text-transform: uppercase;
}

.today-ok {
  color: var(--mastery-3);
}

.today-label {
  margin: 18px 0 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.next-step {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  max-width: 560px;
  text-align: left;
  padding: 12px 14px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--bg) 55%, transparent);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color 150ms, transform 150ms var(--ease);
}

.next-step:hover {
  border-color: var(--text-muted);
  transform: translateY(-1px);
}

.next-title {
  font-size: 16px;
  font-weight: 600;
}

.next-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.next-meta .mdot-static {
  width: 14px;
  height: 14px;
}

.next-empty {
  font-size: 14px;
}

.btn-hero {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  padding: 16px 24px;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 600;
  text-align: left;
  box-shadow: 0 10px 30px color-mix(in srgb, var(--accent) 18%, transparent);
  transition: transform 150ms var(--ease), box-shadow 150ms, background 150ms;
}

.btn-hero:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 36px color-mix(in srgb, var(--accent) 26%, transparent);
}

.btn-hero > .icon {
  width: 22px;
  height: 22px;
}

.btn-hero-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.btn-hero-sub {
  font-size: 13px;
  font-weight: 400;
  opacity: 0.85;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Progress ring (SVG) */
.ring {
  transform: rotate(-90deg);
  overflow: visible;
}

.ring-track {
  fill: none;
  stroke: var(--border);
}

.ring-bar {
  fill: none;
  stroke: var(--accent);
  stroke-linecap: round;
  transition: stroke-dashoffset 900ms var(--ease), stroke 300ms;
}

.ring-done .ring-bar {
  stroke: var(--mastery-3);
}

/* ===== Pomodoro dial, breathing background, summary ===== */
.pomo::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 900px;
  height: 900px;
  margin: -450px 0 0 -450px;
  border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--pomo-color) 22%, transparent) 0%, transparent 60%);
  opacity: 0.55;
  pointer-events: none;
  animation: breathe 8s ease-in-out infinite;
}

.pomo[data-phase="shortBreak"],
.pomo[data-phase="longBreak"] {
  --pomo-color: var(--mastery-3) !important;
}

.pomo.paused::before,
.pomo[data-phase="ready"]::before {
  animation-play-state: paused;
  opacity: 0.3;
}

@keyframes breathe {
  0%,
  100% {
    transform: scale(0.85);
    opacity: 0.35;
  }
  50% {
    transform: scale(1.05);
    opacity: 0.7;
  }
}

.pomo {
  grid-template-columns: minmax(0, 1fr);
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

.pomo-setup,
.pomo-run {
  position: relative; /* above the breathing glow */
  width: 100%;
  max-width: 560px;
  justify-self: center;
}

.pomo-summary {
  max-width: 100%;
}

.pomo-actions {
  flex-wrap: wrap;
}

.pomo-dial {
  position: relative;
  width: 320px;
  height: 320px;
  display: grid;
  place-items: center;
  margin: 6px 0;
}

.pomo-dial .ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.pomo-ring .ring-track {
  stroke: color-mix(in srgb, var(--pomo-color) 16%, var(--border));
}

.pomo-ring .ring-bar {
  stroke: var(--pomo-color);
  transition: stroke-dashoffset 300ms linear, stroke 400ms;
  filter: drop-shadow(0 0 10px color-mix(in srgb, var(--pomo-color) 55%, transparent));
}

.pomo-dial-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.pomo-dial .pomo-cycles {
  margin-top: 2px;
}

.pomo-label {
  font-size: 17px;
  font-weight: 500;
  color: var(--text);
  opacity: 0.85;
}

.pomo-summary {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 18px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  border: 1px solid color-mix(in srgb, var(--mastery-3) 40%, var(--border));
  text-align: left;
  animation: summary-in 450ms var(--ease);
}

.summary-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--mastery-3) 18%, transparent);
  color: var(--mastery-3);
}

.summary-icon .icon {
  width: 22px;
  height: 22px;
  stroke-width: 2.5;
}

.summary-title {
  font-weight: 650;
  font-size: 16px;
}

.summary-target,
.summary-count {
  font-size: 13px;
  color: var(--text-muted);
}

@keyframes summary-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}

.btn-round {
  border-radius: 999px;
  padding-left: 18px;
  padding-right: 18px;
}

/* ===== Duo ===== */
.duo {
  --them: var(--them);
  display: grid;
  grid-template-columns: minmax(220px, 1.1fr) minmax(220px, 1fr) auto;
  align-items: center;
  gap: 24px;
  padding: 18px 22px;
  margin-bottom: var(--gap);
}

.duo.duo-compact {
  display: flex;
  justify-content: space-between;
}

.duo-who,
.duo-invite {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.duo-avatar {
  position: relative;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  font-weight: 700;
  font-size: 19px;
  color: var(--on-mastery);
  background: var(--them);
}

.duo-avatar.ghost {
  background: var(--surface-hover);
  color: var(--text-muted);
  border: 1px dashed var(--border);
}

.duo-avatar.live::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--them);
  animation: live-ring 1.8s ease-out infinite;
}

@keyframes live-ring {
  from {
    transform: scale(0.9);
    opacity: 0.9;
  }
  to {
    transform: scale(1.25);
    opacity: 0;
  }
}

.duo-who-text {
  min-width: 0;
}

.duo-name {
  font-weight: 600;
}

.duo-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--text-muted);
}

.duo-status.st-studying {
  color: var(--them);
}

.duo-status.st-goalDone {
  color: var(--mastery-3);
}

.duo-streak {
  color: var(--text-muted);
  margin-top: 2px;
}

.live-dot {
  display: inline-block;
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--them);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--them) 60%, transparent);
  animation: live-dot 1.6s infinite;
}

@keyframes live-dot {
  70% {
    box-shadow: 0 0 0 7px color-mix(in srgb, var(--them) 0%, transparent);
  }
  100% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--them) 0%, transparent);
  }
}

.duo-week-head {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.duo-week-head .mono {
  color: var(--text);
  font-weight: 600;
}

.duo-bar {
  display: flex;
  gap: 2px;
  height: 10px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.duo-bar span {
  display: block;
  height: 100%;
  transition: width 700ms var(--ease);
}

.duo-bar-me {
  background: var(--accent);
}

.duo-bar-them {
  background: var(--them);
}

.duo-legend {
  display: flex;
  gap: 14px;
  margin-top: 6px;
}

.sw {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  margin-right: 5px;
}

.sw-me {
  background: var(--accent);
}

.sw-them {
  background: var(--them);
}

.duo-cheers {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.duo-cheers .btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.duo-ok {
  color: var(--mastery-3);
}

.today-duo {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  color: var(--them);
  justify-content: center;
}

.pomo-duo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  border-radius: 999px;
  color: var(--them);
  background: color-mix(in srgb, var(--them) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--them) 30%, transparent);
}

/* ===== Customisable dashboard (widgets) ===== */
.dash-toolbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: -8px 0 10px;
}

.dash-toolbar-hint {
  margin-right: auto;
}

.widgets {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: var(--gap);
  grid-auto-flow: row dense;
  align-items: stretch;
}

.widget {
  position: relative;
  container-type: inline-size;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.size-xs { grid-column: span 3; }
.size-s { grid-column: span 4; }
.size-m { grid-column: span 6; }
.size-l { grid-column: span 8; }
.size-xl { grid-column: span 12; }

.widget-body {
  flex: 1;
  min-width: 0;
}

/* Number cards keep their natural height next to tall blocks. */
.widget:has(> .kpi) {
  align-self: start;
}

.widget > .card,
.widget .widget-body.card {
  margin-bottom: 0;
}

/* Nothing to show (e.g. no exam dates): hide the block outside edit mode. */
.widgets:not(.editing) .widget:has(> .widget-body[hidden]) {
  display: none;
}

.widget-empty {
  display: none;
}

.widgets.editing .widget:has(> .widget-body[hidden]) .widget-empty {
  display: grid;
  place-items: center;
  min-height: 80px;
  border-radius: var(--radius);
  background: var(--surface);
}

.widget-tools-slot:empty {
  display: none;
}

.widgets.editing .widget {
  outline: 1.5px dashed color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 4px;
  border-radius: var(--radius);
  cursor: grab;
}

.widgets.editing .widget-body {
  pointer-events: none; /* no accidental clicks while arranging */
  opacity: 0.85;
}

.widgets.editing .widget.dragging {
  opacity: 0.35;
}

.widget.drop-before::before,
.widget.drop-after::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 4px;
  border-radius: 4px;
  background: var(--accent);
  z-index: 3;
}

.widget.drop-before::before {
  left: calc(var(--gap) / -2 - 2px);
}

.widget.drop-after::after {
  right: calc(var(--gap) / -2 - 2px);
}

.widget-tools {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  padding: 6px 8px;
  margin-bottom: 8px;
  border-radius: 10px;
  background: var(--surface-hover);
  border: 1px solid var(--border);
  font-size: 13px;
}

.w-grip {
  display: inline-grid;
  place-items: center;
  color: var(--text-muted);
  cursor: grab;
}

.w-name {
  font-weight: 600;
  margin-right: auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 1;
}

.w-sizes {
  display: inline-flex;
  padding: 2px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
}

.w-size {
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  padding: 2px 6px;
  border-radius: 6px;
  cursor: pointer;
}

.w-size.on {
  background: var(--accent);
  color: var(--on-accent);
}

.add-panel {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}

.add-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}

.add-item {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 10px;
  align-items: start;
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  cursor: pointer;
}

.add-item:hover {
  border-color: var(--accent);
}

.add-item > .icon {
  color: var(--accent);
  margin-top: 2px;
  grid-row: span 2;
}

.add-name {
  font-weight: 600;
  font-size: 14px;
}

.kpi-check {
  color: var(--mastery-3);
}

.kpi-cal {
  color: var(--accent);
}

/* Narrow blocks adapt their own layout, wherever they are placed. */
@container (max-width: 640px) {
  .today {
    grid-template-columns: auto 1fr;
    gap: 16px;
    padding: 18px;
  }

  .today-ring {
    width: 96px;
    height: 96px;
    grid-row: 1;
  }

  .today-count {
    font-size: 22px;
  }

  .today-main {
    display: contents;
  }

  .today-greet {
    grid-column: 2;
    grid-row: 1;
    font-size: 21px;
    align-self: center;
  }

  .today-date {
    display: none;
  }

  .today-label,
  .next-step,
  .next-empty,
  .today-cta {
    grid-column: 1 / -1;
  }

  .today-label {
    margin: 4px 0 -8px;
  }

  .btn-hero {
    width: 100%;
    justify-content: center;
  }

  .duo {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .duo-cheers {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .course-row {
    grid-template-columns: 1fr auto;
    gap: 8px;
  }

  .course-row .course-progress {
    grid-column: 1 / -1;
  }
}

@container (max-width: 200px) {
  .kpi-value {
    font-size: 24px;
  }
}

/* ===== Theme picker ===== */
.settings-wide {
  grid-column: 1 / -1;
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.theme-option {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  text-align: left;
  transition: border-color 150ms, transform 150ms var(--ease);
}

.theme-option:hover {
  transform: translateY(-1px);
  border-color: var(--text-muted);
}

.theme-option.checked {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.theme-preview {
  position: relative;
  display: block;
  height: 58px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--text) 10%, transparent);
}

.theme-preview.split::after {
  content: "";
  position: absolute;
  inset: 0 0 0 50%;
  background: #f5f6f8;
}

.tp-card {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  height: 26px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  z-index: 1;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
}

.tp-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.tp-line {
  flex: 1;
  height: 4px;
  border-radius: 4px;
  background: currentColor;
  opacity: 0.18;
  color: #888;
}

.theme-name {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  font-weight: 500;
}

.theme-name .icon {
  color: var(--accent);
  width: 14px;
  height: 14px;
}

/* ===== Evaluations & grades (continuous assessment) ===== */
.grade-summary {
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: 8px 24px;
  padding: 14px 16px;
  margin-bottom: 12px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
}

.grade-avg,
.grade-target {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.grade-big {
  font-size: 28px;
  font-weight: 650;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.grade-big small {
  font-size: 14px;
  font-weight: 400;
  color: var(--text-muted);
}

.grade-target input {
  width: 70px;
}

.grade-status {
  font-size: 14px;
}

.grade-status.ok,
.grade-row-status.ok {
  color: var(--mastery-3);
}

.grade-status.warn,
.grade-row-status.warn {
  color: var(--mastery-1);
}

.grade-status.bad,
.grade-row-status.bad {
  color: var(--mastery-0);
}

.grade-warn {
  grid-column: 1 / -1;
  color: var(--mastery-2);
}

.evals {
  list-style: none;
  margin: 0;
  padding: 0;
}

.eval {
  padding: 10px 0;
  border-top: 1px solid var(--grid);
}

.eval:first-child {
  border-top: none;
}

.eval.graded .eval-title {
  color: var(--text-muted);
}

.eval-line {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.eval-type {
  font-weight: 600;
}

.eval-title {
  flex: 1;
  min-width: 140px;
}

.eval-meta {
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 13px;
}

.eval-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.eval-field input[type="number"] {
  width: 68px;
  padding: 4px 8px;
}

.eval-field .eval-outof {
  width: 58px;
}

.eval-chapters-btn {
  margin-left: auto;
}

.eval-checklist {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 6px 12px;
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
}

.eval-checklist p {
  grid-column: 1 / -1;
  margin: 4px 0 0;
}

.eval-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
}

.eval-check .mdot-static {
  width: 16px;
  height: 16px;
}

.grade-rows {
  display: flex;
  flex-direction: column;
}

.grade-row {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) auto minmax(90px, 1.3fr);
  grid-template-areas: "name avg bar" "status status status";
  align-items: center;
  gap: 4px 14px;
  padding: 10px 0;
  border-top: 1px solid var(--grid);
  text-align: left;
  background: none;
  border-left: none;
  border-right: none;
  border-bottom: none;
  cursor: pointer;
}

.grade-row:first-child {
  border-top: none;
}

.grade-row-name {
  grid-area: name;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.grade-row-avg {
  grid-area: avg;
  font-weight: 650;
  font-size: 18px;
}

.grade-bar {
  grid-area: bar;
  position: relative;
  height: 8px;
  border-radius: 999px;
  background: var(--border);
}

.grade-bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 999px;
  transition: width 600ms var(--ease);
}

.grade-bar-target {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 2px;
  margin-left: -1px;
  border-radius: 2px;
  background: var(--text);
  opacity: 0.7;
}

.grade-row-status {
  grid-area: status;
  color: var(--text-muted);
}

@container (max-width: 520px) {
  .grade-summary {
    grid-template-columns: auto auto;
  }

  .grade-status {
    grid-column: 1 / -1;
  }
}

/* ===== Sign-in ===== */
body.locked .topbar,
body.locked main,
body.locked .banner,
body.locked .toasts {
  display: none !important;
}

.auth {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
  padding-top: max(24px, env(safe-area-inset-top));
  background: radial-gradient(ellipse at top, color-mix(in srgb, var(--accent) 14%, var(--bg)) 0%, var(--bg) 60%);
  overflow-y: auto;
}

.auth-box {
  width: 380px;
  max-width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 24px 64px color-mix(in srgb, var(--shadow) 45%, transparent);
}

.auth-brand {
  font-weight: 700;
  font-size: 20px;
  margin-bottom: 20px;
}

.auth-step {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-step h2 {
  font-size: 18px;
}

.auth-step input {
  width: 100%;
  font-size: 16px;
  padding: 10px 12px;
}

.auth-step .link {
  align-self: center;
  margin-top: 4px;
}

.btn-block {
  width: 100%;
  padding: 11px;
  font-size: 15px;
}

.code-input {
  text-align: center;
  font-size: 24px !important;
  letter-spacing: 0.3em;
}

.qr {
  align-self: center;
  width: 200px;
  height: 200px;
  background: #fff;
  border-radius: 12px;
  padding: 10px;
}

#enroll-secret {
  word-break: break-all;
  user-select: all;
  color: var(--text);
}

.auth-error {
  margin: 14px 0 0;
  color: var(--mastery-0);
  font-size: 14px;
}

.auth-info {
  margin: 14px 0 0;
  color: var(--mastery-3);
  font-size: 14px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 8px 0 12px;
}

.welcome h2 {
  font-family: var(--font-display);
  font-size: 22px;
}

.welcome {
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  background: linear-gradient(135deg, var(--accent-soft), var(--surface) 60%);
}

.welcome h2 {
  margin-bottom: 6px;
}

/* ===== Sync indicator ===== */
.sync {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}

.sync[data-status="synced"] .sync-dot {
  background: var(--mastery-3);
}

.sync[data-status="syncing"] .sync-dot,
.sync[data-status="pending"] .sync-dot {
  background: var(--accent);
  animation: blink 1s infinite;
}

.sync[data-status="offline"] .sync-dot {
  background: var(--mastery-2);
}

.sync[data-status="error"] .sync-dot {
  background: var(--mastery-0);
}

.sync[data-status="synced"] .sync-label {
  display: none;
}

@keyframes blink {
  50% {
    opacity: 0.3;
  }
}

/* ===== Touch devices: no hover, so actions are always visible ===== */
@media (hover: none) {
  .row-actions,
  .reorder {
    opacity: 1;
  }
}

/* ===== Tablet / narrow windows ===== */
@media (max-width: 1100px) {
  .kpis {
    grid-template-columns: repeat(2, 1fr);
  }

  .kpis .kpi {
    margin-bottom: 0;
  }

  .kpis {
    margin-bottom: var(--gap);
  }

  .dash-grid,
  .dash-grid-2,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .matrix-card {
    grid-row: auto;
  }

  .course-row {
    grid-template-columns: 1fr auto 160px;
  }

  .course-row .dots {
    grid-column: 1 / -1;
  }
}

@media (max-width: 1100px) {
  .size-xs,
  .size-s { grid-column: span 6; }
  .size-m { grid-column: span 6; }
  .size-l { grid-column: span 12; }
}

/* ===== Phone ===== */
@media (max-width: 760px) {
  :root {
    --gap: 12px;
  }

  /* 16 px inputs: iOS Safari does not zoom in on focus. */
  select,
  textarea,
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="date"] {
    font-size: 16px;
  }

  .topbar {
    /* backdrop-filter would make the fixed bottom tab bar position itself inside the header */
    backdrop-filter: none;
    background: var(--bg);
    gap: 12px;
    padding: 10px 16px;
    padding-top: max(10px, env(safe-area-inset-top));
  }

  .brand .brand-name {
    display: none; /* logo only on phones */
  }

  .topbar-right {
    gap: 12px;
  }

  .sync-label,
  .goal-bar {
    display: none;
  }

  #btn-pomodoro {
    min-width: 0;
    padding: 7px 12px;
  }

  /* Tabs become a bottom navigation bar. */
  .tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    justify-content: space-around;
    gap: 0;
    padding: 6px 8px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--bg) 96%, transparent);
    backdrop-filter: blur(8px);
    border-top: 1px solid var(--border);
  }

  .tab {
    flex: 1;
    padding: 10px 4px;
    font-size: 14px;
  }

  main {
    padding: 16px 14px calc(88px + env(safe-area-inset-bottom));
  }

  .banner {
    padding: 8px 16px;
    flex-wrap: wrap;
  }

  .card {
    padding: 16px;
  }

  .size-m,
  .size-l,
  .size-xl { grid-column: span 12; }

  .dash-toolbar {
    margin-top: 0;
  }

  .kpi-value {
    font-size: 24px;
  }

  .kpi-icon {
    width: 20px;
    height: 20px;
  }

  .duo {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .duo.duo-compact {
    flex-wrap: wrap;
  }

  .duo-cheers {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .today {
    grid-template-columns: auto 1fr;
    gap: 16px;
    padding: 18px;
  }

  .today-ring {
    width: 96px;
    height: 96px;
    grid-row: 1;
  }

  .today-count {
    font-size: 22px;
  }

  .today-main {
    display: contents;
  }

  .today-greet {
    grid-column: 2;
    grid-row: 1;
    font-size: 21px;
    align-self: center;
  }

  .today-date {
    display: none;
  }

  .today-label,
  .next-step,
  .next-empty,
  .today-cta {
    grid-column: 1 / -1;
  }

  .today-label {
    margin: 4px 0 -8px;
  }

  .btn-hero {
    width: 100%;
    justify-content: center;
  }

  .kpi {
    padding: 14px;
  }

  .chart-box {
    height: 200px;
  }

  .course-row {
    grid-template-columns: 1fr auto;
    gap: 8px;
  }

  .course-row .course-progress {
    grid-column: 1 / -1;
  }

  .split,
  .split.split-right {
    grid-template-columns: 1fr;
  }

  .side {
    position: static;
  }

  /* Task detail opens as a full-screen sheet. */
  #task-detail {
    position: fixed;
    inset: 0;
    z-index: 30;
    overflow-y: auto;
    background: var(--bg);
    padding: 12px;
    padding-top: max(12px, env(safe-area-inset-top));
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
  }

  .detail .field select,
  .detail .field input[type="date"] {
    width: 60%;
  }

  .quick-add {
    flex-wrap: wrap;
  }

  .quick-add #quick-task {
    flex-basis: 100%;
  }

  .quick-add select,
  .quick-add input[type="date"] {
    flex: 1 1 40%;
    min-width: 0;
  }

  .quick-add .btn-primary {
    margin-left: auto;
  }

  .detail-head {
    flex-wrap: wrap;
  }

  .detail-head .title-input {
    flex-basis: calc(100% - 50px);
  }

  .mastery-label,
  .move-btn {
    display: none;
  }

  .grade-summary {
    grid-template-columns: auto auto;
  }

  .grade-status {
    grid-column: 1 / -1;
  }

  .eval-chapters-btn {
    margin-left: 0;
  }

  .chapter-main {
    flex-wrap: wrap;
  }

  .chapter-main .inline-input {
    flex-basis: 100%;
  }

  .chapter-main .mpicker {
    margin-right: auto;
  }

  .mopt {
    width: 34px;
    height: 34px;
  }

  .mopt .icon {
    width: 18px;
    height: 18px;
  }

  .row-actions {
    opacity: 1;
  }

  .mdot {
    width: 28px;
    height: 28px;
    font-size: 13px;
  }

  .mdot.sm {
    width: 22px;
    height: 22px;
    font-size: 11px;
  }

  .icon-btn {
    width: 32px;
    height: 32px;
  }

  .matrix {
    grid-template-columns: 18px 1fr;
  }

  .matrix-grid {
    min-height: 0;
    gap: 6px;
  }

  .quadrant {
    padding: 8px;
    min-height: 120px;
  }

  .quadrant-head {
    font-size: 13px;
  }

  .quadrant-body,
  .matrix.compact .quadrant-body {
    max-height: none;
  }

  .mcard {
    padding: 6px 8px;
    font-size: 13px;
  }

  .mcard-title {
    white-space: normal;
  }

  .task-meta .badge:not(.due-overdue):not(.due-today) {
    display: none;
  }

  .pomo-time {
    font-size: 60px;
  }

  .pomo-dial {
    width: min(78vw, 300px);
    height: min(78vw, 300px);
  }

  .pomo-setup select {
    width: min(320px, 85vw);
  }

  .toasts {
    left: 16px;
    right: 16px;
    bottom: calc(80px + env(safe-area-inset-bottom));
  }
}

/* ===== Accessibility ===== */
@media (prefers-reduced-motion: reduce) {
  .live-dot,
  .duo-avatar.live::after {
    animation: none !important;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
