/* Shared styles for the free tools under /tools. Uses the tokens from style.css; content/design-notes.md explains the
   look. A tool that needs more adds its own assets/tools/<tool>.css and lists it in its page's front matter (tool_css).
   Markup to pair with these (content/tools-test/demo/demo.js shows all of it): .tool-error gets role="alert" so
   screen readers announce it; .tool-progress gets role="progressbar" with aria-valuenow kept up to date.

   Pieces: .tool (the card) > .tool-stage (the bed: canvas, .tool-drop, .tool-progress, floating chips) then
   .tool-error, .tool-bar (.tool-stats readout and .tool-btn buttons) and .tool-note. Black buttons (.primary) are the
   action; blue marks state (selection, progress, drag-over, focus). Anything floating on the stage takes the chip
   material from the --chip-* tokens below: a new floating element joins the selector list of the chip rule under the
   drop zone (it names tool classes so it can outrank .tool-btn on the Reset view buttons).
   --pad is the inset of everything under the stage: on phones it matches the article column's 24 px. */
.tool{
  --stage:#F1F2F6;--grid:#2442E41A;--grid-fine:#2442E40A;--err-ink:#9A2B1F;--pad:20px;
  --err-icon:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 18 18'%3E%3Ccircle cx='9' cy='9' r='9' fill='%23C0392B'/%3E%3Cpath d='M9 4.6v5.2' stroke='white' stroke-width='1.8' stroke-linecap='round'/%3E%3Ccircle cx='9' cy='12.9' r='1.1' fill='white'/%3E%3C/svg%3E");
  --chip-bg:#FFFFFFE0;--chip-line:#14141314;--chip-shadow:0 1px 2px #14141308,0 6px 20px -8px #14141326;
  --chip-filter:blur(12px) saturate(160%);
  position:relative;
  margin-top:32px;background:var(--card);border:1px solid var(--line);border-radius:16px;
  box-shadow:0 1px 2px #14141308,0 18px 48px -24px #1414131F;overflow:hidden;
  /* Wider than the text on big screens (--wide, 832 px), centred on the column; full width on phones (below). */
  margin-inline:calc((100% - var(--wide)) / 2)}

