#circuitGame {
  --circuit-accent: #35e6d0;
  position: absolute;
  inset: calc(70px + env(safe-area-inset-top, 0px)) 0 0;
  z-index: 3;
  min-width: 0;
  padding: 10px max(16px, env(safe-area-inset-right, 0px)) max(20px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  overflow: auto;
  overscroll-behavior: contain;
  background: radial-gradient(ellipse at 30% 18%, #102a30 0, transparent 60%), #070b17;
  color: #ecfff9;
  font-size: 15px;
  line-height: 1.45;
  touch-action: pan-y;
  scrollbar-color: #367b79 #070b17;
}

#circuitGame [hidden], #circuitGame[hidden] { display: none !important; }
#circuitGame *, #circuitGame *::before, #circuitGame *::after { box-sizing: border-box; }
#circuitGame h1, #circuitGame h2, #circuitGame p { margin: 0; }
#circuitGame button, #circuitGame select, #circuitGame textarea {
  min-width: 0;
  min-height: 44px;
  border: 1px solid #39706c;
  border-radius: 10px;
  padding: 10px 12px;
  background: #14252e;
  color: #ecfff9;
  font: inherit;
  font-weight: 700;
  line-height: 1.25;
  cursor: pointer;
  touch-action: manipulation;
}
#circuitGame button:hover:not(:disabled), #circuitGame select:hover { background: #1a373c; border-color: var(--circuit-accent); }
#circuitGame button:active:not(:disabled) { background: #28504c; }
#circuitGame button:disabled { opacity: .48; cursor: default; }
#circuitGame :focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
#circuitGame .circuit-primary { border-color: var(--circuit-accent); background: #195249; }
#circuitGame .circuit-content { max-width: 1050px; min-width: 0; margin: 0 auto; }
#circuitGame .circuit-header { margin-bottom: 22px; }
#circuitGame .circuit-eyebrow { font-size: 10px; font-weight: 800; letter-spacing: 2px; color: var(--circuit-accent); }
#circuitGame h1 { margin-top: 3px; font-size: clamp(24px, 4vw, 38px); letter-spacing: 2px; line-height: 1.2; }
#circuitGame .circuit-subtitle { margin-top: 7px; color: #bacdcc; }
#circuitGame .circuit-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(260px, 320px); align-items: start; gap: 26px; }
#circuitGame .circuit-board-section, #circuitGame .circuit-side { min-width: 0; }
#circuitGame .circuit-board-title { font-size: 20px; }
#circuitGame .circuit-board-detail { margin-top: 3px; color: #a9c5c5; font-size: 12px; }
#circuitGame .circuit-stats { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
#circuitGame .circuit-stats span { padding: 6px 10px; border: 1px solid #2b5055; border-radius: 8px; background: #10252b; font-size: 13px; font-variant-numeric: tabular-nums; }
#circuitGame .circuit-grid {
  display: grid;
  grid-template-columns: repeat(var(--circuit-size, 4), minmax(0, 1fr));
  gap: 5px;
  width: min(100%, 540px);
  margin-inline: auto;
  padding: 6px;
  border: 1px solid #365761;
  border-radius: 15px;
  background: #09141e;
}
#circuitGame .circuit-tile {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  min-height: 44px;
  padding: 0;
  border: 1px solid #243c4b;
  border-radius: 8px;
  background: #101e2c;
  color: #718c9d;
  overflow: visible;
  transition: background-color .18s, border-color .18s, box-shadow .18s;
  -webkit-tap-highlight-color: transparent;
}
#circuitGame .circuit-tile:hover { background: #19343f; }
#circuitGame .circuit-tile svg { display: block; width: 100%; height: 100%; border-radius: 7px; overflow: hidden; }
#circuitGame .circuit-wire { fill: none; stroke: currentColor; stroke-width: 9; stroke-linecap: square; stroke-linejoin: round; }
#circuitGame .circuit-loose-wire { fill: none; stroke: #dba866; stroke-width: 9; stroke-linecap: square; }
#circuitGame .circuit-junction { fill: #0d202c; stroke: currentColor; stroke-width: 5; }
#circuitGame .is-bulb .circuit-junction { r: 14; }
#circuitGame .is-powered { border-color: #267f77; color: var(--circuit-accent); background: #103334; box-shadow: inset 0 0 18px #35e6d019; }
#circuitGame .is-powered .circuit-wire { filter: drop-shadow(0 0 3px #35e6d077); }
#circuitGame .is-powered .circuit-junction { fill: #c5fff2; stroke: var(--circuit-accent); }
#circuitGame .is-source { border-color: #ffd775; }
#circuitGame .is-source .circuit-junction { fill: #193c38; stroke: #ffd775; }
#circuitGame .circuit-source { position: absolute; inset: 0; display: grid; place-items: center; color: #ffd775; font-size: clamp(17px, 4vw, 32px); font-weight: 900; pointer-events: none; }
#circuitGame .is-selected { border-color: #e7fffb; }
#circuitGame .circuit-tile:focus-visible { z-index: 1; outline-offset: 1px; }
#circuitGame .circuit-board-hint { margin-top: 12px; text-align: center; font-size: 12px; color: #a9c5c5; }
#circuitGame .circuit-tools { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 12px; }
#circuitGame .circuit-side { display: grid; gap: 14px; }
#circuitGame .circuit-card { padding: 16px; border: 1px solid #27434c; border-radius: 14px; background: #0d1b27; }
#circuitGame .circuit-card h2 { font-size: 13px; letter-spacing: 1px; color: var(--circuit-accent); }
#circuitGame .circuit-muted { margin-top: 7px; color: #b1c6cb; font-size: 13px; }
#circuitGame .circuit-choice { display: block; width: 100%; margin-top: 10px; text-align: left; }
#circuitGame .circuit-choice[aria-pressed="true"] { border-color: var(--circuit-accent); box-shadow: inset 3px 0 var(--circuit-accent); }
#circuitGame .circuit-progress { margin-top: 12px; color: #bbd6cc; font-size: 12px; }
#circuitGame .circuit-practice-row { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; margin-top: 12px; }
#circuitGame select { width: 100%; }
#circuitGame .circuit-tutorial { padding: 0; }
#circuitGame summary { min-height: 48px; padding: 14px 16px; cursor: pointer; font-weight: 800; color: var(--circuit-accent); touch-action: manipulation; }
#circuitGame .circuit-tutorial-body { padding: 0 16px 16px; font-size: 13px; color: #c9d9dd; }
#circuitGame .circuit-tutorial-body p + p { margin-top: 12px; }
#circuitGame .circuit-timer-label { display: flex; align-items: center; gap: 8px; min-height: 44px; margin-top: 10px; cursor: pointer; }
#circuitGame input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--circuit-accent); }
#circuitGame .circuit-victory { border-color: var(--circuit-accent); background: linear-gradient(135deg, #16483e, #102536); box-shadow: 0 0 24px #35e6d01f; }
#circuitGame .circuit-victory h2 { font-size: 18px; color: #e4fff5; }
#circuitGame .circuit-victory p { margin-top: 10px; font-size: 13px; }
#circuitGame .circuit-win-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
#circuitGame .circuit-win-actions button { flex: 1 1 110px; }
#circuitGame .circuit-confirm { border-color: #ffd775; }
#circuitGame .circuit-confirm h2 { color: #ffd775; }
#circuitGame .circuit-confirm p { margin-top: 10px; font-size: 13px; }
#circuitGame .circuit-warning { margin-bottom: 16px; padding: 12px 14px; border: 1px solid #ffca72; border-radius: 10px; color: #ffe0a3; background: #3a2714; font-size: 13px; }
#circuitGame .circuit-share-fallback { margin-top: 12px; }
#circuitGame .circuit-share-fallback label { display: block; margin-bottom: 6px; font-size: 12px; }
#circuitGame textarea { width: 100%; resize: vertical; cursor: text; font-weight: 400; font-size: 13px; }
#circuitGame .circuit-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@keyframes circuit-solved {
  0%, 100% { box-shadow: 0 0 0 #35e6d000; }
  50% { box-shadow: 0 0 34px #35e6d060; }
}
#circuitGame.circuit-celebrate .circuit-grid { animation: circuit-solved .85s ease-in-out 2; border-color: var(--circuit-accent); }

@media (min-width: 761px) and (min-height: 581px) {
  #circuitGame .circuit-grid {
    width: min(100%, 540px, max(calc(var(--circuit-size) * 47px + 7px), calc(100dvh - 410px)));
  }
}

