/* Explorer page layout (DESIGN.md §7.1): sidebar + full-bleed viewport. */

.explorer {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
}

/* The sidebar is a full-height panel with its own scroll, sections divided by
   hairlines (see fieldset in widgets.css) — the aperiodic-circuits layout. */
.explorer-sidebar {
  min-width: 0;
  height: calc(100dvh - var(--site-header-h));
  overflow: auto;
  display: flex;
  flex-direction: column;
  padding: 4px 16px 24px;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.explorer-viewport {
  display: flex;
  flex-direction: column;
  /* Deterministic height (mirrors the sidebar): the viewport must never
     size itself from its own canvas, or resize feedback loops the layout. */
  height: calc(100dvh - var(--site-header-h));
  min-height: 420px;
  min-width: 0;
  overflow: hidden;
  background: var(--canvas-bg);
  color: var(--text);
}
.explorer-viewport .panzoom {
  height: 100%;
}
/* The canvas and everything drawn over it; the combination bar sits underneath.
   Its height comes from the viewport (minus the bar), never from the canvas. */
.explorer-field {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
}
/* Under the field: the bar, its tiles in one row (`tilesInRow`). */
.explorer-combo {
  flex: 0 0 auto;
  padding: 6px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

/* Infinite mode: the map's viewport, re-fitted into the explorer's own
   deterministically-sized container. Height comes from the PARENT (100%),
   never from the canvas — same layout rule, one level up. */
.explorer-viewport .map-viewport.explorer-infinite {
  height: 100%;
  min-height: 0;
  border: none;
  border-radius: 0;
}

/* Rooted / infinite switch. */
.mode-row {
  align-items: center;
}
.mode-switch {
  display: inline-flex;
  gap: 4px;
}
.mode-switch button {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font: inherit;
}
.mode-switch button.is-active {
  border-color: var(--text);
  background: var(--text);
  color: var(--panel);
}
.mode-switch button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Inline "do this instead" affordance inside a badge/paragraph. */
.link-button {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}

.is-unavailable legend {
  opacity: 0.6;
}
.map-hud-error {
  color: var(--danger);
}

/* Mobile: the sidebar becomes a scrollable sheet under the viewport. */
@media (max-width: 900px) {
  .explorer {
    grid-template-columns: minmax(0, 1fr);
  }
  .explorer-sidebar {
    height: auto;
    order: 2;
    border-right: none;
    border-top: 1px solid var(--line);
  }
  .explorer-viewport {
    order: 1;
    height: calc(100dvh - var(--site-header-h));
    min-height: 480px;
  }
}

/* Level stepper (also used by the dev gallery's own stylesheet). */
.level-stepper {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.level-stepper button {
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 5px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}
.level-stepper em {
  font-style: normal;
  font-size: 11px;
  color: var(--muted);
}

.explorer-matchings .matching-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
}

.tool-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}
.tool-row button {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}
.tool-row button.is-active {
  border-color: var(--text);
  background: var(--text);
  color: var(--panel);
}

.explorer-advanced {
  padding: 12px 0;
}
.explorer-advanced summary {
  cursor: pointer;
  font-size: 13px;
}
.contract-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  margin: 4px 0;
}
.contract-row .contract-name {
  min-width: 74px;
  color: var(--muted);
}
.contract-row.is-inactive .contract-name,
.contract-row.is-inactive em {
  opacity: 0.5;
}
.contract-row em {
  min-width: 52px;
  text-align: right;
  font-style: normal;
  color: var(--muted);
}

.tiling-overlays {
  color: var(--text);
  pointer-events: none;
}

.analysis-veil {
  position: absolute;
  inset: auto 12px 12px auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  font-size: 12px;
}
.spinner {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  animation: explorer-spin 800ms linear infinite;
}
@keyframes explorer-spin {
  to {
    transform: rotate(360deg);
  }
}

.viewport-caption {
  position: absolute;
  left: 12px;
  bottom: 10px;
  font-size: 12px;
  pointer-events: none;
}

.share-pin {
  align-self: flex-start;
}

/* The hexagons ↔ Spectres morph plays over (and hides) the live view. */
.explorer-viewport .morph-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: var(--panel);
  pointer-events: none;
  z-index: 5;
}

/* Flow overlay summary under the display toggles. */
.flow-summary {
  margin: 6px 0 10px;
  font-size: 12px;
  line-height: 1.5;
}
.flow-key {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  vertical-align: baseline;
}
.flow-key.is-source {
  background: #2ea043;
}
.flow-key.is-sink {
  background: #e5534b;
}


