/* Section 03: eight operation families. Each card carries its own accent in --fam. */

/* --muted is about 4.3:1 on the card surface; small text in this section uses a lighter mix (about 6.2:1). */
#operations { --muted-hi: color-mix(in srgb, var(--muted) 55%, var(--text-2)); }

/* ---------- Toolbar ---------- */
.ops-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 12px 18px; margin: -8px 0 26px; }
.ops-dim button { display: inline-flex; align-items: baseline; gap: 6px; padding: 8px 16px; font-weight: 500; }
.ops-dim-shape { font: 500 11.5px/1 var(--font-mono); opacity: .75; }
.ops-hint { margin: 0; display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted-hi); }
.ops-pause { margin-left: auto; color: var(--text-2); }
.ops-pause svg { width: 14px; height: 14px; }
.ops-pause:hover { color: var(--text); }

/* ---------- Grid of cards ---------- */
.ops { position: relative; isolation: isolate; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.ops::before {
  content: ""; position: absolute; z-index: -1; inset: -80px 0; pointer-events: none;
  background:
    radial-gradient(40% 45% at 22% 28%, rgba(53, 208, 240, .07), transparent 70%),
    radial-gradient(40% 45% at 55% 50%, rgba(139, 124, 246, .06), transparent 70%),
    radial-gradient(40% 45% at 82% 76%, rgba(227, 93, 159, .06), transparent 70%);
}
.op-cell { min-width: 0; display: flex; }

.op-card {
  --fam: var(--accent);
  position: relative; isolation: isolate; overflow: hidden; flex: 1; min-width: 0; container-type: inline-size;
  display: flex; flex-direction: column; gap: 12px; padding: 16px 14px 18px;
  border-radius: 22px; cursor: pointer; outline: none;
  transition: transform .35s cubic-bezier(.2, .7, .2, 1), border-color .3s, box-shadow .35s;
  will-change: transform;
}
/* Faint corner glow in the family hue. */
.op-card::before {
  content: ""; position: absolute; z-index: -1; pointer-events: none;
  width: 260px; height: 260px; top: -150px; right: -120px; border-radius: 50%;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--fam) 40%, transparent), transparent);
  opacity: .62; transition: opacity .4s, transform .6s cubic-bezier(.2, .7, .2, 1);
}
.op-card::after {
  content: ""; position: absolute; z-index: -1; pointer-events: none; inset: 0; border-radius: inherit;
  background: radial-gradient(120% 60% at 0% 100%, color-mix(in srgb, var(--fam) 7%, transparent), transparent 60%);
  opacity: 0; transition: opacity .4s;
}
.op-card:hover, .op-card:focus-visible {
  transform: translateY(-6px);
  border-color: color-mix(in srgb, var(--fam) 48%, transparent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--fam) 16%, transparent), 0 30px 60px -30px color-mix(in srgb, var(--fam) 60%, transparent), var(--shadow);
}
.op-card:focus-visible { outline: 2px solid var(--fam); outline-offset: 3px; }
.op-card:hover::before, .op-card:focus-visible::before { opacity: 1; transform: scale(1.18); }
.op-card:hover::after, .op-card:focus-visible::after { opacity: 1; }

