/* One stylesheet, no build step, no framework -- the homework checker's,
   grown to fit. Cached hard (see SEND_FILE_MAX_AGE_DEFAULT) because under
   CGI every asset request forks an interpreter; bump the query string in
   base.html if you need to break that cache. */

:root {
  --ink: #1c1b1a;
  --ink-soft: #5f5b57;
  --rule: #e2ddd7;
  --page: #fbfaf8;
  --card: #ffffff;
  --cardinal: #8c1515;
  --green: #17603f;
  --green-bg: #eaf4ee;
  --amber: #8a5b00;
  --amber-bg: #fdf3e0;
  --slate: #3f5972;
  --slate-bg: #eef2f7;
  --red-bg: #fbebea;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 47rem; margin: 0 auto; padding: 0 1.25rem; }
/* Staff pages put a scan beside a form, which needs the width. */
body.wide .wrap { max-width: 76rem; }

/* --- chrome --- */

header.site {
  background: var(--card);
  border-bottom: 1px solid var(--rule);
  border-top: 3px solid var(--cardinal);
}
header.site .wrap {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 1rem; padding-top: .9rem; padding-bottom: .9rem;
}
.brand {
  font-weight: 650; font-size: 1rem; letter-spacing: -.01em;
  color: var(--ink); text-decoration: none;
}
.brand span { font-weight: 450; color: var(--ink-soft); margin-left: .35rem; }
header.site nav a {
  color: var(--ink-soft); text-decoration: none; font-size: .875rem;
  margin-left: 1.25rem;
}
header.site nav a:hover { color: var(--cardinal); }
header.site nav .who { color: var(--ink-soft); font-size: .8125rem; margin-left: 1.25rem; }

nav.tabs { background: var(--card); border-bottom: 1px solid var(--rule); margin-bottom: 2rem; }
nav.tabs .wrap { display: flex; flex-wrap: wrap; gap: .25rem 1.5rem; align-items: baseline; }
nav.tabs .exam-title { font-weight: 600; font-size: .9375rem; padding: .6rem 0; margin-right: .5rem; }
nav.tabs a {
  font-size: .875rem; color: var(--ink-soft); text-decoration: none;
  padding: .6rem 0; border-bottom: 2px solid transparent;
}
nav.tabs a:hover { color: var(--cardinal); }
nav.tabs a.current { color: var(--ink); border-bottom-color: var(--cardinal); }
nav.tabs .count { font-size: .75rem; color: var(--cardinal); font-weight: 600; }
header.site + main { margin-top: 2.5rem; }

footer.wrap {
  margin: 4rem auto 3rem; padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
  color: var(--ink-soft); font-size: .8125rem;
}

.devbar {
  background: #222; color: #ddd; font-size: .8125rem; padding: .35rem 0;
}
.devbar form { display: flex; gap: .5rem; align-items: center; }
.devbar input[type=text] { font-size: .8125rem; padding: .1rem .4rem; width: 10rem; }
.devbar button { font-size: .75rem; padding: .15rem .6rem; }

/* --- type --- */

h1 { font-size: 1.6rem; line-height: 1.25; letter-spacing: -.02em; margin: 0 0 .5rem; }
h2 { font-size: 1.125rem; letter-spacing: -.01em; margin: 2rem 0 .75rem; }
h3 { font-size: .9375rem; margin: 0 0 .5rem; }
a { color: var(--cardinal); }
.lede { color: var(--ink-soft); margin: 0 0 2rem; max-width: 42rem; }
.muted { color: var(--ink-soft); }
.meta { color: var(--ink-soft); font-size: .875rem; margin: .25rem 0 1.5rem; }
.hint { color: var(--ink-soft); font-size: .8125rem; margin: .5rem 0 1rem; }
.empty { color: var(--ink-soft); font-style: italic; }
.crumb { font-size: .875rem; margin: 0 0 1.25rem; }
.crumb a { text-decoration: none; color: var(--ink-soft); }
.crumb a:hover { color: var(--cardinal); }
code { font-size: .875em; background: var(--slate-bg); padding: .1em .35em; border-radius: 3px; }
.num { font-variant-numeric: tabular-nums; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .875em; }
.prewrap { white-space: pre-wrap; }

/* --- cards and panels --- */

.card, .panel {
  background: var(--card); border: 1px solid var(--rule);
  border-radius: var(--radius); padding: 1rem 1.25rem; margin-bottom: 1rem;
}
.panel > h2:first-child, .panel > h3:first-child { margin-top: 0; }
ul.cards { list-style: none; margin: 0; padding: 0; }
.card { display: flex; align-items: center; gap: 1rem; margin-bottom: .625rem; }
.card-main { flex: 1; min-width: 0; }
.card h2 { font-size: 1rem; margin: 0 0 .15rem; }
.card h2 a { text-decoration: none; color: var(--ink); }
.card h2 a:hover { color: var(--cardinal); }
.card p { margin: .15rem 0 0; font-size: .875rem; }
/* A card that is one link: its title's link is stretched over the whole
   card, so a click or tap anywhere on it follows the link. */
.link-card { position: relative; transition: border-color .12s, box-shadow .12s; }
.link-card h2 a::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius); }
.link-card:hover { border-color: #cfc9c2; box-shadow: 0 2px 8px rgba(0, 0, 0, .06); }
.link-card h2 a:focus-visible { outline: none; }
.link-card h2 a:focus-visible::after { outline: 2px solid var(--slate); outline-offset: 2px; }
.card .card-cta { margin-top: .5rem; color: var(--cardinal); font-weight: 550; }
.link-card:hover .card-cta { text-decoration: underline; }

.columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr)); gap: 1rem; }

