/* Cape gallery.
 *
 * Every contested rule is written `#tool-root #cgal …` — two ids — because css/tool-theme.css
 * loads after this file and claims buttons, links, chips, inputs and anything named *-card or
 * *-panel at one id. The generic button rule is (1,2,1); a plain `.cgal-chip.is-active` would
 * lose its background to it, exactly as the schematic viewer's selected tab once did.
 *
 * The preview stage, the texture figure and every thumbnail carry data-tnorm-skip in the markup:
 * their colours are Mojang's texture, and theme-normalize.js must not "fix" them.
 */

.cgal {
  width: min(100%, 1240px);
  container-type: inline-size;
  color: var(--fg);
}

.cgal-top {
  display: grid;
  grid-template-columns: minmax(240px, 340px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  margin-bottom: 16px;
}

#tool-root #cgal :is(.cgal-viewer, .cgal-info, .cgal-browse) {
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-width: 0;
}

/* ---------- viewer ---------- */

#tool-root #cgal .cgal-stage {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  aspect-ratio: 5 / 6;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    radial-gradient(circle at 50% 38%, color-mix(in srgb, var(--grass) 16%, transparent), transparent 62%),
    var(--surface-2);
}

#tool-root #cgal .cgal-stage canvas {
  display: block;
  max-width: 100%;
  height: auto;
  cursor: grab;
  touch-action: none;
}
#tool-root #cgal .cgal-stage canvas:active { cursor: grabbing; }

.cgal-view-row,
.cgal-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.cgal-view-row { margin-top: 12px; }

#tool-root #cgal .cgal-chip {
  min-width: 0;
  padding: 5px 11px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.4;
  color: var(--fg-muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}
#tool-root #cgal .cgal-chip:hover { color: var(--fg); border-color: var(--line-strong); }
#tool-root #cgal .cgal-chip.is-active {
  color: var(--grass-bright);
  background: var(--grass-deep);
  border-color: var(--grass);
}

/* ---------- details ---------- */

/* Text in the accent colour takes --grass-bright, never --grass: on the light theme --grass is
 * #059669, 3.77:1 on white — under AA for 12px — and theme-normalize.js was quietly repainting
 * these two to rescue them. --grass-bright is the ink of each theme's pair (#065f46 light, 7.7:1;
 * #34d399 dark). --grass stays right for borders, where 3:1 is the bar. */
#tool-root #cgal .cgal-kicker {
  margin: 0;
  color: var(--grass-bright);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1.6px;
  text-transform: uppercase;
}

#tool-root #cgal .cgal-name {
  margin: 2px 0 8px;
  font-size: 24px;
  line-height: 1.25;
}

.cgal-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 12px;
}

#tool-root #cgal .cgal-badge {
  display: inline-block;
  padding: 2px 9px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.6;
  color: var(--fg-muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
}
#tool-root #cgal .cgal-status { color: var(--fg); border-color: var(--line-strong); }
#tool-root #cgal :is(.cgal-status-open, .cgal-status-free) { color: var(--grass-bright); background: var(--grass-deep); }

#tool-root #cgal .cgal-how {
  margin: 0 0 12px;
  color: var(--fg);
  font-size: 15px;
  line-height: 1.6;
}

.cgal-facts {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 4px 14px;
  margin: 0 0 14px;
  font-size: 13px;
}
#tool-root #cgal .cgal-facts dt { color: var(--fg-dim); font-weight: 700; }
#tool-root #cgal .cgal-facts dd { margin: 0; color: var(--fg); min-width: 0; }
#tool-root #cgal .cgal-texid code {
  display: inline-block;
  max-width: 100%;
  padding: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
  color: inherit;
  background: none;
  border: 0;
  font-size: 12px;
}

#tool-root #cgal .cgal-texture {
  display: inline-block;
  margin: 0 0 14px;
  padding: 8px;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  /* a checkerboard, so the transparent parts of a texture read as transparent */
  background: repeating-conic-gradient(rgba(128, 128, 128, 0.22) 0 25%, transparent 0 50%) 0 0 / 16px 16px;
}
#tool-root #cgal .cgal-texture img {
  display: block;
  width: 256px;
  max-width: 100%;
  height: auto;
  image-rendering: pixelated;
}

.cgal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

#tool-root #cgal .cgal-btn {
  display: inline-flex;
  align-items: center;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--fg);
  text-decoration: none;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
}
#tool-root #cgal .cgal-btn:hover { border-color: var(--grass); }
#tool-root #cgal .cgal-btn-main {
  color: var(--grass-bright);
  background: var(--grass-deep);
  border-color: var(--grass);
}
#tool-root #cgal .cgal-btn[hidden] { display: none !important; }

#tool-root #cgal .cgal-sources {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
  margin: 0;
  font-size: 13px;
  color: var(--fg-muted);
}
#tool-root #cgal .cgal-sources-label {
  color: var(--fg-dim);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
}

/* ---------- browse ---------- */

.cgal-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
#tool-root #cgal .cgal-browse-title {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: var(--grass-bright);
}
#tool-root #cgal #cgal-search { width: min(100%, 260px); }

#tool-root #cgal .cgal-count {
  margin: 10px 0;
  font-size: 13px;
  color: var(--fg-dim);
}

.cgal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.cgal-grid > li { min-width: 0; }

#tool-root #cgal .cgal-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  height: 100%;
  padding: 12px 8px 10px;
  text-align: center;
  text-decoration: none;
  color: var(--fg);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: border-color 120ms, transform 120ms;
}
#tool-root #cgal .cgal-card:hover { border-color: var(--line-strong); transform: translateY(-1px); }
#tool-root #cgal .cgal-card.is-active {
  border-color: var(--grass);
  box-shadow: 0 0 0 1px var(--grass) inset;
}

/* The outside of the cape is x 1–10, y 1–16 of the 64×32 texture. Scaled 6×, that is a 60×96
 * window onto a 384×192 image shifted by one texel — pure CSS, one request per cape, and the
 * <img> keeps its alt text and native lazy loading. */
#tool-root #cgal .cgal-thumb {
  position: relative;
  display: block;
  flex: none;
  width: 60px;
  height: 96px;
  overflow: hidden;
  border-radius: 2px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}
#tool-root #cgal .cgal-thumb img {
  position: absolute;
  left: -6px;
  top: -6px;
  width: 384px;
  height: 192px;
  max-width: none;
  image-rendering: pixelated;
}

#tool-root #cgal .cgal-card-name {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
#tool-root #cgal .cgal-card-meta {
  font-size: 11.5px;
  line-height: 1.3;
  color: var(--fg-dim);
}

#tool-root #cgal .cgal-empty {
  grid-column: 1 / -1;
  padding: 18px;
  color: var(--fg-muted);
  text-align: center;
}

#tool-root #cgal .cgal-credit {
  margin: 14px 0 0;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--fg-dim);
}

/* Right-to-left: the texture id, the date range and the card grid are data, not prose. */
[dir="rtl"] #tool-root #cgal .cgal-texid code { direction: ltr; unicode-bidi: isolate; }

@container (max-width: 700px) {
  .cgal-top { grid-template-columns: minmax(0, 1fr); }
  #tool-root #cgal .cgal-stage { max-width: 340px; margin: 0 auto; width: 100%; }
}

@container (max-width: 420px) {
  .cgal-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
  #tool-root #cgal #cgal-search { width: 100%; }
}
