/* ぴったん パズル — 見た目。ライト=あかるい そら・ダーク=よる。外部フォントは使わない */
:root {
  --bg: #eaf6ff;
  --ink: #2b2433;
  --sub: #5d5568;
  --card: #ffffff;
  --card-sh: #b3cde0;
  --gold: #ffc53d;
  --focus: #2f7cf6;
  --board: #ffffff;
  --line: rgba(43, 36, 51, .3);
  --tray: rgba(255, 255, 255, .6);
  --tray-edge: rgba(43, 36, 51, .22);
  --shadow-op: .3;
  --shadow-f: grayscale(1);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b2130;
    --ink: #f3eefc;
    --sub: #c4bcd4;
    --card: #2d3447;
    --card-sh: #0c0f17;
    --focus: #ffc53d;
    --board: #2d3447;
    --line: rgba(243, 238, 252, .35);
    --tray: rgba(255, 255, 255, .08);
    --tray-edge: rgba(243, 238, 252, .25);
    --shadow-op: .3;
    --shadow-f: grayscale(1) brightness(1.2);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Maru Gothic Pro", "BIZ UDPGothic", "Yu Gothic UI", Meiryo, system-ui, sans-serif;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  overscroll-behavior: none;
  overflow: hidden;
}
#app {
  position: fixed; inset: 0;
  display: grid; grid-template-rows: auto minmax(0, 1fr); grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  /* 画面の下 15% には押すものを置かない(手首が当たる) */
  padding: calc(env(safe-area-inset-top) + 8px) calc(env(safe-area-inset-right) + 10px) 15vh calc(env(safe-area-inset-left) + 10px);
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; margin: 0; cursor: pointer; touch-action: manipulation; }
button:focus-visible { outline: 4px solid var(--focus); outline-offset: 3px; }
svg { display: block; width: 100%; height: 100%; overflow: visible; }

