:root {
  --paper: #EDF0EA;
  --surface: #F8F9F5;
  --ink: #1D2B2A;
  --muted: #5B6966;
  --line: #CBD3CC;
  --accent: #2E6A7E;
  --done: #3F7D4E;
  --warn: #A5452F;
  --cell-0: #DDE3DC;
  --cell-1: #B9D2C0;
  --cell-2: #82B391;
  --cell-3: #4F9064;
  --cell-4: #2D6B42;

  --t-kalamna: #7B4F96;
  --t-study: #2E6A7E;
  --t-project: #A0660F;
  --t-book: #9A3B50;
  --t-video: #56773A;
  --t-leetcode: #3C5DA8;
  --t-research: #46617B;
  --t-review: #6A6F6C;

  --font-ui: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  --font-display: "Bricolage Grotesque", "Atkinson Hyperlegible", system-ui, sans-serif;
  --r-sm: 6px;
  --r-md: 10px;
  color-scheme: light dark;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #152020; --surface: #1D2A29; --ink: #E4EBE7; --muted: #9AA9A4; --line: #33433F;
    --accent: #7FB6C8; --done: #7DC08F; --warn: #E08A73;
    --cell-0: #26332F; --cell-1: #2F5140; --cell-2: #3D7152; --cell-3: #5A9C6E; --cell-4: #8CCB9C;
    --t-kalamna: #C39BDB; --t-study: #7FB6C8; --t-project: #E0A54A; --t-book: #E08A9E;
    --t-video: #A6C98A; --t-leetcode: #97AFEA; --t-research: #A7BDD3; --t-review: #AEB4B1;
  }
}
*, *::before, *::after { box-sizing: inherit; }
html { scroll-padding-top: calc(env(safe-area-inset-top, 0px) + 12px); }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 16px/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; box-sizing: border-box; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
a { color: var(--accent); }

/* Header */
.top { max-width: 1040px; margin: 0 auto; padding: 20px 20px 0; }
.top-row { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: flex-end; justify-content: space-between; }
.brand { font-family: var(--font-display); font-weight: 800; font-size: clamp(1.9rem, 5vw, 2.8rem); line-height: 1; margin: 0; letter-spacing: -0.02em; }
.brand-dates { display: block; font-family: var(--font-ui); font-weight: 400; font-size: 0.95rem; color: var(--muted); letter-spacing: 0; margin-top: 8px; }
.people { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 3px; background: var(--surface); }
.people button { border: 0; background: none; padding: 6px 16px; border-radius: 999px; cursor: pointer; }
.people button[aria-selected="true"] { background: var(--ink); color: var(--paper); }

/* The quarter grid: the one bold element */
.quarter { margin-top: 20px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px 28px; align-items: end; }
.quarter-scroll { overflow-x: auto; padding-bottom: 4px; }
.grid { display: grid; grid-auto-flow: column; grid-template-rows: auto repeat(7, 22px); gap: 4px; width: max-content; }
.grid .rowlabel { font-size: 0.72rem; color: var(--muted); line-height: 22px; padding-right: 4px; }
.grid .month { font-size: 0.78rem; color: var(--muted); height: 18px; white-space: nowrap; }
.cell {
  width: 22px; height: 22px; border-radius: 5px; border: 0; padding: 0; cursor: pointer;
  background: var(--cell-0); position: relative;
}
.cell.pad { visibility: hidden; cursor: default; }
.cell[data-lvl="1"] { background: var(--cell-1); }
.cell[data-lvl="2"] { background: var(--cell-2); }
.cell[data-lvl="3"] { background: var(--cell-3); }
.cell[data-lvl="4"] { background: var(--cell-4); }
.cell.future { background: transparent; box-shadow: inset 0 0 0 1.5px var(--line); }
.cell.today { box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--ink); }
.quarter-stats { display: grid; gap: 10px; min-width: 190px; }
.stat b { font-family: var(--font-display); font-size: 2rem; font-weight: 700; line-height: 1; display: block; }
.stat span { color: var(--muted); font-size: 0.88rem; }

