:root {
  --ui-bg: rgba(255, 255, 255, 0.95);
  --ui-text: #222;
  --ui-border: rgba(0, 0, 0, 0.08);
  --ui-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);

  /* ZOOM slider theme  */
  --zoom-track: #e6e6e9; /* unfilled bar */
  --zoom-fill: #f17e00;

  --dd-bg-1: rgba(18, 19, 22, 0.92);
  --dd-bg-2: rgba(18, 19, 22, 0.86);
  --dd-text: #fff;
  --dd-hover: rgba(255, 255, 255, 0.08);
  --dd-active: rgba(255, 206, 141, 0.18);
  --dd-border: rgba(255, 255, 255, 0.08);
}

body {
  margin: 0;
  overflow: hidden;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

#viewport {
  width: 100vw;
  height: 100vh;
  position: relative;
}

/* Overlay UI */
.overlay-ui {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* CLOSE top-left */
.topbar-left {
  position: absolute;
  top: 16px;
  left: 16px;
  pointer-events: auto;
}
.btn-close,
.btn-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--ui-bg);
  border: 1px solid var(--ui-border);
  box-shadow: var(--ui-shadow);
  color: var(--ui-text);
  cursor: pointer;
  font-size: 13px;
}

/* SHARE top-right */
.topbar-right {
  position: absolute;
  top: 16px;
  right: 16px;
  pointer-events: auto;
}
.share-popover {
  position: absolute;
  top: 48px;
  right: 0;
  background: var(--ui-bg);
  border: 1px solid var(--ui-border);
  box-shadow: var(--ui-shadow);
  border-radius: 12px;
  padding: 12px;
  width: 200px;
  z-index: 999;
}
.share-header {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--ui-text);
}
.share-list {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.share-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 18px;
  border: 0;
  cursor: pointer;
  color: #fff;
}
.share-btn.wa {
  background: #25d366;
}
.share-btn.fb {
  background: #1877f2;
}
.share-btn.x {
  background: #0f1419;
}
.share-btn.li {
  background: #0a66c2;
}
.share-btn.cp {
  background: #6b7280;
}
.share-btn:hover {
  filter: brightness(0.92);
}

.share-btn.copied::after {
  content: "Copied!";
  position: absolute;
  bottom: 120%;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 6px;
  white-space: nowrap;
  opacity: 0;
  animation: fadeInOut 1.2s ease forwards;
}

@keyframes fadeInOut {
  0% {
    opacity: 0;
    transform: translateX(-50%) translateY(4px);
  }
  15% {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
  85% {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
  100% {
    opacity: 0;
    transform: translateX(-50%) translateY(4px);
  }
}

.share-btn i {
  font-size: 18px;
  line-height: 1;
  display: block;
}

/* Bottom bar */
.bottombar {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  display: flex;
  gap: 14px;
  align-items: center;
  pointer-events: auto;
  background: var(--ui-bg);
  border: 1px solid var(--ui-border);
  box-shadow: var(--ui-shadow);
  border-radius: 18px;
  padding: 12px 14px;
  max-width: calc(100vw - 32px);
  box-sizing: border-box;
}
.bb-group {
  display: flex;
  align-items: center;
  gap: 10px;
}
.bb-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--ui-text);
  opacity: 0.9;
  letter-spacing: 0.3px;
}

.bb-icon {
  width: 32px;
  height: 32px;
  border: 0;
  background: transparent;
  cursor: pointer;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #333;
}
.bb-icon:hover {
  background: rgba(0, 0, 0, 0.05);
}

.bb-range {
  width: 140px;
  appearance: none;
  background: linear-gradient(var(--zoom-fill) 0 0) no-repeat var(--zoom-track);
  height: 6px;
  border-radius: 999px;
  outline: none;
  background-size: 50% 100%;
}

.bb-lighting .light-btn {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 10px;
  background: #f6f6f6;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #111;
  font-size: 18px;
}
.bb-lighting .light-btn.active {
  background: #fff;
  border: 1px solid var(--ui-border);
  box-shadow: var(--ui-shadow);
}

/* Lighting icon colors */
.bb-lighting .light-btn i {
  color: #6b7280;
  transition: color 0.2s ease;
}
.bb-lighting .light-btn.active[data-mode="day"] i {
  color: #f4a300;
} /* sun */
.bb-lighting .light-btn.active[data-mode="night"] i {
  color: #4c63d2;
} /* moon */

/* Branding */
.branding {
  position: absolute;
  right: 16px;
  bottom: 16px;
  pointer-events: auto;
  background: var(--ui-bg);
  border: 1px solid var(--ui-border);
  box-shadow: var(--ui-shadow);
  padding: 8px 12px;
  border-radius: 999px;
  color: var(--ui-text);
  text-decoration: none;
  font-size: 12px;
}
.branding strong {
  font-weight: 800;
  color: var(--primary-bg);
}

/* Toggle Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 26px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #d1d5db;
  border-radius: 999px;
  transition: background-color 0.3s ease;
}

.slider::before {
  position: absolute;
  content: "";
  height: 22px;
  width: 22px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  border-radius: 50%;
  transition: transform 0.3s ease;
}

/* Label inside */
.switch-label {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  pointer-events: none;
  user-select: none;
}

