/**
 * trial-rack.css — Quick Lens Rack Drawer & Lens Box Styles
 * ============================================================================
 * The drawer is a size container ("rack"). Everything responsive is keyed to the
 * drawer's own box, not the window, because inside the shell the page sits in an
 * iframe whose window is taller than the part the person can see. rack-viewport.js
 * publishes --rack-hidden-top / --rack-hidden-bottom, the drawer insets itself by
 * them, and so "the container" is exactly the visible region.
 *
 *   Roomy (desktop):   centred modal, quick steps pinned, the grid scrolls.
 *   Narrow (≤ 640px):  bottom sheet that slides up from the thumb.
 *   Short  (≤ 600px):  compact chrome, and the quick steps scroll away *with*
 *                      the lenses so the grid gets the room. This is what a
 *                      phone in the shell (~460px visible) needs: pinned chrome
 *                      alone used to be 360px of a 420px sheet.
 * Direction-aware: every offset is logical.
 * ============================================================================
 */
.tf-rack-drawer {
  position: fixed;
  top: var(--rack-hidden-top, 0px);
  bottom: var(--rack-hidden-bottom, 0px);
  left: 0;
  right: 0;
  z-index: 9999;
  display: none;
  container: rack / size;
}
.tf-rack-drawer.open {
  display: flex;
}
.tf-rack-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.38);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: tfFade 0.18s ease-out both;
  /* a drag on the dimmed area must not scroll the page behind the sheet */
  touch-action: none;
}
.tf-rack-panel {
  position: absolute;
  top: 5%;
  left: 50%;
  transform: translateX(-50%);
  width: 90%;
  max-width: 820px;
  height: 90%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 40px rgba(0,0,0,0.18);
  overflow: hidden;
  z-index: 10;
}
.tf-rack-grip { display: none; }

.tf-rack-header {
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-sunken);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  /* the header is the swipe-down-to-close handle, so it must not pan the page */
  touch-action: none;
}
.tf-rack-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.tf-rack-emoji { font-size: 16px; }
.tf-rack-title {
  margin: 0;
  min-width: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}
