:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #16202b;
  --ink2: #4b5b6c;
  --ink3: #8593a3;
  --line: #dde3ea;
  --line2: #eef1f5;
  --accent: #1f3f74;
  --accent2: #2f62b3;
  --accent-soft: #e8eef8;
  --good: #1a7a4f;
  --good-soft: #e3f3ea;
  --bad: #b23a32;
  --bad-soft: #fbe9e7;
  --live: #c98a12;
  --wkey: #ffffff;
  --bkey: #1d232b;
  --wood: #6b4a2f;
  --wood2: #5a3c25;
  --shadow: 0 1px 2px rgba(20, 32, 44, .06), 0 6px 20px rgba(20, 32, 44, .06);
  --sans: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161c; --card: #1a2129; --ink: #e8edf2; --ink2: #a9b6c4; --ink3: #74828f;
    --line: #2c3540; --line2: #222a33; --accent: #8fb3ef; --accent2: #8fb3ef; --accent-soft: #1f2c40;
    --good: #5cc58f; --good-soft: #17372a; --bad: #ef7f73; --bad-soft: #3e1f1c; --live: #e8b04a;
    --wkey: #e9ecef; --bkey: #0b0e12; --wood: #4a3523; --wood2: #3d2b1c;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font-family: var(--sans); -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
button, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.screen { height: 100dvh; display: flex; flex-direction: column; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }

/* ---------- 共通 ---------- */
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 12px 16px; font-weight: 700; cursor: pointer; box-shadow: var(--shadow); touch-action: manipulation; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0e1622; } }
.btn.small { padding: 7px 12px; font-size: 14px; }
.btn.wide { width: 100%; margin-top: 14px; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow); }
.meter { flex: 1; height: 8px; background: var(--line2); border-radius: 99px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--good); transform-origin: left; transform: scaleX(0); transition: transform .06s linear; }
.seg { display: inline-flex; background: var(--line2); border-radius: 12px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 8px 14px; border-radius: 9px; font-weight: 700; color: var(--ink2); cursor: pointer; }
.seg button.on { background: var(--card); color: var(--accent); box-shadow: var(--shadow); }

