/* ジグソー × 動画再生 試作デモ
   キャラクター素材の色に合わせた、やわらかい配色。
   ステージごとの色は --accent 系を JS が差し替える。 */

:root {
  --accent: #DE7CA2;
  --accent-deep: #C9557F;
  --accent-pale: #FDEDF3;
  --accent-light: #F9CFDE;

  --ink: #4a3b43;
  --ink-soft: #7d6b74;
  --paper: #fffdfe;
  --line: #ecdfe5;
  --shadow: 0 2px 4px rgba(90, 60, 75, .07), 0 14px 30px -18px rgba(90, 60, 75, .35);

  --round: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--round);
  color: var(--ink);
  background: var(--accent-pale);
  transition: background .5s ease;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

.app {
  max-width: 760px;
  margin: 0 auto;
  padding: 18px 16px 48px;
  min-height: 100%;
}

/* ---------- 画面切り替え ---------- */
.screen { display: none; }
.screen.is-on { display: block; animation: rise .28s ease both; }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .screen.is-on { animation: none; }
}

/* ---------- 共通パーツ ---------- */
.bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.bar h2 {
  font-size: 18px;
  margin: 0;
  font-weight: 700;
  letter-spacing: .04em;
}

.bar-note {
  margin-left: auto;
  font-size: 12px;
  color: var(--ink-soft);
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.bar-note b { color: var(--accent-deep); font-weight: 700; }

.btn {
  font-family: var(--round);
  font-size: 15px;
  font-weight: 700;
  color: var(--accent-deep);
  background: var(--paper);
  border: 2px solid var(--accent-light);
  border-radius: 999px;
  padding: 10px 22px;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: var(--shadow);
  transition: transform .12s ease, border-color .2s ease, background .2s ease;
}

.btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

.btn-main {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-size: 17px;
  padding: 14px 40px;
}

.btn-main:hover { background: var(--accent-deep); border-color: var(--accent-deep); }
.btn-sm { font-size: 13px; padding: 7px 14px; border-width: 2px; }
.btn-back { font-size: 13px; padding: 7px 16px; }
.btn-danger { color: #a2453b; border-color: #eccac5; }
.btn-danger:hover { border-color: #cf6a5c; }

/* ---------- タイトル ---------- */
[data-screen="title"] { text-align: center; padding-top: 12px; }

.title-art {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 2px;
  min-height: 132px;
  margin-bottom: 6px;
}

.title-art img {
  width: 25%;
  max-width: 130px;
  border-radius: 14px;
  box-shadow: var(--shadow);
  border: 3px solid var(--paper);
  animation: float 4s ease-in-out infinite;
}

.title-art img:nth-child(2) { animation-delay: .5s; }
.title-art img:nth-child(3) { animation-delay: 1s; }
.title-art img:nth-child(4) { animation-delay: 1.5s; }

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-7px); }
}

@media (prefers-reduced-motion: reduce) {
  .title-art img { animation: none; }
}

.title {
  font-size: clamp(21px, 5.4vw, 30px);
  line-height: 1.55;
  margin: 14px 0 6px;
  font-weight: 700;
  letter-spacing: .02em;
  text-wrap: balance;
}

.title-sub {
  margin: 0 0 26px;
  font-size: 13px;
  color: var(--ink-soft);
  letter-spacing: .08em;
}

.menu {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 30px;
}

.promo {
  max-width: 34em;
  margin: 0 auto;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px 20px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.promo p {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.95;
  color: var(--ink-soft);
  text-align: left;
}

.promo strong { color: var(--accent-deep); }
.promo .btn { text-decoration: none; }

.credit {
  margin: 20px 0 0;
  font-size: 11.5px;
  letter-spacing: .06em;
  color: var(--ink-soft);
}

/* ---------- ステージ一覧・ギャラリー ---------- */
.stage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
}

.stage-card {
  position: relative;
  border: 0;
  padding: 0;
  background: var(--paper);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  text-align: left;
  font-family: var(--round);
  color: var(--ink);
  transition: transform .14s ease;
}

.stage-card:hover { transform: translateY(-3px); }
.stage-card:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.stage-card img { width: 100%; display: block; aspect-ratio: 1; object-fit: cover; }

.stage-card.locked { cursor: not-allowed; }
.stage-card.locked img { filter: grayscale(1) brightness(1.12); opacity: .5; }
.stage-card.locked:hover { transform: none; }

.stage-meta { padding: 10px 12px 12px; }
.stage-meta strong { display: block; font-size: 14px; }

.stage-meta span {
  display: block;
  font-size: 11px;
  color: var(--ink-soft);
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  margin-top: 3px;
}

.tag {
  position: absolute;
  top: 8px;
  left: 8px;
  font-size: 10px;
  font-family: var(--mono);
  letter-spacing: .1em;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .92);
  color: var(--ink-soft);
}

