/* COORD MAZE。土台の色とパーツは space.css にある。ここは配置と盤面の見た目。 */

:root {
  --cell: 48px;
  --gap: 8px;
  --label: 34px;   /* 行頭の軸名の幅。JS が盤面の寸法を計算するのにも読む */
  --rowgap: 12px;  /* 軸名とマス目の間 */
  --edge: 32px;    /* ページ左右の余白 */
}

/* -------------------------------------------------------------- ヘッダー */

header { padding: calc(34px + var(--sat)) var(--edge) 10px; position: relative; }
h1 { margin: 0; font-size: 34px; text-shadow: 0 0 30px rgba(111, 240, 255, 0.28); }
h1 span { color: var(--ion); }
/* タイトルの紋章。盤面と同じ見立て (軌道・惑星・恒星) を小さく */
h1 .logo {
  width: 1.25em; height: 1.25em; vertical-align: -0.24em; margin-right: 0.42em;
  filter: drop-shadow(0 0 10px rgba(111, 240, 255, 0.35));
}
.tagline { margin: 7px 0 0; color: var(--dim); letter-spacing: 0.02em; }

.backs { position: absolute; right: var(--edge); top: 36px; display: flex; gap: 10px; flex-wrap: wrap; }
.back {
  color: var(--dim); text-decoration: none;
  border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 14px; white-space: nowrap;
  background: rgba(130, 170, 240, 0.04);
  transition: 0.16s;
}
@media (hover: hover) {
  .back:hover { color: var(--ion); border-color: var(--ion); box-shadow: var(--glow) rgba(111, 240, 255, 0.5); }
}

main {
  display: grid; grid-template-columns: minmax(0, 1fr) 360px;
  gap: 28px; padding: 20px var(--edge) 48px; align-items: start;
}

/* --------------------------------------------------------------- ホーム */

#home {
  display: flex; align-items: center; justify-content: center;
  min-height: 100dvh; padding: 24px var(--edge);
}
#home[hidden], #game[hidden] { display: none; }
.home-card { max-width: 420px; width: 100%; text-align: center; }
.home-card #btn-start { margin-top: 22px; }
#home-summary { margin: 14px 0 0; color: var(--dim); font-size: 13px; line-height: 1.6; }
.home-card .btnlink { margin-top: 14px; }
/* width: 100% と min-width: 0 がないと、auto マージンのせいで
   盤面の最大幅まで広がり、広い盤面がページごと横に伸びる */
#play { max-width: 820px; width: 100%; min-width: 0; margin: 0 auto; }

/* ---------------------------------------------------------------- 計器類 */

.stats { display: flex; flex-wrap: wrap; gap: 10px 26px; margin-bottom: 22px; }
.stats div { display: flex; flex-direction: column; gap: 3px; }
.stats span { color: var(--dim); font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; }
.stats b { font-size: 21px; font-variant-numeric: tabular-nums; text-shadow: 0 0 20px rgba(111, 240, 255, 0.18); }
.stats .coord b { font-family: ui-monospace, Menlo, monospace; font-size: 17px; }

/* ------------------------------------------------------------------ 盤面 */

#board {
  display: inline-flex; flex-direction: column; gap: var(--gap);
  max-width: 100%; overflow-x: auto;
  padding: 20px 22px;
  /* 指で触る盤面。長押しの選択やダブルタップ拡大が誤作動しないようにする */
  user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  overscroll-behavior-x: contain;
  /* 盤面は宇宙をのぞく窓。右 (恒星の側) がほんのり金色に明るい */
  background:
    radial-gradient(ellipse 60% 90% at 100% 50%, rgba(255, 190, 110, 0.07), transparent 70%),
    radial-gradient(ellipse 70% 80% at 0% 0%, rgba(90, 70, 200, 0.10), transparent 70%),
    linear-gradient(rgba(140, 180, 255, 0.05), rgba(140, 180, 255, 0) 40%),
    rgba(5, 8, 20, 0.66);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(10px);
  box-shadow: 0 20px 60px -34px #000, inset 0 1px 0 rgba(190, 215, 255, 0.06);
}

.colhead { display: flex; gap: var(--gap); justify-content: center; margin-bottom: 4px; }
.colhead div {
  width: var(--cell); text-align: center; color: var(--dim);
  font-size: 10px; letter-spacing: 0.1em; font-variant-numeric: tabular-nums;
}
.colhead div.s { color: var(--ion); }
.colhead div.g { color: var(--star); }

