:root {
  --paper: #f7f7f2;
  --field: #d8d8d4;
  --field-dark: #9a9b99;
  --ink: #111111;
  --muted: #5f5f5b;
  --line: #111111;
  --red: #f21823;
  --white: #ffffff;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--field);
  color: var(--ink);
  font-family: "Helvetica Neue", Arial, sans-serif;
  letter-spacing: 0;
  overscroll-behavior-x: none;
}

button,
input {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: 18px;
}

.workbench {
  display: grid;
  grid-template-columns: minmax(300px, 388px) minmax(0, 1fr);
  gap: 18px;
  max-width: 1480px;
  min-height: calc(100vh - 36px);
  margin: 0 auto;
}

.controls,
.preview-panel {
  border: 4px solid var(--line);
  border-radius: 0;
  background: var(--paper);
  box-shadow: 12px 12px 0 var(--ink);
}

.controls {
  align-self: stretch;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
}

.control-group {
  display: grid;
  gap: 8px;
}

.control-group label,
.swatch-label {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
  gap: 0;
  font-weight: 950;
  text-transform: uppercase;
}

.control-group label span,
.control-group output,
.swatch-label span {
  min-height: 34px;
  padding: 7px 9px;
  border: 3px solid var(--ink);
  background: var(--white);
  color: var(--ink);
  line-height: 1;
}

.control-group output {
  min-width: 86px;
  border-left: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.shape-group output {
  min-width: 118px;
}

.edge-group output {
  min-width: 122px;
}

.color-picker {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0;
  border: 4px solid var(--ink);
  background: var(--ink);
}

.color-swatch {
  min-width: 0;
  min-height: 38px;
  border: 0;
  border-right: 3px solid var(--ink);
  border-radius: 0;
  background: var(--swatch);
  cursor: pointer;
}

.color-swatch:last-child {
  border-right: 0;
}

.color-swatch:hover {
  filter: saturate(1.14) contrast(1.08);
}

.color-swatch.is-active {
  box-shadow: inset 0 0 0 5px var(--white), inset 0 0 0 8px var(--ink);
}

input[type="range"] {
  appearance: none;
  width: 100%;
  height: 18px;
  border: 3px solid var(--ink);
  border-radius: 0;
  background: var(--white);
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 10px;
  border-radius: 0;
  background: var(--white);
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 28px;
  height: 28px;
  margin-top: -9px;
  border: 3px solid var(--ink);
  border-radius: 0;
  background: var(--ink);
}

input[type="range"]::-moz-range-track {
  height: 10px;
  border: 0;
  border-radius: 0;
  background: var(--white);
}

input[type="range"]::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border: 3px solid var(--ink);
  border-radius: 0;
  background: var(--ink);
}

input[type="range"]:active,
input[type="range"]:focus-visible {
  border-color: var(--red);
}

input[type="range"]:active::-webkit-slider-thumb,
input[type="range"]:focus-visible::-webkit-slider-thumb {
  background: var(--red);
}

input[type="range"]:active::-moz-range-thumb,
input[type="range"]:focus-visible::-moz-range-thumb {
  background: var(--red);
}

.range-with-ends {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 950;
  line-height: 1;
  text-transform: uppercase;
}

.range-with-ends span:first-child {
  color: var(--ink);
}

.range-with-ends span:last-child {
  color: var(--ink);
}

.mode-button,
.primary-action,
.ghost-action,
.zoom-button {
  min-height: 46px;
  border: 0;
  border-radius: 0;
  cursor: pointer;
  font-weight: 950;
  text-transform: uppercase;
}

.mode-button {
  border-right: 3px solid var(--ink);
  background: var(--white);
  color: var(--ink);
}

.mode-button:last-child {
  border-right: 0;
}

.mode-button.is-active {
  background: var(--red);
  color: var(--white);
}

.action-row {
  display: grid;
  gap: 0;
  margin-top: auto;
  border: 4px solid var(--ink);
}

.primary-action {
  min-height: 54px;
  padding: 9px;
  font-size: 0.98rem;
}

.primary-action {
  background: var(--ink);
  color: var(--white);
}

.primary-action:hover,
.ghost-action:hover {
  filter: grayscale(0.18) contrast(1.12);
}

.ghost-action {
  border: 4px solid var(--ink);
  background: var(--white);
  color: var(--ink);
}

.preview-panel {
  position: relative;
  min-height: 600px;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(17, 17, 17, 0.08) 1px, transparent 1px),
    linear-gradient(0deg, rgba(17, 17, 17, 0.06) 1px, transparent 1px),
    var(--field);
  background-size: 48px 48px;
}

.preview-heading {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 3;
  display: grid;
  justify-items: end;
  gap: 6px;
  width: max-content;
  max-width: calc(100% - 36px);
}

.preview-title {
  margin: 0;
  width: max-content;
  max-width: 100%;
  color: var(--ink);
  font-size: clamp(1.45rem, 3vw, 2.75rem);
  line-height: 1;
  font-weight: 950;
  text-align: right;
  text-transform: lowercase;
  white-space: nowrap;
  pointer-events: none;
}

