:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efede7;
  --text: #1d1c19;
  --muted: #6b6860;
  --border: #e0ddd5;
  --accent: #2f5bd3;
  --accent-soft: #e4ebfb;
  --maths: #2f5bd3;
  --cs: #0f8a6a;
  --done: #2e8b57;
  --doing: #c27c0e;
  --todo: #9a978f;
  --warn-bg: #fff4e0;
  --warn-text: #7a4b00;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151513;
    --surface: #1e1e1b;
    --surface-2: #272724;
    --text: #ecebe6;
    --muted: #9f9c93;
    --border: #34332f;
    --accent: #7c9cf0;
    --accent-soft: #232c45;
    --maths: #7c9cf0;
    --cs: #4cc6a3;
    --done: #5cc68b;
    --doing: #e7a43c;
    --todo: #77746c;
    --warn-bg: #3a2c12;
    --warn-text: #f3cf8f;
  }
}
:root[data-theme="dark"] {
  --bg: #151513; --surface: #1e1e1b; --surface-2: #272724; --text: #ecebe6; --muted: #9f9c93;
  --border: #34332f; --accent: #7c9cf0; --accent-soft: #232c45; --maths: #7c9cf0; --cs: #4cc6a3;
  --done: #5cc68b; --doing: #e7a43c; --todo: #77746c; --warn-bg: #3a2c12; --warn-text: #f3cf8f;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
.wrap { max-width: 920px; margin: 0 auto; padding: 0 16px; }

/* Header */
.top { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.top > .wrap:first-child { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding-top: 14px; flex-wrap: wrap; }
h1 { font-size: 20px; margin: 0; letter-spacing: -0.01em; }
.sub { margin: 0; color: var(--muted); font-size: 13px; }
.countdown { text-align: right; }
.countdown .num { font-size: 26px; font-weight: 700; line-height: 1; }
.countdown .lbl { color: var(--muted); font-size: 12px; }
.tabs { display: flex; gap: 4px; padding-top: 10px; overflow-x: auto; }
.tab {
  background: none; border: 0; padding: 8px 12px; font: inherit; color: var(--muted);
  border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap;
}
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

main { padding-top: 18px; padding-bottom: 32px; }
h2 { font-size: 17px; margin: 22px 0 10px; }
h3 { font-size: 15px; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px; }
.warn { background: var(--warn-bg); color: var(--warn-text); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; font-size: 14px; }

/* Progress */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.stat .row { display: flex; justify-content: space-between; align-items: baseline; }
.stat .big { font-size: 22px; font-weight: 700; }
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 8px; display: flex; }
.bar span { display: block; height: 100%; }
.bar .d { background: var(--done); }
.bar .g { background: var(--doing); }

/* Subject colouring */
.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 99px; color: #fff; vertical-align: 1px; }
.tag.maths { background: var(--maths); }
.tag.cs { background: var(--cs); }
.lvl { font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 99px; padding: 0 6px; margin-left: 6px; }

/* Plan */
.day { display: grid; grid-template-columns: 74px 1fr; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.day:first-child { border-top: 0; }
.day.today .date b { color: var(--accent); }
.date { font-size: 13px; color: var(--muted); }
.date b { display: block; font-size: 15px; color: var(--text); }
.task { display: flex; gap: 8px; align-items: flex-start; padding: 3px 0; }
.task .t { flex: 1; }
.task .h { color: var(--muted); font-size: 12px; white-space: nowrap; }
.task a { text-decoration: none; }
.task a:hover { text-decoration: underline; }
.task.review .t { font-style: italic; }

/* Controls */
.controls { display: flex; flex-wrap: wrap; gap: 14px; align-items: end; }
label.field { display: flex; flex-direction: column; font-size: 13px; color: var(--muted); gap: 4px; }
input[type="date"], input[type="number"], select {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 8px;
}
input[type="number"] { width: 80px; }
.btn { font: inherit; font-size: 13px; padding: 6px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Paper chooser */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip { display: flex; align-items: center; gap: 6px; border: 1px solid var(--border); border-radius: 99px; padding: 5px 12px; cursor: pointer; font-size: 14px; background: var(--surface); }
.chip input { accent-color: var(--accent); }
.chip.on { border-color: var(--accent); background: var(--accent-soft); }

/* Topics */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.paper-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin: 22px 0 8px; flex-wrap: wrap; }
.paper-head h2 { margin: 0; }
.topic { padding: 0; overflow: hidden; }
.topic-row { display: flex; align-items: center; gap: 10px; padding: 10px 14px; cursor: pointer; }
.topic-row .code { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; min-width: 34px; }
.topic-row .name { flex: 1; font-weight: 500; }
.topic.off .name { color: var(--muted); text-decoration: line-through; }
.status { font: inherit; font-size: 12px; font-weight: 600; border-radius: 99px; padding: 3px 10px; border: 1px solid currentColor; background: none; cursor: pointer; white-space: nowrap; }
.status.todo { color: var(--todo); }
.status.doing { color: var(--doing); }
.status.done { color: var(--done); }
.topic-body { border-top: 1px solid var(--border); padding: 12px 14px 14px; display: none; }
.topic.open .topic-body { display: block; }
.points { list-style: none; padding: 0; margin: 0 0 12px; }
.points li { display: flex; gap: 8px; align-items: flex-start; padding: 3px 0; }
.points input { margin-top: 4px; accent-color: var(--done); }
.points li.ticked span { color: var(--muted); text-decoration: line-through; }
.links { display: flex; flex-wrap: wrap; gap: 8px; }
.links a { font-size: 13px; text-decoration: none; border: 1px solid var(--border); border-radius: 8px; padding: 5px 10px; color: var(--text); background: var(--surface-2); }
.links a:hover { border-color: var(--accent); }
.include { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; margin-top: 10px; }

/* Resources */
.res-group { margin-bottom: 8px; }
.res-group h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 14px 0 6px; }
.res-list { list-style: none; margin: 0; padding: 0; }
.res-list li { padding: 4px 0; }
.tips li { margin-bottom: 6px; }

.foot { color: var(--muted); font-size: 12px; padding-bottom: 28px; }

@media (max-width: 520px) {
  .day { grid-template-columns: 1fr; gap: 4px; }
  .date b { display: inline; margin-right: 6px; }
  .countdown { text-align: left; }
}
