/* sgweb: drafting paper and ink in light, a dark desk at night. The canvas reads its colors from the
   custom properties below (see draw.js), so both themes live here. Canvas colors are #rrggbb where draw.js
   makes them translucent. */

:root {
  color-scheme: light;
  --bg: #f6f4ee;
  --surface: #ffffff;
  --surface-2: #f0ede5;
  --border: #e2ddd0;
  --text: #1d2430;
  --muted: #6b7180;
  --accent: #2f6fde;
  --accent-text: #ffffff;
  --good: #2b8a3e;
  --warn: #b35c00;
  --shadow: 0 6px 24px rgba(40, 32, 12, 0.12), 0 1px 3px rgba(40, 32, 12, 0.1);

  --paper: #fbfaf6;
  --grid-minor: #efebe1;
  --grid-major: #dfd9ca;
  --ruler: rgba(246, 244, 238, 0.86);
  --ruler-text: #8a8577;
  --axis: #a49e8e;
  --ink: #1d2430;
  --free: #2f6fde;
  --sel: #e8590c;
  --err: #d6336c;
  --dim: #7048e8;
  --ref: #6f7686;
  --ghost: rgba(47, 111, 222, 0.75);
  --badge: #e9e5da;
  --badge-text: #4b5263;
  --label: #3b4252;
  --curve-1: #0c8f7e;
  --curve-2: #c2255c;
  --curve-3: #5c940d;
  --curve-4: #d9480f;
  --curve-5: #9c36b5;
  --curve-6: #1971c2;

  --peek: 60px;
  --dock: 64px;
  --insp-w: 360px;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "DejaVu Sans Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #16181d;
    --surface: #1e2127;
    --surface-2: #262a31;
    --border: #30353e;
    --text: #e6e8ec;
    --muted: #9aa1ad;
    --accent: #6ea8ff;
    --accent-text: #0d1526;
    --good: #69db7c;
    --warn: #ffc078;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.45), 0 1px 3px rgba(0, 0, 0, 0.4);
    --paper: #121418;
    --grid-minor: #1a1d23;
    --grid-major: #252a32;
    --ruler: rgba(22, 24, 29, 0.86);
    --ruler-text: #6c7380;
    --axis: #4a515e;
    --ink: #e6e8ec;
    --free: #6ea8ff;
    --sel: #ffa94d;
    --err: #ff6b8b;
    --dim: #b197fc;
    --ref: #8a919e;
    --ghost: rgba(110, 168, 255, 0.75);
    --badge: #262a31;
    --badge-text: #b8bec9;
    --label: #c9ced8;
    --curve-1: #3bc9b4;
    --curve-2: #f783ac;
    --curve-3: #94d82d;
    --curve-4: #ffa94d;
    --curve-5: #e599f7;
    --curve-6: #74c0fc;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #16181d;
  --surface: #1e2127;
  --surface-2: #262a31;
  --border: #30353e;
  --text: #e6e8ec;
  --muted: #9aa1ad;
  --accent: #6ea8ff;
  --accent-text: #0d1526;
  --good: #69db7c;
  --warn: #ffc078;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45), 0 1px 3px rgba(0, 0, 0, 0.4);
  --paper: #121418;
  --grid-minor: #1a1d23;
  --grid-major: #252a32;
  --ruler: rgba(22, 24, 29, 0.86);
  --ruler-text: #6c7380;
  --axis: #4a515e;
  --ink: #e6e8ec;
  --free: #6ea8ff;
  --sel: #ffa94d;
  --err: #ff6b8b;
  --dim: #b197fc;
  --ref: #8a919e;
  --ghost: rgba(110, 168, 255, 0.75);
  --badge: #262a31;
  --badge-text: #b8bec9;
  --label: #c9ced8;
  --curve-1: #3bc9b4;
  --curve-2: #f783ac;
  --curve-3: #94d82d;
  --curve-4: #ffa94d;
  --curve-5: #e599f7;
  --curve-6: #74c0fc;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-text-size-adjust: 100%;
}

/* the app fills the window and never scrolls or zooms as a page: the canvas zooms itself, so a pinch
   elsewhere (on the sheet, the dock) must not zoom the page and leave it cut off at the side */
body {
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: pan-x pan-y;
}

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

[hidden] {
  display: none !important;
}

.grow {
  flex: 1;
}

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

