/* index84 tools — shared tokens, layout and components.
   Every tool links this file; see DESIGN.md for the rules behind it. */
:root {
  --bg: #ffffff;
  --surface: #f4f4f6;
  --ink: #11111a;
  --muted: #66666a;
  --faint: #a0a0a6;
  --line: #e8e8ec;
  --track: #dcdce2;
  --accent: #ff5900;
  --accent-hover: #ff6c1f;
  /* white, not ink: APCA puts white on #FF5900 at about Lc 63 against Lc 46 for ink */
  --on-accent: #ffffff;
  /* state that is fine (saved, published): kept apart from the accent */
  --ok: #11a37c;
  --dot: rgb(17 17 26 / 0.11);
  --danger: #c2372b;
  --f-body: "Geist", system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --ease: cubic-bezier(.22, 1, .36, 1);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0d10; --surface: #17171c; --ink: #f1f1f4; --muted: #9a9aa2; --faint: #66666e; --line: #24242b;
    --track: #34343c; --dot: rgb(255 255 255 / 0.08); --danger: #ff7b6e; --ok: #2fcf9f;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d0d10; --surface: #17171c; --ink: #f1f1f4; --muted: #9a9aa2; --faint: #66666e; --line: #24242b;
  --track: #34343c; --dot: rgb(255 255 255 / 0.08); --danger: #ff7b6e; --ok: #2fcf9f;
  color-scheme: dark;
}
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--ink); font: 14px/1.5 var(--f-body);
  -webkit-font-smoothing: antialiased;
  padding-left: max(24px, env(safe-area-inset-left, 0px));
  padding-right: max(24px, env(safe-area-inset-right, 0px));
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
::selection { background: var(--accent); color: var(--on-accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app {
  display: grid; height: 100%; max-width: 1440px; margin: 0 auto; padding-block: 20px 24px;
  grid-template-columns: minmax(0, 1fr) 300px; grid-template-rows: auto minmax(0, 1fr);
  column-gap: 40px;
}
header { grid-column: 1; display: flex; flex-direction: column; align-items: flex-start; gap: 22px; padding-bottom: 24px; }
.mark { display: flex; align-items: center; gap: 10px; }
.mark svg { width: 22px; height: 22px; color: var(--accent); }
.mark h1 { font: 600 17px/1 var(--f-body); letter-spacing: -0.015em; margin: 0; }
.lead { margin: 0; font: 500 24px/1.3 var(--f-body); letter-spacing: -0.02em; text-wrap: balance; }
.lead span { display: block; color: var(--muted); }
.panel { grid-column: 2; grid-row: 2; }

/* ---------- stage ---------- */
.stage { grid-column: 1; grid-row: 2; display: grid; grid-template-rows: minmax(0, 1fr) auto; gap: 24px; min-height: 0; min-width: 0; }
/* The canvas is ink by default in both themes; it redefines the text tokens inside it,
   so anything a tool draws on the board picks up the right colours. Paper is the fallback for dark artwork. */
.board {
  --board-bg: #11111a; --dot: rgb(255 255 255 / 0.09);
  --ink: #f1f1f4; --muted: rgb(255 255 255 / 0.55); --line: rgb(255 255 255 / 0.1); --track: rgb(255 255 255 / 0.16); --edge: rgb(255 255 255 / 0.1);
  position: relative; border-radius: 16px; overflow: hidden; min-height: 320px;
  background-color: var(--board-bg);
  background-image: radial-gradient(var(--dot) 1px, transparent 1.4px);
  background-size: 16px 16px; background-position: center;
  transition: background-color .35s var(--ease);
}
.board[data-tone="paper"] {
  --board-bg: #f4f4f6; --dot: rgb(17 17 26 / 0.11);
  --ink: #11111a; --muted: #66666a; --line: #e8e8ec; --track: #dcdce2; --edge: rgb(17 17 26 / 0.08);
}
.board.drop::after { content: ""; position: absolute; inset: 10px; border: 1.5px dashed var(--accent); border-radius: 10px; pointer-events: none; }
#preview { position: absolute; inset: 0; display: grid; place-items: center; padding: 64px 48px 92px; }
#preview svg { max-width: 100%; max-height: 100%; width: auto; height: 100%; display: block; }
.views { position: absolute; top: 14px; left: 14px; display: flex; gap: 6px; z-index: 1; }
.chip {
  position: relative; display: inline-flex; align-items: center; gap: 7px; cursor: pointer; user-select: none;
  font: 500 12px/1 var(--f-body); padding: 7px 11px 7px 10px; border-radius: 999px;
  background: rgb(255 255 255 / 0.85); color: #66666a; backdrop-filter: blur(8px);
  box-shadow: 0 0 0 1px rgb(17 17 26 / 0.06), 0 1px 2px rgb(17 17 26 / 0.06);
  transition: color .15s;
}
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #c4c4ca; transition: background .15s; }
.chip:hover { color: #11111a; }
.chip:has(input:checked) { color: #11111a; }
.chip:has(input:checked)::before { background: var(--accent); }
.chip:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.stats {
  position: absolute; right: 16px; top: 20px; font: 12px var(--f-mono); color: var(--muted);
  font-variant-numeric: tabular-nums; pointer-events: none;
}
.msg {
  position: absolute; left: 14px; top: 58px; right: 14px; z-index: 2; font-size: 13px; color: var(--danger);
  background: var(--bg); border-radius: 10px; padding: 10px 14px; box-shadow: 0 2px 12px rgb(0 0 0 / 0.08);
}

/* ---------- shape dock (floats on the board) ---------- */
.dock {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 1;
  transition: left .5s var(--ease), transform .5s var(--ease);
  display: flex; gap: 2px; padding: 4px; border-radius: 14px; max-width: calc(100% - 28px); overflow-x: auto;
  background: rgb(255 255 255 / 0.88); backdrop-filter: blur(12px);
  box-shadow: 0 0 0 1px rgb(17 17 26 / 0.06), 0 6px 20px rgb(17 17 26 / 0.12);
}
.dock .item {
  position: relative; flex: none; display: flex; align-items: center; gap: 9px; padding: 4px 12px 4px 4px;
  border: 0; border-radius: 10px; background: none; color: #66666a; font: 500 12.5px/1 var(--f-body);
  cursor: pointer; white-space: nowrap; transition: background .15s, color .15s;
}
.dock .item:hover { color: #11111a; background: rgb(17 17 26 / 0.05); }
.dock .item[aria-pressed="true"] { color: #11111a; background: rgb(17 17 26 / 0.07); }
.dock .thumb {
  width: 32px; height: 32px; flex: none; border-radius: 7px; padding: 5px; background: #ececf0;
  display: grid; place-items: center; transition: box-shadow .2s var(--ease);
}
.dock .thumb.ink { background: #11111a; }
.dock .thumb svg { width: 100%; height: 100%; display: block; }
.dock .item[aria-pressed="true"] .thumb { box-shadow: 0 0 0 2px var(--accent); }
.dock .rule { flex: none; width: 1px; margin: 8px 4px; background: rgb(17 17 26 / 0.1); }
.dock .own .thumb { background: none; box-shadow: inset 0 0 0 1.5px #d4d4da; color: #66666a; font: 400 18px/1 var(--f-body); }
.dock .own:hover .thumb { box-shadow: inset 0 0 0 1.5px var(--accent); color: var(--accent); }
.dock .own input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.dock .own:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 0; }
.dock .item:focus-visible { outline-offset: 0; }
.dock .more { display: none; }
.dock .more .thumb { background: #ececf0; color: #66666a; }
.dock .more .thumb svg { width: 14px; height: 14px; }
.board.custom #preview { padding-bottom: 64px; }
.board.custom .dock { left: calc(100% - 14px); transform: translateX(-100%); }
.board.custom .dock .more, .board.custom .dock.open > * { animation: dock-in .35s var(--ease) both; }
@keyframes dock-in { from { opacity: 0; transform: translateX(6px); } }
.board.custom .dock .more { display: flex; }
.board.custom .dock:not(.open) > :not(.more) { display: none; }
.board.custom .dock.open .more { order: 1; color: #11111a; background: rgb(17 17 26 / 0.07); }
@media (max-width: 640px) { .dock .name { display: none; } .dock .item { padding: 4px; } }

/* ---------- history ---------- */
.shelf { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.shelf-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.eyebrow { font: 500 13px var(--f-body); color: var(--ink); margin: 0; }
.strip { display: flex; gap: 10px; overflow-x: auto; padding: 8px 8px 6px 6px; margin: -8px -8px -6px -6px; }
.strip .empty { font-size: 13px; color: var(--muted); padding: 4px 0 8px; }
.tile { position: relative; flex: 0 0 auto; width: 88px; display: flex; flex-direction: column; gap: 6px; }
.tile button.open {
  width: 88px; height: 64px; padding: 10px; border-radius: 10px; border: 0;
  background: var(--surface); cursor: pointer; display: grid; place-items: center;
  transition: transform .25s var(--ease);
}
.tile button.open.ink { background: #11111a; }
.tile button.open.paper { background: #f4f4f6; }
.tile button.open:hover { transform: translateY(-2px); }
.tile button.open svg { width: 100%; height: 100%; display: block; }
.tile .meta { font: 10.5px var(--f-mono); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.tile .del {
  position: absolute; top: -7px; right: -7px; width: 20px; height: 20px; border-radius: 50%;
  border: 0; background: var(--ink); color: var(--bg); font-size: 12px; line-height: 1;
  cursor: pointer; display: none; place-items: center; padding: 0;
}
.tile:hover .del, .tile .del:focus-visible { display: grid; }

/* ---------- controls ---------- */
.panel { display: flex; flex-direction: column; gap: 26px; min-height: 0; overflow: auto; padding: 6px 6px 8px; margin: -6px; }
.field { display: flex; flex-direction: column; gap: 12px; }
.field-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
.field-head label, .field-label { font: 500 13px var(--f-body); color: var(--ink); }
.num {
  width: 5.5ch; font: 500 30px/1 var(--f-mono); letter-spacing: -0.03em; text-align: right; color: var(--ink);
  background: none; border: 0; border-bottom: 1.5px solid transparent; border-radius: 0; padding: 0 0 2px;
  font-variant-numeric: tabular-nums; -moz-appearance: textfield; transition: border-color .15s;
}
.num::-webkit-inner-spin-button, .num::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.num:hover { border-bottom-color: var(--track); }
.num:focus { outline: none; border-bottom-color: var(--accent); }
.hint { font-size: 12.5px; line-height: 1.5; color: var(--muted); margin: 0; text-wrap: pretty; }
.hint b { color: var(--ink); font: 500 12px var(--f-mono); font-variant-numeric: tabular-nums; }

input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 20px; margin: 0; background: none; cursor: pointer; --p: 0%; }
input[type=range]:focus-visible { outline: none; }
input[type=range]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px;
  background: linear-gradient(to right, var(--accent) var(--p), var(--track) var(--p));
}
input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--track); }
input[type=range]::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--accent); }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px; margin-top: -7px; border-radius: 50%;
  background: #fff; box-shadow: 0 0 0 1px rgb(17 17 26 / 0.08), 0 2px 6px rgb(17 17 26 / 0.18);
  transition: transform .2s var(--ease);
}
input[type=range]::-moz-range-thumb {
  width: 18px; height: 18px; border: 0; border-radius: 50%;
  background: #fff; box-shadow: 0 0 0 1px rgb(17 17 26 / 0.08), 0 2px 6px rgb(17 17 26 / 0.18);
}
input[type=range]:active::-webkit-slider-thumb { transform: scale(1.15); }
input[type=range]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 3px var(--accent); }
input[type=range]:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 3px var(--accent); }

/* colour sliders: the track shows the real range (set --grad) instead of the accent fill */
input[type=range].grad::-webkit-slider-runnable-track { height: 10px; border-radius: 5px; background: var(--grad); box-shadow: inset 0 0 0 1px rgb(17 17 26 / 0.08); }
input[type=range].grad::-webkit-slider-thumb { margin-top: -4px; }
input[type=range].grad::-moz-range-track { height: 10px; border-radius: 5px; background: var(--grad); }
input[type=range].grad::-moz-range-progress { background: transparent; }

.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface); border-radius: 10px; padding: 3px; }
.seg button {
  border: 0; background: transparent; color: var(--muted); font: 500 12.5px var(--f-body);
  padding: 8px 4px; border-radius: 7px; cursor: pointer; transition: color .15s, background .15s;
}
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--bg); color: var(--ink); box-shadow: 0 1px 3px rgb(0 0 0 / 0.1); }