.views { display: flex; gap: 4px; margin-top: 22px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.views button { border: 0; background: none; padding: 10px 14px; cursor: pointer; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.views button[aria-current="page"] { color: var(--ink); border-bottom-color: var(--ink); font-weight: 700; }

main { max-width: 1040px; margin: 0 auto; padding: 20px 20px 80px; }
main:focus { outline: none; }
.col { max-width: 760px; }
h2 { font-family: var(--font-display); font-weight: 700; font-size: 1.6rem; margin: 8px 0 4px; letter-spacing: -0.01em; }
h3 { font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; margin: 0; }
.sub { color: var(--muted); margin: 0 0 16px; }

#banner:empty { display: none; }
.banner { max-width: 1000px; margin: 16px auto 0; padding: 12px 16px; border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--accent); display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; }
.banner p { margin: 0; flex: 1 1 300px; }

/* Buttons */
.btn { border: 1px solid var(--line); background: var(--surface); padding: 7px 14px; border-radius: var(--r-sm); cursor: pointer; }
.btn:hover { border-color: var(--ink); }
.btn.primary, button.primary { background: var(--ink); color: var(--paper); border: 1px solid var(--ink); padding: 7px 16px; border-radius: var(--r-sm); cursor: pointer; }
.btn.danger, button.danger { color: var(--warn); border: 1px solid var(--warn); background: none; padding: 7px 14px; border-radius: var(--r-sm); cursor: pointer; }
.icon-btn { border: 0; background: none; padding: 4px 6px; border-radius: var(--r-sm); cursor: pointer; color: var(--muted); font-size: 0.85rem; }
.icon-btn:hover { color: var(--ink); background: var(--paper); }

/* Week chips */
.weeks { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }
.weeks button { border: 1px solid var(--line); background: var(--surface); border-radius: var(--r-sm); padding: 6px 10px; cursor: pointer; min-width: 44px; }
.weeks button[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.weeks button .pct { display: block; font-size: 0.7rem; opacity: 0.75; }

.bar { height: 6px; background: var(--cell-0); border-radius: 3px; overflow: hidden; margin: 8px 0 20px; max-width: 760px; }
.bar i { display: block; height: 100%; background: var(--done); }

/* Day card */
.day { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 14px 16px 10px; margin-bottom: 14px; max-width: 760px; }
.day.is-today { border-color: var(--ink); border-width: 2px; }
.day-head { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; justify-content: space-between; }
.day-meta { color: var(--muted); font-size: 0.88rem; }
.tag { font-size: 0.75rem; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); margin-left: 6px; }
.tasks { list-style: none; margin: 10px 0 0; padding: 0; }
.task { display: grid; grid-template-columns: 26px minmax(0, 1fr) auto; gap: 2px 8px; padding: 9px 0; border-top: 1px solid var(--line); align-items: start; }
.task:first-child { border-top: 0; }
.task input[type="checkbox"] { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--done); cursor: pointer; }
.task-title { cursor: pointer; }
.task.done .task-title { text-decoration: line-through; text-decoration-thickness: 1px; color: var(--muted); }
.task-meta { grid-column: 2; display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 0.82rem; color: var(--muted); }
.type { font-weight: 700; }
.type::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; background: currentColor; vertical-align: 1px; }
.type-kalamna { color: var(--t-kalamna); } .type-study { color: var(--t-study); } .type-project { color: var(--t-project); }
.type-book { color: var(--t-book); } .type-video { color: var(--t-video); } .type-leetcode { color: var(--t-leetcode); }
.type-research { color: var(--t-research); } .type-review { color: var(--t-review); }
.task-actions { display: flex; gap: 2px; grid-row: 1 / span 2; grid-column: 3; align-self: start; }
.task-details { grid-column: 2 / 4; font-size: 0.88rem; color: var(--muted); margin: 2px 0 0; }
.task-note { grid-column: 2 / 4; margin-top: 6px; }
.task-note textarea, .day-note textarea, .case textarea { width: 100%; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--paper); padding: 8px 10px; resize: vertical; }
.note-preview { grid-column: 2 / 4; font-size: 0.88rem; margin: 4px 0 0; padding-left: 10px; border-left: 3px solid var(--line); white-space: pre-wrap; }
.day-foot { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line); }
.day-note { flex: 1 1 100%; }
.day-note summary { cursor: pointer; color: var(--muted); font-size: 0.88rem; }
.day-note textarea { margin-top: 6px; }
.overdue { border-left: 4px solid var(--warn); }
.overdue-list .task { grid-template-columns: 26px minmax(0, 1fr) auto; }
.muted { color: var(--muted); }

/* Cases */
.case { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 16px; margin-bottom: 14px; max-width: 760px; }
.case > summary { cursor: pointer; list-style: none; }
.case > summary::-webkit-details-marker { display: none; }
.case-q { margin: 10px 0 14px; padding: 10px 12px; background: var(--paper); border-radius: var(--r-sm); }
.case label { display: block; font-weight: 700; font-size: 0.9rem; margin: 12px 0 4px; }
.case label span { font-weight: 400; color: var(--muted); }
.case-foot { display: flex; gap: 8px; margin-top: 14px; align-items: center; flex-wrap: wrap; }

