/* ============================================================
   DAVIDE SEGA — overlays
   Case study, glossary, extended bio, legal. One shell, four
   contents. Each is a scrollable reading surface, not a dialog box.
   ============================================================ */

/* `display: grid` below out-specifies the UA rule for [hidden], so the
   attribute has to be honoured explicitly. Getting this wrong is what
   forces the usual `visibility: hidden` workaround — and a
   visibility-hidden element cannot take focus, which silently breaks
   keyboard access to the dialog. */
.ov[hidden] { display: none; }

.ov {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  display: grid;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--bg);
  opacity: 0;
  transform: translate3d(0, 2.5%, 0);
  transition: opacity var(--d-mid) var(--e-glide),
              transform var(--d-slow) var(--e-glide);
}
.ov.is-open { opacity: 1; transform: none; }
.ov:focus { outline: none; }

/* Close control rides above the scrolling content. */
.ov__close {
  position: sticky;
  top: 1.1rem;
  z-index: 2;
  justify-self: end;
  margin-right: var(--gutter);
  margin-bottom: -3.4rem;
  display: inline-flex; align-items: center; gap: 0.8rem;
  padding: 0.6rem 0.65rem 0.6rem 1.25rem;
  border: 1px solid var(--hair-2);
  border-radius: var(--r-pill);
  background: color-mix(in oklab, var(--bg) 78%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  font-size: var(--t-small); font-weight: 500;
  transition: border-color var(--d-hover) ease,
              background-color var(--d-hover) ease,
              transform var(--d-press) var(--e-out);
}
.ov__close:hover { border-color: var(--hair-3); }
.ov__close .btn__ico { width: 1.9rem; height: 1.9rem; background: var(--accent-soft); }
@media (hover: hover) and (pointer: fine) {
  .ov__close:hover .btn__ico { transform: rotate(90deg); }
}

.ov__inner { padding-block: 5.5rem clamp(4rem, 9vw, 8rem); }

.ov__head { margin-bottom: clamp(3rem, 6vw, 5rem); }
.ov__title {
  font-size: var(--t-h2);
  letter-spacing: -0.045em;
  margin-top: 1.4rem;
  max-width: 20ch;
}
.ov__lead { margin-top: 1.6rem; }

/* Content inside an overlay staggers in once the overlay is open. */
.ov [data-stagger] {
  opacity: 0;
  transform: translateY(1.6rem);
  transition: opacity var(--d-mid) var(--e-out), transform var(--d-slow) var(--e-out);
}
.ov.is-open [data-stagger] {
  opacity: 1; transform: none;
  transition-delay: calc(var(--i, 0) * 55ms + 120ms);
}
@media (prefers-reduced-motion: reduce) {
  .ov, .ov [data-stagger] { transform: none !important; }
}

/* ------------------------------------------------------ Case study */

.cs__cover { margin-bottom: clamp(3rem, 6vw, 5rem); }
.cs__cover .plate__core { aspect-ratio: 16 / 10; }
.cs__cover img { width: 100%; height: 100%; object-fit: cover; }

.cs__section {
  display: grid; gap: var(--sp-5);
  padding-block: clamp(2.5rem, 5vw, 4rem);
  border-top: 1px solid var(--hair);
}
@media (min-width: 900px) {
  .cs__section { grid-template-columns: minmax(0, 4fr) minmax(0, 7fr); gap: var(--sp-8); }
}
.cs__kicker { font-size: var(--t-h4); font-weight: 500; letter-spacing: -0.028em; line-height: 1.15; }
.cs__kicker .num { display: block; margin-bottom: 0.9rem; }
.cs__body p { color: var(--fg-2); max-width: var(--measure); }
.cs__body p + p { margin-top: 1.1rem; }

.cs__bullets { margin-top: 2rem; display: grid; gap: 1px; background: var(--hair); border-block: 1px solid var(--hair); }
.cs__bullet { background: var(--bg); padding: 1.5rem 0; }
.cs__bullet h4 { font-size: var(--t-body); font-weight: 500; letter-spacing: -0.02em; margin-bottom: 0.6rem; }
.cs__bullet p { font-size: var(--t-small); color: var(--fg-2); }

.cs__figures { display: grid; gap: var(--sp-5); margin-top: clamp(3rem, 6vw, 5rem); }
@media (min-width: 760px) { .cs__figures { grid-template-columns: 1fr 1fr; } }
.cs__figures figure .plate__core { aspect-ratio: 4 / 3; }
.cs__figures img { width: 100%; height: 100%; object-fit: cover; }
.cs__figures figcaption {
  margin-top: 0.9rem;
  font-family: var(--f-mono); font-size: var(--t-micro);
  letter-spacing: 0.1em; color: var(--fg-3);
}
.cs__figures .is-wide { grid-column: 1 / -1; }
.cs__figures .is-wide .plate__core { aspect-ratio: 16 / 9; }

/* -------------------------------------------------------- Glossary */

.gl__grid { display: grid; gap: 1px; background: var(--hair); border-block: 1px solid var(--hair); }
@media (min-width: 780px) { .gl__grid { grid-template-columns: 1fr 1fr; } }
.gl__item {
  background: var(--bg);
  padding: clamp(1.4rem, 3vw, 2rem) clamp(1rem, 2.5vw, 1.8rem);
  transition: background-color var(--d-mid) var(--e-out);
}
.gl__item:hover { background: var(--surface-1); }
.gl__term {
  display: flex; align-items: baseline; gap: 0.9rem;
  font-size: var(--t-body); font-weight: 500; letter-spacing: -0.02em;
  margin-bottom: 0.7rem;
}
.gl__term .num { flex: 0 0 auto; }
.gl__def { font-size: var(--t-small); color: var(--fg-2); }

/* ----------------------------------------------------------- Legal */

.lg__tabs {
  display: inline-flex; gap: 3px; padding: 3px;
  border: 1px solid var(--hair); border-radius: var(--r-pill);
  margin-bottom: clamp(2.5rem, 5vw, 4rem);
}
.lg__tabs button {
  padding: 0.55rem 1.2rem;
  border-radius: var(--r-pill);
  font-size: var(--t-small);
  color: var(--fg-3);
  transition: background-color var(--d-mid) var(--e-out), color var(--d-mid) var(--e-out);
}
.lg__tabs button[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); }

