.beam-panel {
  --beam-base: #241743;
  --beam-line: #b0fbe0;
  display: grid;
  justify-items: center;
  gap: .75rem;
  padding: clamp(.55rem, 3vw, 1rem);
  border: 1px solid #554378;
  border-radius: 1.2rem;
  color: #fbf3ff;
  background:
    linear-gradient(#2c1944c9, #241743ef),
    url('assets/beam.jpg') center / cover,
    var(--beam-base);
}

.beam-instruction {
  margin: 0;
  font-size: .88rem;
  line-height: 1.35;
  color: #e6daf4;
  text-align: center;
}

.beam-board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--beam-columns, 4), minmax(0, 1fr));
  inline-size: min(100%, 22rem);
  gap: 3px;
  padding: 4px;
  border: 1px solid #6f578d;
  border-radius: .82rem;
  background: #171127;
}

.beam-pulse {
  position: absolute;
  inset: -4px auto auto -4px;
  z-index: 4;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f7fff0;
  box-shadow: 0 0 5px 2px #c4ffe8, 0 0 13px 3px #12e7b0;
  pointer-events: none;
}

.beam-board[data-columns="5"] { --beam-columns: 5; }
.beam-board[data-columns="6"] { --beam-columns: 6; }
.beam-board[data-columns="7"] { --beam-columns: 7; }

