/* ============================================================
   ui.css - jackish design system

   Beige-box computer. Rules of the house, applied everywhere
   including inside every project:

     one typeface (IBM Plex Mono), no exceptions
     zero border-radius, everything is a box
     surfaces are bevelled, never drop-shadowed
     colour comes from tokens, never literals
     blue is an accent, never a background

   Both project pages import this file first, then add only
   their own layout. That is what keeps them consistent.
   ============================================================ */

/* ---------- tokens ---------------------------------------- */

:root {
  --font: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --fs-xs: 10px;
  --fs-sm: 11px;
  --fs-base: 13px;
  --fs-md: 15px;
  --fs-lg: 19px;

  --tr-wide: 0.2em;
  --tr-mid: 0.09em;
  --tr-tight: -0.03em;

  --bar-h: 34px;
  --gut: 20px;

  --t-fast: 90ms;
  --t-mid: 160ms;

  /* The whole retro read comes from these two: a light edge
     top-left, a dark edge bottom-right. Flip them for pressed. */
  --bevel: inset 1px 1px 0 var(--bevel-hi), inset -1px -1px 0 var(--bevel-lo);
  --bevel-in: inset 1px 1px 0 var(--bevel-lo), inset -1px -1px 0 var(--bevel-hi);
}

/* Light is the default: an unbadged beige machine. */
:root,
:root[data-theme="light"] {
  color-scheme: light;

  --bg: #cdc6b4;
  --bg-2: #c1b9a5;
  --surface: #e7e2d5;
  --surface-2: #f3efe5;
  --surface-3: #d7d0bf;

  --rule: #928a79;
  --rule-2: #6f695b;
  --bevel-hi: #fffdf6;
  --bevel-lo: #7d7565;

  --dim: #837b6b;
  --muted: #5b5548;
  --text: #2b2620;
  --bright: #14110c;

  --accent: #1d4f8f;
  --accent-2: #2f6ab4;
  --accent-ink: #f6f3ea;
  --accent-wash: rgba(29, 79, 143, 0.13);

  --warn: #9a6410;
  --bad: #a3352c;
  --good: #1f6b4a;

  /* canvas-side colours, read by JS */
  --canvas-void: #b8b09d;
  --canvas-dead: #efebe0;
  --canvas-grid: #b3aa96;
  --alive-dim: 1;

  /* scrim over the contour background */
  --scrim-1: rgba(205, 198, 180, 0.72);
  --scrim-2: rgba(205, 198, 180, 0.3);
  --scrim-3: rgba(205, 198, 180, 0);
}

/* The same machine after hours. */
:root[data-theme="dark"] {
  color-scheme: dark;

  --bg: #1a1815;
  --bg-2: #221f1a;
  --surface: #2a2620;
  --surface-2: #332e26;
  --surface-3: #1f1c17;

  --rule: #4b4539;
  --rule-2: #665f50;
  --bevel-hi: #554e42;
  --bevel-lo: #131110;

  --dim: #8a8170;
  --muted: #aba28f;
  --text: #e3dccb;
  --bright: #f9f4e6;

  --accent: #5b9fe0;
  --accent-2: #8cc4f7;
  --accent-ink: #14120f;
  --accent-wash: rgba(91, 159, 224, 0.14);

  --warn: #d9a441;
  --bad: #e0685c;
  --good: #58bf94;

  --canvas-void: #1a1815;
  --canvas-dead: #232019;
  --canvas-grid: #4b4539;
  --alive-dim: 0;

  --scrim-1: rgba(26, 24, 21, 0.8);
  --scrim-2: rgba(26, 24, 21, 0.42);
  --scrim-3: rgba(26, 24, 21, 0);
}

/* ---------- reset ----------------------------------------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-base);
  font-weight: 400;
  line-height: 1.55;
  font-variant-ligatures: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1,
h2,
h3,
p,
figure,
pre,
dl,
dd {
  margin: 0;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

canvas {
  display: block;
}

::selection {
  background: var(--accent);
  color: var(--accent-ink);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---------- type primitives ------------------------------- */

.u-label {
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: var(--tr-wide);
  text-transform: uppercase;
  color: var(--dim);
}

.u-dim {
  color: var(--dim);
}

.u-muted {
  color: var(--muted);
}

.u-bright {
  color: var(--bright);
}

.u-accent {
  color: var(--accent);
}

/* Blinking block cursor. */
.caret {
  display: inline-block;
  width: 0.62em;
  height: 1.05em;
  vertical-align: -0.18em;
  background: var(--accent);
  animation: caret-blink 1.1s steps(1) infinite;
}

@keyframes caret-blink {
  0%,
  50% {
    opacity: 1;
  }
  50.01%,
  100% {
    opacity: 0;
  }
}

/* ---------- window ---------------------------------------- */

