/* 各画面の並べ方 */
.app {
  max-width: 440px; margin: 0 auto;
  padding-block: 12px calc(120px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 16px;
}

/* 上のバー：左・真ん中・右 */
.bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; min-height: 44px; }
.bar > :first-child { justify-self: start; }
.bar > :last-child { justify-self: end; }
.bar .logo { grid-column: 1 / 3; font-size: 24px; font-weight: 800; letter-spacing: .08em; }

/* 最初の画面 */
.cards { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.card {
  width: 100%; text-align: left; padding: 20px; border-radius: 16px;
  display: flex; flex-direction: column; gap: 6px;
}
.card b { font-size: 20px; letter-spacing: .06em; }
.card span { font-size: 14px; color: var(--mute); }

/* 遊ぶ画面 */
.stage { display: flex; align-items: center; gap: 4px; }
.stage-no { font-size: 16px; min-width: 6em; text-align: center; font-variant-numeric: tabular-nums; }
.info { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px 16px; font-size: 14px; color: var(--mute); font-variant-numeric: tabular-nums; }
.info b { color: var(--ink); margin-left: 2px; }
.info span:empty { display: none; }
.top:empty, .bottom:empty { display: none; }
.msg { text-align: center; font-size: 14px; color: var(--mute); min-height: 1.5em; margin-top: -8px; }
.board-wrap { position: relative; }
.rules-btn { align-self: center; font-size: 13px; padding: 4px 14px; }
.ctrl { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
/* 3つのボタンの幅はいつも同じ。文字の長さで変わらない */
.ctrl button { min-width: 0; padding-inline: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rules { margin: 0; padding-left: 1.2em; font-size: 13px; line-height: 1.75; color: var(--mute); }

/* 遊ぶ画面は1画面に収め、スクロールしない(js/app.js が html に .fixed-screen をつける) */
html.fixed-screen, html.fixed-screen body { height: 100%; overflow: hidden; overscroll-behavior: none; }
html.fixed-screen body { position: fixed; inset: 0; }
html.fixed-screen #app { height: 100%; }
.app.play {
  height: 100%; gap: 10px; touch-action: none;
  padding-block: 8px max(8px, env(safe-area-inset-bottom, 0px));
}
.app.play > * { flex: none; }
/* 盤面は、残りの場所いっぱいの正方形(幅と高さの小さいほう) */
.app.play .board-wrap {
  flex: 1 1 0; min-height: 120px; container-type: size;
  display: flex; align-items: center; justify-content: center;
}
.app.play .board-wrap > .board { width: min(100cqw, calc(100cqh * var(--aspect, 1))); }
/* 確認・ルール・クリアの帯が出ているあいだは、盤面が指を受け付けない(js/ui/play.js) */
.board[inert] { pointer-events: none; }

/* ルールの説明(画面の真ん中) */
.modal {
  position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .35);
  display: flex; align-items: center; justify-content: center;
  padding: max(24px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(24px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
}
.modal-box {
  width: 100%; max-width: 400px; max-height: 100%; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y;
  background: var(--band); border-radius: 18px; padding: 22px 20px 20px;
  display: flex; flex-direction: column; gap: 14px;
}
.modal-box h2 { margin: 0; font-size: 18px; }
.modal-box .rules { font-size: 15px; line-height: 1.8; color: var(--ink); }

/* 飛ばす前の確認(盤面の上に重ねる) */
.confirm {
  position: absolute; inset: 0; border-radius: 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
  text-align: center; padding: 16px; z-index: 5;
}
.confirm p { margin: 0; font-size: 16px; }
.confirm .row { display: flex; gap: 10px; }
.confirm button { padding-inline: 22px; }

/* クリアの帯 */
.band {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: var(--band);
  padding: 18px max(16px, env(safe-area-inset-right, 0px)) calc(18px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  transform: translateY(calc(100% + 30px)); transition: transform .35s cubic-bezier(.3, 1.2, .5, 1);
}
.band.show { transform: none; box-shadow: 0 -6px 24px rgba(0, 0, 0, .08); }
.band-in { max-width: 440px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.band b { font-size: 22px; font-weight: 800; color: var(--accent); }
.band button { padding: 12px 26px; }

/* 一覧 */
.stage-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 8px; }
.stage-grid button { aspect-ratio: 1; padding: 0; font-size: 16px; font-variant-numeric: tabular-nums; }
.stage-grid button.cleared { background: var(--accent); color: var(--accent-ink); }
.stage-grid button.skipped { background: color-mix(in srgb, var(--accent) 35%, var(--tile)); color: var(--ink); }
.stage-grid button.current { box-shadow: inset 0 0 0 3px var(--ink); }

/* 設定 */
.settings { display: flex; flex-direction: column; gap: 10px; }
.settings .row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--tile); border-radius: 14px; padding: 14px 16px; min-height: 60px;
}
.settings .row.column { flex-direction: column; align-items: stretch; }
.toggle { width: 52px; height: 32px; padding: 0; border-radius: 16px; background: var(--gap); position: relative; flex: none; }
.toggle::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .2); transition: transform .2s;
}
.toggle[aria-checked="true"] { background: var(--accent); }
.toggle[aria-checked="true"]::after { transform: translateX(20px); }
.toggle:active:not(:disabled) { transform: none; }
.segment { display: grid; grid-template-columns: 1.7fr 1fr 1fr; gap: 4px; background: var(--bg); border-radius: 12px; padding: 4px; }
.segment button { background: transparent; padding: 10px 2px; font-size: 14px; border-radius: 9px; white-space: nowrap; }
.segment button[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 700; }

/* 確かめ用の仮パズル */
.board.trial { display: grid; grid-template-columns: repeat(var(--n), 1fr); gap: 5px; }
.board.trial .cell {
  position: relative; aspect-ratio: 1; border-radius: 8px; background: var(--tile); cursor: pointer;
  display: flex; align-items: center; justify-content: center; touch-action: manipulation;
}
.board.trial .cell.mark::after { content: ""; width: 26%; height: 26%; border-radius: 50%; background: var(--stripe); }
.board.trial .cell.hit::after { background: rgba(255, 255, 255, .7); }
.board.trial .cell.wrong::after { content: "×"; width: auto; height: auto; background: none; color: var(--mute); font-size: 20px; }
.board.trial .cell.hint { box-shadow: inset 0 0 0 3px var(--accent); animation: blink 1s ease-in-out infinite; }
.board.trial .cell.glow { animation: glow .6s ease; }
@keyframes blink { 50% { box-shadow: inset 0 0 0 3px transparent; } }
@keyframes glow { 0% { filter: none; } 35% { filter: brightness(1.25) saturate(1.2); } 100% { filter: none; } }

/* まじきり */
.mj-label { text-align: center; font-size: 12px; color: var(--mute); margin-bottom: 6px; }
.mj-target { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.mj-chip { display: flex; align-items: center; gap: 3px; background: var(--chip); border-radius: 999px; padding: 6px 10px; min-height: 12px; }
.mj-chip i { display: block; width: 8px; height: 8px; border-radius: 50%; background: var(--dot); }
.board.majikiri { position: relative; aspect-ratio: 1; background: var(--tile); border-radius: 12px; overflow: hidden; touch-action: none; }
.mj-grid { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(var(--n), 1fr); grid-template-rows: repeat(var(--n), 1fr); }
.mj-grid > div { position: relative; box-shadow: inset 0 0 0 .5px var(--gap); display: flex; align-items: center; justify-content: center; }
.mj-dot { width: 36%; aspect-ratio: 1; border-radius: 50%; background: var(--dot); transition: background .2s, transform .2s; }
.mj-dot.bad { background: var(--danger); transform: scale(1.12); }
.mj-dot.win { background: var(--accent); animation: mj-glow .7s ease-out; }
@keyframes mj-glow {
  0% { transform: scale(1); }
  40% { transform: scale(1.35); box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 30%, transparent); }
  100% { transform: scale(1); }
}
.mj-lines { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.mj-line { position: absolute; border-radius: 3px; }
.mj-line.h { height: 5px; left: 0; right: 0; transform: translateY(-50%); }
.mj-line.v { width: 5px; top: 0; bottom: 0; transform: translateX(-50%); }
.mj-line.hint { animation: mj-blink 1s ease-in-out infinite; }
.mj-line.hint.h { background: repeating-linear-gradient(to right, var(--accent) 0 10px, transparent 10px 16px); }
.mj-line.hint.v { background: repeating-linear-gradient(to bottom, var(--accent) 0 10px, transparent 10px 16px); }
@keyframes mj-blink { 50% { opacity: .2; } }

/* のびしろ */
.nb-dots { display: flex; justify-content: center; gap: 8px; min-height: 16px; }
.nb-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--wall); transition: background .25s; }
.board.nobishiro { display: grid; grid-template-columns: repeat(var(--n), 1fr); gap: 5px; }
.nb-cell {
  position: relative; aspect-ratio: 1; min-width: 0; border-radius: 8px; overflow: hidden;
  background: var(--tile); display: flex; align-items: center; justify-content: center;
}
.nb-cell.wall { background: var(--wall) repeating-linear-gradient(135deg, transparent 0 6px, var(--stripe) 6px 8px); }
.nb-cell.empty { cursor: pointer; }
.nb-cell.hint { box-shadow: inset 0 0 0 3px var(--accent); animation: blink 1s ease-in-out infinite; }
/* 色と番号は指の邪魔をしない(触感用のスイッチに指が届くように) */
.nb-fill { position: absolute; inset: 0; pointer-events: none; }
/* 絵の具がにじむように流れる。色の先頭をぼかしながら、置いた所から外へ */
.nb-fill.flow { background-color: transparent !important; animation: nb-flow linear both; }
.nb-fill.right { background-image: linear-gradient(to right, var(--fc) 0 33.4%, transparent 40%); background-size: 300% 100%; --p0: 100% 0; --p1: 0 0; }
.nb-fill.left { background-image: linear-gradient(to left, var(--fc) 0 33.4%, transparent 40%); background-size: 300% 100%; --p0: 0 0; --p1: 100% 0; }
.nb-fill.down { background-image: linear-gradient(to bottom, var(--fc) 0 33.4%, transparent 40%); background-size: 100% 300%; --p0: 0 100%; --p1: 0 0; }
.nb-fill.up { background-image: linear-gradient(to top, var(--fc) 0 33.4%, transparent 40%); background-size: 100% 300%; --p0: 0 0; --p1: 0 100%; }
@keyframes nb-flow { from { background-position: var(--p0); } to { background-position: var(--p1); } }
.nb-num {
  position: absolute; z-index: 2; left: 19%; top: 19%; width: 62%; aspect-ratio: 1; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; pointer-events: none;
  background: rgba(255, 255, 255, .6); color: rgba(0, 0, 0, .55);
  font-weight: 800; font-size: clamp(12px, 4vw, 19px);
}
.nb-num:empty { display: none; }
.nb-cell.glow .nb-fill { animation: nb-glow .5s ease; }
@keyframes nb-glow { 0% { filter: none; } 35% { filter: brightness(1.25) saturate(1.2); } 100% { filter: none; } }

/* うつしえ */
.board.utsushie { position: relative; aspect-ratio: var(--aspect); background: var(--tile); border-radius: 12px; touch-action: none; }
.us-main, .us-hint { display: block; position: absolute; left: 0; top: 0; }
.us-hint { pointer-events: none; animation: us-blink 1s ease-in-out infinite; }
.us-main.glow { animation: us-glow .8s ease; }
@keyframes us-glow { 0% { filter: none; } 40% { filter: brightness(1.18) saturate(1.15); } 100% { filter: none; } }
@keyframes us-blink { 50% { opacity: .15; } }
.us-drag { position: fixed; left: 0; top: 0; z-index: 15; pointer-events: none; }
.us-tray { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px; }
.us-piece {
  padding: 6px; border-radius: 10px; background: var(--tile); touch-action: none; cursor: grab;
  display: flex; align-items: center; justify-content: center;
}
.us-piece canvas { display: block; pointer-events: none; }
.us-piece.lifted { opacity: .35; }
.us-piece.placed { visibility: hidden; }
.us-piece.hint { outline: 2px dashed var(--hc); outline-offset: 1px; animation: us-blink 1s ease-in-out infinite; }
.us-piece.shake { animation: us-shake .3s ease; }
@keyframes us-shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
