/*
 * BubbleSheetTools styles.
 *
 * Look: a printed exam form. Warm paper, ink-dark type, hairline rules
 * between sections, and bubbles as the recurring motif (the wordmark, step
 * markers that fill in when done, and the answer-correction buttons).
 *
 * Fonts are self-hosted (static/fonts, SIL Open Font License) because the
 * site's Content-Security-Policy loads nothing from other domains.
 */

@font-face { font-family: "Fraunces"; font-weight: 600; font-style: normal; font-display: swap;
  src: url("/static/fonts/fraunces-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Fraunces"; font-weight: 400; font-style: italic; font-display: swap;
  src: url("/static/fonts/fraunces-latin-400-italic.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-weight: 400; font-display: swap;
  src: url("/static/fonts/ibm-plex-sans-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-weight: 500; font-display: swap;
  src: url("/static/fonts/ibm-plex-sans-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-weight: 600; font-display: swap;
  src: url("/static/fonts/ibm-plex-sans-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-weight: 500; font-display: swap;
  src: url("/static/fonts/ibm-plex-mono-latin-500-normal.woff2") format("woff2"); }

/* ------------------------------------------------------------ tokens ---- */
:root {
  color-scheme: light;
  --paper: #f4f1e9;
  --surface: #fbfaf6;
  --ink: #1c1a17;
  --ink-2: #57534b;
  --ink-3: #8a857a;
  --rule: #d8d2c4;
  --rule-strong: #b9b2a2;
  --accent: #1f5c4a;        /* form-ink green: links, focus, filled bubbles */
  --accent-soft: #dce8e1;
  --danger: #a3392a;
  --danger-soft: #f6e2dc;
  --highlight: #f4e3a6;     /* highlighter yellow for things to check */
  --ok: #1f5c4a;
  --ok-soft: #e1ece4;

  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --paper: #141412;
    --surface: #1c1b18;
    --ink: #ece8de;
    --ink-2: #aaa498;
    --ink-3: #7d786e;
    --rule: #33312c;
    --rule-strong: #4a4740;
    --accent: #7cc4a8;
    --accent-soft: #1f3129;
    --danger: #ec8f7f;
    --danger-soft: #3a211c;
    --highlight: #4a4020;
    --ok: #7cc4a8;
    --ok-soft: #1c2d25;
  }
}

/* The `hidden` attribute must always win over display rules below. */
[hidden] { display: none !important; }

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 1080px; margin: 0 auto; padding: 0 24px; }
@media (max-width: 640px) { .wrap { padding: 0 16px; } }

h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -0.01em; margin: 0; }
h1 { font-size: clamp(2rem, 4.5vw, 2.9rem); line-height: 1.08; }
h2 { font-size: 1.3rem; line-height: 1.25; }
h3 { font-size: 1.05rem; margin: 28px 0 10px; }
em { font-family: var(--serif); font-style: italic; }
a { color: var(--accent); text-underline-offset: 3px; }
code { font-family: var(--mono); font-size: 0.85em; background: var(--surface);
  border: 1px solid var(--rule); padding: 0 5px; border-radius: 3px; }
strong { font-weight: 600; }

.kicker {
  font: 500 0.72rem/1 var(--mono); letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--ink-3); margin: 0 0 12px;
}
.lead { font-size: 1.08rem; color: var(--ink-2); max-width: 60ch; margin: 14px 0 0; }
.hint { color: var(--ink-2); font-size: 0.9rem; font-weight: 400; }

/* --------------------------------------------------------- masthead ---- */
.masthead { border-bottom: 1px solid var(--rule); background: var(--paper); }
.masthead-inner { display: flex; align-items: center; gap: 28px; min-height: 64px; flex-wrap: wrap; }

.wordmark {
  display: inline-flex; align-items: center; gap: 10px; text-decoration: none; white-space: nowrap;
  color: var(--ink); font: 600 1.15rem/1 var(--serif); letter-spacing: -0.01em;
}
.wm-light { font-family: var(--serif); font-style: italic; font-weight: 400; color: var(--ink-2); }
.mark { display: inline-flex; gap: 3px; }
.mark i { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid var(--ink); display: block; }
.mark i.filled { background: var(--ink); }

.tabs { display: flex; gap: 22px; }
.tab {
  border: 0; background: none; padding: 21px 0 19px; cursor: pointer; font: 500 0.95rem var(--sans);
  color: var(--ink-2); border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); border-bottom-color: var(--ink); }

.account { margin-left: auto; display: flex; gap: 14px; align-items: center; font-size: 0.88rem;
  color: var(--ink-2); }
@media (max-width: 720px) {
  .masthead-inner { gap: 4px 20px; padding-top: 10px; }
  .account { margin-left: 0; width: 100%; order: 3; padding-bottom: 10px; }
  .tab { padding: 12px 0; }
}

