:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #2563eb;
  --n: #dc2626;   /* red */
  --w: #f59e0b;   /* amber */
  --c: #16a34a;   /* green */
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  padding-bottom: 88px;
}
#app { max-width: 1080px; margin: 0 auto; padding: 0 16px 40px; }
/* keep running prose readable even though the shell is wide */
.card > p, .lead, .legend { max-width: 72ch; }
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.6rem; margin: .2em 0; }
h2 { font-size: 1.15rem; margin: 0 0 .5em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.lead, .sub { color: var(--muted); }

/* top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0; margin-bottom: 4px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--bg); z-index: 5;
}
.brand { font-weight: 700; color: var(--ink); }
.topnav a { margin-left: 16px; font-weight: 600; }
.page-head { margin: 18px 0 8px; }
.page-head .sub { margin: .2em 0 0; }
.back { display: inline-block; margin: 14px 0 6px; font-weight: 600; }

/* cards */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; margin: 14px 0; box-shadow: var(--shadow);
}
.card ul { margin: .3em 0; padding-left: 1.2em; }
.card li { margin: .25em 0; }

/* landing */
.subject-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin-top: 10px; }
.subject-card {
  background: var(--card); border: 1px solid var(--line); border-left: 5px solid var(--accent);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-height: 96px;
}
.subject-card h2 { color: var(--ink); }
.subject-card p { color: var(--muted); margin: .2em 0 0; font-size: .85rem; }
.disabled .subject-card { opacity: .55; }
.soon { font-size: .6rem; text-transform: uppercase; letter-spacing: .05em; background: var(--line); color: var(--muted); padding: 2px 6px; border-radius: 6px; vertical-align: middle; }

/* toolbar / tier segmented control */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 8px 0 4px; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 8px 14px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--accent); color: #fff; }
.legend { color: var(--muted); font-size: .9rem; margin: 0; }
.legend-row { display: flex; align-items: center; justify-content: space-between; gap: 10px 14px; flex-wrap: wrap; margin: 8px 0; }
.legend-controls { display: flex; gap: 8px; }
.btn.sm { padding: 6px 11px; font-size: .82rem; }
.btn.ghost.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.row-parent { color: var(--muted); font-weight: 400; font-size: .86em; }

/* checklist rows */
.strand { margin: 18px 0; }
.strand-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 6px; }
.weight { color: var(--muted); font-size: .8rem; }
.rows { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); color: var(--ink); }
.row:first-child { border-top: 0; }
.row-title { flex: 1; font-weight: 500; }
.row-go { color: var(--muted); font-size: 1.3rem; }
.htag { display: inline-block; margin-left: 6px; font-size: .6rem; font-weight: 700; color: #fff; background: #7c3aed; border-radius: 5px; padding: 1px 5px; vertical-align: middle; }

/* status chips + row chip buttons */
.chip, .row-chip {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 8px; font-weight: 800; font-size: .85rem; color: #fff;
}
.row-chip { border: 0; cursor: pointer; width: 34px; height: 34px; font-size: 1rem; }
.st-n { background: var(--n); }
.st-w { background: var(--w); }
.st-c { background: var(--c); }

/* topic detail */
.topic-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin: 6px 0 4px; }
.crumb { color: var(--muted); font-size: .85rem; margin: 0 0 2px; }
.topic-head h1 { margin: 0 0 4px; }
.nextup { margin: 4px 0 0; }
.bigbadge {
  flex: 0 0 auto; border: 0; cursor: pointer; color: #fff; border-radius: 16px;
  width: 108px; min-height: 108px; padding: 12px 8px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; box-shadow: var(--shadow);
}
.bb-letter { font-size: 2.6rem; font-weight: 800; line-height: 1; }
.bb-label { font-size: .7rem; font-weight: 600; opacity: .95; text-align: center; }
.formulae li { font-variant-numeric: tabular-nums; }

