/* Notebook palette: paper, ruled blue lines, red margin, ink blue. Light, quiet, no glow. */
:root {
  --paper: #f7f5ee;
  --sheet: #fffefb;
  --rule: #e3eaf3;
  --margin: #e6a6a1;
  --ink: #1f2a44;
  --ink-soft: #46506a;
  --pencil: #8a8f98;
  --line: #e4e0d5;
  --accent: #2f5d8a;
  --accent-soft: #e8eff7;
  --ok: #3f7f5f;
  --ok-soft: #eaf3ee;
  --bad: #b5523b;
  --bad-soft: #f8ece8;
  --hl: #fdf3c4;
  --radius: 10px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: "Iowan Old Style", "Charter", "Georgia", serif;
}
* { box-sizing: border-box; }
html { color-scheme: light; }
body {
  margin: 0; font: 15.5px/1.6 var(--font); color: var(--ink);
  background: var(--paper);
  display: grid; grid-template-columns: 280px 1fr; min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
code { font: 0.88em ui-monospace, "SF Mono", Menlo, monospace; background: #efece3; padding: 0.05em 0.35em; border-radius: 4px; }

/* sidebar */
.side { position: sticky; top: 0; height: 100vh; overflow-y: auto; border-right: 1px solid var(--line); background: #f3f0e7; padding: 22px 14px; }
.brand { display: flex; gap: 12px; align-items: center; padding: 4px 8px 20px; }
.brand-mark { font: 600 15px ui-monospace, Menlo, monospace; color: var(--accent); border: 1.5px solid var(--accent); border-radius: 6px; padding: 4px 6px; white-space: nowrap; }
.brand-text { font: 600 15px/1.2 var(--serif); }
.brand-text small { font: 12px var(--font); color: var(--pencil); }
.nav-item { display: grid; grid-template-columns: 28px 1fr; gap: 2px 8px; padding: 8px 10px; border-radius: 8px; color: var(--ink-soft); font-size: 13.5px; line-height: 1.3; }
.nav-item:hover { background: #ebe7dc; }
.nav-item.active { background: var(--sheet); color: var(--ink); box-shadow: inset 3px 0 0 var(--accent); }
.nav-num { font: 600 12px ui-monospace, Menlo, monospace; color: var(--pencil); padding-top: 2px; }
.nav-bar { grid-column: 2; height: 3px; background: #e2ddd0; border-radius: 2px; overflow: hidden; margin-top: 5px; }
.nav-bar span { display: block; height: 100%; background: var(--ok); }

/* main */
.page { min-width: 0; padding: 28px 40px 60px; max-width: 1080px; }
.top { display: flex; flex-wrap: wrap; gap: 16px; justify-content: space-between; align-items: flex-end; padding-bottom: 18px; border-bottom: 1px solid var(--line); margin-bottom: 26px; position: sticky; top: 0; background: var(--paper); z-index: 5; padding-top: 6px; }
h1 { font: 600 26px/1.2 var(--serif); margin: 0; letter-spacing: -0.01em; }
.sub { margin: 6px 0 0; color: var(--pencil); font-size: 13px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.score { color: var(--ink-soft); font-size: 13px; margin-right: 6px; }

.btn { font: 500 13.5px var(--font); border: 1px solid #d6d1c4; background: var(--sheet); color: var(--ink); padding: 7px 13px; border-radius: 8px; cursor: pointer; transition: background .15s, border-color .15s; }
.btn:hover { border-color: #b9b3a3; background: #fbf9f3; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #284f75; }
.btn.ghost { background: transparent; }
.mini { font: 12px var(--font); border: 1px solid #d6d1c4; background: var(--sheet); border-radius: 5px; width: 22px; height: 22px; cursor: pointer; color: var(--ink-soft); padding: 0; }

/* cards: a notebook sheet with a red margin and faint rules */
.cards { display: flex; flex-direction: column; gap: 22px; }
.card {
  position: relative; background: var(--sheet); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 22px 14px 58px;
  background-image: linear-gradient(to right, transparent 40px, var(--margin) 40px, var(--margin) 41px, transparent 41px);
}
.card.solved { border-color: #bcd6c6; }
.card.solved .num { color: var(--ok); }
.card-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 8px; }
.num { position: absolute; left: 10px; top: 19px; width: 24px; text-align: center; font: 600 13px ui-monospace, Menlo, monospace; color: var(--pencil); }
.card-head h3 { margin: 0; font: 600 16.5px/1.3 var(--serif); flex: 1; }
.badge { font-size: 11px; letter-spacing: .03em; text-transform: uppercase; padding: 2px 8px; border-radius: 99px; border: 1px solid; white-space: nowrap; }
.b-random { color: var(--accent); border-color: #c4d3e3; background: var(--accent-soft); }
.b-static { color: var(--pencil); border-color: #dcd8cd; }
.b-proof { color: #7a5c99; border-color: #d9cfe5; background: #f5f1fa; }
.b-visual { color: #8a6d2f; border-color: #e5dac0; background: #faf6ec; }
.card-body { line-height: 1.75; overflow-x: auto; }
.card-body p { margin: 0.55em 0; }
.card-body ul { margin: 0.5em 0; padding-left: 1.2em; }
.card-body li { margin: 0.45em 0; }
.card-body .katex-display { margin: 0.7em 0; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.card-foot { display: flex; align-items: center; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
.status { margin-left: auto; font-size: 13px; color: var(--ink-soft); }
.card.solved .status { color: var(--ok); font-weight: 600; }
.hint { margin: 0.5em 0; color: var(--ink-soft); font-size: 14px; }
.hint summary { cursor: pointer; color: var(--accent); font-size: 13px; }

/* fields */
.field { display: inline-flex; align-items: center; gap: 8px; vertical-align: middle; flex-wrap: wrap; margin: 2px 0; }
.field.f-radio, .field.f-checkboxes, .field.f-proof, .field.f-planes, .field.f-veclist, .field.f-eigpairs, .field.f-eiggraph, .field.f-circlemap, .field.f-figure, .field.f-textarea { display: flex; flex-direction: column; align-items: stretch; }
.hidden-field { display: none !important; }
.in { font: 14.5px var(--font); color: var(--ink); background: #fff; border: 1px solid #d3cec1; border-radius: 6px; padding: 5px 8px; outline: none; transition: border-color .15s, background .15s; }
.in:focus, .cell:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.in-text { width: 9.5em; }
.in-text.short { width: 5em; }
.in-area { width: min(22em, 100%); font-family: ui-monospace, Menlo, monospace; }
.in-select { padding-right: 4px; max-width: 100%; }
.note { font-size: 12px; color: var(--pencil); }
.sol { font-size: 13.5px; color: var(--ok); background: var(--ok-soft); padding: 2px 10px; border-radius: 6px; }
.sol-label { color: var(--pencil); }

.matrix { display: inline-block; position: relative; padding: 4px 9px; vertical-align: middle; }
.matrix::before, .matrix::after { content: ""; position: absolute; top: 0; bottom: 0; width: 7px; border: 1.6px solid var(--ink); }
.matrix::before { left: 0; border-right: none; }
.matrix::after { right: 0; border-left: none; }
.mgrid { display: grid; gap: 4px; }
.cell { font: 14px var(--font); text-align: center; width: 100%; padding: 4px 3px; border: 1px solid #dad5c8; border-radius: 4px; background: #fff; outline: none; min-width: 0; }

.is-ok.in, .matrix.is-ok .cell, .is-ok .cell { border-color: #9cc4ab; background: var(--ok-soft); }
.is-bad.in, .matrix.is-bad .cell, .is-bad .cell { border-color: #e0a796; background: var(--bad-soft); }
.choices.is-ok, .proof.is-ok, .planes.is-ok, .veclist-wrap.is-ok, .eigpairs.is-ok { outline: 2px solid #9cc4ab; outline-offset: 4px; border-radius: 6px; }
.choices.is-bad, .proof.is-bad, .planes.is-bad, .veclist-wrap.is-bad, .eigpairs.is-bad { outline: 2px solid #e0a796; outline-offset: 4px; border-radius: 6px; }

.choices { display: flex; flex-direction: column; gap: 6px; margin: 4px 0; }
.choice { display: flex; gap: 10px; align-items: flex-start; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; background: #fff; }
.choice:hover { border-color: #cfc9ba; }
.choice input { margin-top: 0.4em; accent-color: var(--accent); }

.row { display: flex; gap: 8px; align-items: center; }
.veclist { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 8px; }
.vecitem { display: inline-flex; align-items: center; gap: 6px; }
.vlabel { color: var(--ink-soft); font-size: 14px; }
.eigpairs .pair { display: flex; align-items: center; gap: 8px; margin-top: 8px; }

/* proof puzzle */
.proof { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 6px 0; }
.proof-col { min-width: 0; }
.proof-head { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--pencil); margin-bottom: 6px; }
.proof-list { list-style: none; margin: 0; padding: 8px; min-height: 120px; border: 1px dashed #d6d1c4; border-radius: 8px; background: #fcfbf7; display: flex; flex-direction: column; gap: 6px; }
.proof-list.chosen { counter-reset: step; background-image: repeating-linear-gradient(transparent 0 27px, var(--rule) 27px 28px); }
.proof-list.chosen .step::before { counter-increment: step; content: counter(step); font: 600 12px ui-monospace, Menlo, monospace; color: var(--pencil); min-width: 1.4em; padding-top: 3px; }
.step { display: flex; gap: 8px; align-items: flex-start; background: #fff; border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; cursor: grab; font-size: 14px; line-height: 1.55; }
.step:hover { border-color: #cbc5b6; }
.step.dragging { opacity: .5; }
.step-text { flex: 1; min-width: 0; overflow-x: auto; }
.step-ctl { display: flex; gap: 3px; flex-shrink: 0; }
.step.ok { border-color: #9cc4ab; background: var(--ok-soft); }
.step.bad { border-color: #e0a796; background: var(--bad-soft); }
.placeholder { color: var(--pencil); font-size: 13px; padding: 10px; }

/* visual */
.planes { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin: 6px 0; }
.plane-opt { display: flex; flex-direction: column; gap: 4px; border: 1px solid var(--line); border-radius: 8px; padding: 6px; background: #fff; cursor: pointer; }
.plane-canvas { width: 100%; aspect-ratio: 1; touch-action: none; cursor: grab; }
.plane-cap { font-size: 13px; color: var(--ink-soft); display: flex; gap: 6px; align-items: center; }
.plane-cap input { accent-color: var(--accent); }
.eiggraph { display: flex; flex-direction: column; gap: 6px; max-width: 380px; }
.eig-canvas { width: 100%; aspect-ratio: 1; border: 1px solid var(--line); border-radius: 8px; background: #fff; touch-action: none; cursor: crosshair; }
.eig-info { font-size: 13px; color: var(--ink-soft); }
.eig-table table { border-collapse: collapse; font-size: 13px; margin-top: 6px; }
.eig-table td, .eig-table th { border: 1px solid var(--line); padding: 2px 10px; text-align: center; }
.eig-table summary { cursor: pointer; font-size: 13px; color: var(--accent); }
.figure { max-width: 460px; }
.figure svg, .figure-img { width: 100%; height: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; }

/* home */
.home p { max-width: 64ch; color: var(--ink-soft); }
.home-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; margin-top: 22px; }
.home-tile { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px 14px 26px; background: var(--sheet); border: 1px solid var(--line); border-radius: var(--radius); font: 600 15px/1.3 var(--serif);
  background-image: linear-gradient(to right, transparent 12px, var(--margin) 12px, var(--margin) 13px, transparent 13px); }
.home-tile:hover { border-color: #cfc9ba; }
.foot { margin-top: 40px; color: var(--pencil); font-size: 12.5px; border-top: 1px solid var(--line); padding-top: 14px; }

@media (max-width: 860px) {
  body { grid-template-columns: 1fr; }
  .side { position: static; height: auto; border-right: none; border-bottom: 1px solid var(--line); }
  #nav { display: flex; overflow-x: auto; gap: 4px; }
  .nav-item { min-width: 180px; }
  .page { padding: 18px 14px 40px; }
  .card { padding-left: 46px; background-image: linear-gradient(to right, transparent 32px, var(--margin) 32px, var(--margin) 33px, transparent 33px); }
  .num { left: 5px; }
  .proof { grid-template-columns: 1fr; }
  .top { position: static; }
}

/* language toggle */
.lang { display: flex; gap: 0; margin: 18px 10px 0; border: 1px solid #d6d1c4; border-radius: 8px; overflow: hidden; width: max-content; }
.lang button { font: 600 12px var(--font); letter-spacing: .04em; border: 0; background: transparent; color: var(--pencil); padding: 5px 12px; cursor: pointer; }
.lang button.on { background: var(--sheet); color: var(--accent); }
.home-actions { margin: 18px 0 4px; }

/* export dialog */
.export-dlg { position: fixed; inset: 0; background: rgba(31, 42, 68, .18); display: grid; place-items: center; z-index: 50; }
.export-box { position: relative; background: var(--sheet); border: 1px solid var(--line); border-radius: 12px; padding: 22px 24px 18px; width: min(440px, 92vw); display: flex; flex-direction: column; gap: 14px;
  background-image: linear-gradient(to right, transparent 12px, var(--margin) 12px, var(--margin) 13px, transparent 13px); }
.export-box h3 { margin: 0; font: 600 18px var(--serif); }
.export-box .close { position: absolute; top: 12px; right: 12px; }
.export-box .note { margin: 0; }
.seg { display: inline-flex; border: 1px solid #d6d1c4; border-radius: 8px; overflow: hidden; width: max-content; }
.seg-btn { font: 500 13.5px var(--font); border: 0; background: #fff; padding: 7px 14px; cursor: pointer; color: var(--ink-soft); }
.seg-btn.on { background: var(--accent-soft); color: var(--accent); }
.seg-btn:disabled { color: #c3beb2; cursor: not-allowed; }
.chk { font-size: 14px; }

/* print document (screen preview + print) */
body.print-mode { display: block; background: #fff; }
body.print-mode .side, body.print-mode .top, body.print-mode .foot { display: none; }
body.print-mode .page { max-width: 820px; margin: 0 auto; padding: 24px 28px 60px; }
.p-bar { display: flex; gap: 8px; justify-content: flex-end; margin-bottom: 18px; }
.p-head { display: flex; justify-content: space-between; align-items: flex-end; border-bottom: 2px solid var(--ink); padding-bottom: 10px; margin-bottom: 18px; gap: 20px; }
.p-head h1 { font-size: 22px; }
.p-kicker { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); font-weight: 600; }
.p-meta { font-size: 12.5px; color: var(--ink-soft); text-align: right; line-height: 1.8; }
.p-line { display: inline-block; width: 13em; border-bottom: 1px solid var(--ink-soft); }
.p-series h2 { font: 600 18px var(--serif); margin: 6px 0 12px; padding-bottom: 4px; border-bottom: 1px solid var(--line); }
.p-ex { padding: 8px 0 12px; border-bottom: 1px dashed var(--line); break-inside: avoid; page-break-inside: avoid; }
.p-ex h3 { font: 600 15px var(--serif); margin: 4px 0; }
.p-n { color: var(--pencil); font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.p-body { font-size: 13.5px; line-height: 1.7; }
.p-body p { margin: 0.4em 0; }
.p-body ul { margin: 0.3em 0; padding-left: 1.2em; }
.p-body .katex-display { margin: 0.5em 0; }
.p-field { display: inline-block; vertical-align: middle; }
.p-blank { display: inline-block; width: 8em; height: 1.6em; border-bottom: 1px solid var(--ink-soft); vertical-align: middle; }
.p-blank.short { width: 3.5em; }
.p-blank.tall { width: 14em; height: 4.5em; border: 1px solid #bbb; border-radius: 4px; }
.p-matrix { display: inline-grid; gap: 3px; padding: 3px 7px; position: relative; vertical-align: middle; }
.p-matrix::before, .p-matrix::after { content: ""; position: absolute; top: 0; bottom: 0; width: 5px; border: 1.3px solid var(--ink); }
.p-matrix::before { left: 0; border-right: 0; } .p-matrix::after { right: 0; border-left: 0; }
.p-matrix span { height: 1.7em; border-bottom: 1px dotted #aaa; }
.p-opts { font-size: 12.5px; color: var(--ink-soft); }
.p-list { display: flex; flex-direction: column; gap: 3px; margin: 3px 0; }
.p-field.p-radio, .p-field.p-checkboxes, .p-field.p-proof, .p-field.p-planes, .p-field.p-veclist, .p-field.p-figure, .p-field.p-circlemap, .p-field.p-eiggraph { display: block; }
.p-space { display: flex; gap: 14px; align-items: center; margin: 4px 0; flex-wrap: wrap; }
.p-ans { display: inline-block; color: #24573f; background: var(--ok-soft); border-radius: 4px; padding: 0 6px; }
.p-ans ol { margin: 4px 0; padding-left: 1.3em; }
.p-note { font-size: 12px; color: var(--pencil); font-style: italic; }
.p-steps { list-style: none; padding: 0; margin: 4px 0; display: flex; flex-direction: column; gap: 4px; }
.p-steps li { display: flex; gap: 8px; align-items: flex-start; }
.p-num { flex: 0 0 1.8em; height: 1.5em; border: 1px solid #aaa; border-radius: 3px; }
.p-planes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 4px 0; }
.p-planes figure { margin: 0; text-align: center; font-size: 12px; }
.p-canvas { width: 100%; height: auto; border: 1px solid #ddd; border-radius: 4px; }
.p-figure { max-width: 300px; }
.p-figure.small { max-width: 240px; }
.p-figure svg { width: 100%; height: auto; }
.p-cap { font-size: 11px; color: var(--pencil); }
.p-table { border-collapse: collapse; font-size: 12px; margin: 4px 0; }
.p-table td, .p-table th { border: 1px solid #ccc; padding: 1px 9px; text-align: center; }

@media print {
  @page { size: A4; margin: 14mm 14mm 16mm; }
  body { background: #fff !important; }
  .side, .top, .foot, .p-bar, .export-dlg { display: none !important; }
  .page { padding: 0 !important; max-width: none !important; }
  .p-break { break-before: page; page-break-before: always; }
  .p-ans { background: none; border-bottom: 1px solid #9cc4ab; }
  a { color: inherit; }
}
