.qr-game {
  --qr-cell-size: clamp(48px, 10vw, 72px);
  max-width: 760px;
  margin: 28px auto 0;
}

.qr-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex-wrap: wrap;
}

.qr-stat {
  min-width: 88px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.qr-stat span {
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.qr-stat strong {
  font: 700 1.15rem/1.2 "Courier New", monospace;
  color: var(--text);
}

.qr-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.qr-help {
  margin-top: 12px;
  padding: 16px 20px;
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border));
  border-radius: var(--radius);
}

.qr-help[hidden],
.qr-overlay[hidden] {
  display: none;
}

.qr-help h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.qr-help p {
  margin: 6px 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.qr-help kbd {
  display: inline-block;
  min-width: 1.65em;
  margin: 0 2px;
  padding: 1px 5px;
  text-align: center;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: 0 1px 0 var(--border);
}

.qr-stage {
  position: relative;
  margin-top: 16px;
  min-height: 300px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 35%, rgba(76, 195, 255, 0.1), transparent 48%),
    #080d18;
  border: 1px solid rgba(108, 199, 255, 0.25);
  border-radius: var(--radius);
}

.qr-grid-wrap {
  overflow-x: auto;
  padding: clamp(16px, 4vw, 32px);
}

.qr-grid {
  display: grid;
  gap: 5px;
  width: max-content;
  margin: 0 auto;
}

.qr-cell {
  position: relative;
  width: var(--qr-cell-size);
  height: var(--qr-cell-size);
  padding: 0;
  overflow: hidden;
  background: #111a2a;
  border: 1px solid #243654;
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease, transform 120ms ease;
  touch-action: manipulation;
}

.qr-cell:hover {
  border-color: #6c8db9;
  transform: translateY(-1px);
}

.qr-cell:focus-visible {
  outline: 3px solid #ffd166;
  outline-offset: 2px;
  z-index: 3;
}

.qr-cell.is-empty {
  cursor: default;
  opacity: 0.32;
  background: #0b1220;
}

.qr-cell.is-empty:hover {
  transform: none;
  border-color: #243654;
}

.qr-node,
.qr-arm {
  position: absolute;
  display: block;
  background: #65738a;
  transition: background 140ms ease, box-shadow 140ms ease;
}

.qr-node {
  z-index: 2;
  width: 28%;
  height: 28%;
  left: 36%;
  top: 36%;
  border-radius: 50%;
}

.qr-arm {
  z-index: 1;
}

.qr-arm-n,
.qr-arm-s {
  width: 14%;
  height: 38%;
  left: 43%;
}

.qr-arm-e,
.qr-arm-w {
  width: 38%;
  height: 14%;
  top: 43%;
}

.qr-arm-n { top: 0; }
.qr-arm-e { right: 0; }
.qr-arm-s { bottom: 0; }
.qr-arm-w { left: 0; }

.qr-cell.is-powered {
  background: #10273a;
  border-color: #39c4ff;
}

.qr-cell.is-powered .qr-node,
.qr-cell.is-powered .qr-arm {
  background: #5ed6ff;
  box-shadow: 0 0 10px #21baff;
}

.qr-cell.is-source .qr-node {
  background: #ffd166;
  box-shadow: 0 0 14px #ffbf3f;
}

.qr-cell.is-target .qr-node {
  border-radius: 4px;
  background: #ff6ba9;
  box-shadow: 0 0 14px #ff4b98;
}

.qr-cell.is-target.is-powered .qr-node {
  background: #78f7b2;
  box-shadow: 0 0 16px #4cff9b;
}

.qr-marker {
  position: absolute;
  z-index: 4;
  right: 3px;
  bottom: 2px;
  color: #fff;
  font: 700 0.62rem/1 sans-serif;
  text-shadow: 0 1px 3px #000;
  pointer-events: none;
}

.qr-overlay {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(4, 8, 17, 0.8);
  backdrop-filter: blur(3px);
}

.qr-overlay-card {
  max-width: 390px;
  padding: 24px;
  text-align: center;
  color: #eef7ff;
  background: #101a2b;
  border: 1px solid #345174;
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

.qr-overlay-icon {
  font-size: 2.2rem;
}

.qr-overlay-card h3 {
  margin: 8px 0;
  color: #fff;
}

.qr-overlay-card p {
  margin: 0 0 18px;
  color: #b6c6da;
}

.qr-status {
  min-height: 1.5em;
  margin: 12px 4px 0;
  color: var(--text-muted);
  font-weight: 600;
}

.qr-game.is-success .qr-stage {
  animation: qr-success 650ms ease;
}

.qr-game.is-failure .qr-stage {
  animation: qr-failure 350ms ease;
}

@keyframes qr-success {
  50% { box-shadow: 0 0 34px rgba(76, 255, 155, 0.55); }
}

@keyframes qr-failure {
  25%, 75% { transform: translateX(-4px); }
  50% { transform: translateX(4px); border-color: #ff607d; }
}

@media (max-width: 560px) {
  .qr-game {
    --qr-cell-size: 48px;
  }

  .qr-actions {
    width: 100%;
    margin-left: 0;
  }

  .qr-actions .btn {
    flex: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .qr-cell,
  .qr-node,
  .qr-arm {
    transition: none;
  }

  .qr-game.is-success .qr-stage,
  .qr-game.is-failure .qr-stage {
    animation: none;
  }
}
