/* Colors come from the material: concrete, steel ink, a construction-yellow signal. */
:root {
  --concrete: #e6e9ec;
  --panel: #fbfbfc;
  --ink: #15222b;
  --ink-soft: #566772;
  --line: #dde2e6;
  --field-line: #c7ced4;
  --signal: #f0b90b;
  --signal-deep: #dca608;
  --rust: #b4502a;
  --alert: #b3261e;
  --bar-blue: #3366cc;
  --bar-purple: #7a4fb5;
}

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

body {
  font-family: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--concrete);
  -webkit-font-smoothing: antialiased;
}

main {
  display: grid;
  grid-template-columns: clamp(340px, 28vw, 420px) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

/* ---------- left: input and results ---------- */

.input {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 32px 28px 40px;
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.brand h1 {
  font-size: 21px;
  font-weight: 650;
  letter-spacing: -0.015em;
  line-height: 1.2;
}

.version {
  margin-left: 4px;
  padding: 2px 7px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0;
  vertical-align: middle;
  color: var(--ink-soft);
  background: rgba(21, 34, 43, 0.07);
  border-radius: 999px;
}

.version:empty {
  display: none;
}

.brand p {
  margin-top: 4px;
  font-size: 13.5px;
  color: var(--ink-soft);
}

form {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

fieldset {
  border: 0;
  min-width: 0;
}

fieldset + fieldset {
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

legend {
  padding: 0;
  margin-bottom: 12px;
  font-size: 13.5px;
  font-weight: 650;
}

.grid {
  display: grid;
  gap: 12px;
}

.grid + .grid {
  margin-top: 12px;
}

.grid-1 {
  grid-template-columns: 1fr;
}

.grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

/* an odd field out takes the whole row instead of leaving a gap */
.grid-2 > .field:last-child:nth-child(odd) {
  grid-column: span 2;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-soft);
}

.field-input {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 42px;
  padding: 0 12px;
  background: #fff;
  border: 1px solid var(--field-line);
  border-radius: 8px;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}

.field-input:hover {
  border-color: #9aa6af;
}

.field-input:focus-within {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(240, 185, 11, 0.4);
}

.field-input input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--ink);
  appearance: textfield;
  -moz-appearance: textfield;
}

.field-input select {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
}

.field-input input::-webkit-outer-spin-button,
.field-input input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.unit {
  font-size: 12.5px;
  color: var(--ink-soft);
}

/* the table where you fill in your own lap lengths */
.own-laps {
  margin-top: 14px;
}

.own-laps-note {
  margin-bottom: 8px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--ink-soft);
}

.lap-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.lap-table th {
  padding: 4px 6px 4px 0;
  font-size: 12px;
  font-weight: 500;
  text-align: left;
  color: var(--ink-soft);
}

.lap-table tbody th {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

.lap-table td {
  padding: 3px 6px 3px 0;
}

.lap-table input {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--field-line);
  border-radius: 6px;
  background: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--ink);
  appearance: textfield;
  -moz-appearance: textfield;
}

.lap-table input::-webkit-outer-spin-button,
.lap-table input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.lap-table input::placeholder {
  color: #aab3ba;
  font-weight: 500;
}

.lap-table input:focus {
  outline: 0;
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(240, 185, 11, 0.4);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* one row per bar group: name, count, diameter */
.bar-head,
.bar-row {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.bar-head {
  margin-bottom: 6px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-soft);
}

.bar-row + .bar-row {
  margin-top: 10px;
}

.bar-row-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  font-weight: 600;
}

/* same colors as the bars in the 3D view, so each name matches what you see */
.bar-row-name::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--bar-blue);
}

.bar-row-mid .bar-row-name::before {
  background: var(--bar-purple);
}

/* an empty field: the drawing keeps its last state until it has a value again */
.field-input.invalid {
  border-color: var(--alert);
  box-shadow: 0 0 0 3px rgba(179, 38, 30, 0.15);
}

.hint {
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--ink-soft);
}

/* ---------- results ---------- */

#summary {
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

#summary h2 {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

#summary h3 {
  margin: 18px 0 6px;
  font-size: 13.5px;
  font-weight: 650;
  color: var(--ink-soft);
}

/* headings of the bar groups: a dot in the color of those bars, then the sizes */
#summary h3.group {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}

#summary h3.group::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--bar-blue);
}

#summary h3.group-mid::before {
  background: var(--bar-purple);
}

#summary h3.group span {
  margin-left: auto;
  font-weight: 500;
  color: var(--ink-soft);
}

.bars {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.bars th {
  padding: 4px 0;
  font-size: 12px;
  font-weight: 500;
  text-align: left;
  color: var(--ink-soft);
}

.bars td {
  padding: 9px 0;
  border-top: 1px solid var(--line);
}

.bars .num {
  font-weight: 650;
  padding-right: 16px;
  white-space: nowrap;
}

.bars .note {
  text-align: right;
  font-size: 13px;
  color: var(--ink-soft);
}

.source {
  margin-top: 8px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--ink-soft);
}

.source a {
  color: inherit;
}

.side-label {
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--ink-soft);
}

/* shown when the first part was shortened to keep the end piece long enough */
.moved {
  margin-top: 6px;
  padding: 8px 10px;
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--ink-soft);
  background: rgba(240, 185, 11, 0.16);
  border-radius: 6px;
}

.facts {
  font-variant-numeric: tabular-nums;
}

.facts > div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  padding: 9px 0;
  border-top: 1px solid var(--line);
}

.facts dt {
  color: var(--ink-soft);
}

.facts dd {
  font-weight: 650;
  text-align: right;
}

.facts .total dt {
  color: var(--ink);
  font-weight: 600;
}

.facts .total dd {
  font-size: 19px;
  letter-spacing: -0.01em;
}

/* ---------- right: the two 3D views ---------- */

.output {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

canvas {
  display: block;
}

#viewer-close,
#viewer {
  position: relative;
  overflow: hidden;
  width: 100%;
}

/* close-up on top, the whole beam below */
#viewer-close {
  height: 38%;
  border-bottom: 1px solid #cdd3d8;
}

#viewer {
  flex: 1;
  min-height: 0;
}

#viewer-close::before,
#viewer::before {
  position: absolute;
  top: 14px;
  left: 16px;
  z-index: 1;
  padding: 4px 10px;
  font-size: 12.5px;
  font-weight: 550;
  color: var(--ink-soft);
  background: rgba(251, 251, 252, 0.85);
  border-radius: 6px;
}

#viewer-close::before {
  content: "Detail begin balk";
}

#viewer::before {
  content: "Overzicht";
}

/* labels floating in the 3D views */
.label {
  padding: 2px 7px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.94);
  border-radius: 5px;
  box-shadow: 0 1px 2px rgba(21, 34, 43, 0.2);
  white-space: nowrap;
}

.label.lap {
  color: var(--alert);
}

/* the middle bars are purple everywhere: bars, lengths and caption */
.label.flank {
  color: var(--bar-purple);
}

/* caption that says which bars a set of dimension lines belongs to */
.label.tag {
  font-weight: 650;
  color: var(--bar-blue);
}

.label.tag.flank {
  color: var(--bar-purple);
}

.label.stirrup {
  color: var(--rust);
}

/* ---------- narrow screens: stack ---------- */

@media (max-width: 900px) {
  main {
    display: block;
    height: auto;
  }

  .input {
    overflow: visible;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .output {
    height: 90vh;
    min-height: 560px;
  }
}
