* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #1d2333; overscroll-behavior: none; }
body { color: #22304a; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
#app { position: relative; height: 100vh; height: 100dvh; max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; overflow: hidden; background: #f4efe4; }

/* ---------- 上：道 ---------- */
#scene { position: relative; flex: 0 0 60%; overflow: hidden; background: #8fd3ff; }
#road { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#hud { position: absolute; left: 10px; right: 10px; top: max(8px, env(safe-area-inset-top)); display: flex; justify-content: space-between; gap: 8px; pointer-events: none; }
.who { display: flex; align-items: center; gap: 6px; padding: 4px 10px 4px 4px; border-radius: 999px; background: rgba(255, 255, 255, 0.92); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.18); font-weight: 800; font-size: 13px; }
.who .tag { color: #fff; padding: 3px 9px; border-radius: 999px; background: #ff6a3d; }
.who.cpu .tag { background: #3a6df0; }
/* CPUのひとこと（考え中… など）は名前の札の下に小さく */
.who.cpu { position: relative; padding-right: 4px; }
#cpuMsg { position: absolute; right: 2px; top: calc(100% + 4px); padding: 2px 8px; border-radius: 999px; background: rgba(255, 255, 255, 0.85); font-size: 11px; color: #4a5a7a; white-space: nowrap; }

/* お題の紙（ベンと貼られる） */
#paper { position: absolute; left: 50%; top: 46%; transform: translate(-50%, -50%) rotate(-4deg); padding: 6px 18px 8px; background: #fffdf6; border-radius: 3px;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.12), 0 12px 24px rgba(0, 0, 0, 0.25); display: flex; align-items: baseline; gap: 4px; opacity: 0; pointer-events: none;
  background-image: repeating-linear-gradient(0deg, transparent 0 21px, rgba(80, 140, 220, 0.18) 21px 22px); }
#paper .fx { font-size: 64px; line-height: 1; --ink: #3a1d10; background-image: linear-gradient(180deg, #ff9a7a 0%, #ff5a3d 40%, #e8361d 42%, #b8200f 100%); }
#paper .make { white-space: nowrap; font-family: var(--font-jp); font-weight: 900; font-size: 26px; color: #3a1d10; }
#paper .tape { position: absolute; top: -9px; width: 46px; height: 18px; background: rgba(255, 236, 150, 0.85); }
#paper .tape.l { left: -10px; transform: rotate(-28deg); }
#paper .tape.r { right: -10px; transform: rotate(24deg); }
#paper.slap, #paper.up { opacity: 1; }
#paper.slap { animation: slap 0.42s cubic-bezier(0.2, 1.6, 0.4, 1) forwards; }
#paper.up { transition: top 0.7s cubic-bezier(0.5, 0, 0.2, 1), transform 0.7s cubic-bezier(0.5, 0, 0.2, 1); top: 21%; transform: translate(-50%, -50%) rotate(-4deg) scale(0.72); opacity: 1; }
@keyframes slap { 0% { opacity: 0; transform: translate(-50%, -50%) rotate(-14deg) scale(2.6); } 60% { opacity: 1; transform: translate(-50%, -50%) rotate(-3deg) scale(0.93); } 100% { opacity: 1; transform: translate(-50%, -50%) rotate(-4deg) scale(1); } }
#scene.shake { animation: shake 0.28s linear; }
@keyframes shake { 25% { transform: translate(-5px, 3px); } 50% { transform: translate(4px, -3px); } 75% { transform: translate(-2px, 2px); } }

#stamp { position: absolute; left: 50%; top: 53%; transform: translate(-50%, -50%) rotate(-8deg); opacity: 0; pointer-events: none; }
#stamp.on { animation: stamp 1.6s cubic-bezier(0.2, 1.5, 0.4, 1) forwards; }
@keyframes stamp { 0% { opacity: 0; transform: translate(-50%, -50%) rotate(-8deg) scale(3); } 18% { opacity: 1; transform: translate(-50%, -50%) rotate(-8deg) scale(1); } 85% { opacity: 1; } 100% { opacity: 1; transform: translate(-50%, -50%) rotate(-8deg) scale(1); } }

/* れんぞく正解：左上のバッジと、「できた！」の下の呼び声 */
.who.you { position: relative; }
#combo { position: absolute; left: 2px; top: calc(100% + 5px); display: none; align-items: baseline; gap: 2px; padding: 2px 10px 3px 6px; border-radius: 999px; color: #fff; background: linear-gradient(90deg, #ff8a3d, #ff5a3d); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.2); font-size: 12px; white-space: nowrap; }
#combo.on, #combo.lost { display: flex; }
#combo i { font-style: normal; font-size: 13px; }
#combo b { font: 900 17px var(--font-num); }
#combo small { margin-left: 6px; font-size: 10px; opacity: 0.85; }
#combo small:empty { display: none; }
#combo[data-tier="2"] { background: linear-gradient(90deg, #ff3b3b, #d81b60); }
#combo[data-tier="3"] { background: linear-gradient(90deg, #ff3b3b, #ffb21a, #2fb38a, #3a8cf0, #9b6ae0); background-size: 200% 100%; animation: comborainbow 1.2s linear infinite; }
#combo.bump { animation: combobump 0.45s cubic-bezier(0.2, 1.8, 0.4, 1); }
#combo[data-tier="3"].bump { animation: combobump 0.45s cubic-bezier(0.2, 1.8, 0.4, 1), comborainbow 1.2s linear infinite; }
#combo.lost { animation: combolost 0.7s ease-in forwards; }
@keyframes combobump { 0% { transform: scale(0.4); } 60% { transform: scale(1.25); } 100% { transform: scale(1); } }
@keyframes comborainbow { to { background-position: 200% 0; } }
@keyframes combolost { 0% { opacity: 1; filter: grayscale(0); } 30% { transform: translateY(2px); filter: grayscale(1); } 100% { opacity: 0; transform: translateY(10px); filter: grayscale(1); } }
#comboCall { position: absolute; left: 50%; top: 27%; transform: translate(-50%, -50%) rotate(-5deg); opacity: 0; pointer-events: none; z-index: 1; white-space: nowrap; font-family: var(--font-jp); font-weight: 900; font-size: 26px; color: #fff; -webkit-text-stroke: 1px #3a1d10; paint-order: stroke; text-shadow: 0 3px 0 #3a1d10, 0 0 14px rgba(255, 140, 40, 0.9); display: flex; align-items: baseline; gap: 4px; }
#comboCall b { font: 900 52px/1 var(--font-num); color: #ffc21a; -webkit-text-stroke: 2px #3a1d10; }
#comboCall[data-tier="2"] b { color: #ff5a5a; }
#comboCall[data-tier="3"] b { color: #7ef0c0; text-shadow: 0 3px 0 #3a1d10, 0 0 18px #ff8ad8, 0 0 30px #3dc6ff; }
#comboCall em { position: absolute; left: 50%; top: 100%; transform: translateX(-50%); margin-top: 4px; padding: 2px 10px; border-radius: 999px; font-style: normal; font-size: 13px; color: #3a1d10; background: #ffc21a; -webkit-text-stroke: 0; text-shadow: none; }
#comboCall.on { animation: combocall 1.5s cubic-bezier(0.2, 1.6, 0.4, 1) 0.25s forwards; }
@keyframes combocall { 0% { opacity: 0; transform: translate(-50%, -50%) rotate(-5deg) scale(0.3); } 22% { opacity: 1; transform: translate(-50%, -50%) rotate(-5deg) scale(1.1); } 35% { transform: translate(-50%, -50%) rotate(-5deg) scale(1); } 85% { opacity: 1; } 100% { opacity: 1; transform: translate(-50%, -50%) rotate(-5deg) scale(1); } }
@media (prefers-reduced-motion: reduce) { #combo, #combo.bump, #comboCall.on { animation: none; } #comboCall.on { opacity: 1; } }

/* ---------- 下：電卓（画面の約4割） ---------- */
:root { --font-plate: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", "Meiryo", sans-serif; --plate: #0f6b3a; }
#calc { flex: 1 1 auto; display: flex; flex-direction: column; justify-content: space-evenly; gap: 6px; padding: 8px 14px max(8px, env(safe-area-inset-bottom)); background: linear-gradient(180deg, #3b4256, #2a3042); box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.12); }
#lcd { position: relative; flex: 0 0 auto; padding: 4px 12px 2px; border-radius: 10px; background: linear-gradient(180deg, #c9dcb4, #b4cc98); box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.35); color: #1f2e16; font-family: var(--font-num); }
#val { font-size: clamp(40px, 12vw, 52px); line-height: 1.02; text-align: right; letter-spacing: 0.02em; }
#goal { position: absolute; left: 12px; bottom: 6px; font-family: var(--font-ui); font-size: 11px; font-weight: 800; }
#goal b { font-family: var(--font-num); font-size: 20px; color: #b8200f; margin-left: 2px; }
#lcd.ng { animation: ng 0.35s linear; }
@keyframes ng { 20% { transform: translateX(-8px); } 40% { transform: translateX(7px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(3px); } }
#lcd.ok { background: linear-gradient(180deg, #fff6a8, #ffd84a); }

button { cursor: pointer; transition: transform 0.06s, filter 0.15s, opacity 0.15s; }
button:active { transform: translateY(3px); }
button:disabled { cursor: default; transform: none; }

/* 四則のボタンは丸 */
#ops { display: flex; justify-content: center; gap: clamp(8px, 3.2vw, 18px); }
#ops button { width: clamp(50px, 14.5vw, 60px); aspect-ratio: 1; border: 0; border-radius: 50%; font: 900 30px/1 var(--font-num); color: #fff; background: radial-gradient(circle at 35% 30%, #ffc07a, #f2701d 60%); box-shadow: 0 4px 0 #a8460a; }
#ops button:disabled { opacity: 0.4; filter: grayscale(0.7); }
/* 保留：四角いボタン。押すと画面の数字が入り、あとで1つの数字として使える */
#ops #hold { border-radius: 12px; background: #4b5370; box-shadow: 0 4px 0 #1e2333; font: 900 15px/1 var(--font-ui); color: #fff; }
#ops #hold.filled { background: linear-gradient(180deg, #ffffff, #eef2ea); box-shadow: inset 0 0 0 3px var(--plate), 0 4px 0 #9aa7a0; color: var(--plate); font: 800 clamp(20px, 6vw, 26px)/1 var(--font-plate); }
#ops #hold.filled:disabled { opacity: 1; filter: none; color: #c3cdc6; box-shadow: inset 0 0 0 3px #c3cdc6, 0 4px 0 #6b7480; background: #f3f5f2; }
#ops #hold.arriving { color: transparent; }
.fly-num { position: fixed; z-index: 9; pointer-events: none; font-family: var(--font-num); line-height: 1; color: #1f2e16; }
#ops #hold.pop { animation: dpop 0.38s cubic-bezier(0.2, 1.6, 0.4, 1) both; }
#ops button.sel { box-shadow: 0 0 0 3px #fff, 0 4px 0 #a8460a; }
#ops.picked button[data-op]:not(.sel) { opacity: 0.4; filter: grayscale(0.9); }

/* 数字はナンバーと同じ書体・緑。4つに分かれた白いボタン */
#digits { display: grid; grid-template-columns: repeat(4, minmax(0, 84px)); justify-content: center; gap: 12px; }
#digits button { aspect-ratio: 1 / 1.05; max-height: 76px; border: 0; border-radius: 14px; color: var(--plate); background: linear-gradient(180deg, #ffffff, #eef2ea); box-shadow: inset 0 0 0 3px var(--plate), 0 5px 0 #9aa7a0; font: 800 clamp(40px, 12vw, 54px)/1 var(--font-plate); }
#digits button:disabled { color: #c3cdc6; box-shadow: inset 0 0 0 3px #c3cdc6, 0 5px 0 #6b7480; background: #f3f5f2; }
#digits button.pop { animation: dpop 0.38s cubic-bezier(0.2, 1.6, 0.4, 1) both; }
@keyframes dpop { from { transform: scale(0.2) rotate(-20deg); opacity: 0; } }
#digits button.hit { animation: dhit 0.25s ease-out; }
@keyframes dhit { 40% { transform: scale(1.12) translateY(-5px); } }

.row.small { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.row.small button { min-height: 34px; border: 0; border-radius: 12px; font: 800 14px var(--font-ui); color: #e6ebf7; background: #4b5370; box-shadow: 0 3px 0 #1e2333; }
.row.small button:disabled { opacity: 0.4; }

/* 不正解：大きな ✕ と「もう一回」 */
#miss { position: absolute; left: 50%; top: 55%; transform: translate(-50%, -50%); display: grid; place-items: center; opacity: 0; pointer-events: none; }
#miss .x { font: 900 clamp(96px, 28vw, 140px)/0.9 var(--font-ui); color: #ff3b3b; -webkit-text-stroke: 6px #fff; filter: drop-shadow(0 6px 0 rgba(90, 0, 0, 0.45)); }
#miss .again { font-size: clamp(34px, 10vw, 46px); margin-top: -8px; background-image: var(--gloss-white); --ink: #8a1010; }
#miss.on { animation: miss 1.1s ease-out forwards; }
@keyframes miss { 0% { opacity: 0; transform: translate(-50%, -50%) scale(2.2) rotate(-10deg); } 15% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(0); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -50%) scale(1); } }

/* ---------- 開始画面（モードを選ぶ） ---------- */
#title { position: absolute; inset: 0; z-index: 5; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 14px; padding: 0 24px 16px; overflow: hidden; background: linear-gradient(180deg, #5cc0ff, #c8ecff 30%); }
#title > *:not(.title-bg) { position: relative; z-index: 1; }
#title { overflow-y: auto; }
#title.hide { display: none; }
/* タイトル（見本 title-calc 案2・書体B）：上に道と車、下は電卓。電卓の緑の画面にタイトル */
@font-face { font-family: "PixelMplus"; src: url("../fonts/PixelMplus12-Bold.sub.woff2") format("woff2"); font-display: block; }
#title { padding: 0; gap: 0; background: #2a3042; }
.t-scene { position: relative; flex: 0 0 38%; width: 100%; overflow: hidden; background: #7cc58a; }
/* 道・草むら・木は、ゲームと同じ絵を game.js が描く */
.t-ground { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
/* 車：ずっと小刻みに揺れて（carbob）、ときどき石をふんでガクン（外の箱で動かすので揺れは止まらない） */
.t-carbox { position: absolute; left: 50%; bottom: 3%; width: min(66%, calc((38vh - 10px) * 1.28)); transform: translateX(-50%); container-type: inline-size; }
.t-carbox.gakon { animation: gakon 0.55s ease-out; }
@keyframes gakon { 0% { transform: translateX(-50%) translateY(0) rotate(0); } 10% { transform: translateX(-50%) translateY(3%) rotate(1.4deg); } 26% { transform: translateX(-50%) translateY(-7%) rotate(-1.8deg); } 44% { transform: translateX(-50%) translateY(1.5%) rotate(0.8deg); } 64% { transform: translateX(-50%) translateY(-2%) rotate(-0.4deg); } 100% { transform: translateX(-50%) translateY(0) rotate(0); } }
.t-rig { position: relative; animation: carbob 1.1s ease-in-out infinite; transform-origin: 50% 100%; }
@keyframes carbob { 0%, 100% { transform: translateY(0); } 25% { transform: translateY(-6px); } 50% { transform: translateY(-1px); } 75% { transform: translateY(-5px); } }
.t-car { width: 100%; aspect-ratio: 320 / 250; }
.t-car svg { display: block; width: 100%; height: 100%; }
/* 窓ガラスに貼られるお題の紙：ベシッと貼られて、風で飛んでいく */
.t-paper { position: absolute; left: 50%; top: 27%; z-index: 2; opacity: 0; pointer-events: none; transform: translate(-50%, -50%) rotate(-4deg); padding: 1cqw 4cqw 1.6cqw; background: #fffdf6; border-radius: 3px; display: flex; align-items: baseline; gap: 1cqw; box-shadow: 0 5px 0 rgba(0,0,0,.12), 0 10px 20px rgba(0,0,0,.25); background-image: repeating-linear-gradient(0deg, transparent 0 21px, rgba(80,140,220,.18) 21px 22px); }
.t-paper .fx { font-size: 15cqw; line-height: 1; --ink: #3a1d10; background-image: linear-gradient(180deg, #ff9a7a 0%, #ff5a3d 40%, #e8361d 42%, #b8200f 100%); }
.t-paper .make { white-space: nowrap; font-family: var(--font-jp); font-weight: 900; font-size: 6.4cqw; color: #3a1d10; }
.t-paper .tape { position: absolute; top: -2.4cqw; width: 11cqw; height: 4.4cqw; background: rgba(255,236,150,.85); }
.t-paper .tape.l { left: -2.6cqw; transform: rotate(-28deg); } .t-paper .tape.r { right: -2.6cqw; transform: rotate(24deg); }
.t-paper.slap { animation: wslap 0.42s cubic-bezier(.2,1.6,.4,1) forwards; }
@keyframes wslap { 0% { opacity: 0; transform: translate(-50%, -50%) rotate(-14deg) scale(2.6); } 60% { opacity: 1; transform: translate(-50%, -50%) rotate(-3deg) scale(.93); } 100% { opacity: 1; transform: translate(-50%, -50%) rotate(-4deg) scale(1); } }
.t-paper.blow { animation: wblow 1.5s cubic-bezier(.5,0,.7,.4) forwards; }
@keyframes wblow { 0% { opacity: 1; transform: translate(-50%, -50%) rotate(-4deg); } 12% { transform: translate(-50%, -50%) rotate(2deg) skewX(-6deg); } 22% { transform: translate(-50%, -52%) rotate(-7deg) skewX(5deg); } 34% { transform: translate(-44%, -58%) rotate(8deg) skewX(-8deg); } 100% { opacity: 0; transform: translate(160%, -260%) rotate(260deg) scale(.6); } }
/* 電卓 */
.t-calc { flex: 1 0 auto; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: space-evenly; gap: 12px; padding: 16px 16px 18px; background: linear-gradient(180deg, #3b4256, #2a3042); box-shadow: inset 0 3px 0 rgba(255,255,255,.12); }
.t-brand { align-self: stretch; display: flex; justify-content: space-between; align-items: center; font-size: 10px; letter-spacing: .2em; color: #9aa3b8; font-weight: 800; padding: 0 4px; }
.t-brand i { display: inline-block; width: 46px; height: 12px; border-radius: 3px; background: repeating-linear-gradient(90deg, #4a3d2a 0 10px, #2b2418 10px 11px); box-shadow: inset 0 0 0 1px #1a1a1a; }
.t-lcd { position: relative; align-self: stretch; margin: 0; border-radius: 12px; padding: 10px 14px 12px; background: linear-gradient(180deg, #c9dcb4, #b4cc98); box-shadow: inset 0 3px 6px rgba(0,0,0,.35); color: #1f2e16; text-align: center; overflow: hidden; font-weight: 400; }
.t-lcd::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: repeating-linear-gradient(90deg, rgba(180,204,152,.55) 0 1px, transparent 1px 4px), repeating-linear-gradient(0deg, rgba(180,204,152,.55) 0 1px, transparent 1px 4px); }
.t-sub { display: block; font: 400 15px/1.25 "PixelMplus", var(--font-ui); letter-spacing: .12em; opacity: .85; }
.t-title { display: block; font: 400 clamp(28px, 9.5vw, 40px)/1.15 "PixelMplus", var(--font-ui); letter-spacing: -.01em; white-space: nowrap; }
.t-title .blink { animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
body.still .t-title .blink { animation: none; } /* カード撮影など止まった絵では「！」を消さない */
.t-ops { display: flex; justify-content: center; gap: 12px; }
.t-ops b { width: 38px; aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center; font: 900 20px/1 var(--font-num); color: #fff; background: radial-gradient(circle at 35% 30%, #ffc07a, #f2701d 60%); box-shadow: 0 3px 0 #a8460a; opacity: .55; }
/* ラボのカード撮影（?card）：車ははみ出すほど大きく、ナンバーの上にお題の紙。右に電卓の画面とモードのキー */
body.card #title { flex-direction: row; overflow: hidden; }
body.card .t-scene { flex: 0 0 48%; height: 100%; }
body.card .t-carbox { width: 175%; bottom: -6%; }
body.card .t-rig { animation: none; }
body.card .t-paper { opacity: 1; top: 30%; animation: none; padding: 0.8cqw 3cqw 1.2cqw; gap: 0.8cqw; }
body.card .t-paper .fx { font-size: 11.3cqw; } body.card .t-paper .make { font-size: 5cqw; }
body.card .t-paper .tape { width: 8.5cqw; height: 3.4cqw; top: -1.8cqw; }
/* 文字の大きさは見本（カード幅 520px の cqw）を、撮影の幅 640px の vw に直したもの（×0.8125） */
body.card .t-calc { flex: 1 1 auto; min-width: 0; height: 100%; justify-content: center; gap: 1.6vw; padding: 2.6vw 2.45vw; }
body.card .t-brand, body.card .t-ops, body.card .game-version, body.card #tools, body.card #oikaze-lab-return, body.card .modes .m-sub { display: none; }
body.card .t-lcd { padding: 1.3vw 1.6vw 1.6vw; border-radius: 1.6vw; }
body.card .t-sub { font-size: 2.1vw; }
body.card .t-title { font-size: 4vw; }
body.card .modes { gap: 1.8vw; }
body.card .modes button { width: 100%; padding: 1.2vw 1.95vw; gap: 1.3vw; box-shadow: inset 0 -.4vw 0 rgba(0,0,0,.12), inset 0 .3vw 0 rgba(255,255,255,.35), 0 .75vw 0 var(--mc-lo); }
body.card .modes button b { font-size: 2.9vw; }
body.card .modes .badge { font-size: 1.55vw; padding: .4vw 1.15vw; }
/* 設定や友だち対戦を出している間は、記号の飾りをしまう */
#title:has(#modes[hidden]) .t-ops, #title:has(#modes[hidden]) .t-brand { display: none; }
#title:has(#modes[hidden]) .t-scene { flex-basis: 26%; }
#title:has(#modes[hidden]) .t-carbox { width: min(66%, calc((26vh - 10px) * 1.28)); }
#title:has(#modes[hidden]) .t-calc { justify-content: flex-start; gap: 10px; padding-top: 12px; }

.modes { display: flex; flex-direction: column; align-items: center; gap: 12px; width: 100%; }
.modes button { --mc: #e2487a; --mc-hi: #ff8ab0; --mc-lo: #9c1f4a; display: flex; flex-direction: row; align-items: center; justify-content: center; gap: 10px; width: min(86%, 340px); padding: 7px 18px; border: 0; border-radius: 999px; text-align: center; color: #fff; background: radial-gradient(120% 140% at 35% 15%, var(--mc-hi), var(--mc) 55%); box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.12), inset 0 3px 0 rgba(255, 255, 255, 0.35), 0 6px 0 var(--mc-lo), 0 10px 14px rgba(0, 0, 0, 0.25); font-family: var(--font-ui); }
.modes .m-txt { display: flex; flex-direction: column; align-items: center; text-align: center; }
.modes button b { white-space: nowrap; font: 900 18px/1.2 var(--font-jp); color: #fff; text-shadow: 0 2px 0 var(--mc-lo); }
.modes .m-sub { font-size: 11px; line-height: 1.25; color: rgba(255, 255, 255, 0.95); font-weight: 700; white-space: nowrap; letter-spacing: -0.02em; }
.modes .badge { flex: none; padding: 3px 8px; border-radius: 999px; background: #fff; color: var(--mc); font: 800 11px/1.3 var(--font-ui); font-style: normal; }
.modes .badge.soon { background: #5d6675; color: #fff; }
.modes button[data-mode="cpu"] { --mc: #3a6df0; --mc-hi: #8fb4ff; --mc-lo: #1f3f9a; }
.modes button[data-mode="friend"] { --mc: #7b5cd6; --mc-hi: #b9a2ff; --mc-lo: #4a3390; }
.modes button:disabled { --mc: #8a93a3; --mc-hi: #c3c9d4; --mc-lo: #5d6675; }
.modes button:disabled .badge { color: #5d6675; }
.modes button:disabled .badge.soon { color: #fff; }
#title .note { margin: 0; color: #fff; font-size: 12px; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); }

/* モードごとの出し分け */
.who .pt { font: 900 18px var(--font-num); min-width: 1.2em; text-align: center; }
.who.you .pt { display: none; }
body[data-mode="free"] .who.you .pt { display: inline; }
body[data-mode="free"] .who.cpu, body[data-mode="free"] #opp { display: none; }
body:not([data-mode="free"]) .free-only { display: none; }
body[data-mode="free"] .row.small { grid-template-columns: repeat(4, 1fr); }
body[data-mode="free"] .row.small button { font-size: 13px; white-space: nowrap; letter-spacing: -0.02em; }

/* 相手の電卓：逆さま・うっすら。押したボタン・式・答えがそのまま見える */
#opp { position: absolute; left: 50%; top: 50px; width: min(54%, 220px); transform: translateX(-50%) rotate(180deg); padding: 6px 10px 10px; border-radius: 14px; background: linear-gradient(180deg, #3b4256, #2a3042); box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.12), 0 3px 8px rgba(0, 0, 0, 0.3); display: grid; gap: 4px; opacity: 0; transition: opacity 0.4s; pointer-events: none; }
#opp.on { opacity: 0.8; }
.o-label { color: #fff; font: 800 11px/1.2 var(--font-ui); text-align: center; letter-spacing: 0.05em; }
.o-lcd { display: flex; justify-content: flex-end; align-items: baseline; gap: 6px; padding: 2px 8px; border-radius: 6px; background: rgba(201, 220, 180, 0.85); color: #1f2e16; font: 700 12px var(--font-num); min-height: 26px; }
#oVal { font-size: 26px; }
.o-x { position: absolute; inset: 0; display: grid; place-items: center; font: 900 70px/1 var(--font-ui); color: #ff3b3b; opacity: 0; }
.o-x.on { animation: ox 0.8s ease-out; }
@keyframes ox { 15% { opacity: 1; } 70% { opacity: 1; } 100% { opacity: 0; } }
#opp.reveal .o-lcd { background: #fff6a8; }
#paper.up { top: 39% !important; }

#hintMsg { position: absolute; left: 50%; top: 81.5%; transform: translateX(-50%); padding: 7px 14px; border-radius: 12px; background: rgba(255, 255, 255, 0.95); font-weight: 900; font-size: 15px; z-index: 1; white-space: nowrap; box-shadow: 0 4px 0 rgba(0, 0, 0, 0.2); opacity: 0; transition: opacity 0.2s; pointer-events: none; }
#hintMsg.on { opacity: 1; }
#next { position: absolute; right: 12px; bottom: 6px; padding: 9px 18px; border: 0; border-radius: 999px; font: 900 18px var(--font-ui); color: #fff; background: #ff6a3d; box-shadow: 0 5px 0 #a83716; opacity: 0; pointer-events: none; transform: translateY(10px); transition: opacity 0.25s, transform 0.25s; }
#home { position: absolute; left: 12px; bottom: 6px; padding: 9px 16px; border: 0; border-radius: 999px; font: 900 15px var(--font-ui); color: #fff; background: #4b5370; box-shadow: 0 5px 0 #1e2333; opacity: 0; pointer-events: none; }
#home.on { opacity: 1; pointer-events: auto; }
#next.on { opacity: 1; pointer-events: auto; transform: none; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }

/* 2段目：CPUの強さ・何点先取・エンドレス */
#setup { display: flex; flex-direction: column; align-items: center; gap: 10px; width: min(100%, 340px); }
#setup[hidden], #modes[hidden] { display: none; }
#setup .q { margin: 6px 0 0; padding: 2px 12px; border-radius: 999px; background: rgba(20, 28, 48, 0.92); color: #fff; font-weight: 900; font-size: 16px; }
.levels { display: flex; gap: 10px; width: 100%; }
.levels button { flex: 1; padding: 11px 0; border: 0; border-radius: 14px; font: 900 18px var(--font-jp); color: #fff; background: #3a6df0; box-shadow: 0 5px 0 #1f3f9a; filter: saturate(0.3) brightness(0.8); }
.levels button[data-level="weak"] { background: #2fb38a; box-shadow: 0 5px 0 #1a7a5c; }
.levels button[data-level="strong"] { background: #e2364f; box-shadow: 0 5px 0 #8f1526; }
.levels button.sel { filter: none; outline: 3px solid #fff; outline-offset: 2px; }
.stepper { display: flex; align-items: center; gap: 12px; padding: 4px 14px; border-radius: 999px; background: rgba(20, 28, 48, 0.92); color: #fff; font-weight: 900; }
.stepper b { font-size: 54px; min-width: 1.4em; text-align: center; }
.stepper span { font-size: 18px; }
.stepper button { width: 52px; height: 52px; border: 0; border-radius: 50%; font-size: 22px; color: #22304a; background: #fff; box-shadow: 0 4px 0 #9aa7a0; }
.stepper button:disabled { opacity: 0.35; }
#setup .big { width: 100%; padding: 14px 0; border: 0; border-radius: 999px; font: 900 19px var(--font-ui); color: #fff; background: #ff6a3d; box-shadow: 0 5px 0 #a83716; }
#setup .endless { background: #7b5cd6; box-shadow: 0 5px 0 #4a3390; }
#setup .link { border: 0; padding: 6px 14px; border-radius: 999px; background: rgba(20, 28, 48, 0.92); color: #fff; font: 700 14px var(--font-ui); }

/* 点数：電卓の右上に赤い丸（エンドレスは数字） */
#calc { position: relative; }
.marks { position: absolute; top: 3px; right: 16px; display: flex; gap: 4px; align-items: center; z-index: 1; }
.marks i { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid rgba(255, 90, 90, 0.7); }
.marks i.on { background: #ff3b3b; border-color: #ff3b3b; box-shadow: 0 0 6px rgba(255, 59, 59, 0.8); }
.marks i.pop { animation: dpop 0.4s cubic-bezier(0.2, 1.6, 0.4, 1); }
.marks b { min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: #ff3b3b; color: #fff; font: 900 15px/22px var(--font-num); text-align: center; }
#opp .marks { top: 4px; right: 10px; }
body[data-mode="free"] .marks { display: none; }
#calc { padding-top: 18px; }

#result { position: absolute; inset: 0; z-index: 6; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; background: rgba(20, 28, 48, 0.95); }
#result[hidden], .levels[hidden] { display: none; }
#resTitle { position: static; opacity: 1; transform: rotate(-6deg); font-size: clamp(40px, 12vw, 72px); }
#resSub { color: #cfd8ee; font-weight: 800; margin-top: -8px; }
#resScore { font: 900 54px var(--font-num); color: #fff; letter-spacing: 0.06em; }
#result button { width: min(80%, 300px); padding: 14px 0; border: 0; border-radius: 999px; font: 900 20px var(--font-ui); color: #fff; background: #ff6a3d; box-shadow: 0 5px 0 #a83716; }
#result #toTitle { background: #4b5370; box-shadow: 0 5px 0 #1e2333; font-size: 16px; }

/* 決着の演出 */
#stamp.mega { font-size: clamp(52px, 15vw, 96px); top: 46%; z-index: 2; }
#confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 3; }
#confetti i { position: absolute; top: -20px; width: 9px; height: 14px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translate(var(--dx), 560px) rotate(var(--r)); } }
.marks i.flash { animation: mflash 0.5s ease-out; }
@keyframes mflash { 0% { transform: scale(1); } 40% { transform: scale(2); background: #fff; box-shadow: 0 0 14px #ff3b3b; } 100% { transform: scale(1); } }
#resScore.tick { animation: tick 0.22s ease-out; }
@keyframes tick { 40% { transform: scale(1.18); } }
#resRec { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 18px; border-radius: 14px; background: rgba(255, 255, 255, 0.1); color: #e6ebf7; font-size: 14px; font-weight: 700; transition: opacity 0.3s; }
#resRec b { font-size: 12px; color: #cfd8ee; }
#resRec.rounds { max-height: 30vh; overflow-y: auto; align-items: flex-start; text-align: left; width: min(86%, 340px); }
#resRec.rounds span { font-size: 13px; }
#resRec em { font-style: normal; color: #ffc21a; font-weight: 900; }

/* ホーム・音量 */
#tools { position: absolute; left: 50%; top: max(8px, env(safe-area-inset-top)); transform: translateX(-50%); z-index: 7; display: flex; gap: 6px; }
#tools button { display: flex; align-items: center; gap: 2px; height: 34px; min-width: 34px; padding: 0 8px; border: 0; border-radius: 999px; color: #22304a; background: rgba(255, 255, 255, 0.92); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.18); font: 800 11px var(--font-ui); }
#tools svg { width: 18px; height: 18px; }
#btnVol .mute { display: none; }
#btnVol[data-v="0"] .w1, #btnVol[data-v="0"] .w2, #btnVol[data-v="0"] .w3 { display: none; }
#btnVol[data-v="0"] .mute { display: inline; }
#btnVol[data-v="1"] .w2, #btnVol[data-v="1"] .w3, #btnVol[data-v="2"] .w3 { opacity: 0.2; }
body:not([data-mode]) #btnHome { display: none; }
body:not([data-mode]) #tools { left: auto; right: 10px; transform: none; }
#confirm { position: absolute; inset: 0; z-index: 8; display: grid; place-items: center; background: rgba(20, 28, 48, 0.6); }
#confirm[hidden] { display: none; }
#confirm .box { width: min(84%, 300px); padding: 20px 18px 16px; border-radius: 20px; background: #fff; display: grid; gap: 10px; text-align: center; }
#confirm p { margin: 0 0 4px; font-weight: 900; font-size: 18px; display: grid; gap: 4px; }
#confirm small { font-size: 13px; font-weight: 700; color: #4a5a7a; }
#confirm button { padding: 13px 0; border: 0; border-radius: 999px; font: 900 17px var(--font-ui); color: #fff; background: #4b5370; box-shadow: 0 4px 0 #1e2333; }
#confirm #confirmNo { background: #ff6a3d; box-shadow: 0 4px 0 #a83716; }

/* 横向きのスマホ（背が低い）：左に道、右に電卓 */
@media (orientation: landscape) and (max-height: 560px) {
  #app { flex-direction: row; max-width: none; }
  #scene { flex: 1 1 55%; }
  #calc { flex: 1 1 45%; padding: 22px 14px 8px; gap: 6px; }
  #digits button { max-height: 54px; font-size: 34px; aspect-ratio: auto; height: 54px; }
  #ops button { width: 46px; }
  #val { font-size: 34px; }
  .row.small button { min-height: 30px; }
  /* タイトル：左に道と車、右に電卓 */
  #title { flex-direction: row; overflow: hidden; }
  .t-scene { flex: 0 0 48%; height: 100%; }
  .t-carbox { width: 62%; }
  .t-calc { flex: 1 1 auto; height: 100%; overflow-y: auto; justify-content: center; gap: 8px; padding: 12px 14px; }
  .t-brand, .t-ops { display: none; }
  .t-lcd { padding: 6px 10px 8px; }
  .t-sub { font-size: 12px; }
  .t-title { font-size: clamp(22px, 4.2vw, 34px); }
  .modes { gap: 10px; }
  body[data-mode] #tools { left: calc(55% + 14px); transform: none; top: 6px; }
  #stamp { font-size: 50px; }
  #stamp.mega { font-size: 62px; }
  #hintMsg { top: auto; bottom: 64px; }
  #calc { padding-top: 48px; }
}

/* 友だち対戦：待合室など（道の上でも読めるように紺の帯） */
#friend { display: flex; flex-direction: column; align-items: center; gap: 10px; width: min(100%, 340px); }
#friend[hidden], #friend [hidden] { display: none !important; }
.f-title { margin: 0; padding: 4px 16px; border-radius: 999px; background: rgba(20, 28, 48, 0.92); color: #fff; font: 900 18px var(--font-jp); }
.f-col { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%; }
#friend .big { width: 100%; padding: 14px 0; border: 0; border-radius: 999px; font: 900 19px var(--font-ui); color: #fff; background: #7b5cd6; box-shadow: 0 5px 0 #4a3390; }
#friend .big.alt { background: #3a6df0; box-shadow: 0 5px 0 #1f3f9a; }
#friend .big.on { background: #2fb38a; box-shadow: 0 5px 0 #1a7a5c; }
#friend .q, .f-hint, .f-msg, .f-label { margin: 0; padding: 2px 12px; border-radius: 999px; background: rgba(20, 28, 48, 0.92); color: #fff; font-weight: 800; font-size: 14px; text-align: center; }
.f-hint { font-size: 12px; font-weight: 700; }
.f-input { display: flex; gap: 8px; width: 100%; margin: 0; }
.f-input input { flex: 1; min-width: 0; padding: 12px 14px; border: 3px solid #7b5cd6; border-radius: 14px; font: 800 20px var(--font-jp); }
.f-input button { padding: 0 18px; border: 0; border-radius: 14px; font: 900 17px var(--font-ui); color: #fff; background: #7b5cd6; box-shadow: 0 4px 0 #4a3390; }
.f-grid { display: flex; flex-wrap: wrap; justify-content: center; gap: 5px; width: 100%; padding: 8px; border-radius: 14px; background: rgba(20, 28, 48, 0.85); }
.f-grid:empty { display: none; }
.f-grid button { min-width: 38px; min-height: 38px; border: 0; border-radius: 10px; font: 800 18px var(--font-jp); background: #fff; color: #22304a; }
.f-grid button.sel { background: #7b5cd6; color: #fff; }
.f-grid.words { background: rgba(123, 92, 214, 0.92); }
.f-grid.words button { padding: 0 14px; min-height: 46px; font-size: 22px; color: #4a3390; }
.f-game { margin: 0; color: #fff; font: 900 15px var(--font-jp); text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6); }
.f-code { margin: 0; padding: 4px 24px 8px; border-radius: 18px; background: #fff; color: #4a3390; font: 900 48px/1.1 var(--font-jp); letter-spacing: 0.08em; box-shadow: inset 0 0 0 4px #7b5cd6, 0 5px 0 rgba(0, 0, 0, 0.2); }
.f-players { display: flex; gap: 10px; }
.f-players .pl { padding: 6px 14px; border-radius: 999px; background: rgba(255, 255, 255, 0.55); color: #4a5a7a; font-weight: 900; font-size: 14px; }
.f-players .pl.here { background: #fff; color: #22304a; }
.f-players .pl.ok::after { content: " ✓準備OK"; color: #1a7a5c; }
.f-set { display: flex; align-items: center; gap: 10px; padding: 6px 14px; border-radius: 999px; background: rgba(20, 28, 48, 0.92); color: #fff; font-weight: 900; }
.f-set button { width: 40px; height: 40px; border: 0; border-radius: 50%; background: #fff; color: #22304a; font-size: 16px; }
.f-set button:disabled { opacity: 0.35; }
.f-set b { font: 900 30px var(--font-num); min-width: 1.2em; text-align: center; }
.f-set .tog { width: auto; height: 36px; padding: 0 12px; border-radius: 999px; font: 800 13px var(--font-ui); }
.f-set .tog.on { background: #7b5cd6; color: #fff; }
.f-err { margin: 0; min-height: 0; color: #fff; font-weight: 900; font-size: 14px; text-align: center; }
.f-err:not(:empty) { padding: 6px 14px; border-radius: 12px; background: #e2364f; }
#friend .link { border: 0; padding: 6px 14px; border-radius: 999px; background: rgba(20, 28, 48, 0.92); color: #fff; font: 700 14px var(--font-ui); }
#ctdn { position: absolute; inset: 0; z-index: 4; display: grid; place-items: center; pointer-events: none; }
#ctdn b { font-size: clamp(90px, 30vw, 160px); }

@media (prefers-reduced-motion: reduce) {
  #scene.shake, #lcd.ng { animation: none; }
  #miss.on { animation-duration: 1.1s; animation-timing-function: steps(1); }
  #paper.slap, #paper.up { opacity: 1; }
#paper.slap { animation-duration: 0.01s; }
}

/* タイトル右下の版（小さく控えめに。押せない） */
#title .game-version { position: absolute; right: max(10px, env(safe-area-inset-right)); bottom: max(6px, env(safe-area-inset-bottom)); z-index: 2; margin: 0; color: rgba(255, 255, 255, 0.75); font-size: 11px; line-height: 1; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5); pointer-events: none; }
