/* (c) Alpas Made LLC. All rights reserved.
 *
 * Kinetic Scatter on the KC Tools design system.
 *
 * The tool's code reads and toggles these names: over, erasing, grab, and it
 * builds .sl, .name, .val, .note, .mask-row, .mini, .del, .ex, .fmt, .btn,
 * .note-box (good, bad), .readout .v (warn, bad, good) and .pill. They are kept
 * and restyled here, scoped under .ks. Every value is a --kc-* or --kt-* token.
 */

.ks { --ks-panel-w: 360px; }
.ks [hidden] { display: none !important; }

/* ---------- small parts */
.ks .hint { margin: 0; font-size: 13px; line-height: 1.5; color: var(--kc-muted); }
.ks .row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.ks .pill { display: inline-flex; align-items: center; min-height: 28px; padding: 0 12px; border-radius: var(--kc-radius-pill); background: var(--kc-raised); border: 1px solid var(--kc-hairline); font-size: 13px; color: var(--kc-prose); max-width: 100%; overflow-wrap: anywhere; }
.ks .ks-tagline { margin: 4px 0 0; }
.ks #file-row { margin-top: 8px; }
.ks .ks-legal { margin: 0; max-width: 72ch; }
.ks label { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 8px; max-width: 100%; font-size: 14px; color: var(--kc-prose); }

/* ---------- fields */
.ks select, .ks input[type="number"], .ks input[type="url"] {
  min-height: var(--kt-target); padding: 8px 12px; border-radius: var(--kc-radius-control); border: 1px solid var(--kc-hairline);
  background: var(--kc-raised); color: var(--kc-text); font: 400 16px/1.2 var(--kc-body); max-width: 100%; transition: border-color var(--kc-hover);
}
.ks select:hover, .ks input[type="number"]:hover, .ks input[type="url"]:hover { border-color: var(--kc-line-hover); }
.ks input[type="number"] { width: 104px; font-variant-numeric: tabular-nums; }
.ks input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: var(--kt-target); margin: 0; background: transparent; cursor: pointer; }
.ks input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: var(--kc-radius-pill); background: var(--kc-line-ui); }
.ks input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; margin-top: -8px; border-radius: var(--kc-radius-pill); background: var(--kc-red-button); border: 2px solid #ffffff; }
.ks input[type="range"]::-moz-range-track { height: 4px; border-radius: var(--kc-radius-pill); background: var(--kc-line-ui); }
.ks input[type="range"]::-moz-range-thumb { width: 16px; height: 16px; border-radius: var(--kc-radius-pill); background: var(--kc-red-button); border: 2px solid #ffffff; }
.ks input[type="range"]:disabled { cursor: default; opacity: 0.6; }
.ks input[type="range"]:focus-visible { outline: 2px solid var(--kc-focus, #69b3ff); outline-offset: 2px; }
.ks input[type="checkbox"] { width: 20px; height: 20px; margin: 0; accent-color: var(--kc-red-button); }

/* ---------- buttons. .btn is the red one: SVG, the first download. The rest are secondary */
.ks .btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--kt-target); padding: 0 20px; border: 0; border-radius: var(--kc-radius-control); background: var(--kc-red-button); color: #ffffff; font: 600 15px/1 var(--kc-body); cursor: pointer; transition: background var(--kc-hover); }
.ks .btn:hover:not(:disabled) { background: var(--kc-red-hover); }
.ks button.ghost, .ks .ex:not(:first-child) .btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--kt-target); padding: 0 16px; border: 1px solid var(--kc-line-ui); border-radius: var(--kc-radius-control); background: var(--kc-card); color: var(--kc-text); font: 500 15px/1.2 var(--kc-body); cursor: pointer; text-align: center; transition: background var(--kc-hover); }
.ks button.ghost:hover:not(:disabled), .ks .ex:not(:first-child) .btn:hover:not(:disabled) { background: var(--kc-raised); }
.ks button.ghost.small { padding: 0 12px; font-size: 14px; }
.ks button.ghost[aria-pressed="true"] { background: var(--kc-line-inner); border-color: var(--kc-text); box-shadow: inset 0 0 0 1px var(--kc-text); }
.ks .btn:disabled, .ks button.ghost:disabled { opacity: 0.6; cursor: not-allowed; }

