:root {
  color-scheme: light;
  --page: #eee9df;
  --paper: #f8f4eb;
  --ink: #172a2d;
  --muted: #657274;
  --line: #cfc8ba;
  --accent: #a94731;
  --accent-soft: #ead8ca;
  --stage: #10292d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
select,
input {
  font: inherit;
}

button,
select,
a {
  -webkit-tap-highlight-color: transparent;
}

.page-header,
.tiling-main {
  width: min(1440px, calc(100% - 40px));
  margin-inline: auto;
}

.page-header {
  padding: 24px 0 20px;
}

.page-nav {
  display: flex;
  gap: 9px;
  align-items: center;
  margin-bottom: 22px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.page-nav a {
  color: var(--ink);
  text-decoration: none;
}

.page-nav a:hover {
  color: var(--accent);
}

.header-copy {
  display: grid;
  grid-template-columns: minmax(300px, 0.9fr) minmax(320px, 1.1fr);
  gap: 40px;
  align-items: end;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(38px, 5.4vw, 72px);
  font-weight: 400;
  line-height: 0.92;
  letter-spacing: -0.045em;
}

.lede {
  max-width: 720px;
  margin: 0;
  color: var(--muted);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(16px, 1.7vw, 21px);
  line-height: 1.35;
}

.tiling-main {
  padding-bottom: 42px;
}

.tiling-stage {
  position: relative;
  min-height: 600px;
  overflow: hidden;
  border: 1px solid #2d3c3c;
  border-radius: 4px;
  background: var(--stage);
  box-shadow: 0 20px 60px rgba(30, 35, 32, 0.14);
}

#tilingCanvas {
  display: block;
  width: 100%;
  height: min(72vh, 820px);
  min-height: 600px;
  cursor: crosshair;
  touch-action: none;
}

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

.model-switch,
.view-tools,
.journey-status,
.interaction-hint {
  position: absolute;
  z-index: 2;
}

.model-switch {
  top: 16px;
  left: 16px;
  display: flex;
  gap: 3px;
  padding: 4px;
  border: 1px solid rgba(238, 233, 223, 0.34);
  border-radius: 4px;
  background: rgba(12, 34, 38, 0.84);
  backdrop-filter: blur(12px);
}

.model-button,
.view-tools button {
  min-height: 34px;
  border: 0;
  border-radius: 2px;
  color: #dce5df;
  background: transparent;
  cursor: pointer;
}

.model-button {
  padding: 0 13px;
  font-size: 12px;
  font-weight: 700;
}

.model-button:hover,
.view-tools button:hover {
  background: rgba(248, 244, 235, 0.12);
}

.model-button.is-active {
  background: var(--paper);
  color: var(--ink);
}

.view-tools {
  top: 16px;
  right: 16px;
  display: flex;
  gap: 13px;
  align-items: end;
  padding: 8px;
  border: 1px solid rgba(238, 233, 223, 0.34);
  border-radius: 4px;
  background: rgba(12, 34, 38, 0.84);
  color: #dce5df;
  backdrop-filter: blur(12px);
}

.control-field,
.edge-field {
  display: grid;
  gap: 4px;
  color: #b8c5c2;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.control-field select {
  min-width: 150px;
  min-height: 34px;
  border: 1px solid rgba(238, 233, 223, 0.3);
  border-radius: 2px;
  background: #17383c;
  color: #f2eee5;
  padding: 0 28px 0 9px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
}

.family-field select {
  min-width: 184px;
}

.edge-field {
  min-width: 128px;
}

.edge-field span {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.edge-field output {
  color: #f2eee5;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
}

.edge-field input {
  width: 128px;
  height: 34px;
  margin: 0;
  accent-color: #ead8ca;
  cursor: pointer;
}

.button-row {
  display: flex;
  gap: 3px;
}

.view-tools button {
  min-width: 34px;
  padding: 0 9px;
  border: 1px solid rgba(238, 233, 223, 0.26);
  font-size: 17px;
  font-weight: 700;
}

.view-tools .reset-button {
  min-width: 58px;
  font-size: 11px;
  text-transform: uppercase;
}

.journey-status {
  left: 16px;
  bottom: 16px;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid rgba(238, 233, 223, 0.25);
  border-radius: 3px;
  background: rgba(12, 34, 38, 0.8);
  color: #e7e1d6;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(10px);
}

.journey-status sup {
  font-size: 8px;
}

.status-rule {
  width: 18px;
  height: 1px;
  background: rgba(238, 233, 223, 0.45);
}

.interaction-hint {
  right: 18px;
  bottom: 18px;
  margin: 0;
  color: rgba(240, 235, 224, 0.78);
  font-size: 11px;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.55);
}

.error-message {
  position: absolute;
  inset: 50% auto auto 50%;
  width: min(420px, calc(100% - 40px));
  transform: translate(-50%, -50%);
  border: 1px solid #d88973;
  background: var(--paper);
  color: #7e2f22;
  padding: 16px;
  text-align: center;
}

.design-studio {
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.design-studio > summary {
  display: flex;
  min-height: 76px;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 22px;
  cursor: pointer;
  list-style: none;
}

.design-studio > summary::-webkit-details-marker {
  display: none;
}

.design-studio > summary span:first-child {
  display: grid;
  gap: 3px;
}

.design-studio > summary strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 22px;
  font-weight: 400;
}

.design-studio > summary small {
  color: var(--muted);
  font-size: 12px;
}

.studio-summary-action {
  flex: 0 0 auto;
  border-bottom: 1px solid currentColor;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.design-studio[open] .studio-summary-action::after {
  content: " · close";
  color: var(--muted);
}

.studio-layout {
  display: grid;
  grid-template-columns: minmax(300px, 0.85fr) minmax(420px, 1.15fr);
  gap: 34px;
  border-top: 1px solid var(--line);
  padding: 26px 22px 30px;
}

.motif-workbench {
  min-width: 0;
}

.studio-section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
}

.studio-kicker {
  margin: 0 0 2px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.studio-section-heading h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 24px;
  font-weight: 400;
}

.shape-count {
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

#motifEditor {
  display: block;
  width: min(100%, 520px);
  aspect-ratio: 1;
  border: 1px solid #394c4e;
  background: #10292d;
  cursor: crosshair;
  touch-action: none;
}

.motif-editor-background {
  fill: #10292d;
}

.source-cell-fill {
  fill: #17383c;
}

.motif-editor-grid path {
  stroke: rgba(239, 224, 191, 0.11);
  stroke-width: 0.3;
}

.source-cell-axis {
  fill: none;
  stroke: rgba(248, 244, 235, 0.72);
  stroke-width: 0.8;
  vector-effect: non-scaling-stroke;
}

.motif-shape {
  cursor: grab;
  stroke: rgba(248, 244, 235, 0.35);
  stroke-width: 0.6;
  vector-effect: non-scaling-stroke;
}

.motif-shape.is-selected {
  stroke: #f8f4eb;
  stroke-width: 1.6;
}

.motif-shape.is-dragging {
  cursor: grabbing;
}

.shape-actions,
.studio-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.shape-actions {
  margin-top: 10px;
}

.shape-actions button,
.studio-actions button,
.file-action {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: transparent;
  color: var(--ink);
  padding: 0 11px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 750;
}

.shape-actions button:hover,
.studio-actions button:hover,
.file-action:hover {
  border-color: var(--ink);
}

.shape-actions button:disabled,
.studio-actions button:disabled {
  opacity: 0.42;
  cursor: default;
}

.shape-actions .danger-button {
  color: #8e3828;
}

.design-form {
  display: grid;
  min-width: 0;
  gap: 22px;
}

.design-form fieldset {
  display: grid;
  min-width: 0;
  gap: 12px;
  margin: 0;
  border: 0;
  border-top: 1px solid var(--line);
  padding: 13px 0 0;
}

.design-form legend {
  padding: 0 10px 0 0;
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 18px;
}

.fieldset-note {
  margin: -5px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.studio-field,
.color-field,
.studio-range {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.studio-field input,
.studio-field select {
  width: 100%;
  min-width: 0;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: #fffdf7;
  color: var(--ink);
  padding: 0 9px;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0;
  text-transform: none;
}

.palette-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(58px, 1fr));
  gap: 8px;
}

.color-field input {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: transparent;
  padding: 3px;
  cursor: pointer;
}

.shape-fields,
.studio-range-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 11px 16px;
}

