:root{
  --bg:#f5f5f7; --bg2:#ececf0; --card:#ffffff; --card2:#f5f5f7;
  --line:#e3e3e8; --txt:#1d1d1f; --muted:#6e6e73; --muted2:#a1a1a6;
  --accent:#0071e3; --accent2:#0077ed;
  --green:#248a3d; --green-fill:#34c759; --green-dim:#e7f7ec;
  --red:#d70015; --red-dim:#fdeceb;
  --amber:#b25000; --amber-fill:#ff9500; --amber-dim:#fff3e2;
  --purple:#8944ab; --purple-fill:#af52de;
  --radius:18px;
  --shadow:0 1px 2px rgba(0,0,0,.05), 0 10px 30px rgba(0,0,0,.05);
}
*{box-sizing:border-box}
html,body{margin:0;padding:0}
body{
  font-family:-apple-system,BlinkMacSystemFont,"SF Pro Text","SF Pro Display","Segoe UI",Roboto,Helvetica,Arial,sans-serif;
  background:var(--bg); color:var(--txt); min-height:100vh; -webkit-font-smoothing:antialiased;
}

/* ---------- top bar ---------- */
.topbar{
  position:sticky; top:0; z-index:20;
  background:rgba(255,255,255,.72); backdrop-filter:saturate(180%) blur(20px);
  border-bottom:1px solid var(--line);
  padding:12px 22px; display:flex; align-items:center; gap:24px; flex-wrap:wrap;
}
.brand{display:flex; align-items:center; gap:12px}
.brand .logo{font-size:28px}
.brand h1{margin:0; font-size:17px; font-weight:600; letter-spacing:-.01em}
.brand .tagline{font-size:12px; color:var(--muted)}
.tabs{display:flex; gap:4px; flex-wrap:wrap; margin-left:auto}
.tab{
  background:transparent; color:var(--muted); border:none;
  padding:7px 14px; border-radius:980px; font-size:14px; font-weight:500; cursor:pointer; transition:.15s;
}
.tab:hover{color:var(--txt); background:rgba(0,0,0,.04)}
.tab.active{color:#fff; background:var(--accent)}

main{max-width:1080px; margin:0 auto; padding:28px 22px 64px}
.foot{max-width:1080px; margin:0 auto; padding:0 22px 32px; color:var(--muted2); font-size:12px; text-align:center}
.foot .donate{display:inline-flex; align-items:center; gap:5px; margin-left:12px; color:#0070ba; text-decoration:none; font-weight:600}
.foot .donate svg{width:12px; height:12px}
.foot .donate:hover{color:#003087; text-decoration:underline}
.foot .tour{color:var(--muted2); text-decoration:underline; text-underline-offset:2px}
.foot .tour:hover{color:var(--txt)}
.foot .fineprint{margin-top:8px; font-size:11px; opacity:.75}

/* ---------- recommended resources ---------- */
.res-item{display:block; padding:9px 0; border-bottom:1px solid var(--line); text-decoration:none; color:var(--txt)}
.res-item:last-of-type{border-bottom:none}
.res-item:hover .res-name{color:var(--accent); text-decoration:underline}
.res-name{display:block; font-weight:600; font-size:14px}
.res-why{display:block; color:var(--muted); font-size:12.5px; margin-top:2px}

/* ---------- backup warning banner ---------- */
.card.backup-banner{margin-bottom:16px; border-color:#f0c86e; background:#fff7e6; font-size:14px; line-height:1.5}
.card.backup-banner b{color:#8a5a00}

/* ---------- first-visit tutorial ---------- */
.tuto-card{max-width:420px; text-align:center; padding:34px 30px 26px}
.tuto-icon{font-size:44px; line-height:1}
.tuto-card h3{margin:14px 0 8px; font-size:20px}
.tuto-txt{color:var(--muted); font-size:14px; line-height:1.55; min-height:88px}
.tuto-dots{display:flex; gap:7px; justify-content:center; margin:18px 0 20px}
.tuto-dots span{width:8px; height:8px; border-radius:50%; background:var(--line); transition:.15s}
.tuto-dots span.on{background:var(--accent)}
.tuto-actions{display:flex; justify-content:space-between; align-items:center; gap:10px}

/* ---------- cards & layout ---------- */
.card{background:var(--card); border:1px solid var(--line); border-radius:var(--radius); padding:22px; box-shadow:var(--shadow)}
.grid{display:grid; gap:16px}
.grid-3{grid-template-columns:repeat(3,1fr)}
.grid-2{grid-template-columns:repeat(2,1fr)}
.section-title{font-size:12px; text-transform:uppercase; letter-spacing:.04em; color:var(--muted); margin:0 0 14px; font-weight:600}
h2.view-title{font-size:26px; margin:0 0 4px; font-weight:600; letter-spacing:-.02em}
.view-sub{color:var(--muted); margin:0 0 24px; font-size:14px; line-height:1.5}

/* ---------- stat tiles ---------- */
.stat{display:flex; flex-direction:column; gap:6px}
.stat .big{font-size:36px; font-weight:600; line-height:1; letter-spacing:-.02em}
.stat .lbl{font-size:13px; color:var(--muted); font-weight:500}
.lib-metrics{display:flex; gap:30px; flex-wrap:wrap}
.lib-stat .lib-n{font-size:26px; font-weight:600; letter-spacing:-.01em; line-height:1}
.lib-stat .lib-l{font-size:12px; color:var(--muted); margin-top:3px}
.stat .sub{font-size:12px; color:var(--muted2)}
.pill{display:inline-flex; align-items:center; gap:6px; padding:4px 11px; border-radius:980px; font-size:13px; font-weight:600}
.pill.green{background:var(--green-dim); color:var(--green)}
.pill.red{background:var(--red-dim); color:var(--red)}
.pill.amber{background:var(--amber-dim); color:var(--amber)}
.pill.blue{background:#e8f2ff; color:var(--accent)}

/* ---------- progress bars ---------- */
.bar{height:12px; background:var(--bg2); border-radius:980px; overflow:hidden}
.bar > span{display:block; height:100%; background:var(--accent); border-radius:980px; transition:width .4s}
.bar.thin{height:7px}
.bar.green > span{background:var(--green-fill)}
.rowbar{display:flex; align-items:center; gap:12px}
.rowbar .bar{flex:1}
.pct{font-variant-numeric:tabular-nums; font-size:13px; color:var(--muted); min-width:44px; text-align:right}

/* ---------- subjects ---------- */
.subj-row{display:flex; align-items:center; gap:14px; padding:13px 4px; border-bottom:1px solid var(--line); cursor:pointer; transition:.12s}
.subj-row:last-child{border-bottom:none}
.subj-row:hover{background:var(--card2); border-radius:10px}
.subj-name{min-width:220px; font-weight:600; font-size:14px}
.subj-name small{display:block; color:var(--muted); font-weight:400; font-size:12px}
.subj-count{color:var(--muted); font-size:13px; min-width:80px; text-align:right; font-variant-numeric:tabular-nums}
.yield-tag{font-size:10px; padding:2px 7px; border-radius:6px; background:#e8f2ff; color:var(--accent); text-transform:uppercase; letter-spacing:.03em}

/* ---------- chapter list ---------- */
.chap{display:flex; align-items:center; gap:10px; padding:10px 4px; border-bottom:1px solid var(--line)}
.chap:last-child{border-bottom:none}
.chap.done{opacity:.5}
.chap .cname{flex:1; font-size:14px}
.chap .cname .trunc{color:var(--amber)}
.checks{display:flex; gap:6px}
.chk{
  width:32px;height:32px;border-radius:9px;border:1px solid var(--line);background:#f4f4f7;
  color:var(--muted);cursor:pointer;font-size:14px;display:flex;align-items:center;justify-content:center;transition:.12s;
}
.chk:hover{border-color:var(--accent); color:var(--accent)}
.chk.on{background:var(--accent);color:#fff;border-color:var(--accent)}
.chk.on.rev{background:var(--amber-fill);border-color:var(--amber-fill)}
.chk.on.flash{background:var(--purple-fill);border-color:var(--purple-fill)}
.score-in{width:54px;background:#f4f4f7;border:1px solid var(--line);color:var(--txt);border-radius:9px;padding:6px;font-size:13px;text-align:center}
.score-in:focus{outline:none;border-color:var(--accent)}

/* ---------- calendar ---------- */
.cal-head{display:flex; align-items:center; justify-content:space-between; margin-bottom:16px}
.cal-head h3{margin:0; font-size:18px; text-transform:capitalize; font-weight:600}
.cal-nav button{background:var(--card2);border:1px solid var(--line);color:var(--txt);border-radius:9px;padding:6px 12px;cursor:pointer;font-size:15px;font-weight:500}
.cal-nav button:hover{background:#ececf0}
/* the grid scrolls inside its card on narrow screens instead of clipping Fri–Sun */
.cal-scroll{overflow-x:auto; -webkit-overflow-scrolling:touch}
.cal-grid{display:grid; grid-template-columns:repeat(7,1fr); gap:6px; min-width:560px}
.cal-dow{text-align:center; font-size:11px; color:var(--muted); text-transform:uppercase; letter-spacing:.03em; padding-bottom:4px; font-weight:600}
.cal-cell{
  min-height:66px; border:1px solid var(--line); border-radius:11px; padding:6px; background:#fff;
  display:flex; flex-direction:column; gap:1px; cursor:pointer; transition:.12s; position:relative;
}
.cal-cell:hover{border-color:var(--accent)}
.cal-cell.empty{background:transparent; border:none; cursor:default}
.cal-cell.rest{background:var(--card2); opacity:.7; cursor:default}
.cal-cell.today{box-shadow:0 0 0 2px var(--accent); border-color:var(--accent)}
.cal-cell.ok{background:var(--green-dim); border-color:#bfe6c9}
.cal-cell.late{background:var(--red-dim); border-color:#f3c3c0}
.cal-cell.late-b{box-shadow:inset 0 0 0 1.5px rgba(215,0,21,.55)}
.cal-cell .dnum{font-size:13px; font-weight:600}
.cal-cell .cal-subj{font-size:9px; line-height:1.15; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:100%; margin-top:1px; font-weight:600}
.cal-cell .dtarget{font-size:11px; color:var(--muted)}
.cal-cell .cal-rev{color:var(--purple); font-size:10px; font-weight:600}
.cal-cell .dot{position:absolute; top:6px; right:6px; width:8px; height:8px; border-radius:50%}
.dot.green{background:var(--green-fill)} .dot.red{background:#ff3b30} .dot.blue{background:var(--accent)}
.legend{display:flex; gap:16px; flex-wrap:wrap; margin-top:16px; font-size:12px; color:var(--muted)}
.legend span{display:inline-flex;align-items:center;gap:6px}
.legend i{width:12px;height:12px;border-radius:3px;display:inline-block}
.subj-legend{display:flex; flex-wrap:wrap; gap:8px 14px; margin-top:12px; padding-top:12px; border-top:1px solid var(--line)}
.subj-legend span{display:inline-flex; align-items:center; gap:6px; font-size:11px; color:var(--muted)}
.subj-legend i{width:11px; height:11px; border-radius:3px; display:inline-block; flex:none}

/* ---------- modal ---------- */
.modal{position:fixed; inset:0; background:rgba(0,0,0,.32); display:flex; align-items:center; justify-content:center; z-index:50; padding:20px; backdrop-filter:blur(3px)}
.modal.hidden{display:none}
.modal-card{background:var(--card); border-radius:20px; max-width:640px; width:100%; max-height:84vh; overflow:auto; padding:26px; position:relative; box-shadow:0 20px 60px rgba(0,0,0,.25)}
.modal-close{position:absolute; top:16px; right:16px; background:var(--card2); border:none; color:var(--muted); width:32px; height:32px; border-radius:50%; cursor:pointer; font-size:15px; z-index:2}
.modal-close:hover{background:#e3e3e8}
.modal-foot{position:sticky; bottom:-26px; margin:16px -26px -26px; padding:14px 26px; background:var(--card2); border-top:1px solid var(--line); border-radius:0 0 20px 20px; display:flex; align-items:center; gap:16px; flex-wrap:wrap}
.legend2{display:flex; gap:14px; flex-wrap:wrap; font-size:12px; color:var(--muted)}
.legend2 b{color:var(--txt); font-weight:600}
.modal-foot .btn{margin-left:auto; white-space:nowrap}
.saved-btn{background:var(--green-fill)!important}
.rev-sec{margin-top:22px}
.rev-row{display:flex; align-items:center; gap:10px; padding:9px 4px; border-bottom:1px solid var(--line)}
.rev-row:last-child{border:none}

/* ---------- misc ---------- */
.btn{background:var(--accent); color:#fff; border:none; padding:9px 17px; border-radius:980px; cursor:pointer; font-size:14px; font-weight:500; transition:.12s}
.btn:hover{background:var(--accent2)}
.btn.ghost{background:var(--card2); border:1px solid var(--line); color:var(--txt)}
.btn.ghost:hover{background:#ececf0}
.btn.danger{background:var(--red)}
.field{display:flex; flex-direction:column; gap:6px; margin-bottom:16px}
.field label{font-size:13px; color:var(--muted); font-weight:500}
.field input,.field select{background:#fff; border:1px solid var(--line); color:var(--txt); padding:10px; border-radius:10px; font-size:14px}
.field input:focus,.field select:focus{outline:none; border-color:var(--accent)}
.hint{font-size:12px; color:var(--muted2); line-height:1.5}
.empty-state{text-align:center; color:var(--muted); padding:36px 10px; font-size:14px}
.today-chap{display:flex; align-items:center; gap:10px; padding:9px 0; border-bottom:1px solid var(--line)}
.today-chap:last-child{border:none}
.subtag{font-size:11px; color:var(--muted); background:var(--card2); padding:3px 9px; border-radius:7px; white-space:nowrap}
.search-in{width:100%; background:#fff; border:1px solid var(--line); color:var(--txt); padding:11px 14px; border-radius:12px; font-size:14px}
.search-in:focus{outline:none; border-color:var(--accent)}
.today-chap .eff{font-size:11px; color:var(--muted2); font-variant-numeric:tabular-nums; min-width:32px; text-align:right}
.flex{display:flex; gap:10px; align-items:center; flex-wrap:wrap}
.spacer{flex:1}

@media(max-width:720px){
  .grid-3{grid-template-columns:1fr} .grid-2{grid-template-columns:1fr}
  .subj-name{min-width:0} .tabs{width:100%; margin-left:0; justify-content:space-between}
  main{padding:20px 16px 48px}
  .cal-cell{min-height:54px}
}
