/* The two-column proof panel (public/proof.js). The proof is written in chalk on a fresh patch of
   slate: a hand-drawn T divides statements from reasons, and the reasons wait on the pine ledge
   below as sticks of chalk. The student's own writing takes their chalk color (--learner). */

.proof {
  --pf-chalk: var(--chalk, #f1eee6);
  --pf-dim: var(--chalk-dim, rgba(241, 238, 230, 0.7));
  --pf-yellow: var(--chalk-yellow, #f2c94c);
  --pf-coral: var(--chalk-coral, #ef8a74);
  --pf-mint: var(--chalk-mint, #8fd3b6);
  --pf-own: var(--learner, var(--pf-yellow));
  --pf-burn: var(--burn, #3f250f);
  --pf-pine: var(--pine, #c28b55);
  --pf-hand: var(--font-hand, "Andika", system-ui, sans-serif);
  --pf-ui: var(--font-ui, "Atkinson Hyperlegible Next", system-ui, sans-serif);
  --pf-rule: rgba(241, 238, 230, 0.5);
  /* A chalk stroke that wanders a little, drawn once and stretched along a rule. */
  --pf-wobble-h: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 6' preserveAspectRatio='none'%3E%3Cpath d='M1 3.4C60 2.2 120 4 190 3.1S330 2.1 399 3.6' fill='none' stroke='%23f1eee6' stroke-opacity='.62' stroke-width='2.4' stroke-linecap='round'/%3E%3C/svg%3E");
  --pf-wobble-v: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 6 400' preserveAspectRatio='none'%3E%3Cpath d='M3.2 1C2.1 70 4 150 3 220S2.3 340 3.5 399' fill='none' stroke='%23f1eee6' stroke-opacity='.62' stroke-width='2.4' stroke-linecap='round'/%3E%3C/svg%3E");

  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  border-radius: inherit;
  overflow: hidden;
  color: var(--pf-chalk);
  font-family: var(--pf-ui);
  background: radial-gradient(120% 90% at 30% 20%, #2f3b3e, var(--slate, #2a3538) 55%, var(--slate-deep, #1f282a));
  -webkit-font-smoothing: antialiased;
}

.proof :focus-visible { outline: 3px solid var(--pf-yellow); outline-offset: 3px; }
.proof button { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }

.pf-sr {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); clip-path: inset(50%); white-space: nowrap;
}

.pf-scroll {
  overflow: auto;
  outline-offset: -4px;
  overscroll-behavior: contain;
  padding: clamp(16px, 2.6vw, 28px) clamp(16px, 4vw, 48px) 22px;
}

/* ---------- given, prove, figure ---------- */

.pf-page {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "claims" "fig" "chart";
  gap: 18px;
  max-width: 1080px;
  margin: 0 auto;
}
/* Wide boards: the figure stands to the right of the whole proof, so the chart gets the height. */
@media (min-width: 900px) {
  .pf-page.has-fig {
    grid-template-columns: minmax(0, 1fr) minmax(220px, 300px);
    grid-template-areas: "claims fig" "chart fig";
    grid-template-rows: auto 1fr;
    column-gap: 40px;
  }
  .pf-page.has-fig .pf-fig { position: sticky; top: 0; align-self: start; padding-top: 8px; }
  .pf-page.has-fig .pf-figure { max-height: 250px; }
}
.pf-claims { grid-area: claims; }
.pf-fig { grid-area: fig; }
.pf-chart { grid-area: chart; }
.pf-claims { display: grid; gap: 12px; min-width: 0; }
.pf-lede { margin: 0; font: 600 15px/1.4 var(--pf-ui); color: var(--pf-dim); }
.pf-claim { display: grid; grid-template-columns: 5.2em minmax(0, 1fr); align-items: baseline; gap: 12px; }
.pf-key {
  margin: 0;
  font: 700 13px/1 var(--pf-ui);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--pf-dim);
}
.pf-claim:last-child .pf-key { color: var(--pf-yellow); }
.pf-given { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.pf-given, .pf-prove { font: 400 21px/1.5 var(--pf-hand); }
.pf-prove { margin: 0; font-weight: 700; font-size: 25px; color: var(--pf-yellow); }

.pf-fig { margin: 0; width: 100%; }
.pf-figure { display: block; width: 100%; height: auto; max-height: 200px; overflow: visible; }
.pf-ink { fill: none; stroke: var(--pf-chalk); stroke-width: 0.1; stroke-linecap: round; stroke-linejoin: round; opacity: 0.92; }
.pf-dash { stroke-dasharray: 0.34 0.26; opacity: 0.7; }
.pf-mark { stroke: var(--pf-yellow); stroke-width: 0.085; opacity: 0.95; }
.pf-dot { fill: var(--pf-chalk); }
.pf-label { font: 700 0.78px var(--pf-hand); fill: var(--pf-chalk); text-anchor: middle; dominant-baseline: central; }
.pf-label.pf-it { font-style: italic; font-weight: 400; font-size: 0.86px; }
.pf-label.pf-num { font-size: 0.62px; fill: var(--pf-dim); }

/* ---------- math in text ---------- */

.pf-math { white-space: nowrap; }
.pf-math i { font-style: italic; padding-right: 0.04em; }
.pf-rel { margin: 0 0.24em; }
.pf-up { font-style: normal; }
.pf-glyph { display: inline-block; height: 1em; vertical-align: -0.24em; overflow: visible; fill: none; stroke: currentColor; stroke-width: 64; stroke-linecap: round; stroke-linejoin: round; }
.pf-rel .pf-glyph { vertical-align: -0.2em; }
/* Segments, lines, and rays: a bar over the letters, with arrow tips where the figure goes on.
   The bar is painted in currentColor through a mask, so it matches whatever chalk it sits in. */
.pf-seg, .pf-line, .pf-ray { position: relative; display: inline-block; padding: 0 0.08em; }
.pf-seg::before, .pf-line::before, .pf-ray::before {
  content: "";
  position: absolute;
  left: 0; right: 0; top: -0.1em;
  height: 0.3em;
  background: currentColor;
  -webkit-mask: linear-gradient(#000, #000) center / calc(100% - 0.12em) 0.075em no-repeat;
  mask: linear-gradient(#000, #000) center / calc(100% - 0.12em) 0.075em no-repeat;
}
.pf-line { padding-inline: 0.16em; }
.pf-line::before, .pf-ray::before {
  --head-r: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Cpath d='M1 1l8 4-8 4z'/%3E%3C/svg%3E");
  --head-l: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Cpath d='M9 1L1 5l8 4z'/%3E%3C/svg%3E");
  --bar: linear-gradient(#000, #000) center / calc(100% - 0.3em) 0.075em no-repeat;
}
.pf-line::before {
  -webkit-mask: var(--head-l) left center / 0.3em 0.3em no-repeat, var(--head-r) right center / 0.3em 0.3em no-repeat, var(--bar);
  mask: var(--head-l) left center / 0.3em 0.3em no-repeat, var(--head-r) right center / 0.3em 0.3em no-repeat, var(--bar);
}
.pf-ray::before {
  -webkit-mask: var(--head-r) right center / 0.3em 0.3em no-repeat, linear-gradient(#000, #000) left center / calc(100% - 0.15em) 0.075em no-repeat;
  mask: var(--head-r) right center / 0.3em 0.3em no-repeat, linear-gradient(#000, #000) left center / calc(100% - 0.15em) 0.075em no-repeat;
}

/* ---------- the T-chart ---------- */


.pf-cols, .pf-row {
  display: grid;
  grid-template-columns: 2.2em minmax(0, 1.25fr) minmax(0, 1fr);
  column-gap: 20px;
}
.pf-cols {
  padding-bottom: 10px;
  font: 700 13px/1 var(--pf-ui);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--pf-dim);
  background: var(--pf-wobble-h) left bottom / 100% 6px no-repeat;
}
.pf-cols span:first-child { grid-column: 2; }
.pf-cols span:last-child { padding-left: 12px; }

.pf-rows {
  list-style: none;
  margin: 0;
  padding: 6px 0 4px;
  position: relative;
}
/* The stem of the T, between statements and reasons. */
.pf-rows::before {
  content: "";
  position: absolute;
  top: -6px; bottom: 0;
  left: calc((100% - 2.2em - 40px) * 1.25 / 2.25 + 2.2em + 30px);
  width: 6px;
  margin-left: -3px;
  background: var(--pf-wobble-v) center / 6px 100% no-repeat;
  pointer-events: none;
}

.pf-row {
  align-items: center;
  min-height: 56px;
  padding: 4px 0;
  position: relative;
}
.pf-n { font: 700 18px/1 var(--pf-hand); color: var(--pf-dim); text-align: right; padding-right: 4px; }
.pf-stmt { font: 400 20px/1.45 var(--pf-hand); min-width: 0; overflow-wrap: anywhere; }
.pf-reason { font: 700 17px/1.3 var(--pf-hand); overflow-wrap: anywhere; }

/* A reason slot: an empty chalk line until a reason is written on it. */
.pf-slot {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  margin-left: 12px;
  padding: 6px 12px 8px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background-color 160ms ease;
}
.pf-slot .pf-reason { flex: 1; color: var(--pf-own); }
.pf-slot:not(.filled) .pf-reason {
  font: 600 15px/1.2 var(--pf-ui);
  color: rgba(241, 238, 230, 0.55);
  padding-bottom: 6px;
  background: linear-gradient(90deg, rgba(241, 238, 230, 0.42) 50%, transparent 0) left bottom / 10px 2px repeat-x;
}
.pf-slot:hover { background: rgba(241, 238, 230, 0.06); }
.pf-row.active:not(.wrong) .pf-slot { background: rgba(242, 201, 76, 0.1); box-shadow: inset 0 0 0 1.5px rgba(242, 201, 76, 0.55); }
.pf-row.active .pf-slot:not(.filled) .pf-reason { color: var(--pf-yellow); background-image: linear-gradient(90deg, var(--pf-yellow) 50%, transparent 0); }
.pf-row.active .pf-n { color: var(--pf-yellow); }

/* ---------- marks after checking ---------- */

.pf-flag { flex: none; display: grid; place-items: center; pointer-events: none; }
.pf-tick { width: 26px; height: 26px; fill: none; stroke: var(--pf-mint); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.pf-tick path { stroke-dasharray: 26; stroke-dashoffset: 26; animation: pf-draw 360ms ease-out forwards; }
.pf-loop {
  position: absolute;
  inset: -8px -10px;
  border: 2.6px solid var(--pf-coral);
  border-radius: 999px;
  transform: rotate(-0.7deg);
  animation: pf-wipe 480ms ease-out both;
}
.pf-loop::after {
  content: "";
  position: absolute;
  inset: -4px 6px 2px -5px;
  border: 2px solid var(--pf-coral);
  border-left-color: transparent;
  border-bottom-color: transparent;
  border-radius: 999px;
  opacity: 0.55;
  transform: rotate(1.1deg);
}
@keyframes pf-wipe { from { clip-path: inset(-20px 100% -20px -20px); } to { clip-path: inset(-20px -20px -20px -20px); } }
.pf-row.wrong .pf-n { color: var(--pf-coral); }
.pf-row .pf-flag[data-flag="wrong"] { position: absolute; inset: 0; }
.pf-row.wrong .pf-slot, .pf-row.wrong .pf-card, .pf-row.wrong .pf-hole { position: relative; }
@keyframes pf-draw { to { stroke-dashoffset: 0; } }

.proof.solved .pf-prove { text-shadow: 0 0 18px rgba(242, 201, 76, 0.35); }

/* ---------- order mode ---------- */

.proof[data-mode="order"] .pf-cols span:last-child { visibility: hidden; }
.proof[data-mode="order"] .pf-rows::before { display: none; }
.proof[data-mode="order"] .pf-cols, .proof[data-mode="order"] .pf-row { grid-template-columns: 2.2em minmax(0, 1fr) auto; }
.proof[data-mode="order"] .pf-row { min-height: 62px; }
.proof[data-mode="order"] .pf-row > .pf-flag[data-flag="right"] { grid-column: 3; }

.pf-hole {
  grid-column: 2;
  display: flex;
  align-items: center;
  min-height: 52px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1.5px dashed rgba(241, 238, 230, 0.3);
  font: 600 14px var(--pf-ui);
  color: rgba(241, 238, 230, 0.5);
}
.pf-row.pf-over .pf-hole, .pf-row.pf-over .pf-card { border-color: var(--pf-yellow); background: rgba(242, 201, 76, 0.12); }

/* A step card: the statement in chalk with its reason beneath, like a slip written on the board. */
.pf-card {
  display: grid;
  gap: 3px;
  min-height: 52px;
  padding: 9px 16px 10px;
  border-radius: 12px;
  border: 1.5px solid rgba(241, 238, 230, 0.22);
  background: rgba(241, 238, 230, 0.05);
  text-align: left;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: background-color 160ms ease, border-color 160ms ease, opacity 160ms ease;
}
.pf-card .pf-stmt { font-size: 19px; color: var(--pf-chalk); }
.pf-card .pf-reason { font: 600 13px/1.3 var(--pf-ui); letter-spacing: 0.02em; color: var(--pf-dim); }
.pf-card:hover { border-color: rgba(241, 238, 230, 0.45); }
.pf-card.placed { border-color: color-mix(in srgb, var(--pf-own) 55%, transparent); }
.pf-card.placed .pf-stmt { color: var(--pf-own); }
.pf-card.pf-lifted { opacity: 0.35; }
.pf-ghost {
  position: fixed;
  left: 0; top: 0;
  z-index: 10;
  pointer-events: none;
  background: #34413f;
  border-color: var(--pf-yellow);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.45);
}

/* ---------- the ledge ---------- */

.pf-ledge {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  padding: 12px clamp(12px, 3vw, 28px) 14px;
  color: var(--pf-burn);
  background-color: var(--pf-pine);
  background-image:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.035) 0 2px, transparent 2px 11px),
    repeating-linear-gradient(90deg, rgba(90, 50, 15, 0.05) 0 1px, transparent 1px 23px),
    linear-gradient(180deg, var(--pine-light, #cd9860), var(--pf-pine) 45%, var(--pine-deep, #93602f));
  box-shadow: 0 -1px 0 rgba(255, 236, 205, 0.35), 0 -8px 18px rgba(0, 0, 0, 0.28);
}
.pf-ledge > * { min-width: 0; }
.pf-ledge :focus-visible { outline-color: var(--pf-burn); }

.pf-status { margin: 0; min-height: 1.35em; font: 700 15px/1.35 var(--pf-ui); }

.pf-shelf { display: flex; align-items: flex-end; gap: 14px; }

.pf-bank {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 7px 6px;
  max-height: min(30vh, 200px);
  overflow-y: auto;
  padding: 4px 2px 6px;
}

/* A reason on the ledge: a stick of chalk, like the ledge's own buttons. */
.pf-chip {
  appearance: none;
  min-height: 44px;
  padding: 9px 14px;
  border: 0;
  border-radius: 999px;
  font: 700 14px/1.15 var(--pf-ui) !important;
  color: #262422 !important;
  background: var(--pf-chalk);
  box-shadow: 0 2px 0 rgba(63, 37, 15, 0.45), inset 0 -3px 0 rgba(0, 0, 0, 0.07);
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease;
}
.pf-chip:hover { transform: translateY(-1px); box-shadow: 0 3px 0 rgba(63, 37, 15, 0.45), inset 0 -3px 0 rgba(0, 0, 0, 0.07); }
.pf-chip:active { transform: translateY(1px); box-shadow: 0 1px 0 rgba(63, 37, 15, 0.45); }

/* Order mode: the steps wait in a groove cut into the ledge, still chalk on slate. */
.proof[data-mode="order"] .pf-bank {
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 6px;
  border-radius: 14px;
  background: linear-gradient(180deg, #243033, var(--slate, #2a3538));
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.55), 0 1px 0 rgba(255, 236, 205, 0.3);
  scroll-snap-type: x proximity;
}
.pf-bank .pf-card { touch-action: pan-x; flex: none; width: min(300px, 76vw); scroll-snap-align: start; color: var(--pf-chalk); }
.pf-empty { margin: 0; padding: 14px 10px; font: 600 15px var(--pf-ui); color: var(--pf-dim); }

.pf-check {
  flex: none;
  min-height: 48px;
  padding: 12px 22px;
  border: 0;
  border-radius: 999px;
  font: 700 16px/1.1 var(--pf-ui) !important;
  color: #262422 !important;
  background: var(--pf-yellow);
  box-shadow: 0 2px 0 rgba(63, 37, 15, 0.5), inset 0 -3px 0 rgba(0, 0, 0, 0.08);
  cursor: pointer;
}
.pf-check:active { transform: translateY(1px); }

/* ---------- smaller screens ---------- */

@media (max-width: 720px) {
  .pf-fig { justify-self: center; max-width: 280px; }
  .pf-figure { max-height: 170px; }
  .pf-given, .pf-prove { font-size: 19px; }
  .pf-prove { font-size: 22px; }
  .pf-claim { grid-template-columns: 4.6em minmax(0, 1fr); gap: 8px; }

  /* The T folds: each reason sits under its statement, set off by a short chalk stem. */
  .pf-cols { display: none; }
  .pf-rows::before { display: none; }
  .pf-row { grid-template-columns: 1.6em minmax(0, 1fr); column-gap: 10px; row-gap: 2px; padding: 8px 0 10px; background: var(--pf-wobble-h) left bottom / 100% 4px no-repeat; }
  .pf-row:last-child { background: none; }
  .pf-slot { grid-column: 2; margin-left: 0; padding-left: 14px; border-radius: 0 10px 10px 0; background: var(--pf-wobble-v) left center / 5px 100% no-repeat; }
  .pf-row.active:not(.wrong) .pf-slot { background: var(--pf-wobble-v) left center / 5px 100% no-repeat, rgba(242, 201, 76, 0.1); }
  .proof[data-mode="order"] .pf-row { grid-template-columns: 1.6em minmax(0, 1fr) auto; background: none; }
  .pf-stmt { font-size: 19px; }

  .pf-shelf { flex-direction: column; align-items: stretch; gap: 10px; }
  .pf-bank { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; max-height: none; scroll-snap-type: x proximity; }
  .pf-chip { flex: none; white-space: nowrap; scroll-snap-align: start; }
  .pf-check { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .pf-tick path { animation: none; stroke-dashoffset: 0; }
  .pf-loop { animation: none; }
  .pf-chip, .pf-card, .pf-slot { transition: none; }
}