/* The core surface on every page. Title bar carries pinstripes
   with the label knocked out of them, which is what makes a
   plain box read as a machine window rather than a card. */
.win {
  border: 1px solid var(--rule-2);
  background: var(--surface);
  box-shadow: var(--bevel);
}

.win__bar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 24px;
  padding: 0 7px;
  border-bottom: 1px solid var(--rule-2);
  background: var(--bg-2);
  user-select: none;
  overflow: hidden;
}

.win__bar::after {
  content: "";
  flex: 1;
  align-self: stretch;
  margin: 5px 0;
  background: repeating-linear-gradient(
    to bottom,
    var(--rule) 0 1px,
    transparent 1px 3px
  );
}

.win__dot {
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  border: 1px solid var(--rule-2);
  background: var(--accent);
  box-shadow: var(--bevel);
}

.win__title {
  flex: 0 0 auto;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: var(--tr-mid);
  text-transform: uppercase;
  color: var(--text);
  white-space: nowrap;
}

.win__body {
  padding: 16px 18px;
}

/* ---------- bars ------------------------------------------ */

/* Shared by the shell header and by every project's back bar,
   so the chrome is literally the same component everywhere. */
.bar {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: stretch;
  min-height: var(--bar-h);
  background: var(--bg-2);
  border-bottom: 1px solid var(--rule-2);
  box-shadow: var(--bevel);
  font-size: var(--fs-xs);
  letter-spacing: var(--tr-mid);
  text-transform: uppercase;
  user-select: none;
}

.bar__brand {
  display: flex;
  align-items: center;
  padding: 0 13px;
  margin: 3px 0 3px 3px;
  border: 1px solid var(--rule-2);
  background: var(--accent);
  box-shadow: var(--bevel);
  font-weight: 600;
  letter-spacing: var(--tr-wide);
  color: var(--accent-ink);
  white-space: nowrap;
}

.bar__brand:hover {
  background: var(--accent-2);
}

.bar__seg {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border-right: 1px solid var(--rule);
  color: var(--muted);
  white-space: nowrap;
}

.bar__spacer {
  flex: 1;
  min-width: 8px;
}

.bar__right {
  display: flex;
  align-items: stretch;
  margin-left: auto;
}

.bar__right .bar__seg {
  border-right: 0;
  border-left: 1px solid var(--rule);
}

.bar__k {
  color: var(--dim);
}

.bar__v {
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.bar__v--warn {
  color: var(--warn);
}

.bar__v--bad {
  color: var(--bad);
}

/* Back link on project pages. */
.bar__back {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border-right: 1px solid var(--rule);
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

.bar__back:hover {
  color: var(--bright);
  background: var(--surface-2);
}

.bar__back span[aria-hidden] {
  color: var(--accent);
}

/* A bar segment that is also a button (theme switch, etc). */
.bar__seg--btn {
  border: 0;
  border-left: 1px solid var(--rule);
  background: none;
  font: inherit;
  font-size: var(--fs-xs);
  letter-spacing: var(--tr-mid);
  text-transform: uppercase;
  cursor: pointer;
}

.bar__seg--btn:hover {
  background: var(--surface-2);
  color: var(--bright);
}

/* Tabs live in the bar; the active one is a raised key. */
.tabs {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 3px;
}

.tab {
  display: flex;
  align-items: center;
  padding: 0 14px;
  align-self: stretch;
  border: 1px solid var(--rule-2);
  background: var(--surface-3);
  box-shadow: var(--bevel-in);
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: var(--tr-wide);
  text-transform: uppercase;
  cursor: pointer;
  transition: color var(--t-fast), background var(--t-fast);
}

.tab:hover {
  color: var(--bright);
}

.tab[aria-selected="true"] {
  background: var(--surface-2);
  box-shadow: var(--bevel);
  color: var(--bright);
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 28px;
  padding: 5px 12px;
  border: 1px solid var(--rule-2);
  background: var(--surface-2);
  box-shadow: var(--bevel);
  color: var(--text);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: var(--tr-mid);
  text-transform: uppercase;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}

.btn:hover:not(:disabled) {
  background: var(--surface);
  color: var(--bright);
}

.btn:active:not(:disabled) {
  background: var(--surface-3);
  box-shadow: var(--bevel-in);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn--primary:hover:not(:disabled) {
  background: var(--accent-2);
  color: var(--accent-ink);
}

.btn--danger {
  background: var(--bad);
  color: #fff;
}

.btn--on {
  background: var(--surface-3);
  box-shadow: var(--bevel-in);
  color: var(--bright);
}

.btn--icon {
  min-width: 28px;
  padding: 5px 7px;
}

.btn-row {
  display: flex;
  gap: 5px;
}

.btn-row > .btn {
  flex: 1;
}

/* Small keycap, used for keyboard hints. */
.key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border: 1px solid var(--rule-2);
  background: var(--surface-2);
  box-shadow: var(--bevel);
  color: var(--muted);
  font-size: var(--fs-xs);
  line-height: 1;
  text-transform: none;
}

/* ---------- panels ---------------------------------------- */

.panel {
  border: 1px solid var(--rule-2);
  background: var(--surface);
  box-shadow: var(--bevel);
}

.panel__head {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 24px;
  padding: 3px 9px;
  border-bottom: 1px solid var(--rule-2);
  background: var(--bg-2);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: var(--tr-wide);
  text-transform: uppercase;
  color: var(--text);
}

.panel__body {
  padding: 12px;
}

/* A titled group inside a scrolling sidebar. */
.group {
  padding: 12px 13px;
  border-bottom: 1px solid var(--rule);
}

.group:last-child {
  border-bottom: 0;
}

.group__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: var(--tr-wide);
  text-transform: uppercase;
  color: var(--muted);
}

.group__note {
  font-weight: 400;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--dim);
  text-align: right;
}

