/* マジカらないバナナ — 見た目 */
:root {
  --yellow: #FFD60A; --yellow-lt: #FFE66D; --ink: #2B1B00; --white: #FFFDF5;
  --pink: #FF4D8D; --blue: #2D7FF9; --green: #19B36B; --red: #F0342B;
  --accent: var(--pink);
  --ray: rgba(255, 255, 255, .28); --spin: 60s; --dot: .0;
  --font: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font); font-weight: 800; color: var(--ink); background: var(--yellow);
  overflow-x: hidden; -webkit-user-select: none; user-select: none; touch-action: manipulation;
  -webkit-text-size-adjust: 100%; overscroll-behavior: none;
}
[hidden] { display: none !important; }
img { display: block; -webkit-user-drag: none; }
button { font: inherit; color: inherit; }

/* ───── 背景（レベルが上がるほど派手に） ───── */
.bg { position: fixed; inset: 0; overflow: hidden; z-index: 0; background: var(--yellow); transition: background .4s; }
.rays {
  position: absolute; left: 50%; top: 42%; width: 240vmax; height: 240vmax; margin: -120vmax;
  background: repeating-conic-gradient(var(--ray) 0 9deg, transparent 9deg 18deg);
  animation: spin var(--spin) linear infinite;
}
.dots {
  position: absolute; inset: -40px; opacity: var(--dot);
  background-image: radial-gradient(var(--accent) 22%, transparent 24%); background-size: 34px 34px;
  animation: slide 2.4s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes slide { to { transform: translate(34px, 34px); } }
body[data-level="2"] { --spin: 30s; --ray: rgba(255, 255, 255, .36); --accent: #FF7A1A; }
body[data-level="3"] { --spin: 16s; --ray: rgba(255, 255, 255, .42); --accent: var(--pink); --dot: .10; }
body[data-level="4"] { --spin: 9s; --ray: rgba(255, 122, 26, .38); --accent: var(--blue); --dot: .16; }
body[data-level="5"] { --spin: 4.5s; --ray: rgba(255, 77, 141, .40); --accent: var(--red); --dot: .22; }
body[data-level="4"] .dots { animation-duration: 1.2s; }
body[data-level="5"] .dots { animation-duration: .6s; }
/* 拍に合わせて、まん中からふわっと光る（game.js が拍ごとに動かす） */
.pulse { position: absolute; inset: 0; opacity: 0; background: radial-gradient(circle at 50% 40%, #fff 0, rgba(255, 255, 255, .7) 30%, transparent 72%); will-change: opacity; }
body[data-level="4"] .pulse { background: radial-gradient(circle at 50% 40%, #fff 0, rgba(255, 184, 0, .8) 34%, transparent 76%); }
body[data-level="5"] .pulse { background: radial-gradient(circle at 50% 40%, #fff 0, rgba(255, 122, 26, .85) 38%, transparent 80%); }
body[data-screen="start"] .rays, body[data-screen="result"] .rays { animation-duration: 90s; }

/* ───── 枠組み ───── */
.app { position: relative; z-index: 1; max-width: 480px; margin: 0 auto; min-height: 100%; }
.screen { display: none; padding: calc(14px + env(safe-area-inset-top)) 16px calc(14px + env(safe-area-inset-bottom)); }
body[data-screen="start"] .start, body[data-screen="result"] .result { display: block; }
body[data-screen="play"] .play { display: flex; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 60px;
  padding: 10px 18px; border: 4px solid var(--ink); border-radius: 18px; background: var(--white);
  font-size: 20px; font-weight: 900; text-decoration: none; color: var(--ink); cursor: pointer;
  box-shadow: 0 6px 0 var(--ink); transition: transform .06s, box-shadow .06s;
}
.btn:active { transform: translateY(5px); box-shadow: 0 1px 0 var(--ink); }
.btn[disabled] { opacity: .6; }
.btn img { width: 24px; height: 24px; }
.btn.primary { background: var(--pink); color: #fff; font-size: 28px; min-height: 78px; text-shadow: 0 2px 0 rgba(0, 0, 0, .25); }
.btn.share { background: #111; color: #fff; }

/* ───── はじめの画面 ───── */
.start { min-height: 100dvh; flex-direction: column; text-align: center; }
body[data-screen="start"] .start { display: flex; justify-content: center; gap: 18px; }
.logo { margin: 0; line-height: 1.02; font-weight: 900; transform: rotate(-4deg); }
.logo span { display: block; font-size: clamp(38px, 12vw, 58px); color: #fff; -webkit-text-stroke: 10px var(--ink); paint-order: stroke fill; letter-spacing: .02em; }
.logo .big { font-size: clamp(64px, 21vw, 100px); color: var(--yellow-lt); filter: drop-shadow(0 7px 0 var(--ink)); animation: bob 1.25s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(1.5deg); } }
.lead { margin: 6px 0 4px; font-size: 22px; line-height: 1.5; }
.lead b { background: var(--ink); color: var(--yellow); padding: 2px 10px; border-radius: 10px; font-weight: 900; }
.note { margin: 0; font-size: 13.5px; font-weight: 700; line-height: 1.6; opacity: .85; }
.note.strong { font-size: 16px; font-weight: 900; opacity: 1; }
.sound-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sound-row .btn { font-size: 17px; padding: 10px 8px; }
.js-mute[aria-pressed="false"] { background: #E4DCC4; }
body[data-sound="off"] .when-on, body[data-sound="on"] .when-off { display: none; }

/* ───── 遊ぶ画面 ───── */
.play { height: 100dvh; flex-direction: column; gap: 10px; }
.hud { display: flex; justify-content: space-between; gap: 10px; flex: none; }
.chip {
  display: flex; align-items: baseline; gap: 4px; padding: 4px 14px; background: var(--white);
  border: 3px solid var(--ink); border-radius: 999px; font-size: 15px; box-shadow: 0 3px 0 var(--ink);
}
.chip b { font-size: 26px; font-weight: 900; min-width: 1ch; text-align: center; }
.chip.level { background: var(--accent); color: #fff; transition: background .3s; }
.hud-right { display: flex; align-items: center; gap: 8px; }
.mute {
  flex: none; display: grid; place-items: center; width: 46px; height: 46px; padding: 0; cursor: pointer;
  background: var(--white); border: 3px solid var(--ink); border-radius: 50%; box-shadow: 0 3px 0 var(--ink); touch-action: manipulation;
}
.mute img { width: 24px; height: 24px; }
.mute:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }

/* お題などを出す場所。中身の大きさはこの場所の高さに合わせる（cqh = この場所の高さの1%）ので、
   画面が低いスマホでも、上の数字や下の拍の丸にはみ出さない */
.stage { position: relative; flex: 1 1 0; min-height: 130px; display: grid; place-items: center; container-type: size; }
.stage > * { grid-area: 1 / 1; }
.prompt { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.prompt img { width: clamp(64px, 15dvh, 120px); height: clamp(64px, 15dvh, 120px); width: min(120px, 44cqh); height: min(120px, 44cqh); filter: drop-shadow(0 5px 0 rgba(43, 27, 0, .25)); }
.prompt.in img { animation: drop .28s cubic-bezier(.2, 1.6, .4, 1); }
.say { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: center; gap: 2px 6px; line-height: 1.1; }
.topic { font-size: clamp(34px, 10.5vw, 52px); font-size: min(52px, 10.5vw, 21cqh); font-weight: 900; color: #fff; -webkit-text-stroke: 9px var(--ink); paint-order: stroke fill; }
.topic[data-len="5"], .topic[data-len="6"] { font-size: clamp(28px, 8.6vw, 44px); font-size: min(44px, 8.6vw, 21cqh); }
.topic[data-len="7"], .topic[data-len="8"] { font-size: clamp(24px, 7.2vw, 38px); font-size: min(38px, 7.2vw, 21cqh); }
.iwazuni { font-size: clamp(20px, 6vw, 28px); font-size: min(28px, 6vw, 13cqh); font-weight: 900; }
.prompt.in .topic { animation: drop .3s .05s cubic-bezier(.2, 1.6, .4, 1) backwards; }
@keyframes drop { from { transform: scale(.4) rotate(-8deg); opacity: 0; } }

.banner { text-align: center; transform: rotate(-4deg); }
.banner #banner-main { font-size: clamp(36px, 11.5vw, 60px); font-size: min(60px, 11.5vw, 21cqh); font-weight: 900; line-height: 1.1; color: var(--yellow-lt); -webkit-text-stroke: 10px var(--ink); paint-order: stroke fill; filter: drop-shadow(0 6px 0 var(--ink)); }
/* 掛け声に合わせて1拍ずつ光る */
.banner #banner-main span { display: inline-block; opacity: .3; }
.banner #banner-main span.lit { opacity: 1; }
.prompt .iwazuni { opacity: .25; }
.prompt.said .iwazuni { opacity: 1; animation: drop .22s cubic-bezier(.2, 1.6, .4, 1); }
.banner .sub { margin-top: 10px; margin-top: min(10px, 3cqh); display: inline-block; font-size: 20px; font-size: min(20px, 10cqh); font-weight: 900; color: #fff; background: var(--accent); border: 3px solid var(--ink); border-radius: 12px; padding: 2px 14px; }
.banner .sub:empty { display: none; }
.banner.in { animation: zoom .35s cubic-bezier(.2, 1.7, .4, 1); }
@keyframes zoom { from { transform: scale(.2) rotate(-14deg); opacity: 0; } }

.pop { display: flex; flex-direction: column; align-items: center; gap: 4px; z-index: 3; }
.pop img { width: clamp(70px, 16dvh, 130px); height: clamp(70px, 16dvh, 130px); width: min(130px, 52cqh); height: min(130px, 52cqh); }
.pop span { font-size: clamp(30px, 9vw, 46px); font-size: min(46px, 9vw, 26cqh); font-weight: 900; color: #fff; -webkit-text-stroke: 9px var(--green); paint-order: stroke fill; }
.pop.in { animation: pon .42s cubic-bezier(.2, 1.9, .4, 1); }
@keyframes pon { 0% { transform: scale(.2); opacity: 0; } 55% { transform: scale(1.25); opacity: 1; } 100% { transform: scale(1); } }

.oops { z-index: 4; font-size: clamp(44px, 14vw, 72px); font-weight: 900; color: #fff; -webkit-text-stroke: 10px var(--ink); paint-order: stroke fill; }
.oops.in { animation: slump 1.2s cubic-bezier(.3, .1, .3, 1) forwards; }
@keyframes slump { 0% { transform: scale(1.6) rotate(0); } 12% { transform: scale(1) rotate(-3deg); } 100% { transform: translateY(18px) rotate(9deg); } }

/* 音の時計が止まったときに出す「タップしてね」 */
.stall {
  position: absolute; inset: 0; z-index: 20; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  border: 0; background: rgba(43, 27, 0, .72); color: #fff; cursor: pointer; text-align: center;
}
.stall b { font-size: 30px; font-weight: 900; }
.stall span { font-size: 15px; font-weight: 700; }
.play { position: relative; }

/* 拍の丸（1小節4拍。いまの拍が光る。音を消していてもこれでリズムが分かる） */
.beats { flex: none; display: flex; justify-content: center; align-items: center; gap: 16px; height: 34px; }
.beats i { width: 20px; height: 20px; border-radius: 50%; border: 3px solid var(--ink); background: rgba(43, 27, 0, .2); }
.beats i.done { background: var(--white); }
.beats i.on { background: var(--accent); transform: scale(1.35); box-shadow: 0 0 0 5px rgba(255, 255, 255, .9); animation: beatdot .2s cubic-bezier(.2, 1.8, .4, 1); }
.beats i:first-child.on { transform: scale(1.55); }
@keyframes beatdot { from { transform: scale(2.1); } }

/* 残り時間の目盛り（1拍につき1つ減る） */
.gauge { flex: none; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; height: 22px; }
.gauge div { border: 3px solid var(--ink); border-radius: 8px; background: rgba(43, 27, 0, .18); overflow: hidden; }
.gauge i { display: block; height: 100%; background: var(--green); transform-origin: left center; transform: scaleX(0); will-change: transform; }
.gauge.hurry i { background: var(--red); }
.gauge.hurry { animation: jitter .09s linear infinite; }
@keyframes jitter { 50% { transform: translateX(2px); } }

/* 選択肢（2列×3段、親指で押しやすい大きさ） */
.grid { flex: none; display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: repeat(3, 1fr); gap: 10px; height: min(50dvh, 440px); }
.card {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-width: 0;
  padding: 4px; border: 4px solid var(--ink); border-radius: 18px; background: var(--white); cursor: pointer;
  box-shadow: 0 6px 0 var(--ink); visibility: hidden; touch-action: manipulation;
}
.card.on { visibility: visible; animation: cardin .16s cubic-bezier(.2, 1.6, .4, 1) backwards; }
@keyframes cardin { from { transform: scale(.6); opacity: 0; } }
.card img { width: clamp(38px, 7.6dvh, 62px); height: clamp(38px, 7.6dvh, 62px); pointer-events: none; }
.card .name { font-size: clamp(17px, 5.2vw, 23px); font-weight: 900; line-height: 1.15; white-space: nowrap; pointer-events: none; }
.card .name[data-len="6"] { font-size: clamp(15px, 4.5vw, 20px); }
.card .name[data-len="7"] { font-size: clamp(13px, 3.9vw, 18px); }
.card .name[data-len="8"] { font-size: clamp(12px, 3.5vw, 16px); }
.grid.live .card:active { transform: translateY(5px); box-shadow: 0 1px 0 var(--ink); }
.card.hit { background: #C9F7DC; border-color: var(--green); box-shadow: 0 6px 0 var(--green); transform: scale(1.04); }
.card.dim { opacity: .35; }
.card.miss { background: #FFD3D0; border-color: var(--red); box-shadow: 0 6px 0 var(--red); animation: shake .4s; }
.card.answer { background: #C9F7DC; border-color: var(--green); box-shadow: 0 6px 0 var(--green); }
.card.answer::after { content: "関係ない！"; position: absolute; top: -12px; right: -6px; padding: 1px 8px; background: var(--green); color: #fff; font-size: 13px; border: 2px solid var(--ink); border-radius: 999px; transform: rotate(6deg); }
@keyframes shake { 20% { transform: translateX(-9px) rotate(-3deg); } 40% { transform: translateX(8px) rotate(3deg); } 60% { transform: translateX(-6px); } 80% { transform: translateX(4px); } }

/* 高いレベルは選択肢もそわそわする */
body[data-level="4"] .grid.live .card:nth-child(odd) { animation: wob .48s ease-in-out infinite; }
body[data-level="4"] .grid.live .card:nth-child(even) { animation: wob .48s ease-in-out infinite reverse; }
body[data-level="5"] .grid.live .card:nth-child(odd) { animation: wob .22s ease-in-out infinite; }
body[data-level="5"] .grid.live .card:nth-child(even) { animation: wob .22s ease-in-out infinite reverse; }
@keyframes wob { 0%, 100% { transform: rotate(-1.4deg); } 50% { transform: rotate(1.4deg); } }

/* まちがえた瞬間: 色が抜けて、画面がガクッと傾く */
body.fail .bg { filter: grayscale(1) brightness(.75); transition: filter .15s; }
body.fail .rays, body.fail .dots, body.fail .bg { animation-play-state: paused !important; }
body.fail .play { animation: tilt 1.1s cubic-bezier(.3, .1, .3, 1) forwards; }
@keyframes tilt { 0% { transform: translate(0); } 6% { transform: translate(-10px, 4px) rotate(-2deg); } 12% { transform: translate(9px, -3px) rotate(2deg); } 20% { transform: translate(-5px, 2px); } 100% { transform: translateY(8px) rotate(-1.6deg); } }

/* ───── 結果の画面 ───── */
.result { text-align: center; padding-bottom: calc(28px + env(safe-area-inset-bottom)); }
.res-head { margin: 8px 0 10px; font-size: 26px; font-weight: 900; }
.res-head b { font-size: 84px; line-height: 1; color: #fff; -webkit-text-stroke: 12px var(--ink); paint-order: stroke fill; margin-right: 6px; }
.res-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.res-stats div { background: var(--white); border: 4px solid var(--ink); border-radius: 16px; padding: 6px; box-shadow: 0 5px 0 var(--ink); }
.res-stats span { display: block; font-size: 13px; }
.res-stats b { font-size: 30px; font-weight: 900; line-height: 1.1; }
.panel { margin-top: 16px; background: var(--white); border: 4px solid var(--ink); border-radius: 20px; padding: 14px 14px 16px; box-shadow: 0 6px 0 var(--ink); text-align: left; }
.panel h3 { margin: 0 0 10px; font-size: 15px; font-weight: 900; display: inline-block; background: var(--ink); color: var(--yellow); padding: 2px 12px; border-radius: 999px; }
.chain { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 4px; font-size: 16px; }
.chain .link { display: inline-flex; align-items: center; gap: 4px; background: var(--yellow-lt); border: 2px solid var(--ink); border-radius: 999px; padding: 2px 10px 2px 6px; }
.chain .link img { width: 22px; height: 22px; }
.chain .link.end { background: var(--red); color: #fff; padding: 2px 10px; }
.chain .arrow { opacity: .6; }
.ans-q { margin: 0; font-size: 22px; font-weight: 900; }
.ans-how { margin: 2px 0 12px; font-size: 15px; color: var(--red); }
.ans-odd { display: flex; align-items: center; gap: 10px; background: #C9F7DC; border: 3px solid var(--green); border-radius: 16px; padding: 10px 12px; }
.ans-odd span { font-size: 14px; flex: none; }
.ans-odd img { width: 48px; height: 48px; flex: none; }
.ans-odd b { font-size: 28px; font-weight: 900; line-height: 1.1; }
.ans-rest { margin: 16px 0 6px; font-size: 17px; font-weight: 900; }
.ans-list { list-style: none; margin: 0; padding: 0; }
.ans-list li { display: flex; align-items: flex-start; gap: 12px; padding: 12px 0; border-top: 3px dotted rgba(43, 27, 0, .25); }
.ans-list li.picked { background: #FFE3E0; margin: 0 -8px; padding: 12px 8px; border-radius: 12px; border-top-color: transparent; }
.ans-list img { width: 46px; height: 46px; flex: none; margin-top: 2px; }
.ans-list b { display: block; font-size: 23px; font-weight: 900; line-height: 1.2; }
.ans-list p { margin: 3px 0 0; font-size: 18px; font-weight: 700; line-height: 1.5; }
.ans-list .tag { margin-left: 8px; font-size: 12px; background: var(--red); color: #fff; padding: 2px 8px; border-radius: 999px; vertical-align: middle; }
.res-actions { display: grid; gap: 14px; margin-top: 22px; }

@media (min-width: 600px) and (min-height: 700px) { .grid { height: 420px; } }
/* 背の低い画面（小さいスマホ）: すきまをつめて、1画面に収める */
@media (max-height: 600px) {
  .play { gap: 6px; }
  .grid { height: 46dvh; gap: 8px; }
  .beats { height: 28px; }
  .stage { min-height: 96px; }
}
@media (prefers-reduced-motion: reduce) {
  .rays, .dots, .bg, .logo .big, .grid.live .card, .beats i.on { animation: none !important; }
}
