/* shared/primitives.css -- the visual layer for the Phase 3 primitives
   (detail drawer, hover chip, command palette, virtual grid). Mobile-first:
   base rules target the phone, desktop is layered in at --bp-md (768px). Colors
   are the warm-neutral OKLCH tokens; the z-index ladder is tokens, never
   literals (ds/tokens.css). Loaded by the shell after contracts.css. */

/* ════════════════════════ detail drawer ════════════════════════ */

.tcg-drawer-scrim {
  position: fixed;
  inset: 0;
  z-index: var(--z-drawer-scrim);
  background: color-mix(in oklab, var(--bg) 62%, transparent);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-snap);
}
.tcg-drawer-scrim.open {
  opacity: 1;
  pointer-events: auto;
}

.tcg-drawer-layer {
  position: fixed;
  inset: 0;
  z-index: var(--z-drawer);
  pointer-events: none;
}

/* base = phone bottom sheet (one sheet, never stacked) */
.tcg-drawer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: calc(92dvh / var(--ui-scale, 1));
  display: flex;
  flex-direction: column;
  background: var(--bg-elev-1);
  border-top: 1px solid var(--border);
  border-top-left-radius: var(--r-xl);
  border-top-right-radius: var(--r-xl);
  box-shadow: var(--shadow-pop);
  pointer-events: auto;
  padding-bottom: env(safe-area-inset-bottom);
  /* landscape notch: inset the side edges too, not just the bottom (mobile-first
     safe-area rule). Both resolve to 0 in portrait, so no change there. */
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  transform: translateY(100%);
  transition: transform var(--transition-slide);
}
.tcg-drawer.in {
  transform: translateY(0);
}
/* phone grab handle */
.tcg-drawer.sheet::before {
  content: "";
  position: absolute;
  top: 7px;
  left: 50%;
  transform: translateX(-50%);
  width: 36px;
  height: 4px;
  border-radius: var(--r-pill);
  background: var(--border-strong);
}

@media (min-width: 768px) /* --bp-md */ {
  .tcg-drawer {
    left: auto;
    top: 0;
    bottom: 0;
    /* the top drawer sits flush right; lower ones peek 40px to the left */
    right: calc(var(--from-top, 0) * 40px);
    width: min(460px, calc(92vw / var(--ui-scale, 1)));
    max-height: none;
    border-top: none;
    border-left: 1px solid var(--border);
    border-radius: 0;
    transform: translateX(100%);
    transition: transform var(--transition-slide), right var(--transition-snap);
  }
  .tcg-drawer.in {
    transform: translateX(0);
  }
  /* lower drawers in the cascade dim slightly so the top reads as foreground */
  .tcg-drawer:not(.top) {
    filter: brightness(0.82);
  }
}

.tcg-drawer-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px 8px;
  flex-shrink: 0;
}
.tcg-drawer-crumbs {
  display: flex;
  align-items: center;
  gap: 5px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}
.tcg-drawer-crumb {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-3);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tcg-drawer-crumb.cur {
  color: var(--text-2);
  cursor: default;
}
.tcg-drawer-crumb-sep {
  color: var(--text-4);
  font-size: 10px;
}
.tcg-drawer-back {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-2);
  background: none;
  border: none;
  padding: 4px 0;
  cursor: pointer;
}
.tcg-drawer-head-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}
.tcg-drawer-arrow,
.tcg-drawer-close,
.tcg-drawer-open {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  border-radius: var(--r-sm);
  border: none;
  background: none;
  color: var(--text-3);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.tcg-drawer-arrow:hover,
.tcg-drawer-close:hover,
.tcg-drawer-open:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.tcg-drawer-title {
  margin: 0;
  padding: 0 14px 10px;
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 400;
  font-size: var(--font-size-2xl);
  line-height: 1.1;
  color: var(--text);
  flex-shrink: 0;
  outline: none;
}
.tcg-drawer-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 14px 16px;
  -webkit-overflow-scrolling: touch;
}
.tcg-drawer-fallback {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 18px 2px;
  color: var(--text-3);
  font-size: var(--font-size-sm);
  line-height: 1.55;
}

@media (prefers-reduced-motion: reduce) {
  .tcg-drawer,
  .tcg-drawer-scrim {
    transition-duration: 0.01ms;
  }
}

/* View Transitions morph target (enhancement; fallback is the .in transition) */
::view-transition-group(tcg-drawer-morph) {
  animation-duration: 200ms;
}