.studio-range span {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.studio-range output {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
}

.studio-range input {
  width: 100%;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.mapping-legend {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: -7px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 750;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

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

.studio-footer {
  display: grid;
  gap: 9px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.file-action {
  display: inline-flex;
  align-items: center;
}

.studio-actions .primary-action {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--paper);
}

.studio-actions .quiet-action {
  margin-left: auto;
  border-color: transparent;
  color: var(--muted);
}

.studio-status {
  min-height: 17px;
  margin: 0;
  color: var(--muted);
  font-size: 11px;
}

.studio-status.is-error {
  color: #8e3828;
}

.studio-license-note {
  margin: 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.45;
}

.model-note {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 28px;
  border-bottom: 1px solid var(--line);
  padding: 24px 4px 28px;
}

.model-note p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.model-note strong {
  color: var(--ink);
  font-weight: 750;
}

@media (max-width: 820px) {
  .page-header,
  .tiling-main {
    width: min(100% - 24px, 1440px);
  }

  .header-copy {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .tiling-stage,
  #tilingCanvas {
    min-height: 560px;
  }

  .view-tools {
    top: auto;
    left: 12px;
    right: 12px;
    bottom: 48px;
    flex-wrap: wrap;
  }

  .view-tools .control-field {
    flex: 1 1 170px;
  }

  .view-tools .edge-field {
    flex: 1 1 128px;
  }

  .interaction-hint {
    display: none;
  }

  .model-note {
    grid-template-columns: 1fr;
    gap: 12px;
  }

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

  #motifEditor {
    width: min(100%, 560px);
  }
}

@media (max-width: 520px) {
  .page-header {
    padding-top: 18px;
  }

  .page-nav {
    margin-bottom: 18px;
  }

  .model-switch {
    top: 10px;
    left: 10px;
    right: 10px;
  }

  .model-button {
    flex: 1;
  }

  .view-tools {
    left: 10px;
    right: 10px;
    bottom: 52px;
    flex-wrap: wrap;
    justify-content: space-between;
  }

  .control-field,
  .edge-field {
    flex: 1 0 100%;
  }

  .control-field select,
  .edge-field input {
    width: 100%;
    min-width: 0;
  }

  .button-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    width: 100%;
  }

  .view-tools button,
  .view-tools .reset-button {
    min-width: 0;
  }

  .journey-status {
    right: 10px;
    bottom: 10px;
    justify-content: center;
  }

  .design-studio > summary {
    align-items: start;
    padding-inline: 14px;
  }

  .studio-summary-action {
    margin-top: 5px;
  }

  .studio-layout {
    gap: 26px;
    padding: 22px 14px 26px;
  }

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

  .shape-range-grid,
  .studio-range-grid {
    grid-template-columns: 1fr;
  }

  .studio-actions .quiet-action {
    margin-left: 0;
  }
}
