:root {
  background: #fff;
}

html,
body,
#root {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  margin: 0;
}

body {
  overflow: hidden;
  background: #fff;
}

.app-shell {
  width: 100%;
  height: 100%;
  min-height: 0;
  grid-template-columns: clamp(280px, 24vw, 330px) minmax(0, 1fr);
  overflow: hidden;
  background: #fff;
}

.control-panel {
  min-width: 0;
  min-height: 0;
  gap: 0.78rem;
  border-right: 0;
  background: #fff;
  padding: 1.25rem 1.1rem;
  scrollbar-color: rgba(31, 47, 72, 0.2) transparent;
}

.panel-kicker {
  color: #ec1885;
  font-size: 0.68rem;
  font-weight: 800;
}

.control-panel h1 {
  color: #171717;
  font-family: "Avenir Next", "Montserrat", sans-serif;
  font-size: clamp(1.45rem, 2vw, 1.8rem);
  font-weight: 800;
  line-height: 1.05;
}

.panel-copy {
  color: #647083;
  font-size: 0.82rem;
  line-height: 1.4;
}

.size-list {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
}

.size-list > .color-label {
  grid-column: 1 / -1;
  width: 100%;
}

.size-list > .size-option {
  width: 100%;
}

.size-option {
  min-width: 0;
  min-height: 44px;
  border-color: rgba(31, 47, 72, 0.14);
  border-radius: 0.75rem;
  padding: 0.66rem 0.72rem;
}

.size-option.is-active {
  border-color: #ec1885;
  background: #fff2f8;
  box-shadow: 0 0 0 2px rgba(236, 24, 133, 0.09);
}

.size-option strong {
  color: #171717;
  font-size: 0.88rem;
  line-height: 1.15;
}

.size-option span {
  color: #647083;
  font-size: 0.68rem;
  line-height: 1.2;
}

.color-group {
  gap: 0.65rem;
  padding-top: 0.9rem;
  border-top: 1px solid #f0e9ed;
  flex-shrink: 0;
}

.control-panel > .size-list {
  flex-shrink: 0;
}

.thickness-list {
  padding-top: 0.75rem;
}

.control-panel button:focus-visible {
  outline: 2px solid #1f2f48;
  outline-offset: 3px;
}

.color-label,
.color-name {
  color: #1f2f48;
  font-size: 0.76rem;
}

.color-name {
  justify-self: start;
  padding: 3px 9px;
  border-radius: 999px;
  background: #fff2f8;
  font-weight: 500;
}

.color-label {
  font-weight: 700;
}

.color-swatches {
  flex-wrap: wrap;
  gap: 0.5rem;
}

.color-swatch {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  padding: 5px;
  position: relative;
}

.color-swatch.is-active {
  border-color: #ec1885;
  box-shadow: 0 0 0 2px rgba(236, 24, 133, 0.12);
}

.background-color-picker {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  padding: 5px;
  border: 1px solid #ec1885;
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
}

.background-color-picker::-webkit-color-swatch-wrapper {
  padding: 0;
}

.background-color-picker::-webkit-color-swatch {
  border: 1px solid #ddd;
  border-radius: 50%;
}

.background-color-picker::-moz-color-swatch {
  border: 1px solid #ddd;
  border-radius: 50%;
}

.background-color-picker:focus-visible {
  outline: 2px solid #1f2f48;
  outline-offset: 3px;
}

.color-swatch.is-active::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 0;
  width: 10px;
  height: 10px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: #ec1885;
}

.size-note {
  display: none;
}

.scene-panel {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #fff;
}

/* Fade the scene itself so controls remain sharp and interactive. */
.scene-panel::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background:
    linear-gradient(to right, #fff, rgba(255, 255, 255, 0.65) 25%, transparent) left / 44px 100% no-repeat,
    linear-gradient(to left, #fff, rgba(255, 255, 255, 0.65) 25%, transparent) right / 44px 100% no-repeat,
    linear-gradient(to bottom, #fff, rgba(255, 255, 255, 0.65) 25%, transparent) top / 100% 44px no-repeat,
    linear-gradient(to top, #fff, rgba(255, 255, 255, 0.65) 25%, transparent) bottom / 100% 44px no-repeat;
}

.scene-panel canvas {
  width: 100% !important;
  height: 100% !important;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(300px, 56%) minmax(0, 44%);
    height: 100%;
    min-height: 0;
  }

  .scene-panel {
    order: 1;
    height: 100%;
  }

  .control-panel {
    order: 2;
    height: 100%;
    max-height: none;
    gap: 0.6rem;
    overflow-x: hidden;
    overflow-y: auto;
    border: 0;
    border-top: 0;
    border-radius: 0;
    padding: 0.85rem 0.9rem max(0.9rem, env(safe-area-inset-bottom));
    box-shadow: none;
  }

  .panel-copy {
    display: none;
  }

  .control-panel h1 {
    font-size: 1.3rem;
  }

  .size-list {
    gap: 0.48rem;
  }

  .thickness-list {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 0.48rem;
  }

  .thickness-list > .color-label {
    flex: 0 0 100%;
  }

  .thickness-list > .size-option {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
  }

  .size-option {
    padding: 0.56rem 0.62rem;
  }

  .color-swatches {
    flex-wrap: wrap;
    padding: 3px;
  }
}

@media (max-width: 480px) {
  .scene-panel::after {
    background-size: 24px 100%, 24px 100%, 100% 28px, 100% 28px;
  }

  .app-shell {
    grid-template-rows: minmax(280px, 52%) minmax(0, 48%);
  }

  .control-panel {
    gap: 6px;
    padding: 8px 10px max(8px, env(safe-area-inset-bottom));
    overscroll-behavior-y: auto;
  }

  .panel-kicker {
    display: none;
  }

  .control-panel h1 {
    font-size: 1rem;
    line-height: 1.2;
    flex-shrink: 0;
  }

  .size-option {
    padding: 6px 10px;
    min-height: 44px;
    text-align: center;
  }

  .size-option strong {
    font-size: 0.85rem;
    margin: 0;
  }

  .size-option span {
    display: none;
  }

  .color-label,
  .color-name {
    font-size: 0.74rem;
    line-height: 1.3;
  }

  .color-group {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto auto;
    align-items: center;
    gap: 3px 8px;
    padding-top: 6px;
  }

  .color-label {
    grid-column: 1;
    grid-row: 1;
  }

  .color-name {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
    max-width: 100%;
    padding: 2px 6px;
    overflow-wrap: anywhere;
    text-align: right;
  }

  .color-swatches {
    grid-column: 1 / -1;
    grid-row: 2;
    gap: 4px;
    padding: 3px;
  }

  .color-swatch {
    width: 44px;
    height: 44px;
  }
}

/* One page scroll on phones: the host iframe follows this natural height. */
@media (max-width: 640px) {
  html, body, #root {
    height: auto;
  }

  .app-shell {
    height: auto;
    min-height: 0;
    grid-template-rows: clamp(280px, 80vw, 380px) auto;
  }

  .control-panel {
    height: auto;
    max-height: none;
    overflow: visible;
    touch-action: pan-y;
  }
}

@media (prefers-reduced-motion: reduce) {
  .control-panel button {
    transition: none;
  }
}
