:root {
  color-scheme: light;
  --bg: #eef0f3;
  --panel: #fff;
  --ink: #202630;
  --muted: #586371;
  --line: #d4dae1;
  --field: #fff;
  --subtle: #f5f7f9;
  --braid: #245aa8;
  --knit: #a54423;
  --chamber: #d3e9e5;
  --chamber-line: #55847c;
  --clamp: #586371;
  --thread-under: #fff;
  --error: #a32b29;
  --focus: #1e68c7;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1b1e24;
  --panel: #242830;
  --ink: #edf0f5;
  --muted: #afb9c6;
  --line: #424a56;
  --field: #1b1e24;
  --subtle: #2b3039;
  --braid: #86b6ff;
  --knit: #ffae89;
  --chamber: #334f4b;
  --chamber-line: #84b9af;
  --clamp: #a7b2c1;
  --thread-under: #242830;
  --error: #ffaaa6;
  --focus: #86b6ff;
}
* {
  box-sizing: border-box;
}
html {
  scrollbar-color: var(--line) var(--bg);
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}
::selection {
  background: var(--braid);
  color: var(--panel);
}
button,
input,
select {
  font: inherit;
  color: inherit;
}
button,
select,
input[type="number"] {
  border: 1px solid var(--line);
  background: var(--field);
  border-radius: 5px;
  min-height: 36px;
}
button {
  padding: 6px 12px;
  cursor: pointer;
}
button:hover {
  background: var(--subtle);
}
button:disabled {
  opacity: 0.5;
  cursor: default;
}
a {
  color: var(--braid);
  text-underline-offset: 3px;
}
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}
input {
  accent-color: var(--braid);
  caret-color: var(--braid);
}
input[type="range"] {
  width: 100%;
  margin: 10px 0 3px;
  height: 18px;
}
input[type="number"] {
  width: 100%;
  padding: 5px 8px;
  margin-top: 4px;
}
input[type="checkbox"] {
  width: 16px;
  height: 16px;
  flex: none;
}
select {
  width: 100%;
  padding: 5px 8px;
  margin-top: 5px;
}
h1,
h2,
h3,
p {
  margin: 0;
}
h1 {
  font-size: 21px;
  font-weight: 650;
  letter-spacing: -0.02em;
}
h2 {
  font-size: 16px;
  font-weight: 650;
}
h3 {
  font-size: 14px;
  font-weight: 650;
}
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 26px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.app-header p {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}
.header-actions {
  display: flex;
  gap: 8px;
}
.workspace {
  display: grid;
  grid-template-columns: 258px minmax(0, 1fr);
  max-width: 1500px;
  margin: auto;
}
aside {
  padding: 22px 22px 28px;
  border-right: 1px solid var(--line);
  background: var(--panel);
}
aside > h2 {
  margin-bottom: 14px;
}
aside label {
  display: block;
  font-size: 12px;
  font-weight: 600;
}
.control {
  margin-top: 24px;
}
.label-line {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
}
.label-line output {
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}
.hint {
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
}
.initial {
  margin: 24px 0 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
.initial p {
  margin-top: 5px;
}
details {
  border-top: 1px solid var(--line);
  padding-top: 13px;
}
summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
}
form {
  padding-top: 14px;
}
form > label,
.fields {
  margin-bottom: 12px;
}
.fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.check {
  display: flex !important;
  align-items: flex-start;
  gap: 8px;
  font-weight: 400 !important;
}
.check input {
  margin: 2px 0 0;
}
form button {
  margin-top: 14px;
}
#config-error {
  font-size: 12px;
  color: var(--error);
  margin-top: 10px;
}
.layer {
  margin: 20px 0 10px;
}
.transport {
  display: flex;
  gap: 6px;
  margin-top: 12px;
}
.text-button {
  border: 0;
  background: transparent;
  padding-left: 0;
  color: var(--braid);
  font-size: 12px;
  margin-top: 4px;
}
main {
  min-width: 0;
  padding: 0 28px 20px;
  background: var(--panel);
}
.tabs {
  display: flex;
  gap: 24px;
  border-bottom: 1px solid var(--line);
  min-height: 60px;
  align-items: stretch;
}
.tabs button {
  border: 0;
  border-radius: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  padding: 15px 0;
  font-size: 13px;
  color: var(--muted);
}
.tabs button[aria-current] {
  color: var(--ink);
  border-bottom-color: var(--ink);
  font-weight: 650;
}
.board-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  color: var(--muted);
  padding: 17px 0 7px;
}
.muscle-pair,
.structure-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}
.muscle {
  min-width: 0;
  padding: 12px 22px 18px;
}
.muscle + .muscle {
  border-left: 1px solid var(--line);
}
.muscle h2 {
  display: flex;
  align-items: center;
  gap: 8px;
}
.braid {
  --series: var(--braid);
}
.knit {
  --series: var(--knit);
}
.swatch {
  display: inline-block;
  width: 9px;
  height: 9px;
  background: var(--series);
  border-radius: 50%;
  flex: none;
}
.status {
  font-size: 12px;
  color: var(--muted);
  min-height: 36px;
  margin-top: 5px;
}
.muscle > svg {
  width: 100%;
  max-height: 430px;
  display: block;
}
svg {
  overflow: visible;
  font-family: inherit;
  color: var(--ink);
}
svg text {
  fill: var(--muted);
  font-variant-numeric: tabular-nums;
}
.readouts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 18px;
  margin: 0 0 12px;
  padding-top: 13px;
  border-top: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.readouts dt {
  font-size: 11px;
  color: var(--muted);
}
.readouts dd {
  font-size: 17px;
  margin: 0;
  font-weight: 600;
}
.board-note {
  font-size: 12px;
  color: var(--muted);
  padding: 12px 0;
  border-top: 1px solid var(--line);
  max-width: 85ch;
}
.structure {
  margin-top: 22px;
  border-top: 1px solid var(--line);
  padding-top: 20px;
}
.structure-pair {
  gap: 36px;
  margin-top: 18px;
}
.structure-pair svg {
  width: 100%;
  display: block;
  max-height: 230px;
}
.structure-pair p {
  color: var(--muted);
  font-size: 12px;
  max-width: 45ch;
  margin-top: 10px;
}
#graphs,
#theory {
  padding-top: 26px;
}
.section-intro {
  margin: 8px 0 24px;
  color: var(--muted);
  max-width: 76ch;
}
.plots {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}
figure {
  margin: 0;
  min-width: 0;
}
figcaption {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
}
figure svg {
  width: 100%;
}
.legend {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  margin: 18px 0;
  font-size: 12px;
  color: var(--muted);
}
.legend span {
  display: flex;
  align-items: center;
  gap: 7px;
}
.theory {
  max-width: 78ch;
}
.theory p {
  margin: 10px 0 20px;
}
.theory h2:not(:first-child) {
  margin-top: 28px;
}
.equations {
  font-family: Cambria, Georgia, serif;
  font-size: 18px;
  line-height: 1.9;
  padding: 15px 0;
  overflow-wrap: anywhere;
}
.theory table {
  border-collapse: collapse;
  width: 100%;
  font-size: 12px;
  margin-top: 12px;
}
.theory td,
.theory th {
  border-bottom: 1px solid var(--line);
  padding: 8px 6px;
  text-align: left;
}
footer {
  margin-top: 32px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}
