:root {
  --bg: #f6f5f1;
  --panel: #ffffff;
  --ink: #1d1d1b;
  --muted: #62615b;
  --line: #e2e0d8;
  --cs: #2f6fdb;
  --cs-bg: #e8f0fd;
  --me: #a8660f;
  --me-bg: #fbf0df;
  --both: #6b46c1;
  --both-bg: #efe9fb;
  --ge: #2a7d4f;
  --ge-bg: #e4f4ea;
  --done: #8a887f;
  --done-bg: #efeee9;
  --bad: #b83232;
  --bad-bg: #fdecec;
  --warn: #8a5a12;
  --warn-bg: #fdf4e3;
  --ok: #2a7d4f;
  --on-badge: #ffffff;
  --focus: #2f6fdb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141413; --panel: #1e1e1c; --ink: #ecebe6; --muted: #a3a197; --line: #33322e;
    --cs: #7aa7f5; --cs-bg: #1c2a44; --me: #e3a857; --me-bg: #3a2c16; --both: #b39af0; --both-bg: #2b2244;
    --ge: #6cc794; --ge-bg: #173324; --done: #8a887f; --done-bg: #262623;
    --bad: #f07b7b; --bad-bg: #3d1d1d; --warn: #e8b35c; --warn-bg: #3a2e17; --ok: #6cc794;
    --on-badge: #141413; --focus: #7aa7f5;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141413; --panel: #1e1e1c; --ink: #ecebe6; --muted: #a3a197; --line: #33322e;
  --cs: #7aa7f5; --cs-bg: #1c2a44; --me: #e3a857; --me-bg: #3a2c16; --both: #b39af0; --both-bg: #2b2244;
  --ge: #6cc794; --ge-bg: #173324; --done: #8a887f; --done-bg: #262623;
  --bad: #f07b7b; --bad-bg: #3d1d1d; --warn: #e8b35c; --warn-bg: #3a2e17; --ok: #6cc794;
  --on-badge: #141413; --focus: #7aa7f5;
  --shadow: 0 1px 2px rgba(0,0,0,.3);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.45 ui-sans-serif, -apple-system, "Segoe UI", Inter, system-ui, sans-serif; }
body { overflow-x: hidden; }
a { color: var(--cs); }
button, select, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

header.top { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.wrap { max-width: 1400px; margin: 0 auto; padding-inline: 20px; }
.top-inner { display: flex; align-items: center; gap: 8px 16px; padding-block: 12px; flex-wrap: wrap; }
h1 { font-size: 17px; margin: 0; letter-spacing: -.01em; }
h1 small { color: var(--muted); font-weight: 400; margin-left: 6px; }
nav.tabs { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
nav.tabs button { border: 1px solid transparent; background: none; color: var(--muted); padding: 6px 12px;
  border-radius: 999px; cursor: pointer; }
nav.tabs button:hover { color: var(--ink); }
nav.tabs button.on { background: var(--panel); color: var(--ink); border-color: var(--line); box-shadow: var(--shadow); }
nav.tabs .theme { font-size: 12px; }
.badge { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 999px; font-size: 11px; font-weight: 600;
  background: var(--bad); color: var(--on-badge); margin-left: 4px; text-align: center; }
.badge.warn { background: var(--warn); }

main { padding-block: 18px 60px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; box-shadow: var(--shadow); }
.stat .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .v { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat .v small { font-size: 12px; color: var(--muted); font-weight: 400; }
.stat .note { font-size: 11px; color: var(--muted); margin-top: 4px; }
.meter { height: 5px; background: var(--line); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--ok); }
.meter.warn > i { background: var(--warn); } .meter.bad > i { background: var(--bad); }

.banner { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; background: var(--warn-bg); border: 1px solid var(--warn);
  border-radius: var(--radius); padding: 10px 12px; margin-bottom: 12px; }
.banner span { flex: 1 1 260px; }

/* issues summary */
.issues-ok { font-size: 13px; color: var(--ok); margin-bottom: 12px; }
.panel.issues { padding: 10px 14px; }
.issues summary { cursor: pointer; display: flex; align-items: center; gap: 6px; list-style-position: inside; }
.issues summary::-webkit-details-marker { margin-right: 2px; }
.issues ul { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 2px; max-height: 260px; overflow-y: auto; }
.issue { display: flex; gap: 8px; align-items: baseline; width: 100%; text-align: left; background: none; border: 0;
  border-radius: 6px; padding: 4px 6px; cursor: pointer; font-size: 13px; }
.issue:hover { background: var(--bg); }
.issue .dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--bad); transform: translateY(-1px); }
.issue.warn .dot { background: var(--warn); }
.issue .iq { flex: none; width: 118px; color: var(--muted); font-size: 12px; }
.issue .im { min-width: 0; overflow-wrap: anywhere; }