/* Every tile's matching at once: aperiodic-circuits' "next combination". */
/* Decomposition: the factors a rule's pairings force, and its loops by vector. */
.decomposition-factors {
  margin: 0 0 4px;
  font-size: 13px;
}
.decomposition-atom {
  color: var(--accent);
  font-size: 9px;
  margin-left: 2px;
  vertical-align: super;
}
.decomposition-note {
  font-size: 12px;
  margin: 4px 0;
}
.decomposition-sub {
  font-size: 12px;
  font-weight: 600;
  margin: 8px 0 4px;
}
.decomposition-groups {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.decomposition-groups button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  padding: 2px 7px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.decomposition-groups button[aria-pressed='true'] {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

/* Infinite mode's circuit stats: lengths found on screen, in their ink. */
.infinite-length-chips {
  list-style: none;
  margin: 4px 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  font-size: 12px;
}
.infinite-length-chips li {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 7px;
  background: var(--panel-2);
}
.infinite-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

/* X-ray: supertile outlines over the tiling. The layer lets the pointer
   through to the viewport, which it listens on for hover. */
.xray-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.xray-layer canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.xray-tip {
  position: absolute;
  padding: 3px 7px;
  border-radius: var(--radius);
  background: rgba(8, 10, 16, 0.82);
  color: #e7ecf6;
  font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: nowrap;
}
.xray-control {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 9px;
  border: 1px solid rgba(244, 246, 251, 0.28);
  border-radius: var(--radius);
  background: rgba(8, 10, 16, 0.72);
  color: #e7ecf6;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
/* The rooted view's tool row: the infinite view's (.viewport-tools), without its buttons. */
.explorer-tools {
  z-index: 2;
}
.xray-control label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}
.xray-control input[type='range'] {
  width: 120px;
}
@media (max-width: 600px) {
  .xray-control input[type='range'] {
    width: 72px;
  }
}
.xray-level {
  min-width: 6ch;
}

/* Compare and Identify, in the infinite view's readout. */
.map-hud .hud-action,
.map-hud .hud-chip button {
  pointer-events: auto;
  font: inherit;
  cursor: pointer;
}
.map-hud .hud-action {
  align-self: flex-start;
  padding: 1px 8px;
  border: 1px solid rgba(244, 246, 251, 0.4);
  border-radius: var(--radius);
  background: transparent;
  color: #cfeee6;
}
.map-hud .hud-action:disabled {
  opacity: 0.5;
  cursor: default;
}
.map-hud .hud-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  align-self: flex-start;
  padding: 0 0 0 7px;
  border: 1px solid rgba(207, 238, 230, 0.45);
  border-radius: 999px;
  color: #cfeee6;
}
.map-hud .hud-chip button {
  border: none;
  background: transparent;
  color: inherit;
  padding: 0 7px;
}

/* Harmonic search: an item of the viewport's tool row; open, it takes a line of its own. */
.harmonic-control {
  padding: 3px 9px;
  border: 1px solid rgba(244, 246, 251, 0.28);
  border-radius: var(--radius);
  background: rgba(8, 10, 16, 0.8);
  color: #e7ecf6;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.harmonic-control.is-open {
  flex-basis: 100%;
  max-width: 520px;
}
.harmonic-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
}
.harmonic-row label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}
.harmonic-row select,
.harmonic-row input[type='number'] {
  font: inherit;
  color: inherit;
  background: #1a1e28;
  border: 1px solid rgba(244, 246, 251, 0.28);
  border-radius: 4px;
}
.harmonic-row input[type='number'] {
  width: 7ch;
}
.harmonic-panel p {
  margin: 4px 0 0;
}
.harmonic-note {
  color: #9aa3b5;
}
.harmonic-hits {
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
}
.harmonic-hits li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 8px;
}
.viewport-tools .harmonic-hits button,
.harmonic-hits a {
  font: inherit;
  color: #cfeee6;
}
.viewport-tools .harmonic-frame {
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  text-align: left;
}
.harmonic-frame b {
  color: #ffc24a;
}
.viewport-tools .harmonic-hits .hud-action {
  padding: 0 7px;
  border: 1px solid rgba(244, 246, 251, 0.4);
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
}

/* Tail classes: an item of the viewport's tool row; open, it takes a line of its own. */
.tails-control {
  padding: 3px 9px;
  border: 1px solid rgba(244, 246, 251, 0.28);
  border-radius: var(--radius);
  background: rgba(8, 10, 16, 0.8);
  color: #e7ecf6;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.tails-control.is-open {
  flex-basis: 100%;
  max-width: 420px;
}
.tails-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
}
.tails-row label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}
.tails-progress,
.tails-count {
  color: #9aa3b5;
}
.tails-legend {
  margin: 3px 0 0;
  padding: 0;
  list-style: none;
}
.viewport-tools .tails-legend button {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 0 3px;
  border: none;
  border-radius: 3px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.viewport-tools .tails-legend button[aria-pressed='true'] {
  background: rgba(244, 246, 251, 0.16);
}
.tails-legend i {
  flex: none;
  width: 14px;
  height: 0;
  border-top: 4px solid;
}
.tails-legend i.is-dashed {
  border-top-style: dashed;
}
.tails-label {
  flex: 1;
}
.tails-count {
  white-space: nowrap;
}
.tails-detail {
  margin: 4px 0 0;
  color: #cfd6e4;
}
.tails-detail a {
  color: #cfeee6;
}
.tails-tip {
  max-width: 280px;
  white-space: normal;
}
/* On a phone the panel's line under the legend says what the tip would. */
@media (max-width: 600px) {
  .tails-control {
    font-size: 11px;
  }
  .tails-tip {
    display: none;
  }
}
