:root {
  color-scheme: light;
  --bg: #f6f5f1;
  --surface: #fcfcfb;
  --surface-2: #f0efea;
  --border: #dcdad3;
  --text: #1b1b19;
  --text-2: #52514e;
  --muted: #76746f;
  --brand: #1f6f5c;
  --brand-ink: #ffffff;
  --brand-soft: #e3f0ec;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn: #8a5a00;
  --warn-soft: #fff4dc;
  --ok: #1d6b2a;
  --ok-soft: #e6f4e8;
  --series-1: #2a78d6;
  --seq-hi: #1d5fae;
  --grid: #e6e4de;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #3a3936;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #9c9a92;
    --brand: #4fb39a;
    --brand-ink: #0d1f1a;
    --brand-soft: #1d332d;
    --danger: #f2877d;
    --danger-soft: #3a1d1a;
    --warn: #f0c060;
    --warn-soft: #3a2f16;
    --ok: #7fd18b;
    --ok-soft: #1b3320;
    --series-1: #3987e5;
    --seq-hi: #5a9cf0;
    --grid: #2e2d2a;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.pad { padding: 2rem 1rem; }
[hidden] { display: none !important; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--text); text-decoration: none; }
.brand svg { width: 28px; height: 28px; }
.brand svg rect { fill: var(--brand); }
.brand svg path { stroke: var(--brand-ink); stroke-width: 3; fill: none; stroke-linecap: round; }
#nav { display: flex; gap: .25rem; flex-wrap: wrap; margin-left: auto; }
#nav a, #nav button {
  font: inherit; font-size: .9rem; color: var(--text-2); text-decoration: none;
  background: none; border: 0; padding: .4rem .65rem; border-radius: 8px; cursor: pointer;
}
#nav a:hover, #nav button:hover { background: var(--surface-2); color: var(--text); }
#nav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }

main { max-width: 1040px; margin: 0 auto; padding: 1.25rem 1rem 4rem; outline: none; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.narrow { max-width: 440px; margin: 2rem auto; }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grid { display: grid; gap: .75rem; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.stack > * + * { margin-top: .75rem; }

label { display: block; font-size: .875rem; font-weight: 600; color: var(--text-2); margin-bottom: .25rem; }
.hint { font-weight: 400; color: var(--muted); font-size: .8rem; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: .55rem .65rem; min-height: 44px;
}
textarea { min-height: 84px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible, .chip input:focus-visible + span {
  outline: 2px solid var(--brand); outline-offset: 2px;
}
.check { display: flex; gap: .55rem; align-items: flex-start; font-weight: 400; color: var(--text); }
.check input { margin-top: .25rem; width: 18px; height: 18px; flex: none; }

.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip { margin: 0; font-weight: 400; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: inline-block; padding: .4rem .7rem; border: 1px solid var(--border); border-radius: 999px;
  font-size: .875rem; color: var(--text-2); cursor: pointer; user-select: none; min-height: 36px; line-height: 1.5;
}
.chip input:checked + span { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }

.btn {
  font: inherit; font-weight: 600; font-size: .925rem; display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  padding: .55rem 1rem; min-height: 44px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.small { min-height: 34px; padding: .3rem .65rem; font-size: .825rem; }
.btn.link { border: 0; background: none; color: var(--brand); padding: .2rem .3rem; min-height: 0; font-weight: 600; }
.btn:disabled { opacity: .55; cursor: wait; }
.full { width: 100%; }
.grow { flex: 1; min-width: 160px; }
.num-in { width: 96px; }
.row > .error-msg.full { flex-basis: 100%; margin: 0; }
summary { cursor: pointer; font-weight: 600; }
details.small summary { font-weight: 500; color: var(--text-2); margin: .5rem 0; }

.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: .15rem .5rem; border-radius: 999px; background: var(--surface-2); color: var(--text-2); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }

.notice { border-radius: 10px; padding: .75rem .9rem; font-size: .9rem; margin-bottom: 1rem; border: 1px solid; }
.notice.warn { background: var(--warn-soft); border-color: transparent; color: var(--text); }
.notice.danger { background: var(--danger-soft); border-color: transparent; color: var(--text); }
.notice.info { background: var(--brand-soft); border-color: transparent; color: var(--text); }
.error-msg { color: var(--danger); font-size: .9rem; min-height: 1.2em; margin: .25rem 0 0; }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-top: 1px solid var(--border); padding: .8rem 0; }
.list > li:first-child { border-top: 0; }
.student-item { display: flex; justify-content: space-between; align-items: center; gap: 1rem; text-decoration: none; color: inherit; padding: .2rem 0; }
.student-item:hover .code { text-decoration: underline; }
.code { font-weight: 700; font-size: 1.05rem; }
.meta { font-size: .85rem; color: var(--muted); }

.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; overflow-x: auto; }
.tabs a { padding: .6rem .9rem; text-decoration: none; color: var(--text-2); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 600; font-size: .925rem; }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); }

