.circuit-node[hidden], .circuit-dialog [hidden] {
  display: none;
}

.circuit-node {
  position: absolute;
  inset: .4rem .4rem auto auto;
  display: grid;
  width: 2.75rem;
  height: 2.75rem;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: .6rem;
  background: transparent;
  cursor: pointer;
}

.circuit-node::before {
  width: .65rem;
  aspect-ratio: 1;
  border: 1px solid #52739d;
  border-radius: 50%;
  background: #1b304e;
  box-shadow: 0 0 0 .23rem #5d97df12;
  content: "";
}

.circuit-node:is(:hover, :focus-visible)::before,
.approach-card.circuit-charged .circuit-node::before {
  border-color: #c1ddff;
  background: var(--accent);
  box-shadow: 0 0 .85rem #69acffb0;
}

.approach-card.circuit-charged {
  border-color: #6197df;
  box-shadow: inset 0 0 1.8rem #5099ff23;
}

.approach-card.circuit-charged::after {
  opacity: 1;
  transform: scaleX(1);
  animation: circuit-card-signal .4s ease-out both;
}

.approach-principles.circuit-unlocked::before {
  background: linear-gradient(90deg, transparent, #89c6ff, transparent);
  box-shadow: 0 0 .7rem #5ba4ff;
  animation: circuit-card-signal .45s ease-out both;
}

html.circuit-modal-open {
  overflow: hidden;
  overflow-anchor: none;
  overscroll-behavior: none;
}

html.circuit-modal-gutter {
  scrollbar-gutter: stable;
}

.circuit-dialog {
  position: fixed;
  width: min(calc(100% - 1.25rem), 36rem);
  max-height: calc(100dvh - 1.25rem);
  padding: clamp(1rem, 4vw, 2rem);
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid #41699a;
  border-radius: var(--radius);
  background: radial-gradient(ellipse at 88% 0%, #152b47, transparent 50%), var(--surface);
  color: var(--text);
  box-shadow: 0 1.2rem 5rem #000b, inset 0 1px #89baff24;
}

.circuit-dialog::backdrop {
  background: #080c15df;
}

.circuit-dialog[open] {
  animation: circuit-dialog-in .22s ease-out both;
}

.circuit-close {
  position: absolute;
  inset: .65rem .65rem auto auto;
  display: grid;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.circuit-close:hover {
  border-color: var(--accent);
}

.circuit-header {
  padding-right: 2.75rem;
}

.circuit-brand, .circuit-level, .circuit-score-heading {
  color: var(--accent);
  font-size: .83rem;
  font-weight: 750;
  letter-spacing: .09em;
}

.circuit-header h2 {
  margin-top: .35rem;
  font-size: clamp(1.42rem, 4vw, 2.2rem);
  letter-spacing: -.035em;
}

.circuit-note {
  margin-block: .55rem 1rem;
  color: var(--muted);
}

.circuit-level {
  margin-top: .85rem;
}

.circuit-goal {
  margin: -.45rem 0 .8rem;
  color: var(--muted);
  font-size: .875rem;
}

[data-circuit-game][data-size="6"] {
  --circuit-board-width: 24rem;
}

[data-circuit-game][data-size="7"] {
  --circuit-board-width: 25rem;
}

.circuit-board {
  display: grid;
  grid-template-columns: repeat(var(--circuit-size, 5), minmax(0, 1fr));
  gap: 2px;
  width: min(100%, var(--circuit-board-width, 22rem));
  margin-inline: auto;
  padding: .32rem;
  border: 1px solid var(--line);
  border-radius: .8rem;
  background: #0b111a;
  isolation: isolate;
}

.circuit-cell {
  position: relative;
  display: grid;
  min-width: 0;
  aspect-ratio: 1;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: .25rem;
  background: #122034;
  color: #6d87a7;
  box-shadow: inset 0 0 0 1px #203754;
}

button.circuit-cell {
  cursor: pointer;
}

button.circuit-cell:focus-visible {
  z-index: 2;
  outline-offset: -2px;
}

button.circuit-cell:hover {
  background: #1a2c43;
}

.circuit-cell.circuit-hint {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.circuit-cell[aria-disabled="true"] {
  cursor: default;
}

.circuit-cell-empty {
  background: radial-gradient(circle, #263e5b 1px, transparent 2px) center / 25% 25%, #0d1725;
}

.circuit-cell svg {
  width: 100%;
  pointer-events: none;
}

.circuit-trace {
  transform: rotate(var(--circuit-angle, 0deg));
  transform-origin: 50% 50%;
  transition: transform .19s ease;
}

.circuit-trace path {
  fill: none;
  stroke: currentColor;
  stroke-width: 3;
}

.circuit-trace circle {
  fill: currentColor;
}

.circuit-cell-terminal {
  color: #a5b6ce;
}

.circuit-cell[data-circuit-terminal="checkpoint"] {
  color: var(--accent);
}

.circuit-trace .circuit-checkpoint-ring,
.circuit-lock {
  fill: var(--surface);
  stroke: currentColor;
}

.circuit-cell.circuit-powered {
  color: #9bd3ff;
  background: #17314d;
}

.circuit-powered .circuit-trace {
  filter: drop-shadow(0 0 3px #67adffb0);
}

.circuit-key {
  display: flex;
  justify-content: space-between;
  width: min(100%, var(--circuit-board-width, 22rem));
  margin: .35rem auto 0;
  color: var(--muted);
  font-size: .8rem;
}

.circuit-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .35rem .85rem;
  margin-top: .75rem;
  color: var(--muted);
  font-size: .85rem;
}

.circuit-tools [data-circuit-hint] {
  min-height: 2.75rem;
  margin-inline-start: auto;
  padding: .45rem .75rem;
}

.circuit-tools [data-circuit-hint]:disabled {
  opacity: .55;
  cursor: default;
}

.circuit-hint-message {
  color: var(--muted);
  font-size: .85rem;
}

.circuit-hint-message:not(:empty) {
  margin-top: .35rem;
}

.circuit-score {
  margin-top: 1rem;
  padding: clamp(.8rem, 3vw, 1.2rem);
  scroll-margin-top: .75rem;
  border: 1px solid var(--line);
  border-radius: .8rem;
  background: #0b111a;
}

.circuit-score--final {
  border-color: #41699a;
  background: radial-gradient(ellipse at 100% 0%, #142b48, transparent 60%), #0b111a;
}

.circuit-score-heading {
  scroll-margin-top: 1.25rem;
}

.circuit-final-title {
  margin-bottom: .35rem;
  color: var(--text);
  font-size: clamp(1.1rem, 4.5vw, 1.55rem);
}

.circuit-result-level {
  margin-top: .2rem;
  color: var(--text);
  font-weight: 650;
}

.circuit-score-list {
  display: grid;
  margin: .8rem 0 0;
  font-size: .875rem;
  line-height: 1.4;
}

.circuit-score-list > div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  gap: .5rem;
  padding: .38rem 0;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}

.circuit-score-list dd {
  margin: 0;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  text-align: end;
}

.circuit-score-totals {
  margin-top: .45rem;
}

.circuit-score-tally {
  margin-top: .8rem;
  color: var(--accent);
  line-height: 1.15;
}

.circuit-score-label {
  display: block;
  margin-bottom: .25rem;
  color: var(--muted);
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
}

.circuit-score-tally strong {
  color: #9bd3ff;
  font-size: clamp(1.8rem, 7.5vw, 3.15rem);
  font-variant-numeric: tabular-nums;
  letter-spacing: -.04em;
}

.circuit-score-max {
  color: var(--accent);
  font-size: .62em;
  white-space: nowrap;
}

.circuit-score-unit {
  font-size: .78rem;
  font-weight: 700;
}

.circuit-score-rank {
  margin-top: .85rem;
  padding: .65rem .75rem;
  border-left: 2px solid var(--accent);
  border-radius: 0 .4rem .4rem 0;
  background: #15263b;
}

.circuit-rank-name {
  color: var(--text);
  font-size: .95rem;
  font-weight: 750;
  letter-spacing: .05em;
}

.circuit-rank-note {
  color: var(--muted);
  font-size: .85rem;
}

.circuit-score--final .circuit-score-tally,
.circuit-score--final .circuit-score-rank {
  animation: circuit-score-in .3s ease-out both;
}

.circuit-score--final .circuit-score-rank {
  animation-delay: .12s;
}

.circuit-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .55rem;
  margin-top: 1rem;
}

.circuit-cell.circuit-pulse {
  animation: circuit-power-pulse .65s ease both;
  animation-delay: var(--circuit-delay);
}

@keyframes circuit-card-signal {
  from { transform: scaleX(.12); }
  to { transform: scaleX(1); }
}

@keyframes circuit-dialog-in {
  from { opacity: 0; transform: translateY(.4rem); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes circuit-power-pulse {
  35% { background: #29629b; color: #e1f5ff; }
}

@keyframes circuit-score-in {
  from { opacity: 0; transform: translateY(.3rem); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 44rem) {
  .approach-principles.circuit-unlocked::before {
    inset: 1.8rem 1.75rem;
    left: auto;
    display: block;
    width: 1px;
    height: auto;
    background: linear-gradient(transparent, #89c6ff, transparent);
  }
}

@media (prefers-reduced-motion: reduce) {
  .circuit-dialog[open], .approach-card.circuit-charged::after,
  .approach-principles.circuit-unlocked::before, .circuit-cell.circuit-pulse,
  .circuit-score--final .circuit-score-tally, .circuit-score--final .circuit-score-rank {
    animation: none;
  }

  .circuit-trace {
    transition: none;
  }
}
