/* Give the product configurator the first, full-width viewport on every design page. */
:root {
  --config-focus-header: 66px;
}

html {
  scroll-padding-top: var(--config-focus-header);
}

body {
  overflow-x: hidden;
}

body > header:first-child {
  position: sticky;
  top: 0;
  z-index: 30;
  min-height: var(--config-focus-header);
  background: color-mix(in srgb, var(--bg, #f7f4ec) 94%, transparent);
  backdrop-filter: blur(12px);
}

body > main {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
}

body > main > #configure {
  order: 0;
  width: 100%;
  max-width: none;
  min-height: calc(100svh - var(--config-focus-header));
  margin: 0;
  scroll-margin-top: var(--config-focus-header);
}

body > main > #configure.wrap {
  width: 100%;
  max-width: none;
  margin-inline: 0;
}

body > main > .hero,
body > main > .coaster-intro,
body > main > .box-intro {
  order: 1;
  width: min(1180px, calc(100% - 64px));
  margin-inline: auto;
}

body > main > section:not(#configure) {
  order: 2;
  width: min(1180px, calc(100% - 64px));
  margin-inline: auto;
}

/* Use the extra viewport height for the actual model instead of empty margins. */
@media (min-width: 781px) {
  body > main > #configure.box-builder,
  body > main > #configure.coaster-builder {
    display: flex;
    flex-direction: column;
    padding: 16px clamp(16px, 2.2vw, 32px) 20px;
  }

  .box-workspace,
  .coaster-workspace {
    flex: 1 1 auto;
    min-height: max(560px, calc(100svh - 230px));
  }

  .box-viewer,
  .coaster-viewer {
    display: flex;
    flex-direction: column;
  }

  .box-scene,
  .coaster-scene {
    flex: 1 1 auto;
    height: 100%;
    max-height: none;
    min-height: 480px;
  }

  body > main > #configure.section {
    display: flex;
    flex-direction: column;
    padding: 15px clamp(14px, 2vw, 28px) 20px;
  }

  #configure.section > .builder {
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    margin: 0;
    border-radius: 12px;
  }

  #configure.section > .builder > .diagram {
    min-height: 0;
  }

  #configure.section .preview-shell {
    height: clamp(500px, calc(100svh - 250px), 860px);
  }

  #configure.section .model-area {
    min-height: 0;
  }

  #configure.section .shop-floor {
    margin-bottom: 10px;
  }

  #configure .tray-builder {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-height: calc(100svh - var(--config-focus-header) - 35px);
    margin: 0;
    border-radius: 12px;
  }

  #configure .tray-workspace {
    flex: 1 1 auto;
    min-height: max(560px, calc(100svh - 220px));
  }

  #configure .tray-settings {
    max-height: none;
  }

  body > main > #configure.config {
    display: flex;
    flex-direction: column;
    min-height: calc(100svh - var(--config-focus-header));
  }

  #configure.config .work {
    flex: 1 1 auto;
    min-height: max(560px, calc(100svh - 150px));
  }

  #configure.config .viewer {
    min-height: 0;
  }

  #configure.config .model {
    min-height: 460px;
    max-height: none;
  }
}

@media (max-width: 780px) {
  :root {
    --config-focus-header: 60px;
  }

  body > main > #configure {
    padding-inline: 10px;
  }

  body > main > .hero,
  body > main > .coaster-intro,
  body > main > .box-intro,
  body > main > section:not(#configure) {
    width: calc(100% - 32px);
  }

  body > main > #configure.box-builder,
  body > main > #configure.coaster-builder {
    padding: 14px 10px 18px;
  }

  #configure .tray-builder,
  #configure.section > .builder {
    width: 100%;
    margin-inline: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}
