/* =====================================================================
   StudyPilot – styles
   Colours are defined once as custom properties ("tokens") and swapped
   for dark mode, so the rest of the file never uses raw colour values.
   ===================================================================== */

:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #ffffff;
  --surface-2: #f5f5f2;
  --surface-3: #ecebe6;
  --ink: #1a1a18;
  --ink-2: #52514e;
  --muted: #6f6d68;
  --line: #e4e3dc;
  --border: rgba(11, 11, 11, 0.12);
  --accent: #256abf;
  --accent-hover: #1c5cab;
  --accent-soft: #e7f0fb;
  --accent-ink: #1c5cab;
  --on-accent: #ffffff;
  --break: #1baf7a;

  --chart-bar: #2a78d6;
  --chart-grid: #e1e0d9;
  --chart-base: #c3c2b7;

  --critical: #d03b3b;
  --critical-ink: #a32828;
  --critical-soft: #fbeaea;
  --warning: #fab219;
  --warning-ink: #855600;
  --warning-soft: #fdf2d8;
  --good: #0ca30c;
  --good-ink: #006300;
  --good-soft: #e3f3e3;

  /* Course colours – handed out in this fixed order. */
  --cat-0: #2a78d6;
  --cat-1: #eb6834;
  --cat-2: #1baf7a;
  --cat-3: #eda100;
  --cat-4: #e87ba4;
  --cat-5: #008300;
  --cat-6: #6250d6;
  --cat-7: #e34948;

  --shadow-sm: 0 1px 2px rgba(20, 20, 18, 0.05);
  --shadow: 0 1px 2px rgba(20, 20, 18, 0.04), 0 6px 24px rgba(20, 20, 18, 0.06);
  --shadow-lg: 0 24px 60px rgba(20, 20, 18, 0.22);
  --radius: 16px;
  --radius-sm: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f0f0e;
    --surface: #1a1a19;
    --surface-2: #232321;
    --surface-3: #2c2c2a;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #9a9890;
    --line: #2c2c2a;
    --border: rgba(255, 255, 255, 0.12);
    --accent: #2a78d6;
    --accent-hover: #3987e5;
    --accent-soft: rgba(57, 135, 229, 0.16);
    --accent-ink: #86b6ef;
    --break: #199e70;
    --chart-bar: #3987e5;
    --chart-grid: #2c2c2a;
    --chart-base: #383835;
    --critical-ink: #f08a8a;
    --critical-soft: rgba(208, 59, 59, 0.2);
    --warning-ink: #f5c451;
    --warning-soft: rgba(250, 178, 25, 0.16);
    --good-ink: #5ccf5c;
    --good-soft: rgba(12, 163, 12, 0.2);
    --cat-0: #3987e5;
    --cat-1: #d95926;
    --cat-2: #199e70;
    --cat-3: #c98500;
    --cat-4: #d55181;
    --cat-5: #008300;
    --cat-6: #9085e9;
    --cat-7: #e66767;
    --shadow-sm: none;
    --shadow: 0 0 0 1px rgba(255, 255, 255, 0.04);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.6);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f0f0e;
  --surface: #1a1a19;
  --surface-2: #232321;
  --surface-3: #2c2c2a;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #9a9890;
  --line: #2c2c2a;
  --border: rgba(255, 255, 255, 0.12);
  --accent: #2a78d6;
  --accent-hover: #3987e5;
  --accent-soft: rgba(57, 135, 229, 0.16);
  --accent-ink: #86b6ef;
  --break: #199e70;
  --chart-bar: #3987e5;
  --chart-grid: #2c2c2a;
  --chart-base: #383835;
  --critical-ink: #f08a8a;
  --critical-soft: rgba(208, 59, 59, 0.2);
  --warning-ink: #f5c451;
  --warning-soft: rgba(250, 178, 25, 0.16);
  --good-ink: #5ccf5c;
  --good-soft: rgba(12, 163, 12, 0.2);
  --cat-0: #3987e5;
  --cat-1: #d95926;
  --cat-2: #199e70;
  --cat-3: #c98500;
  --cat-4: #d55181;
  --cat-5: #008300;
  --cat-6: #9085e9;
  --cat-7: #e66767;
  --shadow-sm: none;
  --shadow: 0 0 0 1px rgba(255, 255, 255, 0.04);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.6);
}

