/* Construction pad.

   Ported from the Secondary 1 "Polygons & Constructions" lab, whose pad is
   drawn in millimetres on a sheet of paper. That app's palette is not this
   one's, so every colour it used is remapped here onto a single set of
   --pad-* variables built from css/tokens.css. The engine (js/core/
   construction-pad.js) only ever names --pad-* variables, so the pad follows
   this app's theme and its Present mode without touching the JS.

     polygon app        here
     --teal             --pad-tool          (accent blue: the instruments)
     --teal-strong      --pad-tool-strong   (their ticks and numerals)
     --violet           --pad-tool-2        (set square, if a pad asks for one)
     --magenta          --pad-hot           (highlight pink: the drawing edge,
                                             the snap ring — "act here")
     --ink-blue         --pad-arc           (figure teal: compass arcs)
     --line             --pad-line
     --line-soft        --pad-grid
     --surface          --pad-paper
     --surface-2        --pad-desk
     --bad / --good     --no / --ok
*/

.pad-shell {
  --pad-paper: var(--surface);
  --pad-desk: var(--surface-sunk);
  --pad-line: var(--border);
  --pad-grid: #dfe8f0;
  --pad-grid: color-mix(in srgb, var(--border) 45%, var(--surface));
  --pad-ink: var(--ink);
  --pad-arc: var(--figure-stroke);
  --pad-tool: var(--accent);
  --pad-tool-strong: #17456f;
  --pad-tool-strong: color-mix(in srgb, var(--accent) 72%, var(--ink));
  --pad-tool-2: var(--figure-stroke-2);
  --pad-hot: var(--highlight);

  /* the pad draws in viewBox millimetres, so its "type scale" lives here */
  --pad-ink-w: 1.1;
  --pad-label: 5px;
  --pad-tool-num: 2.6px;

  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: var(--sp-3);
  align-items: start;
  width: 100%;
}
.pad-shell.has-guide { grid-template-columns: 56px minmax(0, 1fr) 312px; }

@media (max-width: 980px) {
  .pad-shell, .pad-shell.has-guide { grid-template-columns: 1fr; }
  /* Stacked: the tray takes what it needs, the paper takes the rest. */
  .stage > .pad-shell { grid-template-rows: auto minmax(0, 1fr); }
}

/* Present mode: heavier ink and bigger labels, to read from the back row. */
:root[data-mode="present"] .pad-shell {
  --pad-ink-w: 1.8;
  --pad-label: 7.5px;
  --pad-tool-num: 3.2px;
}

/* ------------------------------------------------------------- the tray */

.pad-tray {
  display: flex; flex-direction: column; gap: var(--sp-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: var(--sp-2);
}
@media (max-width: 980px) {
  .pad-tray { flex-direction: row; flex-wrap: wrap; justify-content: center; }
}

.tool-chip {
  position: relative; appearance: none; cursor: pointer;
  width: 44px; height: 44px; border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-sunk);
  color: var(--ink-soft);
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0;
}
.tool-chip svg { width: 24px; height: 24px; pointer-events: none; }
.tool-chip:hover { border-color: var(--accent); color: var(--accent); }
.tool-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tool-chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.tool-chip[data-role="danger"][aria-pressed="true"] { background: var(--no); border-color: var(--no); }
.tool-chip:disabled { opacity: 0.4; cursor: default; }
.tool-chip .cap {
  position: absolute; left: 52px; top: 50%; transform: translateY(-50%);
  background: var(--ink); color: var(--surface);
  font-size: var(--fs-xs); font-weight: 600;
  padding: 3px 7px; border-radius: var(--radius-sm);
  white-space: nowrap; opacity: 0; pointer-events: none;
  transition: opacity 0.12s; z-index: 5;
}
.tool-chip:hover .cap { opacity: 0.94; }
@media (max-width: 980px) { .tool-chip .cap { display: none; } }

.tray-divider { height: 1px; background: var(--border); margin: 2px 4px; }
@media (max-width: 980px) { .tray-divider { width: 1px; height: auto; margin: 4px 2px; } }

/* ------------------------------------------------------------ the paper */

.pad-canvas-wrap {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: var(--sp-2);
  min-width: 0;
}
svg.pad-canvas {
  display: block; width: 100%; height: auto;
  touch-action: none; user-select: none;
  border-radius: var(--radius-sm);
  background: var(--pad-desk);
}
/* Fit the pad to the stage rather than scrolling it.
   On its own the canvas takes its height from its width (height:auto against
   the viewBox), which on a laptop screen makes the sheet taller than the space
   under the header. Inside the stage it instead fills the height that is left
   and letterboxes: the viewBox's xMidYMid meet keeps the paper square-on and
   whole, whichever dimension runs out first. */