/* ════════════════════════ hover chip ════════════════════════ */

.tcg-ref {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dotted color-mix(in oklab, var(--accent) 45%, transparent);
  cursor: pointer;
  transition: color var(--transition-fast), border-color var(--transition-fast);
}
.tcg-ref:hover {
  color: var(--accent-hover);
  border-bottom-color: var(--accent);
}
.tcg-ref:focus-visible {
  outline: 2px solid var(--accent-ring);
  outline-offset: 2px;
  border-radius: 2px;
}

.tcg-chip-preview {
  position: absolute;
  z-index: calc(var(--z-drawer) + 50);
  max-width: 450px;
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-pop);
  padding: 15px 18px;
  font-size: var(--font-size-sm);
  color: var(--text-2);
  pointer-events: auto;
  animation: chip-fade var(--transition-fast);
}
@keyframes chip-fade {
  from { opacity: 0; transform: translateY(2px); }
  to   { opacity: 1; transform: translateY(0); }
}
.tcg-chip-preview-name {
  font-size: var(--font-size-md);
  color: var(--text);
  margin-top: 2px;
}
/* The card image inside a hover-preview popover: a 5:7 frame that layers the real
   card art (--art-img, set from the trigger when it carries one) over the brand
   hue gradient, so hovering a card chip shows the actual card rather than a tint.
   No art set (a bare text chip) falls back to just the gradient. Lives in shared
   chrome so it works wherever a card chip renders. */
.tcg-chip-preview-art {
  width: 198px;
  aspect-ratio: 5 / 7;
  margin-bottom: 8px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-soft);
  background-image:
    var(--art-img, none),
    linear-gradient(160deg, oklch(0.40 0.055 var(--art-h, 250)), oklch(0.28 0.045 calc(var(--art-h, 250) + 40))),
    repeating-linear-gradient(135deg, transparent 0 7px, rgba(255, 255, 255, 0.03) 7px 14px);
  background-color: var(--bg-elev-2);
  background-size: cover;
  background-position: center;
}
@media (prefers-reduced-motion: reduce) {
  .tcg-chip-preview { animation: none; }
}

/* ════════════════════════ command palette ════════════════════════ */

.tcg-palette-scrim {
  position: fixed;
  inset: 0;
  z-index: var(--z-palette);
  display: none;
  background: color-mix(in oklab, var(--bg) 55%, transparent);
  /* phone: full-screen sheet */
  padding: 0;
}
.tcg-palette-scrim.show {
  display: block;
}

.tcg-palette {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-elev-1);
  overflow: hidden;
  padding-top: env(safe-area-inset-top);
  animation: palette-in var(--transition-snap);
}
@keyframes palette-in {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.tcg-palette-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}
.tcg-palette-icon {
  display: inline-flex;
  color: var(--text-3);
}
.tcg-palette-input {
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 16px; /* >= 16px so iOS does not zoom */
  font-family: var(--font-sans);
}
.tcg-palette-input::placeholder {
  color: var(--text-4);
}
.tcg-palette-esc {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-4);
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  padding: 2px 5px;
}

.tcg-palette-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 6px 0 10px;
}
.tcg-palette-tier-label {
  padding: 10px 16px 4px;
}
.tcg-palette-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  cursor: pointer;
  min-height: 44px;
}
.tcg-palette-row.sel {
  background: var(--accent-soft);
  box-shadow: inset 2px 0 0 var(--accent);
}
.tcg-palette-row-eyebrow {
  flex-shrink: 0;
  min-width: 64px;
  color: var(--text-4);
}
.tcg-palette-row-label {
  flex: 1;
  min-width: 0;
  color: var(--text);
  font-size: var(--font-size-md);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tcg-palette-sub {
  font-size: var(--font-size-sm);
  color: var(--text-3);
  flex-shrink: 0;
  white-space: nowrap;
}
.tcg-palette-sc {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-3);
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  padding: 2px 6px;
  flex-shrink: 0;
}
.tcg-palette-empty {
  padding: 36px 16px;
  text-align: center;
  color: var(--text-4);
  font-size: var(--font-size-sm);
}
.tcg-palette-foot {
  display: flex;
  gap: 16px;
  padding: 10px 16px;
  border-top: 1px solid var(--border-soft);
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-4);
  flex-wrap: wrap;
}
.tcg-palette-foot kbd {
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  padding: 1px 4px;
  margin-right: 2px;
}