/* ------------------------------------------------------------ intro ---- */
.intro { padding: 56px 0 36px; }
.session-intro { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px;
  flex-wrap: wrap; }
@media (max-width: 640px) { .intro { padding: 36px 0 24px; } }

/* ------------------------------------------------------------ steps ---- */
/* Each step: label column on the left, content on the right, hairline on top. */
.step {
  display: grid; grid-template-columns: 240px 1fr; gap: 16px 40px;
  border-top: 1px solid var(--rule); padding: 32px 0 36px;
}
.step-head { display: flex; align-items: center; gap: 12px; align-self: start; }
.step-num { font: 500 0.78rem/1 var(--mono); color: var(--ink-3); letter-spacing: 0.06em; }
.step-body { min-width: 0; }
.step-body > .hint:first-child { margin-top: 0; }
@media (max-width: 800px) { .step { grid-template-columns: 1fr; gap: 14px; padding: 26px 0 30px; } }

/* A bubble that fills in when its step is complete. */
.step-bubble {
  width: 16px; height: 16px; border-radius: 50%; border: 1.5px solid var(--ink-3);
  flex: none; transition: background 0.2s, border-color 0.2s;
}
.step.done .step-bubble { background: var(--accent); border-color: var(--accent); }

.subsection { margin-top: 22px; padding-top: 20px; border-top: 1px dashed var(--rule); }

/* ----------------------------------------------------------- inputs ---- */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px 20px; }
@media (max-width: 640px) { .grid2 { grid-template-columns: 1fr; } }
.row { display: flex; gap: 12px 16px; align-items: center; flex-wrap: wrap; margin-top: 14px; }
.row.end { justify-content: flex-end; }

label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: 0.92rem; }
label.inline { flex-direction: row; align-items: center; gap: 10px 12px; flex-wrap: wrap; }
label.check { flex-direction: row; align-items: flex-start; gap: 10px; font-weight: 400; }
label.check input { margin-top: 4px; accent-color: var(--accent); width: 16px; height: 16px; }

