/* ==========================================================================
   Particle Life — presentation layer.

   Chrome (panel, sliders, matrix) inherits the PaperMod theme variables so it
   tracks the surrounding page. The simulation viewport itself is deliberately
   a fixed dark field in both themes: it reads as an instrument window, and
   low-luminance backgrounds are what make the species colours separable.
   ========================================================================== */

/* Break the widget out of the 680px prose column without touching layouts. */
.sim-mount {
  --sim-width: min(1024px, calc(100vw - 2 * var(--gap, 24px)));
  width: var(--sim-width);
  margin-left: calc((100% - var(--sim-width)) / 2);
  margin-block: calc(1.5 * var(--content-gap, 20px));
}

.sim-noscript {
  padding: 1rem;
  border: 1px solid var(--border, #e6e6e6);
  border-radius: var(--radius, 8px);
}

.pl {
  --pl-fg: var(--content, #1e1e1e);
  --pl-muted: var(--secondary, #6c6c6c);
  --pl-border: var(--border, #e6e6e6);
  --pl-field: var(--code-bg, #f5f5f5);
  --pl-accent: var(--purple, #8e7bd0);
  --pl-accent-strong: var(--lightpurple, #5e42bc);
  --pl-ink: #0b0d12;
  --pl-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  border: 1px solid var(--pl-border);
  border-radius: var(--radius, 8px);
  overflow: hidden;
  background: var(--entry, #fff);
  color: var(--pl-fg);
  font-size: 0.875rem;
  line-height: 1.4;
}

/* ---------- viewport ---------------------------------------------------- */

.pl-stage {
  position: relative;
  background: var(--pl-ink);
  line-height: 0;
}

.pl-canvas {
  display: block;
  width: 100%;
  height: var(--sim-canvas-height, 520px);
  cursor: crosshair;
}

.pl-hud {
  position: absolute;
  top: 10px;
  left: 12px;
  display: flex;
  gap: 14px;
  font-family: var(--pl-mono);
  font-size: 11px;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.42);
  pointer-events: none;
  user-select: none;
}

.pl-hud b {
  font-weight: 500;
  color: rgba(255, 255, 255, 0.72);
}

.pl-hint {
  position: absolute;
  right: 12px;
  bottom: 10px;
  font-family: var(--pl-mono);
  font-size: 11px;
  color: rgba(255, 255, 255, 0.3);
  pointer-events: none;
  user-select: none;
}

.pl-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(11, 13, 18, 0.55);
  line-height: 1.4;
}

.pl-overlay[hidden] {
  display: none;
}

.pl-overlay button {
  padding: 0.6em 1.6em;
  font: inherit;
  font-weight: 500;
  color: #0b0d12;
  background: rgba(255, 255, 255, 0.9);
  border: 0;
  border-radius: 999px;
  cursor: pointer;
}

/* ---------- toolbar ----------------------------------------------------- */

.pl-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--pl-border);
  border-bottom: 1px solid var(--pl-border);
  background: var(--pl-field);
}

.pl-bar button {
  padding: 0.42em 0.95em;
  font: inherit;
  color: var(--pl-fg);
  background: var(--entry, #fff);
  border: 1px solid var(--pl-border);
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.pl-bar button:hover {
  color: var(--pl-accent-strong);
  border-color: var(--pl-accent);
}

.pl-bar button:focus-visible,
.pl-cell:focus-visible {
  outline: 2px solid var(--pl-accent);
  outline-offset: 2px;
}

.pl-bar .pl-spacer {
  flex: 1 1 auto;
}

.pl-status {
  align-self: center;
  font-family: var(--pl-mono);
  font-size: 11px;
  color: var(--pl-muted);
}

/* ---------- controls ---------------------------------------------------- */

.pl-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 22px;
  padding: 16px 14px 18px;
}

.pl-sliders {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px 22px;
  align-content: start;
}

.pl-field label {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 2px;
  color: var(--pl-muted);
}

.pl-field label span:last-child {
  font-family: var(--pl-mono);
  font-size: 11px;
  color: var(--pl-fg);
}

.pl-field input[type="range"] {
  width: 100%;
  margin: 0;
  accent-color: var(--pl-accent);
}

/* ---------- interaction matrix ------------------------------------------ */

.pl-matrix {
  display: grid;
  gap: 8px;
  align-content: start;
  justify-items: center;
}

.pl-matrix h4 {
  margin: 0;
  font-size: 0.8125rem;
  font-weight: var(--semibold, 500);
  color: var(--pl-muted);
}

.pl-table {
  display: grid;
  gap: 3px;
}

.pl-cell,
.pl-key {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 4px;
}

.pl-key {
  display: grid;
  place-items: center;
}

.pl-key i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: currentColor;
}

.pl-cell {
  background: var(--pl-field);
  box-shadow: inset 0 0 0 1px var(--pl-border);
  cursor: ns-resize;
  touch-action: none;
}

.pl-cell[data-selected="true"] {
  box-shadow: inset 0 0 0 2px var(--pl-accent-strong);
}

.pl-legend {
  font-family: var(--pl-mono);
  font-size: 10.5px;
  color: var(--pl-muted);
  text-align: center;
}

@media (max-width: 720px) {
  .pl-body {
    grid-template-columns: minmax(0, 1fr);
  }

  .pl-matrix {
    justify-items: start;
  }

  .pl-canvas {
    height: min(var(--sim-canvas-height, 520px), 62vh);
  }
}

@media (prefers-reduced-motion: reduce) {
  .pl-bar button {
    transition: none;
  }
}
