/* Additions the reference CSS doesn't carry: slow spin for the hydro chip,
   smooth anchor scrolling, and the toast cards. */
html { scroll-behavior: smooth; }
/* never allow the page itself to pan sideways — clip at the root, like the
   reference does one level down. Fixes stray horizontal scrolling at any
   zoom/scrollbar configuration. */
html, body { overflow-x: clip; max-width: 100%; }
canvas { display: block; }
img, video, canvas { max-width: 100%; }

@keyframes spin-slow { to { transform: rotate(360deg); } }
.animate-spin-slow { animation: spin-slow 3s linear infinite; }

#toast-root {
  position: fixed; bottom: 24px; right: 24px; z-index: 200;
  display: flex; flex-direction: column; gap: 10px; pointer-events: none;
}
.toast-card {
  min-width: 280px; max-width: 360px;
  background: #161616; color: #fafafa;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px; padding: 12px 16px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
  font-size: 13px; line-height: 1.45;
  opacity: 0; transform: translateY(8px);
  transition: opacity 250ms ease, transform 250ms ease;
}
.toast-card.is-in { opacity: 1; transform: none; }
.toast-card .t-title { font-weight: 600; }
.toast-card.t-error .t-title { color: #e07a5f; }
.toast-card .t-desc { color: #a3a3a3; font-size: 12px; margin-top: 2px; }

/* ---- gallery (THE ARMORY): responsive 2-4 col card grid — the compiled
   site.css only carries the grid-cols variants index.html uses, so the
   gallery columns live here instead. ---- */
.armory-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}
@media (min-width: 768px) {
  .armory-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1.5rem; }
}
@media (min-width: 1280px) {
  .armory-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* ---- V3: six-link nav rows (subpages) need more room than index's four —
   show the desktop link row from 1024px up instead of 768px (the compiled
   site.css carries no lg:flex utility). ---- */
.cx-nav-links { display: none; }
@media (min-width: 1024px) { .cx-nav-links { display: flex; } }

/* ---- V3: shared auth widget (auth-widget.js) — modal/card entrance and
   inline field-error state. ---- */
@keyframes cx-fade-in { from { opacity: 0; } }
@keyframes cx-pop-in { from { opacity: 0; transform: translateY(10px) scale(0.98); } }
.cx-auth-overlay { animation: cx-fade-in 180ms ease-out; }
.cx-auth-card { animation: cx-pop-in 180ms ease-out; }
.cx-input-error { border-color: rgba(224, 122, 95, 0.6) !important; }

/* ---- V3: account page MY DESIGNS grid — cards carry three action buttons,
   so the 4-col jump waits for lg (the compiled site.css has no
   lg:grid-cols-4). ---- */
.cx-designs-grid { display: grid; gap: 1rem; grid-template-columns: repeat(1, minmax(0, 1fr)); }
@media (min-width: 640px) { .cx-designs-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1024px) { .cx-designs-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

/* ============================================================
   V3: Design Studio (design.html) — page-specific components.
   The compiled site.css only carries utilities index.html uses,
   so studio-only widgets live here.
   ============================================================ */

/* selection overlay sits above the engine canvases and owns the pointer */
#dz-overlay { touch-action: none; }

/* V4: ghost-mannequin views — one stacked canvas per (fit, view), created
   lazily by designer.js. Inactive views hide via visibility (not display)
   so hidden engines keep their geometry and stay capturable for previews. */
#dz-views { position: absolute; inset: 0; }
.dz-view-canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  display: block; user-select: none; -webkit-user-select: none;
}

/* V5: preview zoom — #dz-zoom (canvas stack + overlay) grows inside the
   clipped viewport so every engine's ResizeObserver re-renders its bitmap
   crisply at the larger element size (no CSS-transform blur up to the
   bitmap cap); designer.js pans it via translate(). */
#dz-zoom {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  transform-origin: 0 0;
}

