/* The touch handle covers only the crystal; the room stays available for page scrolling. */
.mobile-only, .mobile-steps, .position-controls { display: none; }
.scene-surface { position: relative; width: 100%; line-height: 0; }
.camera-button {
  display: flex; align-items: center; justify-content: center; gap: 9px;
  width: 100%; min-height: 48px; margin-top: 10px; padding: 10px 12px;
  border: 1px solid #dcd2e0; border-radius: 9px;
  background: var(--purple-light); color: var(--purple); font-size: 14px;
}
.camera-button:hover { background: #e9dfee; }
.camera-button svg { width: 21px; height: 21px; }
.stage canvas { touch-action: pan-y pinch-zoom; cursor: crosshair; }
.crystal-handle {
  position: absolute; z-index: 1; padding: 0; border: 1px solid transparent;
  border-radius: 8px; background: transparent; touch-action: none;
  cursor: grab; min-width: 44px; min-height: 44px; user-select: none;
  -webkit-user-select: none; -webkit-touch-callout: none;
}
.crystal-handle[hidden] { display: none; }
.crystal-handle:hover, .crystal-handle:focus-visible { border-color: #9674a6; }
.crystal-handle.dragging { cursor: grabbing; border-color: var(--purple); }
.crystal-handle:focus-visible { outline: 2px solid #a884b5; outline-offset: 3px; }

@media (max-width: 900px) {
  :root { --mobile-scene-height: clamp(130px, 30vh, 250px); }
  body { padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }
  .mobile-only { display: inline; }
  .desktop-only { display: none !important; }
  .site-header {
    height: auto; min-height: 105px; padding: 15px 16px 0;
    display: grid; grid-template-columns: 1fr auto; gap: 12px;
  }
  .brand { gap: 9px; }
  .brand > span { font-size: 20px; letter-spacing: 2px; }
  .brand-mark { width: 29px; height: 33px; }
  .brand-sub { font-size: 7px; letter-spacing: 2.5px; }
  .private-pill { display: flex; font-size: 10px; padding: 6px 9px; }
  .site-header nav {
    grid-column: 1 / -1; margin: 0; display: grid; gap: 0;
    grid-template-columns: repeat(3, minmax(0, 1fr)); height: 46px;
    border-top: 1px solid var(--line); width: 100%;
  }
  .site-header nav .nav-button {
    display: flex; align-items: center; justify-content: center; gap: 5px;
    font-size: 12px; min-height: 44px; padding: 0 3px;
  }
  .count { margin: 0; min-width: 20px; height: 20px; font-size: 10px; }
  main { padding: 24px 12px; }
  .intro { margin-bottom: 17px; }
  .intro-note { display: none; }
  h1 { font-size: clamp(28px, 8vw, 36px); line-height: 1.2; }
  .intro-copy { font-size: 14px; line-height: 1.7; margin-top: 10px; }
  .eyebrow { font-size: 9px; letter-spacing: 1.7px; }
  .mobile-steps { display: flex; gap: 7px; margin: 0 0 18px; }
  .mobile-steps button {
    flex: 1; min-width: 0; min-height: 44px; padding: 6px 4px;
    border: 1px solid var(--line); background: #fff; border-radius: 8px;
    color: #685a6b; font-size: 11px; line-height: 1.4;
  }
  .mobile-steps span { font-family: Georgia, serif; color: #a68c71; padding-left: 4px; }
  .workspace { display: flex; flex-direction: column; gap: 18px; align-items: stretch; }
  .studio {
    order: 0; position: sticky; top: 8px; z-index: 10; flex-shrink: 0;
    box-shadow: 0 7px 24px #42344814; border-radius: 12px;
  }
  .controls { order: 1; display: block; overflow: visible; border-radius: 12px; }
  .control-section, .controls > .control-section:not(.room-section) {
    padding: 18px 16px; height: auto; border-bottom: 1px solid var(--line);
    scroll-margin-top: calc(var(--studio-offset, 380px) + 18px);
  }
  .controls > .adjustments { border-right: 0; border-top: 0; }
  .control-section h2 { font-size: 16px; margin-bottom: 15px; }
  .step { font-size: 13px; }
  .upload-zone {
    display: grid; grid-template-columns: 42px minmax(0, 1fr); gap: 3px 12px;
    padding: 16px 12px; text-align: right; min-height: 102px;
  }
  .upload-icon { grid-row: 1 / 4; width: 42px; height: 42px; margin: 0; }
  .upload-icon svg { width: 21px; height: 21px; }
  .upload-zone strong { font-size: 15px; }
  .upload-zone > span:not(.upload-icon) { font-size: 12px; line-height: 1.6; margin: 0; }
  .upload-zone small { margin-top: 4px; text-align: right; font-size: 11px; }
  .sample-button { margin: 8px 0 0; min-height: 44px; font-size: 13px; padding: 6px 0; }
  .upload-status { font-size: 12px; margin-top: 6px; }
  .stage-toolbar { padding: 6px 8px; gap: 6px; min-height: 54px; }
  .stage-title { gap: 6px; flex: 1; }
  .stage-title strong { font-size: 12px; max-width: 135px; }
  .sample-tag { display: none; }
  .toolbar-actions { gap: 0; }
  .toolbar-actions .icon-button {
    min-width: 44px; min-height: 44px; padding: 6px; border-radius: 8px;
  }
  .toolbar-actions .icon-button span { display: none; }
  .icon-button svg { width: 19px; height: 19px; }
  .stage {
    height: var(--mobile-scene-height); min-height: 0;
    display: grid; place-items: center;
  }
  .scene-surface { width: min(100%, calc(var(--mobile-scene-height) * var(--room-ratio, 1.5))); }
  .scene-footer {
    padding: 10px 12px 11px; gap: 5px 10px;
    display: grid; grid-template-columns: minmax(0, 1fr) auto;
  }
  .scene-footer .selected-summary { max-width: none; min-width: 0; gap: 8px; }
  .selected-summary strong { font-size: 13px; line-height: 1.5; }
  .selected-summary small { font-size: 11px; line-height: 1.5; }
  .color-dot { width: 23px; height: 23px; flex-shrink: 0; }
  .scene-footer .text-button { font-size: 12px; min-height: 44px; padding: 5px; }
  .scene-footer p {
    grid-column: 1 / -1; font-size: 11px; margin: 0; padding-top: 3px;
    justify-content: center; color: #776b7c; line-height: 1.5;
  }
  .scene-footer p svg { width: 15px; height: 15px; }
  .studio-bottom, .compare-tray { display: none; }
  .catalog-total { font-size: 11px; }
  .catalog-filters { gap: 8px; margin-bottom: 14px; }
  .catalog-filters button { font-size: 13px; min-height: 44px; padding: 8px; }
  .catalog-filters span { font-size: 11px; }
  .catalog-options {
    max-height: none; overflow: visible; padding: 3px;
    grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px 12px;
  }
  .catalog-choice { gap: 0; }
  .catalog-choice .crystal-card { height: auto; padding: 8px 8px 12px; touch-action: manipulation; }
  .catalog-choice .crystal-image { height: clamp(112px, 33vw, 175px); }
  .catalog-choice .crystal-card strong { font-size: 13px; min-height: 39px; margin-top: 8px; }
  .catalog-choice .crystal-card small { display: block; font-size: 11px; min-height: 17px; }
  .catalog-choice .selection-check { width: 22px; height: 22px; }
  .selection-check svg { width: 14px; height: 14px; }
  .catalog-original { min-height: 44px; font-size: 12px; padding: 6px; }
  .catalog-hint { font-size: 12px; line-height: 1.6; }
  .label-row, .label-row > .field-label { font-size: 14px; margin: 18px 0 10px; }
  .label-row > span { font-size: 12px; }
  .label-row output { font-size: 13px; }
  .size-options { gap: 9px; }
  .size-options button { min-height: 48px; padding: 10px; }
  .size-options strong { font-size: 16px; }
  .size-options span { font-size: 13px; }
  .position-controls { display: block; margin-bottom: 17px; }
  .position-controls > span { display: block; font-size: 13px; margin-bottom: 8px; }
  .position-controls > div { display: flex; gap: 9px; }
  .position-controls button {
    flex: 1; min-width: 44px; min-height: 46px; border: 1px solid #dcd2e0;
    border-radius: 8px; background: #faf6fc; font-size: 22px; color: var(--purple);
  }
  input[type="range"] { height: 44px; }
  .scale-note { font-size: 12px; line-height: 1.7; }
  .save-actions {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
    display: flex; gap: 9px; background: #fff; border-top: 1px solid var(--line);
    padding: 12px max(12px, env(safe-area-inset-right, 0px))
      calc(12px + env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
    box-shadow: 0 -4px 20px #46324b0b;
  }
  .save-actions button { flex: 1; min-width: 0; min-height: 48px; font-size: 13px; gap: 6px; padding: 10px 7px; }
  .save-actions svg { width: 18px; height: 18px; }
  .site-footer { margin: 0 16px; padding: 18px 0; }
  .site-footer > span:nth-child(2) { display: none; }
  .site-footer > span:first-child { font-size: 11px; }
  .site-footer small { font-size: 10px; }
  dialog { width: calc(100% - 24px); max-width: 600px; max-height: calc(100vh - 28px); padding: 20px; }
  .collection-dialog { width: calc(100% - 24px); }
  .dialog-heading { gap: 14px; }
  .dialog-heading h2 { font-size: 27px; }
  .dialog-heading .eyebrow { font-size: 12px; }
  .close-button { min-width: 44px; min-height: 44px; width: 44px; height: 44px; }
  .dialog-copy { font-size: 13px; line-height: 1.8; }
  .collection-grid { grid-template-columns: minmax(0, 1fr); }
  #comparisonList { display: flex; gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory; padding: 3px 2px 12px; }
  #comparisonList .collection-card { flex: 0 0 calc(100% - 20px); min-width: 0; scroll-snap-align: start; }
  #comparisonList .empty-state { flex: 1; }
  .collection-card-content { padding: 15px; }
  .collection-card-content h3 { font-size: 16px; }
  .collection-card-content p { font-size: 13px; }
  .collection-card-actions { gap: 8px; }
  .collection-card-actions button { min-height: 44px; font-size: 13px; padding: 8px 10px; }
  .name-dialog { width: calc(100% - 24px); }
  .name-dialog label { font-size: 14px; }
  .name-dialog input[type="text"] { font-size: 16px; min-height: 48px; }
  .name-dialog .primary-button, .product-dialog .primary-button { min-height: 48px; font-size: 14px; }
  .product-dialog { width: calc(100% - 24px); }
  .product-dialog .dialog-heading h2 { font-size: 24px; }
  .product-dialog > img { max-height: 45vh; }
  .product-dialog .dialog-copy { font-size: 13px; }
  .toast { bottom: calc(92px + env(safe-area-inset-bottom, 0px)); font-size: 13px; padding: 13px 16px; }
}
@supports (height: 1svh) {
  @media (max-width: 900px) {
    :root { --mobile-scene-height: clamp(130px, 30svh, 250px); }
    dialog { max-height: calc(100dvh - 28px); }
    .product-dialog > img { max-height: 45svh; }
  }
}
/* Short landscape screens need the full viewport for editing controls. */
@media (max-width: 900px) and (max-height: 500px) {
  .studio { position: relative; top: 0; }
  .control-section, .controls > .control-section:not(.room-section) { scroll-margin-top: 16px; }
}
