:root {
  --blue: #2f8bff;
  --blue-d: #1a62d6;
  --navy: #1c2f6e;
  --sky: #5cc0ff;
  --paper: #fffdf8;
  --yellow: #ffd21f;
  --font: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "Hiragino Sans", "Noto Sans JP", sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-weight: 700;
  color: var(--navy);
  background: linear-gradient(#5cc0ff, #2d82f7) fixed;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
button { font-family: inherit; font-weight: 800; color: inherit; border: 0; cursor: pointer; touch-action: manipulation; }

.screen { display: none; min-height: 100%; }
.screen.active { display: block; }
.wrap {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(20px + env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---------- ボタン・カード ---------- */
.btn {
  display: block;
  width: 100%;
  padding: 13px 16px;
  border-radius: 18px;
  font-size: 17px;
  background: var(--blue);
  color: #fff;
  box-shadow: 0 5px 0 var(--blue-d);
  transition: transform .06s, box-shadow .06s;
  user-select: none;
  -webkit-user-select: none;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--blue-d); }
.btn.big { font-size: 20px; padding: 16px; }
.btn.yellow { background: var(--yellow); color: var(--navy); box-shadow: 0 5px 0 #c99700; }
.btn.yellow:active { box-shadow: 0 1px 0 #c99700; }
.btn.white { background: #fff; color: var(--navy); box-shadow: 0 5px 0 #b9cdf2; }
.btn.white:active { box-shadow: 0 1px 0 #b9cdf2; }
.btn.ghost { background: rgba(255,255,255,.22); color: #fff; box-shadow: none; }
.btn.sq { width: 56px; flex: none; font-size: 24px; padding: 8px 0; }
.card {
  background: #fff;
  border-radius: 24px;
  padding: 18px;
  box-shadow: 0 6px 0 rgba(18,60,160,.28);
}
.note { font-size: 13px; font-weight: 500; line-height: 1.7; color: #4a5c8f; }
.note b { font-weight: 800; }

/* ---------- はじめの画面 ---------- */
.hero { text-align: center; color: #fff; padding: 14px 0 4px; }
.hero h1 {
  font-size: clamp(44px, 13vw, 68px);
  font-weight: 800;
  letter-spacing: .02em;
  line-height: 1.15;
  text-shadow: 0 5px 0 var(--blue-d), 0 9px 0 rgba(18,60,160,.3);
}
.hero .lead { margin-top: 12px; font-size: 16px; line-height: 1.7; }
.hero-dots { display: flex; justify-content: center; gap: 8px; margin-bottom: 10px; }
.hero-dots span {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--c);
  display: grid; place-items: center;
  box-shadow: 0 3px 0 rgba(18,60,160,.3);
  transition: transform .12s;
}
.hero-dots span.on { transform: translateY(-10px) scale(1.25); }
.hero-dots svg, .legend svg { width: 62%; height: 62%; fill: #fff; }
.sound { display: flex; flex-direction: column; gap: 10px; }
.sec { color: #fff; font-size: 20px; font-weight: 800; margin-top: 6px; text-shadow: 0 2px 0 var(--blue-d); }
#songs { display: flex; flex-direction: column; gap: 14px; }
.song { padding: 0; overflow: hidden; }
.song canvas { display: block; width: 100%; height: 92px; border-bottom: 3px solid var(--navy); background: var(--paper); }
.song-body { padding: 14px 16px 18px; }
.song h3 { font-size: 22px; font-weight: 800; }
.song .meta { font-size: 13px; font-weight: 500; color: #4a5c8f; margin: 2px 0 12px; }
.song-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.howto h3 { font-size: 18px; margin-bottom: 8px; }
.howto ol { margin: 0 0 12px; padding-left: 1.4em; font-size: 14px; font-weight: 500; line-height: 1.75; }
.howto ol b { font-weight: 800; }
.legend { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; margin-bottom: 8px; }
.legend div { text-align: center; font-size: 12px; font-weight: 800; }
.legend i {
  display: grid; place-items: center;
  aspect-ratio: 1; border-radius: 12px; background: var(--c); margin-bottom: 3px;
}
.pc-only { display: none; }
@media (hover: hover) and (pointer: fine) { .pc-only { display: block; } }
.foot { text-align: center; color: rgba(255,255,255,.7); font-size: 12px; }

/* ---------- あそぶ画面 ---------- */
#play.active {
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0;
  height: 100dvh;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
#hud {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(6px + env(safe-area-inset-top)) 12px 9px;
  background: #fff;
  box-shadow: 0 3px 0 rgba(18,60,160,.25);
  z-index: 2;
}
.hud-btn {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  background: #e6f0ff; color: var(--navy); font-size: 16px;
}
#hud-title { flex: 1; min-width: 0; font-size: 15px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-score { text-align: right; line-height: 1.05; }
.hud-score small { display: block; font-size: 10px; color: #4a5c8f; }
.hud-score b { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
#prog { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: #d7e6ff; }
#prog i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #ff4757, #ff9226, #ffd21f, #2fcf74, #22a6ff, #3d4fd6, #b558f2); background-size: 100vw 100%; }
#stage { flex: 1; min-height: 0; position: relative; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#pads {
  flex: none;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
  height: clamp(118px, 25dvh, 210px);
  padding: 10px 6px calc(12px + env(safe-area-inset-bottom));
  background: #1c2f6e;
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  touch-action: none;
  cursor: pointer;
}
@media (min-width: 860px) {
  #pads { border-radius: 24px 24px 0 0; gap: 10px; padding: 14px 16px 16px; height: clamp(118px, 22dvh, 170px); }
}
.pad {
  position: relative;
  border-radius: 14px;
  background: var(--c);
  box-shadow: 0 6px 0 var(--d), inset 0 3px 0 rgba(255,255,255,.35);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  pointer-events: none;
  transform: translateY(-3px);
  transition: transform .04s;
}
.pad.on { transform: translateY(3px); box-shadow: 0 0 0 var(--d), inset 0 3px 0 rgba(255,255,255,.35); filter: brightness(1.15); }
.pad svg { width: min(74%, 52px); aspect-ratio: 1; fill: #fff; stroke: rgba(10,25,80,.3); stroke-width: 1.2; }
.pad .pn { color: #fff; font-size: 14px; font-weight: 800; text-shadow: 0 1px 2px rgba(10,25,80,.45); line-height: 1; }
.pad .pk { display: none; }
@media (hover: hover) and (pointer: fine) {
  .pad .pk {
    display: block; font-size: 11px; line-height: 1; padding: 3px 6px; border-radius: 6px;
    background: rgba(10,25,80,.35); color: #fff;
  }
}

.overlay {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(20,45,120,.6);
  display: grid; place-items: center;
  padding: 20px;
  overflow: auto;
}
.modal { width: min(100%, 380px); display: flex; flex-direction: column; gap: 12px; text-align: center; }
.modal h2 { font-size: 22px; font-weight: 800; }
.modal .note { text-align: left; }

/* ---------- 結果の画面 ---------- */
.res-wrap { max-width: 560px; }
.res-pic { display: flex; flex-direction: column; gap: 10px; }
#res-h { color: #fff; font-size: 32px; font-weight: 800; text-align: center; text-shadow: 0 4px 0 var(--blue-d); }
#res-sub { white-space: pre-line; line-height: 1.6; color: #fff; text-align: center; font-size: 14px; }
.frame {
  background: #fff;
  padding: 10px;
  border-radius: 18px;
  box-shadow: 0 6px 0 rgba(18,60,160,.28);
}
#pic { display: block; width: 100%; border-radius: 6px; }
.res-side { display: flex; flex-direction: column; gap: 16px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px 6px; text-align: center; }
.stat small { display: block; font-size: 11px; color: #4a5c8f; }
.stat b { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat.total { grid-column: 1 / -1; border-bottom: 2px dashed #d7e6ff; padding-bottom: 8px; }
.stat.total b { font-size: 40px; color: var(--blue); line-height: 1.1; }
.actions { display: flex; flex-direction: column; gap: 12px; }
@media (min-width: 900px) {
  .res-wrap { max-width: 1040px; flex-direction: row; align-items: flex-start; gap: 32px; }
  .res-pic { flex: 1.25; }
  .res-side { flex: 1; padding-top: 86px; }
}

/* ---------- 調整 ---------- */
.offset-row { display: flex; align-items: center; justify-content: center; gap: 14px; }
.offset-val { min-width: 110px; }
.offset-val b { font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums; }
.offset-val small { display: block; font-size: 11px; color: #4a5c8f; }
#off-range { width: 100%; accent-color: var(--blue); }
#cal-msg:empty { display: none; }
#cal-msg { text-align: center; font-weight: 800; color: var(--blue-d); }

#toast {
  position: fixed; left: 50%; bottom: calc(28px + env(safe-area-inset-bottom)); z-index: 20;
  transform: translate(-50%, 20px);
  background: var(--navy); color: #fff;
  padding: 11px 20px; border-radius: 999px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
