.right-rail {
  position: relative;
  z-index: 12;
  grid-column: 3;
  grid-row: 1;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  align-content: stretch;
  gap: 14px;
}

.right-rail:has(.test-setup-panel) {
  grid-template-rows: auto auto auto minmax(0, 1fr);
}

.right-rail:has(.test-setup-panel) .controls {
  grid-row: 3;
}

.right-rail:has(.test-setup-panel) .log-panel {
  grid-row: 4;
}

.top-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.gear-button,
.icon-button,
.primary-button,
.ghost-button,
.tiny-button {
  border: 1px solid rgba(80, 200, 255, 0.6);
  background: linear-gradient(180deg, rgba(20, 70, 108, 0.82), rgba(5, 18, 31, 0.92));
  color: #dff8ff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease, opacity 140ms ease;
}

.gear-button {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  clip-path: polygon(23% 0, 77% 0, 100% 23%, 100% 77%, 77% 100%, 23% 100%, 0 77%, 0 23%);
}

.pwa-button {
  color: #ffe28a;
  border-color: rgba(239, 184, 77, 0.72);
  background: linear-gradient(180deg, rgba(92, 64, 16, 0.82), rgba(12, 18, 24, 0.92));
  text-shadow: 0 0 12px rgba(255, 226, 138, 0.72);
}

.mobile-test-setup-button {
  display: none;
  color: #fff4c9;
  border-color: rgba(239, 184, 77, 0.78);
  background: linear-gradient(180deg, rgba(92, 64, 16, 0.82), rgba(12, 18, 24, 0.94));
  font-size: 0.88rem;
  font-weight: 1000;
}

.return-lobby-button {
  color: #fff4c9;
  border-color: rgba(239, 184, 77, 0.76);
  background: linear-gradient(180deg, rgba(76, 54, 15, 0.84), rgba(10, 18, 27, 0.94));
  text-shadow: 0 0 10px rgba(255, 226, 138, 0.62);
}

.return-lobby-icon {
  width: 27px;
  height: 27px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 8px rgba(255, 226, 138, 0.54));
}

.icon-button {
  min-height: 88px;
  display: grid;
  place-items: center;
  gap: 6px;
  padding: 12px 10px;
  font-weight: 900;
  text-transform: uppercase;
  clip-path: polygon(10px 0, calc(100% - 10px) 0, 100% 10px, 100% calc(100% - 16px), calc(100% - 16px) 100%, 16px 100%, 0 calc(100% - 16px), 0 10px);
}

.button-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 2px solid currentColor;
  border-radius: 50%;
  font-size: 1.2rem;
}

.primary-button {
  position: relative;
  overflow: hidden;
  min-height: 76px;
  padding: 14px 18px;
  color: #9fe9ff;
  font-size: 1.45rem;
  font-weight: 900;
  text-transform: uppercase;
  clip-path: polygon(8px 0, calc(100% - 24px) 0, 100% 24px, 100% calc(100% - 8px), calc(100% - 8px) 100%, 24px 100%, 0 calc(100% - 24px), 0 8px);
}

.primary-button.is-attention {
  border-color: rgba(255, 226, 138, 0.9);
  color: #fff4c9;
  text-shadow: 0 0 12px rgba(255, 226, 138, 0.72);
  animation: actionButtonNudge 1.35s ease-in-out infinite;
}

.primary-button.is-attention::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(105deg, transparent 0 36%, rgba(255, 226, 138, 0.2) 50%, transparent 64% 100%);
  transform: translateX(-120%);
  animation: actionButtonSweep 1.9s ease-in-out infinite;
}