/* ---------- segmented choices: aria-pressed is the state the code sets */
.ks .seg { display: flex; flex-wrap: wrap; gap: 8px; }
.ks .seg button { min-height: var(--kt-target); padding: 8px 16px; border: 1px solid var(--kc-hairline); border-radius: var(--kc-radius-pill); background: var(--kc-raised); color: var(--kc-muted); font: 500 14px/1.2 var(--kc-body); cursor: pointer; transition: border-color var(--kc-hover), color var(--kc-hover); }
.ks .seg button:hover { color: var(--kc-text); border-color: var(--kc-line-hover); }
.ks .seg button[aria-pressed="true"] { background: var(--kc-line-inner); border-color: var(--kc-text); box-shadow: inset 0 0 0 1px var(--kc-text); color: var(--kc-text); }

/* ---------- before a photo */
.ks .ks-drop { display: grid; gap: 16px; }
.ks #dropzone { display: grid; justify-items: center; gap: 8px; padding: 64px 24px; text-align: center; border: 1px dashed var(--kc-line-ui); border-radius: var(--kc-radius-panel); background: var(--kc-card); cursor: pointer; transition: border-color var(--kc-hover), background var(--kc-hover); }
.ks #dropzone:hover, .ks #dropzone.over { border-color: var(--kc-line-hover); background: var(--kc-raised); }
.ks #dropzone .big { margin: 0; font: 600 clamp(20px, 2.2vw, 24px)/1.1 var(--kc-display); letter-spacing: -0.02em; text-transform: uppercase; color: var(--kc-text); }
.ks #dropzone .hint { max-width: 60ch; }
.ks .ks-drop-ic { width: 28px; height: 28px; color: var(--kc-muted); }
.ks .ks-alt { display: grid; gap: 16px; }
.ks #sample-row { justify-content: center; }
.ks .ks-link { display: grid; gap: 8px; max-width: 640px; width: 100%; justify-self: center; }
.ks .ks-link__label { font-size: 14px; font-weight: 600; color: var(--kc-text); }
.ks .ks-link__row { display: flex; gap: 8px; }
.ks .ks-link__row input { flex: 1 1 auto; min-width: 0; }
.ks .ks-link__msg { display: flex; align-items: center; gap: 12px; }
.ks .ks-link__msg:has(#url-state[hidden]):has(.ks-link__status:empty) { display: none; }
.ks .ks-link__msg.is-error { padding: 12px 16px; border-radius: var(--kc-radius-callout); background: var(--kc-red-tint); border: 1px solid var(--kc-red-edge); }
.ks .ks-link__status { margin: 0; font-size: 13px; line-height: 1.5; color: var(--kc-muted); }
.ks .ks-link__status:empty { display: none; }
.ks .ks-link__status.is-error { color: var(--kc-prose); }
.ks .ks-link__status.is-error b { color: var(--kc-text); font-weight: 600; }

/* ---------- the workbench: preview left, settings right */
.ks .work { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
.ks .stage { display: grid; gap: 12px; min-width: 0; padding: 12px; border-radius: var(--kc-radius-panel); background: var(--kc-card); border: 1px solid var(--kc-hairline); }
.ks .ks-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; }
.ks .ks-bar .seg button { min-height: 36px; padding: 0 12px; position: relative; }
.ks .ks-bar .seg button::after { content: ""; position: absolute; inset: -4px 0; }
.ks .stage-canvas { position: relative; display: grid; place-items: center; min-height: 200px; overflow: hidden; border-radius: var(--kc-radius-callout); background: #000000; }
.ks .stage-canvas canvas { display: block; max-width: 100%; height: auto; }
.ks .stage-canvas.grab canvas { touch-action: none; }
.ks .stage-canvas.erasing canvas { cursor: none; }
.ks .stage-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.ks .stage-bar .spacer { margin-left: auto; }
.ks .zoomer { display: inline-flex; align-items: center; gap: 4px; }
.ks .zoomer button { min-width: var(--kt-target); padding: 0 8px; }
.ks .zoom-label, .ks .erase-count { font: 500 13px/1 var(--kc-mono); color: var(--kc-muted); min-width: 36px; text-align: center; font-variant-numeric: tabular-nums; }
.ks .zoom-hint { font-size: 12px; color: var(--kc-muted); white-space: nowrap; }
.ks .erase-bar .brush { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--kc-muted); }
.ks .erase-bar .brush input[type="range"] { width: 140px; }
.ks .prog { height: 4px; overflow: hidden; border-radius: var(--kc-radius-pill); background: var(--kc-line-inner); }
.ks .prog > i { display: block; width: 0; height: 100%; background: var(--kc-red); transition: width 0.2s linear; }
.ks .readout { display: grid; gap: 4px 16px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); padding-top: 12px; border-top: 1px solid var(--kc-hairline); }
.ks .readout .line { display: flex; align-items: baseline; gap: 8px; min-width: 0; font-size: 14px; }
.ks .readout .line .k { flex: none; min-width: 76px; color: var(--kc-muted); }
.ks .readout .line .v { min-width: 0; overflow-wrap: anywhere; font: 500 14px/1.4 var(--kc-mono); color: var(--kc-text); font-variant-numeric: tabular-nums; }
.ks .readout .line .v.warn { color: var(--kc-flag); }
.ks .readout .line .v.bad { color: var(--kc-red); }
.ks .readout .line .v.good { color: var(--kc-text); }