.switch { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 13px; cursor: pointer; }
.switch input {
  -webkit-appearance: none; appearance: none; flex: none; position: relative; margin: 0; cursor: pointer;
  width: 32px; height: 20px; border-radius: 999px; background: var(--track); transition: background .2s var(--ease);
}
.switch input::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgb(0 0 0 / 0.2); transition: transform .25s var(--ease);
}
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(12px); }

.sep { height: 1px; background: var(--line); flex: none; }
.actions { display: flex; flex-direction: column; gap: 14px; }
.actions .row { display: flex; gap: 8px; }
.btn {
  font: 500 14px var(--f-body); border-radius: 10px; padding: 12px 16px; cursor: pointer;
  border: 0; background: var(--surface); color: var(--ink);
  transition: background .15s, transform .2s var(--ease);
}
.btn:hover { background: color-mix(in srgb, var(--surface), var(--ink) 6%); }
.btn:active { transform: scale(.98); }
.btn.primary { flex: 1; background: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); }
.link { border: 0; background: none; padding: 0; color: var(--muted); font: 500 12.5px var(--f-body); cursor: pointer; }
.link:hover { color: var(--ink); }

.credit { margin: auto 0 0; padding-top: 16px; font-size: 12.5px; color: var(--muted); }
.credit a { color: inherit; text-decoration: none; }
.credit a:hover { color: var(--ink); }

