:root {
  --paper: #f4f4ed;
  --card: #fffefa;
  --ink: #203f38;
  --muted: #6d7971;
  --rule: #dce1d5;
  --green: #285b49;
  --mint: #e6eee4;
  --inferred: #a13d35;
  --inferred-soft: #f8e8e5;
  --given-soft: #e8f0e8;
  --radius: 8px;
  color: var(--ink);
  background: var(--paper);
  font: 14px/1.4 "Avenir Next", "Trebuchet MS", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); }
button, input { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.app-shell {
  height: 100dvh;
  min-height: 0;
  padding: 6px;
  display: grid;
  grid-template-columns: 212px minmax(0, 1fr);
  align-content: stretch;
  gap: 6px;
  overflow: hidden;
}
.app-shell.utility-closed { grid-template-columns: minmax(0, 1fr); }
.workbench { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto auto minmax(0, 1fr); gap: 4px; overflow-x: auto; overflow-y: hidden; }
.sidebar { min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.management-heading, #management-panes { min-width: 0; }
.management-heading { border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; }
.management-heading .pane-header { border-bottom: 0; }
#management-panes { flex: 1; display: grid; grid-template-rows: auto minmax(210px, 1fr); gap: 8px; min-height: 0; }
#management-panes > .pane { min-height: 0; }
.settings-list { display: grid; gap: 7px; margin-bottom: 10px; }
.settings-list label { display: flex; align-items: center; gap: 7px; font-size: 12px; }
.file-panel h3 { margin: 0 0 6px; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .05em; }
.file-panel h3:not(:first-child) { margin-top: 16px; }
.file-actions { display: grid; gap: 6px; }
.file-actions button { width: 100%; }
#file-status { display: block; margin-top: 14px; color: var(--muted); font-size: 10px; }
.management-attribution { margin-top: auto; padding: 7px 3px; text-align: center; font-size: 10px; line-height: 1.4; color: var(--muted); }
.management-attribution a { color: inherit; }
.management-toggle { flex: 0 0 30px; }

.workspace-toolbar {
  min-height: 29px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 2px 5px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--card);
}
#selection-status { margin: 3px 0 0; color: var(--muted); font-size: 11px; }
.workspace-toolbar button { min-height: 23px; padding: 2px 6px; font-size: 11px; }
.workspace-toolbar .toolbar { gap: 3px; }
.workspace-toolbar .management-toggle { width: 25px; }

.toolbar, .hidden-panes { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
button {
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 7px 10px;
  background: var(--card);
  color: var(--ink);
}
button:hover:not(:disabled) { background: var(--mint); border-color: #a9b9aa; }
button:disabled { opacity: 0.38; cursor: not-allowed; }
.filled { background: var(--green); border-color: var(--green); color: white; }
.filled:hover:not(:disabled) { background: #1a4434; }
.text-button { border-color: transparent; background: transparent; text-decoration: underline; text-underline-offset: 3px; }
.hidden-panes { padding: 3px 6px; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--card); }
.hidden-panes button { padding: 3px 7px; font-size: 11px; }
.hidden-panes::before { content: "Hidden panes"; margin-right: 4px; color: var(--muted); font-size: 11px; }

.property-grid {
  position: relative;
  display: grid;
  height: auto;
  min-height: 0;
  gap: 0;
  overflow: hidden;
}
.pane-column {
  min-width: 0;
  min-height: 0;
  display: grid;
  overflow: hidden;
}
.pane-column.has-one { grid-template-rows: minmax(0, 1fr); }
.empty-column-target { position: absolute; z-index: 30; top: 0; bottom: 0; width: 22px; opacity: 0; pointer-events: auto; }
.empty-column-0 { left: 0; }
.empty-column-1 { left: 50%; transform: translateX(-50%); }
.empty-column-2 { right: 0; }
.column-divider, .row-divider {
  position: relative;
  touch-action: none;
  background: transparent;
}
.column-divider { cursor: col-resize; }
.row-divider { cursor: row-resize; }
.column-divider::after, .row-divider::after {
  content: "";
  position: absolute;
  border-radius: 3px;
  background: #c9d1c5;
  opacity: 0.72;
  transition: background 120ms ease, opacity 120ms ease;
}
.column-divider::after { inset: 8px 3px; }
.row-divider::after { inset: 3px 8px; }
.column-divider:hover::after, .row-divider:hover::after {
  background: var(--green);
  opacity: 1;
}
.pane {
  --pane-bg: var(--card);
  --pane-header: #f7f8f3;
  --pane-border: var(--rule);
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border: 1px solid var(--pane-border);
  border-radius: var(--radius);
  background: var(--pane-bg);
  overflow: hidden;
  container-type: inline-size;
  position: relative;
}
.pane[data-pane="construction"] {
  --pane-bg: #f9fbf7;
  --pane-header: #e6eee4;
  --pane-border: #cbd8ca;
}
.pane[data-pane="sides-angles"] {
  --pane-bg: #fff4e3;
  --pane-header: #f8e5c9;
  --pane-border: #e9d1ad;
}
.pane[data-pane="quadrilaterals"] {
  --pane-bg: #edf7e9;
  --pane-header: #dcefd6;
  --pane-border: #c5ddbd;
}
.pane[data-pane="diagonals"] {
  --pane-bg: #f2edfb;
  --pane-header: #e5dcf6;
  --pane-border: #d2c5e9;
}
.pane[data-pane="symmetry"] {
  --pane-bg: #eaf5fb;
  --pane-header: #d7ebf5;
  --pane-border: #bddae8;
}
.pane[data-pane="auxiliary"] {
  --pane-bg: #fff8d9;
  --pane-header: #f6edbd;
  --pane-border: #e4d795;
}
.pane[data-pane="triangles"] {
  --pane-bg: #fbedf1;
  --pane-header: #f3dce4;
  --pane-border: #e1c3ce;
}
.pane.drop-before::before, .pane.drop-after::after {
  content: "";
  position: absolute;
  z-index: 20;
  left: 7px;
  right: 7px;
  height: 4px;
  border-radius: 3px;
  background: var(--green);
  box-shadow: 0 0 0 2px var(--card);
  pointer-events: none;
}
.pane.drop-before::before { top: 2px; }
.pane.drop-after::after { bottom: 2px; }
.pane-column.drop-column-end { outline: 3px solid rgba(40, 91, 73, 0.45); outline-offset: -3px; }
.is-dragging-pane .pane { transition: box-shadow 100ms ease; }
.pane-header {
  min-height: 30px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 4px;
  padding: 3px 6px;
  border-bottom: 1px solid var(--pane-border);
  background: var(--pane-header);
}
.pane-header h2 { margin: 0; font-size: 12px; font-weight: 650; letter-spacing: 0; }
.pane-body { min-height: 0; padding: 6px; overflow: auto; scrollbar-width: thin; }
.scroll-cue {
  position: absolute;
  z-index: 12;
  right: 3px;
  width: 16px;
  height: 15px;
  display: grid;
  place-items: center;
  border-radius: 3px;
  background: color-mix(in srgb, var(--pane-header) 86%, white);
  color: #53675f;
  font-size: 8px;
  line-height: 1;
  pointer-events: none;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--pane-border) 70%, transparent);
}
.scroll-cue-up { top: 33px; }
.scroll-cue-down { bottom: 3px; }
.construction-body { padding: 0; overflow: hidden; }
.construction-stage { position: relative; width: 100%; height: 100%; min-height: 0; }
.construction-svg { width: 100%; height: 100%; display: block; touch-action: none; background: #fcfdf9; }
.quad-fill { fill: rgba(40, 91, 73, 0.08); stroke: none; }
.construction-sides line, .construction-diagonals line, .construction-symmetry line, .construction-symmetry path,
.construction-angle-marks path, .construction-angle-marks line, .construction-angle-marks polyline,
.construction-diagonal-marks line, .construction-diagonal-marks polyline { vector-effect: non-scaling-stroke; }
.construction-sides line { stroke: #203f38; stroke-width: 2; }
.construction-sides line.has-given { stroke-width: 2.8; }
.construction-sides line.has-parallel { stroke-width: 3.25; }
.construction-diagonals line { stroke: #625678; stroke-width: 1.75; stroke-dasharray: 4 2; }
.construction-diagonals line.has-given { stroke-width: 2.4; opacity: 1; }
.construction-angle-marks path, .construction-angle-marks polyline, .construction-angle-marks line {
  fill: none;
  stroke: #68766f;
  stroke-width: 1.25;
  opacity: .62;
}
.construction-angle-marks path.has-given { stroke-width: 2; opacity: 1; }
.construction-angle-marks polyline, .construction-angle-marks line { stroke: #a60000; stroke-width: 2; opacity: 1; }
.construction-diagonal-marks line, .construction-diagonal-marks polyline {
  fill: none;
  stroke: #625678;
  stroke-width: 2;
}
.construction-diagonal-marks.is-blue line, .construction-diagonal-marks.is-blue polyline { stroke: #0000a6; }
.construction-symmetry line, .construction-symmetry path {
  fill: none;
  stroke: #4f6e7d;
  stroke-width: 1.5;
  stroke-dasharray: 4 2;
  opacity: .72;
}
.construction-symmetry path { marker-end: url(#symmetry-arrowhead); stroke-dasharray: 5 3; }
.construction-symmetry .is-active { stroke: #bd322a; stroke-width: 2.5; opacity: 1; }
.construction-symmetry path.is-active { marker-end: url(#symmetry-arrowhead); }
.segment-labels text, .construction-points text, .construction-measures text {
  fill: #203f38;
  font-family: "Iowan Old Style", Georgia, serif;
  font-size: 4px;
  user-select: none;
}
.segment-labels text { fill: #586760; font-style: italic; font-size: 3.4px; }
.construction-measures text { fill: #365547; font-size: 2.8px; text-anchor: middle; dominant-baseline: middle; pointer-events: none; }
.draggable-label { pointer-events: auto; cursor: move; touch-action: none; }
.svg-sub { baseline-shift: sub; font-size: 70%; }
.draggable-point { cursor: grab; outline: none; }
.draggable-point:active { cursor: grabbing; }
.draggable-point circle { fill: #285b49; stroke: #fffefa; stroke-width: 0.45; vector-effect: non-scaling-stroke; }
.draggable-point:hover circle, .draggable-point:focus circle { fill: #a13d35; stroke-width: 0.8; }
.intersection-point circle { fill: #7c877f; }
.intersection-point[hidden] { display: none; }
.construction-controls { position: absolute; right: 8px; bottom: 8px; display: flex; align-items: center; gap: 6px; }
.construction-controls .icon-button { background: rgba(255, 254, 250, 0.9); border-color: #cbd8ca; font-size: 18px; }
.measure-toggle { display: flex; align-items: center; gap: 4px; padding: 4px 7px; border: 1px solid #cbd8ca; border-radius: 5px; background: rgba(255, 254, 250, .9); color: var(--ink); font-size: 10px; cursor: pointer; }
.measure-toggle input { width: 13px; height: 13px; margin: 0; accent-color: var(--green); }
.pane-drag-handle, .icon-button {
  width: 23px;
  height: 23px;
  padding: 0;
  border-color: transparent;
  background: transparent;
  text-decoration: none;
}
.pane-drag-handle { color: var(--muted); cursor: grab; touch-action: none; }
.is-dragging-pane .pane-drag-handle { cursor: grabbing; }
.count {
  min-width: 20px;
  height: 20px;
  display: inline-grid;
  place-items: center;
  padding: 0 5px;
  border-radius: 20px;
  background: #e5eadd;
  font-size: 10px;
}
.property-group { margin: 0; padding: 0; border: 0; }
.property-group + .property-group { margin-top: 6px; padding-top: 5px; border-top: 1px solid rgba(120, 130, 120, .16); }
.property-group legend { margin: 0 0 3px; padding: 0; color: var(--muted); font-size: 8px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.fact-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px 4px; }
.fact {
  min-width: 0;
  min-height: 24px;
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr) 6px;
  align-items: center;
  gap: 4px;
  padding: 2px 3px;
  border-radius: 5px;
  font-family: "Iowan Old Style", Georgia, serif;
  font-size: 12.5px;
  line-height: 1.16;
  cursor: pointer;
}
.fact:hover { background: rgba(255, 255, 255, 0.58); }
.fact input { width: 13px; height: 13px; margin: 0; accent-color: var(--green); }
.fact-label { overflow-wrap: anywhere; }
.math-name { white-space: nowrap; font-style: italic; }
.math-name sub { font-size: 0.7em; line-height: 0; vertical-align: -0.32em; }
.fact.is-given { background: var(--given-soft); font-weight: 650; }
.fact.is-inferred { color: var(--inferred); background: var(--inferred-soft); }
.fact.is-inferred .fact-state { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

@container (max-width: 245px) {
  .fact-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 900px) {
  .app-shell, .app-shell.utility-closed { display: block; height: auto; min-height: 100dvh; }
  .workbench { display: block; }
  .sidebar { margin-bottom: 10px; }
  .workspace-toolbar { align-items: flex-start; flex-direction: column; }
  .toolbar { width: 100%; }
  .toolbar button { flex: 1; }
  .property-grid {
    height: auto;
    min-height: 0;
    display: flex !important;
    flex-direction: column;
    overflow: visible;
  }
  .pane-column { display: contents; }
  .column-divider, .row-divider { display: none; }
  .empty-column-target { display: none; }
  .pane { width: 100%; height: 440px; margin-bottom: 10px; }
  .fact-grid { grid-template-columns: minmax(0, 1fr); }
}
