/* Front page: the machine fills the page, details open over it. */

body.pc-machine {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── stage ───────────────────────────────────────────── */

.stage {
  position: relative;
  width: 100%;
  /* basis 0 rather than auto, so the stage takes the space left over instead
     of growing to the drawing's intrinsic height */
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(ellipse 90% 70% at 50% 42%, #171d27 0%, #0a0c11 72%);
}

/* ── circuit backdrop ────────────────────────────────── */

.circuit {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  mask-image: radial-gradient(ellipse 78% 78% at 50% 46%, #000 35%, transparent 88%);
  -webkit-mask-image: radial-gradient(ellipse 78% 78% at 50% 46%, #000 35%, transparent 88%);
}

.circuit svg { display: block; width: 100%; height: 100%; }

/* Every stroke reads its colour through a variable, so changing the variable
   re-computes `stroke` and these transitions fade between the two. */
.circuit path { fill: none; stroke-linecap: round; stroke-linejoin: round; }

.t-base  { stroke: var(--trace); transition: stroke 1400ms ease; }
.t-via   { fill:   var(--via);   transition: fill   1400ms ease; }

.t-pulse {
  stroke: var(--pulse);
  stroke-dasharray: 9 91;
  transition: stroke 1400ms ease;
  animation-name: trace-run;
  animation-duration: var(--dur);
  animation-delay: var(--delay);
  animation-timing-function: linear;
  animation-iteration-count: infinite;
}

/* Nothing to see while an exploration is over the top, so stop repainting. */
body.is-exploring .t-pulse { animation-play-state: paused; }

@keyframes trace-run {
  from { stroke-dashoffset: 100; }
  to   { stroke-dashoffset: 0; }
}

/* The machine sits above the backdrop. */
.stage #pc-diagram {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
}

.stage-loading {
  padding: 4rem 1rem;
  text-align: center;
  color: var(--dimmer);
  font-family: var(--mono);
  font-size: 0.8rem;
}

/* ── parts ───────────────────────────────────────────── */

#pc-diagram [id^="part-"],
#pc-diagram #case-glass {
  transition: opacity 320ms ease, transform 320ms ease;
  transform-origin: center;
}

#pc-diagram .is-removed {
  opacity: 0;
  transform: translateX(14px) scale(0.985);
  pointer-events: none;
}

#pc-diagram .is-lit {
  filter: drop-shadow(0 0 3px rgba(56, 189, 248, 0.95))
          drop-shadow(0 0 14px rgba(56, 189, 248, 0.55));
}

/* The side panel: drawn with no fill of its own so the glass reads from here. */
#pc-diagram #case-glass rect {
  fill: rgba(125, 195, 255, 0.09);
  stroke: rgba(150, 205, 255, 0.32);
  stroke-width: 10;
}

/* ── click targets ───────────────────────────────────── */

#hit rect,
#hit path {
  fill: #ffffff;
  fill-opacity: 0;
  stroke: none;
  /* `all` rather than the default, so a zero opacity fill still receives
     clicks in every browser. */
  pointer-events: all;
  cursor: pointer;
  outline: none;
}

#hit .is-blocked {
  pointer-events: none;
  cursor: default;
}

/* Fixed features of the board have no removable artwork to light up, so the
   target itself outlines instead. */
#hit .is-fixed:hover {
  fill-opacity: 0.07;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-dasharray: 6 4;
}

#hit .is-fixed.is-blocked:hover {
  fill-opacity: 0;
  stroke: none;
}

#hit :focus-visible {
  stroke: var(--accent);
  stroke-width: 3;
  stroke-dasharray: 7 5;
  fill-opacity: 0.06;
}

/* ── removed parts ───────────────────────────────────── */

.tray {
  position: absolute;
  left: 1.5rem;
  bottom: 1.4rem;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.28rem;
  z-index: 2;
}