details.code summary {
  list-style: none; cursor: pointer; display: flex; justify-content: space-between; align-items: center;
  font: 500 13px var(--f-body); color: var(--ink);
}
details.code summary::-webkit-details-marker { display: none; }
details.code summary::after { content: "+"; font: 400 16px/1 var(--f-mono); color: var(--muted); }
details.code[open] summary::after { content: "−"; }
details.code summary span { color: var(--muted); font-weight: 400; }
textarea {
  display: block; width: 100%; margin-top: 12px; resize: vertical; min-height: 120px; max-height: 320px;
  font: 11.5px/1.55 var(--f-mono); color: var(--ink); background: var(--surface);
  border: 0; border-radius: 10px; padding: 12px;
}
textarea::placeholder { color: var(--faint); }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%) translateY(8px);
  background: var(--ink); color: var(--bg); font-weight: 500; font-size: 13px; padding: 9px 16px; border-radius: 999px;
  opacity: 0; transition: opacity .2s var(--ease), transform .3s var(--ease); pointer-events: none;
}
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }


@media (max-width: 860px) {
  html, body { height: auto; }
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto; height: auto; row-gap: 32px; }
  header { padding-bottom: 0; gap: 16px; }
  .lead { font-size: 20px; }
  .panel { grid-column: 1; grid-row: auto; order: 1; }
  .stage { display: contents; }
  .stage > .shelf { order: 2; }
  .board { height: 58vh; min-height: 300px; }
  .panel { overflow: visible; }
}
