:root {
  --cyan: #0E3B6E;
  --cyan-deep: #092A52;
  --cell: #0C3463;
  --paper: #EAF2FB;
  --wash: #A9C1DD;
  --rule: rgba(234, 242, 251, .42);
  --grid-minor: rgba(234, 242, 251, .05);
  --grid-major: rgba(234, 242, 251, .1);
  --redline: #FF6A55;

  --frame: 28px;
  --gutter: clamp(20px, 3vw, 40px);

  --sans: "Archivo", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Martian Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;

  color-scheme: dark;
}

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

html { background: var(--cyan-deep); }

body {
  position: relative;
  margin: 0;
  padding: var(--frame);
  min-height: 100dvh;
  overflow-x: hidden;
  color: var(--paper);
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  background-color: var(--cyan);
  background-image:
    radial-gradient(130% 95% at 50% 38%, transparent 50%, rgba(4, 22, 46, .6) 100%),
    linear-gradient(var(--grid-major) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-major) 1px, transparent 1px),
    linear-gradient(var(--grid-minor) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-minor) 1px, transparent 1px);
  background-size: 100% 100%, 80px 80px, 80px 80px, 16px 16px, 16px 16px;
  background-position: 0 0, var(--frame) var(--frame), var(--frame) var(--frame), var(--frame) var(--frame), var(--frame) var(--frame);
}

/* Cyanotype mottling + paper grain */
body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}
body::before {
  opacity: .5;
  mix-blend-mode: soft-light;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='900' height='900'%3E%3Cfilter id='m'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.004' numOctaves='3' seed='7'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 .9 -.25'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23m)'/%3E%3C/svg%3E");
  background-size: 900px 900px;
}
body::after {
  opacity: .16;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

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

/* ---------- Sheet frame & zone markers ---------- */

.frame {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: calc(100dvh - 2 * var(--frame));
  padding: var(--gutter);
  border: 1px solid var(--rule);
  outline: 1px solid rgba(234, 242, 251, .16);
  outline-offset: 5px;
  overflow: hidden;
}

.zones {
  position: absolute;
  z-index: 1;
  display: flex;
  color: var(--wash);
  font: 500 10px/1 var(--mono);
  pointer-events: none;
  user-select: none;
}
.zones span {
  position: relative;
  display: grid;
  flex: 1;
  place-items: center;
}
.zones--x {
  top: 0;
  left: var(--frame);
  right: var(--frame);
  height: calc(var(--frame) - 6px);
}
.zones--x span + span::before {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 1px;
  height: 7px;
  background: var(--rule);
}
.zones--y {
  top: var(--frame);
  bottom: var(--frame);
  left: 0;
  width: calc(var(--frame) - 6px);
  flex-direction: column;
}
.zones--y span + span::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 7px;
  height: 1px;
  background: var(--rule);
}

/* ---------- Language switch ---------- */

.bar {
  display: flex;
  justify-content: flex-end;
}
.lang {
  display: inline-flex;
  border: 1px solid var(--rule);
}
.lang button {
  appearance: none;
  min-width: 46px;
  min-height: 40px;
  padding: 0 12px;
  border: 0;
  background: none;
  color: var(--wash);
  font: 500 12px/1 var(--mono);
  letter-spacing: .04em;
  cursor: pointer;
}
.lang button + button { border-left: 1px solid var(--rule); }
.lang button:hover { color: var(--paper); }
.lang button[aria-pressed="true"] {
  background: var(--paper);
  color: var(--cyan);
}

/* ---------- Drawing ---------- */

.drawing {
  align-self: center;
  width: 100%;
  /* Keep the drawing short enough that the note fits on screen too. */
  max-width: max(560px, min(1180px, (100dvh - 400px) * 3.2));
  margin: 0 auto;
  padding-block: clamp(8px, 2.5vh, 32px);
}

.plan {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}
.js:not(.ready) .plan { visibility: hidden; }

