/* ぱったん からくり — 見た目。ライト=そらいろ・ダーク=よる。外部フォントは使わない */
:root {
  --bg: #eaf4ff;
  --panel: #ffffff;
  --grid: #e3ecf7;
  --ink: #2b2433;
  --sub: #5e6a7e;
  --card: #ffffff;
  --card-sh: #b9cbe2;
  --gold: #ffc53d;
  --focus: #2f7cf6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1f2b;
    --panel: #f4f1ea;
    --grid: #e2ddd2;
    --ink: #f3eefc;
    --sub: #b4abc4;
    --card: #2c3142;
    --card-sh: #11141c;
    --focus: #ffc53d;
  }
}

* { 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) auto; 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);
}
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; }
button:disabled { opacity: .45; cursor: default; }
svg { display: block; width: 100%; height: 100%; overflow: visible; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.logo { display: flex; align-items: center; gap: 8px; margin: 0; min-width: 0; font-size: clamp(17px, 4.6vw, 26px); font-weight: 900; white-space: nowrap; }
.logo img { width: 40px; height: 40px; flex-shrink: 0; }
.btns { display: flex; gap: 8px; flex-shrink: 0; }
.snd, .dice { width: 52px; height: 56px; border-radius: 16px; background: var(--card); box-shadow: 0 4px 0 var(--card-sh); display: grid; place-items: center; }
.snd svg, .dice svg { width: 32px; height: 32px; }
.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; }
.go {
  display: inline-flex; align-items: center; gap: 4px; height: 56px; padding: 0 14px 0 8px; border-radius: 16px;
  background: #ff8a3d; color: #fff; font-weight: 900; font-size: 18px; box-shadow: 0 4px 0 #c45a17; white-space: nowrap;
}
.go svg { width: 30px; height: 30px; }
.go.busy { background: #c9b8a9; box-shadow: 0 4px 0 #9b8a7b; }
@media (max-width: 440px) { .logo span { display: none; } }
.snd:active, .dice:active, .go:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--card-sh); }

/* ---- しかけを おく ところ ---- */
[hidden] { display: none !important; }
.wrap { position: relative; min-height: 0; min-width: 0; }
.stage {
  position: absolute; left: 0; top: 0; border: 3px solid var(--ink); border-radius: 22px; overflow: hidden;
  background: var(--panel);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 20px 20px;
}
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.selbox { position: absolute; left: 0; top: 0; z-index: 2; display: flex; gap: 6px; padding: 5px; border-radius: 18px; background: rgba(255, 255, 255, .92); border: 2.5px solid #2b2433; }
.sb { width: 48px; height: 48px; border-radius: 14px; background: #ffe8a3; display: grid; place-items: center; }
.sb svg { width: 32px; height: 32px; }
.sb.del { background: #ff6b6b; }
.sb:active { transform: translateY(2px); }
.go.back { background: #5c7cfa; box-shadow: 0 4px 0 #3b5bdb; }

/* ---- しかけの ボタン ---- */
.tray { display: flex; justify-content: center; }
.parts { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; width: min(100%, 640px); }
.pbtn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  min-height: 64px; padding: 3px 2px; border-radius: 14px; touch-action: none;
  background: var(--card); box-shadow: 0 4px 0 var(--card-sh);
}
.pbtn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--card-sh); }
.pi { width: 100%; max-width: 60px; aspect-ratio: 3 / 2; }
.pn { font-size: clamp(10px, 2.8vw, 14px); font-weight: 900; white-space: nowrap; }
.playing .parts { opacity: .45; }

.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 5; }
.confetti i {
  position: absolute; top: -20px; width: 10px; height: 14px; border-radius: 3px;
  animation-name: fall; animation-timing-function: cubic-bezier(.3, .6, .6, 1); animation-fill-mode: forwards;
}
@keyframes fall { to { transform: translate(var(--dx), 110vh) rotate(var(--r)); } }

/* スマホを横にしたとき: しかけの ボタンを みぎに */
@media (orientation: landscape) and (max-height: 600px) {
  #app { grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto minmax(0, 1fr); column-gap: 10px; }
  .top { grid-column: 1 / -1; }
  .logo img { width: 32px; height: 32px; }
  .snd, .dice, .go { height: 48px; }
  .tray { grid-column: 2; grid-row: 2; align-items: center; }
  .parts { width: auto; grid-template-columns: repeat(3, 60px); gap: 5px; }
  .pbtn { min-height: 48px; height: min(calc((100svh - 15vh - 84px) / 3), 66px); padding: 2px; }
  .pi { max-width: 44px; }
  .pn { font-size: 9px; }
}

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