.lg__block { padding-block: clamp(1.6rem, 3vw, 2.2rem); border-top: 1px solid var(--hair); }
@media (min-width: 900px) {
  .lg__block { display: grid; grid-template-columns: minmax(0, 4fr) minmax(0, 7fr); gap: var(--sp-8); }
}
.lg__block h3 { font-size: var(--t-body); font-weight: 500; letter-spacing: -0.02em; }
.lg__block p { font-size: var(--t-small); color: var(--fg-2); max-width: var(--measure); }
@media (max-width: 899px) { .lg__block h3 { margin-bottom: 0.7rem; } }
.lg__panel[hidden] { display: none; }

/* ---------------------------------------------------- Extended bio */

.bio__grid { display: grid; gap: var(--sp-6); }
@media (min-width: 900px) { .bio__grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: var(--sp-8); } }
.bio__grid p { color: var(--fg-2); }
.bio__grid p + p { margin-top: 1.1rem; }


/* Fifteen glossary cards arriving together is a wall. A 22ms step is
   below the threshold where it reads as a queue, but it gives the grid
   a direction to be read in. Capped at ten so the last card is never
   more than a quarter-second behind the first. */
/* One declaration, not two: a second `transition` shorthand further
   down the file replaces the first outright, which would silently drop
   the hover fade defined above. */
.gl__item {
  transition: opacity var(--d-panel) var(--e-out),
              transform var(--d-panel) var(--e-out),
              background-color var(--d-hover) ease;
  transition-delay: calc(min(var(--i, 0), 10) * 22ms + 180ms), calc(min(var(--i, 0), 10) * 22ms + 180ms), 0s;
}
.ov:not(.is-open) .gl__item {
  opacity: 0;
  transform: translateY(12px);
}
@media (prefers-reduced-motion: reduce) {
  .ov:not(.is-open) .gl__item { transform: none; }
}
