:root {
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --main: #ff8a3d;
  --main-dark: #e26a1c;
  --ink: #3b2a1e;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  overflow: hidden; position: fixed; inset: 0;
  overscroll-behavior: none; touch-action: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
  background: #bfe6ff; color: var(--ink);
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Noto Sans JP", "Noto Sans CJK JP", "Yu Gothic", system-ui, sans-serif;
}
#app { position: fixed; inset: 0; overflow: hidden; touch-action: none; }
#c { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#touch { position: absolute; inset: 0; touch-action: none; }
.hidden { display: none !important; }
button {
  font: inherit; color: #fff; border: 0; cursor: pointer; touch-action: manipulation;
  background: var(--main); border-radius: 999px; font-weight: 800;
  box-shadow: 0 5px 0 var(--main-dark), 0 8px 18px rgba(0,0,0,.18);
  -webkit-user-select: none; user-select: none;
}
button:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--main-dark); }
button.big { font-size: 26px; padding: 16px 0; width: min(78vw, 300px); }
button.mid { font-size: 19px; padding: 13px 18px; min-width: 130px; }
button.small { font-size: 15px; padding: 9px 14px; }
button.ghost { background: #fff; color: var(--main-dark); box-shadow: 0 5px 0 #e9d6c6, 0 8px 18px rgba(0,0,0,.12); }
button.sound {
  position: absolute; z-index: 30;
  top: calc(var(--sat) + 10px); right: calc(var(--sar) + 10px);
  background: rgba(255,255,255,.92); color: var(--ink); box-shadow: 0 3px 0 rgba(0,0,0,.15);
}
button.sound.on { background: #ffe066; }

.screen {
  position: absolute; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  padding: calc(var(--sat) + 56px) calc(var(--sar) + 16px) calc(var(--sab) + 24px) calc(var(--sal) + 16px);
  text-align: center;
}
.screen.dim { background: rgba(40, 30, 20, .45); }
h1 {
  margin: 0; font-size: 72px; line-height: 1.1; color: #fff; letter-spacing: 4px;
  -webkit-text-stroke: 3px var(--main-dark); paint-order: stroke fill;
  text-shadow: 0 6px 0 var(--main-dark), 0 10px 20px rgba(0,0,0,.2);
}
h2 { margin: 0; font-size: 30px; }
.sub { margin: 12px 0 0; font-size: 18px; font-weight: 700; line-height: 1.6;
  background: rgba(255,255,255,.85); padding: 8px 16px; border-radius: 16px; }
#scr-title { justify-content: space-between; padding-top: calc(var(--sat) + 70px); padding-bottom: calc(var(--sab) + 60px); }

/* 犬を選ぶ */
#scr-select { justify-content: flex-end; gap: 10px; }
#scr-select h2 {
  position: absolute; top: calc(var(--sat) + 14px); left: 0; right: 0;
  font-size: 26px; color: #fff; -webkit-text-stroke: 2px var(--main-dark); paint-order: stroke fill;
}
#dogList { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 7px; }
.dog {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; text-align: left;
  width: 100%; min-width: 0; box-sizing: border-box;
  background: rgba(255,255,255,.93); border-radius: 16px; padding: 8px 12px;
  border: 3px solid transparent; color: var(--ink); box-shadow: 0 3px 0 rgba(0,0,0,.08);
  font-weight: 400;
}
.dog:active { transform: none; }
.dog.sel { border-color: var(--main); background: #fff6ea; }
/* 名前が 長いと ★は 下の 行へ（画面から はみ出さない） */
.dog .nm { font-size: 18px; font-weight: 800; min-width: 0; overflow-wrap: anywhere; flex: 0 1 auto; }
.dog .st { font-size: 17px; color: #f2a900; white-space: nowrap; margin-left: auto; letter-spacing: 1px; }
.dog .st .lv { font-size: 12px; color: #8a7565; letter-spacing: 0; margin-right: 4px; }
.dog .ds { flex: 1 0 100%; min-width: 0; font-size: 13.5px; line-height: 1.45; color: #5b4636; }
.dog .bs { flex: 1 0 100%; font-size: 12.5px; color: #8a7565; }
@media (max-width: 359px) {
  .dog { padding: 7px 10px; }
  .dog .nm { font-size: 16.5px; }
  .dog .st { font-size: 15px; }
  .dog .ds { font-size: 12.5px; }
}
.row { display: flex; gap: 12px; justify-content: center; width: 100%; }

/* HUD */
#hud {
  position: absolute; z-index: 25; left: 0; right: 0; top: 0; pointer-events: none;
  padding: calc(var(--sat) + 10px) calc(var(--sar) + 104px) 0 calc(var(--sal) + 12px);
  display: flex; align-items: flex-start; justify-content: space-between;
}
#hud button { pointer-events: auto; background: rgba(255,255,255,.92); color: var(--ink); box-shadow: 0 3px 0 rgba(0,0,0,.15); }
#score { background: rgba(255,255,255,.88); border-radius: 14px; padding: 4px 12px; display: flex; align-items: baseline; gap: 8px; }
#score .lab { font-size: 13px; font-weight: 700; }
#score b { font-size: 26px; font-variant-numeric: tabular-nums; }
#hint, #toast {
  position: absolute; z-index: 24; left: 50%; transform: translateX(-50%);
  background: rgba(255,255,255,.9); border-radius: 16px; padding: 10px 18px;
  font-size: 18px; font-weight: 800; text-align: center; line-height: 1.5; pointer-events: none; white-space: nowrap;
}
#hint { top: calc(var(--sat) + 120px); }
#toast { top: calc(var(--sat) + 76px); background: #ffe066; animation: pop .25s ease-out; }
#cue {
  position: absolute; z-index: 25; left: 50%; top: calc(var(--sat) + 168px); transform: translateX(-50%);
  background: #2f6fd6; color: #fff; border-radius: 18px; padding: 8px 18px 10px; text-align: center; pointer-events: none;
  white-space: nowrap; box-shadow: 0 6px 16px rgba(0,0,0,.18); animation: pop .25s ease-out;
}
#cue b { display: block; font-size: 26px; letter-spacing: .02em; }
#cue span { display: block; font-size: 15px; font-weight: 700; opacity: .95; }
#bonus {
  position: absolute; z-index: 26; left: 50%; top: calc(var(--sat) + 120px); transform: translateX(-50%);
  color: #ff8a00; font-size: 46px; font-weight: 900; pointer-events: none;
  text-shadow: 0 3px 0 #fff, 0 -3px 0 #fff, 3px 0 0 #fff, -3px 0 0 #fff, 0 6px 12px rgba(0,0,0,.25);
  animation: bonusUp 1.3s ease-out forwards;
}
@keyframes bonusUp { 0% { transform: translateX(-50%) scale(.5); opacity: 0; } 12% { transform: translateX(-50%) scale(1.15); opacity: 1; } 25% { transform: translateX(-50%) scale(1); opacity: 1; } 70% { transform: translate(-50%, -18px); opacity: 1; } 100% { transform: translate(-50%, -40px); opacity: 0; } }
@keyframes pop { from { transform: translateX(-50%) scale(.6); } to { transform: translateX(-50%) scale(1); } }

.card {
  background: rgba(255,255,255,.95); border-radius: 24px; padding: 22px 20px 26px;
  width: min(88vw, 340px); display: flex; flex-direction: column; align-items: center; gap: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.2);
}
.card p { margin: 0; font-size: 17px; }
#scr-over { justify-content: flex-end; padding-bottom: calc(var(--sab) + 40px); }
.over h2 { font-size: 36px; color: var(--main-dark); }
.scores { display: flex; gap: 12px; width: 100%; }
.scores div { flex: 1; background: #fff3e2; border-radius: 16px; padding: 8px 4px; display: flex; flex-direction: column; }
.scores span { font-size: 14px; font-weight: 700; color: #8a6a50; }
.scores b { font-size: 30px; font-variant-numeric: tabular-nums; }
.newrec { background: #ff5d73; color: #fff; font-weight: 800; padding: 4px 16px; border-radius: 999px; font-size: 18px; animation: pop2 .3s ease-out; }
@keyframes pop2 { from { transform: scale(.5); } to { transform: scale(1); } }

/* 小さい 画面: ボタンの 文字を 1行に、犬の リストは 画面に 入らなければ たてに スクロール */
#scr-select .row button { white-space: nowrap; }
#dogList { min-height: 0; flex: 0 1 auto; overflow-y: auto; touch-action: pan-y; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
@media (max-width: 359px) {
  #scr-select .row { gap: 8px; }
  #scr-select .row button.mid { font-size: 16px; padding: 12px 12px; min-width: 0; flex: 1 1 0; }
}
@media (max-height: 700px) {
  #scr-select { padding-top: calc(var(--sat) + 52px); }
  .dog { padding: 6px 10px; }
  .dog .ds { font-size: 12.5px; line-height: 1.35; }
}

/* 版の 表示（小さく） */
.ver { position: absolute; left: calc(var(--sal) + 10px); bottom: calc(var(--sab) + 6px); font-size: 11px; font-weight: 700; color: rgba(60,40,25,.55); pointer-events: none; }
.ver.in-card { position: static; margin-top: 4px; }

/* ---- v4.2 ---- */
.title-btns { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.hud-l { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; }
#mult { font-size: 13px; font-weight: 800; color: #2f6fd6; font-variant-numeric: tabular-nums; }
#combo, #dashInd { background: rgba(255,255,255,.82); border-radius: 10px; padding: 2px 9px; font-size: 12.5px; font-weight: 800; }
#combo b { font-size: 15px; color: #ff6a00; }
#combo span { color: #ff6a00; }
#dashInd { color: #d23d6e; }
#dashPips i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-left: 3px; background: #f1d2dc; vertical-align: middle; }
#dashPips i.on { background: #ff3d7f; }
#timer {
  position: absolute; z-index: 24; left: 50%; top: calc(var(--sat) + 52px); transform: translateX(-50%);
  pointer-events: none; display: flex; align-items: baseline; gap: 3px; color: #fff;
  -webkit-text-stroke: 2px #3b2a1e; paint-order: stroke fill; text-shadow: 0 3px 0 #3b2a1e;
}
#timer b { font-size: 58px; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
#timer span { font-size: 16px; font-weight: 800; -webkit-text-stroke: 1px #3b2a1e; }
#timer.last b { color: #ff5d5d; }
#hint { top: calc(var(--sat) + 132px); }
#toast { top: calc(var(--sat) + 122px); }
#cue { top: calc(var(--sat) + 178px); }
#floats { position: absolute; inset: 0; z-index: 26; pointer-events: none; overflow: hidden; }
.fl {
  position: absolute; transform: translate(-50%, -100%); white-space: nowrap; text-align: center;
  font-size: 17px; font-weight: 900; color: #ff7a00; line-height: 1.15;
  text-shadow: 0 2px 0 #fff, 0 -2px 0 #fff, 2px 0 0 #fff, -2px 0 0 #fff, 0 3px 8px rgba(0,0,0,.25);
  animation: flUp 1.1s ease-out forwards;
}
.fl.t1 { color: #ff4f9a; font-size: 19px; }
.fl.perfect { color: #ffcc00; font-size: 22px; -webkit-text-stroke: 1px #c46a00; }
.fl.unko { color: #8a5326; font-size: 15px; } /* v4.4: ポロッ */
.fl small { display: block; font-size: 11.5px; color: #2f6fd6; }
@keyframes flUp { 0% { opacity: 0; transform: translate(-50%, -80%) scale(.7); } 15% { opacity: 1; transform: translate(-50%, -100%) scale(1.08); } 30% { transform: translate(-50%, -100%) scale(1); } 100% { opacity: 0; transform: translate(-50%, calc(-100% - 46px)); } }
#dashPop {
  position: absolute; z-index: 26; left: 50%; top: calc(var(--sat) + 230px); transform: translateX(-50%);
  font-size: 30px; font-weight: 900; color: #ff3d7f; pointer-events: none; white-space: nowrap;
  text-shadow: 0 3px 0 #fff, 0 -3px 0 #fff, 3px 0 0 #fff, -3px 0 0 #fff; animation: pop .2s ease-out;
}
#goal {
  position: absolute; z-index: 27; left: 0; right: 0; top: 38%; transform: translateY(-50%); text-align: center;
  font-size: 64px; font-weight: 900; color: #fff; pointer-events: none; white-space: nowrap;
  -webkit-text-stroke: 3px var(--main-dark); paint-order: stroke fill; text-shadow: 0 6px 0 var(--main-dark), 0 10px 20px rgba(0,0,0,.25);
  animation: goalIn .45s cubic-bezier(.2,1.6,.4,1);
}
@keyframes goalIn { from { transform: translateY(-50%) scale(.3); opacity: 0; } to { transform: translateY(-50%) scale(1); opacity: 1; } }
.over.goal h2 { color: #e0a100; }
.detail { font-size: 13.5px; color: #6b5442; line-height: 1.5; }
.help { gap: 10px; max-height: calc(100vh - 80px); }
.help ul { margin: 0; padding: 0 0 0 1.1em; text-align: left; font-size: 14.5px; line-height: 1.5; overflow-y: auto; touch-action: pan-y; }
.help li { margin: 0 0 6px; }
.help b { color: var(--main-dark); }