.skip {
  position: absolute;
  left: 12px;
  top: -80px;
  background: var(--panel);
  padding: 8px;
  z-index: 10;
}
.skip:focus {
  top: 8px;
}
[hidden] {
  display: none !important;
}
@media (min-width: 1450px) {
  .muscle > svg {
    max-height: 480px;
  }
}
@media (max-width: 1000px) {
  main {
    padding: 0 18px 20px;
  }
  .muscle {
    padding: 12px;
  }
  .tabs {
    gap: 18px;
  }
  .plots {
    grid-template-columns: 1fr;
  }
  figure svg {
    max-height: 285px;
  }
  .workspace {
    grid-template-columns: 236px minmax(0, 1fr);
  }
}
@media (max-width: 700px) {
  .app-header {
    padding: 14px 16px;
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }
  h1 {
    font-size: 20px;
  }
  .header-actions {
    width: 100%;
  }
  .workspace {
    display: block;
  }
  aside {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 20px 18px;
  }
  .control {
    margin-top: 18px;
  }
  .initial {
    margin-top: 18px;
  }
  main {
    padding: 0 14px 20px;
  }
  .tabs {
    gap: 16px;
    min-height: 55px;
  }
  .tabs button {
    font-size: 11px;
    padding: 12px 0;
  }
  .board-meta {
    font-size: 10px;
    gap: 6px;
  }
  .muscle {
    padding: 10px 8px;
  }
  .muscle h2 {
    font-size: 13px;
    gap: 5px;
  }
  .status {
    font-size: 11px;
    min-height: 51px;
  }
  .muscle > svg {
    max-height: 350px;
  }
  .readouts {
    gap: 8px;
    grid-template-columns: 1fr;
  }
  .readouts dd {
    font-size: 15px;
  }
  .muscle .hint {
    font-size: 10px;
  }
  .structure-pair {
    gap: 16px;
  }
  .structure-pair h3 {
    font-size: 13px;
  }
  .structure-pair p {
    font-size: 11px;
  }
  .theory table {
    font-size: 12px;
  }
  .equations {
    font-size: 16px;
  }
  .board-note {
    font-size: 11px;
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
  }
}
.detail-measure {
  font-variant-numeric: tabular-nums;
}
.structure-pair svg text:last-child {
  display: none;
}
@media (max-width: 700px) {
  .muscle > svg text {
    display: none;
  }
  .detail-measure {
    font-size: 11px !important;
  }
}
/* P2 review: quieter work area, distinct structural threads, a clean slide view. */
:root {
  --bg: #e9edf2;
  --panel: #ffffff;
  --ink: #202c3e;
  --muted: #526477;
  --line: #d9e1e9;
  --subtle: #f2f5f8;
  --braid: #3659a4;
  --knit: #b45532;
  --chamber: #dce9ef;
  --chamber-line: #819ba9;
  --clamp: #465369;
  --fiber: #65758b;
  --knit-fiber: #9c7d70;
  --thread-under: #eaf0f3;
}
:root[data-theme="dark"] {
  --bg: #151b24;
  --panel: #1e2734;
  --ink: #edf3fb;
  --muted: #b1c0d3;
  --line: #394b61;
  --subtle: #253348;
  --braid: #91b0ff;
  --knit: #ffb398;
  --chamber: #344b5c;
  --chamber-line: #7293a3;
  --clamp: #acbcd0;
  --fiber: #90a5c1;
  --knit-fiber: #ba9d91;
  --thread-under: #344b5c;
}
.app-header {
  padding: 15px 26px;
}
.header-actions {
  flex-wrap: wrap;
}
.header-actions button {
  font-size: 12px;
}
#capture {
  background: var(--ink);
  color: var(--panel);
  border-color: var(--ink);
}
#capture:hover {
  background: var(--braid);
  border-color: var(--braid);
  color: #fff;
}
.board-meta,
.board-note {
  display: none;
}
.muscle {
  padding-top: 20px;
  padding-bottom: 4px;
}
.muscle h2 {
  font-size: 17px;
}
.muscle > svg {
  max-height: 360px;
  margin-top: 12px;
}
.status:empty {
  display: none;
}
.status {
  margin: 7px 0 0;
  min-height: 0;
  color: var(--error);
  font-weight: 600;
}
.readouts {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 4px 0 8px;
  padding-top: 12px;
}
.readouts dd {
  font-size: 16px;
  white-space: nowrap;
}
.structure {
  margin-top: 12px;
  padding-top: 16px;
}
.structure-pair {
  margin-top: 0;
  gap: 30px;
}
.structure-pair svg {
  max-height: 210px;
}
.structure-pair h3 {
  font-size: 14px;
  font-weight: 600;
}
.structure-pair .detail-measure {
  margin: 3px 0 0;
  font-size: 12px;
}
.structure-pair svg text:last-child {
  display: initial;
}
.muscle > svg text {
  display: initial;
}
.dimension {
  fill: var(--muted);
}
.braid-back {
  fill: none;
  stroke: var(--fiber);
  stroke-width: 0.75;
  opacity: 0.18;
}
.braid-strand {
  fill: none;
  stroke: var(--fiber);
  stroke-width: 1.1;
  opacity: 0.85;
}
.crossing-under {
  fill: none;
  stroke: var(--thread-under);
  stroke-width: 3.4;
}
.fragment {
  fill: none;
  stroke-width: 2.6;
}
.fragment-braid {
  stroke: var(--braid);
}
.fragment-knit {
  stroke: var(--knit);
}
.knit-under {
  fill: none;
  stroke: var(--thread-under);
  stroke-width: 3;
}
.knit-strand {
  fill: none;
  stroke: var(--knit-fiber);
  stroke-width: 1.05;
  opacity: 0.68;
}
.initial-cell {
  fill: none;
  stroke: var(--line);
  stroke-width: 1.4;
  stroke-dasharray: 3 4;
}
.pantograph-cell {
  fill: var(--subtle);
  stroke: var(--braid);
  stroke-width: 2.5;
  stroke-linejoin: round;
}
.angle-label {
  fill: var(--braid);
  font-weight: 600;
}
.point-guide {
  fill: none;
  stroke: var(--muted);
  stroke-width: 1;
  opacity: 0.4;
  stroke-dasharray: 3 3;
}
.initial-point {
  fill: var(--panel);
  stroke: var(--muted);
  stroke-width: 1;
  opacity: 0.5;
}
#plot-pressure {
  font-size: 13px;
  font-weight: 400;
  color: var(--muted);
}
#capture-error {
  color: var(--error);
  margin-top: 15px;
}
.presenting .workspace {
  display: block;
  max-width: 1250px;
}
.presenting aside,
.presenting .tabs,
.presenting .app-header h1,
.presenting .app-header p,
.presenting #theme,
.presenting #export {
  display: none;
}
.presenting .app-header {
  justify-content: flex-end;
  background: var(--bg);
  border: 0;
}
.presenting main {
  padding: 0 35px 22px;
}
.presenting #comparison {
  display: block !important;
}
.presenting #graphs,
.presenting #theory {
  display: none !important;
}
.presenting .muscle > svg {
  max-height: 365px;
}
.presenting .muscle h2 {
  font-size: 20px;
}
.presenting .readouts dd {
  font-size: 20px;
}
.presenting .structure-pair svg {
  max-height: 220px;
}
.presenting .structure {
  margin-top: 14px;
}
body[data-mode="geometry"] .readouts {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
@media (max-width: 1100px) {
  .readouts {
    grid-template-columns: 1fr 1fr;
  }
  .readouts dd {
    font-size: 16px;
  }
  .muscle {
    padding-left: 12px;
    padding-right: 12px;
  }
  .muscle > svg {
    max-height: 325px;
  }
}
@media (max-width: 700px) {
  .app-header {
    padding: 14px 16px;
  }
  .header-actions {
    gap: 6px;
  }
  .header-actions button {
    font-size: 11px;
    padding: 6px 8px;
  }
  .muscle h2 {
    font-size: 13px;
  }
  .muscle > svg {
    margin-top: 5px;
  }
  .muscle > svg text {
    display: none;
  }
  .structure-pair {
    gap: 16px;
  }
  .structure-pair svg {
    min-height: 150px;
  }
  .structure-pair .detail-measure {
    font-size: 10px;
  }
  .readouts {
    grid-template-columns: 1fr !important;
  }
  .readouts dd {
    font-size: 14px;
  }
  .structure-pair svg .angle-label {
    font-size: 17px;
  }
  .presenting main {
    padding: 0 12px 16px;
  }
  .presenting .readouts dd {
    font-size: 15px;
  }
  .presenting .muscle h2 {
    font-size: 14px;
  }
}
.fragment-braid {
  stroke-width: 1.4;
}
.fragment-zone .braid-strand {
  stroke: var(--braid);
  stroke-width: 1.2;
  opacity: 1;
}
#braid-measure {
  display: none;
}
@media (max-width: 700px) {
  #braid-measure {
    display: block;
    font-size: 12px !important;
  }
  .structure-pair .angle-label {
    display: none;
  }
}
:root {
  --yarn-outline: #6a4a3f;
  --yarn-core: #e5c9b8;
  --yarn-neutral: #8795a6;
  --ply-0: #944521;
  --ply-1: #c67b43;
  --ply-2: #edbb7d;
  --ply-3: #734537;
  --study-green: #24776d;
  --study-purple: #7952a2;
  --study-fill: #ce9e74;
}
:root[data-theme="dark"] {
  --yarn-outline: #1a1514;
  --yarn-core: #806452;
  --yarn-neutral: #96a5b7;
  --ply-0: #f1bf91;
  --ply-1: #bc713f;
  --ply-2: #ffe1bb;
  --ply-3: #dd9664;
  --study-green: #83ccb7;
  --study-purple: #c9aff5;
  --study-fill: #ad7245;
}
.yarn-outline {
  stroke: var(--yarn-outline);
}
.yarn-core {
  stroke: var(--yarn-core);
}
.ply-back {
  stroke: var(--yarn-neutral);
  opacity: 0.3;
}
.neutral-yarn .ply-front {
  stroke: var(--yarn-neutral);
  opacity: 0.7;
}
.selected-yarn .ply-0 {
  stroke: var(--ply-0);
}
.selected-yarn .ply-1 {
  stroke: var(--ply-1);
}
.selected-yarn .ply-2 {
  stroke: var(--ply-2);
}
.selected-yarn .ply-3 {
  stroke: var(--ply-3);
}
.ply-front {
  opacity: 1;
}
.neighbour-cell {
  fill: none;
  stroke: var(--fiber);
  stroke-width: 1;
  opacity: 0.55;
}
.cell-axis {
  fill: none;
  stroke: var(--braid);
  stroke-width: 0.8;
  stroke-dasharray: 2 3;
}
.cell-angle {
  fill: none;
  stroke: var(--braid);
  stroke-width: 1.5;
}
.yarn-control {
  margin-top: 20px;
}
.yarn-inspector {
  margin-top: 20px;
  border-top: 1px solid var(--line);
  padding-top: 17px;
}
.inspector-heading {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: baseline;
}
.inspector-heading h3 {
  font-size: 14px;
}
.inspector-heading span {
  font-size: 12px;
  color: var(--muted);
}
#yarn-detail {
  width: 100%;
  height: 330px;
  display: block;
}
.study-heading {
  display: flex;
  justify-content: space-between;
  gap: 15px;
  align-items: center;
  border-top: 1px solid var(--line);
  padding-top: 22px;
  margin: 28px 0 16px;
}
.study-controls {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr;
  gap: 14px;
  max-width: 650px;
  margin: 15px 0 25px;
}
.study-controls label {
  font-size: 12px;
}
.study-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 30px 26px;
}
.study-grid figure {
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}
.study-grid figcaption {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.study-grid figcaption button {
  font-size: 11px;
  min-height: 28px;
  padding: 2px 7px;
}
.study-grid svg {
  width: 100%;
  max-height: 300px;
  display: block;
}
.study-legend {
  display: flex;
  gap: 8px 15px;
  flex-wrap: wrap;
  font-size: 11px;
  color: var(--muted);
}
.study-legend span {
  display: flex;
  align-items: center;
  gap: 5px;
}
.study-legend i {
  display: inline-block;
  width: 17px;
  border-top: 2px solid var(--curve);
}
.study-legend i.dashed {
  border-top-style: dashed;
}
.study-note {
  font-size: 11px;
  line-height: 1.45;
  color: var(--muted);
  margin-top: 8px;
}
.origin-tag {
  font-size: 11px;
  color: var(--muted);
}
.origin-tag.example {
  display: inline-block;
  color: var(--knit);
  font-weight: 600;
}
.example-control {
  display: grid;
  grid-template-columns: auto minmax(80px, 180px) 40px;
  gap: 10px;
  align-items: center;
  justify-content: start;
  margin: 15px 0 24px;
  font-size: 12px;
}
.example-control input {
  margin: 0;
}
.example-control output {
  font-variant-numeric: tabular-nums;
}
#study-error {
  color: var(--error);
  font-size: 12px;
  margin: 18px 0;
}
.presenting .yarn-inspector {
  display: none;
}
@media (max-width: 1000px) {
  .study-grid {
    grid-template-columns: 1fr;
  }
  .study-controls {
    gap: 8px;
  }
  .study-grid svg {
    max-height: 310px;
  }
}
@media (max-width: 700px) {
  #yarn-detail {
    height: 275px;
  }
  .study-controls {
    grid-template-columns: 1fr 1fr;
  }
  .study-controls label:first-child {
    grid-column: 1/-1;
  }
  .study-heading {
    align-items: flex-start;
  }
  .study-heading h2 {
    font-size: 15px;
  }
  .study-heading button {
    font-size: 11px;
    padding: 4px 8px;
  }
  .example-heading {
    flex-direction: column;
    gap: 5px;
  }
  .study-grid {
    gap: 24px;
  }
  .study-legend {
    font-size: 10px;
  }
  .inspector-heading {
    gap: 8px;
  }
  .inspector-heading h3 {
    font-size: 12px;
  }
}