/* what-if */
.whatif h3 { font-size: 14px; }
.whatif h3 .hint { font-weight: 400; }
.scen { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 8px; }
.scen-item { display: flex; gap: 8px; align-items: flex-start; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; cursor: pointer; }
.scen-item.on { border-color: var(--both); background: var(--both-bg); }
.scen-item input { margin-top: 3px; }
.scen-item .hint { display: block; }

.toolbar { display: flex; gap: 8px 14px; flex-wrap: wrap; align-items: center; margin-bottom: 4px; color: var(--muted); font-size: 12px; }
.toolbar .grp { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.toolbar button, .toolbar select, .btn, .dlg button, .banner button, .drawer .dactions button, .drawer select, .movebar button {
  font-size: 12px; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 5px 10px; border-radius: 8px; cursor: pointer; }
.toolbar select { max-width: 160px; }
.toolbar button:hover, .btn:hover, .dlg button:hover, .banner button:hover, .drawer .dactions button:hover { border-color: var(--muted); }
button:disabled { opacity: .45; cursor: default; }
button.armed, button.danger:hover { border-color: var(--bad); color: var(--bad); }
.legend { display: flex; gap: 10px; flex-wrap: wrap; margin-left: auto; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.howto { margin: 0 0 12px; }

.year { margin-bottom: 18px; }
.year h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 8px; font-weight: 600; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 1000px) { .grid4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .grid4 { grid-template-columns: minmax(0, 1fr); } }
.q { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; min-height: 120px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; transition: border-color .15s, background .15s; min-width: 0; }
.q.summer { background: color-mix(in srgb, var(--panel) 70%, var(--bg)); border-style: dashed; }
.q.past { opacity: .85; }
.q.current { border-color: var(--cs); }
.q.drop { border-color: var(--both); background: var(--both-bg); }
.q.armed { outline: 2px dashed var(--both); outline-offset: 2px; cursor: copy; }
.qh { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.qh b { font-size: 13px; }
.qh .u { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.qh .u.bad { color: var(--bad); font-weight: 600; }
.qtag { font-size: 10px; padding: 1px 6px; border-radius: 999px; background: var(--cs-bg); color: var(--cs); margin-left: 4px; }
.qtag.done { background: var(--done-bg); color: var(--muted); }
.qmsg { font-size: 11px; color: var(--bad); }
.qmsg.warn { color: var(--warn); }
.q, .c { scroll-margin-top: 120px; scroll-margin-bottom: 80px; }
.dropline { height: 3px; border-radius: 2px; background: var(--both); margin: -2px 0; }

.c { border-radius: 8px; padding: 6px 8px; border-left: 4px solid var(--muted); background: var(--done-bg); cursor: pointer;
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0 6px; user-select: none; position: relative; min-width: 0; }
.c[draggable="true"] { cursor: grab; }
.c[draggable="true"]:active { cursor: grabbing; }
.c.dragging { opacity: .4; }
.c.sel { outline: 2px solid var(--both); outline-offset: 1px; }
.c.open { box-shadow: 0 0 0 2px var(--focus); }
.c .n { font-weight: 600; font-size: 13px; overflow-wrap: anywhere; }
.c .t { font-size: 11px; color: var(--muted); grid-column: 1 / -1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.c .cu { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.c .flags { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 2px; margin-top: 3px; }
.flag { font-size: 11px; line-height: 1.3; }
.flag.bad { color: var(--bad); } .flag.warn { color: var(--warn); } .flag.info { color: var(--muted); }
.c.cs { border-color: var(--cs); background: var(--cs-bg); }
.c.me { border-color: var(--me); background: var(--me-bg); }
.c.both { border-color: var(--both); background: var(--both-bg); }
.c.ge { border-color: var(--ge); background: var(--ge-bg); }
.c.done { opacity: .8; }
.c.hasbad { box-shadow: inset 0 0 0 1px var(--bad); }
.c .x { position: absolute; top: 2px; right: 3px; border: none; background: none; color: var(--muted); cursor: pointer;
  font-size: 15px; line-height: 1; padding: 2px 4px; opacity: 0; }
.c:hover .x, .c:focus-within .x { opacity: 1; }
.c .x:hover { color: var(--bad); }
@media (hover: none) { .c .x { opacity: 1; } }
.c .cu { margin-right: 16px; }
.add { margin-top: auto; }
.add select { width: 100%; font-size: 12px; padding: 4px; border-radius: 6px; border: 1px dashed var(--line);
  background: transparent; color: var(--muted); }
.pulse { animation: pulse 1.6s ease-out; }
@keyframes pulse { 0%, 40% { box-shadow: 0 0 0 3px var(--warn); } 100% { box-shadow: 0 0 0 3px transparent; } }
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; box-shadow: 0 0 0 3px var(--warn); } }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 14px; }
.panel h3 { margin: 0 0 10px; font-size: 15px; }
.panel p { margin: 6px 0; }
.two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; }
@media (max-width: 900px) { .two { grid-template-columns: minmax(0, 1fr); } }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
td, th { text-align: left; padding: 6px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.sec td { font-weight: 600; background: var(--bg); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
tr.missing td:first-child { color: var(--bad); }
.st { white-space: nowrap; font-size: 12px; font-weight: 600; }
.st.ok { color: var(--ok); } .st.plan { color: var(--cs); } .st.miss { color: var(--bad); }
.pill { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); margin: 1px 2px 1px 0; white-space: nowrap; color: var(--ink); }
.pillbtn { cursor: pointer; font-size: 12px; padding: 2px 9px; }
.pillbtn:hover { border-color: var(--muted); }
.linkbtn { background: none; border: 0; padding: 0; color: var(--cs); cursor: pointer; text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--cs) 35%, transparent); text-underline-offset: 2px; }
.linkbtn:hover { text-decoration-color: currentColor; }
b .linkbtn { font-weight: 600; }
.muted { color: var(--muted); }
.scroll { overflow-x: auto; }

