:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --sidebar: #1f2433;
  --sidebar-text: #c9cede;
  --sidebar-active: #2e3549;
  --text: #1c2030;
  --muted: #6b7185;
  --border: #e3e6ef;
  --primary: #036efc;
  --primary-text: #ffffff;
  --danger: #d6455d;
  --overdue: #d6455d;
  --today: #e08a1e;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 24, 40, 0.06), 0 2px 8px rgba(20, 24, 40, 0.04);
  color-scheme: light;
}

/* Theme (Settings → Appearance): data-theme="light" | "dark" on <html>; none = Auto (follow the device). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12141c;
    --surface: #1b1e29;
    --sidebar: #0d0f15;
    --sidebar-text: #aab0c2;
    --sidebar-active: #1f2332;
    --text: #e7e9f0;
    --muted: #8d93a7;
    --border: #2a2e3d;
    --primary: #3d8bff;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12141c;
  --surface: #1b1e29;
  --sidebar: #0d0f15;
  --sidebar-text: #aab0c2;
  --sidebar-active: #1f2332;
  --text: #e7e9f0;
  --muted: #8d93a7;
  --border: #2a2e3d;
  --primary: #3d8bff;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

[hidden] { display: none !important; }

button, input, select, textarea { font: inherit; color: inherit; }

/* Phones/tablets: keep zoom fixed at 100%. iOS zooms into any field with text under 16px,
   so fields get 16px; touch-action stops double-tap zoom. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
@media (pointer: coarse) {
  html, body { touch-action: pan-x pan-y; }
  input, select, textarea { font-size: 16px; }
}

/* ---------- layout ---------- */

/* App shell: the page itself never scrolls. The sidebar and the main area each scroll on
   their own, and overscroll-behavior stops a scroll (or bounce) in one from moving the other. */
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
.layout { display: flex; height: 100vh; height: 100dvh; }

.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 19px;
  letter-spacing: -0.01em;
  color: #fff;
  padding: 4px 10px 18px;
}
.brand-logo { width: 26px; height: auto; display: block; }
.brand-add { position: relative; margin-left: auto; }
.brand-add-btn {
  width: 28px; height: 28px; border-radius: 50%; border: 0; padding: 0; cursor: pointer;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.1); color: var(--sidebar-text);
  transition: background 0.15s, color 0.15s;
}
.brand-add-btn svg { width: 14px; height: 14px; }
.brand-add-btn:hover, .brand-add-btn.open { background: rgba(255, 255, 255, 0.18); color: #fff; }
.brand-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 190px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 5px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  display: flex; flex-direction: column; gap: 2px;
}
.brand-menu[hidden] { display: none; }
.brand-menu button {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  border: 0; background: none; padding: 8px 10px; border-radius: 7px; cursor: pointer;
  font-size: 14px; font-weight: 500; letter-spacing: normal; color: var(--text);
}
.brand-menu button:hover, .brand-menu button:focus-visible { background: var(--bg); outline: none; }
.brand-menu-icon { width: 18px; text-align: center; }

nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  color: inherit;
  text-decoration: none;
  background: none;
  border: 0;
  cursor: pointer;
  text-align: left;
  width: 100%;
}
.nav-item:hover { background: var(--sidebar-active); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; font-weight: 600; }
.nav-item.add { color: var(--muted); margin-top: 4px; }

/* Drag to reorder classes / organizations */
#class-nav .nav-item, #org-nav .nav-item { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.reordering { cursor: grabbing; }
.reordering .nav-item { cursor: grabbing; }
.nav-item.dragging {
  background: var(--sidebar-active); color: #fff; position: relative; z-index: 1;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35), inset 0 0 0 1px rgba(255, 255, 255, 0.12);
  transform: scale(1.02);
}