/* P2d: larger construction views, stable layout and persistent touch controls. */
html {
  scrollbar-gutter: stable;
}
aside {
  position: sticky;
  top: 0;
  align-self: start;
  max-height: 100dvh;
  overflow: auto;
}
#comparison,
.structure,
.plots,
.study-grid {
  overflow-anchor: none;
}
.muscle > svg {
  height: 400px;
  max-height: none;
}
.status,
.status:empty {
  display: block;
  min-height: 20px;
  height: 20px;
  line-height: 20px;
  margin: 7px 0 0;
}
.status:empty {
  visibility: hidden;
}
.readouts {
  min-height: 60px;
}
.readouts div {
  min-width: 0;
}
.structure-pair {
  gap: 32px;
}
.structure-pair svg {
  height: 330px;
  max-height: none;
  overflow: hidden;
}
.structure-pair .detail-measure {
  font-size: 13px;
  min-height: 20px;
}
#braid-measure {
  display: block;
}
.neighbour-cell {
  stroke-width: 0.45;
  opacity: 0.85;
}
.selected-cable {
  fill: none;
  stroke: var(--braid);
  stroke-width: 0.65;
}
.pantograph-cell {
  stroke-width: 0.3;
}
.braid-strand {
  stroke-width: 0.4;
  opacity: 0.9;
}
.braid-back {
  stroke-width: 0.3;
}
.crossing-under {
  stroke-width: 4;
}
.fragment-zone .braid-strand {
  stroke-width: 0.5;
}
.closeup-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
}
.yarn-inspector {
  min-width: 0;
}
.inspector-heading {
  min-height: 38px;
  flex-wrap: wrap;
  gap: 6px 12px;
}
.inspector-heading h3 {
  font-size: 14px;
}
.inspector-heading .check {
  font-size: 11px;
  color: var(--muted);
  align-items: center;
}
.inspector-heading .check input {
  margin: 0;
}
#yarn-detail,
#contact-detail {
  width: 100%;
  height: 350px;
  display: block;
  overflow: hidden;
}
.contact-crossing {
  fill: none;
  stroke: var(--braid);
  stroke-width: 1.2;
  stroke-dasharray: 3 3;
  opacity: 0.8;
}
.hide-crossings .crossing-marks {
  visibility: hidden;
}
.touch-controls {
  display: none;
}
.presenting .muscle > svg {
  height: 400px;
  max-height: none;
}
.presenting .structure-pair svg {
  height: 300px;
  max-height: none;
}
@media (max-width: 1160px) {
  .structure-pair,
  .closeup-pair {
    grid-template-columns: 1fr;
    gap: 22px;
  }
  .structure-pair svg {
    height: 340px;
  }
  #yarn-detail,
  #contact-detail {
    height: 380px;
  }
  .muscle > svg {
    height: 350px;
  }
}
@media (max-width: 700px) {
  body {
    padding-bottom: 116px;
  }
  .workspace {
    min-height: 0;
  }
  aside {
    position: static;
    max-height: none;
    overflow: visible;
  }
  body[data-section="comparison"] aside .control,
  body[data-section="comparison"] aside .initial {
    display: none !important;
  }
  aside {
    padding-top: 16px;
    padding-bottom: 12px;
  }
  aside .yarn-control {
    margin-top: 12px;
  }
  aside .layer {
    margin-top: 12px;
    margin-bottom: 0;
  }
  aside details {
    margin-top: 12px;
  }
  .header-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .header-actions button {
    min-height: 40px;
    font-size: 12px;
  }
  .tabs {
    gap: 14px;
    flex-wrap: wrap;
  }
  .tabs button {
    min-height: 48px;
  }
  .muscle {
    padding: 14px 8px 6px;
  }
  .muscle h2 {
    font-size: 13px;
  }
  .muscle > svg {
    height: 290px;
    max-height: none;
  }
  .status,
  .status:empty {
    font-size: 10px;
  }
  .readouts {
    min-height: 124px;
  }
  .structure-pair {
    gap: 24px;
  }
  .structure-pair svg {
    height: 350px;
    min-height: 0;
  }
  .structure-pair h3,
  .inspector-heading h3 {
    font-size: 15px;
  }
  .structure-pair .detail-measure {
    font-size: 12px !important;
  }
  #yarn-detail {
    height: 330px;
  }
  #contact-detail {
    height: 360px;
  }
  input[type="range"] {
    min-height: 32px;
    touch-action: pan-y;
  }
  .touch-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    position: fixed;
    z-index: 5;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--panel);
    border-top: 1px solid var(--line);
    padding: 10px 16px max(9px, env(safe-area-inset-bottom));
  }
  .touch-controls .label-line {
    font-size: 12px;
  }
  #touch-play {
    font-size: 11px;
    min-height: 32px;
    padding: 4px 8px;
  }
  .touch-controls input {
    width: 100%;
    margin: 3px 0 0;
    min-height: 34px;
  }
  .touch-phase {
    grid-column: 1/-1;
  }
  body[data-mode="geometry"] .touch-pressure,
  body[data-mode="geometry"] .touch-load,
  body[data-mode="load"] .touch-phase {
    display: none;
  }
  body[data-section="graphs"] .touch-controls,
  body[data-section="theory"] .touch-controls,
  .presenting .touch-controls {
    display: none;
  }
  .presenting {
    padding-bottom: 0;
  }
  .presenting .muscle > svg {
    height: 290px;
    max-height: none;
  }
}

