/* RockWedge – own design rules (SPEC_ETAPPE2A chapter 1.3).
   Structure and building blocks adapted from GroundSlide app/style.css, reduced to what this step needs.
   No framework, no web fonts, no image files. Every colour, spacing, radius, shadow and font size is a
   variable in :root below; nothing else in this file contains a fixed colour value.
   Light and dark: "color-scheme: light dark" follows the system (prefers-color-scheme); the switch in the
   header sets data-theme on <html>. */

:root {
  color-scheme: light dark;

  /* --- colours: surfaces and text --- */
  --color-bg: light-dark(#f3f4f7, #14161b);
  --color-surface: light-dark(#ffffff, #1c1f26);
  --color-surface-2: light-dark(#e9ecf1, #262a33);
  --color-border: light-dark(#cdd2db, #3a414d);
  --color-border-strong: light-dark(#8b95a5, #66707f);
  --color-text: light-dark(#1a1d24, #e8ebf0);
  --color-text-muted: light-dark(#4d5767, #a7b0be);
  --color-text-disabled: light-dark(#7c8695, #7b8493);

  /* --- colours: one accent for main actions and selection --- */
  --color-accent: light-dark(#1d5ed8, #7aa7ff);
  --color-accent-text: light-dark(#ffffff, #0a1020);
  --color-accent-soft: color-mix(in srgb, var(--color-accent) 14%, var(--color-surface));
  --color-accent-hover: color-mix(in srgb, var(--color-accent) 88%, var(--color-text));
  --color-focus: var(--color-accent);

  /* --- colours: status (red only for errors and "not fulfilled", yellow for warnings, green for fulfilled) --- */
  --color-error: light-dark(#b42318, #ff9a92);
  --color-error-bg: light-dark(#fdecea, #3d1e1f);
  --color-warn: light-dark(#7a4f00, #f2c561);
  --color-warn-bg: light-dark(#fff3d1, #3b2f12);
  --color-ok: light-dark(#17692f, #6fd69a);
  --color-ok-bg: light-dark(#e4f5e9, #163223);
  --color-info: light-dark(#1d4fb0, #8db3ff);
  --color-info-bg: light-dark(#e8effc, #1c2b4a);

  /* --- colours: wedges (SPEC_ETAPPE2A 6.3); the same in light and dark; Okabe-Ito, distinguishable with red-green weakness --- */
  --wedge-000: #E69F00;
  --wedge-001: #56B4E9;
  --wedge-010: #009E73;
  --wedge-011: #F0E442;
  --wedge-100: #0072B2;
  --wedge-101: #D55E00;
  --wedge-110: #CC79A7;
  --wedge-111: #8C6D31;
  /* classes by FS (mode characteristic) or utilisation (mode sia): red (small FS) over yellow to blue; exception to "red only for errors" (1.3) */
  --class-1: #d73027;
  --class-2: #fc8d59;
  --class-3: #fee090;
  --class-4: #ffffbf;
  --class-5: #e0f3f8;
  --class-6: #91bfdb;
  --class-7: #4575b4;
  --wedge-stable: light-dark(#b8bec9, #5b6370);

  /* --- colours: cross-section graphic --- */
  --sketch-bg: light-dark(#fbfbfd, #171a20);
  --export-ground: #ffffff; /* the ground of an exported graphic: white, in the dark theme too */
  --sketch-outline: light-dark(#1a1d24, #e8ebf0);
  --sketch-opening: light-dark(rgb(255 255 255 / 0.6), rgb(0 0 0 / 0.25));
  --sketch-grid: light-dark(rgb(60 70 90 / 0.14), rgb(200 210 230 / 0.14));
  --sketch-axis: light-dark(#4d5767, #a7b0be);
  --sketch-bolt: light-dark(#6d3fc0, #b9a0ff);
  /* stereonet (SPEC_ETAPPE2B 5): joints J1 to J3 in green, violet, blue (no red), lighter in dark; axis and lines of intersection */
  --net-j1: light-dark(#2f9e44, #5fcf7b);
  --net-j2: light-dark(#7048e8, #a58bff);
  --net-j3: light-dark(#2563eb, #6ea0ff);
  --net-axis: light-dark(#1a1d24, #e8ebf0);
  --net-int: light-dark(#4d5767, #a7b0be);
  --sketch-label-bg: light-dark(rgb(255 255 255 / 0.88), rgb(23 26 32 / 0.88));

  --color-backdrop: rgb(0 0 0 / 0.4);

  /* --- shadows --- */
  --shadow-color: light-dark(rgb(20 30 50 / 0.14), rgb(0 0 0 / 0.5));
  --shadow-1: 0 1px 2px var(--shadow-color);

  /* --- spacing, radii, sizes --- */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --radius-s: 4px;
  --radius-m: 6px;
  --radius-l: 10px;
  --control-height: 32px;
  --header-height: 52px;
  --splitter-width: 8px;
  --input-width: 420px;
  --input-width-min: 280px;

  /* --- type --- */
  --font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
  --font-size-s: 0.8125rem;
  --font-size-m: 0.875rem;
  --font-size-l: 1rem;
  --font-size-xl: 1.125rem;
  --line-height: 1.45;
}

:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

/* ---------- base ---------- */

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

html { height: 100%; }

body {
  display: flex;
  flex-direction: column;
  height: 100dvh; /* the page fills the window and does not scroll as a whole (from 900 px width, see below) */
  margin: 0;
  overflow: hidden;
  background: var(--color-bg);
  color: var(--color-text);
  font: var(--font-size-m) / var(--line-height) var(--font-family);
}

h1, h2, h3 { margin: 0; font-weight: 600; line-height: 1.25; }
h2 { font-size: var(--font-size-l); }
p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }

table, input, .num { font-variant-numeric: tabular-nums; }

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.hint { color: var(--color-text-muted); font-size: var(--font-size-s); }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--control-height);
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-m);
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}
.btn:hover { background: var(--color-surface-2); }
.btn:active { background: var(--color-border); }
.btn:disabled {
  background: var(--color-surface-2);
  border-color: var(--color-border);
  color: var(--color-text-disabled);
  cursor: not-allowed;
}
.icon { display: inline-flex; width: 16px; height: 16px; }
.icon svg { width: 16px; height: 16px; }

/* switch buttons in a row (language, light/dark/system) */
.segmented {
  display: inline-flex;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-m);
  overflow: hidden;
  background: var(--color-surface);
}
.segmented button {
  min-height: calc(var(--control-height) - 2px);
  padding: 0 var(--space-3);
  border: 0;
  border-right: 1px solid var(--color-border);
  background: transparent;
  color: var(--color-text);
  font: inherit;
  cursor: pointer;
}
.segmented button:last-child { border-right: 0; }
.segmented button:hover { background: var(--color-surface-2); }
.segmented button[aria-pressed="true"] {
  background: var(--color-accent-soft);
  color: var(--color-accent);
  font-weight: 600;
}
.segmented button:focus-visible { outline-offset: -2px; }

/* ---------- tabs ---------- */

.tabs { display: flex; gap: var(--space-1); border-bottom: 1px solid var(--color-border); }
.tab {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--control-height);
  padding: 0 var(--space-3);
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--color-text-muted);
  font: inherit;
  cursor: pointer;
}
.tab:hover { color: var(--color-text); }
.tab[aria-selected="true"] {
  border-bottom-color: var(--color-accent);
  color: var(--color-accent);
  font-weight: 600;
}
.tab:focus-visible { outline-offset: -2px; }
.tab-badge {
  min-width: 1.5em;
  padding: 0 var(--space-1);
  border-radius: 999px;
  background: var(--color-warn-bg);
  color: var(--color-warn);
  font-size: var(--font-size-s);
  font-weight: 600;
  line-height: 1.5;
  text-align: center;
}
.tab-badge.is-error { background: var(--color-error-bg); color: var(--color-error); }
.tab-badge[hidden] { display: none; }

/* ---------- notice rows: info, warning, error, fulfilled ---------- */

.notice {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-1) var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-left: 3px solid currentColor;
  border-radius: var(--radius-s);
}
.notice[hidden] { display: none; }
.notice-info { background: var(--color-info-bg); color: var(--color-info); }
.notice-warn { background: var(--color-warn-bg); color: var(--color-warn); }
.notice-error { background: var(--color-error-bg); color: var(--color-error); }
.notice-ok { background: var(--color-ok-bg); color: var(--color-ok); }
.notice .notice-text { color: var(--color-text); }
.notice .code {
  font-family: var(--font-mono);
  font-size: var(--font-size-s);
  font-weight: 600;
}

/* ---------- page layout ---------- */

.app-header {
  display: flex;
  flex: none;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3) var(--space-4);
  min-height: var(--header-height);
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  box-shadow: var(--shadow-1);
}
.brand { display: flex; align-items: center; gap: var(--space-2); font-size: var(--font-size-xl); font-weight: 700; }
.brand svg { width: 24px; height: 24px; color: var(--color-accent); }
.model-name {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  min-width: 0;
  max-width: 28ch;
  padding: 0 var(--space-3);
  border-left: 1px solid var(--color-border);
  font-weight: 600;
}
.model-name #model-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-name #dirty-mark { color: var(--color-warn); }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.calc-status { color: var(--color-text-muted); font-size: var(--font-size-s); white-space: nowrap; }
.header-spacer { flex: 1; }

.layout {
  display: grid;
  grid-template-columns: var(--input-width) var(--splitter-width) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  flex: 1 1 auto;
  min-height: 0;
}
.inputs,
.output {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-width: 0;
  min-height: 0;
  padding: var(--space-4);
}
.inputs { overflow: auto; }

.splitter {
  cursor: col-resize;
  background: var(--color-border);
  touch-action: none;
}
.splitter:hover,
.splitter.is-dragging { background: var(--color-accent); }
.splitter:focus-visible { outline-offset: -2px; background: var(--color-accent); }

.output { overflow: hidden; }
.output-head { flex: none; border-bottom: 1px solid var(--color-border); }
.main-tabs { border-bottom: 0; }
.main-tabs .tab { margin-bottom: -1px; font-size: var(--font-size-l); }
.main-panels { display: flex; flex: 1 1 auto; flex-direction: column; min-height: 0; }
.main-panel { flex: 1 1 auto; min-height: 0; }
.main-panel[hidden] { display: none; }
.area {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-l);
  background: var(--color-surface);
  overflow: auto; /* the tab "Result" scrolls for itself; the drawing area of "Cross-section" fills the height (order 6) */
}

/* below 900 px the input is above the tabs and the page scrolls (SPEC_ETAPPE2A 1.3) */
@media (max-width: 899.98px) {
  body {
    display: block;
    height: auto;
    min-height: 100%;
    overflow: visible;
  }
  .layout { display: block; }
  .inputs,
  .output,
  .area { overflow: visible; }
  .main-panel { min-height: 360px; }
  .splitter { display: none; }
  .model-name { max-width: none; border-left: 0; padding-left: 0; }
}

/* ---------- input: areas, fields, tables ---------- */

.inputs { gap: var(--space-2); }

details.panel {
  flex: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-m);
  background: var(--color-surface);
}
details.panel[hidden] { display: none; }
details.panel > summary {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 36px;
  padding: 0 var(--space-3);
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  border-radius: var(--radius-m);
}
details.panel > summary::-webkit-details-marker { display: none; }
details.panel > summary::before {
  content: "";
  width: 6px;
  height: 6px;
  border-right: 2px solid var(--color-text-muted);
  border-bottom: 2px solid var(--color-text-muted);
  transform: rotate(-45deg);
  transition: transform 0.12s;
}
details.panel[open] > summary::before { transform: rotate(45deg); }
details.panel > summary:hover { background: var(--color-surface-2); }
details.panel > summary:focus-visible { outline-offset: -2px; }
details.panel[open] > summary { border-bottom: 1px solid var(--color-border); border-radius: var(--radius-m) var(--radius-m) 0 0; }
.summary-info { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--color-text-muted); font-size: var(--font-size-s); font-weight: 400; text-align: right; }
.summary-errors {
  padding: 0 var(--space-2);
  border-radius: 999px;
  background: var(--color-error-bg);
  color: var(--color-error);
  font-size: var(--font-size-s);
  font-weight: 600;
}
.summary-errors[hidden] { display: none; }
.panel-body { display: grid; gap: var(--space-3); padding: var(--space-3); }

.field { display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; gap: var(--space-1); min-width: 0; }
.field > label { font-size: var(--font-size-s); color: var(--color-text-muted); }
.field-control {
  display: flex;
  align-items: center;
  min-height: var(--control-height);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-m);
  background: var(--color-surface);
}
.field-control:hover { border-color: var(--color-text-muted); }
.field-control:has(:focus-visible) { outline: 2px solid var(--color-focus); outline-offset: 1px; }
.field-control input,
.field-control select,
.field-control textarea {
  flex: 1;
  min-width: 0;
  padding: 0 var(--space-2);
  border: 0;
  background: transparent;
  color: var(--color-text);
  font: inherit;
}
.field-control input { text-align: right; }
.field-control textarea { padding: var(--space-1) var(--space-2); resize: vertical; text-align: left; }
.field-wide .field-control input { text-align: left; }
.field-control :focus-visible { outline: 0; }
.field-unit { padding-right: var(--space-2); color: var(--color-text-muted); font-size: var(--font-size-s); white-space: nowrap; }
.field.is-invalid .field-control { border-color: var(--color-error); }
.field-error { color: var(--color-error); font-size: var(--font-size-s); }
.field-error[hidden] { display: none; }
.field-row { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: var(--space-3); }
.field-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr)); gap: var(--space-3); }

.check { display: inline-flex; align-items: center; gap: var(--space-2); cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--color-accent); }
.toolbar-row { display: flex; flex-wrap: wrap; gap: var(--space-2); }

.table-wrap {
  max-height: 22rem;
  overflow: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-m);
  background: var(--color-surface);
}
table.compact { width: 100%; border-collapse: separate; border-spacing: 0; }
table.compact th,
table.compact td {
  height: var(--row-height, 28px);
  padding: 0 var(--space-1);
  border-bottom: 1px solid var(--color-border);
  text-align: left;
  white-space: nowrap;
}
table.compact thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 0 var(--space-2);
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  font-size: var(--font-size-s);
  font-weight: 600;
}
table.compact td.num, table.compact th.num { text-align: right; }
table.compact th[scope="row"] { color: var(--color-text-muted); font-weight: 400; padding: 0 var(--space-2); }
table.compact tbody tr:hover { background: var(--color-accent-soft); }
table.compact tbody tr:last-child td, table.compact tbody tr:last-child th { border-bottom: 0; }
table.compact tr.is-invalid { background: var(--color-error-bg); }
table.compact td input,
table.compact td select {
  width: 100%;
  min-width: 4.2rem;
  height: 26px;
  padding: 0 var(--space-1);
  border: 1px solid transparent;
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--color-text);
  font: inherit;
  text-align: right;
}
table.compact td input.cell-text, table.compact td select { text-align: left; min-width: 5rem; }
table.compact td input:hover, table.compact td select:hover { border-color: var(--color-border-strong); }
table.compact td input.is-invalid { border-color: var(--color-error); background: var(--color-error-bg); }
table.compact td.actions { display: flex; align-items: center; gap: var(--space-1); }
table.compact td.muted { color: var(--color-text-disabled); text-align: center; }
.bolts-table td input { min-width: 3.6rem; }

.btn-icon { min-width: var(--control-height); padding: 0; }
.btn-icon .icon { margin: 0; }
table.compact .btn-icon { min-height: 24px; height: 24px; min-width: 24px; border-color: var(--color-border); }
.btn-icon-danger { color: var(--color-error); }
.btn-small { min-height: 28px; padding: 0 var(--space-2); font-size: var(--font-size-s); }
.btn[aria-pressed="true"] { background: var(--color-accent-soft); border-color: var(--color-accent); color: var(--color-accent); }

/* ---------- template form ---------- */

dialog.template-dialog {
  max-width: min(30rem, calc(100vw - 2 * var(--space-4)));
  padding: var(--space-4);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-l);
  background: var(--color-surface);
  color: var(--color-text);
}
dialog.template-dialog::backdrop { background: var(--color-backdrop); }
.template-form { display: grid; gap: var(--space-3); }
dialog.tool-dialog { max-width: min(42rem, calc(100vw - 2 * var(--space-4))); width: 100%; }
.tool-dialog .field-wide { grid-column: 1 / -1; }
.tool-dialog textarea.jl-link { width: 100%; font-family: var(--font-mono); font-size: var(--font-size-s); resize: vertical; }
.dxf-group { display: flex; flex-wrap: wrap; gap: var(--space-3); border: 1px solid var(--color-border); border-radius: var(--radius-m); padding: var(--space-2) var(--space-3); margin: 0; }
.dxf-group legend { padding: 0 var(--space-1); color: var(--color-text-muted); }
.dxf-choice { display: inline-flex; align-items: center; gap: var(--space-2); cursor: pointer; }
.dxf-table tr.is-selected { background: var(--color-accent-soft); }
.dxf-preview { display: block; }
.dxf-preview path { fill: none; stroke: var(--sketch-outline); stroke-width: 1.5; stroke-linejoin: round; }
.jl-table tr.is-muted { color: var(--color-text-muted); }
.sk-bolt.is-selected line { stroke: var(--color-accent); stroke-width: 5; }
.sk-bolt.is-selected text { fill: var(--color-accent); }
.is-pickable { cursor: pointer; }
.bolt-table tr.is-selected { background: var(--color-accent-soft); box-shadow: inset 3px 0 0 var(--color-accent); }
dialog.opt-dialog { max-width: min(46rem, calc(100vw - 2 * var(--space-4))); }
.opt-progress { display: flex; align-items: center; gap: var(--space-3); }
.opt-progress progress { flex: 1; }
.opt-plot { display: block; width: 100%; height: auto; max-width: 640px; }
.opt-band { fill: transparent; }
.opt-band.is-shade { fill: var(--color-accent-soft); }
.opt-band-label { fill: var(--color-text-muted); font-size: 10px; }
.opt-frame { fill: none; stroke: var(--color-border-strong); }
.opt-grid { stroke: var(--color-border); stroke-width: 0.5; }
.opt-tick, .opt-axis { fill: var(--color-text-muted); font-size: 11px; }
.opt-ref { stroke: var(--color-text-muted); stroke-width: 1; stroke-dasharray: 5 4; }
.opt-line { fill: none; stroke-width: 2; stroke-linejoin: round; }
.opt-line.is-strong { stroke-width: 3.5; }
.opt-line.is-thin { stroke-width: 1.2; opacity: 0.75; }
.dxf-choice.is-disabled { opacity: 0.55; cursor: not-allowed; }
.opt-line-all { stroke: var(--color-accent); }
.opt-line-sel { stroke: var(--sketch-bolt); }
.opt-arrow { stroke: none; }
.opt-arrow.opt-line-all { fill: var(--color-accent); }
.opt-arrow.opt-line-sel { fill: var(--sketch-bolt); }
.opt-mark { stroke-width: 1.5; }
.opt-mark-current { stroke: var(--color-text); stroke-dasharray: 3 3; }
.opt-mark-best { stroke: var(--sketch-outline); }
.opt-mark-value { font-size: 11px; font-weight: 600; paint-order: stroke; stroke: var(--color-surface); stroke-width: 3px; fill: var(--color-text); }
.opt-legend { display: flex; flex-wrap: wrap; gap: var(--space-3); margin: 0; font-size: var(--font-size-s); }
.opt-key::before { content: ''; display: inline-block; width: 1.4em; height: 0; border-top: 2px solid; vertical-align: middle; margin-right: 0.4em; }
.opt-key-all::before { border-color: var(--color-accent); }
.opt-key-sel::before { border-color: var(--sketch-bolt); }
.opt-key-current::before { border-color: var(--color-text); border-top-style: dashed; }
.opt-key-best::before { border-color: var(--sketch-outline); }
.dialog-actions { display: flex; justify-content: flex-end; gap: var(--space-2); }
.btn-primary { background: var(--color-accent); border-color: var(--color-accent); color: var(--color-accent-text); }
.btn-primary:hover { background: var(--color-accent-hover); }

/* ---------- cross-section graphic ---------- */

.area-section { overflow: auto; }
#sketch { display: flex; flex: 1 1 auto; flex-direction: column; gap: var(--space-2); min-height: 0; }
#sketch > * { flex: none; }
/* no text is marked while dragging in the drawing areas (SPEC_ETAPPE2B 12.7); input fields stay selectable */
#sketch, #view3d, #stereonet { -webkit-user-select: none; user-select: none; }
#sketch input, #view3d input, #stereonet input, #sketch textarea { -webkit-user-select: text; user-select: text; }
#sketch > .sketch-canvas { flex: 1 1 0; }
#sketch:fullscreen { padding: var(--space-3); background: var(--color-surface); }
.sketch-bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); }
.sketch-bar .btn-icon { border-color: var(--color-border-strong); background: var(--color-surface); }
.sketch-field { display: inline-flex; align-items: center; gap: var(--space-2); color: var(--color-text-muted); font-size: var(--font-size-s); }
.sketch-select {
  min-height: 28px;
  padding: 0 var(--space-2);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-m);
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
}
.sketch-help { position: relative; display: inline-flex; }
.sketch-help-button {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--color-border-strong);
  border-radius: 50%;
  background: var(--color-surface);
  color: var(--color-text-muted);
  font: inherit;
  font-size: var(--font-size-s);
  font-weight: 600;
  line-height: 1;
  cursor: help;
}
.sketch-help-button:hover { color: var(--color-text); }
.sketch-help-tip {
  display: none; /* out of the layout while hidden; shown at a place inside the window that lib/tooltip-position.js computes */
  position: fixed;
  left: 0;
  top: 0;
  z-index: 20;
  width: max-content;
  max-width: min(26rem, calc(100vw - 16px));
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-m);
  background: var(--color-surface);
  box-shadow: var(--shadow-1);
  color: var(--color-text);
  font-size: var(--font-size-s);
  font-weight: 400;
  text-align: left;
  white-space: normal;
}
.sketch-help.is-open .sketch-help-tip { display: block; }
.hint .sketch-help,
.detail-table th .sketch-help { margin-left: var(--space-1); vertical-align: middle; }
.hint .sketch-help-button,
.detail-table th .sketch-help-button { width: 20px; height: 20px; }
.sketch-canvas {
  position: relative;
  min-height: 8rem; /* about 128 px (SPEC_ETAPPE2A 1.3) */
  border: 1px solid var(--color-border);
  border-radius: var(--radius-m);
  background: var(--sketch-bg);
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}
.sketch-canvas.is-dragging { cursor: grabbing; }
.sketch-canvas:focus-visible { outline-offset: -2px; }
.sketch-svg { display: block; width: 100%; height: 100%; font: var(--font-size-s) var(--font-family); }
.sketch-coords {
  position: absolute;
  top: var(--space-1);
  right: var(--space-2);
  padding: 0 var(--space-1);
  border-radius: var(--radius-s);
  background: var(--sketch-label-bg);
  color: var(--color-text-muted);
  font-size: var(--font-size-s);
  pointer-events: none;
}
.sketch-coords:empty { display: none; }
.sketch-empty { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.sketch-empty:empty { display: none; }
.sketch-legend { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-4); }
.legend-item { display: inline-flex; align-items: center; gap: var(--space-1); font-size: var(--font-size-s); }
.legend-title { font-size: var(--font-size-s); font-weight: 600; color: var(--color-text-muted); }
.swatch { width: 14px; height: 14px; border: 1px solid var(--color-border-strong); border-radius: var(--radius-s); }

.sk-grid line { stroke: var(--sketch-grid); stroke-width: 1; vector-effect: non-scaling-stroke; }
.sk-axis-line { stroke: var(--sketch-axis); stroke-width: 1; }
.sk-axis-label, .sk-axis-title { fill: var(--sketch-axis); font-size: 11px; }
.sk-axis-title { font-weight: 600; }
/* ---------- export button with the menu of the formats ---------- */
.export-menu { position: relative; display: inline-block; }
.menu { position: absolute; z-index: 20; top: calc(100% + 2px); left: 0; margin: 0; padding: var(--space-1); list-style: none; min-width: 100%; background: var(--color-surface); border: 1px solid var(--color-border-strong); border-radius: var(--radius-m); box-shadow: 0 4px 14px var(--shadow-color); }
.menu[hidden] { display: none; }
.menu-item { display: block; width: 100%; padding: var(--space-1) var(--space-3); text-align: left; background: transparent; border: 0; border-radius: var(--radius-s); color: var(--color-text); cursor: pointer; font: inherit; }
.menu-item:hover, .menu-item:focus-visible { background: var(--color-accent-soft); }

/* ---------- short message over the page (toast) ---------- */
.toast { position: fixed; z-index: 50; top: 72px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: var(--space-3); max-width: min(48rem, calc(100vw - 2 * var(--space-4))); padding: var(--space-2) var(--space-3); background: var(--color-surface); color: var(--color-text); border: 1px solid var(--color-border-strong); border-left: 4px solid var(--color-accent); border-radius: var(--radius-m); box-shadow: 0 4px 14px var(--shadow-color); }
.toast[hidden] { display: none; }
.toast-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast-close { background: transparent; border: 0; color: var(--color-text-muted); font-size: 1.2rem; line-height: 1; cursor: pointer; }

/* ---------- graphic export (SPEC_ETAPPE2C 6): only in the hidden box with the light colour scheme ---------- */
.ex-ground { fill: var(--export-ground); stroke: none; }
.ex-frame { fill: none; stroke: var(--color-border-strong); stroke-width: 1; }
.ex-text { fill: var(--color-text); font-size: 12px; }
.ex-bold { font-weight: 600; }
.ex-swatch { stroke: var(--sketch-outline); stroke-width: 1; }
.sk-outline { fill: var(--sketch-opening); stroke: var(--sketch-outline); stroke-width: 2; stroke-linejoin: round; }
/* handles: corners of the section and collars of the bolts (SPEC_ETAPPE2A 6.4) */
/* ---------- 3D view (SPEC_ETAPPE2B) ---------- */

#view3d { display: flex; flex: 1 1 auto; flex-direction: column; gap: var(--space-2); min-height: 0; }
#view3d > * { flex: none; }
#view3d > .v3-canvas { flex: 1 1 0; }
#view3d:fullscreen { padding: var(--space-3); background: var(--color-surface); }
.v3-canvas { cursor: grab; touch-action: none; }
.v3-canvas-el { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
.v3-labels { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.v3-label {
  position: absolute;
  left: 0;
  top: 0;
  padding: 0 var(--space-1);
  border-radius: var(--radius-s);
  background: var(--sketch-label-bg);
  font-size: 12px;
  font-weight: 600;
  line-height: 16px;
  white-space: nowrap;
  will-change: transform;
}
.v3-label-wedge { border: 1.5px solid var(--v3-label-color, var(--color-border-strong)); color: var(--color-text); }
.v3-label-wedge.is-selected { border-width: 3px; }
.v3-label-bolt { font-size: 11px; }
.v3-axes { position: absolute; left: var(--space-2); bottom: var(--space-2); pointer-events: none; overflow: visible; }
.v3-bolt-note {
  position: absolute;
  left: calc(120px + var(--space-4) + var(--space-2));
  bottom: var(--space-2);
  max-width: calc(100% - 120px - var(--space-4) - var(--space-3));
  padding: 2px var(--space-2);
  border-radius: var(--radius-s);
  background: var(--sketch-label-bg);
  color: var(--color-text-muted);
  font-size: var(--font-size-s);
  pointer-events: none;
}
.v3-bolt-note:empty { display: none; }
.v3-axis line { stroke: var(--sketch-axis); stroke-width: 2; }
.v3-axis polygon { fill: var(--sketch-axis); }
.v3-axis text { fill: var(--color-text); font-size: 12px; font-weight: 600; paint-order: stroke; stroke: var(--sketch-bg); stroke-width: 3px; }
.v3-axis.is-axis line { stroke: var(--sketch-bolt); }
.v3-axis.is-axis polygon { fill: var(--sketch-bolt); }
.v3-axis.is-axis text { fill: var(--sketch-bolt); }
.v3-pivot { position: absolute; left: 0; top: 0; width: 9px; height: 9px; border-radius: 50%; background: var(--color-accent); border: 1.5px solid var(--sketch-bg); pointer-events: none; display: none; will-change: transform; }
.v3-pivot.is-on { display: block; }
.v3-probe { position: absolute; width: 0; height: 0; overflow: hidden; visibility: hidden; }
.v3-slider { width: 7rem; accent-color: var(--color-accent); }
.v3-explosion-value { min-width: 4.5em; text-align: right; color: var(--color-text); }

.sk-handles { pointer-events: none; }
.sk-handle { r: 4.5px; fill: var(--sketch-outline); stroke: var(--sketch-bg); stroke-width: 1.5; }
.sk-handle-bolt { fill: var(--sketch-bolt); }
.sk-handle-boltEnd { fill: var(--sketch-bg); stroke: var(--sketch-bolt); stroke-width: 2; }
.sk-handle.is-locked { opacity: 0.55; }
.sk-handle.is-active { r: 6.5px; fill: var(--color-accent); stroke: var(--sketch-bg); stroke-width: 2; opacity: 1; }
.sk-readout { fill: var(--color-text); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; paint-order: stroke; stroke: var(--sketch-bg); stroke-width: 3px; stroke-linejoin: round; pointer-events: none; }
.sketch-canvas.is-over-handle { cursor: move; }
.sketch-canvas.is-moving-node { cursor: grabbing; }
.sketch-canvas.is-bolt-tool { cursor: crosshair; }
.btn-danger { color: var(--color-error); border-color: var(--color-error); }
.btn-danger:disabled { color: var(--color-text-disabled); border-color: var(--color-border); }
.node-editor {
  position: absolute;
  z-index: 4;
  display: grid;
  gap: var(--space-2);
  min-width: 11rem;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-m);
  background: var(--color-surface);
  box-shadow: var(--shadow-1);
  cursor: default;
}
.node-editor-row { display: grid; gap: var(--space-1); }
.node-editor-label { display: flex; align-items: center; gap: var(--space-2); }
.node-editor-key { min-width: 3.2em; color: var(--color-text-muted); font-weight: 600; }
.node-editor input {
  flex: 1;
  min-width: 0;
  min-height: 28px;
  padding: 0 var(--space-2);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-s);
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  text-align: right;
}
.node-editor input.is-invalid { border-color: var(--color-error); }
.node-editor-unit { min-width: 1.2em; color: var(--color-text-muted); font-size: var(--font-size-s); }
.node-editor-error { color: var(--color-error); font-size: var(--font-size-s); }
.node-editor-error[hidden] { display: none; }
.node-editor-actions { display: flex; gap: var(--space-2); }
.node-editor-hint { margin: 0; }
.sk-trace { fill-opacity: 0.32; stroke-width: 1.5; stroke-linejoin: round; }
.sk-trace.is-selected { fill-opacity: 0.5; stroke-width: 4; }
.sk-apex { stroke: var(--sketch-bg); stroke-width: 1.5; }
.sk-bolt line { stroke: var(--sketch-bolt); stroke-width: 3; stroke-linecap: round; }
.sk-bolt.is-ineffective line { stroke-dasharray: 7 5; stroke-width: 2.5; }
.sk-bolt text { fill: var(--sketch-bolt); font-size: 11px; font-weight: 600; }
.sk-arrows { fill: var(--sketch-axis); stroke: var(--sketch-axis); stroke-width: 1.5; }
.sk-arrows text { stroke: none; fill: var(--color-text); font-size: 11px; }
.sk-arrows path { stroke: none; }
.sk-label-bg { fill: var(--sketch-label-bg); stroke-width: 1.5; }
.sk-label text { fill: var(--color-text); font-size: 12px; }
.sk-label .sk-label-title { font-weight: 600; }
.sk-leader { stroke-width: 1; }

/* ---------- result (SPEC_ETAPPE2A 8) ---------- */

.result-tabs { margin-bottom: var(--space-3); }
.result-panel[hidden] { display: none; }
.tab-badge { margin-left: var(--space-1); padding: 0 var(--space-1); border-radius: 999px; background: var(--color-accent-soft); color: var(--color-accent); font-size: var(--font-size-s); font-weight: 600; }
.result-head { display: grid; grid-template-columns: max-content 1fr; gap: var(--space-1) var(--space-4); margin: 0 0 var(--space-3); }
.result-head dt { color: var(--color-text-muted); }
.result-head dd { margin: 0; }
.result-table { margin-bottom: var(--space-3); }
.result-table tbody tr.is-wedge { cursor: pointer; }
.result-table tbody tr.is-selected { background: var(--color-accent-soft); box-shadow: inset 3px 0 0 var(--color-accent); }
.result-table tbody tr.is-below-min td, .result-table tbody tr.is-below-min th { color: var(--color-text-muted); }
.result-table tbody tr.is-muted td, .result-table tbody tr.is-muted th { color: var(--color-text-muted); }
.result-table tbody tr:focus-visible { outline: 2px solid var(--color-focus); outline-offset: -2px; }
.result-table td, .result-table th { vertical-align: middle; }
.code-cell { font-weight: 600; color: var(--color-text); }
.result-table .swatch { display: inline-block; vertical-align: middle; }
.below-min { color: var(--color-text-muted); font-size: var(--font-size-s); white-space: nowrap; }
.verdict-ok { color: var(--color-ok); font-weight: 600; }
.verdict-bad { color: var(--color-error); font-weight: 600; }
.verdict { margin: var(--space-1) 0 0; }
.detail { display: grid; gap: var(--space-3); margin-top: var(--space-3); }
.detail-title { font-size: var(--font-size-l); }
.detail-group { display: grid; gap: var(--space-2); }
.detail-group h4 { margin: 0; font-size: var(--font-size-m); color: var(--color-text-muted); }
.detail-table th[scope="row"] { font-weight: 400; text-align: left; color: var(--color-text); }
.detail-table tr.is-governing, .detail-table tr.is-governing th, .detail-table tr.is-governing td { font-weight: 700; background: var(--color-accent-soft); }

.result-state { font-weight: 600; }
.result-state.is-error { color: var(--color-error); }
.result-section { display: grid; gap: var(--space-2); margin-top: var(--space-3); }
.result-section h3 { font-size: var(--font-size-m); }
.messages-list { display: grid; gap: var(--space-2); }
.notice-jump {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-1) var(--space-2);
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.notice:has(> .notice-jump) { padding: var(--space-2) var(--space-3); }
.notice .where { flex-basis: 100%; color: var(--color-text-muted); font-size: var(--font-size-s); }
.is-invalid-note { color: var(--color-error); }

/* ---------- stereonet (SPEC_ETAPPE2B 5) ---------- */

#stereonet { display: flex; flex: 1 1 auto; flex-direction: column; gap: var(--space-2); min-height: 0; }
#stereonet > * { flex: none; }
#stereonet > .net-canvas { flex: 1 1 0; }
.net-canvas { cursor: default; touch-action: auto; }
.net-holder { position: absolute; inset: 0; }
.net { display: block; font: var(--font-size-s) var(--font-family); }
.net-grid { fill: none; stroke: var(--sketch-grid); stroke-width: 1; }
.net-rim { fill: none; stroke: var(--sketch-axis); stroke-width: 1.5; }
.net-cardinal { fill: var(--color-text); font-size: 13px; font-weight: 700; }
.net-j1 { --c: var(--net-j1); }
.net-j2 { --c: var(--net-j2); }
.net-j3 { --c: var(--net-j3); }
.net-gc { fill: none; stroke: var(--c); stroke-width: 2; }
.net-pole { fill: var(--c); stroke: var(--sketch-bg); stroke-width: 1.5; }
.net-hit { fill: none; stroke: transparent; stroke-width: 12; }
.net-hit-pole { fill: transparent; stroke: none; }
.net-joint:hover .net-gc { stroke-width: 3.5; }
.net-joint:hover .net-pole { r: 7; }
.net-axis-line { stroke: var(--net-axis); stroke-width: 1; }
.net-axis-head { fill: var(--net-axis); stroke: var(--net-axis); stroke-width: 1; stroke-linejoin: round; }
.net-axis-mark { fill: var(--net-axis); stroke: var(--sketch-bg); stroke-width: 1.5; stroke-linejoin: round; }
.net-int-mark { fill: var(--net-int); stroke: var(--sketch-bg); stroke-width: 1.5; }
.net-axis:hover .net-axis-mark, .net-int:hover .net-int-mark { stroke: var(--color-accent); }
.net-label { font-size: 12px; font-weight: 600; fill: var(--c, var(--color-text)); paint-order: stroke; stroke: var(--sketch-bg); stroke-width: 4px; stroke-linejoin: round; pointer-events: none; }
.net-axis-label { fill: var(--net-axis); }
.net-int-label { fill: var(--net-int); }
.net-tip {
  display: none;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 20;
  width: max-content;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-m);
  background: var(--color-surface);
  box-shadow: var(--shadow-1);
  color: var(--color-text);
  font-size: var(--font-size-s);
  white-space: pre-line;
  pointer-events: none;
}

/* below 900 px the drawing area is at least 360 px high and the page scrolls (SPEC_ETAPPE2A 1.3) */
@media (max-width: 899.98px) {
  #view3d > .v3-canvas { flex: none; }
  #stereonet > .net-canvas { flex: none; }
  .sketch-canvas { flex: none; height: clamp(360px, 60dvh, 720px); min-height: 360px; }
  #sketch > .sketch-canvas { flex: none; }
}
.calc-status.is-error { color: var(--color-error); }

/* the message line of the last action stays one line (long model names) and does not take more height than needed */
#app-notice { flex-wrap: nowrap; }
#app-notice .notice-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#app-notice .code { flex: none; }
.bolts-table td input, table.compact td input { min-width: 3.2rem; }
table.compact thead th { padding: 0 var(--space-1); }

/* ---------- result document (SPEC_ETAPPE2C 7, 14): hidden on the screen, the only thing that prints ---------- */

#print-doc { display: none; }
@media print {
  @page { margin: 15mm; }
  /* the page is replaced by the document as soon as it has been filled; otherwise it prints as it is */
  html:has(#print-doc:not(:empty)) { height: auto; color-scheme: light; background: var(--export-ground); }
  body:has(#print-doc:not(:empty)) { display: block; height: auto; overflow: visible; background: var(--export-ground); }
  body:has(#print-doc:not(:empty)) > :not(#print-doc) { display: none !important; }
  #print-doc:not(:empty) {
    display: block;
    color-scheme: light; /* the document is always light, also when the page is dark */
    background: var(--export-ground);
    color: var(--color-text);
    font-family: var(--font-family);
    font-size: 9.5pt;
    line-height: 1.35;
  }
  .pd-frame { width: 100%; border-collapse: collapse; }
  .pd-frame > tbody > tr > td, .pd-frame > tfoot > tr > td { padding: 0; }
  .pd-frame > tfoot { display: table-footer-group; }
  .pd-head h1 { margin: 0 0 2mm; font-size: 16pt; }
  .pd-description { margin: 0 0 2mm; color: var(--color-text-muted); }
  .pd-meta { display: grid; grid-template-columns: max-content 1fr; gap: 0.6mm 6mm; margin: 0 0 2mm; }
  .pd-meta dt { color: var(--color-text-muted); }
  .pd-meta dd { margin: 0; font-weight: 600; }
  .pd-note { margin: 1.5mm 0; }
  .pd-section h2 { margin: 5mm 0 1.5mm; font-size: 12pt; break-after: avoid; border-bottom: 0.3mm solid var(--color-border-strong); }
  .pd-section h3 { margin: 3mm 0 1mm; font-size: 10pt; break-after: avoid; }
  .pd-section h4 { margin: 2mm 0 0.5mm; font-size: 9pt; break-after: avoid; color: var(--color-text-muted); }
  .pd-assumptions ol { margin: 0; padding-left: 5mm; }
  .pd-block { break-inside: avoid; }
  .pd-table { width: 100%; border-collapse: collapse; font-size: 8pt; font-variant-numeric: tabular-nums; }
  .pd-table thead { display: table-header-group; } /* the head is repeated on every page */
  .pd-table tr { break-inside: avoid; }
  .pd-table th, .pd-table td { padding: 0.5mm 1.5mm; border-bottom: 0.2mm solid var(--color-border-strong); }
  .pd-table thead th { border-bottom-width: 0.4mm; font-weight: 600; }
  .pd-table th.num, .pd-table td.num { text-align: right; }
  .pd-table th.txt, .pd-table td.txt { text-align: left; }
  .pd-section sub { font-size: 0.75em; line-height: 0; } /* indices of symbols (SPEC_ETAPPE2C 15 point 4) */
  .pd-kv th { width: 45%; font-weight: 400; color: var(--color-text-muted); }
  .pd-facts { margin-top: 1mm; }
  .pd-below td { color: var(--color-text-muted); }
  .pd-figure { margin: 3mm 0; break-inside: avoid; text-align: center; }
  .pd-figure figcaption { margin-top: 1mm; font-size: 8pt; color: var(--color-text-muted); }
  /* the graphics are drawn for their width in pixels (lib/page-graphic.js): 1 unit = 1 px, text 8 pt; on a narrower page they shrink */
  .pd-fig-2d .pd-svg svg { display: block; width: 180mm; max-width: 100%; height: auto; margin: 0 auto; }
  .pd-fig-net .pd-svg svg { display: block; width: 90mm; max-width: 100%; height: auto; margin: 0 auto; }
  .pd-img-3d { display: block; width: 180mm; max-width: 100%; height: auto; max-height: 120mm; object-fit: contain; margin: 0 auto; }
  .pd-wedge { margin: 3mm 0 4mm; padding-top: 1mm; border-top: 0.2mm solid var(--color-border-strong); break-inside: avoid; }
  .pd-wedge-title { margin: 0 0 1mm; font-size: 10.5pt; }
  .pd-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 6mm; break-inside: avoid; }
  .pd-math { margin: 0.5mm 0 1.5mm 3mm; break-inside: avoid; }
  .pd-formula { display: grid; grid-template-columns: 32mm 1fr; align-items: center; break-inside: avoid; }
  .pd-formula-math { display: flex; justify-content: flex-start; min-width: 0; }
  .pd-formula-label { font-size: 8pt; color: var(--color-text-muted); }
  .pd-formula math { font-size: 9.5pt; margin: 0.3mm 0; }
  .pd-case { margin: 1mm 0; padding-left: 2mm; border-left: 0.6mm solid var(--color-border-strong); break-inside: avoid; }
  .pd-case.is-governing { border-left-color: var(--color-accent); }
  .pd-case-name { margin: 0; font-weight: 600; font-size: 9pt; }
  .pd-verdict { margin: 1mm 0; }
  .pd-ok { color: var(--color-ok); }
  .pd-bad { color: var(--color-error); }
  .pd-bolts { margin: 1mm 0; }
  .pd-foot { display: flex; justify-content: space-between; gap: 6mm; margin: 4mm 0 0; padding-top: 1.5mm; border-top: 0.2mm solid var(--color-border-strong); color: var(--color-text-muted); font-size: 8pt; }
}
