*, *::before, *::after {
  box-sizing: border-box;
}

:root {
  --teal: #17c3d6;
  --teal-dark: #0ea7ba;
  --navy: #16262f;
  --grey: #64767e;
  --card-border: #dcf0f3;
}

html, body {
  margin: 0;
  height: 100%;
  background: #d9dde5;
  font: 13px/1.4 "Inter", system-ui, sans-serif;
  color: var(--navy);
  overflow: hidden;
}

#c {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
}

#ui {
  position: fixed;
  top: 14px;
  left: 14px;
  bottom: 14px;
  /* 290 = the original 258px content width, preserved after the border-box
     reset (which folds this rule's own 15px+15px padding and 1px+1px
     border back into the same declared width) - keeps desktop pixel-
     identical to before that reset. */
  width: 290px;
  overflow-y: auto;
  background: rgba(255, 255, 255, .94);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 14px 15px 16px;
  box-shadow: 0 10px 30px rgba(22, 38, 47, .18);
}

.back-link {
  display: inline-block;
  font-family: "Space Grotesk", sans-serif;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--teal-dark);
  text-decoration: none;
  margin-bottom: 10px;
}
.back-link:hover { text-decoration: underline; }

#ui h1 {
  font-family: "Space Grotesk", sans-serif;
  font-size: 16px;
  margin: 0 0 1px;
  color: var(--navy);
}
#ui small { color: var(--grey); }

#ui h2 {
  font-family: "Space Grotesk", sans-serif;
  font-size: 11px;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--teal-dark);
  margin: 14px 0 4px;
  border-top: 1px solid var(--card-border);
  padding-top: 9px;
}

#ui label.l { display: flex; justify-content: space-between; margin: 6px 0 1px; }
#ui input[type=range] { width: 100%; margin: 0; accent-color: var(--teal); }
#ui select {
  width: 100%;
  padding: 4px 6px;
  border: 1px solid var(--card-border);
  border-radius: 6px;
  background: #fff;
  color: var(--navy);
  font: inherit;
}

.row { display: flex; gap: 5px; margin-top: 6px; flex-wrap: wrap; }
button {
  flex: 1;
  min-width: 52px;
  padding: 6px 4px;
  border: 1px solid var(--card-border);
  border-radius: 7px;
  background: #fff;
  color: var(--navy);
  cursor: pointer;
  font: 600 12px "Inter", sans-serif;
  transition: background .15s, border-color .15s;
}
button:hover { background: #eafcff; border-color: var(--teal); }

.chk { display: flex; align-items: center; gap: 6px; margin: 4px 0; }
.chk label { margin: 0; }
.chk input[type=checkbox] { accent-color: var(--teal); }

#hint {
  position: fixed;
  bottom: 10px;
  left: 292px;
  right: 0;
  text-align: center;
  color: var(--navy);
  opacity: .55;
  font-size: 12px;
  pointer-events: none;
}

.drawer-header,
.drawer-handle,
.drawer-chevron {
  display: none;
}

/* Mobile: #ui becomes a bottom drawer instead of a top-left floating panel.
   The canvas's own height is kept in sync with the drawer's current height
   by JS (model-viewer.js's resize()), so the 3D viewer always occupies
   exactly the space above the drawer - never hidden behind it - and the
   camera is refit whenever that height changes. Desktop is untouched: none
   of this block's selectors have any effect outside this media query, and
   #c/#ui's desktop rules (inset:0 / fixed 290px sidebar) are unchanged. */
@media (max-width: 640px) {
  #c {
    bottom: auto;
    transition: height .25s ease;
  }
  #hint { display: none; }

  #ui {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: none;
    height: 56px; /* JS keeps this authoritative; matches DRAWER_COLLAPSED_H */
    display: flex;
    flex-direction: column;
    border-radius: 18px 18px 0 0;
    padding: 0 15px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    overflow: hidden;
    transition: height .25s ease;
  }

  #ui.collapsed .drawer-body { display: none; }

  .drawer-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: none;
    padding: 8px 0 6px;
    margin: 0 -15px;
    cursor: pointer;
  }

  .drawer-handle {
    display: block;
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--card-border);
    margin-bottom: 8px;
  }

  .drawer-header-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: "Space Grotesk", sans-serif;
    font-size: 13px;
    font-weight: 600;
    color: var(--navy);
  }

  .drawer-chevron {
    display: block;
    width: 14px;
    height: 14px;
    color: var(--teal-dark);
    transition: transform .2s ease;
  }
  #ui:not(.collapsed) .drawer-chevron { transform: rotate(180deg); }

  .drawer-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding-bottom: 8px;
  }

  .ui-close,
  .ui-open {
    display: none;
  }

  /* Bigger tap targets than the desktop button rule */
  button {
    padding: 10px 6px;
    font-size: 13px;
  }
  .chk {
    margin: 8px 0;
  }
}