/* P2e: alternating neighboring rows; the solo loop retains its warm cord. */
:root {
  --row-alt-outline: #254a53;
  --row-alt-core: #c3d9dd;
  --row-alt-0: #1f6776;
  --row-alt-1: #368b99;
  --row-alt-2: #b6dbe0;
  --row-alt-3: #194955;
}
:root[data-theme="dark"] {
  --row-alt-outline: #152b32;
  --row-alt-core: #476d77;
  --row-alt-0: #76c6d0;
  --row-alt-1: #3a8797;
  --row-alt-2: #c0eef0;
  --row-alt-3: #5cabb9;
}
.yarn-tone-1 .yarn-outline {
  stroke: var(--row-alt-outline);
}
.yarn-tone-1 .yarn-core {
  stroke: var(--row-alt-core);
}
.yarn-tone-1 .ply-0 {
  stroke: var(--row-alt-0);
}
.yarn-tone-1 .ply-1 {
  stroke: var(--row-alt-1);
}
.yarn-tone-1 .ply-2 {
  stroke: var(--row-alt-2);
}
.yarn-tone-1 .ply-3 {
  stroke: var(--row-alt-3);
}
.knit-row-cool {
  stroke: var(--row-alt-0);
}
.defect-control {
  margin-top: 10px !important;
}