/* sessions + links lists */
.sessions, .links { list-style: none; padding: 0; margin: 0 0 10px; }
.ses { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.ses:first-child { border-top: 0; }
.ses-when { font-weight: 600; min-width: 130px; }
.ses-type { color: var(--muted); flex: 1; }
.ses.done .ses-when, .ses.done .ses-type { text-decoration: line-through; color: var(--muted); }
.ses.future .ses-when { color: var(--accent); }
.links li { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.link-x { margin-left: auto; border: 0; background: transparent; color: var(--muted); font-size: 1rem; cursor: pointer; }
.add-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.add-row input, .add-row select { padding: 9px 10px; border: 1px solid var(--line); border-radius: 9px; font: inherit; }
.add-row input[type="text"], .add-row input[type="url"] { flex: 1; min-width: 160px; }

/* buttons */
.btn { border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-weight: 600; padding: 9px 14px; border-radius: 10px; cursor: pointer; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.big { font-size: 1.05rem; padding: 13px 20px; }
.update-foot { text-align: center; margin: 24px 0 10px; }
.update-foot p { margin: 6px 0 0; }

/* save bar */
.savebar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  background: #0f172a; color: #fff; padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}
.savebar-actions { display: flex; gap: 8px; }
.savebar .btn.ghost { color: #fff; border-color: #334155; }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 40; }
.modal { background: var(--card); border-radius: var(--radius); padding: 20px; max-width: 560px; width: 100%; max-height: 90vh; overflow: auto; }
.modal .cmd { background: #0f172a; color: #e2e8f0; padding: 10px 12px; border-radius: 8px; overflow-x: auto; font-size: .8rem; }
.export-text { width: 100%; height: 220px; margin: 10px 0; font-family: ui-monospace, Menlo, monospace; font-size: .75rem; border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* tables */
.tbl { width: 100%; border-collapse: collapse; }
.tbl td { padding: 6px 8px; border-top: 1px solid var(--line); vertical-align: top; }

/* calendar */
.three-day { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 12px 0; }
.day3 { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); }
.day3.is-today { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(37, 99, 235, .15), var(--shadow); }
.day3 h3 { margin: 0 0 8px; font-size: 1rem; display: flex; flex-direction: column; }
.day3 h3 span { font-weight: 500; color: var(--muted); font-size: .78rem; }
.cal-item { display: flex; gap: 8px; align-items: baseline; padding: 7px 8px; margin: 6px 0; border-left: 4px solid var(--accent); background: #f8fafc; border-radius: 8px; color: var(--ink); }
.cal-time { font-weight: 700; font-variant-numeric: tabular-nums; font-size: .85rem; }
.cal-topic { font-size: .85rem; }
.cal-topic em { color: var(--muted); font-style: normal; font-size: .75rem; }
.cal-subject { display: inline-block; background: var(--accent); color: #fff; font-size: .68rem; font-weight: 700; padding: 1px 7px; border-radius: 6px; margin-right: 6px; vertical-align: middle; }
.merge-link { margin-top: 26px; text-align: center; font-size: .85rem; }
.month { overflow-x: auto; }
.mrow.head, .mgrid { display: grid; grid-template-columns: repeat(7, 1fr); }
.mhd { text-align: center; font-size: .7rem; color: var(--muted); padding: 4px 0; font-weight: 700; }
.mcell { min-height: 62px; border: 1px solid var(--line); padding: 4px; }
.mcell.empty { background: #f8fafc; }
.mcell.today { background: #dbeafe; }
.mcell.today .mnum { background: var(--accent); color: #fff; border-radius: 999px; padding: 2px 8px; font-weight: 700; }
.mcell[data-date] { cursor: pointer; }
.mcell.selected { box-shadow: inset 0 0 0 2px var(--accent); }

/* two-column calendar body + Outlook-style day panel */
.cal-body { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
.day-panel { margin: 0; }
.day-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.day-head h2 { margin: 0; font-size: 1.05rem; }
.day-scroll { height: 560px; overflow-y: auto; position: relative; border-top: 1px solid var(--line); }
.next-day { position: absolute; left: 0; right: 0; background: rgba(148, 163, 184, .16); pointer-events: none; }
.next-day > span { position: absolute; top: 5px; left: 54px; font-size: .64rem; font-weight: 700; color: var(--muted); background: var(--card); padding: 1px 6px; border-radius: 6px; }
.day-event.next { opacity: .9; }
.day-grid { position: relative; margin-top: 8px; }
.now-line { position: absolute; left: 52px; right: 4px; border-top: 2px solid #ef4444; z-index: 3; }
.now-line::before { content: ''; position: absolute; left: -5px; top: -5px; width: 8px; height: 8px; border-radius: 50%; background: #ef4444; }
.hourline { position: absolute; left: 0; right: 0; border-top: 1px solid var(--line); }
.hlabel { position: absolute; top: -8px; left: 0; width: 48px; font-size: .66rem; color: var(--muted); background: var(--card); padding-right: 4px; }
.day-track { position: absolute; left: 54px; right: 4px; top: 0; bottom: 0; }
.day-event { position: absolute; left: 0; right: 0; box-sizing: border-box; background: var(--evt); color: #fff; border-radius: 8px; padding: 3px 8px; overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 1px; }
.day-event .de-time { font-size: .64rem; font-weight: 700; opacity: .95; font-variant-numeric: tabular-nums; }
.day-event .de-title { font-size: .74rem; line-height: 1.15; }
.day-event.done { opacity: .5; }
.day-event .cal-subject { background: rgba(255, 255, 255, .25); color: #fff; margin-right: 5px; }
@media (max-width: 700px) { .cal-body { grid-template-columns: 1fr; } }
.mnum { font-size: .8rem; color: var(--muted); }
.mdots { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 4px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* save toast + sign-in modal */
.toast { position: fixed; left: 50%; bottom: 88px; transform: translate(-50%, 12px); background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: .9rem; opacity: 0; transition: opacity .25s, transform .25s; z-index: 60; box-shadow: var(--shadow); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: #b91c1c; }
.modal.signin { text-align: center; max-width: 360px; }
.rb-list { margin: 8px 0 4px; max-height: 50vh; overflow-y: auto; }
.rb-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.rb-row:first-child { border-top: 0; }
.rb-title { font-weight: 500; }
.rb-sub { color: var(--muted); font-weight: 400; font-size: .85em; }
.rb-opts { display: flex; gap: 6px; flex: 0 0 auto; }
.rb-opt { border: 2px solid var(--line); background: var(--card); border-radius: 8px; padding: 4px 9px; cursor: pointer; display: flex; align-items: center; gap: 6px; font: inherit; }
.rb-opt.sel { border-color: var(--accent); background: #eff6ff; }
.rb-opt .who { font-size: .62rem; text-transform: uppercase; color: var(--muted); letter-spacing: .03em; }
.gbtn { display: flex; justify-content: center; margin: 14px 0; min-height: 40px; }

/* Progress chart */
.progress-modal { max-width: 640px; }
.pg-head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.pg-head h2 { margin: 0; flex: 1; font-size: 1.2rem; }
.pg-back { border: 0; background: transparent; font-size: 1.7rem; line-height: 1; cursor: pointer; color: var(--accent); padding: 0 6px; }
.pg-sub { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 2px 0 12px; }
.pg-sub[hidden] { display: none; }
#pg-overall { font-weight: 700; }
.pg-hint { color: var(--muted); font-size: .85rem; }
.pg-chart { min-height: 60px; }
.pg-chart text.pg-label { font: 600 .82rem -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; fill: var(--ink); }
.pg-chart text.pg-pct { font: 700 .72rem -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; fill: var(--muted); }
.pg-chart rect.pg-track { fill: #eef2f7; }
.pg-chart rect.pg-track.hot { fill: #e2e8f0; }
.pg-legend { display: flex; gap: 16px; margin-top: 14px; color: var(--muted); font-size: .8rem; }
.pg-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: middle; }
.pg-prow { margin: 10px 0; }
.pg-prow.click { cursor: pointer; }
.pg-plabel { font-weight: 600; font-size: .82rem; margin-bottom: 3px; }
.pg-ppct { color: var(--muted); font-weight: 700; font-size: .75rem; }
.pg-pbar { display: flex; height: 16px; border-radius: 4px; overflow: hidden; background: #eef2f7; }
.pg-pbar span { transition: width .5s ease; }


/* important dates (landing + subject pages) */
.idates { margin: 22px 0 10px; }
.page-head + .idates { margin-top: 12px; }
.idates-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.idates-head h2 { margin: 0; }
.idate-list { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.idate {
  display: grid; grid-template-columns: minmax(9.5rem, 14rem) minmax(0, 1fr) auto; gap: 4px 14px; align-items: center;
  padding: 10px 14px; border-top: 1px solid var(--line); border-left: 5px solid var(--lvl);
}
.idate:first-child { border-top: 0; }
.idate-date { font-weight: 600; }
.idate-session { display: block; font-size: .78rem; color: var(--muted); }
.idate-subj { display: inline-block; font-size: .72rem; font-weight: 700; color: #fff; background: var(--subj); border-radius: 999px; padding: 1px 8px; margin-right: 8px; vertical-align: 1px; }
.idate-count { text-align: right; }
.idate-days { display: inline-block; font-weight: 700; font-size: .85rem; padding: 2px 10px; border-radius: 999px; background: var(--lvl-bg); color: var(--lvl-ink); white-space: nowrap; font-variant-numeric: tabular-nums; }
.lvl-red    { --lvl: var(--n); --lvl-bg: #fee2e2; --lvl-ink: #b91c1c; }
.lvl-yellow { --lvl: var(--w); --lvl-bg: #fef3c7; --lvl-ink: #92400e; }
.lvl-green  { --lvl: var(--c); --lvl-bg: #dcfce7; --lvl-ink: #166534; }
.lvl-past   { --lvl: var(--line); --lvl-bg: var(--bg); --lvl-ink: var(--muted); color: var(--muted); }
.idates-more { margin-top: 8px; }
@media (max-width: 560px) {
  .idate { grid-template-columns: minmax(0, 1fr); }
  .idate-count { text-align: left; }
}
.loading, .error { padding: 40px 0; color: var(--muted); }
.error pre { white-space: pre-wrap; color: var(--n); }

/* phone */
@media (max-width: 560px) {
  .three-day { grid-template-columns: 1fr; }
  .topic-head { flex-direction: column-reverse; align-items: stretch; }
  .bigbadge { width: 100%; flex-direction: row; min-height: 76px; justify-content: center; gap: 14px; }
  .bb-letter { font-size: 2rem; }
  .ses-when { min-width: 108px; }
}