/* Course colour hook: any element with data-c="0..7" gets --course. */
[data-c="0"] { --course: var(--cat-0); }
[data-c="1"] { --course: var(--cat-1); }
[data-c="2"] { --course: var(--cat-2); }
[data-c="3"] { --course: var(--cat-3); }
[data-c="4"] { --course: var(--cat-4); }
[data-c="5"] { --course: var(--cat-5); }
[data-c="6"] { --course: var(--cat-6); }
[data-c="7"] { --course: var(--cat-7); }

/* ------------------------------------------------------------------ */
/* Base                                                                */
/* ------------------------------------------------------------------ */

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: clamp(24px, 3vw, 30px); font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 16px; font-weight: 650; }
p { margin: 0; }

a { color: var(--accent-ink); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.icon {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0);
  white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: 12px; top: -48px; z-index: 100;
  background: var(--accent); color: var(--on-accent);
  padding: 8px 14px; border-radius: 8px; text-decoration: none;
}
.skip-link:focus { top: 12px; }

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

.muted { color: var(--muted); }
.link { font-size: 14px; font-weight: 600; text-decoration: none; color: var(--accent-ink); }
.link:hover { text-decoration: underline; }

kbd {
  font-family: inherit; font-size: 12px; font-weight: 600;
  padding: 1px 6px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface-2);
}

/* ------------------------------------------------------------------ */
/* Layout                                                              */
/* ------------------------------------------------------------------ */

.app {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 22px 14px;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 0 8px;
  color: var(--ink); text-decoration: none;
  font-weight: 750; font-size: 18px; letter-spacing: -0.02em;
}
.brand-mark {
  display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--accent); color: var(--on-accent);
}
.brand-mark .icon { width: 18px; height: 18px; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--ink-2);
  text-decoration: none;
  font-weight: 550;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-ink); }

.timer-chip {
  display: flex; align-items: center; gap: 10px;
  margin: 0 4px;
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--ink); color: var(--bg);
  text-decoration: none; font-weight: 700;
  font-variant-numeric: tabular-nums;
  box-shadow: var(--shadow);
}
.timer-chip-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent-hover);
  animation: pulse 1.6s ease-in-out infinite;
}
.timer-chip.is-break .timer-chip-dot { background: var(--break); }
.timer-chip.is-paused .timer-chip-dot { animation: none; opacity: 0.5; }
@keyframes pulse { 50% { opacity: 0.3; } }

.sidebar-foot { margin-top: auto; padding: 0 10px; font-size: 12px; color: var(--muted); }

.main {
  width: 100%;
  max-width: 1180px;
  padding: 32px clamp(16px, 4vw, 48px) 64px;
}

.view-header {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  margin-bottom: 24px;
}
.eyebrow { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }

