/* ------------------------------------------------------------------
   Tesselate — dark grey bench, white paper, one vermilion accent. The
   tools recede so the work does not have to compete with them; all
   colour is in the artwork, none in the room around it.

   `ink` is the foreground the rail is written in, `paper` what sits
   against it — light on dark now, which is why a chip that fills with
   ink reads as light with dark lettering. The names keep their
   meaning; only the values change hands.
   ------------------------------------------------------------------ */

:root {
  color-scheme: dark;
  --paper: #212120;
  --paper-lift: #2e2e2c;
  --shade: #1a1a19;
  --ink: #eceae4;
  --ink-60: rgba(236, 234, 228, 0.6);
  --ink-42: rgba(236, 234, 228, 0.42);
  --ink-22: rgba(236, 234, 228, 0.24);
  --ink-12: rgba(236, 234, 228, 0.14);
  --ink-06: rgba(236, 234, 228, 0.07);
  --accent: #e2542f;
  --rail: 268px;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --serif: "Fraunces", "Hoefler Text", Georgia, serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--shade);
  color: var(--ink);
  font-family: var(--mono);
  -webkit-font-smoothing: antialiased;
  touch-action: none;
}

body { display: flex; }

/* ---------------- rail ---------------- */

.rail {
  width: var(--rail);
  flex: 0 0 var(--rail);
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--paper-lift);
  border-right: 1px solid var(--ink-22);
  box-shadow: 1px 0 0 rgba(255, 255, 255, 0.05) inset, -18px 0 30px -24px rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
}
.rail::-webkit-scrollbar { width: 8px; }
.rail::-webkit-scrollbar-thumb { background: var(--ink-12); }

.panel { padding: 12px 20px 13px; border-bottom: 1px solid var(--ink-12); }
/* Nothing follows the last panel, so its rule would just hang in the gap. */
.rail > .panel:last-child { border-bottom: none; }
.rail > section.panel:first-of-type { padding-top: 17px; }

.label {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-42);
}
.label i { flex: 1; height: 1px; background: var(--ink-12); }

/* The New-confirm block eases in the same way the symmetry panel used to. */
@keyframes unfold {
  from { opacity: 0; transform: translateY(-3px); }
  to { opacity: 1; transform: none; }
}

/* ---------------- buttons ---------------- */

button {
  font-family: var(--mono);
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--ink-22);
  border-radius: 2px;
  cursor: pointer;
  transition: background 0.13s ease, color 0.13s ease, border-color 0.13s ease;
}
button:hover { background: var(--ink-06); }
button:active { transform: translateY(0.5px); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Nine tools, three to a row: four to a row left the warp on a row of
   its own. */
.tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.tool {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 2px 6px;
}
.tool svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.35;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tool em {
  font-style: normal;
  font-size: 8px;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--ink-60);
}
.tool.on { background: var(--ink); border-color: var(--ink); color: var(--paper); }
/* The lit tool is light, so its caption is the dark of the rail — the
   light one it had was left over from when the rail was light, and wrote
   the caption out of sight on its own button. */
.tool.on em { color: rgba(33, 33, 32, 0.72); }
.tool.on::before {
  content: "";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 4px;
  height: 4px;
  background: var(--accent);
}