/* ---------- the stage: a print bed with a millimetre grid that fades out towards the edges ---------- */
.tool-stage{position:relative;width:100%;aspect-ratio:16/10;max-height:72vh; /* width:100%: with max-height, the ratio would otherwise narrow the bed */
  border-bottom:1px solid var(--line);
  background:
    radial-gradient(ellipse 70% 65% at 50% 50%,#F1F2F600 25%,var(--stage) 95%),
    linear-gradient(var(--grid) 1px,transparent 1px) 50% 50%/48px 48px,
    linear-gradient(90deg,var(--grid) 1px,transparent 1px) 50% 50%/48px 48px,
    linear-gradient(var(--grid-fine) 1px,transparent 1px) 50% 50%/12px 12px,
    linear-gradient(90deg,var(--grid-fine) 1px,transparent 1px) 50% 50%/12px 12px,
    var(--stage)}
/* Before the first part is shown (no canvas yet) the empty bed is shorter on wide screens; it grows when the 3D view
   arrives. Phones keep 1:1 throughout. */
.tool-stage:not(:has(.tool-canvas)){aspect-ratio:2/1}
/* viewer.js sets touch-action: pan-y on the canvas (inline, after OrbitControls), so a vertical swipe scrolls the page. */
.tool-canvas{display:block;width:100%;height:100%;cursor:grab}
.tool-canvas:focus-visible{outline:2px solid var(--blue);outline-offset:-4px}
.tool-canvas:active{cursor:grabbing}

/* Drop zone: fills the stage until a file is open. A dashed outline only where dropping is possible. */
.tool-drop{position:absolute;inset:14px;display:grid;place-items:center;align-content:center;gap:10px;text-align:center;padding:24px;
  border:1.5px solid transparent;border-radius:12px;color:var(--gray);font-size:15px;line-height:1.5;
  transition:border-color 150ms ease,background-color 150ms ease,box-shadow 150ms ease}
.tool-drop strong{color:var(--fg);font-weight:600;font-size:17px;letter-spacing:-.01em}
@media (pointer:fine){.tool-drop{border-style:dashed;border-color:var(--blue)}} /* about 6:1 on the bed */
/* The drop zone usually wraps a visually hidden <input type=file>; show keyboard focus inside it on the zone. Not
   :focus-within, which also lights up when a tool hands focus back to its button after a tap. */
.tool-drop:has(:focus-visible),.tool-drop:has(input[type=file]:focus){border-color:var(--blue);border-style:solid;box-shadow:0 0 0 4px #2442E41F}
/* While a file is dragged over, the zone frosts whatever part is on screen behind it. */
.tool-drop.over{border-color:var(--blue);border-style:solid;color:var(--fg);background:#EDEFF8E6;-webkit-backdrop-filter:blur(6px);backdrop-filter:blur(6px)}
.tool-drop[hidden]{display:none}

/* The chip material, for everything that floats on the stage. Tool parts are listed here, not copied into each file. */
.tool-progress,.tool-stage .step-reset,.tool-bar [data-reset],.sf-legend,.sf-busy,.sf-stale-note{background:var(--chip-bg);border:1px solid var(--chip-line);
  border-radius:10px;box-shadow:var(--chip-shadow);-webkit-backdrop-filter:var(--chip-filter);backdrop-filter:var(--chip-filter)}

/* Progress: a card centred on the bed. */
.tool-progress{position:absolute;z-index:2;left:50%;top:50%;transform:translate(-50%,-50%);width:min(340px,calc(100% - 32px));
  display:grid;gap:8px;padding:12px 14px;font-size:13.5px;color:var(--fg)}
.tool-progress[hidden]{display:none}
/* While it shows, the prompt under it steps back so the card reads first. */
.tool-stage:has(>.tool-progress:not([hidden])) .tool-drop>*{visibility:hidden}
.tool-progress i{display:block;height:4px;border-radius:4px;background:#2442E41F;overflow:hidden}
.tool-progress i>span{display:block;height:100%;width:0;border-radius:4px;background:var(--blue);transition:width 120ms linear}

/* ---------- below the stage ---------- */
.tool-error{position:relative;margin:14px var(--pad) 0;padding:11px 14px 11px 42px;font-size:14.5px;line-height:1.5;color:var(--err-ink);
  background:#C0392B0D;border:1px solid #C0392B3D;border-radius:12px}
.tool-error::before{content:"";position:absolute;left:14px;top:13px;width:18px;height:18px;background:var(--err-icon) center/18px no-repeat}
.tool-error[hidden]{display:none}

.tool-bar{display:flex;flex-wrap:wrap;align-items:center;gap:10px;padding:14px var(--pad)}

/* The readout: each <span>Label <b>value</b></span> (or <div><dt>…</dt><dd>…</dd></div>) is a cell, label above value. */
.tool-stats{flex:1 1 auto;display:flex;flex-wrap:wrap;gap:12px 28px;margin:0 8px 0 0;font-size:12.5px;color:var(--gray)}
.tool-stats>span,.tool-stats>div{display:flex;flex-direction:column;gap:1px;min-width:0}
.tool-stats b,.tool-stats dd{font-family:var(--mono);font-size:15px;line-height:1.35;color:var(--fg);font-weight:400;font-variant-numeric:tabular-nums;margin:0}
.tool-note{display:grid;gap:4px;padding:14px var(--pad) 16px;font-size:13px;line-height:1.5;color:var(--gray)}
/* A shown bar already leaves 14 px below it; a shown error, which has no bottom margin, needs the note's gap back. */
.tool-bar:not([hidden])~.tool-note{padding-top:0}
.tool-error:not([hidden])~.tool-note{padding-top:14px}

/* ---------- controls ---------- */
.tool-btn{display:inline-flex;align-items:center;justify-content:center;gap:8px;height:44px;padding:0 18px;border:1px solid #14141326;border-radius:12px;background:var(--card);
  color:var(--fg);font:inherit;font-size:14.5px;font-weight:520;letter-spacing:-.005em;white-space:nowrap;cursor:pointer;
  touch-action:manipulation;-webkit-user-select:none;user-select:none;
  transition:transform 140ms var(--ease-out),background-color 150ms ease,border-color 150ms ease,color 150ms ease}
.tool-btn:active{transform:scale(.97)}
.tool-btn.primary{background:var(--fg);border-color:var(--fg);color:#fff}
/* Disabled: a flat, faint fill with grey text, so it reads as "not yet" rather than a grey slab (and isn't dashed like a drop zone). */
.tool-btn[disabled],.tool-btn.primary[disabled]{background:#1414130A;border-color:transparent;color:var(--gray);cursor:default;transform:none}
/* The display values above would otherwise beat the hidden attribute. */
.tool [hidden]{display:none!important}

/* Field borders use --gray (about 5:1 on white) so number fields and selects meet WCAG 1.4.11's 3:1 for control edges. */
.tool select,.tool input[type=number],.tool input[type=text]{height:44px;padding:0 12px;font:inherit;font-size:14.5px;color:var(--fg);background-color:var(--card);
  border:1px solid var(--gray);border-radius:12px;min-width:0;transition:border-color 150ms ease,box-shadow 150ms ease}
.tool select{-webkit-appearance:none;appearance:none;padding-right:36px;cursor:pointer;
  background:var(--card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5 6 7.5 9 4.5' fill='none' stroke='%23141413' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") right 12px center/12px no-repeat}
/* Keyboard focus: the site's 2 px blue outline (style.css), plus a blue edge. */
.tool select:focus-visible,.tool input[type=number]:focus-visible,.tool input[type=text]:focus-visible{outline:2px solid var(--blue);outline-offset:2px;border-color:var(--blue)}
.tool label{font-size:13.5px;color:var(--gray)}
/* Desktop Safari draws spin arrows over the unit suffix; arrow keys still step the value. */
.tool input[type=number]{-moz-appearance:textfield;appearance:textfield}
.tool input[type=number]::-webkit-inner-spin-button,.tool input[type=number]::-webkit-outer-spin-button{-webkit-appearance:none;margin:0}
/* 16 px on touch screens stops iOS Safari zooming the page when a field gets focus. */
@media (pointer:coarse){.tool select,.tool input[type=number],.tool input[type=text]{font-size:16px}}

/* ---------- motion: the readout and an error fade in when they appear. Only these: bars that are on screen from the
   start must not animate on page load. Opacity only, so nothing inside changes its containing block mid-fade. ---------- */
.tool-bar[data-bar],.tool-error{transition:opacity 240ms var(--ease-out)}
@starting-style{.tool-bar[data-bar],.tool-error{opacity:0}}

/* ---------- tools hub (/tools) ---------- */
.tool-hub{margin-top:40px;margin-inline:calc((100% - var(--wide)) / 2)}
.tool-hub h2{margin-top:0;font-size:17px;letter-spacing:-.015em;color:var(--fg);font-weight:600}
.tool-hub h2~h2{margin-top:44px}
.tool-hub .tool-list{list-style:none;padding:0;margin-top:14px;display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:12px}
.tool-hub .tool-list li{margin:0}
.tool-list a{position:relative;display:flex;flex-direction:column;gap:4px;height:100%;padding:16px 18px 18px;background:var(--card);border:1px solid var(--line);border-radius:16px;
  text-decoration:none;box-shadow:0 1px 2px #14141308;transition:border-color 150ms ease,transform 140ms var(--ease-out);touch-action:manipulation}
.tool-list a:active{transform:scale(.985)}
.tool-list a strong{color:var(--fg);font-weight:600;font-size:16px;line-height:1.3;letter-spacing:-.01em}
.tool-list a span{font-size:14px;line-height:1.5;color:var(--gray)}
.tool-list a .tool-tag{order:-1;align-self:flex-start;margin-bottom:6px;padding:2px 8px;border-radius:6px;background:#2442E40F;color:#1F38C4;font-family:var(--mono);font-size:12px;line-height:1.6}

@media (hover:hover) and (pointer:fine){
  .tool-btn:hover{border-color:#14141359}
  .tool-btn.primary:hover{background:#2E2E2B;border-color:#2E2E2B}
  .tool-btn[disabled]:hover{border-color:transparent}
  .tool select:hover,.tool input[type=number]:hover,.tool input[type=text]:hover{border-color:var(--fg)}
  .tool-list a:hover{border-color:#2442E466}
}
@media (max-width:860px){.tool-hub .tool-list{grid-template-columns:repeat(2,minmax(0,1fr))}}
/* Phones: the tool runs edge to edge (the column has 24 px padding), so the 3D view gets the whole width. */
@media (max-width:560px){
  .tool{--pad:24px;margin-inline:-24px;border-radius:0;border-left:0;border-right:0;box-shadow:none}
  .tool-stage,.tool-stage:not(:has(.tool-canvas)){aspect-ratio:1/1} /* both, or the empty-bed 2:1 rule above wins and clips the drop zone */
  .tool-drop{inset:10px}
  .tool-stats{flex-basis:100%;margin:0 0 4px;display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:10px 16px}
  .tool-stats>span:first-child,.tool-stats>div:first-child{grid-column:1/-1}
  .tool-stats b,.tool-stats dd{font-size:14.5px}
  .tool-bar .tool-btn{flex:1 1 calc(50% - 5px)}
  .tool-bar .tool-btn.primary{flex-basis:100%}
  .tool-hub .tool-list{grid-template-columns:minmax(0,1fr);gap:10px}
}
@media (prefers-reduced-motion:reduce){
  .tool-btn,.tool-drop,.tool-list a{transition:none}
  .tool-bar[data-bar],.tool-error{transition:opacity 200ms ease}
}
/* Safari doesn't support this query yet; Chromium does. */
@media (prefers-reduced-transparency:reduce){
  .tool{--chip-bg:#fff;--chip-filter:none}
  .tool-drop.over{background:#EDEFF8;-webkit-backdrop-filter:none;backdrop-filter:none}
}