.tag.clear { background: #2f8f74; color: #fff; }
.empty { text-align: center; color: var(--ink-soft); font-size: 13px; margin-top: 30px; }
.empty.hide { display: none; }

/* ---------- パズル ---------- */
.puzzle-wrap { display: flex; flex-direction: column; gap: 14px; align-items: center; }

.board {
  position: relative;
  width: min(100%, 440px);
  aspect-ratio: 1;
  background: var(--paper);
  border: 3px solid var(--paper);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
  touch-action: none;
}

.board-guide {
  position: absolute;
  inset: 0;
  background-size: cover;
  opacity: .14;
  transition: opacity .25s ease;
}

.board-guide.off { opacity: 0; }
.board-guide.peek { opacity: 1; }
.board-layer { position: absolute; inset: 0; }

.board-done {
  position: absolute;
  inset: 0;
  background-size: cover;
  opacity: 0;
  pointer-events: none;
  transition: opacity .45s ease;
}

.board-done.on { opacity: 1; }

/* touch-action: none がないと、スマホでピースの上を指でなぞったときに
   ブラウザがスクロールとして横取りし、pointermove が届かずドラッグが始まらない */
.piece {
  position: absolute;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;      /* iOS の長押しメニューを出さない */
  filter: drop-shadow(0 2px 3px rgba(70, 45, 60, .34));
}
.piece svg { display: block; width: 100%; height: 100%; pointer-events: none; }
.piece.locked { cursor: default; filter: none; }
.piece.dragging { cursor: grabbing; z-index: 90; filter: drop-shadow(0 8px 12px rgba(70, 45, 60, .45)); }

.piece.pop { animation: pop .34s ease; }

@keyframes pop {
  0% { transform: scale(1.14); }
  60% { transform: scale(.97); }
  100% { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .piece.pop { animation: none; }
}

.tray {
  width: min(100%, 440px);
  min-height: 96px;
  max-height: min(240px, 34vh);
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 4px;
  padding: 8px;
  background: var(--accent-light);
  border-radius: 14px;
  box-shadow: inset 0 2px 6px rgba(90, 60, 75, .12);
}

.tray .piece { position: relative; width: var(--tray-piece, 78px); height: var(--tray-piece, 78px); flex: none; }
.puzzle-tools { display: flex; gap: 10px; }

/* ---------- 動画 ---------- */
.movie-wrap { display: flex; flex-direction: column; gap: 14px; align-items: center; }

video {
  width: min(100%, 440px);
  aspect-ratio: 1;
  display: block;
  background: #2a2026;
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.vctl {
  width: min(100%, 440px);
  display: flex;
  flex-direction: column;
  gap: 11px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
}

.vctl-row { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }

.vctl-label {
  font-size: 12px;
  color: var(--ink-soft);
  width: 4.6em;
  flex: none;
  letter-spacing: .06em;
}

.rates { display: flex; gap: 6px; flex-wrap: wrap; }

.rate {
  font-family: var(--mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  padding: 5px 10px;
  border-radius: 999px;
  border: 2px solid var(--accent-light);
  background: var(--paper);
  color: var(--accent-deep);
  cursor: pointer;
}

.rate[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.rate:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

input[type="range"] { accent-color: var(--accent); flex: 1; min-width: 120px; }

.vnum {
  font-family: var(--mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
  width: 3.4em;
  text-align: right;
}

.check { font-size: 13px; display: flex; align-items: center; gap: 6px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }

.vstate {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
}

#btnNext { margin-left: auto; }

/* ---------- 再生設定モーダル ---------- */
.modal {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: 400px;
  width: calc(100% - 32px);
}

.modal::backdrop { background: rgba(60, 40, 52, .45); backdrop-filter: blur(2px); }

.modal-in {
  background: var(--paper);
  border-radius: 18px;
  padding: 20px 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 20px 50px -18px rgba(60, 40, 52, .6);
}

.modal-in h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .04em;
}

.modal-row { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.modal-note { margin: 0; font-size: 11.5px; color: var(--ink-soft); }
.modal-close { align-self: flex-end; }

/* ---------- オプション ---------- */
.opts { display: flex; flex-direction: column; gap: 18px; }

.opt {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.opt-label { font-size: 14px; font-weight: 700; }
.opt-help { margin: 0; font-size: 12px; color: var(--ink-soft); line-height: 1.8; }
.seg, .seg-row { display: flex; gap: 8px; flex-wrap: wrap; }

.seg button {
  font-family: var(--round);
  font-size: 13px;
  font-weight: 700;
  padding: 8px 16px;
  border-radius: 999px;
  border: 2px solid var(--accent-light);
  background: var(--paper);
  color: var(--accent-deep);
  cursor: pointer;
}

.seg button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.seg button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