.primary-button.danger-button {
  color: #ffe0dc;
  border-color: rgba(255, 75, 67, 0.78);
  background: linear-gradient(180deg, rgba(126, 32, 29, 0.9), rgba(28, 7, 10, 0.94));
  box-shadow: var(--shadow-red), inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.primary-button.danger-button.is-attention {
  border-color: rgba(255, 138, 128, 0.95);
  color: #fff2ef;
  text-shadow: 0 0 12px rgba(255, 138, 128, 0.76);
  animation-name: dangerButtonNudge;
}

.ghost-button {
  min-height: 38px;
  padding: 8px 12px;
  font-weight: 800;
  text-transform: uppercase;
  clip-path: polygon(8px 0, calc(100% - 8px) 0, 100% 8px, 100% calc(100% - 8px), calc(100% - 8px) 100%, 8px 100%, 0 calc(100% - 8px), 0 8px);
}

.tiny-button {
  min-width: 32px;
  min-height: 32px;
  padding: 4px 8px;
  font-weight: 900;
  border-radius: 4px;
}

.gear-button:hover,
.icon-button:hover,
.primary-button:hover,
.ghost-button:hover,
.tiny-button:hover {
  transform: translateY(-1px);
  border-color: #ffffff;
  box-shadow: var(--shadow-blue);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.mode-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.controls {
  display: grid;
  gap: 12px;
  align-self: start;
  align-content: start;
}

.control-stack {
  display: grid;
  gap: 10px;
}

.mobile-action-row,
.primary-action-slot {
  display: contents;
}

.mobile-action-menu-shell {
  position: relative;
  display: none;
  min-width: 0;
}

.mobile-action-menu-toggle {
  position: relative;
  width: 100%;
  min-width: 0;
  min-height: 48px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(80, 200, 255, 0.62);
  background: linear-gradient(180deg, rgba(8, 24, 38, 0.94), rgba(3, 9, 16, 0.98));
  color: #dff8ff;
  cursor: pointer;
  clip-path: polygon(10px 0, calc(100% - 10px) 0, 100% 10px, 100% calc(100% - 10px), calc(100% - 10px) 100%, 10px 100%, 0 calc(100% - 10px), 0 10px);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.mobile-action-menu-toggle span,
.mobile-action-menu-toggle::before,
.mobile-action-menu-toggle::after {
  content: "";
  width: 20px;
  height: 2px;
  display: block;
  background: currentColor;
  box-shadow: 0 0 10px rgba(157, 236, 255, 0.7);
}

.mobile-action-menu-toggle {
  gap: 5px;
}

.mobile-action-menu-panel {
  position: absolute;
  z-index: 90;
  left: 0;
  bottom: calc(100% + 8px);
  width: 176px;
  display: grid;
  gap: 4px;
  padding: 7px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px) scale(0.98);
  transform-origin: left bottom;
  transition: opacity 140ms ease, transform 140ms ease;
  border: 1px solid rgba(80, 200, 255, 0.62);
  background: linear-gradient(160deg, rgba(6, 20, 34, 0.98), rgba(2, 7, 13, 0.98));
  box-shadow: 0 -12px 30px rgba(0, 0, 0, 0.56), 0 0 22px rgba(80, 200, 255, 0.2);
  clip-path: polygon(0 10px, 10px 0, calc(100% - 18px) 0, 100% 18px, 100% calc(100% - 10px), calc(100% - 10px) 100%, 18px 100%, 0 calc(100% - 18px));
}

.mobile-action-menu-panel.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.mobile-action-menu-item {
  min-height: 36px;
  display: grid;
  place-items: center;
  padding: 7px 9px;
  border: 1px solid rgba(80, 200, 255, 0.42);
  background: rgba(8, 24, 38, 0.72);
  color: #dff8ff;
  font-size: 0.72rem;
  line-height: 1;
  font-weight: 900;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  clip-path: polygon(7px 0, calc(100% - 7px) 0, 100% 7px, 100% calc(100% - 7px), calc(100% - 7px) 100%, 7px 100%, 0 calc(100% - 7px), 0 7px);
}

.mobile-action-menu-item.danger {
  border-color: rgba(255, 92, 78, 0.72);
  color: #ffd1cc;
  background: rgba(74, 18, 16, 0.78);
}

.action-meter {
  min-height: 34px;
  display: grid;
  align-items: center;
  padding: 7px 10px;
  border: 1px solid rgba(80, 200, 255, 0.45);
  background: linear-gradient(180deg, rgba(6, 34, 55, 0.86), rgba(3, 10, 18, 0.92));
  color: #dff8ff;
  font-size: 0.78rem;
  font-weight: 900;
  line-height: 1.12;
  text-transform: uppercase;
  box-shadow: 0 0 14px rgba(80, 200, 255, 0.14);
}

.action-meter.is-spent {
  border-color: rgba(239, 184, 77, 0.6);
  color: #ffe28a;
  background: linear-gradient(180deg, rgba(68, 46, 11, 0.84), rgba(7, 12, 18, 0.94));
}

.game-over-controls .ghost-button,
.game-over-controls .primary-button {
  min-height: 54px;
  font-size: 0.98rem;
  line-height: 1.08;
}

.feedback-open-button {
  color: #fff4c9;
  border-color: rgba(255, 226, 138, 0.86);
  background: linear-gradient(180deg, rgba(92, 64, 16, 0.86), rgba(8, 18, 30, 0.94));
  text-shadow: 0 0 12px rgba(255, 226, 138, 0.62);
}

.modal-sheet.post-match-sheet {
  position: relative;
  width: min(460px, calc(100vw - 28px));
  height: auto;
  max-height: calc(100vh - 28px);
  align-self: center;
  justify-self: center;
  align-content: start;
  grid-template-rows: auto auto auto;
  gap: 14px;
  padding: 22px 18px 18px;
  text-align: center;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.modal-sheet.post-match-sheet.is-entering {
  animation: postMatchSheetIn 420ms ease-out both;
}

.post-match-backdrop.is-entering {
  animation: postMatchBackdropIn 420ms ease-out both;
}

.post-match-head {
  display: grid;
  gap: 7px;
  padding: 6px 24px 0;
}

.post-match-head p {
  margin: 0;
  color: #dff8ff;
  font-weight: 800;
  line-height: 1.35;
}

.post-match-result {
  color: #9beaff;
  font-size: 1rem;
  line-height: 1.15;
  text-transform: uppercase;
}

.post-match-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
}

.post-match-reopen-button {
  border-color: rgba(92, 213, 255, 0.82);
  background: linear-gradient(180deg, rgba(13, 82, 117, 0.92), rgba(4, 27, 43, 0.98));
  color: #e8fbff;
  text-shadow: 0 0 12px rgba(92, 213, 255, 0.5);
}

.rematch-status {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--blue-soft);
  font-size: 0.8rem;
  line-height: 1.35;
}

.post-match-actions .primary-button,
.post-match-actions .ghost-button {
  min-width: 0;
  min-height: 46px;
  padding: 8px;
  font-size: 0.86rem;
  line-height: 1.08;
}

.post-match-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(80, 200, 255, 0.6);
  background: linear-gradient(180deg, rgba(20, 70, 108, 0.82), rgba(5, 18, 31, 0.92));
  color: #dff8ff;
  cursor: pointer;
  font-size: 1.2rem;
  font-weight: 900;
  line-height: 1;
  clip-path: polygon(8px 0, calc(100% - 8px) 0, 100% 8px, 100% calc(100% - 8px), calc(100% - 8px) 100%, 8px 100%, 0 calc(100% - 8px), 0 8px);
}