/* ------------------------------------------------------------------ */
/* Buttons & form controls                                             */
/* ------------------------------------------------------------------ */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-weight: 600; font-size: 14px;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: transparent; color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--critical); border-color: transparent; color: #fff; }
.btn-danger:hover { background: #b83030; }
.btn-danger-outline { color: var(--critical-ink); }
.btn-small { min-height: 32px; padding: 0 12px; font-size: 13px; }
.btn-lg { min-height: 46px; padding: 0 22px; font-size: 15px; }
label.btn { cursor: pointer; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px;
  border: 0; border-radius: 9px;
  background: transparent; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn .icon { width: 17px; height: 17px; }
.icon-btn.danger:hover { color: var(--critical-ink); background: var(--critical-soft); }

.button-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }

input:not([type="radio"]):not([type="checkbox"]):not([type="file"]),
select,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
}
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input[aria-invalid="true"] { border-color: var(--critical); }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; margin: 0; padding: 0; border: 0; }
.field > span, .field > legend { font-size: 13px; font-weight: 600; color: var(--ink-2); padding: 0; margin-bottom: 0; }
.field > legend { margin-bottom: 6px; }
.field em { font-style: normal; font-weight: 400; color: var(--muted); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.error { color: var(--critical-ink); font-size: 13px; min-height: 0; }
.error:empty { display: none; }

/* Segmented control (used for filters, theme and priority). */
.segmented {
  display: inline-flex; gap: 2px;
  padding: 3px;
  border-radius: 12px;
  background: var(--surface-3);
  max-width: 100%;
}
.segmented > button,
.segmented > label {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  border: 0; border-radius: 9px;
  background: transparent;
  color: var(--ink-2);
  font-size: 14px; font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.segmented > button:hover { color: var(--ink); }
.segmented > button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm), 0 0 0 1px var(--border); }
.segmented .count {
  font-size: 12px; font-weight: 700;
  min-width: 20px; padding: 0 6px;
  border-radius: 999px;
  background: var(--surface-2); color: var(--muted);
  text-align: center;
}
.segmented > button[aria-pressed="true"] .count { background: var(--accent-soft); color: var(--accent-ink); }
.scroll-x { overflow-x: auto; scrollbar-width: none; }
.scroll-x::-webkit-scrollbar { display: none; }

.radio-segmented { display: flex; }
.radio-segmented > label { flex: 1; justify-content: center; position: relative; }
.radio-segmented input { position: absolute; opacity: 0; pointer-events: none; }
.radio-segmented label:has(input:checked) { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm), 0 0 0 1px var(--border); }
.radio-segmented label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ------------------------------------------------------------------ */
/* Cards, banner, stats                                                */
/* ------------------------------------------------------------------ */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
.card > h2 { margin-bottom: 6px; }
.card-header {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  margin-bottom: 14px;
}
.card-header .muted { font-size: 14px; }

.banner {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 14px 16px;
  margin-bottom: 20px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--ink);
}
.banner > .icon { color: var(--accent-ink); }
.banner p { flex: 1 1 260px; font-size: 14px; }
.banner-actions { display: flex; gap: 8px; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}
.stat-label { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.stat-label .icon { width: 15px; height: 15px; }
.stat-value { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; margin: 4px 0 2px; }
.stat-sub { font-size: 13px; color: var(--muted); }
.stat.is-alert .stat-label .icon { color: var(--critical); }
.stat.is-alert { border-color: color-mix(in srgb, var(--critical) 35%, var(--line)); }
.stat.is-streak .stat-label .icon { color: var(--cat-1); }

.dash-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.span-2 { grid-column: span 2; }

/* ------------------------------------------------------------------ */
/* Course tags & progress                                              */
/* ------------------------------------------------------------------ */

.course-tag {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--ink-2); font-weight: 550;
  min-width: 0;
}
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--course, var(--muted));
  flex: none;
}

.progress-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px 28px; }
.progress-head { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 8px; font-size: 13px; }
.progress {
  height: 8px; border-radius: 999px; overflow: hidden;
  background: color-mix(in srgb, var(--course, var(--accent)) 16%, var(--surface-2));
}
.progress-fill {
  height: 100%; border-radius: 999px;
  background: var(--course, var(--accent));
  transition: width 0.4s ease;
}

/* ------------------------------------------------------------------ */
/* Task list                                                           */
/* ------------------------------------------------------------------ */

.toolbar { display: flex; flex-direction: column; gap: 12px; margin-bottom: 20px; }
.toolbar-row { display: flex; gap: 12px; flex-wrap: wrap; }
.search { position: relative; flex: 1 1 240px; }
.search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input { padding-left: 38px !important; background: var(--surface) !important; }
.select-wrap { flex: 0 1 220px; }
.select-wrap select { background: var(--surface); }

.task-group { margin-bottom: 24px; }
.task-group-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted);
  margin: 0 0 10px 4px;
}
.task-group-title .count { font-weight: 600; }