.wide {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  font-size: 10.5px;
  letter-spacing: 0.05em;
  text-align: left;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.grid2 .wide { justify-content: center; text-align: center; }
.grid2 + .grid2, .filename + .grid2, .confirm + .grid2 { margin-top: 6px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.grid3 .wide { justify-content: center; text-align: center; padding: 8px 4px; }
.binders { margin-top: 8px; }
.binders + .binders { margin-top: 6px; }
.wide.turn { justify-content: center; padding: 7px 0; }
.wide.turn svg {
  width: 15px;
  height: 15px;
  flex: 0 0 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.wide:disabled { opacity: 0.32; cursor: default; }
.wide:disabled:hover { background: transparent; }

/* The file the drawing belongs to, with a dot while it has moved on. */
.filename {
  margin: 7px 0 0;
  font-size: 9px;
  letter-spacing: 0.04em;
  color: var(--ink-42);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.filename::before {
  content: "";
  display: inline-block;
  width: 4px;
  height: 4px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0;
  vertical-align: 0.1em;
}
.filename.dirty::before { opacity: 1; }

/* The table's own controls, at the top where the work starts. They
   share the row between them, so it holds however many there are, and a
   little air marks off the three groups: history, file, export. */
.toolbar { display: flex; gap: 3px; }
.toolbar > button {
  flex: 1 1 0;
  min-width: 0;
  height: 28px;
  padding: 0;
  display: grid;
  place-items: center;
}
.toolbar > button.gap { margin-left: 7px; }
.toolbar > button svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}
/* The two exports say what they write, on the same disk the save uses.
   `textLength` stretches the letters to the disk's own width, so they
   fill it whatever the font turns out to be. */
.toolbar > button svg text {
  fill: currentColor;
  stroke: none;
  font-family: var(--mono);
  font-size: 8.4px;
  font-weight: 600;
}
.toolbar > button:disabled { opacity: 0.3; cursor: default; }
.toolbar > button:disabled:hover { background: transparent; }

/* Clear asks first, in the rail rather than in a browser box. */
.confirm {
  margin-top: 7px;
  padding: 9px 10px 10px;
  border: 1px solid rgba(207, 67, 38, 0.45);
  border-radius: 2px;
  background: rgba(207, 67, 38, 0.055);
  animation: unfold 0.16s ease both;
}
.confirm p {
  margin: 0 0 8px;
  font-size: 10px;
  line-height: 1.45;
  letter-spacing: 0.02em;
  color: var(--ink-60);
}
.confirm p .mono { color: var(--ink-42); }
.wide.fatal {
  justify-content: center;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--paper);
}
.wide.fatal:hover { background: #b9351b; border-color: #b9351b; }

.toggle { margin-top: 6px; }
.sub-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  margin-top: 10px;
}
/* One row, however many sizes there are: they share the width between
   them rather than wrapping a lone number onto a line of its own. */
.subs { display: flex; flex-wrap: nowrap; gap: 3px; margin-top: 6px; }
/* The sizes belong to the switch above them; with it off there is no
   grid for them to size, so they go quiet rather than disappearing. */
.subs button:disabled { opacity: 0.3; cursor: default; }
.subs button:disabled:hover { background: transparent; }
.subs button {
  flex: 1 1 0;
  min-width: 0;
  height: 24px;
  padding: 0 2px;
  font-size: 10px;
  display: grid;
  place-items: center;
}
.subs button.on { background: var(--ink); border-color: var(--ink); color: var(--paper); }

.modes { display: flex; gap: 4px; margin-left: auto; }
.modes button {
  height: 24px;
  padding: 0 8px;
  font-size: 9.5px;
  letter-spacing: 0.06em;
}
.modes button.on { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.toggle .tick {
  width: 11px;
  height: 11px;
  flex: 0 0 11px;
  border: 1px solid var(--ink-42);
  border-radius: 1px;
  position: relative;
}
.toggle.muted { opacity: 0.42; }
.toggle.on .tick { background: var(--ink); border-color: var(--ink); }
/* A tick, drawn as two sides of a box turned on its corner. */
.toggle.on .tick::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 0.5px;
  width: 2.5px;
  height: 6px;
  border: solid var(--paper);
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(42deg);
}

/* ---------------- palette ---------------- */

.pal-bar { display: flex; gap: 5px; align-items: stretch; margin-bottom: 9px; }
.sel { position: relative; flex: 1; min-width: 0; }
.sel::after {
  content: "";
  position: absolute;
  right: 8px;
  top: 50%;
  margin-top: -1.5px;
  width: 5px;
  height: 5px;
  border-right: 1px solid var(--ink-42);
  border-bottom: 1px solid var(--ink-42);
  transform: rotate(45deg) translateY(-1px);
  pointer-events: none;
}
#palSel {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 100%;
  padding: 6px 20px 6px 8px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--ink-22);
  border-radius: 2px;
  cursor: pointer;
  text-overflow: ellipsis;
}
#palSel:hover { background: var(--ink-06); }
#palSel:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.mini {
  padding: 0 8px;
  height: 26px;
  font-size: 9.5px;
  letter-spacing: 0.07em;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}