@keyframes postMatchBackdropIn {
  from {
    background: rgba(0, 0, 0, 0);
  }
  to {
    background: rgba(0, 0, 0, 0.72);
  }
}

@keyframes postMatchSheetIn {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.test-setup-panel {
  position: relative;
  z-index: 2;
  min-height: 0;
  max-height: 330px;
  overflow: auto;
  padding: 12px;
  border: 1px solid rgba(80, 200, 255, 0.42);
  background: linear-gradient(180deg, rgba(7, 24, 40, 0.92), rgba(3, 9, 17, 0.92));
  box-shadow: 0 0 18px rgba(80, 200, 255, 0.15), inset 0 0 0 1px rgba(255, 255, 255, 0.03);
  display: grid;
  gap: 10px;
}

.test-setup-panel .section-title {
  margin-bottom: 2px;
  font-size: 0.95rem;
  line-height: 1.12;
}

.test-setup-sheet {
  width: min(520px, 96vw);
  max-height: min(620px, 92vh);
  grid-template-rows: auto minmax(0, 1fr);
}

.test-setup-sheet .test-setup-panel {
  align-content: start;
  max-height: none;
}

.test-setup-sheet .test-setup-panel .section-title {
  display: none;
}

.test-select-grid {
  display: grid;
  gap: 8px;
}

.test-field,
.feedback-field {
  display: grid;
  gap: 5px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 900;
  text-transform: uppercase;
}

.test-field select,
.feedback-field input,
.feedback-field select,
.feedback-field textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid rgba(80, 200, 255, 0.42);
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.36);
  color: #f4fbff;
  padding: 8px 9px;
  font: inherit;
  font-weight: 800;
  text-transform: none;
}

.test-field select,
.feedback-field select {
  min-height: 34px;
}

.test-start-button {
  min-height: 42px;
  padding: 8px 10px;
  font-size: 0.78rem;
  line-height: 1.08;
}

.test-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 8px 9px;
  border: 1px solid rgba(239, 184, 77, 0.42);
  background: rgba(0, 0, 0, 0.24);
  color: #fff4c9;
  font-size: 0.68rem;
  font-weight: 900;
  line-height: 1.1;
  text-transform: uppercase;
}

.test-toggle input {
  width: 16px;
  height: 16px;
  accent-color: #efb84d;
}

.builder-reactor-toggle {
  justify-self: start;
}

.protocol-button {
  color: #ffe28a;
  border-color: rgba(239, 184, 77, 0.7);
  background: linear-gradient(180deg, rgba(92, 64, 16, 0.78), rgba(8, 18, 30, 0.94));
  text-shadow: 0 0 10px rgba(255, 226, 138, 0.62);
}

.reaction-choice {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-items: stretch;
}

.reaction-choice .primary-button,
.reaction-choice .ghost-button {
  min-height: 58px;
  padding: 10px 12px;
  font-size: 1rem;
  line-height: 1.05;
}

.mini-pill input {
  max-width: 92px;
  margin-left: 6px;
  border: 1px solid rgba(80, 200, 255, 0.45);
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.35);
  color: #ffffff;
  padding: 3px 5px;
}

.mode-buttons .is-active {
  border-color: #ffffff;
  box-shadow: var(--shadow-blue);
}

