/* 蜃気楼パズル スタイル。
   背景演出はプラットフォーム(トップページ)と同じダーク(シンセウェイブ)に統一し、
   盤面だけを砂漠色でまとめる。見せ場は「陽炎ラインの揺らぎ」と「水のように光る虚像の足場」(仕様§8)。 */
:root {
  --aqua: #2de2ff; --aqua-deep: #7ef0ff; --pink: #ff3caf;
  --ink: #e9ecff; --mut: #9a9ed6; --bg: #08060f;
  --sand: #d8b782; --sand-dark: #b8935c; --sand-edge: #8a6a3c;
  --chasm: #2a1c12; --pillar: #7c5730; --lever: #c8862c;
  --cell: clamp(28px, min(11vw, 8.2vh), 48px);
}
* { 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 {
  display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap;
  max-width: 640px; margin: 0 auto;
}

/* ---- 盤面 ---- */
.board-area { flex: 0 0 auto; }
.stage-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;
}
.stage-head h1 {
  font-size: 1.15rem; margin: 0; color: #fff3d8;
  text-shadow: 0 0 10px rgba(255,200,120,.5); letter-spacing: .04em;
}

.board {
  display: grid;
  grid-template-columns: repeat(var(--cols, 5), var(--cell));
  grid-template-rows: repeat(var(--rows, 5), var(--cell));
  gap: 2px; padding: 6px;
  background: linear-gradient(180deg, #3a2a18, #241a10);
  border: 3px solid var(--sand-edge); border-radius: 10px;
  box-shadow: inset 0 2px 14px rgba(0,0,0,.6), 0 0 20px rgba(45,226,255,.12);
}

/* 砂: 乾いた砂色に細かい風紋 */
.cell {
  position: relative; border-radius: 4px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.cell.t-sand, .cell.t-lever {
  background-color: var(--sand);
  background-image:
    repeating-linear-gradient(115deg, rgba(255,255,255,.13) 0 2px, transparent 2px 7px),
    linear-gradient(180deg, rgba(255,245,220,.2), rgba(120,85,40,.25));
  box-shadow: inset 0 -2px 4px rgba(120,85,40,.35);
}
/* 谷: 底の見えない裂け目 */
.cell.t-chasm {
  background-color: var(--chasm);
  background-image: linear-gradient(180deg, rgba(0,0,0,.75), rgba(60,35,18,.5));
  box-shadow: inset 0 3px 8px rgba(0,0,0,.85);
}

/* ゴール: 砂の上の目印(オアシスの旗) */
.cell.is-goal::before {
  content: "⚑"; font-size: calc(var(--cell) * .5); color: #1d6b7a;
  text-shadow: 0 0 6px rgba(45,226,255,.6);
}
.cell.is-goal { outline: 2px dashed rgba(45,226,255,.75); outline-offset: -3px; }

/* レバー */
.cell.t-lever::before {
  content: "⇅"; font-size: calc(var(--cell) * .5); font-weight: 900; color: #6a3d06;
}
.cell.t-lever { box-shadow: inset 0 0 0 2px var(--lever), inset 0 -2px 4px rgba(120,85,40,.35); }

/* 柱: 実物。コピーの「源」 */
.cell.is-pillar::after {
  content: ""; position: absolute; inset: 12%;
  border-radius: 3px;
  background:
    repeating-linear-gradient(90deg, rgba(50,25,8,.28) 0 1px, transparent 1px 4px),
    linear-gradient(180deg, #a97f47, #66451f);
  border: 1px solid rgba(0,0,0,.45);
  box-shadow: inset 0 2px 0 rgba(255,235,200,.4), 0 2px 4px rgba(0,0,0,.5);
}

/* 虚像の足場: 水のように光る。これがこのゲームの見せ場 */
.cell.is-copy {
  background-color: #0d3d4d;
  background-image: linear-gradient(180deg, rgba(126,240,255,.55), rgba(45,226,255,.2));
  box-shadow: inset 0 0 0 2px rgba(126,240,255,.8), 0 0 14px rgba(45,226,255,.55);
  animation: copyShimmer 2.6s ease-in-out infinite;
}
@keyframes copyShimmer { 0%, 100% { filter: brightness(1); } 50% { filter: brightness(1.28); } }

/* プレイヤー: 旅人 */
.cell.is-player::before {
  content: ""; position: absolute; width: 58%; height: 58%; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff6e0, #ff9d4d 60%, #c2521c);
  box-shadow: 0 0 12px rgba(255,157,77,.85), inset 0 -2px 4px rgba(120,40,0,.5);
  z-index: 4; animation: pop .18s ease-out;
}
.cell.is-goal.is-player::before { z-index: 5; }
@keyframes pop { from { transform: scale(.65); } to { transform: scale(1); } }

/* 陽炎ライン: 対称軸。ゆらゆら揺れる帯 */
.mirage-line {
  pointer-events: none; z-index: 3; align-self: stretch;
  border-top: 1px dashed rgba(126,240,255,.45);
  border-bottom: 1px dashed rgba(126,240,255,.45);
  background: linear-gradient(90deg, transparent, rgba(126,240,255,.16), transparent);
}
.mirage-line.on {
  border-color: rgba(126,240,255,.9);
  background: linear-gradient(90deg, rgba(45,226,255,.05), rgba(126,240,255,.4), rgba(45,226,255,.05));
  box-shadow: 0 0 16px rgba(45,226,255,.5);
  animation: heat 1.8s ease-in-out infinite;
}
@keyframes heat {
  0%, 100% { transform: translateY(0) scaleY(1); opacity: .95; }
  50% { transform: translateY(1px) scaleY(1.18); opacity: .7; }
}

/* 柱 → 虚像 をつなぐ光の筋 */
.ray {
  pointer-events: none; z-index: 2; justify-self: center; width: 30%;
  background: linear-gradient(180deg, rgba(126,240,255,0), rgba(126,240,255,.28), rgba(126,240,255,0));
  border-radius: 999px;
}

/* 無効な操作: 落下死のかわりに盤面を揺らす(仕様§4.6) */
.board.shake { animation: shake .28s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}
/* クリア演出: 足場が水面のように広がる */
.board.cleared .cell.is-copy { animation: ripple 1.1s ease-out; }
@keyframes ripple {
  0% { box-shadow: inset 0 0 0 2px rgba(126,240,255,.8), 0 0 14px rgba(45,226,255,.55); }
  60% { box-shadow: inset 0 0 0 2px rgba(126,240,255,1), 0 0 40px 12px rgba(45,226,255,.75); }
  100% { box-shadow: inset 0 0 0 2px rgba(126,240,255,.8), 0 0 14px rgba(45,226,255,.55); }
}

/* ---- 右パネル ---- */
.panel { flex: 1 1 200px; min-width: 186px; }
.hint { font-size: .78rem; color: var(--mut); line-height: 1.55; margin: 0 0 .6rem; }
.stats { display: flex; gap: 16px; margin-bottom: .6rem; }
.stat { display: flex; flex-direction: column; }
.stat .lbl {
  font-size: .62rem; color: var(--aqua-deep); letter-spacing: .12em;
  font-family: ui-monospace, "Courier New", monospace;
}
.stat b { font-size: 1.3rem; font-variant-numeric: tabular-nums; font-family: ui-monospace, "Courier New", monospace; }

/* 方向パッド */
.pad {
  display: grid; grid-template-columns: repeat(3, 40px); grid-template-rows: repeat(2, 36px);
  gap: 5px; margin-bottom: .6rem;
}
.pad-btn {
  font: inherit; font-size: .9rem; border-radius: 8px; cursor: pointer;
  border: 1px solid rgba(45,226,255,.55); color: var(--aqua-deep);
  background: rgba(45,226,255,.08);
}
.pad-btn:active { background: rgba(45,226,255,.28); }
.pad-btn.up { grid-area: 1 / 2; }
.pad-btn.left { grid-area: 2 / 1; }
.pad-btn.down { grid-area: 2 / 2; }
.pad-btn.right { grid-area: 2 / 3; }

.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: .42rem .85rem;
  background: linear-gradient(135deg, var(--aqua), #13b6d6); color: #04121a;
  box-shadow: 0 0 12px rgba(45,226,255,.5);
}
.btn.on { background: linear-gradient(135deg, #ffd47a, #ff9d4d); box-shadow: 0 0 14px rgba(255,157,77,.7); }
.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.4em; font-size: .76rem; font-weight: 700; color: var(--aqua-deep); margin: 0 0 .5rem; }
.msg.warn { color: #ffcf6b; }
.msg.info { color: var(--aqua-deep); }

.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: .66rem; color: var(--mut); }
.legend li { display: flex; align-items: center; gap: 4px; }
.sw { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.sw-sand { background: var(--sand); }
.sw-chasm { background: var(--chasm); box-shadow: inset 0 0 0 1px rgba(255,255,255,.15); }
.sw-copy { background: linear-gradient(180deg, #7ef0ff, #2de2ff); box-shadow: 0 0 6px rgba(45,226,255,.7); }
.sw-pillar { background: linear-gradient(180deg, #a97f47, #66451f); }
.sw-lever { background: var(--sand); box-shadow: inset 0 0 0 2px var(--lever); }
.sw-goal { background: var(--sand); box-shadow: inset 0 0 0 2px rgba(45,226,255,.8); }

/* ---- クリアパネル ---- */
.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 .45s 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: 480px) {
  .wrap { gap: 10px; }
  .panel { flex: 1 1 100%; }
  .pad { grid-template-columns: repeat(3, 48px); grid-template-rows: repeat(2, 42px); }
}

/* アニメーション低減の希望を尊重(仕様§9) */
@media (prefers-reduced-motion: reduce) {
  body::before, body::after,
  .mirage-line.on, .cell.is-copy, .cell.is-player::before,
  .board.shake, .board.cleared .cell.is-copy, .clear-panel.show { animation: none; }
}