.glyph text {
  font-family: var(--sans);
  font-size: 300px;
  font-weight: 900;
  font-variation-settings: "wdth" 125;
}
.glyph-fill { fill: url(#hatch); }
.glyph-line {
  fill: none;
  stroke: var(--paper);
  stroke-width: 1.6;
  stroke-linejoin: round;
}
.glyph.is-hot .glyph-line {
  stroke: var(--redline);
  stroke-dasharray: var(--sel-dash, 9 6);
}
.hit {
  fill: transparent;
  pointer-events: all;
  cursor: pointer;
}

.hatch-bg { fill: var(--paper); fill-opacity: .07; }
.hatch-line { stroke: var(--paper); stroke-opacity: .72; stroke-width: 1.6; }

.cl {
  stroke: var(--paper);
  stroke-opacity: .26;
  stroke-width: 1;
}
.cl--center {
  stroke-opacity: .2;
  stroke-dasharray: 22 6 3 6;
}
.cl--v { stroke-opacity: .16; }

.dim-ext,
.dim-line {
  stroke: var(--paper);
  stroke-opacity: .62;
  stroke-width: 1;
}
.dim-tick {
  stroke: var(--paper);
  stroke-width: 1.75;
}
.dim-label {
  fill: var(--paper);
  font-family: var(--mono);
  font-weight: 500;
}
.dim--hot .dim-ext,
.dim--hot .dim-line,
.dim--hot .dim-tick {
  stroke: var(--redline);
  stroke-opacity: 1;
}
.dim--hot .dim-label { fill: var(--redline); }

.datum circle,
.datum line {
  fill: none;
  stroke: var(--paper);
  stroke-opacity: .75;
  stroke-width: 1;
}

/* ---------- Note ---------- */

.note {
  padding-left: var(--indent, 11.3%);
  margin-top: clamp(4px, 1.5vh, 20px);
}
.note h1 {
  max-width: 22ch;
  margin: 0 0 .45em;
  font-size: clamp(1.75rem, 1.05rem + 2.5vw, 3.25rem);
  font-weight: 650;
  font-variation-settings: "wdth" 112;
  line-height: 1.08;
  letter-spacing: -.012em;
  text-wrap: balance;
}
.note p {
  max-width: 44ch;
  margin: 0;
  color: var(--wash);
  font-size: clamp(1rem, .95rem + .25vw, 1.1875rem);
}
.note .hint {
  display: none;
  margin-top: 1.1rem;
  font-size: .875rem;
  opacity: .8;
}
@media (hover: hover) and (pointer: fine) {
  .note .hint { display: block; }
}

/* ---------- Title block ---------- */

.titleblock {
  align-self: end;
  justify-self: end;
  width: min(100%, 372px);
  margin: 24px calc(-1 * var(--gutter)) calc(-1 * var(--gutter)) 0;
  border-top: 1px solid var(--rule);
  border-left: 1px solid var(--rule);
  background: var(--rule);
}
.titleblock dl {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  margin: 0;
}
.tb-cell {
  min-width: 0;
  padding: 8px 12px 10px;
  background: var(--cell);
}
.tb-wide { grid-column: 1 / -1; }
.titleblock dt {
  color: var(--wash);
  font-size: .6875rem;
  line-height: 1.3;
}
.titleblock dd {
  margin: 2px 0 0;
  font: 500 .8125rem/1.35 var(--mono);
}
.titleblock .tb-project {
  font: 700 1.375rem/1.15 var(--sans);
  font-variation-settings: "wdth" 125;
  letter-spacing: -.01em;
}
.tb-status {
  display: flex;
  align-items: center;
  gap: 9px;
}
.titleblock .tb-status { font-family: var(--sans); font-size: .9375rem; font-weight: 600; }
.redline-dot {
  width: 9px;
  height: 9px;
  flex: none;
  border-radius: 50%;
  background: var(--redline);
  box-shadow: 0 0 0 3px rgba(255, 106, 85, .22);
}
.tb-rev {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 20px;
}
.tb-rev svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  fill: none;
  stroke: var(--redline);
  stroke-width: 1.4;
}
.tb-rev span {
  position: relative;
  top: 2px;
  color: var(--redline);
  font-size: .625rem;
}

/* ---------- Intro states (only when app.js runs the sequence) ---------- */

.intro .note,
.intro .titleblock,
.intro .dims {
  opacity: 0;
}
.intro.show-note .note,
.intro.show-note .titleblock,
.intro.show-dims .dims {
  opacity: 1;
  transition: opacity .7s ease;
}
.intro.show-note .titleblock { transition-delay: .5s; }

/* ---------- CAD crosshair ---------- */

.crosshair {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: none;
  pointer-events: none;
}
.has-crosshair .crosshair { display: block; }
.has-crosshair body,
.has-crosshair .hit { cursor: none; }
.has-crosshair button { cursor: pointer; }
.crosshair.is-hidden { opacity: 0; }

.ch-h,
.ch-v {
  position: absolute;
  background: rgba(234, 242, 251, .3);
}
.ch-h {
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  transform: translateY(var(--y, -20px));
}
.ch-v {
  top: 0;
  bottom: 0;
  left: 0;
  width: 1px;
  transform: translateX(var(--x, -20px));
}
.ch-box {
  position: absolute;
  top: 0;
  left: 0;
  width: 13px;
  height: 13px;
  border: 1px solid var(--paper);
  /* `translate` (not `transform`) so the snap `scale` stays centred on the cursor */
  translate: calc(var(--x, -20px) - 6px) calc(var(--y, -20px) - 6px);
  transition: scale .15s ease, border-color .15s ease;
}
.crosshair.is-snap .ch-box {
  border-color: var(--redline);
  scale: 1.45;
}
.ch-read {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  gap: 12px;
  padding: 6px 8px;
  border: 1px solid var(--rule);
  background: rgba(9, 42, 82, .88);
  color: var(--wash);
  font: 400 11px/1 var(--mono);
  white-space: nowrap;
  transform: translate(calc(var(--x, -200px) + 16px), calc(var(--y, -200px) + 16px));
}
.ch-read b {
  color: var(--paper);
  font-weight: 500;
}
.crosshair.flip-x .ch-read {
  transform: translate(calc(var(--x) - 16px - 100%), calc(var(--y) + 16px));
}

/* Wide sheets: the title block sits in the corner, out of the content flow. */
@media (min-width: 1200px) and (min-height: 600px) {
  .frame { grid-template-rows: auto 1fr; }
  .titleblock {
    position: absolute;
    right: 0;
    bottom: 0;
    margin: 0;
  }
}

/* ---------- Small screens ---------- */

@media (max-width: 640px) {
  :root { --frame: 10px; --gutter: 18px; }
  .zones { display: none; }
  .frame { outline-offset: 3px; }
  .titleblock {
    justify-self: stretch;
    width: auto;
    margin: 28px calc(-1 * var(--gutter)) calc(-1 * var(--gutter));
    border-left: 0;
  }
  .note { padding-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .ch-box { transition: none; }
}