input, select, textarea {
  font: 400 1rem var(--sans); color: var(--ink); background: var(--surface);
  border: 1px solid var(--rule-strong); border-radius: 3px; padding: 9px 11px; min-width: 0;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input::placeholder, textarea::placeholder { color: var(--ink-3); }
input[type="number"] { width: 7.5em; font-variant-numeric: tabular-nums; }
textarea { width: 100%; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
button:focus-visible, a:focus-visible, .file-btn:focus-within, .drop-zone:focus-within {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.invalid { border-color: var(--danger) !important; box-shadow: 0 0 0 3px var(--danger-soft); }

.written-list { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 16px; }
.written-list label { font-weight: 400; font-size: 0.88rem; color: var(--ink-2); }

/* ---------------------------------------------------------- buttons ---- */
button, .button {
  font: 500 0.95rem/1.2 var(--sans); border-radius: 3px; padding: 10px 16px; cursor: pointer;
  border: 1px solid var(--rule-strong); background: transparent; color: var(--ink);
  text-decoration: none; display: inline-flex; align-items: center; gap: 8px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.primary:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); color: var(--paper); }
.ghost:hover:not(:disabled) { border-color: var(--ink); }
.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.danger:hover:not(:disabled) { border-color: var(--danger); background: var(--danger-soft); }
.big { padding: 14px 24px; font-size: 1.02rem; }
.small-btn { padding: 5px 10px; font-size: 0.85rem; }
.link {
  border: 0; background: none; color: var(--accent); padding: 0; font-weight: 500;
  text-decoration: underline; text-underline-offset: 3px;
}

.file-btn {
  display: inline-flex; flex-direction: row; align-items: center; border: 1px solid var(--rule-strong);
  border-radius: 3px; padding: 10px 16px; cursor: pointer; font-weight: 500; font-size: 0.95rem;
}
.file-btn:hover { border-color: var(--ink); }
.file-btn.solid { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.file-btn.solid:hover { background: var(--accent); border-color: var(--accent); }
.file-btn input, .drop-zone input { position: absolute; width: 1px; height: 1px; opacity: 0; }

.submit-row { border-top: 1px solid var(--rule); padding: 32px 0 8px; }
.submit-row .alert { margin-top: 0; }

/* ----------------------------------------------------------- alerts ---- */
.alert {
  border-left: 3px solid var(--ink-3); background: var(--surface); padding: 12px 16px;
  margin: 16px 0; font-size: 0.94rem;
}
.alert.error { border-left-color: var(--danger); background: var(--danger-soft); }
.alert.warn { border-left-color: #b8932a; background: var(--highlight); }
.alert.ok { border-left-color: var(--ok); background: var(--ok-soft); }
.alert ul { margin: 6px 0 0; padding-left: 18px; }

.chips { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; margin: 16px 0 0; }
.chips li { border: 1px solid var(--rule); background: var(--surface); border-radius: 999px;
  padding: 2px 11px; font-size: 0.85rem; }

/* ------------------------------------------------------------- auth ---- */
.auth .intro { padding-bottom: 28px; }
.auth-panel { max-width: 460px; border-top: 1px solid var(--rule); padding-top: 28px; }
.auth-form { display: flex; flex-direction: column; gap: 16px; }
.auth-form > .primary { justify-content: center; margin-top: 4px; }
.auth-links { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  font-size: 0.9rem; color: var(--ink-2); }

.dialog {
  border: 1px solid var(--rule-strong); border-radius: 4px; background: var(--paper);
  color: var(--ink); padding: 28px; width: min(440px, calc(100vw - 32px));
}
.dialog::backdrop { background: rgb(20 18 14 / 0.45); }

/* ---------------------------------------------------------- grading ---- */
.locked { font-family: var(--mono); font-size: 0.82rem; letter-spacing: 0.02em; }

.drop-zone {
  border: 1.5px dashed var(--rule-strong); border-radius: 4px; padding: 36px 20px;
  text-align: center; cursor: pointer; display: flex; flex-direction: column; gap: 4px;
  align-items: center; margin: 16px 0; background: var(--surface); font-weight: 400;
  transition: border-color 0.15s, background 0.15s;
}
.drop-zone:hover, .drop-zone.over { border-color: var(--accent); background: var(--accent-soft); }
.drop-title { font: 600 1.1rem var(--serif); }

.upload-log { list-style: none; padding: 0; margin: 8px 0 16px; font-size: 0.9rem; }
.upload-log li { padding: 8px 0; border-bottom: 1px solid var(--rule); display: flex;
  justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.upload-log .fname { font-family: var(--mono); font-size: 0.82rem; }
.upload-log .status { color: var(--ink-2); }
.upload-log .status.ok { color: var(--ok); }
.upload-log .status.err { color: var(--danger); }

.flag-list { display: flex; flex-direction: column; margin-top: 8px; }
.flag {
  display: grid; grid-template-columns: minmax(200px, 1fr) auto; gap: 12px 28px; align-items: center;
  padding: 18px 0; border-bottom: 1px solid var(--rule);
}
.flag:first-child { border-top: 1px solid var(--rule); }
.flag.resolved { opacity: 0.6; }
.flag-title { font-weight: 600; }
.flag-q { font-family: var(--mono); font-size: 0.82rem; color: var(--ink-3); margin-left: 8px; }
.flag img { display: block; max-width: 100%; height: auto; margin-top: 10px;
  border: 1px solid var(--rule); border-radius: 3px; background: #fff; }
.flag-note { font-size: 0.85rem; color: var(--ink-2); margin-top: 2px; }
.tag { display: inline-block; font: 500 0.7rem/1 var(--mono); letter-spacing: 0.08em;
  text-transform: uppercase; padding: 4px 7px; border-radius: 2px; background: var(--highlight);
  color: var(--ink); vertical-align: middle; }
.tag.checked { background: var(--ok-soft); color: var(--ok); }
@media (max-width: 640px) { .flag { grid-template-columns: 1fr; } }

/* Answer correction buttons drawn as bubbles. */
.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choices button {
  width: 38px; height: 38px; padding: 0; border-radius: 50%; justify-content: center;
  border: 1.5px solid var(--ink-2); font: 500 0.85rem var(--mono); color: var(--ink-2);
}
.choices button:hover { border-color: var(--ink); color: var(--ink); }
.choices button.on { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.flag .row { margin-top: 12px; }

.table-wrap { overflow-x: auto; margin-top: 8px; }
table { border-collapse: collapse; width: 100%; font-size: 0.92rem; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 9px 12px 9px 0; border-bottom: 1px solid var(--rule); white-space: nowrap; }
th { font: 500 0.72rem var(--mono); letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink-3); border-bottom-color: var(--rule-strong); }
td input[type="number"] { width: 5.5em; padding: 5px 7px; }

.downloads { display: flex; flex-wrap: wrap; gap: 8px; }
.charts { display: grid; gap: 20px; margin-top: 28px; }
.charts img { max-width: 100%; height: auto; border: 1px solid var(--rule); border-radius: 3px; background: #fff; }

/* ----------------------------------------------------------- footer ---- */
.footer { padding-top: 0; padding-bottom: 48px; margin-top: 48px; }
.footer-inner {
  display: flex; gap: 8px 24px; flex-wrap: wrap; padding-top: 28px;
  border-top: 1px solid var(--rule); font-size: 0.85rem; color: var(--ink-3);
}
.footer a { color: var(--ink-2); }