/* 横なぞりは「行を動かす」に使うので、ブラウザの横スクロールには渡さない。
   盤面が横に流れるとき (.scrolls) だけは、指のスクロールを優先する。 */
.row { display: flex; align-items: center; justify-content: center; gap: var(--rowgap); cursor: pointer; touch-action: pan-y; }
/* 右側の釣り合いを取るための空き。これがないとマス目が軸名のぶん右にずれる */
.row::after { content: ''; flex: none; width: var(--label); }
#board.scrolls .row { touch-action: auto; justify-content: flex-start; }
#board.scrolls .colhead { justify-content: flex-start; margin-left: calc(var(--label) + var(--rowgap)); }
#board.scrolls .row::after { display: none; }
.rowlabel {
  width: var(--label); flex: none; text-align: right;
  font-family: ui-monospace, Menlo, monospace; font-size: 15px;
  color: var(--dim); transition: color 0.16s, text-shadow 0.16s;
}
.row.sel .rowlabel { color: var(--rowc); text-shadow: 0 0 14px var(--rowc); font-weight: 700; }
/* 横に流れるときは軸名だけ左端に貼り付ける (列見出しはマスと一緒に動かす) */
#board.scrolls .rowlabel {
  position: sticky; left: 0; z-index: 1;
  background: rgba(6, 10, 22, 0.92);
}

/* 各行は軌道。コマはその上を進む惑星、ゴール列は恒星という見立て。
   軌道は点線で引き、選んでいる行だけ光がゴールへ向かって流れる。 */
.track { position: relative; display: flex; gap: var(--gap); }
.track::before {
  content: ''; position: absolute; left: calc(var(--cell) / 2); right: calc(var(--cell) / 2); top: 50%;
  height: 1px; transform: translateY(-0.5px);
  background: repeating-linear-gradient(90deg, var(--rowc) 0 5px, transparent 5px 11px);
  opacity: 0.22; pointer-events: none;
}
.row.sel .track::before {
  height: 2px; transform: translateY(-1px); opacity: 0.6;
  animation: orbit-flow 1.1s linear infinite;
}
@keyframes orbit-flow { to { background-position: 11px 0; } }

/* マスは軌道上の「停泊点」。四角い箱ではなく、中心に小さな点のある淡い円 */
.cell {
  width: var(--cell); height: var(--cell);
  flex: none;
  border-radius: 50%;
  border: 1px solid rgba(122, 156, 224, 0.12);
  background:
    radial-gradient(circle, rgba(170, 200, 255, 0.28) 0 5%, transparent 6.5%),
    radial-gradient(circle, rgba(140, 180, 255, 0.05), transparent 70%);
  position: relative;
  transition: border-color 0.16s, background 0.16s, box-shadow 0.16s, transform 0.1s, filter 0.1s;
}