/* The rename pencil, drawn in the same line as the tool icons. */
.mini.pen { padding: 0 7px; }
.mini.pen svg {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.mini:disabled { opacity: 0.32; cursor: default; }
.mini:disabled:hover { background: transparent; }
.armed {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--paper);
}
.armed:hover { background: #b9351b; border-color: #b9351b; }

.pal-name { display: flex; gap: 5px; margin-bottom: 9px; animation: unfold 0.16s ease both; }
.pal-name input {
  flex: 1;
  min-width: 0;
  height: 26px;
  padding: 0 8px;
  font-size: 10.5px;
  letter-spacing: 0.03em;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--ink-42);
  border-radius: 2px;
}
.pal-name input:focus { outline: none; border-color: var(--accent); }

.swatches { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
/* Somewhere to aim at while it is still empty — a new palette starts
   that way, and dropping a colour in is how it stops being. */
.swatches { min-height: 30px; }
/* The strip a colour is being dragged into, and the place in it the
   drop would land — a bar down the side of the swatch it would go in
   front of, or behind the last one where it would go on the end. */
.swatches.drop, .recent.drop {
  outline: 1px dashed var(--accent);
  outline-offset: 3px;
}
.swatch.ins-before::before,
.swatch.ins-after::before {
  content: "";
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 2px;
  background: var(--accent);
  pointer-events: none;
}
.swatch.ins-before::before { left: -4px; }
.swatch.ins-after::before { right: -4px; }
/* Ink that was mixed rather than picked, kept to hand. Ten slots, small
   enough that the palette above stays the thing that reads; the empty
   ones are drawn so the strip does not change shape as it fills. */
.recent { display: grid; grid-template-columns: repeat(10, 1fr); gap: 3px; margin-top: 6px; }
.recent .swatch { border-radius: 1px; }
.recent .swatch .well { inset: 2px; }
/* The cross, cut down for a slot half the size of a palette swatch. */
.recent .swatch .kill {
  width: 10px;
  height: 10px;
  font-size: 9px;
}
.recent .slot {
  aspect-ratio: 1;
  border: 1px dashed var(--ink-12);
  border-radius: 1px;
}
.swatch {
  aspect-ratio: 1;
  border: 1px solid var(--ink-22);
  border-radius: 2px;
  padding: 0;
  position: relative;
}
/* Alpha only reads against something, so every well sits on a check. */
.chk {
  background-color: #fff;   /* alpha reads against the paper, which is white */
  background-image:
    linear-gradient(45deg, rgba(0, 0, 0, 0.16) 25%, transparent 25% 75%, rgba(0, 0, 0, 0.16) 75%),
    linear-gradient(45deg, rgba(0, 0, 0, 0.16) 25%, transparent 25% 75%, rgba(0, 0, 0, 0.16) 75%);
  background-size: 8px 8px;
  background-position: 0 0, 4px 4px;
}
/* colour well: the check sits under the ink, not around it */
.well {
  position: absolute;
  inset: 3px;
  border-radius: 1px;
  overflow: hidden;
}
.well i { position: absolute; inset: 0; }
.swatch.on { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
/* The ring on the swatch in hand. It lies over the whole button, the
   remove cross included, so it has to let the pointer through — with it
   catching the click, the cross on the selected swatch did nothing but
   pick the colour again. */
.swatch.on::after {
  content: "";
  position: absolute;
  inset: -1px;
  border: 1px solid var(--paper-lift);
  pointer-events: none;
}
.swatch .kill {
  position: absolute;
  top: 0;
  right: 0;
  width: 13px;
  height: 13px;
  display: grid;
  place-items: center;
  font-size: 11px;
  line-height: 1;
  font-style: normal;
  color: var(--paper);
  background: var(--ink);
  opacity: 0;
  transition: opacity 0.12s ease;
}
.swatch:hover .kill { opacity: 0.85; }
.swatch .kill:hover { opacity: 1; background: var(--accent); }

.mixer { display: flex; align-items: center; gap: 5px; margin-top: 9px; }
/* The gradient's own controls, shown only while the ink is one. */
.grad-body { animation: unfold 0.16s ease both; }
.grad-body .sub-row { margin-top: 8px; }
.grad-body .modes { margin-left: auto; }
.swatch-preview {
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  border: 1px solid var(--ink-22);
  border-radius: 2px;
  position: relative;
}

.hex {
  flex: 1;
  min-width: 0;
  height: 26px;
  padding: 0 7px;
  font-size: 10.5px;
  letter-spacing: 0.06em;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--ink-22);
  border-radius: 2px;
  text-transform: lowercase;
}
.hex::placeholder { color: var(--ink-22); text-transform: none; }
.hex:focus { outline: none; border-color: var(--ink-42); background: #2b2b29; }
.hex.bad { border-color: var(--accent); color: var(--accent); }

.pick {
  position: relative;
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  display: grid;
  place-items: center;
  border: 1px solid var(--ink-22);
  border-radius: 2px;
  cursor: pointer;
  transition: background 0.13s ease;
}
.pick:hover { background: var(--ink-06); }
.pick svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: var(--ink-60);
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}
.pick input {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  cursor: pointer;
}
.mini.add { width: 26px; height: 26px; padding: 0; font-size: 14px; line-height: 1; }
/* Bootstrap's eyedropper is a filled glyph, not an outline like the tools. */
.mini.drop { width: 26px; height: 26px; padding: 0; }
.mini.drop svg { width: 15px; height: 15px; fill: currentColor; stroke: none; }

.row { display: flex; align-items: center; gap: 9px; }
.slide { margin-top: 9px; }
.slide .tiny { flex: 0 0 34px; }
.num { font-size: 10.5px; width: 22px; text-align: right; color: var(--ink-60); font-variant-numeric: tabular-nums; }
.tiny { font-size: 9px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-42); }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  min-width: 0;
  height: 18px;
  background: transparent;
  cursor: ew-resize;
}
input[type="range"]::-webkit-slider-runnable-track { height: 1px; background: var(--ink-22); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 9px;
  height: 16px;
  margin-top: -8px;
  border-radius: 1px;
  background: var(--ink);
}
input[type="range"]::-moz-range-track { height: 1px; background: var(--ink-22); }
input[type="range"]::-moz-range-thumb { width: 9px; height: 16px; border: 0; border-radius: 1px; background: var(--ink); }