.small {
  font-size: 12.5px;
}

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

kbd {
  font: 11.5px var(--mono);
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}

/* ---------------------------------------------------------------- icons and buttons */

.ic {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ic .f {
  fill: currentColor;
  stroke: none;
}

.ic .t {
  stroke-width: 1.15;
}

.ic.big {
  width: 44px;
  height: 44px;
  opacity: 0.4;
}

.ic.invisible {
  visibility: hidden;
}

.ibtn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.ibtn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.ibtn.on {
  color: var(--accent);
}

.ibtn:disabled {
  opacity: 0.4;
  cursor: default;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  cursor: pointer;
  white-space: nowrap;
}

.btn .ic {
  width: 17px;
  height: 17px;
}

.btn:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--accent) 50%, var(--border));
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.btn.small {
  height: 28px;
  padding: 0 9px;
  font-size: 12.5px;
}

select.btn {
  padding-right: 8px;
}

.link {
  border: 0;
  padding: 0;
  background: none;
  color: var(--accent);
  cursor: pointer;
  text-align: left;
}

.link:hover {
  text-decoration: underline;
}

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

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid color-mix(in srgb, var(--muted) 30%, transparent);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------------------------------------------------------------- frame */

/* fixed to the window rather than sized in viewport units, which some phone browsers measure differently
   from the window they lay fixed elements out in */
#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  display: grid;
  /* one column exactly as wide as the window: an auto column would grow to the widest content's minimum,
     such as a text box's natural width, and push everything past the screen's edge */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
}

.bar {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 52px;
  padding: 0 10px 0 14px;
  padding-top: env(safe-area-inset-top);
  box-sizing: content-box;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
  text-decoration: none;
  margin-right: 6px;
}

.brand svg {
  width: 26px;
  height: 26px;
}

.brand .b1 {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.2;
  stroke-linejoin: round;
}

.brand .b2 {
  fill: none;
  stroke: var(--dim);
  stroke-width: 2;
}

.brand .b3 {
  fill: var(--sel);
}

.doc-name {
  min-width: 0;
  width: 15em;
  height: 34px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: none;
  font-weight: 600;
  text-overflow: ellipsis;
}

.doc-name:hover,
.doc-name:focus {
  border-color: var(--border);
  background: var(--surface);
}

.menus {
  display: flex;
  gap: 2px;
}

.menus button {
  height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  cursor: pointer;
}

.menus button:hover {
  background: var(--surface-2);
}

.narrow-only {
  display: none !important;
}

.work {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr) var(--insp-w);
  min-height: 0;
}

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

.rail {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 6px;
  border-right: 1px solid var(--border);
  background: var(--bg);
  overflow-y: auto;
  scrollbar-width: none;
}

.tool {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-height: 56px;
  padding: 7px 2px 6px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 10.5px;
  line-height: 1.15;
}

.tool .ic {
  width: 24px;
  height: 24px;
}

.tool span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tool:hover {
  background: var(--surface-2);
  color: var(--text);
}

.tool.on {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
  font-weight: 600;
}

.tool.group::after {
  content: "";
  position: absolute;
  right: 7px;
  top: 7px;
  border: 3.5px solid transparent;
  border-top-color: currentColor;
  border-right-color: currentColor;
  opacity: 0.6;
}

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

.stage {
  position: relative;
  overflow: hidden;
  background: var(--paper);
}

#canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  outline: none;
  -webkit-user-select: none;
  user-select: none;
}

.hint,
.fnbar,
.actions,
.status .dof,
.zoomctl,
.welcome,
.dim-editor {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.hint {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100% - 48px);
  padding: 5px 6px 5px 12px;
  border-radius: 999px;
}

.hint .tool-name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--accent);
}

.hint .text {
  color: var(--text);
}

.fnbar {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  width: min(560px, calc(100% - 32px));
  padding: 8px 8px 8px 14px;
  border-radius: 14px;
}

.fnbar label {
  font-weight: 600;
  color: var(--accent);
}

.fnbar input {
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--paper);
  font: 15px var(--mono);
}

.fnbar .msg {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--err);
  font-size: 12.5px;
}

.fnbar .msg:empty {
  display: none;
}

input.bad,
.qrow input.bad {
  border-color: var(--err) !important;
  color: var(--err);
}

.actions {
  position: absolute;
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  max-width: calc(100% - 16px);
  overflow-x: auto;
  scrollbar-width: none;
}

