/* Layout concept: a lab logbook. A summary header with a 30-cell session strip, then six week
   ledgers of ruled rows. Each row opens into the session sheet: readings, quiz, answer key, notes. */
:root {
  --bg: #F3F6F9;
  --surface: #FFFFFF;
  --ink: #14202E;
  --muted: #566678;
  --line: #D9E1EA;
  --soft: #E8EEF4;
  --focus: #1F5FBF;
  --swe: #2E5AAC;
  --cloud: #1B8449;
  --net: #B45F06;
  --cyber: #BE3A2E;
  --mixed: #6D28A9;
  --good: #1B8449;
  --bad: #BE3A2E;
  --display: 'Bricolage Grotesque', 'Segoe UI', system-ui, sans-serif;
  --body: 'IBM Plex Sans', 'Segoe UI', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0D131A; --surface: #141C26; --ink: #E7EEF6; --muted: #93A3B6; --line: #263241; --soft: #1B2531; --focus: #7AA5F0;
    --swe: #7AA5F0; --cloud: #52C98A; --net: #F2A552; --cyber: #F08577; --mixed: #BE95F2; --good: #52C98A; --bad: #F08577;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0D131A; --surface: #141C26; --ink: #E7EEF6; --muted: #93A3B6; --line: #263241; --soft: #1B2531; --focus: #7AA5F0;
  --swe: #7AA5F0; --cloud: #52C98A; --net: #F2A552; --cyber: #F08577; --mixed: #BE95F2; --good: #52C98A; --bad: #F08577;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-padding-top: 16px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.5;
  padding-inline: max(16px, env(safe-area-inset-left));
  padding-block: 28px 56px;
}
[hidden] { display: none !important; }
.wrap { max-width: 980px; margin: 0 auto; display: flex; flex-direction: column; gap: 28px; }
h1, h2, h3 { font-family: var(--display); margin: 0; text-wrap: balance; }
button, select, input, textarea { font: inherit; color: inherit; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--muted); margin: 0; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* header */
.top { display: flex; flex-direction: column; gap: 6px; }
.topline { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
h1 { font-size: clamp(1.9rem, 5vw, 2.6rem); font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.sub { color: var(--muted); margin: 0; max-width: 62ch; }
.theme { flex: none; font-size: 13px; }

.summary { display: flex; flex-direction: column; gap: 22px; padding-block: 20px; border-block: 1px solid var(--line); }
.stats { display: flex; flex-wrap: wrap; gap: 18px 44px; }
.stat { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.lbl { font-family: var(--mono); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.val { font-family: var(--display); font-weight: 700; font-size: 2rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.val small { font-size: 1rem; color: var(--muted); font-weight: 600; }
.next { margin: 0; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; }
.next button { background: none; border: 0; padding: 0; text-align: left; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line); }
.next button:hover { text-decoration-color: currentColor; }

.strip { display: flex; flex-wrap: wrap; gap: 12px 20px; }
.wkgrp { display: flex; align-items: center; gap: 8px; }
.wl { font-family: var(--mono); font-size: 11px; color: var(--muted); width: 1.6rem; }
.cells { display: flex; gap: 4px; }
.cell {
  --c: var(--swe);
  width: 24px; height: 24px; padding: 0; cursor: pointer;
  border: 1.5px solid color-mix(in srgb, var(--c) 40%, var(--line));
  border-radius: 5px; background: transparent;
}
[data-track="swe"] { --c: var(--swe); }
[data-track="cloud"] { --c: var(--cloud); }
[data-track="net"] { --c: var(--net); }
[data-track="cyber"] { --c: var(--cyber); }
[data-track="mixed"] { --c: var(--mixed); }
.cell[data-status="doing"] { border-color: var(--c); background: linear-gradient(135deg, var(--c) 50%, transparent 50%); }
.cell[data-status="done"] { border-color: var(--c); background: var(--c); }
.cell.next { outline: 2px solid var(--ink); outline-offset: 2px; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; background: var(--c); display: inline-block; }

.howto { color: var(--muted); }
.howto p { margin: 10px 0 0; max-width: 70ch; }
details > summary { cursor: pointer; color: var(--muted); }

/* toolbar */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: transparent; padding: 7px 13px; cursor: pointer; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.spacer { flex: 1 1 auto; }
#sync { font-family: var(--mono); font-size: 12px; color: var(--muted); }

.btn { display: inline-block; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 14px; cursor: pointer; line-height: 1.4; }
.btn:hover { border-color: var(--muted); }
.btn.danger { color: var(--bad); }
.btn.danger.armed { background: var(--bad); color: var(--bg); border-color: var(--bad); }

/* ledgers */
.weeks { display: flex; flex-direction: column; gap: 30px; }
.weekhead { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; padding-bottom: 8px; border-bottom: 2px solid var(--ink); }
.weekhead h2 { font-size: 1.3rem; font-weight: 700; }
.weekhead .theme-t { color: var(--muted); }
.weekhead .count { margin-left: auto; font-family: var(--mono); font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

.row { border-bottom: 1px solid var(--line); transition: background-color .4s; }
.rowhead { display: grid; grid-template-columns: 78px minmax(0, 1fr) auto; gap: 8px 14px; align-items: center; padding: 12px 2px; }
.id { display: flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: 12px; color: var(--muted); white-space: nowrap; }
.dot { width: 11px; height: 11px; border-radius: 50%; border: 1.5px solid var(--c); flex: none; }
.row[data-status="doing"] .dot { background: linear-gradient(90deg, var(--c) 50%, transparent 50%); }
.row[data-status="done"] .dot { background: var(--c); }
.topic { display: flex; align-items: baseline; gap: 4px 10px; min-width: 0; background: none; border: 0; padding: 0; text-align: left; cursor: pointer; flex-wrap: wrap; }
.pill { font-family: var(--mono); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); padding: 2px 8px; border-radius: 4px; }
.tt { font-weight: 500; min-width: 0; overflow-wrap: anywhere; }
.topic:hover .tt { text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line); }
.chev { display: inline-block; width: 0.6em; color: var(--muted); transition: transform .15s; font-family: var(--mono); }
.row.open .chev { transform: rotate(90deg); }
.row[data-status="done"] .tt { color: var(--muted); }

.ctl { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ctl select, .ctl input[type="number"], .ctl button, .sheet textarea {
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 6px 9px;
}
.ctl select, .ctl button { cursor: pointer; }
.score { display: inline-flex; align-items: center; gap: 4px; font-family: var(--mono); color: var(--muted); }
.score input { width: 3.4em; text-align: center; font-family: var(--mono); padding-inline: 4px; }
.pct { font-family: var(--mono); font-size: 12px; min-width: 3.2em; color: var(--muted); font-variant-numeric: tabular-nums; }
.rev[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.nbtn[data-has="1"]::after { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--c); margin-left: 7px; vertical-align: middle; }
.row.flash { background: color-mix(in srgb, var(--c) 10%, transparent); }
.empty { color: var(--muted); padding-block: 24px; text-align: center; }

/* session sheet */
.sheet {
  margin: 0 0 18px 0; padding: 18px 20px 20px;
  background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--c); border-radius: 0 8px 8px 0;
  display: flex; flex-direction: column; gap: 22px;
}
.sec { display: flex; flex-direction: column; gap: 10px; }
.sechead { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 12px; }
.sechead h3 { font-size: 1.02rem; font-weight: 700; }
.sechead .lbl { font-size: 10.5px; }
.sechead .grow { flex: 1 1 auto; }

.reads { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.read { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 10px; }
.read input[type="checkbox"] { margin: 4px 0 0; width: 16px; height: 16px; accent-color: var(--c); cursor: pointer; }
.read .rt { overflow-wrap: anywhere; }
.read.ticked .rt { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--line); }
.links { grid-column: 2; display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.links a {
  display: inline-flex; flex-wrap: wrap; align-items: baseline; gap: 0 6px; max-width: 100%;
  padding: 4px 10px; border-radius: 6px; text-decoration: none;
  border: 1px solid color-mix(in srgb, var(--c) 35%, var(--line));
  background: color-mix(in srgb, var(--c) 7%, var(--surface));
  font-size: 13.5px; overflow-wrap: anywhere;
}
.links a:hover { border-color: var(--c); }
.links a .dom { font-family: var(--mono); font-size: 11px; color: var(--muted); white-space: nowrap; }
.links a .arr { color: var(--c); font-family: var(--mono); font-size: 12px; }
.links a.internal { border-style: dashed; background: transparent; font-family: var(--mono); font-size: 12px; }
.offline { grid-column: 2; font-family: var(--mono); font-size: 11px; color: var(--muted); }
.rnote { grid-column: 2; font-size: 13px; color: var(--muted); margin: 4px 0 0; padding-left: 10px; border-left: 2px solid var(--line); }

.quiz { margin: 0; padding-left: 1.6em; display: flex; flex-direction: column; gap: 14px; }
.quiz > li { padding-left: 4px; }
.quiz > li::marker { font-family: var(--mono); font-size: 13px; color: var(--muted); }
.ans {
  margin-top: 8px; padding: 8px 12px; border-radius: 6px;
  background: var(--soft); border-left: 3px solid var(--c);
  display: flex; flex-direction: column; gap: 8px;
}
.ans .lbl { font-size: 10px; }
.ans p { margin: 0; overflow-wrap: anywhere; }
.mark { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.mark button { font-size: 13px; padding: 3px 10px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; color: var(--muted); }
.mark button[data-v="1"][aria-pressed="true"] { background: var(--good); border-color: var(--good); color: var(--bg); }
.mark button[data-v="0"][aria-pressed="true"] { background: var(--bad); border-color: var(--bad); color: var(--bg); }
.revealbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.reveal { font-weight: 600; }
.reveal[aria-expanded="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.tally { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.notes textarea { width: 100%; min-height: 5em; resize: vertical; line-height: 1.45; }
.notes .meta { font-family: var(--mono); font-size: 11px; color: var(--muted); min-height: 1em; }
.sheetfoot { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

/* appendix */
.appendix { display: flex; flex-direction: column; gap: 14px; padding-top: 18px; border-top: 2px solid var(--ink); }
.appendix h2 { font-size: 1.3rem; }
.lib { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 18px 28px; }
.libcol { display: flex; flex-direction: column; gap: 10px; }
.libcol h3 { font-size: 1rem; display: flex; align-items: center; gap: 8px; }
.libcol h3 i { width: 10px; height: 10px; border-radius: 3px; background: var(--c); display: inline-block; }
.libcol ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.libcol li { display: flex; flex-direction: column; gap: 2px; }
.libcol .links { margin-top: 2px; }
.checklist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.checklist label { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; cursor: pointer; }
.checklist input { margin: 4px 0 0; width: 16px; height: 16px; accent-color: var(--mixed); }
.checklist input:checked + span { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--line); }

/* export */
.export { display: flex; flex-direction: column; gap: 12px; padding-top: 18px; border-top: 1px solid var(--line); }
.export h2 { font-size: 1.15rem; }
.export h3 { font-size: 1rem; margin-top: 8px; }
.export p { margin: 0; color: var(--muted); max-width: 66ch; }
.export .acts { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.export textarea { width: 100%; min-height: 14em; font-family: var(--mono); font-size: 12px; line-height: 1.5; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 10px; resize: vertical; margin-top: 10px; }
.foot { font-size: 13px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 14px; }

@media (max-width: 680px) {
  .rowhead { grid-template-columns: auto minmax(0, 1fr); }
  .ctl { grid-column: 1 / -1; }
  .weekhead .count { margin-left: 0; width: 100%; }
  .sheet { padding: 14px 14px 16px; margin-inline: -4px; }
  .stats { gap: 14px 28px; }
  .val { font-size: 1.7rem; }
  .seg button { padding: 7px 10px; }
}
@media (prefers-reduced-motion: reduce) {
  .row, .chev { transition: none; }
}
@media print {
  .toolbar, .ctl, .export, .theme, .strip, .legend { display: none !important; }
  .sheet { border: 0; padding: 0; }
}
