:root {
  --orange: #ff9f43;
  --pink: #ff6b9d;
  --yellow: #ffd43b;
  --blue: #3a86ff;
  --green: #2ec27e;
  --purple: #8e5cf7;
  --ink: #2b2d42;
  --paper: #fffaf0;
  --font: "Hiragino Maru Gothic ProN", "Hiragino Maru Gothic Pro", "Yu Gothic", "Meiryo", "Noto Sans JP", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #ffcf8b;
  color: var(--ink);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

#app { position: fixed; inset: 0; overflow: hidden; }

#game {
  position: absolute; inset: 0;
  touch-action: none;
  cursor: pointer;
}
#game canvas { display: block; width: 100%; height: 100%; }

img { -webkit-user-drag: none; user-select: none; pointer-events: none; }

.hidden { display: none !important; }

/* ===== ボタン ===== */
button {
  font-family: inherit;
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
  cursor: pointer;
}
.btn {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 999px;
  color: #fff;
  font-weight: 800;
  letter-spacing: .06em;
  background: linear-gradient(#ff7a59, #ff4d6d);
  box-shadow: 0 6px 0 #c9184a, 0 10px 18px rgba(0,0,0,.18);
  transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(5px); box-shadow: 0 1px 0 #c9184a, 0 4px 8px rgba(0,0,0,.18); }
.btn.big { font-size: clamp(28px, 8vw, 40px); padding: 16px 20px; margin: 10px 0 16px; }
.btn.mid { font-size: clamp(18px, 5vw, 22px); padding: 12px 16px; margin: 8px 0; }
.btn.small { width: auto; font-size: 16px; padding: 10px 16px; margin: 0; }
.btn.alt { background: linear-gradient(#4dabf7, #3a86ff); box-shadow: 0 6px 0 #1c5ed6, 0 10px 18px rgba(0,0,0,.15); }
.btn.alt:active { box-shadow: 0 1px 0 #1c5ed6; }
.btn.ghost { background: #fff; color: var(--ink); box-shadow: 0 5px 0 #c8c2b6, 0 8px 14px rgba(0,0,0,.12); }
.btn.ghost:active { box-shadow: 0 1px 0 #c8c2b6; }
.btn.small { background: #fff; color: var(--ink); box-shadow: 0 4px 0 #c8c2b6; }

.sound-btn .ico-off { display: none; }
body.muted .sound-btn .ico-on { display: none; }
body.muted .sound-btn .ico-off { display: block; }

.btn.sound-on {
  width: auto; display: inline-block;
  margin: 10px 0 0; padding: 10px 22px;
  font-size: clamp(17px, 4.8vw, 21px);
  color: var(--ink);
  background: linear-gradient(#fff3a0, #ffd43b);
  box-shadow: 0 5px 0 #e67700, 0 8px 14px rgba(0,0,0,.15);
  animation: blink 0.9s infinite alternate;
}
.btn.sound-on:active { box-shadow: 0 1px 0 #e67700; }
.btn.sound-on.on { background: rgba(255,255,255,.85); box-shadow: 0 3px 0 rgba(0,0,0,.15); animation: none; font-size: 15px; padding: 6px 14px; }

/* 音のせってい */
.settings { text-align: left; }
.settings h2 { text-align: center; }
.set-block { background: #fff; border-radius: 18px; padding: 10px 14px; margin: 8px 0; box-shadow: 0 3px 0 rgba(0,0,0,.08); }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.set-label { font-size: 20px; font-weight: 800; }
.set-label rt { font-size: 10px; }
.tog {
  min-width: 84px; border: 0; border-radius: 99px; padding: 10px 14px;
  font-size: 18px; font-weight: 800; color: #fff;
  background: var(--green); box-shadow: 0 4px 0 #1b8a57;
}
.tog[aria-pressed="false"] { background: #adb5bd; box-shadow: 0 4px 0 #868e96; }
.vol-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; font-weight: 800; color: #888; }
.vol-row input { flex: 1; height: 36px; accent-color: var(--orange); touch-action: pan-x; }
.vol-row input:disabled { opacity: .4; }
.set-note { margin: 4px 0 0; font-size: 13px; color: #777; font-weight: 700; }
.credit { margin: 8px 0 0; font-size: 10px; color: #999; text-align: center; line-height: 1.4; }

/* ===== HUD ===== */
#hud {
  position: absolute; left: 0; right: 0; top: 0;
  padding: calc(8px + env(safe-area-inset-top)) calc(10px + env(safe-area-inset-right)) 0 calc(10px + env(safe-area-inset-left));
  pointer-events: none;
}
.hud-row { display: flex; align-items: center; gap: 8px; }
.hud-row .spacer { flex: 1; }
.chip {
  background: rgba(255,255,255,.92);
  border-radius: 999px;
  padding: 6px 14px;
  font-weight: 800;
  font-size: clamp(15px, 4.2vw, 20px);
  box-shadow: 0 3px 0 rgba(0,0,0,.12);
  white-space: nowrap;
}
.chip.coins { display: flex; align-items: center; gap: 6px; min-width: 76px; }
.coin-ico {
  display: inline-block; width: 1em; height: 1em; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff6b0 0 18%, #ffd43b 20% 62%, #f59f00 64%);
  box-shadow: inset 0 0 0 2px #e67700;
}
.ibtn {
  pointer-events: auto;
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 0;
  background: rgba(255,255,255,.95);
  color: var(--ink);
  box-shadow: 0 4px 0 rgba(0,0,0,.18);
  display: grid; place-items: center;
  padding: 0;
}
.ibtn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.18); }
.ibtn svg { width: 28px; height: 28px; fill: currentColor; }

.progress { position: relative; margin: 10px 46px 0 6px; height: 30px; }
.progress .track {
  position: absolute; left: 0; right: 0; top: 10px; height: 12px;
  border-radius: 99px; background: rgba(255,255,255,.75);
  box-shadow: inset 0 2px 0 rgba(0,0,0,.12);
  overflow: hidden;
}
#progFill { height: 100%; width: 0; background: linear-gradient(90deg, var(--yellow), var(--orange)); border-radius: 99px; }
#progHead {
  position: absolute; top: -4px; left: 0; height: 36px; width: auto;
  transform: translateX(-50%);
  filter: drop-shadow(0 2px 1px rgba(0,0,0,.25));
}
.goal-flag {
  position: absolute; right: -46px; top: 4px;
  font-size: 13px; font-weight: 800; color: #fff;
  background: var(--green); border-radius: 6px; padding: 3px 6px;
}

/* ===== 画面（オーバーレイ） ===== */
.screen {
  position: absolute; inset: 0;
  display: none;
  align-items: center; justify-content: center;
  padding: calc(16px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}
.screen.show { display: flex; }
.screen.dim { background: rgba(30, 20, 60, .45); }

.panel {
  width: min(420px, 100%);
  margin: auto;
  background: var(--paper);
  border-radius: 28px;
  padding: 22px 22px 14px;
  text-align: center;
  box-shadow: 0 10px 0 rgba(0,0,0,.12), 0 20px 40px rgba(0,0,0,.25);
  border: 4px solid #fff;
  animation: pop .35s cubic-bezier(.2,1.6,.4,1);
}
@keyframes pop { from { transform: scale(.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.panel h2 { margin: 4px 0 8px; font-size: clamp(28px, 8vw, 38px); }
.panel .sub { margin: 0 0 6px; font-size: 18px; font-weight: 700; white-space: pre-line; line-height: 1.4; }
.fail-title { color: #5c7cfa; }
.clear-title {
  color: #ff4d6d;
  text-shadow: 0 3px 0 #ffd43b;
}
.result { display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 44px; font-weight: 900; margin: 6px 0; }
.result small { font-size: 22px; color: #777; }
.big-ico { width: 44px; height: 44px; }
.newrec {
  display: inline-block; margin: 2px 0 6px; padding: 4px 14px;
  border-radius: 99px; background: var(--yellow); font-weight: 800; font-size: 18px;
  animation: blink 1s infinite alternate;
}
.newrec.hidden { display: none; }
@keyframes blink { from { transform: scale(1); } to { transform: scale(1.08); } }
.celebrate .small-hero { height: 120px; width: auto; animation: bounce 0.8s infinite alternate ease-in-out; }
@keyframes bounce { from { transform: translateY(0) rotate(-4deg); } to { transform: translateY(-14px) rotate(4deg); } }

/* ===== タイトル ===== */
#scrTitle {
  background:
    radial-gradient(circle at 15% 20%, rgba(255,255,255,.5) 0 60px, transparent 61px),
    radial-gradient(circle at 85% 80%, rgba(255,255,255,.35) 0 90px, transparent 91px),
    linear-gradient(160deg, #ffe066 0%, #ffa94d 45%, #ff6b9d 100%);
}
.title-wrap {
  width: min(460px, 100%);
  margin: auto;
  display: flex; flex-direction: column; align-items: center;
}
.hero-box { position: relative; }
.hero {
  display: block;
  height: min(30vh, 240px); width: auto;
  filter: drop-shadow(0 8px 0 rgba(0,0,0,.12));
  animation: bounce 1.2s infinite alternate ease-in-out;
}
.title-main { width: 100%; text-align: center; }
h1 {
  margin: 4px 0 0;
  font-size: clamp(40px, 13vw, 64px);
  line-height: 1.1;
  color: #fff;
  letter-spacing: .04em;
  text-shadow: 0 4px 0 #c9184a, 0 8px 12px rgba(0,0,0,.2);
  -webkit-text-stroke: 2px #c9184a;
  paint-order: stroke fill;
}
h1 rt { font-size: .32em; -webkit-text-stroke: 0; text-shadow: none; color: #fff; letter-spacing: .1em; }
h1 span { display: inline-block; }
.howto { display: flex; gap: 10px; }
.how-card {
  flex: 1;
  background: rgba(255,255,255,.92);
  border-radius: 18px;
  padding: 8px 8px 6px;
  box-shadow: 0 4px 0 rgba(0,0,0,.1);
}
.how-card svg { width: 100%; height: auto; display: block; }
.how-card p { margin: 4px 0 0; font-size: clamp(16px, 4.6vw, 20px); font-weight: 700; line-height: 1.25; }
.how-card b { color: #ff4d6d; }
.pc-note { margin: 8px 0 6px; font-size: 13px; font-weight: 700; color: rgba(0,0,0,.6); }
.stage-list { display: flex; gap: 8px; margin: 6px 0 10px; }
.stage-btn {
  flex: 1;
  border: 0; border-radius: 16px;
  padding: 8px 4px 6px;
  background: #fff;
  box-shadow: 0 4px 0 rgba(0,0,0,.15);
  font-weight: 800; color: var(--ink);
  font-size: 15px; line-height: 1.3;
}
.stage-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.15); }
.stage-btn .num { font-size: 13px; color: #888; }
.stage-btn .nm { display: block; font-size: 16px; }
.stage-btn .st { display: block; font-size: 13px; color: #e67700; min-height: 1.3em; }
.stage-btn.cleared { background: #fff3bf; }
.stage-btn.locked { opacity: .55; }
.title-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.best { font-weight: 800; font-size: 15px; background: rgba(255,255,255,.7); padding: 8px 12px; border-radius: 99px; }

/* 横もち */
@media (orientation: landscape) and (max-height: 620px) {
  .title-wrap { width: min(820px, 100%); flex-direction: row; gap: 18px; align-items: center; }
  .hero { height: min(62vh, 300px); }
  .title-main { flex: 1; }
  h1 { font-size: clamp(34px, 7vh, 52px); }
  .btn.big { font-size: 28px; padding: 10px; margin: 6px 0 10px; }
  .how-card svg { max-height: 13vh; }
  .stage-btn { padding: 4px 4px 3px; }
  .how-card p { font-size: 15px; }
  .pc-note { margin: 4px 0; }
  .btn.sound-on { margin-top: 4px; padding: 6px 16px; font-size: 16px; }
  .set-block { padding: 6px 12px; margin: 5px 0; }
  .set-note { display: none; }
  .credit { margin-top: 2px; }
  .stage-list { margin: 4px 0 6px; }
  .panel { padding: 12px 18px 8px; }
  .panel h2 { font-size: 28px; margin: 0 0 4px; }
  .result { font-size: 34px; margin: 0; }
  .panel .btn.big { margin: 6px 0 8px; padding: 10px; font-size: 26px; }
  .panel .btn.mid { margin: 5px 0; padding: 8px; }
  .celebrate .small-hero { display: none; }
  .panel .sub { font-size: 15px; margin-bottom: 2px; }
  .newrec { margin: 0 0 2px; font-size: 15px; }
  .ibtn { width: 46px; height: 46px; }
  .progress { margin-top: 4px; }
}
@media (orientation: landscape) and (max-height: 620px) and (pointer: coarse) {
  .pc-note { display: none; }
}