/* Settings */
.setting { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 16px; margin-bottom: 14px; max-width: 760px; }
.setting p { margin: 4px 0 12px; color: var(--muted); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* Dialog */
dialog { border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); color: var(--ink); padding: 20px; width: min(520px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(20 30 29 / 0.45); }
dialog label { display: block; font-size: 0.9rem; font-weight: 700; margin-bottom: 12px; }
dialog input, dialog select, dialog textarea { display: block; width: 100%; margin-top: 4px; font-weight: 400; border: 1px solid var(--line); border-radius: var(--r-sm); padding: 8px 10px; background: var(--paper); }
dialog h2 { margin-top: 0; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dialog-actions { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.dialog-actions button { padding: 8px 14px; border-radius: var(--r-sm); border: 1px solid var(--line); background: none; cursor: pointer; }
.spacer { flex: 1; }

#toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: var(--r-sm); opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; }

@media (max-width: 720px) {
  .quarter { grid-template-columns: 1fr; }
  .quarter-stats { grid-template-columns: repeat(3, 1fr); min-width: 0; }
  .stat b { font-size: 1.5rem; }
  .task-actions { grid-row: auto; grid-column: 2 / 4; }
  .two { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
@media print {
  .views, .people, .task-actions, .day-foot, #banner, .quarter { display: none; }
  body { background: #fff; }
}
.dialog-actions button.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.dialog-actions button.danger { border-color: var(--warn); color: var(--warn); }

/* Topics guide */
.guide-week { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 18px 18px 8px; margin-bottom: 16px; scroll-margin-top: 16px; }
.guide-head { display: flex; flex-wrap: wrap; gap: 10px 16px; justify-content: space-between; align-items: flex-start; }
.guide-num { margin: 0 0 2px; font-family: var(--font-display); font-weight: 800; font-size: 2rem; line-height: 1; color: var(--accent); }
.guide-goal { margin: 10px 0 4px; }
.guide-sec { font-family: var(--font-display); font-weight: 700; font-size: 1rem; margin: 16px 0 6px; }
.topics { list-style: none; margin: 0 0 8px; padding: 0; columns: 2 300px; column-gap: 24px; }
.topics li { break-inside: avoid; padding: 3px 0; }
.topics label { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; }
.topics input { width: 18px; height: 18px; margin: 3px 0 0; flex: none; accent-color: var(--done); }
.topics input:checked + span { color: var(--muted); }
.topics.plain { list-style: disc; padding-left: 20px; }
.guide-next { border-style: dashed; border-color: var(--accent); }
.flow { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 12px 0; }
.flow span:not(.flow-arrow) { padding: 3px 10px; border-radius: 999px; background: var(--paper); border: 1px solid var(--line); font-size: 0.9rem; }
.flow .flow-next { border-color: var(--accent); color: var(--accent); font-weight: 700; }
.flow-arrow { color: var(--muted); }

/* Materials */
.mats { list-style: none; margin: 0 0 8px; padding: 0; }
.mat { display: flex; flex-wrap: wrap; gap: 6px 16px; justify-content: space-between; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 12px 14px; margin-bottom: 8px; }
.mat-main { flex: 1 1 320px; min-width: 0; }
.mat h4 { margin: 2px 0; font-size: 1rem; font-weight: 700; overflow-wrap: anywhere; }
.mat h4 a { color: var(--ink); text-decoration-color: var(--line); text-underline-offset: 3px; }
.mat h4 a:hover { text-decoration-color: var(--ink); }
.mat-note { margin: 4px 0 0; font-size: 0.9rem; color: var(--muted); }
.mat-actions { display: flex; gap: 2px; align-items: flex-start; }
.kind { display: inline-block; font-size: 0.75rem; font-weight: 700; color: var(--accent); border: 1px solid var(--line); border-radius: 999px; padding: 0 8px; }
.mat-group { margin: 22px 0 10px; }
.week-mats { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 12px 16px; margin-bottom: 14px; max-width: 760px; }
.week-mats summary { cursor: pointer; font-weight: 700; }
.week-mats ul { list-style: none; padding: 0; margin: 10px 0; }
.week-mats li { padding: 3px 0; }
fieldset.link-task { border: 1px solid var(--line); border-radius: var(--r-sm); padding: 10px 12px 2px; margin: 0 0 12px; }
fieldset.link-task legend { font-size: 0.9rem; font-weight: 700; padding: 0 4px; }
dialog label.inline { display: flex; gap: 8px; align-items: center; font-weight: 400; }
dialog label.inline input { width: auto; margin: 0; }
.mat .day-meta { display: block; margin: 2px 0 0; }
.mat-main > * { margin-top: 0; margin-bottom: 0; }
.mat h4 { margin: 4px 0 2px; }