.op-head { position: relative; min-height: 42px; }
.op-id { display: grid; gap: 5px; min-width: 0; }
.op-name {
  font: 600 18px/1 var(--font-mono); letter-spacing: .01em; color: var(--fam);
  text-shadow: 0 0 22px color-mix(in srgb, var(--fam) 45%, transparent);
}
.op-full { font-size: 13.5px; line-height: 1.2; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.op-more {
  position: absolute; top: -4px; right: 0; display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 10px 0 11px; border-radius: 999px;
  font-size: 12.5px; font-weight: 500; color: var(--fam);
  background: color-mix(in srgb, var(--fam) 13%, transparent); border: 1px solid color-mix(in srgb, var(--fam) 26%, transparent);
  opacity: 0; transform: translateX(-6px); transition: opacity .25s, transform .3s cubic-bezier(.2, .7, .2, 1);
}
.op-arrow { display: inline-block; transition: transform .3s cubic-bezier(.2, .7, .2, 1); }
.op-card:hover .op-more, .op-card:focus-visible .op-more { opacity: 1; transform: none; }
.op-card:hover .op-arrow { transform: translateX(2px); }

/* Stage: the 2D and 3D canvases sit on top of each other and cross-fade. */
.op-stage {
  position: relative; aspect-ratio: 1; border-radius: 14px; overflow: hidden;
  background: var(--bg-soft); border: 1px solid var(--line);
  transition: border-color .3s;
}
.op-stage::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .6s;
  background:
    radial-gradient(60% 42% at 50% 72%, color-mix(in srgb, var(--fam) 13%, transparent), transparent 75%),
    radial-gradient(80% 60% at 50% 30%, rgba(255, 255, 255, .025), transparent 70%);
}
.op-card:hover .op-stage { border-color: color-mix(in srgb, var(--fam) 22%, var(--line)); }
/* --i (card index) staggers the switch into a wave across the grid. */
.op-stage canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  transition: opacity .45s ease, transform .6s cubic-bezier(.2, .7, .2, 1);
  transition-delay: calc(var(--i, 0) * 45ms);
}
.op-stage .c3 { opacity: 0; transform: scale(.94); pointer-events: none; }
.ops[data-dim="3"] .op-stage::before { opacity: 1; }
.ops[data-dim="3"] .op-stage .c2 { opacity: 0; transform: scale(1.04); pointer-events: none; }
.ops[data-dim="3"] .op-stage .c3 { opacity: 1; transform: none; }
/* Step readout under the stage: T with a hairline track, then the event itself. */
.op-step { display: grid; gap: 6px; min-width: 0; margin-top: -1px; font: 500 11px/1.4 var(--font-mono); color: var(--text-2); }
.op-tl { display: flex; align-items: center; gap: 9px; color: var(--text-2); font-size: 11.5px; }
.op-t { flex: none; }
.op-t b { display: inline-block; min-width: 2ch; color: var(--fam); font-weight: 600; font-size: 12px; }
.op-n { flex: none; }
.op-prog { position: relative; flex: 1; height: 2px; border-radius: 2px; background: rgba(160, 180, 220, .1); overflow: hidden; }
.op-prog i {
  position: absolute; inset: 0; transform-origin: 0 50%; transform: scaleX(0); border-radius: inherit;
  background: linear-gradient(90deg, color-mix(in srgb, var(--fam) 25%, transparent), var(--fam));
  transition: transform .5s cubic-bezier(.2, .7, .2, 1);
}
/* The longest event has 39 characters (39 x 0.575em wide). It stays on one line at 11px or more while
   the card is wide enough; narrower cards keep 11px and wrap it into a reserved second line. */
.op-ev { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; letter-spacing: -0.025em; font-size: clamp(11px, calc(100cqi / 22.6), 11.5px); }
@container (max-width: 248px) {
  .op-ev { white-space: normal; overflow-wrap: anywhere; text-overflow: clip; min-height: 2.8em; }
}
.op-ev b { color: var(--text); font-weight: 600; }
.op-init { color: var(--muted-hi); }

.op-desc { margin: 0; font-size: 14.5px; line-height: 1.5; color: var(--text-2); text-wrap: pretty; }

/* ---------- Dialog ---------- */
dialog.op-dialog {
  --fam: var(--accent);
  width: min(780px, calc(100% - 32px)); max-height: min(880px, calc(100% - 40px)); padding: 0;
  border: 1px solid var(--line-strong); border-radius: 20px; color: var(--text);
  background: linear-gradient(180deg, rgba(255, 255, 255, .03), rgba(255, 255, 255, 0) 30%) var(--surface);
  box-shadow: var(--shadow-lg), 0 50px 120px -40px rgba(0, 0, 0, .9);
  overflow: hidden auto; overscroll-behavior: contain; isolation: isolate;
}
dialog.op-dialog[open] { animation: dlg-in .34s cubic-bezier(.2, .8, .2, 1); }
dialog.op-dialog::backdrop { background: rgba(3, 5, 10, .62); backdrop-filter: blur(10px) saturate(120%); -webkit-backdrop-filter: blur(10px) saturate(120%); }
dialog.op-dialog[open]::backdrop { animation: dlg-fade .3s ease; }
@keyframes dlg-in { from { opacity: 0; transform: translateY(16px) scale(.98); } }
@keyframes dlg-fade { from { opacity: 0; } }
.dlg-glow {
  position: absolute; z-index: -1; top: 0; left: 0; right: 0; height: 380px; pointer-events: none; border-radius: 20px 20px 0 0;
  background: radial-gradient(300px 240px at 100% 0%, color-mix(in srgb, var(--fam) 24%, transparent), transparent 75%);
}