.qa { counter-reset: q; list-style: none; padding: 0; margin: 0; }
.qa li { padding: 12px 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: 4px 10px; }
.qa li::before { counter-increment: q; content: counter(q); font-weight: 700; color: var(--both); font-variant-numeric: tabular-nums; }
.qa .qq { font-weight: 600; }
.qa .why { grid-column: 2; color: var(--muted); font-size: 13px; }
.qa .pr { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; padding: 1px 6px; border-radius: 4px; margin-right: 6px; vertical-align: 1px; }
.pr.high { background: var(--bad-bg); color: var(--bad); } .pr.med { background: var(--warn-bg); color: var(--warn); } .pr.low { background: var(--bg); color: var(--muted); }
.qa input[type=checkbox] { margin-right: 6px; }
.qa textarea { grid-column: 2; width: 100%; font-size: 13px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); padding: 6px; min-height: 34px; resize: vertical; }
.findings li { margin: 4px 0; }
.src { font-size: 12px; }
footer { color: var(--muted); font-size: 12px; padding-bottom: 30px; }
.hint { font-size: 12px; color: var(--muted); }

/* course detail side panel */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(400px, 100vw); z-index: 40; overflow-y: auto;
  background: var(--panel); border-left: 1px solid var(--line); box-shadow: -8px 0 24px rgba(0,0,0,.12);
  padding: 16px 18px calc(24px + env(safe-area-inset-bottom, 0px)); overscroll-behavior: contain; }
