:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #171717;
  background: #f2f1ee;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
}

button, input { font: inherit; }
button { color: inherit; }

.app-shell {
  width: min(1400px, calc(100% - 32px));
  margin: 32px auto;
}

.visualiser-card {
  padding: clamp(18px, 3vw, 36px);
  background: #fff;
  border: 1px solid #ddd9d1;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.08);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 4px;
  text-transform: uppercase;
  letter-spacing: .12em;
  font-size: 12px;
  color: #6c6a65;
}

h1 {
  margin: 0;
  font-size: clamp(24px, 3vw, 40px);
  line-height: 1.08;
}

.toolbar-actions {
  display: flex;
  gap: 10px;
}

.icon-button {
  width: 46px;
  height: 46px;
  display: inline-grid;
  place-items: center;
  border: 1px solid #d7d4cc;
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
  transition: transform .15s ease, background .15s ease;
}

.icon-button:hover {
  transform: translateY(-1px);
  background: #f7f6f3;
}

.icon-button.primary {
  color: #fff;
  background: #111;
  border-color: #111;
}

.icon-button svg {
  width: 21px;
  height: 21px;
  fill: currentColor;
}

.controls {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}

.custom-select {
  position: relative;
  width: min(520px, 100%);
}

.select-trigger {
  width: 100%;
  min-height: 72px;
  display: grid;
  grid-template-columns: 46px 1fr 24px;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  text-align: left;
  border: 1px solid #d7d4cc;
  border-radius: 14px;
  background: #fff;
  cursor: pointer;
}

.selected-swatch {
  width: 46px;
  height: 46px;
  border: 1px solid rgba(0,0,0,.14);
  border-radius: 9px;
}

.selected-copy {
  display: grid;
  gap: 2px;
}

.selected-copy strong { font-size: 16px; }
.selected-copy span {
  font-size: 14px;
  color: #6b6964;
}

.chevron {
  width: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
}

.select-panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  overflow: hidden;
  border: 1px solid #d7d4cc;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 18px 50px rgba(0,0,0,.14);
}

.search-wrap {
  display: block;
  padding: 12px;
  border-bottom: 1px solid #eceae5;
}

.search-wrap input {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid #d8d5ce;
  border-radius: 9px;
  outline: none;
}

.option-list {
  max-height: 340px;
  overflow-y: auto;
}

.colour-option {
  width: 100%;
  display: grid;
  grid-template-columns: 52px 1fr;
  align-items: stretch;
  min-height: 62px;
  padding: 0;
  border: 0;
  border-bottom: 1px solid rgba(0,0,0,.08);
  background: var(--option-colour);
  cursor: pointer;
  text-align: left;
}

.colour-option:hover,
.colour-option[aria-selected="true"] {
  outline: 3px solid rgba(255,255,255,.9);
  outline-offset: -5px;
}

.option-swatch { background: var(--option-colour); }

.option-copy {
  display: grid;
  align-content: center;
  padding: 9px 14px;
  background: linear-gradient(90deg, rgba(255,255,255,.86), rgba(255,255,255,.68));
  color: #111;
}

.option-copy strong { font-size: 14px; }
.option-copy span { font-size: 13px; }

.colour-meta {
  display: grid;
  gap: 4px;
  font-size: 13px;
  color: #6b6964;
}

#statusText { min-height: 1em; }

.canvas-frame {
  overflow: hidden;
  border-radius: 14px;
  border: 1px solid #d7d4cc;
}

.preview {
  position: relative;
  width: 100%;
  aspect-ratio: 2000 / 1320;
  background: #fff;
}

.preview img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  pointer-events: none;
}

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

@media (max-width: 700px) {
  .toolbar, .controls { align-items: stretch; }
  .toolbar { flex-direction: column; }
  .toolbar-actions { align-self: flex-end; }
  .controls { flex-direction: column; }
  .custom-select { width: 100%; }
}


.cube-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(12, 12, 12, .72);
  backdrop-filter: blur(8px);
}

.cube-modal[hidden] { display: none; }

.cube-dialog {
  width: min(980px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  padding: 22px;
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 30px 90px rgba(0,0,0,.34);
}

.cube-dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 14px;
}