.stage > .pad-shell {
  flex: 1 1 auto;
  min-height: 0;
  align-items: stretch;
  /* A definite row, so the canvas's height:100% has something to resolve
     against — an auto row would size to the canvas and the canvas to the row. */
  grid-template-rows: minmax(0, 1fr);
}
.stage .pad-canvas-wrap {
  display: flex;
  min-height: 0;
}
.stage .pad-canvas {
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  /* A floor, so a short window squeezes the paper rather than flattening it:
     letterboxed down to a slit it is technically "fitted" and useless. Below
     this the stage scrolls, which is the lesser of the two evils. */
  min-height: 300px;
}

.pad-guide { display: flex; flex-direction: column; gap: var(--sp-3); }

/* --------------------------------------------------- what the pad draws */

.ink-seg { stroke: var(--pad-ink); stroke-width: var(--pad-ink-w); stroke-linecap: round; fill: none; }
.ink-arc { stroke: var(--pad-arc); stroke-width: var(--pad-ink-w); fill: none; stroke-linecap: round; }
.ink-pt { fill: var(--pad-ink); }
.ink-ptlabel {
  fill: var(--pad-ink); font-weight: 700; font-style: italic;
  font-size: var(--pad-label); font-family: var(--font-math);
}
.ink-free {
  stroke: var(--pad-ink); stroke-width: var(--pad-ink-w); fill: none;
  stroke-linecap: round; stroke-linejoin: round;
}
.ink-text { fill: var(--pad-ink); font-size: var(--pad-label); font-weight: 600; font-family: inherit; }

.ghost { stroke: var(--pad-tool); stroke-width: 1.1; fill: none; stroke-dasharray: 2 2; opacity: 0.85; stroke-linecap: round; }
.ghost-fill { fill: var(--pad-tool); opacity: 0.4; }
.snap-ring { fill: none; stroke: var(--pad-hot); stroke-width: 0.8; }

.tool-body { stroke: var(--pad-tool-strong); stroke-width: 0.5; }
.tool-tick { stroke: var(--pad-tool-strong); }
.tool-num { fill: var(--pad-tool-strong); font-size: var(--pad-tool-num); font-family: inherit; font-weight: 600; }

.hud-pill-bg { fill: var(--ink); opacity: 0.9; }
.hud-pill-tx {
  fill: var(--surface); font-size: 4px; font-weight: 700;
  font-family: inherit; font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------- pop-overs on the pad */

.pad-pop {
  position: fixed; z-index: 60;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: var(--sp-2);
  font-family: var(--font-sans); font-size: var(--fs-sm);
}
.pad-pop .pop-hint { font-size: var(--fs-xs); color: var(--ink-faint); margin-bottom: var(--sp-1); }
.pad-pop .pop-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.pad-pop button {
  font: inherit; cursor: pointer;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-sunk); color: var(--ink);
  padding: 5px 6px; font-weight: 650;
}
.pad-pop button:hover { border-color: var(--accent); }
.pad-pop button.is-default { background: var(--accent); border-color: var(--accent); color: #fff; }
.pad-pop button.wide { width: 100%; margin-top: var(--sp-2); font-weight: 500; }
.pad-pop input[type="text"] {
  width: 100%; font: inherit; padding: 6px 8px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-sunk); color: var(--ink);
}
.pad-pop .pop-row { display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; margin-top: var(--sp-2); }
.pad-pop .pop-row .grow { flex: 1 1 auto; }
.pad-pop .pop-value {
  font-weight: 700; font-variant-numeric: tabular-nums;
  min-width: 4em; text-align: center;
}

/* -------------------------------------------------------- guided rails */

.step-list { list-style: none; margin: var(--sp-3) 0 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.step-item {
  display: flex; gap: var(--sp-2); align-items: flex-start;
  padding: 7px 8px; border-radius: var(--radius-sm);
  font-size: var(--fs-sm); color: var(--ink-soft); line-height: 1.35;
}
.step-item .num {
  flex: none; width: 22px; height: 22px; border-radius: 50%;
  background: var(--surface-sunk); border: 1px solid var(--border);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: var(--fs-xs); font-weight: 800; color: var(--ink-faint);
}
.step-item.done { color: var(--ink); }
.step-item.done .num { background: var(--ok); border-color: var(--ok); color: #fff; }
.step-item.current { background: var(--accent-soft); color: var(--ink); }
.step-item.current .num { background: var(--accent); border-color: var(--accent); color: #fff; }

.instr-card {
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-3);
  font-size: var(--fs-sm);
}
.instr-card .step-tag {
  font-size: var(--fs-xs); letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--accent); font-weight: 800;
}
.instr-card p { margin: var(--sp-1) 0 0; }

.pad-status { font-size: var(--fs-sm); min-height: 1.3em; }
.pad-status[data-tone="ok"] { color: var(--ok); font-weight: 600; }
.pad-status[data-tone="no"] { color: var(--no); }
.pad-status[data-tone="info"] { color: var(--ink-soft); }
