/* 磁石マーブルパズル スタイル。
   背景演出はプラットフォーム(トップページ)と同じダーク(シンセウェイブ)に統一し、
   盤面(canvas)の中だけをゲーム側で描く。見せ場は「効果範囲の円」と「玉の軌跡」。 */
:root {
  --aqua: #2de2ff; --aqua-deep: #7ef0ff; --pink: #ff3caf;
  --amber: #ffb02e;
  --ink: #e9ecff; --mut: #9a9ed6; --bg: #08060f;
}
* { 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: .6rem;
  -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 6px; }
.chip {
  font-family: ui-monospace, "Courier New", monospace; font-size: .64rem; 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.1rem; margin: 0; color: #fff3d8;
  text-shadow: 0 0 10px rgba(255,200,120,.5); letter-spacing: .04em;
}
.clock { margin-left: auto; display: flex; align-items: baseline; gap: 6px; }
.clock .lbl {
  font-size: .6rem; color: var(--aqua-deep); letter-spacing: .12em;
  font-family: ui-monospace, "Courier New", monospace;
}
.clock b { font-size: 1.1rem; font-variant-numeric: tabular-nums; font-family: ui-monospace, "Courier New", monospace; }

/* ---- 本体: 盤面 + 右パネル ----
   プレイ画面の枠は 640x480(仕様§5)。縦に積むと操作ボタンが枠外へ出てしまうので、
   横に置ける幅があるときは 2カラムにして、盤面と操作系が枠内に収まるようにする。 */
.main { display: flex; gap: 10px; align-items: flex-start; }
.board-area { flex: 3 1 340px; min-width: 240px; }
.side { flex: 1 1 175px; min-width: 175px; }

#board {
  display: block; width: 100%; height: auto;
  /* 高さが足りない画面でも縦横比を保ったまま収める(max-height だと歪むので幅で抑える) */
  max-width: min(100%, calc(70vh * 4 / 3));
  aspect-ratio: 4 / 3;
  border: 2px solid rgba(45,226,255,.5); border-radius: 10px;
  box-shadow: 0 0 22px rgba(45,226,255,.18), inset 0 0 30px rgba(0,0,0,.6);
  touch-action: none;   /* ドラッグ配置中にスクロールさせない */
  cursor: crosshair;
}

.hint { font-size: .74rem; color: var(--mut); line-height: 1.5; margin: 0 0 .5rem; }

/* ---- パレット ---- */
.palette { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-bottom: .5rem; }
.mag-btn {
  font: inherit; font-size: .8rem; font-weight: 800; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  padding: .34rem .7rem; border-radius: 999px;
  background: rgba(255,255,255,.05); color: var(--ink);
  border: 1px solid rgba(255,255,255,.25);
}
.mag-btn .dot { width: 13px; height: 13px; border-radius: 50%; display: inline-block; }
.mag-btn.attract .dot { background: var(--aqua); box-shadow: 0 0 8px var(--aqua); }
.mag-btn.repel .dot { background: var(--amber); box-shadow: 0 0 8px var(--amber); }
.mag-btn.attract.active { border-color: var(--aqua); background: rgba(45,226,255,.18); box-shadow: 0 0 12px rgba(45,226,255,.4); }
.mag-btn.repel.active { border-color: var(--amber); background: rgba(255,176,46,.18); box-shadow: 0 0 12px rgba(255,176,46,.4); }
.mag-btn:disabled { cursor: default; opacity: .5; }
.mag-btn.locked { opacity: .28; text-decoration: line-through; }
.remain { font-size: .74rem; color: var(--mut); }
.remain b { font-size: 1rem; color: var(--aqua-deep); font-family: ui-monospace, "Courier New", monospace; }

/* ---- ボタン ---- */
.controls { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: .4rem; }
.btn {
  font: inherit; font-size: .82rem; font-weight: 800; letter-spacing: .03em;
  border: 0; border-radius: 8px; cursor: pointer; padding: .45rem .9rem;
  background: linear-gradient(135deg, var(--aqua), #13b6d6); color: #04121a;
  box-shadow: 0 0 12px rgba(45,226,255,.5);
}
.btn.stop { background: linear-gradient(135deg, #ff86d2, #ff3caf); color: #1a0313; box-shadow: 0 0 14px rgba(255,60,175,.55); }
.btn.ghost {
  background: transparent; color: var(--aqua-deep); border: 1px solid var(--aqua);
  box-shadow: inset 0 0 10px rgba(45,226,255,.12);
}
.btn:disabled { opacity: .38; cursor: default; box-shadow: none; }
:focus-visible { outline: 3px solid #ffd47a; outline-offset: 2px; }

.msg { min-height: 2.2em; font-size: .76rem; font-weight: 700; color: var(--aqua-deep); margin: 0 0 .4rem; }
.msg.warn { color: #ffcf6b; }
.msg.info { color: var(--aqua-deep); }

/* ---- 凡例・遊び方 ---- */
.legend { list-style: none; margin: 0 0 .5rem; padding: 0; display: flex; flex-wrap: wrap; gap: 3px 10px; font-size: .64rem; color: var(--mut); }
.legend li { display: flex; align-items: center; gap: 4px; }
.sw { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.sw-start { border-radius: 50%; border: 2px dashed rgba(126,240,255,.8); }
.sw-goal { background: rgba(255,60,175,.35); box-shadow: inset 0 0 0 2px rgba(255,134,210,.95); }
.sw-wall { background: #243055; box-shadow: inset 0 0 0 1px rgba(45,226,255,.55); }
.sw-spike { background: #ff5a7a; }
.sw-attract { border-radius: 50%; background: var(--aqua); box-shadow: 0 0 6px var(--aqua); }
.sw-repel { border-radius: 50%; background: var(--amber); box-shadow: 0 0 6px var(--amber); }
.howto { font-size: .68rem; color: var(--mut); line-height: 1.6; margin: 0; }

/* ---- クリアパネル ---- */
.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; } /* .clear-panel の 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: 20rem;
  box-shadow: 0 0 34px rgba(45,226,255,.28);
}
.clear-card h2 { margin: 0 0 .5rem; font-size: 1.25rem; color: #ff86d2; text-shadow: 0 0 12px rgba(255,60,175,.6); }
.clear-body { margin: 0 0 .4rem; font-size: .86rem; color: var(--ink); }
.clear-save { margin: 0 0 .8rem; font-size: .76rem; min-height: 1.2em; color: var(--aqua-deep); }

/* 狭い画面: 盤面の下にパネルを積む(横に並べる幅が無いので縦積み+スクロール) */
@media (max-width: 560px) {
  body { padding: .4rem; }
  .main { flex-direction: column; gap: 8px; }
  .board-area, .side { flex: 1 1 auto; width: 100%; min-width: 0; }
  #board { max-width: 100%; }
  .head h1 { font-size: .98rem; }
  .btn { padding: .5rem .9rem; }
  .mag-btn { padding: .4rem .8rem; }
}

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