/* Compact sidebar (Settings → Appearance): classes and organizations sit closer together. */
:root[data-sidebar="compact"] #class-nav,
:root[data-sidebar="compact"] #org-nav { display: flex; flex-direction: column; gap: 0; }
:root[data-sidebar="compact"] #class-nav .nav-item,
:root[data-sidebar="compact"] #org-nav .nav-item { padding-top: 4px; padding-bottom: 4px; font-size: 14px; }
:root[data-sidebar="compact"] #class-nav .count,
:root[data-sidebar="compact"] #org-nav .count { font-size: 11px; }
.nav-item.add:hover { color: #fff; }

.nav-icon { width: 18px; text-align: center; flex-shrink: 0; }
.nav-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.nav-item .dot { margin: 0 4px; }

.count {
  font-size: 12px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  padding: 0 8px;
  min-width: 22px;
  text-align: center;
}
.count:empty { display: none; }

.nav-section {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  padding: 18px 10px 6px;
}

.link-btn {
  background: none;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  padding: 8px 10px;
  text-align: left;
}
.link-btn:hover { color: #fff; }

.main { flex: 1; min-width: 0; height: 100%; overflow-y: auto; overscroll-behavior: contain; padding: 24px 32px 48px; }
/* Content width limits live on the children so the scrollbar stays at the window edge. */
.main > * { max-width: 900px; }
.main.wide > * { max-width: 1280px; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.title-wrap { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.title-wrap h1 { margin: 0; font-size: 26px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.title-text { min-width: 0; display: flex; flex-direction: column; }
.page-eyebrow { margin: 0 0 2px; font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--primary); }
.page-subtitle { margin: 4px 0 0; font-size: 14px; color: var(--muted); }
.title-dot { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }
.title-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

.menu-btn {
  display: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 38px;
  height: 38px;
  cursor: pointer;
  font-size: 18px;
}

.scrim { display: none; }

/* ---------- controls ---------- */

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 13px; }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 8px 10px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
label .muted { font-weight: 400; }
.muted { color: var(--muted); }
.error { color: var(--danger); margin: 0; font-size: 14px; }

.row { display: flex; gap: 12px; }
.row > * { flex: 1; }

/* ---------- cards & lists ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}


.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 12px; }
.toggle { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.toggle input { width: auto; }

.group { margin-bottom: 22px; }
.group h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 8px 2px;
}
.group-toggle {
  display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; padding: 2px 4px 2px 0;
  font: inherit; letter-spacing: inherit; text-transform: inherit; color: inherit; cursor: pointer; border-radius: 6px;
}
.group-toggle:hover { color: var(--text); }
.group.overdue .group-toggle:hover, .group.today .group-toggle:hover { filter: brightness(0.85); }
.chev { width: 12px; height: 12px; flex-shrink: 0; transition: transform 0.15s ease; }
.group.collapsed .chev { transform: rotate(-90deg); }
.group.collapsed .list { display: none; }
.group.collapsed { margin-bottom: 12px; }
.group.overdue h3 { color: var(--overdue); }
.group.today h3 { color: var(--today); }

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

.item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.item:last-child { border-bottom: 0; }
.item .check { width: 18px; height: 18px; margin-top: 2px; flex-shrink: 0; cursor: pointer; accent-color: var(--primary); }
/* Events (calendar day view): no checkbox, so the name starts where checkboxes do. */
/* Calendar day view mixes to-dos and events: each row's details line starts at the left edge
   (where checkboxes are), under the checkbox, so to-do and event details line up. The 4px
   matches the checkbox's built-in left margin. */
.day-list .item { display: grid; grid-template-columns: auto 1fr auto; column-gap: 12px; row-gap: 0; align-items: start; }
.day-list .item .body { display: contents; }
.day-list .item .check { grid-column: 1; grid-row: 1; }
.day-list .item .title { grid-column: 2; grid-row: 1; }
.day-list .item.event .title { grid-column: 1 / 3; margin-left: 4px; }
.day-list .item .meta, .day-list .item .notes { grid-column: 1 / 3; margin-left: 4px; }
.day-list .item .actions { grid-column: 3; grid-row: 1 / span 2; align-self: center; }
.item .body { flex: 1; min-width: 0; }
.item .title { font-weight: 600; word-break: break-word; }
.item.done .title { text-decoration: line-through; color: var(--muted); font-weight: 500; }
.item .meta { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 13px; color: var(--muted); margin-top: 2px; align-items: center; }
.item .notes { font-size: 13px; color: var(--muted); margin-top: 4px; white-space: pre-wrap; word-break: break-word; }
.item .due.overdue { color: var(--overdue); font-weight: 600; }
.item .due.today { color: var(--today); font-weight: 600; }
.item .actions { display: flex; gap: 4px; opacity: 0; transition: opacity 0.15s; }
.item:hover .actions, .item:focus-within .actions { opacity: 1; }

.icon-btn {
  background: none;
  border: 0;
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  color: var(--muted);
}
.icon-btn:hover { background: var(--bg); color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}
.chip:hover { text-decoration: underline; }

.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}
.empty .big { font-size: 40px; margin-bottom: 8px; }
.empty-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.kind-tag { font-size: 12px; color: var(--muted); }

/* ---------- dialogs ---------- */

dialog {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  width: min(440px, calc(100vw - 32px));
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
dialog::backdrop { background: rgba(10, 12, 20, 0.45); }
.dialog-form { display: flex; flex-direction: column; gap: 14px; padding: 22px; }
.dialog-form h2 { margin: 0 0 4px; font-size: 19px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.dialog-actions .delete-left { margin-right: auto; }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; margin-top: -8px; }
.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}
.swatch.selected { border-color: var(--text); box-shadow: inset 0 0 0 2px var(--surface); }

/* Eyedropper circle: rainbow ring around a plain center, or filled with the custom color once chosen. */
.swatch-custom {
  display: grid;
  place-items: center;
  background: conic-gradient(#f43f5e, #f5a524, #eab308, #2fa36b, #0ea5b7, #4f6bed, #a855f7, #f43f5e);
}
.swatch-custom span {
  width: 20px; height: 20px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface); color: var(--muted);
  transition: background 0.15s, color 0.15s;
}
.swatch-custom svg { width: 9px; height: 9px; }
.swatch-custom:hover span { color: var(--text); }
.swatch-custom.has-color span { background: var(--custom); color: var(--custom-ink); }
.swatch-custom[aria-expanded="true"]:not(.selected) { border-color: var(--border); }

/* Hex box revealed by the eyedropper: color preview (doubles as a native picker) inside the input. */
.custom-color { margin-top: -4px; animation: reveal 0.15s ease-out; }
@keyframes reveal { from { opacity: 0; transform: translateY(-4px); } }
.hex-field { position: relative; width: 160px; }
.hex-field input[name="hex"] {
  padding-left: 40px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.hex-field input[name="hex"].invalid { border-color: var(--danger); outline-color: var(--danger); }
.hex-field input[type="color"] {
  position: absolute; left: 8px; top: 50%; transform: translateY(-50%);
  width: 22px; height: 22px; padding: 0; border: 1px solid var(--border); border-radius: 6px;
  background: none; cursor: pointer; overflow: hidden;
}
.hex-field input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.hex-field input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 5px; }
.hex-field input[type="color"]::-moz-color-swatch { border: 0; border-radius: 5px; }

/* ---------- login ---------- */

.login { height: 100vh; height: 100dvh; overflow-y: auto; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 28px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; }
.login-brand { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px; margin-bottom: 6px; }
.login-logo { width: 72px; height: auto; margin-bottom: 10px; filter: drop-shadow(0 4px 10px rgba(20, 24, 40, 0.12)); }
.login-card h1 { margin: 0; font-size: 26px; letter-spacing: -0.02em; }
.login-brand p { margin: 0; font-size: 14px; }
.empty-logo { width: 64px; height: auto; margin-bottom: 8px; }

.tabs { display: flex; background: var(--bg); border-radius: 8px; padding: 3px; gap: 3px; }
.tab { flex: 1; border: 0; background: none; padding: 7px; border-radius: 6px; cursor: pointer; color: var(--muted); font-weight: 600; }
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.hint { font-size: 13px; margin: -4px 0 0; }

.account { display: flex; align-items: center; justify-content: space-between; gap: 4px; border-top: 1px solid rgba(255, 255, 255, 0.08); padding-top: 12px; margin-top: 12px; }
.account-link { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; padding: 6px 8px; border-radius: 8px; color: inherit; text-decoration: none; }
.account-link:hover, .account-link.active { background: var(--sidebar-active); }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; flex-shrink: 0; }
.account-text { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.2; }
.account-name { color: #fff; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-type { font-size: 11px; color: var(--muted); font-weight: 500; letter-spacing: 0.02em; }
.gear { color: var(--muted); font-size: 14px; }
.account-link:hover .gear { color: #fff; }

/* profile form (first-time prompt + settings) */
.profile-form { display: flex; flex-direction: column; gap: 14px; }
.profile-form fieldset, .kind-field, .type-field, .theme-field { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.profile-form legend, .kind-field legend, .type-field legend, .theme-field legend { font-size: 13px; font-weight: 600; color: var(--muted); padding: 0; margin-bottom: 6px; }
.choices { display: flex; gap: 8px; }
.choice { flex: 1; flex-direction: row; justify-content: center; position: relative; border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px; cursor: pointer; color: var(--text); font-size: 15px; font-weight: 500; background: var(--surface); }
.choice input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.choice:has(input:checked) { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); color: var(--primary); font-weight: 600; }
.choice:has(input:disabled) { opacity: 0.45; cursor: not-allowed; }
.choice:has(input:focus-visible) { outline: 2px solid var(--primary); outline-offset: 2px; }
.form-actions { display: flex; justify-content: flex-end; align-items: center; gap: 12px; }
.profile-intro { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px; margin-bottom: 4px; }
.profile-intro img { width: 48px; height: auto; margin-bottom: 6px; }
.profile-intro p { margin: 0; font-size: 14px; }
.profile-dialog { width: min(480px, calc(100vw - 32px)); }

.settings-card { padding: 20px; margin-bottom: 16px; max-width: 560px; }
.hint-text { font-size: 13px; margin: 8px 0 0; }
.settings-gap { margin-top: 18px; }
.settings-text { margin: -6px 0 14px; font-size: 14px; }
.settings-card .btn { text-decoration: none; display: inline-block; }
.settings-card h2 { margin: 0 0 14px; font-size: 17px; }
.kv { display: flex; justify-content: space-between; gap: 12px; }
.kv + .kv { margin-top: 10px; }

/* ---------- calendar ---------- */
.cal-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.cal-nav { display: flex; align-items: center; gap: 6px; min-width: 0; }
.btn.icon { width: 32px; padding: 4px 0; font-size: 17px; line-height: 1; }
.cal-label { margin: 0 0 0 8px; font-size: 18px; font-weight: 700; white-space: nowrap; }
.cal-actions { display: flex; align-items: center; gap: 10px; }
.cal-cell { cursor: pointer; }
.cal-cell:hover:not(:has(.cal-chip:hover, .cal-date:hover, .cal-more:hover)) { background: color-mix(in srgb, var(--primary) 5%, var(--surface)); }
.cal-cell.outside:hover:not(:has(.cal-chip:hover, .cal-date:hover, .cal-more:hover)) { background: color-mix(in srgb, var(--primary) 5%, var(--bg)); }
.segmented { display: inline-flex; background: var(--border); border-radius: 9px; padding: 3px; gap: 2px; }
.segmented button { border: 0; background: none; padding: 5px 14px; border-radius: 7px; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; }
.segmented button:hover { color: var(--text); }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.cal-month { overflow: hidden; }
.cal-weekdays, .cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-weekdays div { padding: 8px 10px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); border-bottom: 1px solid var(--border); }
.cal-cell { min-height: 108px; padding: 6px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.cal-cell:nth-child(7n) { border-right: 0; }
.cal-grid > .cal-cell:nth-last-child(-n + 7) { border-bottom: 0; }
.cal-cell.outside { background: var(--bg); }
.cal-cell.outside .cal-date { color: var(--muted); opacity: 0.6; }
.cal-date { align-self: flex-start; border: 0; background: none; width: 26px; height: 26px; border-radius: 50%; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--text); padding: 0; }
.cal-date:hover { background: var(--bg); }
.cal-cell.today .cal-date { background: var(--primary); color: #fff; }
.cal-chips { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cal-dots { display: none; }

.cal-chip {
  display: flex; align-items: center; gap: 5px; width: 100%; min-width: 0; text-align: left;
  border: 0; border-radius: 5px; padding: 3px 6px 3px 8px; cursor: pointer; font-size: 12px; font-weight: 500;
  color: var(--text); background: color-mix(in srgb, var(--chip) 14%, var(--surface));
  box-shadow: inset 3px 0 0 var(--chip);
}
.cal-chip:hover { background: color-mix(in srgb, var(--chip) 24%, var(--surface)); }
/* Events: a faint checkerboard in the item's color, so they read differently from to-dos. */
.cal-chip.event {
  background:
    repeating-conic-gradient(
      color-mix(in srgb, var(--chip) 24%, var(--surface)) 0 25%,
      color-mix(in srgb, var(--chip) 9%, var(--surface)) 0 50%
    ) 0 0 / 8px 8px;
}
.cal-chip.event:hover {
  background:
    repeating-conic-gradient(
      color-mix(in srgb, var(--chip) 34%, var(--surface)) 0 25%,
      color-mix(in srgb, var(--chip) 16%, var(--surface)) 0 50%
    ) 0 0 / 8px 8px;
}
.cal-chip.event.done .cal-chip-title { text-decoration: none; }
.cal-chip-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-chip.done { opacity: 0.55; }
.cal-chip.done .cal-chip-title { text-decoration: line-through; }
.cal-chip.overdue { color: var(--overdue); }
.cal-time { font-size: 11px; color: var(--muted); flex-shrink: 0; }
.cal-more { border: 0; background: none; text-align: left; font-size: 12px; color: var(--muted); cursor: pointer; padding: 1px 6px; }
.cal-more:hover { color: var(--text); }

.cal-week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); overflow: hidden; }
.cal-day-col { border-right: 1px solid var(--border); min-height: 320px; display: flex; flex-direction: column; min-width: 0; }
.cal-day-col:last-child { border-right: 0; }
.cal-day-head { border: 0; border-bottom: 1px solid var(--border); background: none; padding: 10px 8px; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; }
.cal-day-head:hover { background: var(--bg); }
.cal-dow { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.cal-dnum { font-size: 18px; font-weight: 700; color: var(--text); width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; }
.cal-day-col.today .cal-dnum { background: var(--primary); color: #fff; }
.cal-day-items { padding: 6px; display: flex; flex-direction: column; gap: 4px; }
.cal-day-items .cal-chip { flex-direction: column; align-items: flex-start; gap: 1px; padding: 5px 6px 5px 9px; }
.cal-day-items .cal-chip-title { white-space: normal; word-break: break-word; }
.cal-none { color: var(--muted); font-size: 13px; text-align: center; padding-top: 8px; opacity: 0.6; }

/* ---------- mobile ---------- */

@media (max-width: 760px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    height: 100dvh;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .sidebar.open { transform: none; }
  .scrim.open { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); z-index: 10; }
  .menu-btn { display: block; }
  .main { padding: 16px 16px 40px; }
  .title-wrap h1 { font-size: 21px; }
  .menu-btn { align-self: flex-start; }
  /* calendar on phones: month shows dots (tap a day for details); week stacks by day */
  .cal-label { font-size: 16px; margin-left: 4px; }
  .cal-actions { width: 100%; }
  .cal-toolbar .segmented { flex: 1; }
  .segmented button { flex: 1; }
  .cal-cell { min-height: 54px; padding: 4px 2px; align-items: center; cursor: pointer; }
  .cal-weekdays div { padding: 6px 0; text-align: center; font-size: 10px; }
  .cal-date { align-self: center; width: 26px; height: 26px; }
  .cal-chips { display: none; }
  .cal-dots { display: flex; gap: 3px; justify-content: center; flex-wrap: wrap; max-width: 100%; }
  .cal-dots span { width: 6px; height: 6px; border-radius: 50%; }
  .cal-week { grid-template-columns: 1fr; }
  .cal-day-col { min-height: 0; flex-direction: row; border-right: 0; border-bottom: 1px solid var(--border); }
  .cal-day-col:last-child { border-bottom: 0; }
  .cal-day-head { border-bottom: 0; border-right: 1px solid var(--border); width: 64px; flex-shrink: 0; }
  .cal-day-items { flex: 1; min-width: 0; }
  .cal-none { text-align: left; padding: 6px 4px; }
  .topbar { flex-wrap: wrap; }
  .title-actions { width: 100%; justify-content: flex-start; }
  .title-actions:empty { display: none; }
  #add-assignment { flex: 1; }
        .item .actions { opacity: 1; }
  .row { flex-direction: column; }
}