@media (max-width: 760px) {
  #circuitGame { padding-inline: max(14px, env(safe-area-inset-left, 0px)) max(14px, env(safe-area-inset-right, 0px)); }
  #circuitGame .circuit-content { max-width: 540px; }
  #circuitGame .circuit-header { margin-bottom: 16px; }
  #circuitGame .circuit-layout { grid-template-columns: minmax(0, 1fr); gap: 20px; }
  #circuitGame .circuit-practice-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}

@media (max-width: 360px) {
  #circuitGame { padding-left: max(8px, env(safe-area-inset-left, 0px)); padding-right: max(8px, env(safe-area-inset-right, 0px)); }
  #circuitGame .circuit-grid { gap: 3px; padding: 4px; }
  #circuitGame .circuit-tools { gap: 5px; }
  #circuitGame .circuit-tools button { padding-inline: 9px; font-size: 13px; }
  #circuitGame .circuit-stats { gap: 5px; }
  #circuitGame .circuit-stats span { padding-inline: 7px; font-size: 12px; }
}

@media (max-height: 580px) and (min-width: 650px) {
  #circuitGame .circuit-content { position: relative; max-width: 1050px; }
  #circuitGame .circuit-layout { grid-template-columns: minmax(0, 1fr) minmax(250px, 320px); gap: 18px; }
  #circuitGame .circuit-header { position: absolute; top: 0; right: 0; width: 320px; max-width: 45%; margin: 0; }
  #circuitGame h1 { font-size: 23px; }
  #circuitGame .circuit-eyebrow { font-size: 8px; letter-spacing: 1px; }
  #circuitGame .circuit-subtitle { font-size: 12px; margin-top: 4px; }
  #circuitGame .circuit-side { padding-top: 80px; }
  #circuitGame .circuit-board-title { font-size: 17px; }
  #circuitGame .circuit-board-detail { display: none; }
  #circuitGame .circuit-stats { margin-block: 6px; gap: 5px; }
  #circuitGame .circuit-stats span { padding: 4px 8px; font-size: 11px; }
  #circuitGame .circuit-grid { width: min(100%, max(calc(var(--circuit-size) * 47px + 7px), calc(100dvh - 148px))); gap: 3px; padding: 4px; }
  #circuitGame .circuit-board-hint { margin-top: 8px; }
  #circuitGame .circuit-tools { margin-top: 8px; }
  #circuitGame .circuit-practice-row { grid-template-columns: minmax(0, 1fr); }
  #circuitGame .circuit-warning { position: relative; z-index: 1; }
}

@media (prefers-reduced-motion: reduce) {
  #circuitGame *, #circuitGame *::before, #circuitGame *::after { animation: none !important; transition: none !important; }
}