/* zoom control pill, top-right over the canvas (WETNESS-chip styling) */
.dz-zoom-ctl {
  position: absolute; top: 12px; right: 12px; z-index: 10;
  display: flex; gap: 2px; padding: 3px;
  background: rgba(0, 0, 0, 0.4); border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.dz-zoom-btn {
  min-width: 44px; padding: 8px 4px; border-radius: 6px;
  font-size: 10px; letter-spacing: 0.08em; line-height: 1;
  text-transform: uppercase; color: rgba(255, 255, 255, 0.45);
  transition: all 0.15s;
}
.dz-zoom-btn:hover { color: #fff; background: rgba(255, 255, 255, 0.08); }
.dz-zoom-btn.is-on { background: #847A65; color: #fff; }

/* draft recovery bar (below the fixed header) */
.dz-draftbar {
  position: fixed; top: 72px; left: 50%; transform: translateX(-50%);
  z-index: 120; display: flex; align-items: center; gap: 12px;
  background: #161616; border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px; padding: 10px 16px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6); font-size: 12px;
  max-width: calc(100vw - 32px);
}
.dz-bar-btn {
  border: 1px solid rgba(255, 255, 255, 0.1); border-radius: 6px;
  padding: 5px 12px; font-size: 10px; letter-spacing: 0.08em;
  color: #a3a3a3; transition: all 0.2s;
}
.dz-bar-btn:hover { background: rgba(255, 255, 255, 0.05); color: #fff; }
.dz-bar-btn-primary { background: #847A65; border-color: #847A65; color: #fff; }
.dz-bar-btn-primary:hover { background: #A39985; color: #fff; }

/* square icon buttons (undo/redo) */
.dz-icon-btn {
  flex: none; display: flex; align-items: center; justify-content: center;
  width: 42px; height: 42px; border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px; color: #a3a3a3; transition: all 0.2s;
}
.dz-icon-btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.05); color: #fff; }
.dz-icon-btn:disabled { opacity: 0.35; pointer-events: none; }

/* stock art library grid */
.dz-art-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.dz-art-thumb {
  position: relative; aspect-ratio: 1 / 1; padding: 6px 6px 14px;
  background: rgba(0, 0, 0, 0.4); border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px; overflow: hidden; cursor: pointer;
  transition: border-color 0.2s;
}
.dz-art-thumb:hover { border-color: #847A65; }
.dz-art-thumb canvas { width: 100%; height: 100%; }
.dz-art-thumb .at-name {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 2px 4px;
  background: rgba(0, 0, 0, 0.65); color: #d4d4d4; font-size: 8px;
  letter-spacing: 0.08em; text-transform: uppercase; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* layers panel */
.dz-layers { max-height: 236px; overflow-y: auto; padding-right: 2px; }
.dz-layer {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px;
  background: rgba(0, 0, 0, 0.25); border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px; cursor: pointer; font-size: 11px; user-select: none;
}
.dz-layer.is-sel { border-color: rgba(132, 122, 101, 0.7); background: rgba(132, 122, 101, 0.12); }
.dz-layer.is-drag { opacity: 0.4; }
.dz-layer .lr-type {
  flex: none; font-size: 9px; letter-spacing: 0.08em; color: #847A65;
  border: 1px solid rgba(132, 122, 101, 0.4); border-radius: 4px; padding: 1px 4px;
}
.dz-layer .lr-name {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; color: #d4d4d4;
}
.dz-layer .lr-btn {
  flex: none; display: flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 5px; color: #8a8a8a; font-size: 11px;
  transition: all 0.15s;
}
.dz-layer .lr-btn:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.dz-layer .lr-btn:disabled { opacity: 0.25; pointer-events: none; }

/* native select dropdown readability on the dark theme */
.dz-select option { background: #141414; color: #fafafa; }

/* the two canvas HUD chips collide on very narrow screens — keep wetness */
@media (max-width: 480px) { .dz-hud-left { display: none; } }

/* auth modal: margin-auto keeps the card reachable when taller than the viewport */
.cx-auth-overlay > * { margin: auto; }

/* ---- Nav rework: solid ORDER NOW CTA (all widths) + CSS-only mobile menu.
   The desktop link row (.cx-nav-links) is unchanged; below lg the hamburger
   provides the same links. No JS: <details> handles open/close (CSP-safe). ---- */
.cx-order-cta {
  display: inline-flex; align-items: center; justify-content: center;
  height: 2.25rem; padding: 0 1.1rem; border-radius: 0.5rem;
  background: #847A65; color: #fff;
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.12em;
  white-space: nowrap; transition: background 200ms ease;
}
.cx-order-cta:hover { background: #A39985; }

.cx-mnav { position: relative; }
@media (min-width: 1024px) { .cx-mnav { display: none; } }
.cx-mnav > summary {
  list-style: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  width: 2.25rem; height: 2.25rem; border-radius: 0.5rem;
  border: 1px solid rgba(255, 255, 255, 0.1); color: #a3a3a3;
  transition: color 200ms ease, background 200ms ease;
}
.cx-mnav > summary::-webkit-details-marker { display: none; }
.cx-mnav[open] > summary { color: #fff; background: rgba(255, 255, 255, 0.06); }
.cx-mnav > nav {
  position: absolute; right: 0; top: calc(100% + 0.85rem);
  min-width: 13rem; padding: 0.5rem; z-index: 60;
  display: flex; flex-direction: column; gap: 0.15rem;
  background: rgba(8, 8, 8, 0.97);
  border: 1px solid rgba(255, 255, 255, 0.1); border-radius: 0.75rem;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.55);
}
.cx-mnav > nav a {
  display: block; padding: 0.7rem 0.95rem; border-radius: 0.5rem;
  font-size: 0.72rem; letter-spacing: 0.12em;
}
.cx-mnav > nav a:hover { background: rgba(255, 255, 255, 0.05); }

/* Compact header under lg so logo + auth + CTA + hamburger fit on phones
   (the lockup's 44px height is inline-styled, hence the !important). */
@media (max-width: 1023px) {
  header img[alt="Covert Expression"] { height: 30px !important; }
  header .flex.items-center.gap-4 { gap: 0.5rem; }
  .cx-order-cta { height: 2rem; padding: 0 0.7rem; font-size: 0.62rem; }
  .cx-mnav > summary { width: 2rem; height: 2rem; }
}

/* 3D preview modal (shirt3d.js — lazy-loaded from the design studio) */
.sd3-overlay {
  position: fixed; inset: 0; z-index: 150;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  animation: cx-fade-in 180ms ease-out;
}
.sd3-panel {
  display: flex; flex-direction: column;
  width: min(960px, 100%); max-height: calc(100vh - 32px); margin: auto;
  background: #0a0a0a; border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 1rem; overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.7);
  animation: cx-pop-in 180ms ease-out;
}
.sd3-head {
  flex: none; padding: 14px 20px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.sd3-title {
  font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase;
  color: #847A65;
}
.sd3-controls {
  flex: none; display: flex; align-items: center; gap: 14px;
  padding: 10px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.sd3-fit { display: flex; gap: 6px; }
.sd3-fit-btn {
  width: 34px; height: 30px; border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #a3a3a3; font-size: 11px; letter-spacing: 0.08em;
  transition: all 0.2s;
}
.sd3-fit-btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.05); color: #fff; }
.sd3-fit-btn:disabled { opacity: 0.4; pointer-events: none; }
.sd3-fit-btn.is-on { background: #847A65; border-color: #847A65; color: #fff; }
.sd3-sliderwrap {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px;
}
.sd3-slider-label {
  flex: none; font-size: 10px; letter-spacing: 0.12em; color: #737373;
}
.sd3-slider-label.sd3-wet { color: #847A65; font-weight: 700; }
.sd3-slider {
  flex: 1; min-width: 40px; height: 4px;
  background: #262626; border-radius: 8px;
  appearance: none; -webkit-appearance: none;
  accent-color: #847A65; cursor: pointer; outline: none;
}
.sd3-close {
  flex: none; padding: 7px 14px; border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #a3a3a3; font-size: 10px; letter-spacing: 0.12em;
  transition: all 0.2s;
}
.sd3-close:hover { background: rgba(255, 255, 255, 0.05); color: #fff; }
.sd3-body {
  position: relative; flex: 1; min-height: 60vh;
  background: #0d0d0d; overflow: hidden;
}
.sd3-canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  touch-action: none; cursor: grab;
}
.sd3-canvas:active { cursor: grabbing; }
.sd3-loading {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  font-size: 11px; letter-spacing: 0.2em; text-transform: uppercase;
  color: #847A65; pointer-events: none;
}
.sd3-foot {
  flex: none; padding: 10px 20px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 9px; letter-spacing: 0.18em; color: #737373;
  text-transform: uppercase;
}
@media (max-width: 560px) {
  .sd3-controls { flex-wrap: wrap; }
  .sd3-sliderwrap { order: 3; flex-basis: 100%; }
}

/* ---- 3D preview mounted INLINE (order page product window) ---- */
.sd3-inline {
  width: 100%; height: 100%; max-height: none; margin: 0;
  border: 0; border-radius: 0; box-shadow: none; animation: none;
  background: #0d0d0d;
}
.sd3-inline .sd3-body { min-height: 0; }
.sd3-inline .sd3-controls { border-bottom-color: rgba(255, 255, 255, 0.08); }
.sd3-inline .sd3-foot { padding: 8px 16px 10px; }

/* ---- studio control rows: breathing room + phone-first tap targets ----
 * (site.css is a compiled Tailwind capture — new utilities don't exist, so
 * all responsive/spacing corrections live here against the studio's ids.) */
#fit-tabs button { padding: 9px 14px; font-size: 11px; }
#zone-tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
#zone-tabs button { padding: 11px 4px; font-size: 11px; }
#placement-row { display: block; margin-top: 16px; }
#placement-row > span { display: block; margin-bottom: 8px; }
#placement-row > div { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
#placement-row button { padding: 11px 4px; font-size: 11px; }
#placement-row.hidden { display: none; }
#btn-add-text, #btn-add-art, #btn-add-upload { padding-top: 12px; padding-bottom: 12px; }
@media (max-width: 440px) {
  #zone-tabs { grid-template-columns: repeat(2, 1fr); } /* 2x2 beats 4 slivers */
}

/* ---- phone-first: comfortable touch targets everywhere ---- */
@media (pointer: coarse) {
  #zone-tabs button, #placement-row button, #fit-tabs button,
  #btn-add-text, #btn-add-art, #btn-add-upload,
  .dz-zoom-btn, .sd3-fit-btn, .sd3-close { min-height: 44px; }
  #wetness, .sd3-slider { height: 8px; }
  .dz-art-thumb { min-width: 88px; min-height: 88px; }
}

/* order page: the purchase card only pins on desktop — on phones a sticky
 * panel fights the natural scroll to the reserve button */
@media (max-width: 1023px) {
  #order-panel > div.sticky { position: static; }
}

/* ---- phone nav: stop the logo / handle / CTA collision ---- */
@media (max-width: 560px) {
  header img[alt="Covert Expression"] { height: 30px !important; }
  #nav-auth { max-width: 92px; }
  #nav-auth a, #nav-auth button, #nav-auth span {
    display: inline-block; max-width: 92px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .cx-order-cta { padding: 8px 10px; font-size: 10px; }
}

/* ---- gallery on phones: one comfortable card per row ---- */
@media (max-width: 479px) {
  #gallery-grid { grid-template-columns: 1fr !important; }
}

/* ================= PHONE-OPTIMIZED (not just phone-tolerant) =============
 * The studio behaves like an app on phones: the shirt preview stays pinned
 * while the controls scroll beneath it, and SAVE lives in a fixed thumb bar. */
@media (max-width: 1023px) {
  #studio-preview-col {
    position: sticky; top: 46px; z-index: 40;
    background: #050505; padding-bottom: 10px;
    box-shadow: 0 16px 18px -14px rgba(0, 0, 0, 0.9);
  }
  #dz-wetrow { margin-top: 10px; }
  /* iOS zooms the page when a focused input is under 16px — never let it */
  input[type="text"], input[type="email"], input[type="password"],
  input[type="search"], input[type="number"], textarea, select { font-size: 16px !important; }
}
@media (max-width: 639px) {
  #dz-hints { display: none; }               /* keyboard shortcuts are desktop-speak */
  #product-window { aspect-ratio: 1 / 1.08; } /* taller, more immersive product view */
}

/* fixed bottom action bar (created by designer.js on small screens) */
#dz-mobile-bar { display: none; }
@media (max-width: 1023px) {
  #dz-mobile-bar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    display: flex; gap: 10px;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
    background: rgba(5, 5, 5, 0.92);
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
  }
  .dz-mb-primary {
    flex: 2; background: #847A65; color: #fff; border-radius: 10px;
    padding: 14px 10px; font-size: 13px; letter-spacing: 0.12em; font-weight: 700;
  }
  .dz-mb-primary:active { background: #A39985; }
  .dz-mb-secondary {
    flex: 1; border: 1px solid rgba(255, 255, 255, 0.14); color: #d4d4d4;
    border-radius: 10px; padding: 14px 10px; font-size: 11px; letter-spacing: 0.08em;
  }
  body.has-dz-bar { padding-bottom: 84px; }
}

/* touch niceties everywhere */
button, [role="button"], summary { touch-action: manipulation; }
#hero-canvas { touch-action: pan-y; } /* the hero sim must never trap page scroll */

/* Tailwind's overflow-x-hidden on the page wrapper creates a scroll
 * container, which silently kills position:sticky for every descendant —
 * clip gives identical clipping without the side effect. */
div.overflow-x-hidden { overflow-x: clip; }

/* ---- desktop studio: balanced workbench ----
 * The preview frame runs the controls panel's full resting height (the
 * cover-fitted masters crop their empty sides, so the shirt renders LARGER
 * with no distortion), and the column pins so the shirt stays in view when
 * the panel grows (element properties, art library). */
@media (min-width: 1024px) {
  #studio-preview-col { position: sticky; top: 84px; }
  #dz-viewport { aspect-ratio: auto; height: min(76vh, 880px); }
}

/* ---- audit round: touch targets, reduced motion ---- */
@media (pointer: coarse) {
  .cx-nav-links a, footer a, #nav-auth a, #nav-auth button {
    padding-top: 10px; padding-bottom: 10px; display: inline-block;
  }
  footer .flex.gap-4 a { padding: 10px; } /* social icons */
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