/* Checked State */
.switch input:checked + .slider {
  background-color: var(--primary-bg);
}
.switch input:checked + .slider::before {
  transform: translateX(24px);
}
.switch input:checked + .slider .switch-label {
  content: "On";
}

/* === Texture drop-UP === */
.bb-texture {
  position: relative;
}

/* trigger pill */
.select-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--ui-border);
  box-shadow: var(--ui-shadow);
  color: var(--ui-text);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.select-pill .caret {
  transition: transform 0.18s ease;
}
.select-pill[aria-expanded="true"] .caret {
  transform: rotate(180deg);
}

/* Panel opens upward */
.dropdown-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 10px);
  width: max-content;
  min-width: 100%;
  background: rgba(255, 232, 199, 0.1);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(0, 0, 0, 0.1);
  box-shadow: var(--ui-shadow);
  border-radius: 14px;
  padding: 10px;
  z-index: 1000;
}

/* pointer arrow */
.dropdown-panel::after {
  content: "";
  position: absolute;
  right: 24px;
  bottom: -6px;
  width: 12px;
  height: 12px;
  background: rgba(255, 232, 199, 0.1);
  transform: rotate(45deg);
  border-right: 1px solid rgba(0, 0, 0, 0.1);
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

/* option rows */
.dropdown-panel .option {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 0;
  background: transparent;
  color: var(--ui-text);
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
}

/* warm translucent hover  */
.dropdown-panel .option:hover {
  background: rgba(255, 206, 141, 0.16);
}

.dropdown-panel .option.active {
  background: rgba(38, 40, 44, 0.85);
  color: #fff;
}

/* small warm dots for each option */
.dropdown-panel .option .dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffe8b4;
  box-shadow: 0 0 0 2px #fff inset, 0 0 0 1px rgba(0, 0, 0, 0.06);
}
.dropdown-panel .option.active .dot {
  background: #fff;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.25);
}

.bb-texture .dropdown-panel {
  background: linear-gradient(180deg, var(--dd-bg-1), var(--dd-bg-2));
  color: var(--dd-text);
  border-color: var(--dd-border);
  backdrop-filter: blur(10px) saturate(120%);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}

.bb-texture .dropdown-panel::after {
  background: var(--dd-bg-2);
  border-right-color: var(--dd-border);
  border-bottom-color: var(--dd-border);
}

/* Options */
.bb-texture .dropdown-panel .option {
  color: var(--dd-text);
  text-shadow: 0 0.5px 0 rgba(0, 0, 0, 0.35);
  transition: background-color 0.15s ease;
}
.bb-texture .dropdown-panel .option:hover {
  background: var(--dd-hover);
}
.bb-texture .dropdown-panel .option.active {
  background: var(--dd-active);
  outline: 1px solid rgba(255, 255, 255, 0.12);
}

.bb-texture .dropdown-panel .option .dot {
  background: #ffd18a;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.5) inset;
}
.bb-texture .dropdown-panel .option.active .dot {
  background: #fff;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.25);
}

.bb-texture .dropdown-panel::after,
.bb-texture .dropdown-panel::before {
  content: none !important;
  display: none !important;
}

.bb-texture .dropdown-panel {
  margin-bottom: 0 !important;
}

