/* 数式ドロップ スタイル。
   背景演出はプラットフォーム(トップページ)と同じダーク(シンセウェイブ)に統一し、
   盤面(canvas)の中だけをゲーム側で描く。見せ場は「なぞった式のプレビュー」。 */
:root {
  --aqua: #2de2ff; --aqua-deep: #7ef0ff; --pink: #ff3caf;
  --amber: #ffb02e; --good: #5ef2c0;
  --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: #2a1500; background: var(--amber); border-radius: 999px; padding: 2px 8px; font-weight: 800;
  white-space: nowrap;
}
.head h1 {
  font-size: 1.05rem; margin: 0; color: #fff3d8;
  text-shadow: 0 0 10px rgba(255,200,120,.5); letter-spacing: .04em;
}
.score-box { margin-left: auto; display: flex; align-items: baseline; gap: 6px; }
.lbl {
  font-size: .6rem; color: var(--aqua-deep); letter-spacing: .12em;
  font-family: ui-monospace, "Courier New", monospace;
}
.score-box b { font-size: 1.2rem; font-variant-numeric: tabular-nums; font-family: ui-monospace, "Courier New", monospace; }

/* ---- 本体: 盤面 + 右パネル(枠 640x480 に収める) ---- */
.main { display: flex; gap: 10px; align-items: flex-start; }
.board-area { flex: 3 1 300px; min-width: 220px; }
.side { flex: 1 1 190px; min-width: 190px; }

#board {
  display: block; width: 100%; height: auto;
  max-width: min(100%, calc(72vh * 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: pointer;
}

/* ---- 次のブロック ---- */
.next-box { display: flex; align-items: center; gap: 8px; margin-bottom: .5rem; }
.next { display: inline-flex; gap: 5px; }
.nb {
  width: 26px; height: 26px; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  font-family: ui-monospace, "Courier New", monospace; font-weight: 800; font-size: .85rem;
  border: 1px solid; opacity: .6;
}
.nb.num { background: #123a52; border-color: var(--aqua); color: #dff9ff; }
.nb.op { background: #4a2412; border-color: var(--amber); color: #ffe6bd; }
.nb.now { opacity: 1; transform: scale(1.12); box-shadow: 0 0 10px rgba(45,226,255,.5); }

/* ---- 式のプレビュー ---- */
.formula {
  min-height: 3.2em; margin: 0 0 .5rem; padding: .4rem .5rem;
  border-radius: 8px; border: 1px solid rgba(255,255,255,.18);
  background: rgba(255,255,255,.04);
  font-family: ui-monospace, "Courier New", monospace; font-size: .78rem; font-weight: 700;
  color: var(--mut); word-break: break-word;
}
.formula.good { color: var(--good); border-color: rgba(94,242,192,.6); background: rgba(94,242,192,.1); }
.formula.merge { color: var(--amber); border-color: rgba(255,176,46,.6); background: rgba(255,176,46,.1); }
.formula.zero { color: var(--aqua-deep); border-color: rgba(45,226,255,.6); background: rgba(45,226,255,.1); }
.formula.bad { color: #ff9dd8; border-color: rgba(255,60,175,.5); }

/* ---- ボタン ---- */
.controls { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: .5rem; }
.btn {
  font: inherit; font-size: .82rem; font-weight: 800; letter-spacing: .03em;
  border: 0; border-radius: 8px; cursor: pointer; padding: .45rem 1rem;
  background: linear-gradient(135deg, var(--good), #23b98c); color: #03231a;
  box-shadow: 0 0 12px rgba(94,242,192,.45);
}
.btn.merge { background: linear-gradient(135deg, var(--amber), #d97f0b); color: #2a1500; box-shadow: 0 0 12px rgba(255,176,46,.5); }
.btn.zero { 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);
}
.btn:disabled { opacity: .38; cursor: default; box-shadow: none; }
:focus-visible { outline: 3px solid #ffd47a; outline-offset: 2px; }

/* ---- 記録 ---- */
.stats { list-style: none; margin: 0 0 .4rem; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.stats li { display: flex; align-items: baseline; gap: 4px; }
.stats b { font-family: ui-monospace, "Courier New", monospace; font-size: .95rem; }

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

.howto { font-size: .66rem; color: var(--mut); line-height: 1.65; margin: .5rem 0 0; }
.howto b { color: var(--aqua-deep); }

/* ---- ゲームオーバー ---- */
.over-panel {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  background: rgba(8,6,15,.72); padding: 1rem;
}
.over-panel[hidden] { display: none; } /* display:flex に hidden 属性が負けるのを防ぐ */
.over-panel.show { animation: fadeIn .4s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.over-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: 22rem;
  box-shadow: 0 0 34px rgba(45,226,255,.28);
}
.over-card h2 { margin: 0 0 .5rem; font-size: 1.25rem; color: #ff86d2; text-shadow: 0 0 12px rgba(255,60,175,.6); }
.over-body { margin: 0 0 .4rem; font-size: .84rem; color: var(--ink); }
.over-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: .95rem; }
}

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