:root {
  --bg: #f5f5f7; --card: #ffffff; --text: #1d1d1f; --muted: #6e6e73; --line: rgba(0,0,0,.08);
  --accent: #4b8a91; --accent-ink: #ffffff; --done: #8e8e93; --chip: rgba(0,0,0,.05);
  --high: #ff3b30; --medium: #ff9f0a; --low: #0a84ff; --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000; --card: #1c1c1e; --text: #f5f5f7; --muted: #98989d; --line: rgba(255,255,255,.1);
    --accent: #7fbcc3; --accent-ink: #00191c; --done: #636366; --chip: rgba(255,255,255,.08);
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 17px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  min-height: 100vh; display: flex; flex-direction: column;
}
a { color: var(--accent); }
[hidden] { display: none !important; }

.bar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px max(16px, env(safe-area-inset-left)); padding-top: max(12px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: -.01em; color: var(--text); text-decoration: none; font-size: 17px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.pill {
  display: inline-flex; align-items: center; height: 32px; padding: 0 14px; border-radius: 16px;
  background: var(--chip); color: var(--text); text-decoration: none; font-size: 14px; font-weight: 600; white-space: nowrap;
}
.pill-primary { background: var(--accent); color: var(--accent-ink); }

main { flex: 1; width: 100%; max-width: 880px; margin: 0 auto; padding: 24px 16px 48px; }
.status { text-align: center; color: var(--muted); padding: 80px 16px; }
.status h1 { color: var(--text); font-size: 22px; margin: 0 0 8px; }
.spinner {
  width: 28px; height: 28px; margin: 0 auto 16px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.crumbs { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 16px; font-size: 14px; color: var(--muted); }
.crumbs button { all: unset; cursor: pointer; color: var(--accent); }
.crumbs button:focus-visible { outline: 2px solid var(--accent); border-radius: 4px; }

.head { margin-bottom: 20px; }
.head h1 { font-size: 30px; line-height: 1.15; letter-spacing: -.02em; margin: 0 0 6px; overflow-wrap: anywhere; }
.meta { color: var(--muted); font-size: 14px; }
.colour { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 8px; vertical-align: 1px; }

.seg { display: inline-flex; background: var(--chip); border-radius: 9px; padding: 2px; margin: 4px 0 18px; }
.seg button { all: unset; cursor: pointer; padding: 5px 14px; border-radius: 7px; font-size: 14px; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

.pages { display: flex; flex-direction: column; gap: 18px; align-items: center; }
.page { width: 100%; background: #fff; border-radius: 6px; box-shadow: var(--shadow); overflow: hidden; border: 1px solid var(--line); }
.page img { display: block; width: 100%; height: 100%; object-fit: contain; }

.doc { background: var(--card); border-radius: 14px; padding: clamp(20px, 5vw, 48px); box-shadow: var(--shadow); overflow-wrap: anywhere; }
.doc h1 { font-size: 1.9em; line-height: 1.2; margin: .8em 0 .35em; }
.doc h2 { font-size: 1.45em; line-height: 1.25; margin: .8em 0 .3em; }
.doc h3 { font-size: 1.15em; margin: .7em 0 .25em; }
.doc p { margin: 0 0 .55em; }
.doc p.gap { margin: 0; line-height: .9; }
.doc img { max-width: 100%; height: auto; border-radius: 6px; display: block; margin: .4em 0; }
.doc > :first-child { margin-top: 0; }

.section { margin: 0 0 22px; }
.section h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px 4px; font-weight: 600; }
.tasks { list-style: none; margin: 0; padding: 0; background: var(--card); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.tasks .tasks { box-shadow: none; border-radius: 0; background: transparent; padding-left: 28px; }
.task { display: grid; grid-template-columns: 22px 1fr auto; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); align-items: start; }
.tasks > li:first-child > .task { border-top: 0; }
.box { width: 20px; height: 20px; border-radius: 50%; border: 1.6px solid var(--muted); margin-top: 2px; display: grid; place-items: center; }
.box.done { background: var(--accent); border-color: var(--accent); }
.box.done::after { content: ""; width: 9px; height: 5px; border: 2px solid var(--accent-ink); border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px, -1px); }
.box.note { border: 0; }
.box.note::after { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.title { overflow-wrap: anywhere; }
.task.done .title { color: var(--done); text-decoration: line-through; }
.sub { color: var(--muted); font-size: 14px; margin-top: 2px; white-space: pre-wrap; overflow-wrap: anywhere; }
.due { color: var(--muted); font-size: 13px; white-space: nowrap; margin-top: 2px; }
.due.overdue { color: var(--high); }
.flag { font-size: 12px; font-weight: 700; margin-right: 6px; }
.flag.high { color: var(--high); } .flag.medium { color: var(--medium); } .flag.low { color: var(--low); }
.empty { color: var(--muted); text-align: center; padding: 32px 0; }

.items { list-style: none; margin: 0; padding: 0; background: var(--card); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.items button {
  all: unset; box-sizing: border-box; cursor: pointer; width: 100%; display: grid; grid-template-columns: 28px 1fr auto;
  gap: 12px; align-items: center; padding: 14px 16px; border-top: 1px solid var(--line);
}
.items li:first-child button { border-top: 0; }
.items button:hover { background: var(--chip); }
.items button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.icon { font-size: 20px; text-align: center; }
.items .when { color: var(--muted); font-size: 13px; }
.chev { color: var(--muted); }

.foot { text-align: center; color: var(--muted); font-size: 13px; padding: 24px 16px max(24px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.foot p { margin: 4px 0; }
.lock { filter: grayscale(1); }

@media (max-width: 520px) {
  .head h1 { font-size: 26px; }
  #get-app { display: none; }
  .task { padding: 11px 14px; }
}
@media print {
  .bar, .foot, .seg, .crumbs { display: none !important; }
  body { background: #fff; }
  .doc, .tasks, .items, .page { box-shadow: none; }
}
.doc a:not([href]) { color: inherit; }