/* ---------- form controls --------------------------------- */

/* Inputs are wells: bevel runs the other way. */
.field {
  width: 100%;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid var(--rule-2);
  background: var(--surface-2);
  box-shadow: var(--bevel-in);
  color: var(--text);
  font-size: var(--fs-sm);
}

.field::placeholder {
  color: var(--dim);
}

select.field {
  border-radius: 0;
  -webkit-appearance: none;
  appearance: none;
  padding-right: 24px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 13px) 52%, calc(100% - 8px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}

.ctl {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
}

.ctl > label {
  flex: 0 0 62px;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: var(--tr-mid);
  text-transform: uppercase;
  color: var(--muted);
}

.ctl__val {
  flex: 0 0 auto;
  min-width: 48px;
  font-size: var(--fs-sm);
  color: var(--text);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  min-width: 0;
  height: 18px;
  background: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 5px;
  border: 1px solid var(--rule-2);
  background: var(--surface-3);
  box-shadow: var(--bevel-in);
}

input[type="range"]::-moz-range-track {
  height: 5px;
  border: 1px solid var(--rule-2);
  background: var(--surface-3);
  box-shadow: var(--bevel-in);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 9px;
  height: 15px;
  margin-top: -6px;
  border: 1px solid var(--rule-2);
  border-radius: 0;
  background: var(--surface-2);
  box-shadow: var(--bevel);
}

input[type="range"]::-moz-range-thumb {
  width: 9px;
  height: 15px;
  border: 1px solid var(--rule-2);
  border-radius: 0;
  background: var(--surface-2);
  box-shadow: var(--bevel);
}

input[type="range"]:hover::-webkit-slider-thumb {
  background: var(--accent);
}

input[type="range"]:hover::-moz-range-thumb {
  background: var(--accent);
}

/* Checkbox as a real checkbox. */
.toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: var(--tr-mid);
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
}

.toggle:hover {
  color: var(--bright);
}

.toggle input {
  -webkit-appearance: none;
  appearance: none;
  width: 13px;
  height: 13px;
  margin: 0;
  border: 1px solid var(--rule-2);
  background: var(--surface-2);
  box-shadow: var(--bevel-in);
  cursor: pointer;
  position: relative;
}

.toggle input:checked::after {
  content: "";
  position: absolute;
  inset: 2px;
  background: var(--accent);
}

/* Square pill used for place presets and colour ramps. */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border: 1px solid var(--rule-2);
  background: var(--surface-2);
  box-shadow: var(--bevel);
  color: var(--muted);
  font-size: var(--fs-xs);
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: color var(--t-fast), background var(--t-fast);
}

.chip:hover {
  color: var(--bright);
  background: var(--surface);
}

.chip[aria-pressed="true"] {
  background: var(--accent-wash);
  box-shadow: var(--bevel-in);
  color: var(--bright);
  font-weight: 600;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

/* ---------- status line ----------------------------------- */

.status {
  padding: 6px 10px;
  border: 1px solid var(--rule-2);
  background: var(--surface);
  box-shadow: var(--bevel);
  color: var(--muted);
  font-size: var(--fs-sm);
  line-height: 1.5;
}

.status--err {
  color: var(--bad);
}

.status[hidden] {
  display: none;
}

/* ---------- misc ------------------------------------------ */

.skip {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  padding: 8px 14px;
  background: var(--accent);
  color: var(--accent-ink);
}

.skip:focus {
  left: 0;
}

.scroll {
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--rule) var(--surface-3);
}

.scroll::-webkit-scrollbar {
  width: 13px;
  height: 13px;
}

.scroll::-webkit-scrollbar-track {
  background: var(--surface-3);
  border-left: 1px solid var(--rule);
}

.scroll::-webkit-scrollbar-thumb {
  background: var(--surface-2);
  border: 1px solid var(--rule-2);
  box-shadow: var(--bevel);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