.beam-cell {
  position: relative;
  display: grid;
  place-items: center;
  min-inline-size: 0;
  padding: 0;
  aspect-ratio: 1;
  border: 1px solid #54466b;
  border-radius: .35rem;
  background: radial-gradient(circle, #6b5887 1px, transparent 1.5px), #32254a;
  color: #f0d7ff;
  line-height: 1;
}

.beam-cell[data-kind="mirror"] {
  border-color: #b48be2;
  background: #624485;
  box-shadow: inset 0 -2px 0 #372557;
  transition: background-color .18s, border-color .18s;
}

.beam-cell[data-kind="mirror"]:hover:not(:disabled) {
  border-color: #f0d6ff;
  background: #775699;
}

.puzzle-playfield .beam-cell:focus-visible {
  z-index: 3;
  outline: 2px solid #ffdc7f;
  outline-offset: 0;
  box-shadow: inset 0 0 0 2px #30204b;
}

.beam-cell[data-kind="fixed"] {
  border-style: dashed;
  border-color: #c1a8da;
  background: #3e3155;
}

.beam-cell[data-kind="fixed"]::after {
  position: absolute;
  right: 12%;
  bottom: 11%;
  inline-size: 13%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: #e9c9ff;
  content: "";
}

.beam-cell[data-kind="source"] { border-color: #72cdb7; background: #345960; color: #e0fff4; }
.beam-cell[data-kind="goal"] { border-color: #d3a862; background: #594260; color: #ffe4a0; }
.beam-cell[data-kind="crystal"] { border-color: #8766ae; background: #493562; color: #dfabf6; }
.beam-cell[data-kind="wall"] { border-color: #8d5d80; background: #513655; color: #ecb4c8; }
.beam-cell[data-impact="true"] { border-color: #ffd1a2; box-shadow: inset 0 0 0 1px #ffd1a2; }

.beam-cell-icon {
  z-index: 2;
  position: relative;
  font-size: clamp(.95rem, 4vw, 1.52rem);
  font-weight: 850;
  pointer-events: none;
}

.beam-cell[data-turn] > .beam-cell-icon {
  position: absolute;
  inline-size: 67%;
  block-size: clamp(2.5px, .7vw, 4px);
  border-radius: 999px;
  background: #f8e6ff;
  box-shadow: 0 1px 2px #211336, 0 0 5px #cec2f19e;
  transform: rotate(-45deg);
  transition: transform .18s ease-out;
}

.beam-cell[data-turn="down"] > .beam-cell-icon { transform: rotate(45deg); }
.beam-cell[data-kind="fixed"] > .beam-cell-icon { background: #c7b4e1; }
.beam-cell[data-kind="goal"]:not([data-ray=""]) > .beam-cell-icon { color: #fff3bd; text-shadow: 0 0 9px #f4c142; }
.beam-cell[data-kind="crystal"]:not([data-ray=""]) > .beam-cell-icon { color: #dafff4; text-shadow: 0 0 9px #70f4ca; }

.beam-arm {
  z-index: 1;
  position: absolute;
  display: none;
  border-radius: 3px;
  color: var(--beam-line);
  background: #e2fff7;
  box-shadow: 0 0 4px #a0ffdf, 0 0 9px #25e2a2;
  pointer-events: none;
}

.beam-cell[data-ray~="N"] > [data-direction="N"],
.beam-cell[data-ray~="E"] > [data-direction="E"],
.beam-cell[data-ray~="S"] > [data-direction="S"],
.beam-cell[data-ray~="W"] > [data-direction="W"] {
  display: block;
  animation: beam-ignite .24s ease-out;
}

.beam-arm[data-direction="N"],
.beam-arm[data-direction="S"] { inset-inline-start: calc(50% - 1px); inline-size: 2px; block-size: calc(50% + 4px); }
.beam-arm[data-direction="E"],
.beam-arm[data-direction="W"] { inset-block-start: calc(50% - 1px); block-size: 2px; inline-size: calc(50% + 4px); }
.beam-arm[data-direction="N"] { inset-block-start: -3px; }
.beam-arm[data-direction="E"] { inset-inline-end: -3px; }
.beam-arm[data-direction="S"] { inset-block-end: -3px; }
.beam-arm[data-direction="W"] { inset-inline-start: -3px; }

@keyframes beam-ignite {
  from { opacity: .4; }
  to { opacity: 1; }
}

.beam-status {
  min-block-size: 2.25em;
  margin: 0;
  padding-inline: .2rem;
  color: #eee2ff;
  font-size: .84rem;
  font-weight: 760;
  line-height: 1.35;
  text-align: center;
}

.beam-status[data-outcome="success"] { color: #a9ffda; }
.beam-status[data-outcome="limit"] { color: #ffcdaf; }

.beam-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: .55rem;
  inline-size: 100%;
}

.beam-legend {
  display: flex;
  flex: 1 1 13rem;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: .25rem .7rem;
  margin: 0;
  padding: 0;
  list-style: none;
  color: #eadcf7;
  font-size: .76rem;
}

.beam-legend li { display: flex; align-items: center; gap: .2rem; }
.beam-legend-sign {
  min-inline-size: .95em;
  color: #e6c6fb;
  font-size: .99rem;
  font-weight: 850;
  text-align: center;
}
.beam-legend-sign[data-kind="source"] { color: #9af9d8; }
.beam-legend-sign[data-kind="goal"] { color: #ffe196; }

.beam-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: .35rem; }

.puzzle-playfield .beam-reset {
  min-block-size: 35px;
  padding: .35rem .65rem;
  border: 1px solid #9576ac;
  border-radius: .6rem;
  background: #4a3463;
  color: #f9ecff;
  font-size: .79rem;
  font-weight: 770;
}

.puzzle-playfield .beam-reset:hover:not(:disabled, [aria-disabled="true"]) { background: #604478; }
.puzzle-playfield .beam-reset:focus-visible { outline: 2px solid #ffdc7f; outline-offset: 2px; }
.puzzle-playfield .beam-reset[aria-disabled="true"],
.puzzle-playfield .beam-reset:disabled { border-color: #786389; background: #39294c; color: #c3afd5; }

@media (prefers-reduced-motion: reduce) {
  .beam-cell, .beam-cell[data-turn] > .beam-cell-icon { transition: none; }
  .beam-panel .beam-cell > .beam-arm { animation: none; }
}