/* P2g: presentation timing remains explicit beside the load transport. */
.motion-note {
  font-size: 11px;
  line-height: 1.45;
  color: var(--muted);
  margin: 8px 0;
}
.stitch-control {
  border-top: 1px solid var(--line);
  padding-top: 18px;
}
#load-controls .transport {
  flex-wrap: wrap;
  gap: 6px;
}
#load-play {
  flex: 1;
  min-width: 120px;
}

.touch-run {
  display: none;
}
@media (max-width: 700px) {
  body[data-mode="load"] .touch-run {
    display: flex;
    grid-column: 1/-1;
    justify-content: space-between;
    align-items: center;
  }
  .touch-run::after {
    content: "Время условное";
    font-size: 10px;
    color: var(--muted);
  }
  body[data-mode="geometry"] .touch-run {
    display: none;
  }
}
@media (max-width: 700px) {
  body[data-section="comparison"] aside .stitch-control {
    display: block !important;
  }
  body[data-mode="load"] {
    padding-bottom: 160px;
  }
}

@media (max-width: 700px) {
  body.presenting {
    padding-bottom: 0;
  }
}

/* P2h: readable text, deliberate touch and keyboard feedback. */
button,
select {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
h1,
h2,
h3 {
  text-wrap: balance;
}
.theory p {
  max-width: 76ch;
}
.theory a {
  overflow-wrap: anywhere;
}
#capture:hover {
  background: var(--braid);
  border-color: var(--braid);
}
@media (max-width: 700px) {
  html {
    scroll-padding-block: 16px 180px;
  }
  button,
  select,
  input[type="number"],
  input[type="range"] {
    min-height: 44px;
  }
  .check {
    min-height: 44px;
    align-items: center;
  }
  .touch-controls input {
    min-height: 44px;
  }
  #touch-play {
    min-height: 44px;
  }
  .study-legend {
    font-size: 11px;
  }
}

