/* PenForge — framed-sheet style (tasteskill app sheet), light, industrial.
   Grid arithmetic (desktop): window − 2×8px margin − 2×12px gap = steps 232 + stage 1fr + rail 340. */
:root {
  --frame: #eceeef;
  --ground: #f5f6f7;
  --surface: #ffffff;
  --raised: #f4f6f8;
  --active: #e6e8ea;
  --border: #e3e5e7;
  --rule: #eff0f1;
  --control: #c4c7ca;
  --text: #131416;
  --muted: #565a5d;
  --faint: #6b6f72;
  --primary: #1d1f20;
  --accent: #d97a06;
  --accent-ink: #8a4a00;
  --positive: #1e7b4f;
  --negative: #c4242a;
  --pill-neutral-bg: #e6e8ea;
  --pill-neutral-ink: #353736;
  --pill-positive-bg: #dcfae5;
  --pill-positive-ink: #04250e;
  --pill-warning-bg: #fff3d6;
  --pill-warning-ink: #6b3b00;
  --radius-card: 8px;
  --radius-control: 4px;
  --radius-sheet: 10px;
  --margin: 8px;
  --gap: 12px;
  --pad: 16px;
  --control-height: 32px;
  --fs-title: 22px;
  --fs-section: 16px;
  --fs-body: 14px;
  --fs-small: 12px;
  --font: "IBM Plex Sans", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { background: var(--frame); }
body { margin: 0; font: 400 var(--fs-body)/1.45 var(--font); color: var(--text); background: var(--frame); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, p, ol, dl, dd { margin: 0; padding: 0; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }
kbd { font: 500 11px/1 var(--font); padding: 2px 5px; border: 1px solid var(--control); border-radius: 3px; background: var(--surface); color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--primary); color: #fff; padding: 8px 12px; z-index: 50; border-radius: var(--radius-control); }
.skip:focus { left: 8px; }

/* Shell ------------------------------------------------------------------ */
.app { display: flex; flex-direction: column; min-height: 100vh; height: 100vh; padding: 0 var(--margin) var(--margin); }
.topbar { height: 48px; flex: none; display: flex; align-items: center; gap: 8px; padding: 0 4px; }
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-size: var(--fs-section); color: var(--text); text-decoration: none; padding-right: 8px; }
.brand svg { color: var(--accent); }
.doc-title { font-size: var(--fs-body); font-weight: 500; color: var(--muted); max-width: 28ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-spacer { flex: 1; }
.workspace { flex: 1; min-height: 0; display: grid; grid-template-columns: 232px minmax(0, 1fr) 340px; gap: var(--gap); }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sheet); min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.panel-title { padding: 14px var(--pad) 8px; font-size: var(--fs-small); color: var(--muted); font-weight: 500; }

/* Controls --------------------------------------------------------------- */
.btn { height: var(--control-height); padding: 0 12px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: var(--surface); border: 1px solid var(--control); border-radius: var(--radius-control); cursor: pointer; font-weight: 500; white-space: nowrap; transition: background-color .12s, transform .08s; }
.btn:hover { background: var(--active); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: #000; }
.btn.small { height: 26px; padding: 0 8px; font-size: var(--fs-small); }
.btn.block { width: 100%; justify-content: flex-start; white-space: normal; text-align: left; height: auto; min-height: var(--control-height); padding: 6px 12px; }
.btn:disabled { color: var(--faint); background: var(--raised); cursor: not-allowed; }
.icon-btn { width: var(--control-height); height: var(--control-height); display: inline-grid; place-items: center; background: transparent; border: 0; border-radius: var(--radius-control); cursor: pointer; color: var(--muted); transition: background-color .12s; }
.icon-btn:hover { background: var(--active); color: var(--text); }
.icon-btn.solid { background: var(--surface); border: 1px solid var(--control); color: var(--text); font-size: 16px; line-height: 1; }
.icon-btn.solid:hover { background: var(--active); }
.inline-field { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: var(--fs-small); }
select, input[type="number"], input[type="text"], textarea { height: var(--control-height); padding: 0 8px; background: var(--surface); border: 1px solid var(--control); border-radius: var(--radius-control); }
select { padding-right: 4px; }
textarea { height: auto; padding: 8px; resize: vertical; font-family: ui-monospace, "IBM Plex Mono", Menlo, monospace; font-size: 12px; line-height: 1.5; }
.pill { display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: 4px; font-size: var(--fs-small); font-weight: 500; background: var(--pill-neutral-bg); color: var(--pill-neutral-ink); white-space: nowrap; }
.pill.ok { background: var(--pill-positive-bg); color: var(--pill-positive-ink); }
.pill.warn { background: var(--pill-warning-bg); color: var(--pill-warning-ink); }

/* Steps ------------------------------------------------------------------ */
.step-list { list-style: none; padding: 4px 8px; flex: 1; overflow: auto; }
.step-list button { width: 100%; text-align: left; display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 0; min-height: 48px; padding: 0 8px; border: 0; border-radius: var(--radius-control); background: transparent; cursor: pointer; font-weight: 400; color: var(--text); }
.step-list button:hover { background: var(--raised); }
.step-list button[aria-current="step"] { background: var(--active); font-weight: 600; }
.step-list .sub { color: var(--muted); font-size: var(--fs-small); font-weight: 400; }
.steps-foot { padding: 8px; display: grid; gap: 6px; border-top: 1px solid var(--rule); }

/* Stage ------------------------------------------------------------------ */
.stage { background: var(--surface); }
.tabs { display: flex; align-items: center; gap: 4px; padding: 0 var(--pad); height: 44px; flex: none; border-bottom: 1px solid var(--rule); overflow-x: auto; }
.tabs [role="tab"] { height: 44px; padding: 0 12px; background: transparent; border: 0; border-bottom: 2px solid transparent; color: var(--muted); cursor: pointer; font-weight: 400; white-space: nowrap; }
.tabs [role="tab"]:hover { color: var(--text); }
.tabs [role="tab"][aria-selected="true"] { color: var(--text); font-weight: 600; border-bottom-color: var(--accent); }
.tabs-spacer { flex: 1; }
.well { position: relative; flex: 1; min-height: 0; background: var(--raised); overflow: hidden; display: grid; place-items: center; }
.bed-wrap { position: absolute; inset: 0; display: grid; place-items: center; padding: 16px; }
.bed { width: 100%; height: 100%; }
.bed line, .bed polygon { vector-effect: non-scaling-stroke; }
.bed .edge { fill: var(--surface); stroke: var(--control); stroke-width: 1.5; }
.bed .gridline { stroke: var(--control); stroke-width: 1; stroke-dasharray: 3 5; }
.bed .sheet { fill: none; stroke: var(--accent); stroke-width: 2; }
.bed text { font: 500 12px var(--font); fill: var(--muted); }
.canvas { position: relative; max-width: 100%; max-height: 100%; background: #fff; border: 1px solid var(--control); image-rendering: auto; transform-origin: center; }
.dropzone { position: relative; z-index: 2; background: var(--surface); border: 1px dashed var(--control); border-radius: var(--radius-card); padding: 24px 32px; text-align: center; max-width: 380px; transition: border-color .12s, background-color .12s; }
.dropzone.over { border-color: var(--accent); background: #fffaf2; }
.dz-title { font-size: var(--fs-section); font-weight: 600; margin-bottom: 4px; }
.dz-sub { color: var(--muted); margin-bottom: 16px; }
.well-note { position: absolute; z-index: 2; left: 50%; bottom: 56px; transform: translateX(-50%); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); padding: 8px 12px; color: var(--muted); max-width: 90%; text-align: center; }
.overlay { position: absolute; z-index: 3; display: flex; align-items: center; gap: 6px; }
.overlay.tl { top: 12px; left: 12px; }
.overlay.br { right: 12px; bottom: 12px; background: var(--surface); border: 1px solid var(--control); border-radius: var(--radius-control); padding: 4px 8px; color: var(--muted); font-size: var(--fs-small); }
.zoom-val { min-width: 48px; text-align: center; font-size: var(--fs-small); color: var(--muted); }
.timeline { flex: none; display: flex; align-items: center; gap: 12px; padding: 10px var(--pad); border-top: 1px solid var(--rule); flex-wrap: wrap; }
.timeline output { min-width: 84px; color: var(--muted); }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-small); color: var(--muted); cursor: pointer; }
.scrub { flex: 1; min-width: 120px; }

/* Range inputs ----------------------------------------------------------- */
input[type="range"] { -webkit-appearance: none; appearance: none; height: 20px; background: transparent; margin: 0; width: 100%; cursor: pointer; }
input[type="range"]::-webkit-slider-runnable-track { height: 4px; background: var(--control); border-radius: 2px; }
input[type="range"]::-moz-range-track { height: 4px; background: var(--control); border-radius: 2px; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; margin-top: -6px; background: var(--primary); border: 2px solid var(--surface); border-radius: 50%; }
input[type="range"]::-moz-range-thumb { width: 12px; height: 12px; background: var(--primary); border: 2px solid var(--surface); border-radius: 50%; }
input[type="range"]:hover::-webkit-slider-thumb { background: var(--accent); }
input[type="range"]:hover::-moz-range-thumb { background: var(--accent); }
input[type="checkbox"] { accent-color: var(--primary); width: 15px; height: 15px; margin: 0; }

/* Rail ------------------------------------------------------------------- */
.rail-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px var(--pad); border-bottom: 1px solid var(--rule); flex: none; }
.rail-head h2 { font-size: var(--fs-section); font-weight: 600; }
.rail-body { flex: 1; min-height: 0; overflow: auto; padding: 4px var(--pad) 16px; }
.group { margin-top: 18px; font-size: var(--fs-body); font-weight: 600; }
.ctl { padding: 10px 0; border-bottom: 1px solid var(--rule); }
.ctl:last-child { border-bottom: 0; }
.ctl-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 24px; }
.ctl-row > label, .ctl-row > .lbl { font-size: var(--fs-body); }
.ctl-val { display: flex; align-items: center; gap: 4px; color: var(--muted); }
.ctl-val input[type="number"] { width: 72px; height: 26px; text-align: right; padding: 0 6px; }
.ctl-val .unit { font-size: var(--fs-small); min-width: 2ch; }
.ctl .reset { width: 22px; height: 22px; opacity: 0; }
.ctl:hover .reset, .ctl:focus-within .reset { opacity: 1; }
.ctl .reset[disabled] { visibility: hidden; }
.ctl-field { margin-top: 6px; }
.ctl-field select, .ctl-field input[type="text"], .ctl-field textarea { width: 100%; }
.hint { margin-top: 2px; font-size: var(--fs-small); color: var(--muted); }
.switch { position: relative; width: 34px; height: 20px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; width: 100%; height: 100%; cursor: pointer; }
.switch span { position: absolute; inset: 0; background: var(--control); border-radius: 10px; transition: background-color .12s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; background: #fff; border-radius: 50%; transition: transform .12s; }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(14px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.code-panel { flex: none; margin-top: var(--gap); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sheet); }
.code-panel summary { cursor: pointer; padding: 10px var(--pad); font-weight: 600; display: flex; gap: 12px; align-items: baseline; }
.code-bar { display: flex; align-items: center; gap: 12px; padding: 0 var(--pad) 8px; }
.code-panel textarea { display: block; width: calc(100% - 2 * var(--pad)); margin: 0 var(--pad) var(--pad); height: 200px; min-height: 80px; max-height: 70vh; resize: vertical; }

/* Pen picker ------------------------------------------------------------- */
.pens { display: grid; gap: 8px; margin-top: 8px; }
.pen-row { display: flex; gap: 6px; align-items: center; }
.pen-row input[type="color"] { flex: none; width: 36px; height: var(--control-height); padding: 2px; background: var(--surface); border: 1px solid var(--control); border-radius: var(--radius-control); cursor: pointer; }
.pen-row input[type="text"] { flex: 1 1 0; width: 0; min-width: 0; }
.pen-row .btn { flex: none; }
.pen-cat { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 0 2px; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--control); cursor: pointer; padding: 0; }
.swatch:hover, .swatch:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Dialog, toast ---------------------------------------------------------- */
dialog { border: 1px solid var(--border); border-radius: var(--radius-sheet); padding: 24px; width: min(420px, 92vw); box-shadow: 0 8px 32px rgba(0,0,0,.14); }
dialog::backdrop { background: rgba(20,22,24,.35); }
dialog h2 { font-size: var(--fs-section); margin-bottom: 16px; }
.keys { display: grid; gap: 8px; margin-bottom: 20px; }
.keys > div { display: grid; grid-template-columns: 120px 1fr; gap: 8px; align-items: center; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 16px); background: var(--primary); color: #fff; padding: 8px 14px; border-radius: var(--radius-control); opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; z-index: 60; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Footer (from pierref/landing v2, light) -------------------------------- */
.footer-v2 { padding: 4rem 16px 1.5rem; text-align: center; overflow: hidden; position: relative; }
.footer-nav { display: flex; gap: 2rem; justify-content: center; flex-wrap: wrap; margin-bottom: 2.5rem; font-size: .95rem; font-weight: 600; }
.footer-nav a { color: var(--text); text-decoration: none; transition: color .2s; }
.footer-nav a:hover { color: var(--accent-ink); }
.footer-nav { font-weight: 700; letter-spacing: .05em; }
.footer-nav .footer-dim { color: var(--muted); font-weight: 600; }
.footer-nav .footer-credits { color: #ec6a11; font-weight: 800; border-bottom: 2px solid #ec6a11; padding-bottom: 2px; }
.pierref-review-widget { max-width: 520px; margin: 0 auto 2.5rem; }
.huge-text { font-weight: 900; font-size: 15vw; line-height: .8; color: transparent; -webkit-text-stroke: 2px var(--control); opacity: .6; transition: color .3s, -webkit-text-stroke .3s, opacity .3s; user-select: none; }
.huge-text:hover { color: var(--text); -webkit-text-stroke: 0 transparent; opacity: 1; }
.footer-copy { margin-top: 1.5rem; font-size: .8rem; color: var(--muted); letter-spacing: .1em; text-transform: uppercase; }

/* Narrow screens --------------------------------------------------------- */
@media (max-width: 1180px) {
  .workspace { grid-template-columns: 200px minmax(0, 1fr) 300px; }
  .doc-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  #btn-copy { display: none; }
}
@media (max-width: 900px) {
  .app { height: auto; min-height: 0; }
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 4px; }
  .topbar .inline-field span, #btn-recalc kbd { display: none; }
  .workspace { grid-template-columns: 1fr; }
  .steps .panel-title, .steps-foot { display: none; }
  .step-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px; padding: 8px; }
  .step-list button { min-height: 40px; }
  .step-list .sub { display: none; }
  .tabs { padding: 0 8px; gap: 0; }
  .tabs [role="tab"] { padding: 0 8px; }
  #pill-state { display: none; }
  .stage { min-height: 420px; }
  .rail { min-height: 360px; }
  .huge-text { font-size: 17vw; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* colour layer picker */
.overlay.tr { top: 12px; right: 12px; flex-wrap: wrap; justify-content: flex-end; max-width: 60%; }
.layer { display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 9px; border: 1px solid var(--control); border-radius: var(--radius-control); background: var(--surface); color: var(--muted); font-size: var(--fs-small); cursor: pointer; }
.layer.on { color: var(--ink, inherit); border-color: var(--accent); }
.layer i { width: 12px; height: 12px; border-radius: 50%; border: 1px solid rgba(0,0,0,.25); }