/* ---------------- symmetry ---------------- */

.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  padding: 5px 8px;
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-60);
}
.chip.on { background: var(--ink); border-color: var(--ink); color: var(--paper); }

.block-row { margin: 11px 0 9px; justify-content: space-between; }
.sizes { display: flex; gap: 4px; }
.sizes button {
  width: 24px;
  height: 24px;
  font-size: 10px;
  display: grid;
  place-items: center;
}
.sizes button.on { background: var(--ink); border-color: var(--ink); color: var(--paper); }

.pattern-grid {
  display: grid;
  max-width: 122px;
  gap: 3px;
  padding: 7px;
  background: var(--paper);
  border: 1px solid var(--ink-12);
  border-radius: 2px;
}
.cell {
  position: relative;
  aspect-ratio: 1;
  padding: 0;
  border-color: var(--ink-12);
  background: var(--paper-lift);
  display: grid;
  place-items: center;
}
.cell svg {
  width: 74%;
  height: 74%;
  color: var(--ink-60);
  overflow: visible;
  transition: transform 0.16s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.cell svg text {
  font-size: 14px;
  fill: currentColor;
}
.cell:hover svg { color: var(--ink); }
.cell.src { border-color: var(--ink-42); background: rgba(236, 234, 228, 0.1); }
.cell.src svg { color: var(--accent); }
.cell.src::after {
  content: "";
  position: absolute;
  inset: 3px;
  border: 1px dashed var(--ink-22);
}
.note {
  margin: 8px 0 0;
  font-size: 9px;
  line-height: 1.45;
  color: var(--ink-42);
  letter-spacing: 0.01em;
}

/* ---------------- stage ---------------- */

.stage-wrap { position: relative; flex: 1; min-width: 0; height: 100%; }
#stage { display: block; width: 100%; height: 100%; cursor: crosshair; }
#stage.gripping { cursor: pointer; }
#stage.panning { cursor: grabbing; }
#stage.outside { cursor: grab; }
#stage.selecting { cursor: default; }
#stage.grabbable { cursor: move; }
#stage.dropping { cursor: crosshair; }

@media (max-width: 820px) {
  body { flex-direction: column-reverse; }
  .rail { width: 100%; flex: 0 0 auto; max-height: 46%; border-right: 0; border-top: 1px solid var(--ink-22); }
  .stage-wrap { flex: 1; }
}