/* notices under the preview */
.ks #warnings:empty { display: none; }
.ks .note-box { margin: 8px 0 0; padding: 12px 16px; border-radius: var(--kc-radius-callout); background: var(--kc-raised); border: 1px solid var(--kc-hairline); border-left: 3px solid var(--kc-flag); font-size: 14px; line-height: 1.45; color: var(--kc-prose); }
.ks .note-box.bad { background: var(--kc-red-tint); border-color: var(--kc-red-edge); border-left-color: var(--kc-red); }
.ks .note-box.good { border-left-color: var(--kc-hairline); }
.ks .note-box strong { color: var(--kc-text); }
.ks .note-box p { margin: 0; }
.ks .note-box p + p { margin-top: 8px; }

/* ---------- settings column: one panel, groups divided by hairlines */
.ks .settings { display: grid; min-width: 0; border-radius: var(--kc-radius-panel); background: var(--kc-card); border: 1px solid var(--kc-hairline); }
.ks .panel { display: grid; gap: 12px; padding: 16px; }
.ks .panel + .panel { border-top: 1px solid var(--kc-hairline); }
.ks .panel h3 { margin: 0; font: 600 16px/1.2 var(--kc-display); letter-spacing: -0.02em; text-transform: uppercase; color: var(--kc-heading); }
.ks .sliders { display: grid; gap: 8px; grid-template-columns: minmax(0, 1fr); }
.ks .sliders:empty { display: none; }
.ks .sl { position: relative; display: grid; grid-template-columns: 1fr auto; align-items: baseline; gap: 0 12px; }
.ks .sl > .name { font-size: 14px; font-weight: 500; color: var(--kc-text); }
.ks .sl > .val { justify-self: end; font: 500 13px/1 var(--kc-mono); color: var(--kc-prose); font-variant-numeric: tabular-nums; white-space: nowrap; }
.ks .sl > input[type="range"] { grid-column: 1 / -1; }
.ks .sl > .note { position: absolute; top: 100%; left: 0; right: 0; z-index: 6; padding: 8px 12px; margin-top: 4px; border-radius: var(--kc-radius-callout); background: var(--kc-raised); border: 1px solid var(--kc-line-ui); box-shadow: var(--kt-float-shadow); font-size: 13px; line-height: 1.45; color: var(--kc-prose); opacity: 0; visibility: hidden; transform: translateY(-4px); transition: opacity 0.12s ease, transform 0.12s ease, visibility 0.12s; pointer-events: none; }
.ks .sl:hover > .note, .ks .sl:focus-within > .note { opacity: 1; visibility: visible; transform: none; }
.ks .sl.key > .name::before, .ks .key-dot, .ks .key-legend .dot { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 8px; border-radius: var(--kc-radius-pill); background: var(--kc-red); vertical-align: 0.08em; }
.ks .key-legend { margin: 0; font-size: 13px; line-height: 1.5; color: var(--kc-muted); }
.ks .ks-size-note:empty { display: none; }
.ks .ks-size-note { color: var(--kc-flag); }
.ks .mask-row { display: flex; align-items: center; gap: 8px; padding: 4px 4px 4px 12px; border-radius: var(--kc-radius-callout); background: var(--kc-raised); border: 1px solid var(--kc-hairline); }
.ks .mask-row + .mask-row { margin-top: 8px; }
.ks .mask-row.sel { border-color: var(--kc-text); box-shadow: inset 0 0 0 1px var(--kc-text); }
.ks .mask-row .what { flex: 1; min-width: 0; font-size: 14px; }
.ks .mask-row .mini { min-height: 36px; padding: 0 12px; border: 1px solid var(--kc-line-ui); border-radius: var(--kc-radius-pill); background: none; color: var(--kc-muted); font: 500 13px/1 var(--kc-body); cursor: pointer; }
.ks .mask-row .mini[aria-pressed="true"] { border-color: var(--kc-text); color: var(--kc-text); background: var(--kc-line-inner); }
.ks .mask-row .del { width: var(--kt-target); height: var(--kt-target); padding: 0; border: 0; border-radius: var(--kc-radius-control); background: none; color: var(--kc-muted); font-size: 20px; line-height: 1; cursor: pointer; }
.ks .mask-row .del:hover { color: var(--kc-text); background: var(--kc-line-inner); }
.ks #mask-list:empty { display: none; }

