/* 論理回路パズル スタイル。
   背景演出はプラットフォーム(トップページ)と同じダーク(シンセウェイブ)に統一。
   見せ場は「1 が流れている配線が光る」こと。0 は暗い線、1 はネオンシアンで走らせる。 */
:root {
  --aqua: #2de2ff; --aqua-deep: #7ef0ff; --pink: #ff3caf;
  --amber: #ffb02e; --good: #5ef2c0;
  --ink: #e9ecff; --mut: #9a9ed6; --bg: #08060f; --panel: #151129; --line: #2c2a55;
}
* { box-sizing: border-box; }
html { color-scheme: dark; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  color: var(--ink); line-height: 1.5;
  background: var(--bg); min-height: 100vh; padding: .5rem;
  -webkit-user-select: none; user-select: none;
}
/* 背景演出をトップページ(サイト)に統一:夕焼けグロー + ネオングリッド床 */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -2; pointer-events: none;
  background:
    radial-gradient(120% 85% at 50% -25%, rgba(255,60,175,.38), transparent 55%),
    radial-gradient(90% 60% at 8% 0%, rgba(45,226,255,.26), transparent 60%),
    radial-gradient(90% 60% at 100% 8%, rgba(124,77,255,.26), transparent 60%),
    var(--bg);
  animation: skyPulse 5s ease-in-out infinite;
}
@keyframes skyPulse { 0%, 100% { opacity: 1; } 50% { opacity: .72; } }
body::after {
  content: ""; position: fixed; left: -25%; right: -25%; bottom: 0; height: 48vh; z-index: -1; pointer-events: none;
  background-image:
    linear-gradient(rgba(45,226,255,.7) 2px, transparent 2px),
    linear-gradient(90deg, rgba(255,60,175,.5) 2px, transparent 2px);
  background-size: 44px 44px;
  transform: perspective(300px) rotateX(66deg); transform-origin: bottom center;
  -webkit-mask-image: linear-gradient(to top, #000 6%, transparent 84%);
          mask-image: linear-gradient(to top, #000 6%, transparent 84%);
  opacity: .85; filter: drop-shadow(0 0 6px rgba(45,226,255,.5));
  animation: gridScroll 2.4s linear infinite;
}
@keyframes gridScroll { from { background-position: 0 0, 0 0; } to { background-position: 0 44px, 0 44px; } }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.wrap { max-width: 640px; margin: 0 auto; }

/* ---- 見出し ---- */
.head { display: flex; align-items: baseline; gap: 8px; margin: 0 0 .3rem; }
.chip {
  font-family: ui-monospace, "Courier New", monospace; font-size: .62rem; letter-spacing: .12em;
  color: #04121a; background: var(--aqua); border-radius: 999px; padding: 2px 8px; font-weight: 800;
  white-space: nowrap;
}
.head h1 {
  font-size: 1.02rem; margin: 0; color: #fff3d8;
  text-shadow: 0 0 10px rgba(255,200,120,.5); letter-spacing: .04em;
}
.stats { margin-left: auto; display: flex; gap: 10px; }
.stat { display: inline-flex; align-items: baseline; gap: 4px; }
.lbl {
  font-size: .58rem; color: var(--aqua-deep); letter-spacing: .12em;
  font-family: ui-monospace, "Courier New", monospace;
}
.stat b { font-size: 1rem; font-variant-numeric: tabular-nums; font-family: ui-monospace, "Courier New", monospace; }

/* ---- お題 ---- */
.goal { display: flex; flex-wrap: wrap; gap: 4px; margin: 0 0 .3rem; }
.goal-chip {
  font-size: .64rem; font-weight: 700; font-family: ui-monospace, "Courier New", monospace;
  border: 1px solid rgba(255,60,175,.55); color: #ff9dd8; background: rgba(255,60,175,.08);
  border-radius: 999px; padding: .05rem .5rem; white-space: nowrap;
}
.goal-chip.ok { border-color: rgba(94,242,192,.7); color: var(--good); background: rgba(94,242,192,.1); }

/* ---- 回路 ---- */
#circuit {
  display: block; width: 100%; height: auto; margin: 0 auto;
  max-width: min(100%, calc(66vh * 640 / 400));
  aspect-ratio: 640 / 400;
  border: 1px solid var(--line); border-radius: 10px; background: #0d0b1e;
  box-shadow: inset 0 0 40px rgba(0,0,0,.6);
}
/* 配線: 0 は暗く、1 はネオンで光らせる(仕様§3 の可視化) */
.wire { fill: none; stroke: #3a3768; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.wire.on { stroke: var(--aqua); stroke-width: 3; filter: drop-shadow(0 0 4px rgba(45,226,255,.9)); }

/* スイッチ */
.sw { cursor: pointer; }
.sw-box { fill: #1e1b3d; stroke: #6f74a8; stroke-width: 2; transition: fill .12s, stroke .12s; }
.sw.on .sw-box { fill: #0f4a5c; stroke: var(--aqua); filter: drop-shadow(0 0 6px rgba(45,226,255,.7)); }
.sw-label { fill: var(--mut); font: 700 15px ui-monospace, "Courier New", monospace; text-anchor: middle; }
.sw.on .sw-label { fill: #eafcff; }
.sw:hover .sw-box { stroke: var(--aqua-deep); }
.sw:focus-visible { outline: none; }
.sw:focus-visible .sw-box { stroke: #ffd47a; stroke-width: 3; }

/* ゲート */
.gate-shape { fill: #1b1838; stroke: #7c7fbe; stroke-width: 2; }
.gate.on .gate-shape { stroke: var(--aqua); fill: #14304a; }
.gate-shape.xor-arc, .gate-shape.bubble { fill: none; }
.gate.on .gate-shape.bubble { fill: #14304a; }
.gate-label { fill: var(--mut); font: 700 10px ui-monospace, "Courier New", monospace; text-anchor: middle; letter-spacing: .04em; }
.gate.on .gate-label { fill: var(--aqua-deep); }

/* 出力ランプ */
.lamp-bulb { fill: #241f3f; stroke: #6f74a8; stroke-width: 2.5; }
.lamp.on .lamp-bulb { fill: #7a5a12; stroke: var(--amber); filter: drop-shadow(0 0 10px rgba(255,176,46,.85)); }
.lamp.ok .lamp-bulb { stroke: var(--good); }
.lamp.on.ok .lamp-bulb { fill: #17694f; stroke: var(--good); filter: drop-shadow(0 0 10px rgba(94,242,192,.85)); }
.lamp-label { fill: var(--ink); font: 700 11px system-ui, sans-serif; }
.lamp-goal { fill: var(--mut); font: 10px ui-monospace, "Courier New", monospace; }
.lamp.ok .lamp-goal { fill: var(--good); }

/* ---- 文言・ボタン ---- */
.under { display: flex; align-items: center; gap: 10px; margin: .3rem 0 .1rem; }
.hint { font-size: .68rem; color: var(--mut); line-height: 1.45; margin: 0; flex: 1; }
.msg { min-height: 1.2em; font-size: .7rem; font-weight: 700; color: var(--aqua-deep); margin: 0; }
.msg.warn { color: #ffcf6b; }
.msg.info { color: var(--aqua-deep); }
.btn {
  font: inherit; font-size: .74rem; white-space: nowrap; font-weight: 800; letter-spacing: .03em;
  border: 0; border-radius: 8px; cursor: pointer; padding: .4rem .9rem;
  background: linear-gradient(135deg, var(--aqua), #13b6d6); color: #04121a;
  box-shadow: 0 0 12px rgba(45,226,255,.5);
}
.btn.ghost {
  background: transparent; color: var(--aqua-deep); border: 1px solid var(--aqua);
  box-shadow: inset 0 0 10px rgba(45,226,255,.12);
}
:focus-visible { outline: 3px solid #ffd47a; outline-offset: 2px; }
.howto { font-size: .64rem; color: var(--mut); line-height: 1.65; margin: .2rem 0 0; }
.howto b { color: var(--aqua-deep); }

/* ---- クリアパネル ---- */
.clear-panel {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  background: rgba(8,6,15,.72); padding: 1rem;
}
.clear-panel[hidden] { display: none; } /* display:flex に hidden 属性が負けるのを防ぐ */
.clear-panel.show { animation: fadeIn .4s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.clear-card {
  background: linear-gradient(180deg, #1a1430, #120e22);
  border: 1px solid rgba(45,226,255,.45); border-radius: 14px;
  padding: 1.1rem 1.4rem; text-align: center; max-width: 21rem;
  box-shadow: 0 0 34px rgba(45,226,255,.28);
}
.clear-card h2 { margin: 0 0 .5rem; font-size: 1.2rem; color: #ff86d2; text-shadow: 0 0 12px rgba(255,60,175,.6); }
.clear-body { margin: 0 0 .4rem; font-size: .84rem; }
.clear-save { margin: 0 0 .8rem; font-size: .74rem; min-height: 1.2em; color: var(--aqua-deep); }

@media (max-width: 560px) {
  body { padding: .35rem; }
  .head h1 { font-size: .92rem; }
  .howto { font-size: .6rem; }
}

/* アニメーション低減の希望を尊重 */
@media (prefers-reduced-motion: reduce) {
  body::before, body::after, .clear-panel.show { animation: none; }
}