/* P2i: a clearer instrument surface and aligned construction scales. */
:root {
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
}
.app-header {
  padding-block: 22px;
}
.app-header h1 {
  font-size: 28px;
  font-weight: 700;
}
.app-header p {
  font-size: 12px;
  margin-top: 5px;
}
.workspace {
  max-width: 1700px;
  grid-template-columns: 270px minmax(0, 1fr);
}
main {
  padding-inline: 32px;
}
aside {
  padding: 28px 24px;
}
aside > h2 {
  font-size: 19px;
}
.label-line output {
  color: var(--braid);
  font-size: 15px;
}
button {
  transition:
    background-color 160ms ease,
    border-color 160ms ease,
    color 160ms ease,
    transform 120ms var(--ease-out);
}
button:active:not(:disabled) {
  transform: scale(0.98);
}
#load-play,
#play {
  background: var(--braid);
  border-color: var(--braid);
  color: var(--panel);
  font-weight: 650;
}
nav[aria-label="Разделы модели"] {
  position: relative;
  gap: 28px;
}
nav[aria-label="Разделы модели"] button {
  border-bottom-color: transparent;
  padding-block: 18px;
  font-size: 13px;
}
nav[aria-label="Разделы модели"] button[aria-current] {
  color: var(--ink);
}
.tab-indicator {
  display: block;
  position: absolute;
  bottom: 0;
  left: 0;
  width: 1px;
  height: 2px;
  background: var(--braid);
  transform-origin: 0 50%;
  pointer-events: none;
}
.muscle h2 {
  font-size: 22px;
}
.muscle > svg {
  height: 440px;
}
.readouts {
  padding-top: 20px;
}
.readouts dt {
  color: var(--muted);
  font-size: 12px;
}
.readouts dd {
  font-size: 19px;
  font-weight: 650;
}
.construction-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 40px;
}
.construction-column {
  min-width: 0;
}
.construction-title {
  font-size: 23px;
  margin-bottom: 22px;
  letter-spacing: -0.02em;
}
.construction-column.braid .construction-title {
  color: var(--braid);
}
.construction-column.knit .construction-title {
  color: var(--knit);
}
.construction-figure {
  margin: 0;
  border-top: 1px solid var(--line);
  padding-top: 18px;
  height: 425px;
  overflow: clip;
}
.construction-figure figcaption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 38px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
}
.construction-figure figcaption > span:last-child:not(:first-child) {
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}
.construction-figure figcaption .check {
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
}
.construction-figure > svg,
#yarn-detail,
#contact-detail {
  display: block;
  width: 100%;
  height: 335px;
  max-height: none;
}
.construction-figure .detail-measure {
  font-size: 13px;
  height: 24px;
  color: var(--muted);
}
.angle-label {
  fill: var(--braid);
  font-size: 13px;
  font-weight: 600;
}
.neighbour-cell {
  stroke-width: 0.7;
  opacity: 1;
}
.selected-cable {
  stroke-width: 0.9;
}
.presenting .construction-figure {
  height: 340px;
}
.presenting .construction-figure > svg {
  height: 260px;
}
.presenting .construction-figure.yarn-inspector {
  display: block;
}
@media (hover: hover) and (pointer: fine) {
  #load-play:hover,
  #play:hover {
    filter: brightness(1.12);
  }
  .construction-figure:hover figcaption {
    color: var(--braid);
  }
}
@media (max-width: 1050px) {
  .workspace {
    grid-template-columns: 240px minmax(0, 1fr);
  }
  main {
    padding-inline: 22px;
  }
  aside {
    padding-inline: 18px;
  }
  .construction-columns {
    gap: 24px;
  }
  .construction-figure {
    height: 355px;
  }
  .construction-figure > svg,
  #yarn-detail,
  #contact-detail {
    height: 270px;
  }
  .construction-figure figcaption {
    flex-wrap: wrap;
    align-content: center;
    font-size: 13px;
    height: 46px;
  }
  .readouts dd {
    font-size: 17px;
  }
}
@media (max-width: 700px) {
  .app-header {
    padding: 18px 16px;
  }
  .app-header h1 {
    font-size: 23px;
  }
  .workspace {
    display: block;
  }
  aside {
    padding: 22px 16px;
  }
  main {
    padding-inline: 16px;
  }
  nav[aria-label="Разделы модели"] {
    gap: 18px;
  }
  nav[aria-label="Разделы модели"] button {
    font-size: 11px;
  }
  .muscle h2 {
    font-size: 17px;
  }
  .muscle > svg {
    height: 330px;
  }
  .readouts dd {
    font-size: 17px;
  }
  .construction-columns {
    grid-template-columns: 1fr;
    gap: 32px;
  }
  .construction-title {
    font-size: 22px;
    margin-bottom: 16px;
  }
  .construction-figure {
    height: 385px;
  }
  .construction-figure > svg,
  #yarn-detail,
  #contact-detail {
    height: 305px;
  }
  .construction-figure figcaption {
    font-size: 14px;
  }
  .construction-figure figcaption .check {
    min-height: 32px;
  }
}
@media (prefers-reduced-motion: reduce) {
  button {
    transition:
      background-color 160ms ease,
      color 160ms ease;
  }
  button:active:not(:disabled) {
    transform: none;
  }
}
.scale-tools {
  display: flex;
  justify-content: flex-end;
  padding-top: 12px;
}
#width-scale {
  font-size: 11px;
  padding: 5px 10px;
  color: var(--muted);
  background: transparent;
}
.motion-note {
  font-size: 12px;
}
@media (max-width: 700px) {
  #width-scale {
    min-height: 44px;
  }
}