/* Preset-locked visual buttons */
body.preset-locked .select-pill[aria-disabled="true"],
body.preset-locked .bb-group [disabled] {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ---------- Tile Info Modal ---------- */
.tileinfo-modal {
  position: fixed;
  inset: 0;
  z-index: 1100;
}
.tileinfo-modal[hidden] {
  display: none !important;
}

.tileinfo-backdrop {
  position: absolute;
  inset: 0;
  backdrop-filter: blur(4px);
  background: rgba(0, 0, 0, 0.45);
}

.tileinfo-panel {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(980px, calc(100vw - 32px));
  max-height: min(80vh, 820px);
  background: var(--ui-bg);
  border: 1px solid var(--ui-border);
  box-shadow: var(--ui-shadow);
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.tileinfo-close {
  position: absolute;
  top: 10px;
  right: 10px;
  border: 0;
  background: #fff;
  border: 1px solid var(--ui-border);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #111;
  box-shadow: var(--ui-shadow);
}

.tileinfo-title {
  margin: 0;
  padding: 16px 56px 12px 16px;
  font-size: 16px;
  font-weight: 700;
  color: var(--ui-text);
  border-bottom: 1px solid var(--ui-border);
  background: #fff;
}

.tileinfo-body {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 16px;
  padding: 16px;
  overflow: auto;
}

/* -------- Gallery -------- */
.ti-gallery {
  display: grid;
  gap: 16px;
}

.ti-hero {
  background: var(--ui-bg);
  border-radius: 12px;
  min-height: 260px;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.ti-hero img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ti-thumbs {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(96px, 1fr);
  gap: 12px; /* spacing between individual thumbs */
  overflow-x: auto;
  padding-bottom: 4px;
}

/* Thumb tile */
.ti-thumb {
  background: #fff;
  border: 1px solid var(--ui-border);
  border-radius: 12px;
  height: 70px;
  cursor: pointer;
  padding: 0;
  overflow: hidden;
  outline: none;
}
.ti-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.ti-thumb.active {
  border: 2px solid var(--primary-bg);
  box-shadow: 0 0 0 2px rgba(241, 126, 0, 0.2);
}

.ti-thumb:focus-visible {
  border: 2px solid var(--primary-bg);
  box-shadow: 0 0 0 3px rgba(241, 126, 0, 0.28);
}

.ti-empty {
  font-size: 12px;
  color: #666;
  padding: 8px 0;
}

/* -------- Specs -------- */
.ti-specs dl {
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 14px;
}
.ti-specs dt {
  font-size: 12px;
  color: #666;
}
.ti-specs dd {
  margin: 0;
  font-weight: 600;
  color: var(--ui-text);
}

/* ---------- Mobile bottom-sheet ---------- */
.bb-fab {
  position: absolute;
  left: 16px;
  bottom: 16px;
  z-index: 10;
  pointer-events: auto;
  display: none;
  width: 48px;
  height: 48px;
  border-radius: 999px;
  border: 1px solid var(--ui-border);
  background: var(--ui-bg);
  box-shadow: var(--ui-shadow);
  place-items: center;
  font-size: 20px;
  color: var(--ui-text);
}

/* small drag handle on the sheet */
#bbPanel::before {
  content: "";
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 38px;
  height: 4px;
  border-radius: 99px;
  background: rgba(0, 0, 0, 0.14);
}

/* ===== Responsive layout ===== */

@media (max-width: 1024px) {
  .bottombar {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-row-gap: 12px;
    align-items: center;
  }

  .bb-zoom {
    order: 1;
    grid-column: 1 / span 2;
  }
  .bb-shine {
    order: 1;
    grid-column: 3;
  }

  .bb-lighting {
    order: 2;
    grid-column: 1;
  }
  .bb-carving {
    order: 2;
    grid-column: 2;
  }
  .bb-texture {
    order: 2;
    grid-column: 3;
  }
}

@media (max-width: 900px) {
  .tileinfo-body {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .bb-zoom {
    display: flex;
    order: 1;
    grid-column: 1 / -1;
    gap: 10px;
    align-items: center;
  }
  .bb-shine {
    display: flex;
    order: 2;
    grid-column: 1 / -1;
    gap: 10px;
    align-items: center;
  }
  .bb-zoom .bb-shine .bb-range {
    width: 100%;
    height: 8px;
  }

  .bb-lighting {
    order: 2;
    grid-column: 1;
    justify-self: start;
  }

  .bb-carving {
    order: 3;
    grid-column: 2;
    justify-self: start;
  }

  .bb-texture {
    order: 4;
    grid-column: 1;
    justify-self: end;
  }

  .bb-fab {
    display: grid;
  }

  .bottombar {
    position: fixed;
    left: 50%;
    transform: translate(-50%, 120%);
    transition: transform 0.24s ease;
    padding: 16px;
    gap: 12px;
    width: auto;
    max-width: 90vw;
    border-radius: 16px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-row-gap: 12px;
    grid-column-gap: 12px;
  }
  .bottombar.open {
    bottom: 50px;
    transform: translate(-50%, 0);
  }

  .bb-zoom,
  .bb-shine {
    grid-column: 1 / -1;
  }
  .bb-range {
    width: 100%;
    height: 8px;
  }
}

@media (max-width: 600px) {
  .bottombar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-column-gap: 12px;
    grid-row-gap: 12px;
    align-items: center;
  }

  .bb-zoom {
    display: flex;
    order: 1;
    grid-column: 1 / -1;
    gap: 10px;
    align-items: center;
  }
  .bb-shine {
    display: flex;
    order: 2;
    grid-column: 1 / -1;
    gap: 10px;
    align-items: center;
  }
  .bb-zoom .bb-shine .bb-range {
    width: 100%;
    height: 8px;
  }

  .bb-lighting {
    order: 2;
    grid-column: 1;
    justify-self: start;
  }

  .bb-carving {
    order: 3;
    grid-column: 2;
    justify-self: start;
  }

  .bb-texture {
    order: 4;
    grid-column: 1;
    justify-self: center;
  }

  .bb-icon,
  .bb-lighting .light-btn {
    width: 40px;
    height: 40px;
  }

  .dropdown-panel {
    right: -4px;
  }
}

@media (max-width: 575px) {
  .bottombar {
    width: auto;
    max-width: none;
  }
}

@media (max-width: 480px) {
  .bottombar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-column-gap: 12px;
    grid-row-gap: 12px;
  }

  .bb-zoom,
  .bb-shine {
    grid-column: 1 / -1;
  }

  .bb-lighting {
    grid-column: 1;
    justify-self: start;
  }
  .bb-carving {
    grid-column: 2;
    justify-self: end;
  }

  .bb-texture {
    grid-column: 1 / -1;
    justify-self: start;
  }

  .dropdown-panel {
    max-width: calc(100vw - 24px);
    right: 0;
    left: 0;
    margin: 0 auto;
  }
}