.chip-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 10px 0 8px;
  border: 0;
  border-radius: 8px;
  background: none;
  cursor: pointer;
  white-space: nowrap;
  font-size: 13px;
}

.chip-btn .ic {
  width: 18px;
  height: 18px;
  color: var(--muted);
}

.chip-btn:hover {
  background: var(--surface-2);
}

.chip-btn:hover .ic {
  color: var(--accent);
}

.chip-btn.danger:hover,
.chip-btn.danger:hover .ic {
  color: var(--err);
}

.status {
  position: absolute;
  left: 30px;
  bottom: 30px;
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}

.status .dof {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 28px;
  padding: 0 11px 0 9px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 500;
}

.dof::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--free);
}

.dof.good::before {
  background: var(--good);
}

.dof.bad::before {
  background: var(--err);
}

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

.coords {
  font: 12px var(--mono);
  color: var(--muted);
}

.zoomctl {
  position: absolute;
  right: 12px;
  bottom: 30px;
  display: flex;
  border-radius: 10px;
  padding: 2px;
}

.dim-editor {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 3px 3px 10px;
  border-radius: 999px;
  border-color: var(--dim);
  z-index: 5;
}

.dim-editor .label {
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
}

.dim-editor input {
  width: 110px;
  height: 28px;
  padding: 0 6px;
  border: 0;
  background: none;
  font-weight: 600;
  color: var(--dim);
  outline: none;
}

.dim-editor .unit {
  color: var(--dim);
}

.dim-editor .ok {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  background: var(--dim);
  color: var(--surface);
  cursor: pointer;
}

.dim-editor .ok .ic {
  width: 16px;
  height: 16px;
  stroke-width: 2.4;
}

.welcome {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(440px, calc(100% - 32px));
  max-height: calc(100% - 32px);
  overflow: auto;
  padding: 22px 24px 18px;
  border-radius: 16px;
}

.welcome h2 {
  margin: 0 0 8px;
  font-size: 20px;
  letter-spacing: -0.01em;
}

.welcome h3 {
  margin: 18px 0 6px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

.welcome p {
  margin: 0 0 14px;
  color: var(--muted);
}

.welcome .close {
  position: absolute;
  top: 8px;
  right: 8px;
}

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

.welcome .examples {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 4px;
}

/* ---------------------------------------------------------------- inspector */

.inspector {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-left: 1px solid var(--border);
  background: var(--surface);
}

.tabs {
  display: flex;
  gap: 2px;
  padding: 8px 10px 0;
  border-bottom: 1px solid var(--border);
}

.tabs button {
  flex: 1;
  height: 38px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  font-weight: 500;
  cursor: pointer;
}

.tabs button.on {
  color: var(--text);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.panes {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.pane {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 14px 16px 18px;
}

.about {
  margin: 0;
  padding: 0 22px 16px;
  font-size: 11.5px;
  color: var(--muted);
}

.empty {
  display: grid;
  justify-items: center;
  text-align: center;
  padding: 36px 12px;
  color: var(--muted);
}

.empty h3 {
  margin: 10px 0 4px;
  color: var(--text);
  font-size: 15px;
}

.empty p {
  margin: 4px 0;
  max-width: 30em;
}

.result-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 22px;
  font-weight: 600;
}

.result-head .eq {
  color: var(--muted);
  font-weight: 400;
}

.result-head .muted {
  font-size: 13px;
  font-weight: 400;
}

.qname sub {
  font-size: 0.68em;
}

.result-status {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 26px;
  margin: 6px 0 12px;
  font-size: 12.5px;
  color: var(--muted);
}

.chip {
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.chip.good {
  color: var(--good);
  background: color-mix(in srgb, var(--good) 13%, transparent);
}

.chip.warn {
  color: var(--warn);
  background: color-mix(in srgb, var(--warn) 15%, transparent);
}

.formula {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--paper);
  overflow-x: auto;
}

.formula-row {
  display: block;
  max-width: 100%;
  height: auto;
}

.latex-fallback {
  font: 13px var(--mono);
  white-space: pre-wrap;
  word-break: break-all;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.pane > .error {
  display: flex;
  gap: 6px;
  align-items: flex-start;
  font-size: 13px;
}

.qsec + .qsec {
  margin-top: 18px;
}

.qsec header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  color: var(--muted);
}

.qsec header h3 {
  margin: 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
}

.qsec header .ic {
  width: 17px;
  height: 17px;
}

.qrow {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px;
  margin: 0 -4px;
  border-radius: 8px;
}

.qrow.sel {
  background: color-mix(in srgb, var(--sel) 12%, transparent);
}

.qrow input[type="text"] {
  height: 30px;
  min-width: 0;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--paper);
}

.qrow input.name {
  width: 58px;
  flex: none;
  font-weight: 600;
}

.qrow input.expr,
.qrow .slider,
.qrow .value,
.qrow .con-text {
  flex: 1;
  min-width: 0;
}

.qrow input.expr {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--dim);
}

