/* Isopleth studio. Paper, sumi ink, one vermilion accent; hairlines, no shadows. */

:root {
  --paper: #f4f1ea;
  --desk: #e6e2d8;
  --sheet: #fcfbf7;
  --ink: #1f1e1c;
  --muted: #69645b;
  --rule: #cfc9bc;
  --accent: #b73823;
  --ui: "Helvetica Neue", "Segoe UI", "Hiragino Sans", "Yu Gothic UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Courier New", monospace;
  --masthead: 52px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font: 14px/1.5 var(--ui);
  -webkit-font-smoothing: antialiased;
}

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

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

/* Masthead */
.masthead {
  height: var(--masthead);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  border-bottom: 1px solid var(--ink);
}
.brand { display: flex; align-items: baseline; gap: 16px; }
.wordmark {
  font-size: 15px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
}
.subtitle { font-size: 12px; color: var(--muted); letter-spacing: 0.04em; }
.masthead nav { display: flex; gap: 24px; font-size: 13px; }
.masthead a, .link {
  color: var(--ink);
  text-decoration: none;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  border-bottom: 1px solid transparent;
}
.masthead a:hover, .link:hover { border-bottom-color: var(--ink); }

/* Studio grid */
.studio {
  display: grid;
  grid-template-columns: 360px 1fr;
  height: calc(100% - var(--masthead));
}

.panel {
  border-right: 1px solid var(--rule);
  overflow-y: auto;
  padding: 22px 28px 40px;
}

.block { margin: 0 0 22px; }
.block.row { display: flex; gap: 28px; align-items: flex-start; }

.caption {
  display: block;
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: normal;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

#formula {
  display: block;
  width: 100%;
  resize: vertical;
  min-height: 64px;
  padding: 10px 12px;
  font: 15px/1.5 var(--mono);
  background: var(--ink);
  color: var(--paper);
  border: 0;
  border-radius: 0;
  caret-color: var(--accent);
}
#formula:focus-visible { outline-offset: 3px; }

.error {
  margin: 6px 0 0;
  min-height: 0;
  font: 12px/1.45 var(--mono);
  color: var(--accent);
  white-space: pre-wrap;
}
.error:empty { display: none; }

/* Variables table */
.vars { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.vars th {
  font-size: 11px;
  font-weight: normal;
  color: var(--muted);
  text-align: left;
  padding: 0 6px 4px 0;
  letter-spacing: 0.06em;
}
.vars td { padding: 3px 6px 3px 0; border-top: 1px solid var(--rule); }
.vars tr:first-child td { border-top: 1px solid var(--ink); }
.vars td.name { font: italic 15px var(--ui); width: 64px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 64px; }
.vars tr.output td.name { color: var(--accent); }
.vars input {
  width: 100%;
  min-width: 0;
  padding: 4px 2px;
  border: 0;
  border-bottom: 1px solid transparent;
  background: transparent;
  font: 14px var(--mono);
  font-variant-numeric: tabular-nums;
  border-radius: 0;
}
.vars input:hover { border-bottom-color: var(--rule); }
.vars input:focus { border-bottom-color: var(--ink); outline: none; }
.vars input[aria-invalid="true"] { border-bottom-color: var(--accent); color: var(--accent); }
.vars .computed { font: 13px var(--mono); color: var(--muted); padding-left: 2px; }

/* Layout and tolerance */
.layout { border: 0; margin: 0; padding: 0; }
.layout legend { padding: 0; }
.layout label { display: block; font-size: 13px; cursor: pointer; }
.layout input { accent-color: var(--ink); margin: 0 6px 0 0; vertical-align: -1px; }
.layout label.disabled { color: var(--rule); cursor: default; }
.tolerance input {
  width: 72px;
  padding: 4px 2px;
  border: 0;
  border-bottom: 1px solid var(--ink);
  background: transparent;
  font: 14px var(--mono);
  border-radius: 0;
}

.certificate { margin: 0; font-size: 13px; line-height: 1.55; }
.method { margin: 4px 0 0; font-size: 11.5px; color: var(--muted); }

/* Buttons */
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions button {
  padding: 7px 12px;
  background: transparent;
  border: 1px solid var(--ink);
  border-radius: 0;
  font-size: 13px;
  cursor: pointer;
}
.actions button:hover { background: var(--ink); color: var(--paper); }

/* Examples */
.examples { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--ink); }
.examples li { border-bottom: 1px solid var(--rule); }
.examples button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 0;
  background: none;
  border: 0;
  cursor: pointer;
}
.examples .ex-name { display: block; font-size: 13px; }
.examples .ex-formula { display: block; font: 12px var(--mono); color: var(--muted); }
.examples button:hover .ex-name, .examples button[aria-current="true"] .ex-name { color: var(--accent); }

