/* どうぶつ カードあわせ — 見た目。ライト=クリーム・ダーク=夜。外部フォントは使わない(何も送らないため) */
:root {
  --bg: #fff4e8;
  --ink: #2b2433;
  --sub: #6b6177;
  --card: #ffffff;
  --card-sh: #ecd5b6;
  --back: #ff8a3d;
  --back-2: #ffa766;
  --back-sh: #d96a22;
  --gold: #ffc53d;
  --p1: #ff8a3d;
  --p2: #4d8dff;
  --focus: #2f7cf6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1b29;
    --ink: #f3eefc;
    --sub: #b4abc4;
    --card: #2c2840;
    --card-sh: #14121c;
    --back: #e06f2a;
    --back-2: #f08a48;
    --back-sh: #8f4111;
    --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: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}
[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; }
.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; }

/* ---- 大きいボタン ---- */
.big { background: var(--card); border-radius: 22px; box-shadow: 0 6px 0 var(--card-sh); transition: transform .06s; }
.big:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--card-sh); }
.back {
  display: inline-flex; align-items: center; gap: 2px;
  min-height: 56px; min-width: 56px; padding: 0 16px 0 10px;
  border-radius: 16px; background: var(--card); box-shadow: 0 4px 0 var(--card-sh);
  font-weight: 800; font-size: 18px;
}
.back span { font-size: 32px; line-height: 1; margin-top: -5px; }
.back:active, .snd:active, .seg:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--card-sh); }

/* ---- はじめの画面 ---- */
.menu { padding: 4vh 16px 15vh; gap: 3vh; overflow-y: auto; }
.menu > .logo { margin-top: auto !important; }
.menu > .opts { margin-bottom: auto; }
.logo { display: flex; flex-direction: column; align-items: center; gap: 10px; margin: 2vh 0 0; }
.logo-cards { display: flex; gap: 10px; }
.lc { width: clamp(54px, 15vw, 84px); aspect-ratio: 3 / 4; border-radius: 12px; border: 3px solid var(--ink); display: grid; place-items: center; padding: 8%; }
.lc svg { width: 100%; height: auto; }
.lc.back { background: repeating-linear-gradient(45deg, var(--back) 0 10px, var(--back-2) 10px 20px); }
.lc.face:nth-child(2) { transform: rotate(-6deg); }
.lc.face:nth-child(3) { transform: rotate(7deg); }
.logo-text { font-size: clamp(36px, 10vw, 64px); font-weight: 900; letter-spacing: .02em; line-height: 1.1; }
.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; width: min(100%, 620px); }
.mode { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 14px 6px; min-height: 150px; }
.mode.last { box-shadow: 0 6px 0 var(--card-sh), 0 0 0 4px var(--gold); }
.mode-pic { display: flex; align-items: center; justify-content: center; gap: 2px; width: 100%; height: 72px; }
.mode-pic svg { width: 62px; height: 62px; }
.mode-pic[data-pic="cpu"] svg, .mode-pic[data-pic="duo"] svg { width: 46px; height: 46px; }
.mode-name { font-size: clamp(19px, 5.4vw, 28px); font-weight: 900; }
.opts { display: flex; flex-direction: column; align-items: center; gap: 10px; width: min(100%, 620px); }
.opt { display: flex; align-items: center; gap: 10px; }
.seg {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 56px; min-width: 88px; padding: 0 16px; border-radius: 999px;
  background: var(--card); box-shadow: 0 4px 0 var(--card-sh);
  font-weight: 900; font-size: 22px;
}
.seg[aria-pressed="true"] { background: var(--ink); color: var(--bg); box-shadow: 0 4px 0 rgba(0, 0, 0, .3); }
.pips { display: grid; grid-template-columns: repeat(4, 7px); gap: 3px; }
.pips i { width: 7px; height: 10px; border-radius: 2px; background: var(--back); }
.link { min-height: 48px; padding: 0 14px; font-size: 16px; color: var(--sub); text-decoration: underline; text-underline-offset: 3px; }

/* ---- あそぶ画面 ---- */
.game {
  display: grid; width: 100%; align-items: stretch;
  grid-template-rows: auto 1fr;
  /* 画面の下 15% には押すものを置かない(手首が当たる) */
  padding: 10px 12px 15vh; gap: 10px;
}
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.top .back, .snd { flex-shrink: 0; }
.snd { width: 56px; height: 56px; border-radius: 16px; background: var(--card); box-shadow: 0 4px 0 var(--card-sh); display: grid; place-items: center; }
.snd svg { width: 34px; height: 34px; }
.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; }

/* とった どうぶつの はこ(人ごと)。番の人は ふちが光る */
.trays { flex: 1; min-width: 0; display: flex; gap: 6px; justify-content: center; }
.tray {
  flex: 1 1 0; min-width: 0; max-width: 260px; height: 56px;
  display: flex; align-items: center; gap: 4px; padding: 4px 6px;
  background: var(--card); border-radius: 14px; box-shadow: 0 3px 0 var(--card-sh);
  transition: transform .2s;
}
.tray .who { flex: 0 0 auto; width: 40px; height: 40px; }
.tray .got { flex: 1; min-width: 0; height: 100%; display: flex; align-items: center; }
.mini { flex: 0 0 auto; width: 30px; height: 36px; padding: 3px; border-radius: 6px; border: 2px solid var(--ink); margin-left: -12px; }
.mini:first-child { margin-left: 0; }
.trays.n2 .tray.now { box-shadow: 0 3px 0 var(--card-sh), 0 0 0 4px var(--gold); transform: translateY(-2px); }
.trays.n2 .tray.now .who { animation: bob 1.1s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-4px); } }