/* ---------- output, always last */
.ks .ks-export { display: grid; gap: 16px; padding: 24px; border-radius: var(--kc-radius-panel); background: var(--kc-card); border: 1px solid var(--kc-hairline); }
.ks .ks-export .lead { margin: 0; max-width: 72ch; font-size: 15px; line-height: 1.6; color: var(--kc-prose); }
.ks .exports { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); }
.ks .ex { display: grid; grid-template-rows: auto auto 1fr auto; gap: 8px; padding: 16px; border-radius: var(--kc-radius-panel); background: var(--kc-raised); border: 1px solid var(--kc-hairline); }
.ks .ex h4 { margin: 0; font: 600 16px/1.2 var(--kc-display); letter-spacing: -0.02em; text-transform: uppercase; color: var(--kc-heading); }
.ks .ex p { margin: 0; font-size: 13px; line-height: 1.5; color: var(--kc-muted); }
.ks .ex .fmt { font: 500 12px/1.4 var(--kc-mono); color: var(--kc-muted); }
.ks .ex .btn { width: 100%; margin-top: 4px; }
.ks .subhead { margin: 8px 0 0; font: 600 16px/1.2 var(--kc-display); letter-spacing: -0.02em; text-transform: uppercase; color: var(--kc-heading); }
.ks .scroll-x { overflow-x: auto; }
.ks table.recipe { width: 100%; border-collapse: collapse; font-size: 14px; }
.ks table.recipe th, .ks table.recipe td { padding: 8px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--kc-line-row); }
.ks table.recipe th { font-weight: 500; white-space: nowrap; color: var(--kc-muted); }
.ks table.recipe td { color: var(--kc-text); }

/* the floating preview on a phone (the code shows it once the real one scrolls away) */
#mini-preview { position: fixed; left: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 40; width: 32vw; max-width: 152px; padding: 0; overflow: hidden; border-radius: var(--kc-radius-panel); border: 1px solid var(--kc-line-ui); background: #000000; box-shadow: var(--kt-float-shadow); cursor: pointer; }
#mini-preview canvas { display: block; width: 100%; height: auto; }

/* ---------- widths. 900px is the code's own switch (matchMedia): keep them together */
@media (min-width: 901px) {
  #mini-preview { display: none !important; }
  .ks .work { grid-template-columns: minmax(0, 1fr) var(--ks-panel-w); gap: 24px; height: calc(100vh - 32px); min-height: 540px; align-items: stretch; grid-template-rows: minmax(0, 1fr); }
  .ks .stage { height: 100%; min-height: 0; grid-template-rows: auto minmax(0, 1fr) auto auto auto auto auto auto; }
  .ks .settings { height: 100%; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; align-content: start; }
  .ks #warnings { max-height: 16vh; overflow-y: auto; overscroll-behavior: contain; }
}
@media (min-width: 901px) and (max-height: 880px) {
  .ks .readout { grid-template-columns: repeat(auto-fit, minmax(152px, 1fr)); gap: 4px 12px; }
  .ks .readout .line { font-size: 13px; }
  .ks #warnings { max-height: 96px; }
  .ks .stage { gap: 8px; }
}
@media (max-width: 599px) {
  .ks #dropzone { padding: 48px 16px; }
  .ks .stage { padding: 8px; }
  .ks .ks-export { padding: 16px; }
  .ks .zoom-hint { display: none; }
}
@media (prefers-reduced-motion: reduce) { .ks .sl > .note, .ks .prog > i { transition: none; } }