.qrow input.expr.measured {
  color: var(--muted);
  border-style: dashed;
}

.qrow input.conflict {
  color: var(--err);
  border-color: var(--err);
}

.qrow .value {
  padding: 0 9px;
  color: var(--muted);
  font-family: var(--mono);
}

.slider {
  display: flex;
  align-items: center;
  gap: 8px;
}

.slider input.num {
  width: 76px;
  flex: none;
  font-family: var(--mono);
  font-size: 13px;
}

.slider .range {
  flex: 1;
  min-width: 40px;
  accent-color: var(--accent);
}

.qrow .btns {
  display: flex;
  flex: none;
}

.qrow .ibtn {
  width: 28px;
  height: 28px;
}

.qrow .ibtn .ic {
  width: 17px;
  height: 17px;
}

.qrow .ibtn.del:hover {
  color: var(--err);
}

.swatch {
  width: 10px;
  height: 10px;
  margin: 0 4px;
  flex: none;
  border-radius: 50%;
}

.badge {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  flex: none;
  border-radius: 50%;
  background: var(--badge);
  color: var(--badge-text);
  font-weight: 700;
  font-size: 12px;
}

.badge.bad {
  background: var(--err);
  color: var(--surface);
}

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

.text-pane {
  display: flex;
  flex-direction: column;
}

.text-pane p {
  margin: 0 0 8px;
}

textarea.sgp {
  flex: 1;
  min-height: 200px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--paper);
  font: 12.5px/1.5 var(--mono);
  resize: none;
  tab-size: 2;
}

/* ---------------------------------------------------------------- menus, toasts, dialogs */