.tf-rack-close {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-soft);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
  touch-action: manipulation;
}
.tf-rack-close:hover { background: var(--accent); color: #fff; }

.tf-rack-filter-bar {
  padding: 10px 18px;
  background: var(--surface-sunken);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}
.tf-lens-search {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 16px; /* ≥16px: iOS Safari must not zoom the page on focus */
  font-family: 'IBM Plex Mono', monospace;
  text-overflow: ellipsis;
}
/* The typed text stays 16px (iOS zoom); the hint may be smaller so it isn't cut. */
.tf-lens-search::placeholder { font-size: 14px; }
.tf-category-tabs {
  --tf-fade-dir: to right;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  padding-inline-end: 26px; /* the last chip clears the fade below */
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  /* a soft edge says "there is more this way" instead of a hard clipped word */
  -webkit-mask-image: linear-gradient(var(--tf-fade-dir), #000 calc(100% - 26px), transparent);
  mask-image: linear-gradient(var(--tf-fade-dir), #000 calc(100% - 26px), transparent);
}
html[dir='rtl'] .tf-category-tabs { --tf-fade-dir: to left; }
.tf-category-tabs::-webkit-scrollbar { display: none; }
.tf-category-tabs .ret-snap-btn {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 6px 12px;
  white-space: nowrap;
  font-size: 12px;
}
.tf-category-tabs .ret-snap-btn.active {
  background: var(--accent);
  color: #fff;
}

/* Owns the scrolling. Roomy: it only hosts the pinned steps and the scrolling grid.
   Compact (below): it is the one scroller, steps and lenses together. */
.tf-rack-scroll {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.tf-rack-quick-steps {
  flex-shrink: 0;
  padding: 8px 18px;
  background: var(--surface-sunken);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  font-size: 12px;
}
.tf-step-group {
  display: flex;
  align-items: center;
  gap: 8px;
}
.tf-step-label {
  color: var(--text-soft);
  font-weight: 600;
  white-space: nowrap;
}
.tf-step-buttons { display: flex; gap: 4px; }
/* The stepper class is shared with the trial frame's fixed 44px dial buttons;
   inside the box the buttons carry a value, so they size to it. */
.tf-step-buttons .ret-step-btn {
  width: auto;
  min-width: 52px;
  height: 40px;
  padding: 0 8px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  font-weight: 700;
  touch-action: manipulation;
}

.tf-lens-grid {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 14px 18px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  gap: 10px;
  align-content: start;
  justify-items: center;
}
.tf-lens-disk {
  padding: 0;
  margin: 0;
  appearance: none;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, box-shadow 0.15s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  background: radial-gradient(circle at 35% 35%, rgba(0,0,0,0.05) 0%, rgba(0,0,0,0.01) 70%, rgba(0,0,0,0.1) 100%);
  position: relative;
}
.tf-lens-disk:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 14px rgba(0,0,0,0.08);
}
.tf-lens-disk:active { transform: scale(0.94); }
.tf-lens-disk.black {
  border: 4px solid #1a1a1a;
  box-shadow: inset 0 0 4px rgba(255,255,255,0.3), 0 2px 6px rgba(0,0,0,0.15);
}
.tf-lens-disk.red {
  border: 4px solid #dc2626;
  box-shadow: inset 0 0 4px rgba(255,255,255,0.3), 0 2px 8px rgba(220,38,38,0.15);
}
.tf-lens-disk.silver {
  border: 4px solid var(--text-soft);
  box-shadow: inset 0 0 4px rgba(255,255,255,0.5), 0 2px 6px rgba(0,0,0,0.15);
}
.tf-lens-disk.gold {
  border: 4px solid #f59e0b;
  box-shadow: inset 0 0 4px rgba(255,255,255,0.4), 0 2px 8px rgba(245,158,11,0.15);
}
.tf-lens-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  font-weight: 800;
  color: var(--text);
  text-shadow: 0 1px 2px rgba(255,255,255,0.8);
}
.tf-lens-sub {
  font-size: 9px;
  color: var(--text-soft);
  font-weight: 600;
}
.tf-lens-empty {
  grid-column: 1 / -1;
  margin: 24px 0 0;
  color: var(--text-soft);
  font-size: 13px;
  text-align: center;
}
.tf-axis-notch {
  position: absolute;
  width: 2px;
  height: 8px;
  background: #ef4444;
}
.tf-axis-notch.top { top: 1px; }
.tf-axis-notch.bottom { bottom: 1px; }
.tf-active-ring {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ── Vertex-distance alert (shown under the dials when |Rx| ≥ 4 D) ── */
.ret-vertex-alert {
  grid-column: 1 / -1;
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid #f59e0b;
  color: #7c4a03;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.5;
  margin-top: 4px;
}
.ret-vertex-alert[hidden] { display: none; }

/* ── Responsive: keyed to the drawer (the visible region), not the window ── */
@keyframes tfFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes tfSheetUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

/* Narrow → bottom sheet */
@container rack (max-width: 640px) {
  .tf-rack-panel {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    transform: none;
    width: 100%;
    max-width: none;
    /* fill the visible region but leave a sliver of backdrop to tap; at least
       440px when there is room, never taller than a comfortable 720px */
    height: min(calc(100% - 10px), max(88%, 440px), 720px);
    border-radius: 22px 22px 0 0;
    border-bottom: none;
    padding-bottom: env(safe-area-inset-bottom);
    animation: tfSheetUp 0.26s cubic-bezier(0.2, 0.9, 0.25, 1) both;
  }
  .tf-rack-grip {
    display: block;
    flex-shrink: 0;
    width: 40px;
    height: 4px;
    margin: 6px auto 0;
    border-radius: 2px;
    background: var(--border);
    touch-action: none;
  }
  .tf-rack-header { padding: 4px 12px 6px 14px; }
  .tf-rack-filter-bar,
  .tf-rack-quick-steps { padding-inline: 14px; }
  .tf-lens-grid {
    padding: 12px 14px calc(14px + env(safe-area-inset-bottom));
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
    gap: 8px;
  }
  .tf-lens-disk { width: 64px; height: 64px; }
}

/* Short and wide (a landscape phone) → use nearly the whole height */
@container rack (min-width: 641px) and (max-height: 600px) {
  .tf-rack-panel { top: 3%; height: 94%; }
}

/* Narrow or short → compact chrome, and steps + lenses share ONE scroller */
@container rack (max-width: 640px) or (max-height: 600px) {
  .tf-rack-scroll {
    display: block;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
  }
  /* Filling the scroller's height lets a short result list still be scrolled up to
     the top, right under the filters, instead of sitting below the quick steps. */
  .tf-lens-grid { overflow: visible; min-height: 100%; }

  .tf-rack-header { padding-block: 4px 6px; }
  .tf-rack-close { width: 38px; height: 38px; }
  .tf-rack-filter-bar { padding-block: 8px; gap: 6px; }
  .tf-lens-search { padding: 7px 12px; }
  .tf-category-tabs .ret-snap-btn { min-height: 34px; }

  /* Two aligned rows — [label][5 steppers] — instead of a stack of wrapped groups. */
  .tf-rack-quick-steps {
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr);
    align-items: center;
    gap: 6px 8px;
    padding-block: 8px;
  }
  .tf-step-group { display: contents; }
  .tf-step-label { font-size: 12px; }
  .tf-step-buttons { min-width: 0; gap: 4px; }
  .tf-step-buttons .ret-step-btn {
    flex: 1;
    min-width: 0;
    height: 40px;
    padding: 0 2px;
    font-size: 13px;
  }
  .tf-step-group > .ret-snap-btn { justify-self: start; min-height: 36px; padding: 6px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .tf-rack-panel,
  .tf-rack-backdrop { animation: none; }
  .tf-lens-disk { transition: none; }
}