.tray button {
  padding: 0;
  border: none;
  background: none;
  font-family: var(--sans);
  font-style: italic;
  font-size: 0.86rem;
  line-height: 1.35;
  color: var(--dim);
  opacity: 0.4;
  cursor: pointer;
  transition: opacity var(--ease), color var(--ease);
}

.tray button:hover,
.tray button:focus-visible {
  opacity: 1;
  color: var(--accent);
  outline: none;
}

.tray button[aria-disabled="true"] {
  opacity: 0.16;
  cursor: default;
}

.tray button[aria-disabled="true"]:hover { color: var(--dim); opacity: 0.16; }

/* ── popup ───────────────────────────────────────────── */

/* Positioned by placePanel, beside whichever part was clicked. No top or
   right here, or it would fight the placement. */
.detail {
  position: absolute;
  z-index: 3;
  width: min(430px, calc(100% - 2rem));
  max-height: calc(100% - 3rem);
  overflow-y: auto;
  padding: 1.6rem 1.7rem 1.7rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 1px solid var(--accent-dk);
  border-radius: 4px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
  animation: detail-in 170ms ease-out;
  outline: none;
}

@keyframes detail-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

.detail[hidden] { display: none; }

.detail-close {
  position: absolute;
  top: 0.65rem;
  right: 0.7rem;
  width: 1.7rem;
  height: 1.7rem;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 3px;
  background: transparent;
  color: var(--dimmer);
  font-size: 0.78rem;
  cursor: pointer;
  transition: background var(--ease), color var(--ease);
}

.detail-close:hover {
  background: var(--panel-alt);
  color: var(--text);
}

.detail h2 {
  font-family: var(--sans);
  font-size: 1.32rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 1.6rem 0.4rem 0;
  color: #fff;
  line-height: 1.2;
}

.detail-spec {
  font-family: var(--mono);
  font-size: 0.735rem;
  letter-spacing: 0.01em;
  color: var(--accent);
  opacity: 0.85;
  margin: 0 0 1.15rem;
  padding-bottom: 1.15rem;
  border-bottom: 1px solid var(--line);
}

.detail p {
  font-size: 0.925rem;
  line-height: 1.68;
  color: #c6cede;
  margin: 0 0 0.9rem;
}

/* First in the panel, so it sits in the corner nearest the part. */
.detail-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 2rem 1.1rem 0;
  padding: 0.55rem 1rem;
  background: transparent;
  border: 1px solid var(--accent-dk);
  color: var(--accent);
  border-radius: 3px;
  text-decoration: none;
  font-family: var(--mono);
  font-size: 0.8rem;
  letter-spacing: 0.01em;
  transition: background var(--ease), border-color var(--ease), color var(--ease);
}

.detail-link:hover {
  background: rgba(56, 189, 248, 0.1);
  border-color: var(--accent);
  color: #eaf7ff;
}

.detail-link::after { content: "\203A"; font-size: 1.2em; line-height: 1; }

@media (max-width: 900px) {
  .detail { width: calc(100% - 2rem); }
}

@media (prefers-reduced-motion: reduce) {
  .t-pulse { animation: none; }
  .t-pulse { stroke-dasharray: none; opacity: 0.5; }
  #pc-diagram [id^="part-"],
  #pc-diagram #case-glass,
  .tray button,
  .detail-link { transition: none; }
  #pc-diagram .is-removed { transform: none; }
  .detail { animation: none; }
}

/* ── hover readout ───────────────────────────────────── */

#machine-tip {
  z-index: 4;
  max-width: 22rem;
  white-space: normal;
  pointer-events: none;
}

#machine-tip .tip-value {
  font-size: 0.72rem;
  color: var(--accent);
  opacity: 0.85;
}

#machine-tip .tip-meta:empty { display: none; }

#machine-tip .tip-meta {
  font-family: var(--sans);
  font-size: 0.78rem;
  line-height: 1.5;
  color: #a9b3c4;
  margin-top: 0.15rem;
}