/* ---- うえの おび(え・かず・おと) ---- */
.top {
  display: grid; gap: 6px 8px; align-items: center;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "counts snd" "picks picks";
}
.picks { grid-area: picks; display: grid; grid-template-columns: repeat(4, minmax(48px, 1fr)); gap: 4px; justify-content: center; }
.counts { grid-area: counts; display: flex; gap: 6px; }
.snd { grid-area: snd; }
.pk, .cn, .snd { height: 52px; border-radius: 14px; background: var(--card); box-shadow: 0 4px 0 var(--card-sh); display: grid; place-items: center; }
.pk { padding: 0; }
.pk svg { width: 40px; height: 40px; overflow: hidden; border-radius: 9px; border: 2.5px solid var(--ink); }
.cn { width: 58px; }
.cn svg { width: 40px; height: 34px; }
.snd { width: 56px; height: 52px; }
.snd svg { width: 32px; height: 32px; }
.pk[aria-pressed="true"], .cn[aria-pressed="true"] { box-shadow: 0 4px 0 var(--card-sh), 0 0 0 4px var(--gold); }
.pk:active, .cn:active, .snd:active { transform: translateY(3px); }
.spk { fill: var(--ink); }
.wave, .slash { fill: none; stroke: var(--ink); stroke-width: 3.5; stroke-linecap: round; }
.snd.off .wave, .snd:not(.off) .slash { display: none; }
.dot { fill: #ffc53d; stroke: #2b2433; stroke-width: 2; }
@media (min-width: 480px) {
  .picks { grid-template-columns: repeat(8, minmax(48px, 60px)); }
}
@media (min-width: 900px) and (min-height: 601px) {
  .top { grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "picks counts snd"; gap: 12px; }
  .picks { grid-template-columns: repeat(8, 58px); justify-content: start; }
  .counts { justify-content: center; }
}

/* ---- あそぶ ところ ---- */
.play { position: relative; min-height: 0; touch-action: none; }
.trayBg { position: absolute; border-radius: 20px; background: var(--tray); border: 3px dashed var(--tray-edge); pointer-events: none; }
.board { position: absolute; border-radius: 9px; background: var(--board); box-shadow: 0 0 0 3px var(--ink); overflow: hidden; pointer-events: none; }
.shadow { position: absolute; inset: 0; opacity: var(--shadow-op); filter: var(--shadow-f); }
.shadow svg, .fin svg { overflow: hidden; }
.lines { position: absolute; inset: 0; }
.lines path { fill: none; stroke: var(--line); stroke-width: 2.5; stroke-dasharray: 7 6; vector-effect: non-scaling-stroke; }
.fin { position: absolute; inset: 0; }

.pc {
  position: absolute; left: 0; top: 0; z-index: 2; cursor: grab;
  border-radius: 9px; overflow: hidden; background: #fff;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .22);
  touch-action: none; will-change: transform; transform-origin: 50% 50%;
}
.pc svg { overflow: hidden; }
.pc::after { content: ""; position: absolute; inset: 0; border: 3px solid #2b2433; border-radius: 9px; pointer-events: none; }
.pc.drag { z-index: 6; cursor: grabbing; box-shadow: 0 10px 14px rgba(0, 0, 0, .28); }
.pc.placed { z-index: 1; cursor: default; pointer-events: none; box-shadow: none; }
.pc.placed::after { border-width: 2px; border-color: rgba(43, 36, 51, .55); }
.play.finished .pc { visibility: hidden; }

.fx { position: absolute; inset: 0; pointer-events: none; z-index: 8; overflow: hidden; }
.fx i { position: absolute; left: 0; top: 0; display: block; border-radius: 2px; will-change: transform; }

.next {
  position: absolute; z-index: 7; display: flex; align-items: center; justify-content: center; gap: 12px;
  min-height: 56px; border-radius: 28px; background: var(--gold); color: #2b2433; border: 4px solid #2b2433;
  box-shadow: 0 6px 0 #2b2433; font-size: clamp(26px, 7vw, 38px); font-weight: 900;
}
.next svg { width: 34px; height: 34px; flex-shrink: 0; }
.next:active { transform: translateY(4px); box-shadow: 0 2px 0 #2b2433; }

/* ---- できあがりの うごき(え ごとに 1つ) ---- */
.fin-kuma .mv { transform-origin: 84px 82px; animation: wave 1.6s ease-in-out infinite; }
@keyframes wave { 0% { transform: rotate(0); } 15% { transform: rotate(-140deg); } 30% { transform: rotate(-105deg); } 45% { transform: rotate(-140deg); } 60% { transform: rotate(-105deg); } 75% { transform: rotate(-140deg); } 100% { transform: rotate(0); } }
.fin-roketto .mv { animation: fly 2.6s ease-in infinite; }
@keyframes fly { 0% { transform: translateY(0); } 8% { transform: translate(-2px, 2px); } 16% { transform: translate(2px, 0); } 24% { transform: translate(-2px, 2px); } 55% { transform: translateY(-160px); } 56% { transform: translateY(160px); } 100% { transform: translateY(0); } }
.fin-sakana .mv { animation: swim 1.8s ease-in-out infinite alternate; }
@keyframes swim { from { transform: translateX(-12px) rotate(-4deg); } to { transform: translateX(12px) rotate(4deg); } }
.fin-kuruma .mv { animation: drive 1.8s ease-in-out infinite alternate; }
@keyframes drive { from { transform: translateX(-14px); } 50% { transform: translateX(0) translateY(-2px); } to { transform: translateX(14px); } }
.fin-ouchi .mv { transform-origin: 60px 102px; animation: hop 1s ease-out infinite; }
@keyframes hop { 0% { transform: scale(1.04, .94); } 30% { transform: translateY(-12px) scale(.98, 1.04); } 60% { transform: translateY(0) scale(1.04, .94); } 100% { transform: scale(1); } }
.fin-keki .mv { transform-origin: 60px 100px; animation: wiggle 1.2s ease-in-out infinite alternate; }
.fin-keki .fl { transform-origin: 60px 26px; animation: flick .3s ease-in-out infinite alternate; }
@keyframes wiggle { from { transform: rotate(-4deg); } to { transform: rotate(4deg); } }
@keyframes flick { from { transform: scale(1, .85); } to { transform: scale(.9, 1.1); } }
.fin-kyouryu .mv { transform-origin: 62px 106px; animation: stomp 1s ease-in-out infinite; }
.fin-kyouryu .tl { transform-origin: 34px 70px; animation: wag .5s ease-in-out infinite alternate; }
@keyframes stomp { 0%, 100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-8px) rotate(-3deg); } }
@keyframes wag { from { transform: rotate(-12deg); } to { transform: rotate(14deg); } }
.fin-ohana .mv { transform-origin: 60px 106px; animation: sway 1.6s ease-in-out infinite alternate; }
@keyframes sway { from { transform: rotate(-8deg); } to { transform: rotate(8deg); } }

/* スマホを よこに したとき: え・かず・おとを ひだりに たてに ならべる */
@media (orientation: landscape) and (max-height: 600px) {
  #app { grid-template-columns: auto minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); column-gap: 10px; }
  .top { grid-template-columns: auto 48px; grid-template-areas: "picks counts" "picks snd"; align-content: start; align-items: start; gap: 6px 6px; }
  .picks { grid-template-columns: repeat(2, 48px); grid-auto-rows: 48px; gap: 4px; justify-content: start; }
  .counts { flex-direction: column; gap: 4px; }
  .pk, .cn, .snd { height: 48px; border-radius: 12px; }
  .pk, .cn, .snd { width: 48px; }
  .pk svg { width: 36px; height: 36px; }
  .cn svg { width: 36px; height: 30px; }
  .snd svg { width: 28px; height: 28px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .fin .mv, .fin .tl, .fin .fl { animation: none !important; }
}
