/* Figure: one tab per semantic direction, each applied to several faces.
   Behaviour lives in static/js/attribute-tabs.js;
   markup is <d-figure id="attribute-tabs-figure"> in src/index.html. */

/* Colours come from the shared theme (static/js/theme.js), which also handles
   the light/dark switch; the literals here are only fallbacks for if it fails
   to load. */
.atb {
  --atb-surface: var(--vx-surface, #fcfcfb);
  --atb-ink: var(--vx-ink, #16160f);
  --atb-muted: var(--vx-muted, #6b6a63);
  --atb-rule: var(--vx-rule, #d8d7cf);
  --atb-block: var(--vx-block, #ebeae2);
  --atb-accent: var(--vx-accent, #eb6834);
  margin: 2rem 0 2.5rem;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, sans-serif;
}

/* Text column, like the article's other figures, which puts each of the four
   faces at ~144px. If the screenshots want more room, this figure is the one
   candidate for `grid-column: page` — the grid and the rail both stretch. */
d-figure#attribute-tabs-figure {
  grid-column: text;
}

/* ---- micro-label above the tab strip ---- */
.atb-head {
  font-size: 11px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--atb-muted);
  margin-bottom: 6px;
}

/* ---- tabs ---- */
/* The strip scrolls rather than wraps: five directions on one line is the whole
   point of the control, and a wrapped second row reads as a second group. */
.atb-tabs {
  display: flex;
  gap: 0;
  overflow-x: auto;
  border-bottom: 1px solid var(--atb-rule);
  scrollbar-width: none;
}
.atb-tabs::-webkit-scrollbar {
  display: none;
}

.atb-tab {
  font: inherit;
  font-size: 13px;
  line-height: 1;
  flex: none;
  padding: 9px 14px;
  color: var(--atb-muted);
  background: transparent;
  border: none;
  /* The selected underline sits *on* the strip's own rule, so switching tabs
     moves one mark instead of thickening the border. */
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  white-space: nowrap;
}
.atb-tab:hover {
  color: var(--atb-ink);
}
.atb-tab.is-active {
  color: var(--atb-ink);
  font-weight: 700;
  border-bottom-color: var(--atb-accent);
}
.atb-tab:focus-visible {
  outline: 2px solid var(--atb-ink);
  outline-offset: -2px;
  border-radius: 3px 3px 0 0;
}

/* ---- panel ---- */
.atb-panel {
  padding-top: 12px;
}
.atb-note {
  margin: 0 0 12px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--atb-muted);
}
.atb-note b {
  font-weight: 700;
  color: var(--atb-ink);
}
.atb-note sub {
  font-size: 0.72em;
}

/* ---- the example grid ---- */
.atb-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}
.atb-cell {
  margin: 0;
  min-width: 0;
}

.atb-frame {
  position: relative;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: 3px;
  background: var(--atb-block);
  cursor: crosshair;
}
.atb-frame:focus-visible {
  outline: 2px solid var(--atb-ink);
  outline-offset: 2px;
}
/* A hairline over the image rather than a border under it, so the frame does not
   change size between a loaded render and a placeholder. */
.atb-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 4; /* above both image buffers, which take z-index 1 and 2 while swapping */
  border: 1px solid var(--atb-rule);
  border-radius: 3px;
  pointer-events: none;
}

/* Two stacked buffers per tile: the outgoing render stays fully opaque until the
   incoming one has decoded, so scrubbing never flashes the empty tile. */
.atb-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  display: block;
}

/* A missing render reads as "not here yet", not as a broken image. */
.atb-missing {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 8px;
  text-align: center;
  background: repeating-linear-gradient(
    45deg,
    transparent 0 5px,
    var(--atb-rule) 5px 7px
  );
}
.atb-frame.is-missing .atb-missing {
  display: flex;
}
.atb-missing span {
  font-size: 11px;
  font-weight: 700;
  color: var(--atb-muted);
  background: var(--atb-surface);
  padding: 2px 6px;
  border-radius: 3px;
}

/* Signed step size, bottom-left of each tile. */
.atb-badge {
  position: absolute;
  left: 6px;
  bottom: 6px;
  z-index: 3;
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--atb-ink);
  background: var(--atb-surface);
  padding: 2px 6px;
  border-radius: 3px;
  border: 1px solid var(--atb-rule);
  pointer-events: none;
}
.atb-badge.is-zero {
  color: var(--atb-muted);
}
/* While the tile is showing the unedited face for comparison. */
.atb-badge.is-compare {
  color: var(--atb-surface);
  background: var(--atb-ink);
  border-color: var(--atb-ink);
}

.atb-cap {
  margin-top: 5px;
  font-size: 11px;
  color: var(--atb-muted);
  font-variant-numeric: tabular-nums;
}

/* ---- step-size rail ---- */
.atb-controls {
  margin-top: 14px;
}
.atb-rail-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.atb-end {
  flex: none;
  font-size: 11px;
  color: var(--atb-muted);
  white-space: nowrap;
}
.atb-end-neg {
  text-align: right;
}

/* The ticks are positioned against the thumb's own travel (half a thumb in from
   each edge), so "0" sits under the thumb when the slider is centred. */
.atb-rail {
  position: relative;
  flex: 1 1 auto;
  min-width: 120px;
  --atb-thumb: 18px;
}
.atb-range {
  display: block;
  width: 100%;
  margin: 0;
  accent-color: var(--atb-accent);
}
.atb-ticks {
  position: relative;
  height: 16px;
  margin-top: 2px;
}
.atb-tick {
  position: absolute;
  top: 0;
  left: calc(var(--atb-thumb) / 2 + var(--t) * (100% - var(--atb-thumb)));
  transform: translateX(-50%);
  font: inherit;
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  padding: 2px 3px;
  color: var(--atb-muted);
  background: transparent;
  border: none;
  cursor: pointer;
}
.atb-tick:hover {
  color: var(--atb-ink);
}
.atb-tick.is-current {
  color: var(--atb-accent);
  font-weight: 700;
}

/* ---- readout line ---- */
.atb-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-top: 8px;
}
.atb-readout {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 13px;
  color: var(--atb-ink);
  font-variant-numeric: tabular-nums;
  min-width: 5.5em;
}
.atb-readout em {
  font-size: 12px;
  color: var(--atb-muted);
}
.atb-btn {
  font: inherit;
  font-size: 12px;
  line-height: 1;
  padding: 6px 12px;
  color: inherit;
  background: transparent;
  border: 1px solid var(--atb-rule);
  border-radius: 4px;
  cursor: pointer;
}
.atb-btn:hover {
  border-color: var(--atb-muted);
}
.atb-btn.is-on {
  color: var(--atb-surface);
  background: var(--atb-ink);
  border-color: var(--atb-ink);
}
.atb-hint {
  margin-left: auto;
  font-size: 12px;
  font-style: italic;
  color: var(--atb-muted);
}

@media screen and (max-width: 768px) {
  .atb-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  /* The end labels cost more width than they earn once the rail is this narrow;
     the tick signs and the readout still name the direction. */
  .atb-end {
    display: none;
  }
  .atb-hint {
    margin-left: 0;
    flex-basis: 100%;
  }
}