@media (min-width: 768px) /* --bp-md */ {
  .tcg-palette-scrim {
    padding: calc(10dvh / var(--ui-scale, 1)) 16px 16px;
    display: none;
  }
  .tcg-palette-scrim.show {
    display: flex;
    justify-content: center;
  }
  .tcg-palette {
    position: relative;
    inset: auto;
    width: min(640px, 100%);
    max-height: calc(70dvh / var(--ui-scale, 1));
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-pop);
  }
}

@media (prefers-reduced-motion: reduce) {
  .tcg-palette { animation: none; }
}

/* ════════════════════════ virtual grid ════════════════════════ */

.tcg-vgrid {
  position: relative;
  overflow-y: auto;
  height: 100%;
  -webkit-overflow-scrolling: touch;
}
.tcg-vgrid .vg-spacer {
  position: relative;
  width: 100%;
}
.tcg-vgrid .vg-window {
  position: absolute;
  inset: 0;
}
.tcg-vgrid .vg-header,
.tcg-vgrid .vg-row {
  position: absolute;
  left: 0;
  right: 0;
}
.tcg-vgrid .vg-row {
  display: grid;
}
.tcg-vgrid .vg-pinned {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg);
  will-change: transform;
}
.tcg-vgrid .vg-header,
.tcg-vgrid .vg-pinned {
  border-bottom: 1px solid var(--border-soft);
}
.vg-header-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 100%;
  padding: 0 6px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-2);
  text-align: left;
}
.vg-caret {
  display: inline-flex;
  color: var(--text-4);
  transition: transform var(--transition-fast);
}
.vg-caret.collapsed {
  transform: rotate(-90deg);
}
.vg-header-label {
  flex: 1;
  min-width: 0;
  font-size: var(--font-size-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.vg-header-count {
  color: var(--text-4);
}
.vg-cell {
  min-width: 0;
  overflow: hidden;
}
@media (prefers-reduced-motion: reduce) {
  .vg-caret { transition: none; }
}

/* ════════════════════════ fullscreen image viewer ════════════════════════ */
/* Generic full-viewport image inspector driven by sections/decks/fullscreen-
   viewer.js. Lives here (globally loaded) so any section can open it — the
   decks slot drawer and the styles detail keepers both reuse it. */

.fv-scrim {
  position: fixed; inset: 0; z-index: calc(var(--z-palette) + 10);
  background: oklch(0 0 0 / 0.88); display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 200ms ease; outline: none;
}
.fv-scrim.fv-open { opacity: 1; }
.fv-close {
  position: absolute; top: 16px; right: 16px; background: oklch(0 0 0 / 0.5);
  border: 1px solid oklch(1 0 0 / 0.15); color: oklch(1 0 0 / 0.8);
  width: 36px; height: 36px; border-radius: 50%; font-size: 16px;
  cursor: pointer; display: flex; align-items: center; justify-content: center; line-height: 1;
}
.fv-close:hover { background: oklch(0 0 0 / 0.7); color: #fff; }
.fv-stage {
  display: flex; align-items: center; justify-content: center;
  gap: 12px; max-width: 100%; padding: 16px;
}
.fv-nav {
  background: oklch(0 0 0 / 0.4); border: 1px solid oklch(1 0 0 / 0.15);
  color: oklch(1 0 0 / 0.7); width: 44px; height: 64px; border-radius: var(--r-md);
  font-size: 28px; cursor: pointer; flex-shrink: 0; display: flex;
  align-items: center; justify-content: center; line-height: 1;
}
.fv-nav:hover:not(:disabled) { background: oklch(0 0 0 / 0.6); color: #fff; }
.fv-nav:disabled { opacity: 0.25; cursor: default; }
.fv-card-wrap {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  max-height: calc(90dvh / var(--ui-scale, 1));
}
.fv-card-img {
  max-height: calc(86dvh / var(--ui-scale, 1)); max-width: calc(92vw / var(--ui-scale, 1));
  width: auto; border-radius: 10px; object-fit: contain; display: block;
  box-shadow: 0 8px 48px oklch(0 0 0 / 0.7);
}
.fv-card-ph { width: 220px; aspect-ratio: 63/88; border-radius: 10px; background: oklch(0.15 0 0); }
.fv-caption { font-family: var(--font-display); font-style: italic; font-size: 14px; color: oklch(1 0 0 / 0.7); }