.preview-title span {
  display: inline-block;
  justify-self: end;
  max-width: 100%;
  padding: 6px 13px 13px;
  border: 4px solid var(--ink);
  background: var(--white);
}

.source-link {
  position: absolute;
  top: 100px;
  right: 18px;
  z-index: 3;
  display: block;
  max-width: 100%;
  color: var(--ink);
  font-size: 0.68rem;
  font-weight: 850;
  line-height: 1.2;
  text-align: right;
  text-decoration: none;
  text-transform: uppercase;
}

.source-link:hover {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.view-toggle {
  position: absolute;
  left: 18px;
  bottom: 18px;
  z-index: 3;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  width: min(260px, calc(100% - 36px));
  border: 4px solid var(--ink);
  background: var(--white);
}

.view-toggle .mode-button {
  min-height: 42px;
  padding: 6px 8px;
  font-size: 0.85rem;
  text-transform: none;
}

.zoom-controls {
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 3;
  display: grid;
  width: 48px;
  border: 4px solid var(--ink);
  background: var(--white);
}

.zoom-button {
  width: 100%;
  min-height: 44px;
  background: var(--white);
  color: var(--ink);
  font-size: 1.8rem;
  line-height: 1;
}

.zoom-button:first-child {
  border-bottom: 3px solid var(--ink);
}

.zoom-button:hover {
  background: var(--ink);
  color: var(--white);
}

#meshCanvas {
  position: relative;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  min-height: 600px;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

#meshCanvas.is-dragging {
  cursor: grabbing;
}

@media (max-width: 860px) {
  body {
    background: var(--paper);
  }

  .app-shell {
    min-height: 100svh;
    padding: 0;
    overflow-x: hidden;
  }

  .workbench {
    grid-template-columns: 1fr;
    gap: 0;
    width: 100%;
    min-height: 100svh;
  }

  .controls,
  .preview-panel {
    border-width: 3px;
    box-shadow: none;
  }

  .controls {
    order: 2;
    gap: 12px;
    padding: 12px;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
  }

  .preview-panel {
    order: 1;
    height: clamp(430px, 58svh, 620px);
    min-height: 430px;
    border-top: 0;
    border-right: 0;
    border-left: 0;
  }

  #meshCanvas {
    height: 100%;
    min-height: 0;
  }

  .control-group label span,
  .control-group output,
  .swatch-label span {
    border-width: 3px;
    min-height: 32px;
    padding: 7px 8px;
    font-size: 0.86rem;
  }

  .control-group output {
    min-width: 80px;
  }

  .shape-group output {
    min-width: 108px;
  }

  .edge-group output {
    min-width: 116px;
  }

  .preview-heading {
    top: 12px;
    right: 12px;
    left: 12px;
    justify-items: center;
    width: auto;
    max-width: calc(100% - 24px);
    gap: 4px;
  }

  .preview-title {
    width: auto;
    font-size: clamp(1.35rem, 6.2vw, 1.85rem);
    text-align: center;
  }

  .preview-title span {
    border-width: 3px;
    padding: 6px 12px 11px;
  }

  .source-link {
    top: auto;
    right: 12px;
    bottom: 8px;
    left: 12px;
    font-size: 0.56rem;
    text-align: center;
  }

  .view-toggle {
    left: 12px;
    bottom: 34px;
    width: min(232px, calc(100% - 84px));
    border-width: 3px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .view-toggle .mode-button {
    border-right: 3px solid var(--ink);
    border-bottom: 0;
  }

  .view-toggle .mode-button:last-child {
    border-right: 0;
  }

  .view-toggle .mode-button {
    min-height: 40px;
    padding: 5px 6px;
    font-size: 0.78rem;
  }

  .zoom-controls {
    right: 12px;
    bottom: 34px;
    width: 42px;
    border-width: 3px;
  }

  .zoom-button {
    min-height: 40px;
    font-size: 1.45rem;
  }

  .color-swatch {
    min-height: 42px;
  }

  .action-row {
    margin-top: 2px;
    border-width: 3px;
  }

  .primary-action,
  .ghost-action {
    min-height: 50px;
  }
}

@media (max-width: 420px) {
  .preview-panel {
    height: 56svh;
    min-height: 390px;
  }

  .preview-title {
    font-size: clamp(1.18rem, 5.9vw, 1.45rem);
  }

  .source-link {
    bottom: 8px;
    font-size: 0.52rem;
  }

  .controls {
    gap: 10px;
    padding: 10px;
  }

  .control-group {
    gap: 6px;
  }

  .control-group label span,
  .control-group output,
  .swatch-label span {
    font-size: 0.8rem;
  }

  .view-toggle {
    width: min(214px, calc(100% - 78px));
  }

  .view-toggle .mode-button {
    font-size: 0.72rem;
  }
}