.board-wrap { min-height: 0; min-width: 0; display: flex; align-items: center; justify-content: center; }
.board { display: grid; grid-template-columns: repeat(var(--cols, 3), var(--cw, 90px)); gap: var(--gap, 10px); }
.card { width: var(--cw, 90px); aspect-ratio: 3 / 4; perspective: 600px; border-radius: 14px; }
.card .in { position: relative; display: block; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform .28s ease-out; }
.card.open .in, .card.done .in { transform: rotateY(180deg); }
.side {
  position: absolute; inset: 0; border-radius: 14px; border: 3px solid var(--ink);
  -webkit-backface-visibility: hidden; backface-visibility: hidden;
  display: grid; place-items: center;
}
.side.bk {
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, .55) 0 18%, transparent 19%),
    repeating-linear-gradient(45deg, var(--back) 0 10px, var(--back-2) 10px 20px);
  box-shadow: inset 0 -5px 0 var(--back-sh);
}
.side.fr { transform: rotateY(180deg); padding: 9%; }
.card:not(.open):not(.done):active .in { transform: scale(.95); }
.board.cat .card { cursor: default; }
.card.nudge { animation: nudge .25s; }
@keyframes nudge { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.card.match .side.fr { animation: hop .55s ease-out; box-shadow: 0 0 0 5px var(--gold); }
@keyframes hop { 30% { transform: rotateY(180deg) translateY(-10%) scale(1.06); } 60% { transform: rotateY(180deg) translateY(0) scale(1); } }
.card.done { pointer-events: none; }

/* ---- おしまい ---- */
.finish { position: fixed; inset: 0; z-index: 4; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 12px 15vh; background: rgba(0, 0, 0, .25); }
.finish-card {
  width: min(100%, 560px); max-height: 100%; overflow-y: auto;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 18px 16px 20px; border-radius: 26px; background: var(--bg); box-shadow: 0 8px 0 var(--card-sh);
  animation: pop .35s ease-out;
}
@keyframes pop { 0% { transform: scale(.7); } 70% { transform: scale(1.05); } }
.finish-title { margin: 0; font-size: clamp(26px, 7.5vw, 40px); font-weight: 900; }
.parade { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.pa { width: 48px; height: 58px; padding: 5px; border-radius: 9px; border: 2.5px solid var(--ink); animation: dance 1s ease-in-out infinite; animation-delay: calc(var(--k) * -.12s); }
@keyframes dance { 50% { transform: translateY(-7px) rotate(-5deg); } }
.finish-rows { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.frow { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: var(--card); border-radius: 14px; }
.frow .who { position: relative; flex: 0 0 auto; width: 46px; height: 46px; }
.frow .crown { position: absolute; left: 6px; top: -16px; width: 34px; height: 20px; }
.frow .cnt { flex: 1; display: flex; flex-wrap: wrap; gap: 3px; }
.frow .cnt i { width: 12px; height: 16px; border-radius: 3px; background: var(--back); }
.frow b { font-size: 26px; font-variant-numeric: tabular-nums; }
.again {
  min-height: 70px; min-width: min(80vw, 320px); padding: 0 24px;
  font-size: clamp(22px, 6vw, 28px); font-weight: 900;
  background: var(--gold); color: #3a2a00; box-shadow: 0 6px 0 #c98a00;
}
.again:active { box-shadow: 0 2px 0 #c98a00; }
.again:disabled { opacity: .55; }

.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) {
  .menu { padding-top: 2vh; gap: 2vh; }
  .logo { flex-direction: row; gap: 16px; }
  .lc { width: 46px; }
  .logo-text { font-size: 36px; }
  .mode { min-height: 110px; padding: 8px 6px; }
  .mode-pic { height: 52px; }
  .mode-pic svg { width: 48px; height: 48px; }
  .mode-pic[data-pic="cpu"] svg, .mode-pic[data-pic="duo"] svg { width: 38px; height: 38px; }
  .finish { padding-top: 3vh; }
  .parade .pa { width: 38px; height: 46px; }
  /* おしまいは 2れつ(左: どうぶつと かず・右: ボタン)。たてに ならべると 下15%に かかる */
  .finish-card { width: min(100%, 760px); display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 18px; row-gap: 6px; align-items: center; padding: 10px 16px 12px; }
  .finish-title { grid-column: 1 / -1; justify-self: center; font-size: 28px; }
  .parade, .finish-rows { grid-column: 1; }
  .frow { padding: 3px 10px; }
  .again { grid-column: 2; grid-row: 2; min-height: 60px; min-width: 200px; }
  #finishBack { grid-column: 2; grid-row: 3; }
}

/* よこで ひくい 画面(ブラウザの 帯が ある スマホ・たかさ 360px 以下) */
@media (orientation: landscape) and (max-height: 360px) {
  .menu .opts { display: none; } /* おとは あそぶ画面の 右上で きりかえる */
  .menu { gap: 1.6vh; }
}

/* よこで たかさ 361〜380px(帯の ない 小さい スマホ): 「おと」を カードの かずの よこに ならべる(たてに ならべると 下15%に かかる) */
@media (orientation: landscape) and (min-height: 361px) and (max-height: 380px) {
  .opts { flex-direction: row; justify-content: center; gap: 16px; }
}

/* はばが せまい スマホ(350px 以下): 3つの ボタンが 右に はみ出さないよう、2ひきの 絵を 小さく */
@media (max-width: 350px) {
  .modes { gap: 8px; }
  .mode-pic[data-pic="cpu"] svg, .mode-pic[data-pic="duo"] svg { width: 36px; height: 36px; }
}

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