/* The close button is a direct child of the dialog, so it stays pinned while the dialog scrolls.
   Its negative bottom margin lets the header start at the dialog top; the header reserves room on the right. */
.op-dialog > .dlg-x { position: sticky; top: 16px; z-index: 3; margin: 26px 28px -64px auto; background: var(--surface); }
.dlg-head { padding: 26px 82px 8px 28px; }
.dlg-op { font: 600 15px/1 var(--font-mono); letter-spacing: .02em; color: var(--fam); text-shadow: 0 0 22px color-mix(in srgb, var(--fam) 50%, transparent); }
.dlg-head h3 { margin: 10px 0 0; font: 700 clamp(28px, 4vw, 36px)/1.05 var(--font-display); letter-spacing: -0.03em; }
.dlg-one { margin: 10px 0 0; font-size: 16px; color: var(--text-2); }
.dlg-x {
  flex: none; width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; cursor: pointer;
  border: 1px solid var(--line-strong); background: rgba(255, 255, 255, .03); color: var(--text-2);
  transition: color .2s, border-color .2s, transform .25s, background .2s;
}
.dlg-x svg { width: 16px; height: 16px; }
.dlg-x:hover { color: var(--text); border-color: var(--text-2); transform: rotate(90deg); background: color-mix(in srgb, var(--surface) 88%, #fff); }

.dlg-body { padding: 18px 28px 26px; display: grid; gap: 20px; }
.dlg-ex {
  padding: 18px 20px 16px; border-radius: 16px; border: 1px solid var(--line);
  background: radial-gradient(70% 90% at 100% 0%, color-mix(in srgb, var(--fam) 7%, transparent), transparent 70%), var(--bg-soft);
  display: grid; gap: 6px;
}
.dlg-ex-head { display: flex; align-items: baseline; justify-content: space-between; gap: 4px 12px; flex-wrap: wrap; margin-bottom: 6px; }
.dlg-ex h4, .dlg-def dt { margin: 0; font: 600 15px/1.2 var(--font-display); letter-spacing: -0.01em; color: var(--text); }
.dlg-ex-note { font-size: 13px; color: var(--text-2); }
/* Labels and strips share one centered two-column grid, so the example sits in the middle of the panel. */
.strip-grid { display: grid; grid-template-columns: 52px auto; justify-content: center; align-items: center; gap: 6px 14px; }
.strip-grid .k { font-size: 13px; color: var(--text-2); }
.strip-grid .k:not(:empty) { padding-bottom: 24px; } /* center on the cells, not on cells plus index labels */
.strip { min-width: 0; }
.strip svg { width: auto; max-width: 100%; height: auto; overflow: visible; }
.strip-key { margin: 2px 0 0; display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); }
.strip-key i { width: 14px; height: 14px; flex: none; border-radius: 4px; border: 2px solid var(--fam); }
.strip-ev {
  justify-self: start; display: inline-flex; align-items: center; gap: 8px; max-width: 100%;
  padding: 6px 12px 6px 9px; border-radius: 16px; margin: 4px 0;
  background: color-mix(in srgb, var(--fam) 11%, transparent); border: 1px solid color-mix(in srgb, var(--fam) 28%, transparent);
  color: var(--fam);
}
.strip-ev svg { width: 14px; height: 14px; flex: none; }
.strip-ev code { font: 500 12.5px/1.35 var(--font-mono); color: var(--text); overflow-wrap: anywhere; }

.dlg-def { margin: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 24px; }
.dlg-def > div { padding-left: 14px; border-left: 2px solid color-mix(in srgb, var(--fam) 45%, transparent); }
.dlg-def dd { margin: 6px 0 0; font-size: 14.5px; line-height: 1.5; color: var(--text-2); }

.dlg-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.dlg-chip { height: auto; min-height: 28px; padding: 5px 11px; white-space: normal; line-height: 1.35; font-size: 12px; color: var(--text); }
.dlg-chip .k { color: var(--muted-hi); }

.op-dialog details.disclosure > summary { font-size: 14px; }
.op-dialog .rule-text { max-height: 340px; overflow: auto; }

.dlg-foot {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px 16px;
  /* margin-top: 0 overrides the site footer rule; no part of the dialog's own box shows between body and footer. */
  margin-top: 0; padding: 16px 28px 22px; border-top: 1px solid var(--line); background: rgba(6, 8, 14, .45);
}
.dlg-src { margin: 0; flex: 1 1 300px; min-width: 0; font-size: 12.5px; line-height: 1.5; color: var(--muted-hi); }
.dlg-src code { font: 500 11.5px/1.5 var(--font-mono); color: var(--text-2); overflow-wrap: anywhere; }
.dlg-navs { display: flex; gap: 8px; }
.dlg-nav { font-family: var(--font-mono); font-size: 12.5px; color: var(--text-2); }
.dlg-nav svg { width: 14px; height: 14px; }
.dlg-nav:hover { color: var(--text); border-color: color-mix(in srgb, var(--fam) 60%, transparent); }

/* The page behind the modal does not scroll. body's overflow-x is switched to clip so it does not
   become its own scroll container (which would detach sticky elements in other sections). */
html:has(#op-dialog[open]) { overflow: hidden; scrollbar-gutter: stable; }
html:has(#op-dialog[open]) body { overflow-x: clip; }

.ops-dots { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1080px) {
  .ops { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
}
@media (max-width: 640px) {
  /* Phones: one swipeable row instead of eight stacked cards; the next card peeks in as the cue.
     The top padding leaves room for a focused card's lift and focus ring. */
  .ops {
    display: flex; gap: 12px; overflow-x: auto; overscroll-behavior-x: contain;
    scroll-snap-type: x mandatory; scroll-padding-inline: var(--gutter); scrollbar-width: none;
    margin: -10px calc(-1 * var(--gutter)) -4px; padding: 14px var(--gutter) 12px;
  }
  .ops::-webkit-scrollbar { display: none; }
  .ops::before { inset: 0; }
  .ops > .op-cell { flex: 0 0 min(84%, 340px); scroll-snap-align: start; }
  .ops-dots { display: flex; justify-content: center; gap: 6px; margin-top: 12px; }
  .ops-dots i { width: 6px; height: 6px; border-radius: 3px; background: rgba(148, 170, 205, .28); transition: width .25s ease, background .25s ease; }
  .ops-dots i.is-on { width: 18px; background: var(--accent); }
  .ops-bar { gap: 12px; margin-top: -12px; }
  .ops-hint { order: 3; flex-basis: 100%; font-size: 13.5px; }
  .op-card { padding: 16px 16px 18px; }
  .op-step, .op-ev { font-size: 12px; }
  dialog.op-dialog { width: calc(100% - 20px); max-width: calc(100% - 20px); max-height: calc(100% - 24px); border-radius: 18px; }
  .op-dialog > .dlg-x { top: 12px; margin: 20px 18px -58px auto; }
  .dlg-head { padding: 20px 68px 6px 18px; }
  .dlg-body { padding: 14px 18px 22px; gap: 16px; }
  .dlg-ex { padding: 14px 14px 12px; }
  .strip-grid { grid-template-columns: minmax(0, 1fr); justify-content: stretch; gap: 4px; }
  .strip-grid .k:empty { display: none; }
  .strip-grid .k:not(:empty) { padding-bottom: 0; }
  .dlg-def { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .dlg-foot { padding: 14px 18px 18px; }
  .dlg-navs { width: 100%; justify-content: space-between; }
}
/* Touch screens have no hover, so the dialog affordance stays visible. */
@media (hover: none) {
  .op-more { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .op-card, .op-card::before, .op-stage canvas, .op-prog i, .op-more, .dlg-x, .ops-dots i { transition: none; }
}

/* Exact text: show "<=" and "->" as typed, not as font ligatures. */
.op-step, .strip-ev code, .dlg-src code, .op-dialog .rule-text { font-variant-ligatures: none; font-feature-settings: "liga" 0, "calt" 0; }