.obs { display: grid; gap: .25rem; }
.obs-head { display: flex; justify-content: space-between; gap: .5rem; align-items: baseline; flex-wrap: wrap; }
.obs-func { font-weight: 700; }
.tags { display: flex; flex-wrap: wrap; gap: .3rem; }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .5rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--text-2); font-weight: 600; font-size: .8rem; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
.heat td.cell { text-align: center; font-variant-numeric: tabular-nums; min-width: 2.2rem; border: 2px solid var(--surface); border-radius: 4px; }
.heat th.rot { font-size: .72rem; font-weight: 600; vertical-align: bottom; }

.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 11px; }
.chart .line { stroke: var(--series-1); stroke-width: 2; fill: none; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.chart .dot.hover { stroke: var(--text); }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .criterion { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 4; }
.tooltip {
  position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  border-radius: 8px; padding: .4rem .6rem; font-size: .8rem; white-space: nowrap; transform: translate(-50%, calc(-100% - 10px));
}
.tooltip strong { display: block; font-size: .95rem; color: var(--text); }
.tooltip span { color: var(--text-2); }

dialog { overflow-y: auto; overscroll-behavior: contain; border: 0; border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 1.5rem)); max-height: calc(100vh - 2rem); background: var(--surface); color: var(--text); box-shadow: 0 10px 40px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(0,0,0,.45); }
#modal-body { padding: 1.25rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; flex-wrap: wrap; }

#toast { position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%); z-index: 50; display: grid; gap: .5rem; }
.toast-item { background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 10px; font-size: .9rem; box-shadow: var(--shadow); max-width: 90vw; }
.toast-item.error { background: var(--danger); color: #fff; }

.secret { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 1.15rem; background: var(--surface-2); padding: .6rem .8rem; border-radius: 8px; user-select: all; word-break: break-all; }
.terms { max-height: 50vh; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; padding: 1rem; background: var(--surface-2); font-size: .9rem; }
.terms h3 { margin-top: 1rem; }
.terms ul { padding-left: 1.2rem; margin: 0 0 .75rem; }

.report-head { border-bottom: 2px solid var(--text); padding-bottom: .75rem; margin-bottom: 1rem; }
.report section { margin-bottom: 1.5rem; break-inside: avoid-page; }
.report .disclaimer { font-size: .8rem; color: var(--muted); border-top: 1px solid var(--border); padding-top: .75rem; }
.goal-block { break-inside: avoid; margin-bottom: 1rem; }

@media (max-width: 640px) {
  .topbar { gap: .5rem; }
  #nav { margin-left: 0; width: 100%; }
  main { padding-top: 1rem; }
  .card { padding: .9rem; }
}

@media print {
  :root { color-scheme: light; --bg: #fff; --surface: #fff; --text: #000; --text-2: #333; --muted: #555; --border: #ccc; --grid: #ddd; --series-1: #2a78d6; --seq-hi: #1d5fae; }
  .topbar, .no-print, .tabs, #toast { display: none !important; }
  main { max-width: none; padding: 0; }
  .card { border: 0; box-shadow: none; padding: 0; }
  body { background: #fff; }
  .heat td.cell { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