.drawer:focus { outline: none; }
.drawer .dh { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.drawer h2 { margin: 0; font-size: 18px; }
.drawer h4 { margin: 14px 0 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.drawer p { margin: 4px 0; }
.drawer .dtitle { margin-top: 8px; }
.close { flex: none; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; width: 32px; height: 32px;
  font-size: 18px; line-height: 1; cursor: pointer; color: var(--muted); }
.close:hover { color: var(--ink); border-color: var(--muted); }
.dactions { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 4px; }
.dactions select { max-width: 100%; }
.dflags { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 2px; }
.dflags .flag { font-size: 12px; }
.reqlist { list-style: none; padding: 0; margin: 0; display: grid; gap: 3px; }
.reqlist .mk { display: inline-block; width: 1em; font-weight: 700; }
.reqlist .met .mk { color: var(--ok); } .reqlist .unmet .mk { color: var(--bad); }
.majfill { margin: 4px 0 8px; }
.majfill > b { display: block; font-size: 13px; }
.dbl { font-size: 13px; padding: 6px 8px; border-radius: 6px; background: var(--bg); }
.dbl.both { background: var(--both-bg); }

/* tap-to-move bar and toast */
.movebar { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 45;
  display: flex; gap: 10px; align-items: center; background: var(--ink); color: var(--bg); padding: 8px 10px 8px 14px; border-radius: 12px;
  box-shadow: 0 6px 24px rgba(0,0,0,.25); max-width: calc(100vw - 32px); font-size: 13px; }
.movebar button { flex: none; }
.toast { position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); transform: translate(-50%, 20px); z-index: 50;
  background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 10px; font-size: 13px; display: flex; gap: 12px; align-items: center;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button { background: none; border: 0; color: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; padding: 0; }
.movebar:not([hidden]) ~ .toast { bottom: calc(70px + env(safe-area-inset-bottom, 0px)); }

/* plans dialog */
.dlg { border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--ink); padding: 16px 18px;
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.dlg::backdrop { background: rgba(0,0,0,.35); }
.dlg-h { display: flex; justify-content: space-between; align-items: center; }
.dlg h3 { margin: 0; font-size: 16px; }
.dlg h4 { margin: 16px 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.dlg .row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.dlg input[type=text] { flex: 1 1 160px; min-width: 0; border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; background: var(--bg); font-size: 13px; }
.dlg textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; background: var(--bg); resize: vertical; }
.mono { font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; }
.plans { list-style: none; padding: 0; margin: 6px 0; display: flex; flex-wrap: wrap; gap: 6px 14px; }
.dlgmsg { margin: 10px 0 0; padding: 6px 10px; border-radius: 8px; background: var(--cs-bg); font-size: 13px; }

@media (max-width: 600px) {
  .wrap { padding-inline: 16px; }
  .top-inner { padding-block: 8px; gap: 6px; }
  h1 { font-size: 15px; }
  h1 small { display: block; margin: 0; font-size: 12px; }
  nav.tabs { margin-left: 0; }
  nav.tabs button { padding: 4px 9px; font-size: 13px; }
  .legend { margin-left: 0; }
  .issue .iq { width: 90px; }
  .drawer { width: 100vw; border-left: 0; }
}

@media print {
  @page { size: landscape; margin: 10mm; }
  :root { --bg: #fff; --panel: #fff; --shadow: none; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  header.top { position: static; backdrop-filter: none; }
  nav.tabs, .toolbar, .howto, .add, .c .x, .drawer, .movebar, .toast, .dlg, .whatif, .banner, .qa textarea:placeholder-shown { display: none !important; }
  .issues ul { max-height: none; overflow: visible; }
  .issue .dot { print-color-adjust: exact; }
  .wrap { max-width: none; padding: 0; }
  main { padding: 0; }
  .grid4 { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; gap: 6px; }
  .q, .stat, .issues { break-inside: avoid; }
  .year h2 { break-after: avoid; }
  .q { min-height: 0; }
  .c .t { white-space: normal; }
  .two { grid-template-columns: 1fr 1fr !important; }
  a { color: inherit; }
}