.menu {
  position: fixed;
  z-index: 50;
  min-width: 220px;
  max-height: calc(100dvh - 16px);
  overflow-y: auto;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.menu hr {
  margin: 5px 6px;
  border: 0;
  border-top: 1px solid var(--border);
}

.menu-heading {
  padding: 6px 10px 3px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 34px;
  padding: 4px 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  text-align: left;
  cursor: pointer;
}

.menu-item .ic {
  width: 18px;
  height: 18px;
  color: var(--muted);
}

.menu-item:hover:not(:disabled),
.menu-item:focus-visible {
  background: var(--surface-2);
  outline: none;
}

.menu-item:disabled {
  opacity: 0.5;
}

.menu-item .ic.sub {
  width: 16px;
  height: 16px;
  margin-right: -4px;
}

.tool-menu .ic {
  width: 22px;
  height: 22px;
  color: var(--text);
}

.toasts {
  position: fixed;
  z-index: 60;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  display: grid;
  gap: 6px;
  justify-items: center;
  width: min(520px, calc(100% - 24px));
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 9px 14px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  box-shadow: var(--shadow);
  font-size: 13.5px;
  animation: toast-in 0.18s ease-out;
  transition: opacity 0.3s, transform 0.3s;
}

.toast.error {
  background: var(--err);
  color: #fff;
}

.toast .ic {
  width: 18px;
  height: 18px;
  margin-top: 1px;
}

.toast.has-action {
  align-items: center;
  pointer-events: auto;
}

.toast-action {
  margin-left: 6px;
  padding: 4px 10px;
  border: 0;
  border-radius: 7px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  cursor: pointer;
}

.toast-close {
  display: grid;
  place-items: center;
  padding: 2px;
  border: 0;
  background: none;
  color: inherit;
  opacity: 0.7;
  cursor: pointer;
}

.toast.out {
  opacity: 0;
  transform: translateY(6px);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

dialog.help {
  width: min(720px, calc(100% - 24px));
  max-height: calc(100dvh - 40px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

dialog.help::backdrop {
  background: rgba(10, 12, 16, 0.4);
}

dialog.help header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 6px 22px;
}

dialog.help h2 {
  margin: 0;
  font-size: 18px;
}

.help-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  padding: 0 22px 22px;
}

.help-body h3 {
  margin: 14px 0 6px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.help-body p {
  margin: 0 0 10px;
}

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

.help-body dd {
  margin: 0;
}

/* ---------------------------------------------------------------- loading */

.boot {
  display: none;
}

#app.loading .boot,
#app.failed .boot {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  background: var(--bg);
}

#app.failed .boot .spinner {
  display: none;
}

.boot .spinner {
  width: 28px;
  height: 28px;
  border-width: 3px;
}

/* ---------------------------------------------------------------- narrow screens: a dock and a sheet */

@media (max-width: 760px) {
  .wide-only {
    display: none !important;
  }

  .narrow-only {
    display: inherit !important;
  }

  .bar {
    height: 48px;
    gap: 2px;
    padding: 0 4px 0 10px;
    padding-top: env(safe-area-inset-top);
  }

  .brand span {
    display: none;
  }

  /* the name box takes what is left, down to nothing, not its natural width */
  .doc-name {
    flex: 1 1 0;
    width: 0;
  }

  /* the canvas, a row the lowered sheet fills, and the dock; the raised sheet covers the canvas */
  .work {
    position: relative;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) var(--peek) auto;
  }

  .stage {
    grid-row: 1;
  }

  .rail {
    grid-row: 3;
    flex-direction: row;
    gap: 2px;
    height: calc(var(--dock) + env(safe-area-inset-bottom));
    padding: 4px 6px env(safe-area-inset-bottom);
    border-right: 0;
    border-top: 1px solid var(--border);
    overflow-x: auto;
    overflow-y: hidden;
    position: relative;
    z-index: 12;
  }

  .tool {
    flex: 1 1 0;
    min-width: 40px;
    min-height: 0;
    padding: 6px 1px 4px;
    font-size: 9.5px;
  }

  .tool.group::after {
    right: 3px;
    top: 5px;
  }

  .inspector {
    position: absolute;
    z-index: 11;
    left: 0;
    right: 0;
    bottom: calc(var(--dock) + env(safe-area-inset-bottom));
    height: var(--peek);
    border: 1px solid var(--border);
    border-bottom: 0;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.12);
    will-change: transform;
  }

  .inspector[data-sheet="half"] {
    height: 50%;
  }

  .inspector[data-sheet="full"] {
    height: calc(100% - var(--dock) - env(safe-area-inset-bottom) - 12px);
  }

  .inspector[data-sheet="peek"] .panes {
    visibility: hidden;
  }

  .sheet-handle {
    display: grid !important;
    place-items: center;
    height: 22px;
    cursor: grab;
    touch-action: none;
  }

  .sheet-handle span {
    width: 38px;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
  }

  /* the tabs drag the sheet too, so the browser must not take the gesture to scroll */
  .tabs {
    padding: 0 8px;
    touch-action: none;
  }

  .tabs button {
    height: 36px;
  }

  .hint {
    top: 8px;
    left: 8px;
    right: 8px;
    transform: none;
    max-width: none;
    border-radius: 14px;
    flex-wrap: wrap;
    row-gap: 2px;
  }

  .hint .text {
    flex: 1 1 60%;
    font-size: 13px;
  }

  .fnbar {
    top: 8px;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .fnbar label {
    display: none;
  }

  .fnbar .cancel {
    display: none;
  }

  .actions {
    left: 8px !important;
    right: 8px;
    top: auto !important;
    bottom: 10px;
    max-width: none;
    width: max-content;
    max-width: calc(100% - 16px);
  }

  .chip-btn {
    height: 40px;
  }

  .status {
    left: auto;
    right: 8px;
    bottom: 28px;
  }

  .actions:not([hidden]) ~ .status {
    display: none;
  }

  .help-body {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .toasts {
    bottom: calc(var(--dock) + var(--peek) + 70px);
  }
}

@media (pointer: coarse) {
  .ibtn {
    width: 40px;
    height: 40px;
  }

  .qrow input[type="text"] {
    height: 36px;
    font-size: 16px;
  }

  .dim-editor input,
  .fnbar input,
  .doc-name {
    font-size: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition: none !important;
  }
}