/* A scan on the left, everything about it on the right. */
.split {
  display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(19rem, 1fr);
  gap: 1.25rem; align-items: start;
}
.split > .side { position: sticky; top: 1rem; }
iframe.pdf {
  width: 100%; height: 82vh; border: 1px solid var(--rule);
  border-radius: var(--radius); background: #f3f1ee;
}
iframe.pdf.short { height: 60vh; }

/* Scanned pages, drawn by app.js: side by side, a magnifier under the
   pointer. Wider than other staff pages, so two pages are big enough to
   read. Unselectable and left out of print, which would otherwise save
   them as a PDF in two clicks. */
body.scan .wrap { max-width: 104rem; }
body.scan .split { grid-template-columns: minmax(0, 1.9fr) minmax(19rem, 1fr); }
.pages { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.pages-bar { display: flex; flex-wrap: wrap; gap: .25rem 1rem; align-items: center;
             justify-content: space-between; margin-bottom: .5rem; }
.pages-bar .hint { margin: 0; }
.zoom { display: inline-flex; gap: .3rem; }
.zoom button[aria-pressed=true] { background: var(--ink); color: #fff; box-shadow: none; }
.pages-grid { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.pages-grid canvas { display: block; max-width: 100%; height: auto; background: #fff;
                     border: 1px solid var(--rule); box-shadow: 0 1px 3px rgba(0, 0, 0, .06); }
.pages.magnify .pages-grid canvas { cursor: crosshair; }
.pages-status { margin: .5rem 0; }
.lens {
  position: fixed; z-index: 20; pointer-events: none;
  border-radius: 50%; background: #fff;
  box-shadow: 0 0 0 2px var(--ink), 0 8px 28px rgba(0, 0, 0, .3);
}
.lens[hidden] { display: none; }
@media print {
  .pages-bar, .pages-grid, .lens { display: none !important; }
  .pages::before { content: "Scans are not printed."; }
}

/* --- badges --- */

.badge {
  display: inline-block; white-space: nowrap;
  font-size: .75rem; font-weight: 600; letter-spacing: .01em;
  padding: .2rem .55rem; border-radius: 100px;
  background: var(--slate-bg); color: var(--slate);
}
.badge.correct    { background: var(--green-bg); color: var(--green); }
.badge.needs-work { background: var(--amber-bg); color: var(--amber); }
.badge.error      { background: var(--red-bg);   color: var(--cardinal); }
.badge.pending    { background: var(--slate-bg); color: var(--slate); }
.badge.idle       { background: transparent; color: var(--ink-soft);
                    box-shadow: inset 0 0 0 1px var(--rule); }

/* --- notices --- */

.notice {
  border: 1px solid var(--rule); border-left: 3px solid var(--ink-soft);
  background: var(--card); border-radius: var(--radius);
  padding: .875rem 1.25rem; margin: 0 0 1.5rem;
}
.notice h2 { margin: 0 0 .4rem; font-size: 1.0625rem; }
.notice p  { margin: .4rem 0 0; }
.notice p:first-child { margin-top: 0; }
.notice ul { margin: .4rem 0 0; padding-left: 1.1rem; }
.notice.correct    { border-left-color: var(--green);    background: var(--green-bg); }
.notice.needs-work { border-left-color: var(--amber);    background: var(--amber-bg); }
.notice.error      { border-left-color: var(--cardinal); background: var(--red-bg); }
.notice.pending    { border-left-color: var(--slate);    background: var(--slate-bg); }

.spinner {
  display: inline-block; width: .75rem; height: .75rem; margin-right: .4rem;
  border: 2px solid var(--slate); border-right-color: transparent;
  border-radius: 50%; animation: spin .8s linear infinite; vertical-align: baseline;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

.progress { height: .4rem; background: var(--slate-bg); border-radius: 100px;
            overflow: hidden; margin: .5rem 0 .25rem; }
.progress > span { display: block; height: 100%; background: var(--slate);
                   width: 0; transition: width .4s; }

/* --- forms --- */

label { display: block; font-size: .875rem; font-weight: 550; margin: 0 0 .3rem; }
label.inline { display: inline-flex; align-items: center; gap: .4rem; font-weight: 450; }
input[type=text], input[type=number], input[type=search], select, textarea {
  font: inherit; font-size: .9375rem; color: var(--ink);
  padding: .45rem .6rem; border: 1px solid #cfc9c2; border-radius: 6px;
  background: #fff; width: 100%; max-width: 100%;
}
input[type=number] { width: 7rem; appearance: textfield; -moz-appearance: textfield; }
/* No up and down arrows: a stray click on one changed a score. app.js turns
   off the arrow keys and the scroll wheel too, so a number is only typed. */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
textarea { min-height: 6rem; line-height: 1.5; resize: vertical; }
textarea.code, textarea.tall { font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
                               font-size: .8125rem; }
textarea.tall { min-height: 18rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--slate); outline-offset: 1px; }
.field { margin-bottom: 1rem; }
.row { display: flex; flex-wrap: wrap; gap: .75rem 1.25rem; align-items: flex-end; }
.row .field { margin-bottom: 0; }
form.inline { display: inline; }
input[type=file] { font-size: .875rem; max-width: 100%; }
input[type=file]::file-selector-button {
  font: inherit; font-size: .875rem; margin-right: .75rem;
  padding: .35rem .75rem; border: 1px solid var(--rule);
  border-radius: 6px; background: var(--page); color: var(--ink); cursor: pointer;
}

button, .button {
  display: inline-block; font: inherit; font-size: .9375rem; font-weight: 550;
  padding: .5rem 1.1rem; border: 0; border-radius: 6px;
  background: var(--cardinal); color: #fff; text-decoration: none; cursor: pointer;
}
button:hover, .button:hover { background: #6f1010; }
button.secondary, .button.secondary {
  background: var(--card); color: var(--ink); box-shadow: inset 0 0 0 1px #cfc9c2;
}
button.secondary:hover, .button.secondary:hover { background: var(--page); }
button.small, .button.small { font-size: .8125rem; padding: .3rem .7rem; }
button.link { background: none; color: var(--cardinal); padding: 0; font-weight: 450;
              text-decoration: underline; font-size: inherit; }
button:disabled { opacity: .6; cursor: default; }
.button[aria-disabled="true"] { opacity: .45; pointer-events: none; }
.answer-nav { display: flex; align-items: center; justify-content: space-between;
              gap: .6rem; margin-bottom: .75rem; }
fieldset.plain { border: 0; margin: 0; padding: 0; min-width: 0; }
/* Locked: another TA's grade, readable, not faded to illegibility. */
fieldset.plain:disabled input, fieldset.plain:disabled textarea {
  color: var(--ink); -webkit-text-fill-color: var(--ink); background: var(--slate-bg);
  opacity: 1; resize: none; cursor: not-allowed;
}
fieldset.plain:disabled button { opacity: .4; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-top: 1rem; }
.danger { border-top: 1px solid var(--rule); margin-top: 1.5rem; padding-top: 1rem; }

/* --- tables --- */

table.data { width: 100%; border-collapse: collapse; font-size: .875rem; }
table.data th {
  text-align: left; font-weight: 600; color: var(--ink-soft);
  font-size: .75rem; text-transform: uppercase; letter-spacing: .04em;
  padding: 0 .75rem .5rem 0; border-bottom: 1px solid var(--rule);
}
table.data td { padding: .55rem .75rem .55rem 0; border-bottom: 1px solid var(--rule);
                vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }
table.data th.num, table.data td.num { text-align: right; padding-right: .75rem; }
table.data tfoot td { border-top: 1px solid var(--rule); border-bottom: 0;
                      padding-top: .625rem; color: var(--ink-soft); }
table.data select { width: auto; font-size: .875rem; padding: .25rem .4rem; }
.table-scroll { overflow-x: auto; }
/* Totals: a score or total that is not final yet. */
.provisional { color: var(--ink-soft); font-style: italic; }
table.totals th a { color: inherit; }
table.totals .hint { margin: .1rem 0 0; }

/* --- grades on the review pages --- */

ol.grades { list-style: none; margin: 0 0 1rem; padding: 0; }
ol.grades li { border: 1px solid var(--rule); border-radius: var(--radius);
               background: var(--card); padding: .6rem .9rem; margin-bottom: .4rem; }
ol.grades .who { font-weight: 600; font-size: .875rem; }
ol.grades .score { float: right; font-weight: 650; }
ol.grades .comment { margin: .3rem 0 0; font-size: .9rem; white-space: pre-wrap; }
ol.grades .use-grade { display: block; margin-top: .5rem; }

.bigscore { font-size: 1.75rem; font-weight: 650; letter-spacing: -.02em; }
.bigscore small { font-size: 1rem; color: var(--ink-soft); font-weight: 450; }

details { margin: .75rem 0; }
details > summary { cursor: pointer; font-weight: 550; font-size: .9375rem; }

/* --- rendered Markdown (rubrics, solutions) --- */

.md { font-size: .9375rem; overflow-wrap: anywhere; }
.md h1, .md h2, .md h3, .md h4 { font-size: 1rem; margin: 1.1rem 0 .4rem; }
.md > :first-child { margin-top: 0; }
.md p { margin: .4rem 0; }
.md ul, .md ol { margin: .3rem 0 .6rem; padding-left: 1.3rem; }
.md li { margin: .15rem 0; }
.md pre { background: var(--slate-bg); padding: .6rem .8rem; border-radius: 6px;
          overflow-x: auto; font-size: .8125rem; }
.md table { border-collapse: collapse; margin: .5rem 0; }
.md td, .md th { border: 1px solid var(--rule); padding: .25rem .5rem; }
/* The source, before (or without) the script that renders it. */
pre.md-src { white-space: pre-wrap; font: inherit; font-size: .9rem; margin: 0; }
.katex-display { overflow-x: auto; overflow-y: hidden; }

.scroll-box { max-height: 26rem; overflow-y: auto; border: 1px solid var(--rule);
              border-radius: var(--radius); padding: .75rem 1rem; background: var(--card); }

@media (max-width: 56rem) {
  .split, body.scan .split { grid-template-columns: minmax(0, 1fr); }
  .split > .side { position: static; }
  iframe.pdf { height: 70vh; }
}
@media (max-width: 34rem) {
  .card { flex-direction: column; align-items: flex-start; gap: .5rem; }
  header.site .wrap { flex-direction: column; gap: .25rem; }
  header.site nav a, header.site nav .who { margin: 0 1.25rem 0 0; }
}

/* --- the Totals histogram (drawn by app.js) --- */

.chart-controls { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; align-items: center; }
.chart-controls h3 { margin: 0 auto 0 0; }
.chart-controls label { margin: 0; }
.chart-controls select { width: auto; font-size: .875rem; padding: .25rem .4rem; }
.chart-caption { margin: .25rem 0 .5rem; }
.chart-plot { position: relative; }
.chart-plot svg { display: block; overflow: visible; }
.chart-plot text { font-size: 12px; fill: var(--ink-soft); font-variant-numeric: tabular-nums; }
.chart-plot .grid { stroke: #efebe6; }
.chart-plot .baseline { stroke: #cfc9c2; }
.chart-plot .bar { fill: var(--slate); transition: fill .12s, fill-opacity .12s; }
.chart-plot .bar.hover { fill: #5a7591; }
.chart-plot .bar.dim { fill-opacity: .28; }
.chart-plot .mean { stroke: var(--ink); stroke-width: 1; pointer-events: none; }
.chart-plot .mean-halo { stroke: var(--card); stroke-width: 3; pointer-events: none; }
.chart-plot .mean-label { fill: var(--ink); font-weight: 550; }
.chart-plot .hit { fill: transparent; outline: none; }
.chart-plot .hit[role=button] { cursor: pointer; }
.chart-plot .hit:focus-visible { stroke: var(--slate); stroke-width: 2; }
.chart-tip {
  position: absolute; z-index: 5; pointer-events: none; white-space: nowrap;
  background: var(--card); border: 1px solid var(--rule); border-radius: 6px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .1); padding: .35rem .6rem;
  font-size: .8125rem; line-height: 1.4; color: var(--ink-soft);
}
.chart-tip strong { display: block; color: var(--ink); font-size: .9375rem; }
.chart-filter { font-size: .875rem; margin: .5rem 0 0; }
@media (prefers-reduced-motion: reduce) { .chart-plot .bar { transition: none; } }