.task-list {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 8px;
}
.task-groups-card .task-list { gap: 0; }

.task {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  grid-template-areas: "check main due actions";
  align-items: center;
  gap: 4px 14px;
  padding: 12px 12px 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.task:hover { border-color: var(--border); box-shadow: var(--shadow-sm); }
.task-list.compact .task {
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas: "check main due";
  border: 0; border-radius: 10px;
  padding: 9px 4px;
  background: transparent;
}
.task-list.compact .task + .task { border-top: 1px solid var(--line); border-radius: 0; }
.task-list.compact .task:hover { box-shadow: none; }

.check {
  grid-area: check;
  display: grid; place-items: center;
  width: 24px; height: 24px;
  border-radius: 8px;
  border: 2px solid var(--border);
  background: var(--surface);
  color: transparent;
  padding: 0;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.check .icon { width: 14px; height: 14px; stroke-width: 3; }
.check:hover { border-color: var(--good); color: var(--good); }
.check[aria-pressed="true"] { background: var(--good); border-color: var(--good); color: #fff; }

.task-main { grid-area: main; min-width: 0; }
.task-title { font-weight: 600; overflow-wrap: anywhere; }
.task.is-done .task-title { text-decoration: line-through; color: var(--muted); font-weight: 500; }
.task-meta {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px;
  margin-top: 2px;
  font-size: 13px; color: var(--muted);
}
.task-notes { margin-top: 4px; font-size: 13px; color: var(--ink-2); overflow-wrap: anywhere; }
.prio { display: inline-flex; align-items: center; gap: 5px; }
.prio-bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 12px; }
.prio-bars i { width: 3px; border-radius: 1px; background: var(--surface-3); }
.prio-bars i:nth-child(1) { height: 5px; }
.prio-bars i:nth-child(2) { height: 8px; }
.prio-bars i:nth-child(3) { height: 12px; }
.prio-low .prio-bars i:nth-child(1),
.prio-medium .prio-bars i:nth-child(-n+2),
.prio-high .prio-bars i { background: var(--ink-2); }
.prio-high { color: var(--ink-2); font-weight: 600; }

.due {
  grid-area: due;
  display: inline-flex; align-items: center; gap: 6px;
  justify-self: end;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 13px; font-weight: 600;
  white-space: nowrap;
  color: var(--ink-2);
  background: var(--surface-2);
}
.due .icon { width: 14px; height: 14px; }
.due-overdue { background: var(--critical-soft); color: var(--critical-ink); }
.due-today { background: var(--warning-soft); color: var(--warning-ink); }
.due-soon { background: var(--accent-soft); color: var(--accent-ink); }
.due-later { background: transparent; color: var(--muted); font-weight: 500; }
.due-done { background: var(--good-soft); color: var(--good-ink); }

.task-actions { grid-area: actions; display: flex; gap: 2px; }

.empty {
  grid-column: 1 / -1;
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px;
  padding: 40px 20px;
  color: var(--muted);
}
.empty .icon { width: 32px; height: 32px; color: var(--muted); stroke-width: 1.6; }
.empty h3 { color: var(--ink); }
.empty p { max-width: 380px; font-size: 14px; }
.empty-row { padding: 18px 4px; color: var(--muted); font-size: 14px; list-style: none; }

/* ------------------------------------------------------------------ */
/* Bar chart (focus minutes per day)                                   */
/* ------------------------------------------------------------------ */

.chart { position: relative; }
.chart-plot {
  position: relative;
  height: 190px;
  margin-left: 44px;
}
.plot-area { position: absolute; left: 0; right: 0; top: 22px; bottom: 0; }
.gridline {
  position: absolute; left: 0; right: 0;
  border-top: 1px solid var(--chart-grid);
}
.gridline.is-base { border-top-color: var(--chart-base); }
.gridline span {
  position: absolute; right: calc(100% + 8px); top: -8px;
  font-size: 11px; line-height: 16px; color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.cols { position: absolute; inset: 0; display: flex; }
.col {
  position: relative;
  flex: 1;
  display: flex; justify-content: center; align-items: flex-end;
  border-radius: 8px;
  outline-offset: -2px;
  cursor: default;
}
.col:hover, .col:focus-visible { background: color-mix(in srgb, var(--chart-bar) 7%, transparent); }
.bar {
  position: relative;
  width: min(24px, 58%);
  background: var(--chart-bar);
  border-radius: 4px 4px 0 0;
  transition: height 0.4s ease;
}
.col:hover .bar, .col:focus-visible .bar { filter: brightness(1.08); }
.cap-label {
  position: absolute; bottom: calc(100% + 4px); left: 50%; transform: translateX(-50%);
  font-size: 12px; font-weight: 600; color: var(--ink-2);
  white-space: nowrap;
}
.chart-x {
  display: flex;
  margin-left: 44px;
  padding-top: 8px;
}
.chart-x span { flex: 1; text-align: center; font-size: 12px; color: var(--muted); }
.chart-x span.is-today { color: var(--ink); font-weight: 700; }
.chart-tooltip {
  position: absolute; z-index: 5;
  transform: translate(-50%, -100%);
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--ink); color: var(--bg);
  font-size: 12px; line-height: 1.35;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: var(--shadow);
}
.chart-tooltip strong { display: block; font-size: 14px; }

/* ------------------------------------------------------------------ */
/* Courses                                                             */
/* ------------------------------------------------------------------ */

.course-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.course-card {
  position: relative;
  display: flex; flex-direction: column; gap: 14px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.course-card::before {
  content: "";
  position: absolute; left: 0; top: 0; right: 0; height: 4px;
  background: var(--course);
}
.course-card-top { display: flex; align-items: center; gap: 10px; }
.course-card-top h3 { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.course-card-top .dot { width: 12px; height: 12px; }
.course-card .actions { display: flex; gap: 2px; margin: -6px -8px -6px 0; }
.progress-label { font-size: 13px; color: var(--muted); margin-top: -6px; }
.course-facts {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px;
  margin: 0;
  padding: 12px 0 0;
  border-top: 1px solid var(--line);
}
.course-facts dt { font-size: 12px; color: var(--muted); }
.course-facts dd { margin: 2px 0 0; font-weight: 650; font-size: 14px; }
.course-card .link { align-self: flex-start; }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch {
  position: relative;
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--course);
  cursor: pointer;
}
.swatch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.swatch:has(input:checked) { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--course); }
.swatch:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 5px; }

/* ------------------------------------------------------------------ */
/* Focus timer                                                         */
/* ------------------------------------------------------------------ */

.focus-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.timer-card { display: flex; flex-direction: column; align-items: center; gap: 20px; padding: 28px 24px; }
.timer-card .field { width: 100%; max-width: 420px; }
.timer-mode {
  padding: 5px 14px;
  border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-ink);
  font-size: 13px; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase;
}
.timer-card[data-mode="break"] .timer-mode { background: color-mix(in srgb, var(--break) 16%, transparent); color: var(--good-ink); }
.ring-wrap { position: relative; width: min(260px, 72vw); aspect-ratio: 1; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 12; }
.ring-track { stroke: var(--surface-3); }
.ring-progress {
  stroke: var(--accent);
  stroke-linecap: round;
  transition: stroke-dashoffset 0.3s linear, stroke 0.3s;
}
.timer-card[data-mode="break"] .ring-progress { stroke: var(--break); }
.ring-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 0 30px;
}
.timer-display {
  font-size: clamp(44px, 12vw, 60px); font-weight: 700; letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.timer-sub { font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.timer-controls { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.timer-controls #timer-start { min-width: 132px; }
.durations { display: flex; gap: 20px; flex-wrap: wrap; justify-content: center; font-size: 14px; color: var(--ink-2); }
.durations label { display: inline-flex; align-items: center; gap: 8px; }
.durations input { width: 72px !important; min-height: 36px !important; padding: 6px 10px !important; text-align: center; }

.session-list { list-style: none; margin: 0 0 16px; padding: 0; }
.session-list li {
  display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: 12px; align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.session-list li:last-child { border-bottom: 0; }
.session-time { color: var(--muted); font-variant-numeric: tabular-nums; }
.session-what { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-mins { font-weight: 650; }
.tip {
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--surface-2);
  font-size: 13px; color: var(--ink-2);
}

/* ------------------------------------------------------------------ */
/* Settings                                                            */
/* ------------------------------------------------------------------ */

.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; align-items: start; }
.settings-grid .card p + p { margin-top: 10px; }
.settings-grid .segmented { margin-top: 14px; }
.data-summary { margin-top: 12px; font-size: 14px; font-weight: 600; }

/* ------------------------------------------------------------------ */
/* Dialogs                                                             */
/* ------------------------------------------------------------------ */

.dialog {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 0;
  border-radius: 20px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
}
.dialog-small { width: min(420px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(10, 10, 9, 0.45); backdrop-filter: blur(2px); }
.dialog[open] { animation: pop 0.16s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
.dialog-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px 0 24px;
}
.dialog-header h2 { font-size: 19px; }
.dialog-body { display: flex; flex-direction: column; gap: 16px; padding: 20px 24px; }
.dialog-body > h2 { font-size: 19px; }
.dialog-footer {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 16px 24px 20px;
  border-top: 1px solid var(--line);
}

/* ------------------------------------------------------------------ */
/* Toasts                                                              */
/* ------------------------------------------------------------------ */

.toasts {
  position: fixed; left: 50%; bottom: 24px; z-index: 50;
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  width: max-content; max-width: calc(100vw - 32px);
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 14px;
  padding: 11px 12px 11px 16px;
  border-radius: 12px;
  background: var(--ink); color: var(--bg);
  font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toast-in 0.2s ease-out;
}
.toast.leaving { opacity: 0; transform: translateY(6px); transition: opacity 0.2s, transform 0.2s; }
.toast-action {
  border: 0; border-radius: 8px;
  padding: 5px 10px;
  background: color-mix(in srgb, var(--bg) 18%, transparent);
  color: var(--bg); font-weight: 700; font-size: 13px;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ------------------------------------------------------------------ */
/* Responsive                                                          */
/* ------------------------------------------------------------------ */

@media (max-width: 980px) {
  .dash-grid, .focus-layout { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
}

@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; z-index: 30;
    left: 0; right: 0; bottom: 0; top: auto;
    height: auto;
    flex-direction: row;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    border-right: 0; border-top: 1px solid var(--line);
  }
  .brand, .sidebar-foot { display: none; }
  .nav { flex-direction: row; width: 100%; gap: 0; }
  .nav a {
    flex: 1; flex-direction: column; gap: 3px;
    padding: 6px 2px;
    font-size: 11px; font-weight: 600;
  }
  .nav a .icon { width: 21px; height: 21px; }
  .timer-chip { position: fixed; right: 16px; bottom: calc(76px + env(safe-area-inset-bottom)); margin: 0; }
  .main { padding: 22px 16px calc(96px + env(safe-area-inset-bottom)); }
  .toasts { bottom: calc(84px + env(safe-area-inset-bottom)); }
}

@media (max-width: 600px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 14px; }
  .stat-value { font-size: 24px; }
  .stat:last-child:nth-child(odd) { grid-column: span 2; }
  .view-header .btn-primary { width: 100%; }
  .task {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "check main actions" ". due due";
    padding: 12px;
    column-gap: 12px;
  }
  .task-list.compact .task {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas: "check main" ". due";
  }
  .due { justify-self: start; margin-top: 4px; }
  .task-actions { align-self: start; margin: -4px -4px 0 0; }
  .task .check { align-self: start; margin-top: 1px; }
  .field-row { grid-template-columns: minmax(0, 1fr); }
  .course-facts { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .card { padding: 16px; }
  .dialog-body { padding: 16px 18px; }
  .dialog-header { padding: 16px 16px 0 18px; }
  .dialog-footer { padding: 14px 18px 16px; }
}

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