/* ---------- ホーム ---------- */
.hhead { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; padding: 14px 16px 10px; }
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.brand b { font-size: 24px; font-weight: 900; letter-spacing: .02em; display: block; line-height: 1.1; }
.brand span { font-size: 12px; color: var(--ink2); }
.hbody { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 340px; gap: 16px; padding: 4px 16px 16px; }
.steps { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); grid-auto-rows: 1fr; gap: 12px; overflow: auto; align-content: start; }
.step { text-align: left; display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto 1fr auto; gap: 2px 12px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; box-shadow: var(--shadow); cursor: pointer; min-height: 120px; }
.step:hover { border-color: var(--accent2); }
.step .sn { grid-row: 1 / 4; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 900; font-size: 18px; }
.step .st { font-weight: 900; font-size: 18px; }
.step .st em { font-style: normal; font-size: 11px; background: var(--live); color: #fff; border-radius: 6px; padding: 1px 6px; margin-left: 6px; vertical-align: 3px; }
.step .sd { font-size: 13px; color: var(--ink2); line-height: 1.5; }
.step .sd small { color: var(--ink3); }
.step .sb { font-size: 13px; font-weight: 700; color: var(--ink2); display: flex; align-items: center; gap: 6px; }
.step .sb i { font-style: normal; color: var(--ink3); font-weight: 500; }
.r { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; color: #fff; font-size: 13px; }
.r-S { background: #b8860b; } .r-A { background: var(--good); } .r-B { background: var(--accent2); } .r-C { background: var(--ink3); }
.side { display: flex; flex-direction: column; gap: 12px; overflow: auto; }
details summary { font-weight: 900; cursor: pointer; padding: 2px 0; }
.form { display: grid; gap: 8px; margin-top: 12px; }
.form label { display: grid; grid-template-columns: 7.5em 1fr; align-items: center; gap: 8px; font-size: 14px; color: var(--ink2); }
.form label.off { display: none; }
.form select { width: 100%; padding: 8px; border-radius: 9px; border: 1px solid var(--line); background: var(--card); }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper button { width: 40px; height: 36px; border-radius: 9px; border: 1px solid var(--line); background: var(--card); font-size: 18px; font-weight: 700; cursor: pointer; }
.stepper b { min-width: 2.2em; text-align: center; font-size: 20px; color: var(--ink); }
.mictest .mtop { display: flex; justify-content: space-between; align-items: center; }
.mt-row { display: flex; align-items: center; gap: 12px; margin: 12px 0 6px; }
.mt-note { font-size: 26px; font-weight: 900; min-width: 5.5em; color: var(--accent); }
.note { font-size: 12px; color: var(--ink3); margin: 6px 0 0; line-height: 1.5; }
@media (max-width: 820px) {
  .hbody { grid-template-columns: 1fr; }
  .steps { grid-template-columns: 1fr 1fr; overflow: visible; }
  .step { min-height: 0; grid-template-columns: 1fr; grid-template-rows: auto; padding: 12px; }
  .step .sn { grid-row: auto; width: 28px; height: 28px; font-size: 14px; }
  .step .st { font-size: 16px; }
}

/* ---------- プレイ ---------- */
.pbar { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--card); }
.icon { border: 0; background: transparent; padding: 8px; border-radius: 10px; cursor: pointer; color: var(--ink2); }
.pstat { flex: 1; text-align: center; line-height: 1.1; }
.pstat .k { display: block; font-size: 11px; color: var(--ink3); }
.pstat b { font-size: 20px; font-variant-numeric: tabular-nums; }
.pstat.big b { font-size: 26px; color: var(--accent); }
.limit { height: 6px; background: var(--line2); }
.limit i { display: block; height: 100%; background: var(--accent2); transform-origin: left; }
.limit.low i { background: var(--bad); }
.staffBox { flex: 1.25; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 6px 12px; }
.staff { width: 100%; height: 100%; color: var(--ink); }
.staff .sl { color: var(--ink2); }
.cur-band { fill: var(--accent-soft); }
.note.n-cur { color: var(--accent); }
.note.n-ok, .nlabel.n-ok { color: var(--good); fill: var(--good); }
.note.n-late, .nlabel.n-late { color: var(--live); fill: var(--live); }
.note.n-miss, .nlabel.n-miss { color: var(--bad); fill: var(--bad); }
.nlabel { font-size: 15px; font-weight: 900; fill: var(--accent); }
.ghost { color: var(--bad); opacity: .85; }
.fb { display: flex; align-items: center; gap: 12px; padding: 4px 16px 8px; }
.msg { flex: 1; font-size: 18px; font-weight: 900; min-height: 1.4em; color: var(--ink2); }
.msg.good { color: var(--good); } .msg.bad { color: var(--bad); }
.live { display: flex; align-items: center; gap: 8px; width: 170px; font-size: 13px; color: var(--ink3); }
.live span { min-width: 3.2em; font-weight: 700; color: var(--live); text-align: right; }
.illus { flex: 1; min-height: 0; max-height: 34dvh; display: flex; align-items: center; justify-content: center; padding: 0 10px; }
.illus svg { width: 100%; height: 100%; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.wk { fill: var(--wkey); stroke: var(--ink3); stroke-width: 1; cursor: pointer; }
.bk { fill: var(--bkey); stroke: var(--bkey); cursor: pointer; }
.k-target { fill: var(--accent2); }
.k-held { fill: var(--good); }
.k-wrong { fill: var(--bad); }
.k-live { fill: var(--live); }
.ck { font-size: 10px; fill: var(--ink3); pointer-events: none; }
.mid-c { fill: var(--ink3); }
.klabel { font-size: 15px; font-weight: 900; }
.kl-target { fill: var(--accent2); } .kl-held { fill: var(--good); } .kl-wrong { fill: var(--bad); } .kl-live { fill: var(--live); }
.fb rect, .fb2 { }
.guitar .fb { fill: var(--wood); }
.guitar .inlay { fill: #e9dcc4; opacity: .7; }
.guitar .fret { stroke: #c9ccd1; stroke-width: 2.4; }
.guitar .nut { stroke: #f1ece1; stroke-width: 6; }
.guitar .str { stroke: #d8d2c4; }
.guitar .sn, .guitar .fn { font-size: 12px; fill: var(--ink3); font-weight: 700; }
.guitar .hit { cursor: pointer; }
.fm circle { stroke: #fff; stroke-width: 1.5; }
.fm text { font-size: 8.5px; font-weight: 900; fill: #fff; }
.fm-target circle { fill: var(--accent2); } .fm-held circle { fill: var(--good); } .fm-wrong circle { fill: var(--bad); } .fm-live circle { fill: var(--live); }
.ctrls { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 10px 12px 12px; }
.ctrls .btn { padding: 12px 6px; font-size: 14px; }
.ghostbtn { color: var(--ink2); }
@media (max-width: 520px) {
  .live { width: 120px; }
  .msg { font-size: 15px; }
  .illus.is-guitar { max-height: 22dvh; }
}

/* ---------- 結果 ---------- */
.rwrap { margin: auto; width: 100%; padding: 20px 16px; display: grid; grid-template-columns: auto 1fr; gap: 18px 28px; align-items: center; max-width: 980px; }
.rank { width: 150px; height: 150px; border-radius: 32px; display: grid; place-items: center; font-size: 96px; font-weight: 900; color: #fff; }
.rk { font-size: 14px; color: var(--ink2); font-weight: 700; }
.rtime { font-size: clamp(56px, 10vw, 104px); font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.rtime small { font-size: .35em; margin-left: 4px; color: var(--ink2); }
.rbest { margin-top: 6px; font-weight: 700; color: var(--good); }
.rstats { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); }
.stat .k { display: block; font-size: 12px; color: var(--ink2); }
.stat b { font-size: 26px; font-variant-numeric: tabular-nums; }
.weak { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.weak span { font-size: 13px; color: var(--ink2); margin-right: 4px; }
.weak b { background: var(--bad-soft); color: var(--bad); padding: 4px 10px; border-radius: 99px; }
.weak b small { font-weight: 500; margin-left: 3px; }
.ractions { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.ractions .btn { padding: 16px; font-size: 16px; }
@media (max-width: 620px) {
  .rwrap { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .rank { width: 110px; height: 110px; font-size: 70px; }
  .rstats { grid-template-columns: repeat(2, 1fr); width: 100%; }
  .rstats .stat:last-child { grid-column: 1 / -1; }
  .ractions { grid-template-columns: 1fr; width: 100%; }
  .weak { justify-content: center; }
}

/* アプリの広告（下のバナー）の分だけ画面を上げる */
body.has-ad .screen { padding-bottom: calc(env(safe-area-inset-bottom) + 62px); }
@media (min-width: 728px) { body.has-ad .screen { padding-bottom: calc(env(safe-area-inset-bottom) + 96px); } }

/* タブレット・PC の大きい画面では文字とボタンを大きく */
@media (min-width: 900px) and (min-height: 820px) {
  .pbar { padding: 12px 20px; }
  .pstat .k { font-size: 14px; }
  .pstat b { font-size: 28px; }
  .pstat.big b { font-size: 36px; }
  .msg { font-size: 26px; }
  .live { width: 260px; font-size: 16px; }
  .ctrls { gap: 14px; padding: 14px 20px 20px; }
  .ctrls .btn { font-size: 19px; padding: 18px 8px; }
  .step .st { font-size: 22px; }
  .step .sd { font-size: 15px; }
  .step .sb { font-size: 15px; }
  .brand b { font-size: 30px; }
  .seg button { font-size: 17px; padding: 10px 18px; }
}

/* ---------- 設定画面（10/24 作り直し） ---------- */
#home, #result { overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
#home .hbody { flex: none; }
#home .hbody { grid-template-columns: 1fr 1fr; align-items: start; }
#home .col { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.panel h3 { margin: 0 0 10px; font-size: 16px; font-weight: 900; }
.panel h3 small { font-size: 12px; font-weight: 500; color: var(--ink3); margin-left: 8px; }
.segrow { display: flex; flex-wrap: wrap; gap: 8px; }
#home .steps { display: flex; flex-direction: column; gap: 6px; overflow: visible; }
#home .step { display: grid; grid-template-columns: 30px 1fr auto; grid-template-rows: auto; align-items: center; gap: 10px; min-height: 0; padding: 10px 12px; border-radius: 12px; box-shadow: none; }
#home .step .sn { grid-row: auto; width: 28px; height: 28px; font-size: 14px; }
#home .step .st { font-size: 15px; }
#home .step .st small { display: block; font-size: 12px; font-weight: 500; color: var(--ink3); }
.dsum { margin: 0 0 8px; font-size: 14px; color: var(--ink2); }
.dsum b { font-size: 26px; color: var(--accent); }
.dsum span { display: block; font-size: 12px; color: var(--ink3); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 4px; }
.chip { display: inline-flex; flex-direction: column; align-items: center; padding: 4px 9px; border-radius: 10px; background: var(--line2); font-weight: 900; font-size: 14px; }
.chip i { font-style: normal; font-size: 8px; letter-spacing: 1px; color: var(--accent2); }
.chip.done { background: var(--good-soft); color: var(--good); }
.chip.done i { color: var(--good); }
.drow { display: flex; gap: 8px; margin-top: 12px; }
.drow .btn { flex: 1; }
.links { text-align: center; }
.links a { color: var(--ink2); }
@media (max-width: 820px) { #home .hbody { grid-template-columns: 1fr; } }

/* ---------- 練習画面: モード名・特訓の進み具合・スタートの幕 ---------- */
.mode { text-align: center; font-size: 12px; font-weight: 700; color: var(--ink3); padding: 6px 0 0; letter-spacing: .04em; }
.dbar { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; padding: 8px 12px 0; }
.dchip { position: relative; min-width: 40px; padding: 4px 8px 7px; border-radius: 9px; background: var(--card); border: 1px solid var(--line); text-align: center; overflow: hidden; }
.dchip b { font-size: 13px; }
.dchip i { position: absolute; left: 0; bottom: 0; height: 3px; width: 100%; background: var(--accent2); transform-origin: left; transform: scaleX(var(--p)); }
.dchip.cur { border-color: var(--accent2); background: var(--accent-soft); }
.dchip.done { color: var(--good); }
.dchip.done i { background: var(--good); }
#play { position: relative; }
.startov { position: absolute; inset: auto 16px 90px 16px; height: 36%; border: 0; border-radius: 20px; background: color-mix(in srgb, var(--accent) 94%, transparent); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; cursor: pointer; font: inherit; box-shadow: var(--shadow); }
.startov b { font-size: 26px; font-weight: 900; }
.startov span { font-size: 14px; opacity: .85; }
@media (prefers-color-scheme: dark) { .startov { color: #0e1622; } }
.chip sup,.dchip sup{font-size:.6em;margin-left:1px}

/* ---------- 正解の ○・まちがいの × ---------- */
.judge { position: fixed; inset: 0; display: grid; place-items: center; pointer-events: none; z-index: 20; opacity: 0; }
.judge svg { grid-area: 1 / 1; width: min(78vw, 64vh); height: min(78vw, 64vh); display: none; fill: none; stroke-linecap: round; }
.judge.ok .j-ok { display: block; stroke: var(--good); stroke-width: 11; }
.judge.ng .j-ng { display: block; stroke: var(--bad); stroke-width: 9; width: min(46vw, 38vh); height: min(46vw, 38vh); }
.judge.on { animation: judge-in .95s ease-out forwards; }
.judge.ng.on { animation-duration: .6s; }
@keyframes judge-in {
  0% { opacity: 0; transform: scale(.55); }
  18% { opacity: .92; transform: scale(1.04); }
  30% { transform: scale(1); }
  75% { opacity: .92; }
  100% { opacity: 0; transform: scale(1); }
}
.staffBox { flex: 1.6; }
.voc textarea { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px; font: inherit; font-size: 16px; background: var(--bg); color: var(--ink); resize: vertical; }
.voc .btn.wide { margin-top: 8px; }

/* ドの位置のヒント */
.wk.k-c { fill: var(--accent-soft); }
.ck { font-size: 13px; font-weight: 900; fill: var(--accent2); }
.fm-c circle { fill: var(--accent-soft); stroke: var(--accent2); stroke-width: 1; }
.fm-c text { fill: var(--accent2); font-size: 9px; font-weight: 900; }
#bInput.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent2); }
.hint-c { color: var(--accent2); opacity: .75; }
.hint-c text { fill: var(--accent2); font-size: 12px; font-weight: 900; }

/* 待機モード: 数字と答えのボタンは隠し、下に「練習スタート」 */
#bStart { display: none; }
#play.idle #bStart { display: block; font-size: 18px; }
#play.idle #bAnswer, #play.idle #bListen, #play.idle #bSkip { display: none; }
#play.idle .pstat { visibility: hidden; }
#play.idle .ctrls { grid-template-columns: 1fr 1.6fr; }
#play.idle #bInput { white-space: nowrap; }
