/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */

:root {
  --bg: #f6f5f2;
  --panel: #ffffff;
  --ink: #1d1d1f;
  --muted: #6b6b70;
  --line: #e2e0db;
  --accent: #b5462a;
  --accent-ink: #ffffff;
  --stage: #eeece7;
  --field: #faf9f7;
  --error: #b3261e;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141416;
    --panel: #1c1c1f;
    --ink: #ececef;
    --muted: #9b9ba3;
    --line: #2e2e33;
    --accent: #e0714f;
    --accent-ink: #141416;
    --stage: #101012;
    --field: #232327;
    --error: #ff8a80;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #141416;
  --panel: #1c1c1f;
  --ink: #ececef;
  --muted: #9b9ba3;
  --line: #2e2e33;
  --accent: #e0714f;
  --accent-ink: #141416;
  --stage: #101012;
  --field: #232327;
  --error: #ff8a80;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: grid;
  grid-template-columns: minmax(300px, 360px) 1fr;
  overflow: hidden;
}

a {
  color: var(--accent);
}

.panel {
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 20px 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

h1 {
  font-size: 22px;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}

h2 {
  font-size: 16px;
  margin: 0 0 8px;
}

.beta {
  font-size: 11px;
  font-weight: 600;
  vertical-align: middle;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.lede {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field[hidden] {
  display: none;
}

.field > span {
  font-weight: 600;
  font-size: 13px;
}

.field small {
  color: var(--muted);
  font-size: 12px;
}

input,
select,
textarea {
  font: inherit;
  color: inherit;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 9px;
  width: 100%;
}

textarea {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  resize: vertical;
  min-height: 2.6em;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.editor {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.editor[hidden] {
  display: none;
}

.editor canvas {
  width: 100%;
  max-width: 220px;
  aspect-ratio: 1;
  align-self: center;
  cursor: pointer;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
}

.editor.machine canvas {
  max-width: none;
  aspect-ratio: auto;
}

.editor small {
  color: var(--muted);
  font-size: 12px;
}

/* The machine's handle: step 0, back, a step, run; and the step reached. */
.examples.handle {
  align-items: center;
}

.examples.handle .step {
  color: var(--muted);
  font-size: 12px;
  margin-left: 4px;
}

.examples.handle[hidden] {
  display: none;
}

.examples {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.examples button {
  font-size: 12px;
  padding: 3px 8px;
}

button {
  font: inherit;
  color: var(--ink);
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: var(--muted);
}

button:disabled {
  opacity: 0.55;
  cursor: progress;
}

.actions-row {
  display: flex;
  gap: 8px;
}

.actions-row #build {
  flex: 1;
}

#build {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  font-weight: 600;
  padding: 9px 12px;
}

.advanced summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.advanced[open] {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.status {
  margin: 0;
  min-height: 1.4em;
  font-size: 13px;
  color: var(--muted);
}

.status.error {
  color: var(--error);
}

/* What is known of the braid, over the view: under the cross-section,
 * folded away to its title when not wanted. */
.about {
  position: absolute;
  left: 12px;
  top: 12px;
  width: min(300px, 40vw);
  max-height: calc(100% - 96px);
  overflow-y: auto;
  padding: 10px 12px;
  background: color-mix(in srgb, var(--panel) 90%, transparent);
  border: 1px solid var(--line);
  border-radius: 8px;
  backdrop-filter: blur(6px);
}

.section:not([hidden]) ~ .about {
  top: calc(24px + min(240px, 38vw));
  max-height: calc(100% - 108px - min(240px, 38vw));
}

.about[hidden] {
  display: none;
}

.about summary {
  cursor: pointer;
  list-style-position: outside;
  margin-left: 14px;
}

.about summary h2 {
  display: inline;
  font-size: 14px;
  margin: 0;
}

.about[open] summary {
  margin-bottom: 8px;
}

.about dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  margin: 0;
  font-size: 13px;
}

.about dt {
  color: var(--muted);
}

.about dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.about dd code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  /* A long word in three lines; all of it copied. */
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.about .actions {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

.about .actions button {
  font-size: 12px;
  padding: 2px 8px;
}

/* The braid's kin: other ways of making it, and braids like it. */
.kin h3 {
  margin: 10px 0 4px;
  font-size: 13px;
  font-weight: 600;
}

.kin ul {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
}

.kin li {
  margin: 2px 0;
}

.kin button.link {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  text-decoration: underline;
  cursor: pointer;
}

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

/* The braid made other ways: small buttons beside each. */
.kin button.small {
  font-size: 11px;
  padding: 1px 6px;
  margin-left: 2px;
}

.notes {
  margin: 10px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 13px;
}

footer {
  margin-top: auto;
  color: var(--muted);
  font-size: 12px;
}

/* Asking for help, not shouting for it: one quiet button. */
.support-button {
  display: table;
  margin: 0 0 6px;
  padding: 4px 10px;
  border: 1px solid currentColor;
  border-radius: 999px;
  color: inherit;
  font-weight: 600;
  text-decoration: none;
}

.support-button:hover {
  background: color-mix(in srgb, currentColor 12%, transparent);
}

.stage {
  position: relative;
  background: var(--stage);
  min-width: 0;
  min-height: 0;
}

.viewer {
  position: absolute;
  inset: 0;
}

.viewer canvas {
  display: block;
}

.topview {
  position: absolute;
  top: 12px;
  right: 12px;
  width: min(240px, 38vw);
  aspect-ratio: 1;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border: 1px solid var(--line);
  border-radius: 8px;
  backdrop-filter: blur(6px);
  pointer-events: none;
}

.section {
  position: absolute;
  top: 12px;
  left: 12px;
  width: min(240px, 38vw);
  aspect-ratio: 1;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border: 1px solid var(--line);
  border-radius: 8px;
  backdrop-filter: blur(6px);
  pointer-events: none;
}

.section[hidden] {
  display: none;
}

.topview[hidden] {
  display: none;
}

.toolbar {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border: 1px solid var(--line);
  border-radius: 8px;
  backdrop-filter: blur(6px);
}

.toolbar input[type="range"] {
  flex: 1 1 140px;
  width: auto;
  padding: 0;
  accent-color: var(--accent);
}

.toolbar select {
  width: auto;
  padding: 6px 8px;
}

/* The view's switches, in a menu opening up from the toolbar. */
.menu {
  position: relative;
}

.menu summary {
  list-style: none;
  font-size: 14px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field);
  cursor: pointer;
}

.menu summary::-webkit-details-marker {
  display: none;
}

.menu summary::after {
  content: " ▴";
  color: var(--muted);
}

.menu-items {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.15);
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  white-space: nowrap;
}

.check input {
  width: auto;
  accent-color: var(--accent);
}

.empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  pointer-events: none;
}

.empty[hidden] {
  display: none;
}

@media (max-width: 760px) {
  body {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    overflow: auto;
    height: auto;
  }

  .panel {
    order: 2;
    border-right: none;
    border-top: 1px solid var(--line);
    padding: 16px;
    overflow: visible;
  }

  .stage {
    order: 1;
    display: flex;
    flex-direction: column;
  }

  .viewer {
    position: relative;
    inset: auto;
    height: 56vh;
  }

  .topview {
    width: 32vw;
    top: 8px;
    right: 8px;
  }

  .section {
    width: 32vw;
    top: 8px;
    left: 8px;
  }

  .toolbar {
    position: static;
    margin: 8px;
    gap: 6px;
  }

  .about,
  .section:not([hidden]) ~ .about {
    position: static;
    width: auto;
    max-height: none;
    margin: 0 8px;
  }

  .empty {
    bottom: auto;
    height: 56vh;
  }
}

.diagram-scroll {
  max-height: 320px;
  overflow: auto;
  scrollbar-gutter: stable;
  border-radius: 8px;
}

.diagram canvas {
  display: block;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.diagram small {
  color: var(--muted);
}

/* The strands, each with the colour it is drawn in. */
.strands-card {
  margin-top: 12px;
}

.strands {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: 4px 10px;
  margin: 8px 0 10px;
  padding: 0;
  list-style: none;
}

.strands .swatch {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  padding: 2px 4px 2px 2px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: none;
  font: inherit;
  font-size: 13px;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

/* The strand's own colour, in a box before its name. */
.strands .swatch::before {
  content: "";
  flex: none;
  width: 20px;
  height: 20px;
  border: 1px solid var(--line, #8884);
  border-radius: 4px;
  background: var(--swatch, #000);
}

.strands .swatch:hover,
.strands .swatch:focus-visible {
  border-color: var(--line, #8884);
}

.strands span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The strand being pointed at, shown among the others. */
.strands li.picked .swatch {
  font-weight: 600;
  border-color: var(--line, #8884);
}

.strands li.picked .swatch::before {
  box-shadow: 0 0 0 2px var(--line, #8884);
}

/* The one colour box the list shares: reachable, not in the way. */
.offscreen {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

/* The colours on offer, under the strand they are for. */
/* `display` here would beat the browser's own rule for [hidden], so say it. */
.palette[hidden] {
  display: none;
}

.palette {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  margin: 2px 0 8px;
  padding: 7px;
  border: 1px solid var(--line, #8884);
  border-radius: 6px;
}

.palette .whose {
  width: 100%;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 12px;
}

.palette .dab {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--line, #8884);
  border-radius: 4px;
  background: var(--swatch, #000);
  cursor: pointer;
}

.palette .dab:hover,
.palette .dab:focus-visible {
  outline: 2px solid var(--text, #222);
  outline-offset: 1px;
}

.palette .more {
  margin-left: auto;
  padding: 3px 8px;
  border: 1px solid var(--line, #8884);
  border-radius: 4px;
  background: none;
  font: inherit;
  font-size: 12px;
  color: inherit;
  cursor: pointer;
}

.strands li.changing .swatch {
  border-color: var(--text, #222);
}

/* `display` here would beat the browser's own rule for [hidden], so say it. */
.strands.groups[hidden],
.groups-caption[hidden] {
  display: none;
}

.groups-caption {
  margin: 10px 0 0;
  font-size: 13px;
  font-weight: 600;
}

/* The groups apart from the strands below them. */
.strands.groups {
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line, #8884);
}

.strands.groups li.picked .swatch {
  font-weight: 600;
  border-color: var(--line, #8884);
}