/* スタートは小さな渦 (ワームホール)。ここから全部の惑星が出発する */
.cell.start { border-color: rgba(111, 240, 255, 0.28); }
.cell.start::before {
  content: ''; position: absolute; inset: 8%; border-radius: 50%; pointer-events: none;
  background:
    radial-gradient(circle, rgba(4, 8, 20, 0.9) 0 16%, transparent 30%),
    repeating-conic-gradient(from 0deg, rgba(111, 240, 255, 0.34) 0 7deg, transparent 7deg 24deg, rgba(176, 107, 255, 0.26) 24deg 31deg, transparent 31deg 45deg);
  -webkit-mask: radial-gradient(circle, #000 40%, transparent 72%);
          mask: radial-gradient(circle, #000 40%, transparent 72%);
  animation: spin 16s linear infinite;
}

/* ゴールは恒星。白い芯・金色の光球・ゆっくり回るコロナ */
.cell.goal {
  border-color: rgba(255, 217, 138, 0.28);
  background:
    radial-gradient(circle, #fffbea 0 9%, #ffe3a0 15%, rgba(255, 186, 84, 0.72) 26%,
                    rgba(255, 140, 50, 0.22) 44%, transparent 64%);
  box-shadow: 0 0 28px -6px rgba(255, 200, 110, 0.85);
}
.cell.goal::before {
  content: ''; position: absolute; inset: -16%; border-radius: 50%; pointer-events: none;
  background: repeating-conic-gradient(rgba(255, 217, 138, 0.26) 0 3deg, transparent 3deg 13deg);
  -webkit-mask: radial-gradient(circle, transparent 26%, #000 36%, transparent 68%);
          mask: radial-gradient(circle, transparent 26%, #000 36%, transparent 68%);
  animation: spin 48s linear infinite;
}
@keyframes spin { to { transform: rotate(1turn); } }

/* 動かせる先。まだ行っていない状態へは、行の色で脈打つ輪 */
.cell.can { cursor: pointer; }
.cell.can.fresh {
  border-color: var(--rowc);
  background:
    radial-gradient(circle, var(--rowc) 0 6%, transparent 7.5%),
    radial-gradient(circle, color-mix(in srgb, var(--rowc) 18%, transparent), transparent 72%);
  box-shadow: 0 0 16px -4px var(--rowc), inset 0 0 12px -6px var(--rowc);
  animation: beacon 1.8s ease-in-out infinite;
}
@keyframes beacon {
  50% { box-shadow: 0 0 22px -2px var(--rowc), 0 0 0 3px color-mix(in srgb, var(--rowc) 22%, transparent),
                    inset 0 0 12px -6px var(--rowc); }
}
.cell.goal.can.fresh { background:
    radial-gradient(circle, #fffbea 0 9%, #ffe3a0 15%, rgba(255, 186, 84, 0.72) 26%,
                    rgba(255, 140, 50, 0.22) 44%, transparent 64%); }
/* 通ったことのある状態へ戻る手。脈打たせず、点を大きめに出して「行ける」ことだけ伝える */
.cell.can.been {
  border-color: rgba(150, 180, 235, 0.58);
  background: radial-gradient(circle, rgba(122, 156, 224, 0.12), transparent 72%);
  box-shadow: inset 0 0 10px -5px rgba(170, 200, 255, 0.9);
}
.cell.can.been::after {
  content: ''; position: absolute; left: 50%; top: 50%;
  width: 7px; height: 7px; margin: -3.5px 0 0 -3.5px;
  border-radius: 50%; background: rgba(185, 210, 255, 0.85);
}
@media (hover: hover) {
  .cell.can:hover { filter: brightness(1.45); }
}
.cell.can:active { filter: brightness(1.6); transform: scale(0.94); }
.cell.hint { animation: hint 0.9s ease-in-out 3; }
@keyframes hint {
  0%, 100% { box-shadow: 0 0 0 0 transparent; }
  50% { box-shadow: 0 0 0 3px var(--star), 0 0 26px -4px var(--star); }
}

/* ------------------------------------------------------------------ 惑星 */

/* コマの入れ物。位置だけを受け持つ (中の惑星・光跡は下) */
.token {
  position: absolute; left: 0; top: 0; z-index: 1;
  width: var(--cell); height: var(--cell);
  transform: translateX(calc(var(--c) * (var(--cell) + var(--gap))));
  transition: transform 0.18s cubic-bezier(0.3, 0.9, 0.35, 1);
  pointer-events: none;
}

/* 惑星の本体。下地は行の色の球 (左上から光が当たる)。
   --surface に模様を重ね、::before で陰と大気の縁を、::after で輪や衛星を描く。 */
.planet {
  --lit: color-mix(in srgb, var(--rowc) 45%, #fff);
  --dark: color-mix(in srgb, var(--rowc) 30%, #04050c);
  --surface: linear-gradient(transparent, transparent);
  position: absolute; inset: 15%; border-radius: 50%;
  background:
    var(--surface),
    radial-gradient(circle at 36% 32%, var(--lit), var(--rowc) 42%, var(--dark) 100%);
  box-shadow: 0 0 18px -4px var(--rowc), 0 0 40px -14px var(--rowc);
  transition: box-shadow 0.3s;
}
.planet::before {
  content: ''; position: absolute; inset: 0; border-radius: 50%;
  background:
    radial-gradient(circle at 30% 26%, rgba(255, 255, 255, 0.62), transparent 26%),
    radial-gradient(circle at 76% 80%, rgba(2, 3, 10, 0.78), transparent 64%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.10), inset 0.06em 0.08em 0.3em rgba(255, 255, 255, 0.12);
}
.planet::after { content: none; }

/* 0: 縞のガス惑星と、大きな渦 */
.planet.p0 { --surface:
  radial-gradient(ellipse 20% 12% at 62% 63%, rgba(255, 238, 220, 0.6), transparent 72%),
  repeating-linear-gradient(8deg, transparent 0 13%, rgba(255, 255, 255, 0.16) 13% 19%,
                            transparent 19% 27%, rgba(0, 0, 0, 0.2) 27% 34%); }

/* 1: 輪のある惑星。輪の奥側は薄く、手前側は濃く描いて球の前を横切らせる */
.planet.p1 { --surface:
  repeating-linear-gradient(-16deg, transparent 0 22%, rgba(255, 255, 255, 0.12) 22% 27%); }
.planet.p1::after, .planet.p5::after {
  content: ''; position: absolute; left: -42%; right: -42%; top: 38%; height: 24%;
  border-radius: 50%;
  border: max(1.5px, 0.09em) solid color-mix(in srgb, var(--rowc) 45%, #fff);
  border-top-color: color-mix(in srgb, var(--rowc) 30%, transparent);
  transform: rotate(-17deg);
  box-shadow: 0 0 10px -3px var(--rowc);
}

/* 2: クレーターの岩石惑星 */
.planet.p2 { --surface:
  radial-gradient(circle at 30% 60%, rgba(0, 0, 0, 0.30) 0 10%, rgba(255, 255, 255, 0.10) 11%, transparent 13%),
  radial-gradient(circle at 63% 30%, rgba(0, 0, 0, 0.26) 0 7%, rgba(255, 255, 255, 0.10) 8%, transparent 10%),
  radial-gradient(circle at 70% 66%, rgba(0, 0, 0, 0.24) 0 5%, transparent 7%),
  radial-gradient(circle at 44% 36%, rgba(0, 0, 0, 0.18) 0 4%, transparent 5.5%),
  radial-gradient(circle at 48% 82%, rgba(0, 0, 0, 0.2) 0 4%, transparent 5.5%); }

/* 3: 氷の惑星。両極の白い氷冠と、薄い筋 */
.planet.p3 { --surface:
  radial-gradient(ellipse 62% 24% at 50% 3%, rgba(255, 255, 255, 0.85), transparent 72%),
  radial-gradient(ellipse 50% 18% at 50% 98%, rgba(255, 255, 255, 0.6), transparent 72%),
  repeating-linear-gradient(-32deg, transparent 0 16%, rgba(255, 255, 255, 0.12) 16% 18%); }

/* 4: 溶岩の惑星。暗い地表に光る割れ目 */
.planet.p4 {
  --surface:
    radial-gradient(circle at 42% 56%, rgba(255, 226, 170, 0.75) 0 4%, transparent 9%),
    radial-gradient(circle at 66% 36%, rgba(255, 226, 170, 0.6) 0 3%, transparent 7%),
    repeating-linear-gradient(58deg, transparent 0 17%, rgba(255, 210, 150, 0.32) 17% 19.5%),
    repeating-linear-gradient(-38deg, transparent 0 23%, rgba(255, 210, 150, 0.22) 23% 25%);
  background:
    var(--surface),
    radial-gradient(circle at 36% 32%, var(--rowc), var(--dark) 70%);
}

/* 5: 縦に近い輪を持つ青白い惑星 (天王星のように横倒し) */
.planet.p5 { --surface:
  linear-gradient(90deg, rgba(255, 255, 255, 0.10), transparent 40%, rgba(255, 255, 255, 0.08)); }
.planet.p5::after { transform: rotate(72deg); left: -30%; right: -30%; }

/* 6: 衛星を連れた惑星。小さな月がまわりを回る */
.planet.p6 { --surface:
  radial-gradient(ellipse 34% 20% at 38% 64%, rgba(0, 0, 0, 0.18), transparent 70%),
  radial-gradient(ellipse 26% 16% at 66% 34%, rgba(255, 255, 255, 0.14), transparent 70%); }
.planet.p6::after {
  content: ''; position: absolute; left: 39%; top: 39%; width: 22%; height: 22%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, #b9c3d8 60%, #4b5468);
  animation: moon 7s linear infinite;
}
@keyframes moon {
  from { transform: rotate(0deg) translateX(330%) rotate(0deg); }
  to { transform: rotate(360deg) translateX(330%) rotate(-360deg); }
}

/* 7: 雲の渦巻く、地球のような惑星 */
.planet.p7 { --surface:
  radial-gradient(ellipse 30% 14% at 34% 34%, rgba(255, 255, 255, 0.55), transparent 70%),
  radial-gradient(ellipse 26% 12% at 64% 60%, rgba(255, 255, 255, 0.45), transparent 70%),
  radial-gradient(ellipse 20% 10% at 42% 78%, rgba(255, 255, 255, 0.35), transparent 70%),
  conic-gradient(from 40deg at 56% 46%, transparent 0 20%, rgba(0, 0, 0, 0.16) 20% 34%, transparent 34% 60%,
                 rgba(0, 0, 0, 0.12) 60% 72%, transparent 72%); }

/* 動いた瞬間の光跡。進んだ向きの反対側 (来た側) に、行の色で短く尾を引く */
.trail {
  position: absolute; top: 45%; height: 10%; left: -60%; right: 50%;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, var(--rowc));
  transform-origin: 100% 50%;
  transform: scaleX(var(--dir, 1));
  opacity: 0; pointer-events: none;
}
.token.fly .trail { animation: trail 0.42s ease-out; }
@keyframes trail {
  0% { opacity: 0.9; clip-path: inset(0 0 0 0); }
  100% { opacity: 0; clip-path: inset(0 0 0 75%); }
}

.token.bump .planet { animation: bump 0.22s; }
@keyframes bump {
  25% { transform: translateX(-6%); filter: brightness(0.5) saturate(0.4); }
  75% { transform: translateX(6%); }
}

/* 恒星に着いた惑星は、金色の光を浴びる。✓ は小さな印にして惑星の絵を隠さない */
.token.done .planet { box-shadow: 0 0 22px 1px rgba(255, 217, 138, 0.75), 0 0 0 1.5px rgba(255, 230, 170, 0.9); }
.token.done::after {
  content: '✓'; position: absolute; right: 2%; bottom: 2%;
  width: max(12px, 34%); height: max(12px, 34%);
  display: grid; place-items: center; border-radius: 50%;
  background: var(--star); color: #3a2600;
  font-size: max(8px, calc(var(--cell) * 0.2)); font-weight: 800; line-height: 1;
  box-shadow: 0 0 10px rgba(255, 217, 138, 0.9);
}

@media (prefers-reduced-motion: reduce) {
  .row.sel .track::before, .cell.start::before, .cell.goal::before,
  .cell.can.fresh, .planet.p6::after, .token.fly .trail { animation: none; }
}

/* 右カラムの見出しは、スマホでは開閉できる見出しになる (details/summary) */
.sec { border-bottom: 1px solid transparent; }
.sec > summary { list-style: none; cursor: default; }
.sec > summary::-webkit-details-marker { display: none; }
.sec > summary h2 { display: inline-block; }

.controls { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 22px; }

/* ---------------------------------------------------------------- シェア */

button.back { font-size: inherit; font-family: inherit; cursor: pointer; }
button.share { display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.share-ico {
  width: 15px; height: 15px; flex: none;
  fill: currentColor; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round;
}

/* アプリにする (webapp-kit)。枠の中に + の角丸四角。塗らずに線だけで描く */
.install-ico { fill: none; stroke-linejoin: round; }
/* iPhone / Mac Safari で出る「ホーム画面に追加」の案内を宇宙テーマの色にそろえる */
:root {
  --wak-bg: #0a1022;
  --wak-fg: var(--ink);
  --wak-muted: var(--dim);
  --wak-line: var(--line);
  --wak-accent: var(--ion);
  --wak-accent-fg: #03121a;
  --wak-radius: var(--radius);
}

/* 画面の下に一瞬だけ出る知らせ (「リンクをコピーしました」) */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--sab)); z-index: 60;
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  padding: 10px 18px; border-radius: 999px; white-space: nowrap;
  background: rgba(9, 14, 28, 0.94); border: 1px solid var(--ion); color: var(--ion);
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ------------------------------------------------- メニュー (狭い画面用) */

/* 広い画面では右カラムをそのまま出すので、ボタンも背景も要らない */
.menu-btn, .scrim, .side-head, button.side-share { display: none; }

.menu-btn {
  position: absolute; right: var(--edge); top: 30px;
  align-items: center; gap: 9px;
  padding: 10px 14px; font-size: 13px;
}
/* ハンバーガー (3 本線) */
.bars, .bars::before, .bars::after {
  content: ''; display: block; width: 16px; height: 2px; border-radius: 2px;
  background: currentColor; transition: transform 0.18s, opacity 0.18s;
}
.bars { position: relative; }
.bars::before { position: absolute; top: -5px; }
.bars::after { position: absolute; top: 5px; }
body.menu-open .bars { background: transparent; }
body.menu-open .bars::before { transform: translateY(5px) rotate(45deg); }
body.menu-open .bars::after { transform: translateY(-5px) rotate(-45deg); }

.side-head { align-items: center; gap: 10px; margin-bottom: 4px; }
.side-head .btnlink { flex: 1; margin-top: 0; }
.side-head .close { flex: none; width: 44px; padding: 0; font-size: 16px; line-height: 1; }

/* -------------------------------------------------------------- 右カラム */

aside { padding: 22px 24px; }
aside h2 {
  font-size: 12px; letter-spacing: 0.18em; text-transform: uppercase;
  margin: 24px 0 11px; color: var(--ion);
}
aside h2:first-child, aside .sec:first-of-type > summary h2 { margin-top: 0; }
aside p { line-height: 1.95; margin: 0 0 12px; color: #b6c6e0; }
aside p.note { color: var(--dim); font-size: 12px; line-height: 1.9; }
aside b { color: var(--ion); font-weight: 600; }
aside a { color: var(--ion); }
/* 制作元 (ポータル) へのリンク。引き出し / 右カラムのいちばん下に控えめに置く */
aside p.credit { margin: 22px 0 0; padding-top: 6px; border-top: 1px solid var(--line); font-size: 12px; text-align: center; }
aside p.credit a { color: var(--dim); text-decoration: none; display: inline-block; padding: 10px 12px; }
@media (hover: hover) { aside p.credit a:hover { color: var(--ion); } }

.chip { display: inline-block; width: 26px; height: 14px; border-radius: 4px; vertical-align: -2px; border: 1px solid; }
.chip.new { border-color: var(--ion); background: rgba(111, 240, 255, 0.16); }
.chip.seen { border-color: rgba(122, 156, 224, 0.4); background: rgba(122, 156, 224, 0.06); }

.field { margin-bottom: 16px; }
.field > label { display: block; color: var(--dim); font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; margin-bottom: 8px; }
.field small { display: block; color: var(--dim); margin-top: 6px; font-size: 11px; }
.opts { display: flex; gap: 6px; flex-wrap: wrap; }
.opts button { flex: 1 0 auto; min-width: 46px; padding: 8px 4px; font-variant-numeric: tabular-nums; }
.opts button:disabled { opacity: 0.22; cursor: not-allowed; }
.opts button[hidden] { display: none; }
/* 「もっと大きく」で増えたボタンは、少し色を変えて上級だと分かるように */
.opts button.more { border-style: dashed; }
.opts button.more.on { border-style: solid; }
button.more-toggle { margin: -4px 0 16px; font-size: 12px; color: var(--dim); }
button.wide { width: 100%; }
/* 設定の先頭に置く効果音の切り替え */
button.sound { margin-bottom: 16px; }
.states { margin: -6px 0 16px; color: var(--dim); font-size: 11px; font-family: ui-monospace, Menlo, monospace; }
/* 状態数の下に「どんな迷路になるか」を 1 行で出す */
.states span { display: block; margin-top: 4px; font-family: "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif; }

/* ---------------------------------------------------------------- 記録 */

.rec-table { margin: 2px 0 18px; font-size: 12px; }
.rec-head, .rec-row {
  display: grid; grid-template-columns: 4.2em 3.4em 1fr; gap: 8px;
  padding: 7px 0; border-bottom: 1px solid var(--line);
}
.rec-head { color: var(--dim); font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; }
.rec-row { color: #b6c6e0; font-variant-numeric: tabular-nums; }
.rec-row span:first-child { color: var(--ion); }
.rec-row small, .rec-item small { color: var(--dim); }

.rec-list h3 { margin: 0 0 8px; font-size: 11px; letter-spacing: 0.12em; color: var(--dim); font-weight: 600; }
.rec-item {
  display: grid; grid-template-columns: 3.6em 1fr auto; gap: 4px 8px;
  align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line);
  font-size: 12px; color: #b6c6e0; font-variant-numeric: tabular-nums;
}
.rec-item b { color: var(--ion); font-weight: 600; }
.rec-item button { grid-row: 1 / span 2; grid-column: 3; padding: 8px 12px; font-size: 12px; }
.rec-seed { font-family: ui-monospace, Menlo, monospace; letter-spacing: 0.08em; color: var(--star); }
.rec-num { grid-column: 1 / span 2; }
.rec-date { display: none; }
.rec-list + button { margin-top: 16px; }

/* ---------------------------------------------------------------- 結果 */

/* クリアの光。恒星の色の輪が 3 重に広がり、うしろで光条がゆっくり回る */
.burst { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.burst::before {
  content: ''; position: absolute; left: 50%; top: 42%; width: 140vmax; height: 140vmax;
  margin: -70vmax 0 0 -70vmax;
  background: repeating-conic-gradient(rgba(255, 217, 138, 0.05) 0 4deg, transparent 4deg 14deg);
  -webkit-mask: radial-gradient(circle, #000 0, transparent 55%);
          mask: radial-gradient(circle, #000 0, transparent 55%);
  animation: spin 60s linear infinite, burst-in 0.8s ease-out;
}
.burst i {
  position: absolute; left: 50%; top: 42%; width: 40px; height: 40px; margin: -20px 0 0 -20px;
  border-radius: 50%; border: 2px solid rgba(255, 217, 138, 0.8);
  box-shadow: 0 0 24px rgba(255, 200, 110, 0.5), inset 0 0 16px rgba(255, 200, 110, 0.3);
  opacity: 0; animation: ring 1.8s cubic-bezier(0.2, 0.7, 0.3, 1) forwards;
}
.burst i:nth-child(2) { animation-delay: 0.18s; border-color: rgba(111, 240, 255, 0.7); }
.burst i:nth-child(3) { animation-delay: 0.36s; border-color: rgba(176, 107, 255, 0.7); }
/* scale で広げると線まで太るので、大きさそのものを広げる (輪は 3 つだけなので軽い) */
@keyframes ring {
  0% { width: 16px; height: 16px; margin: -8px 0 0 -8px; opacity: 1; }
  100% { width: 170vmax; height: 170vmax; margin: -85vmax 0 0 -85vmax; opacity: 0; }
}
@keyframes burst-in { from { opacity: 0; } }
#win .sheet { position: relative; }
#win .sheet h2 {
  background: linear-gradient(90deg, var(--star), #fff3d6 50%, var(--star));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: none; filter: drop-shadow(0 0 16px rgba(255, 217, 138, 0.45));
}
@media (prefers-reduced-motion: reduce) {
  .burst::before, .burst i { animation: none; }
}

.confirm-body { line-height: 1.95; margin: 0 0 20px; color: #b6c6e0; }
.sheet h2 { margin: 0 0 18px; font-size: 24px; letter-spacing: 0.06em; }
.win-note { margin: -10px 0 18px; color: var(--star); font-size: 13px; }
.win-note:empty { display: none; }
.result { display: grid; gap: 9px; margin-bottom: 22px; }
.result div { display: flex; justify-content: space-between; border-bottom: 1px dashed var(--line); padding-bottom: 7px; }
.result span { color: var(--dim); }
.result b { font-variant-numeric: tabular-nums; }
.sheet button { width: 100%; margin-top: 10px; }

/* ============================================================================
   画面が狭いとき (タブレット〜スマホ)
   盤面がいちばん大事なので、まず盤面に幅と縦位置を譲る。
   説明文はたたみ、よく使うボタンは親指の届く下端に固定する。
   ========================================================================== */

@media (max-width: 1000px) {
  :root { --edge: 18px; --gap: 6px; }
  main { grid-template-columns: minmax(0, 1fr); }

  /* 画面はパズルと操作ボタンだけにして、説明と設定は引き出しにしまう */
  .backs { display: none; }
  .side-head { display: flex; }
  button.side-share { display: flex; margin: 10px 0 14px; }
  /* アプリにする と シェア が並ぶときは、間を詰めて 1 組に見せる */
  button.side-share:not([hidden]) + button.side-share { margin-top: -6px; }

  /* タイトルとメニューを 1 行に並べる (絶対配置だと狭い画面で重なる) */
  header { display: flex; flex-wrap: wrap; align-items: center; column-gap: 12px; }
  h1 { flex: 1 1 auto; min-width: 0; }
  .tagline { flex: 1 0 100%; order: 3; }
  .menu-btn { display: inline-flex; position: static; flex: none; margin-left: auto; }

  aside {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: 30;
    width: min(400px, 92vw);
    border-radius: 0; border-right: 0; border-top: 0; border-bottom: 0;
    overflow-y: auto; overscroll-behavior: contain;
    padding: calc(18px + var(--sat)) max(18px, var(--sar))
             calc(18px + var(--sab)) 18px;
    transform: translateX(101%);
    transition: transform 0.22s cubic-bezier(0.3, 0.9, 0.35, 1);
    box-shadow: -24px 0 60px -30px #000;
  }
  body.menu-open aside { transform: none; }
  body.menu-open { overflow: hidden; }

  body.menu-open .scrim {
    display: block; position: fixed; inset: 0; z-index: 25;
    background: rgba(3, 5, 12, 0.6);
    backdrop-filter: blur(3px);
    animation: overlay-in 0.2s ease-out;
  }
}

@media (prefers-reduced-motion: reduce) {
  aside { transition: none; }
}

@media (max-width: 700px) {
  :root { --edge: 14px; --gap: 5px; --label: 26px; }

  /* ヘッダーは 1 画面ぶんの高さを食わない程度に詰める */
  header { padding-top: calc(16px + var(--sat)); padding-bottom: 4px; }
  h1 { font-size: 22px; letter-spacing: 0.1em; white-space: nowrap; }
  h1 .logo { margin-right: 0.3em; }
  .tagline { font-size: 12px; margin-top: 4px; }
  .menu-btn { padding: 9px 12px; }

  main { padding-top: 14px; padding-bottom: 28px; gap: 18px; }

  /* 計器は 2 列に畳む。数字は小さくしても読めるので盤面に高さを回す */
  .stats { gap: 8px 18px; margin-bottom: 14px; }
  .stats b { font-size: 17px; }
  .stats .coord b { font-size: 14px; }

  #board { padding: 14px 12px; border-radius: 12px; width: 100%; }
  :root { --rowgap: 8px; }
  .colhead div { font-size: 9px; }
  .rowlabel { font-size: 13px; }

  /* よく使う操作は下端に固定して、片手で押せるようにする */
  .controls {
    position: sticky; bottom: 0; z-index: 6;
    margin: 16px calc(var(--edge) * -1) 0;
    padding: 9px var(--edge) max(9px, calc(6px + var(--sab)));
    display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
    background: rgba(4, 6, 15, 0.86);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
  }
  .controls button { padding: 11px 4px; font-size: 12px; }
  /* よく使う順に、左上から: 1手戻す / ヒント / 最初から / 別の問題 */
  #btn-undo  { grid-area: 1 / 1; }
  #btn-hint  { grid-area: 1 / 2; }
  #btn-reset { grid-area: 2 / 1; }
  #btn-new   { grid-area: 2 / 2; }

  /* キーボードのない端末では、ボタンのキー表示は意味がないので消す */
  kbd { display: none; }

  /* 上の @media (max-width:1000px) で入れた端末の余白を打ち消さないよう、
     ここでも同じように余白を足しておく */
  aside { padding: calc(16px + var(--sat)) max(16px, var(--sar))
                   calc(20px + var(--sab)) 16px; }
  aside h2 { margin: 16px 0 9px; }
  aside p { line-height: 1.85; }

  /* 説明はたたんでおく。開閉できることが分かるように印を出す */
  .sec { border-bottom: 1px solid var(--line); padding-bottom: 4px; margin-bottom: 8px; }
  .sec:last-of-type { border-bottom: 0; }
  .sec > summary {
    cursor: pointer; display: flex; align-items: center; justify-content: space-between;
    padding: 6px 0; min-height: 40px;
  }
  .sec > summary::after {
    content: ''; width: 8px; height: 8px; flex: none; margin-right: 4px;
    border-right: 2px solid var(--dim); border-bottom: 2px solid var(--dim);
    transform: rotate(45deg) translate(-2px, -2px); transition: transform 0.16s;
  }
  .sec[open] > summary::after { transform: rotate(-135deg) translate(-2px, -2px); }
  .sec > summary h2 { margin: 0; }

  /* 設定の選択肢は指で押せる大きさに */
  .opts { gap: 5px; }
  .opts button { min-width: 42px; padding: 9px 2px; }
}

/* 狭いスマホでは、メニューは三本線だけにしてタイトル (と紋章) に場所を譲る */
@media (max-width: 420px) {
  h1 { font-size: 21px; }
  .menu-label { display: none; }
  .menu-btn { padding: 10px 13px; }
}

/* 横向きで背の低い画面。盤面だけで画面が埋まらないように詰める */
@media (max-height: 460px) and (orientation: landscape) {
  header { padding-top: 10px; padding-bottom: 0; }
  h1 { font-size: 20px; }
  .tagline { display: none; }
  main { padding-top: 10px; }
}