.cube-dialog h2 { margin: 0; font-size: clamp(24px, 3vw, 34px); }
.cube-subtitle { margin: 6px 0 0; color: #6b6964; }

.cube-stage {
  position: relative;
  overflow: hidden;
  border: 1px solid #d7d4cc;
  border-radius: 16px;
  background: radial-gradient(circle at 50% 38%, #fafafa, #dfddd7);
}

#cubeScene {
  width: 100%;
  height: min(68vh, 650px);
  display: grid;
  place-items: center;
  perspective: 1100px;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

#cubeScene:active { cursor: grabbing; }

.css-cube {
  --cube-size: min(42vw, 360px);
  --half-cube: calc(var(--cube-size) / 2);
  position: relative;
  width: var(--cube-size);
  height: var(--cube-size);
  transform-style: preserve-3d;
  transform: rotateX(-24deg) rotateY(39deg);
  will-change: transform;
}

.cube-face {
  position: absolute;
  inset: 0;
  width: var(--cube-size);
  height: var(--cube-size);
  overflow: hidden;
  border: 1px solid rgba(0,0,0,.09);
  background-color: var(--cube-colour, #ffffff);
  background-image: url("texture.png");
  background-repeat: no-repeat;
  background-position: center center;
  background-size: auto 100%;
  backface-visibility: hidden;
}

/* Fixed face tones create depth without simulating a movable light source. */
.cube-face::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: rgba(var(--face-tone-rgb, 255,255,255), var(--face-tone-alpha, 0));
}

.cube-front  { transform: rotateY(0deg) translateZ(var(--half-cube)); --face-tone-rgb: 255,255,255; --face-tone-alpha: .012; }
.cube-back   { transform: rotateY(180deg) translateZ(var(--half-cube)); --face-tone-rgb: 0,0,0;       --face-tone-alpha: .028; }
.cube-right  { transform: rotateY(90deg) translateZ(var(--half-cube)); --face-tone-rgb: 0,0,0;       --face-tone-alpha: .045; }
.cube-left   { transform: rotateY(-90deg) translateZ(var(--half-cube)); --face-tone-rgb: 0,0,0;      --face-tone-alpha: .022; }
.cube-top    { transform: rotateX(90deg) translateZ(var(--half-cube)); --face-tone-rgb: 255,255,255; --face-tone-alpha: .035; }
.cube-bottom { transform: rotateX(-90deg) translateZ(var(--half-cube)); --face-tone-rgb: 0,0,0;      --face-tone-alpha: .055; }


.cube-hint {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  padding: 7px 11px;
  border-radius: 999px;
  background: rgba(255,255,255,.82);
  box-shadow: 0 4px 18px rgba(0,0,0,.12);
  font-size: 12px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .2s ease, visibility .2s ease;
}

.cube-hint.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

@media (max-width: 600px) {
  .cube-dialog { padding: 16px; }
}


.cube-view-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 18px;
}

.cube-control-button {
  min-width: 42px;
  height: 40px;
  padding: 0 13px;
  border: 1px solid #d7d4cc;
  border-radius: 999px;
  background: rgba(255,255,255,.94);
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
  box-shadow: 0 4px 16px rgba(0,0,0,.06);
}

.cube-control-button:hover:not(:disabled) { background: #f5f3ef; }
.cube-control-button:disabled { opacity: .35; cursor: default; }
.cube-control-button.cube-zoom-value { min-width: 72px; font-size: 13px; font-weight: 650; }
#cubeScene { touch-action: none; overflow: visible; }
.css-cube { transition: transform .12s ease-out; }
#cubeScene:active .css-cube { transition: none; }

/* Fullscreen 3D viewer: fills the viewport with safe spacing and never scrolls. */
.cube-modal {
  box-sizing: border-box;
  width: 100vw;
  height: 100dvh;
  min-height: 100vh;
  padding: clamp(12px, 2.5vw, 32px);
  overflow: hidden;
}

.cube-dialog {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding: clamp(14px, 2vw, 24px);
}

.cube-dialog-header {
  margin-bottom: clamp(10px, 1.5vh, 16px);
}

.cube-stage {
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#cubeScene {
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.css-cube {
  --cube-size: min(58vmin, 620px);
}

.cube-view-controls {
  position: absolute;
  z-index: 5;
  top: clamp(12px, 2vw, 20px);
  right: clamp(12px, 2vw, 20px);
  margin: 0;
}

.cube-hint {
  z-index: 5;
  bottom: clamp(10px, 1.8vw, 18px);
  white-space: nowrap;
}

body:has(.cube-modal:not([hidden])) {
  overflow: hidden;
}

@media (max-width: 700px) {
  .cube-modal { padding: 12px; }
  .cube-dialog { padding: 14px; border-radius: 16px; }
  .cube-dialog-header { padding-right: 0; }
  .cube-dialog h2 { font-size: 22px; }
  .cube-subtitle { font-size: 13px; }
  .css-cube { --cube-size: min(62vmin, 430px); }
  .cube-view-controls { top: 10px; right: 10px; }
  .cube-hint { max-width: calc(100% - 24px); text-align: center; }
}

@media (max-height: 620px) {
  .cube-modal { padding: 10px; }
  .cube-dialog { padding: 12px; }
  .cube-dialog-header { margin-bottom: 8px; }
  .cube-dialog h2 { font-size: 20px; }
  .cube-subtitle { margin-top: 2px; font-size: 12px; }
  .css-cube { --cube-size: min(52vmin, 420px); }
  .cube-hint { bottom: 8px; }
}


/* 3D viewer action buttons */
.cube-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.css-cube.is-auto-rotating {
  transition: none;
}

@media (max-width: 700px) {
  .cube-header-actions { gap: 6px; }
  .cube-header-actions .icon-button { width: 40px; height: 40px; }
}




/* Full-screen cube-stage toggle */
.cube-expand-button .close-icon { display: none; }
.cube-expand-button.is-expanded .expand-icon { display: none; }
.cube-expand-button.is-expanded .close-icon { display: block; }

.cube-stage-expand {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 12;
  background: rgba(255,255,255,.9);
  backdrop-filter: blur(8px);
}

html.cube-expanded,
body.cube-expanded {
  overflow: hidden !important;
}

.cube-stage.is-expanded {
  position: fixed !important;
  inset: 0 !important;
  z-index: 99999 !important;
  width: 100vw !important;
  height: 100dvh !important;
  max-width: none !important;
  max-height: none !important;
  margin: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  overflow: hidden !important;
}

.cube-stage.is-expanded #cubeScene {
  width: 100% !important;
  height: 100% !important;
  min-height: 100dvh !important;
  display: grid !important;
  place-items: center !important;
}

.cube-stage.is-expanded .css-cube {
  --cube-size: min(52vmin, 520px);
}

.cube-stage.is-expanded .cube-view-controls {
  position: absolute;
  z-index: 12;
}

@media (max-width: 700px) {
  .cube-stage-expand {
    top: 10px;
    left: 10px;
  }

  .cube-stage.is-expanded .css-cube {
    --cube-size: min(60vmin, 420px);
  }
}