/* Desk and sheet */
.desk {
  background: var(--desk);
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: auto;
  padding: 20px 20px 12px;
  min-width: 0;
}
.sheet-frame {
  position: relative;
  flex: none;
  background: var(--sheet);
  outline: 1px solid var(--rule);
}
.sheet-holder, .sheet-holder svg, .overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.overlay { touch-action: none; overflow: visible; }
.sheet-holder .empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 15%;
  font: 13px/1.6 var(--mono);
  color: var(--muted);
  text-align: center;
  white-space: pre-wrap;
}

/* Straightedge */
.se-line { stroke: var(--accent); stroke-width: 0.35; }
.se-line.off { stroke-dasharray: 1.6 1.2; }
.se-handle { cursor: grab; }
.se-handle:active { cursor: grabbing; }
.se-handle .hit { fill: transparent; stroke: none; }
.se-handle .ring { fill: var(--sheet); stroke: var(--accent); stroke-width: 0.45; }
.se-handle.solved .ring { fill: var(--accent); }
.se-handle.out .ring { fill: var(--sheet); stroke-dasharray: 0.8 0.6; }
.se-handle:focus { outline: none; }
.se-handle:focus-visible .ring { stroke-width: 0.9; }
.se-tag { font: 3.1px var(--ui); fill: var(--accent); paint-order: stroke; stroke: var(--sheet); stroke-width: 0.8; stroke-linejoin: round; font-variant-numeric: tabular-nums; }

/* Readout */
.readout { width: 100%; max-width: 760px; text-align: center; padding-top: 12px; }
.reading {
  margin: 0;
  font: 17px/1.4 var(--mono);
  font-variant-numeric: tabular-nums;
  white-space: pre;
}
.reading .solved { color: var(--accent); }
.reading .arrow { color: var(--muted); }
.verify { margin: 2px 0 0; font: 11.5px var(--mono); color: var(--muted); }

/* How it works */
dialog {
  max-width: 560px;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: var(--paper);
  color: var(--ink);
  padding: 28px 32px 22px;
}
dialog::backdrop { background: rgba(31, 30, 28, 0.25); }
dialog h2 { margin: 0 0 12px; font-size: 13px; font-weight: normal; letter-spacing: 0.16em; text-transform: uppercase; }
dialog p { margin: 0 0 10px; font-size: 14px; line-height: 1.65; }
dialog button { margin-top: 8px; padding: 6px 14px; background: none; border: 1px solid var(--ink); border-radius: 0; cursor: pointer; }

/* Narrow screens: panel above the sheet */
@media (max-width: 1023px) {
  .studio { grid-template-columns: 1fr; height: auto; }
  .panel { border-right: 0; border-bottom: 1px solid var(--rule); }
  .desk { overflow: visible; padding: 12px; }
}

/* Phones: keep the masthead on one row */
@media (max-width: 599px) {
  .masthead { padding: 0 16px; }
  .subtitle { display: none; }
  .masthead nav { gap: 14px; }
  .masthead nav a, .masthead nav .link { white-space: nowrap; }
}

/* Print: the sheet alone, at true scale */
@media print {
  @page { size: A4 portrait; margin: 0; }
  html, body { background: #fff; height: auto; }
  .masthead, .panel, .readout, .overlay, dialog { display: none !important; }
  .studio { display: block; height: auto; }
  .desk { display: block; padding: 0; background: #fff; overflow: visible; }
  .sheet-frame { width: 210mm !important; height: 297mm !important; outline: 0; margin: 0; }
  .sheet-holder svg { width: 210mm; height: 297mm; }
}
