:root {
  --paper: #F3F6FB;
  --ink: #1F2A44;
  --ink-soft: #5B6784;
  --line: #C9D2E6;
  --sun: #F7C531;
  --ok: #2FBF71;
  --ng: #F06C64;
  --accent: #3B6FE0;
  --accent-deep: #2A52B0;
  --key-black: #2A3350;
  --shadow-ink: #0F1730;
  /* 全画面表示の背景。白文字とのコントラストは test/contrast.test.mjs が検査する */
  --overlay-text: #FFFFFF;
  --overlay-ok: #17804A;
  --overlay-ng: #C4392F;
  --overlay-reveal: #1F2A44;
}

* { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  font-family: "Hiragino Maru Gothic ProN", "ヒラギノ丸ゴ ProN W4", "BIZ UDPGothic", "M PLUS Rounded 1c", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding: max(12px, env(safe-area-inset-top)) 16px max(14px, env(safe-area-inset-bottom));
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
button:focus-visible, summary:focus-visible, .key:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.noscript { padding: 16px; text-align: center; font-weight: 700; }

/* ヘッダー */
.head { display: flex; flex-direction: column; flex-shrink: 0; }
.top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.title { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
/* たのラボ（入口サイト）へ戻る */
.home { font-size: 13px; font-weight: 700; color: var(--accent-deep); text-decoration: none; white-space: nowrap;
  border: 2px solid var(--line); border-radius: 999px; padding: 3px 10px; }
h1 { font-size: 22px; margin: 0; font-weight: 800; letter-spacing: .02em; }
.scoreboard { display: flex; align-items: baseline; gap: 14px; }
.score { font-size: 15px; color: var(--ink-soft); font-weight: 700; }
.stamps { font-size: 18px; letter-spacing: 1px; min-width: 1em; }
.controls { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0 4px; flex-shrink: 0; }
.seg { display: flex; flex: 1; min-width: 220px; background: #fff; border: 2px solid var(--ink); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 999px; padding: 8px; font-weight: 700; font-size: 15px; white-space: nowrap; }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }

/* 出題エリア */
.stage { flex: 1 0 auto; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; min-height: 300px; }
.side { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 100%; }
.staff { width: min(100%, 560px); height: auto; }
.staff .staff-line { stroke: var(--ink); stroke-width: 1.8; }
.staff .clef path { fill: none; stroke: var(--ink); stroke-width: 4.2; stroke-linecap: round; stroke-linejoin: round; }
.staff .clef-dot { fill: var(--ink); }
.staff .stem { stroke: var(--ink); stroke-width: 2.6; }
.staff .notehead { fill: var(--ink); }
.status { flex-shrink: 0; min-height: 1.6em; margin: 0; font-size: 18px; text-align: center; font-weight: 700; color: var(--ink-soft); padding: 0 8px; }
.input { flex-shrink: 0; display: flex; flex-direction: column; align-items: center; gap: 10px; min-height: 132px; justify-content: center; }
.hint { margin: 0; font-size: 13px; color: var(--ink-soft); text-align: center; }


.btn { border: 2px solid var(--ink); background: #fff; border-radius: 999px; padding: 12px 24px; font-weight: 800; font-size: 17px; }
.btn:active { transform: translateY(2px); }
.btn-small { padding: 6px 14px; font-size: 13px; }
.btn.is-danger { background: var(--overlay-ng); border-color: var(--overlay-ng); color: var(--overlay-text); }
.link { background: none; border: 0; color: var(--ink-soft); text-decoration: underline; font-size: 13px; padding: 4px 0; }

/* なまえボタン（既定のこたえかた） */
.names { display: grid; grid-template-columns: repeat(4, minmax(64px, 1fr)); gap: 10px; width: min(100%, 360px); }
.names button { min-height: 60px; border: 2px solid var(--ink); border-radius: 16px; background: #fff; font-size: 22px; font-weight: 900; box-shadow: 0 4px 0 var(--ink); }
.names button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.names button.is-active { background: var(--sun); }

/* 鍵盤 */
.keys { width: min(100%, 420px); height: auto; display: block; }
.key-white { fill: #fff; stroke: var(--ink); stroke-width: 2; }
.key-black { fill: var(--key-black); stroke: var(--ink); stroke-width: 2; }
.key-white.is-active { fill: var(--sun); }
.key-black.is-active { fill: var(--accent); }
.keys.is-tappable .key { cursor: pointer; }

/* 正解・不正解の全画面表示 */
.overlay { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; flex-direction: column; gap: 10px; pointer-events: none; text-align: center; padding: 24px; z-index: 10; color: var(--overlay-text); }
.overlay.is-visible { display: flex; }
.overlay.is-correct { background: var(--overlay-ok); }
.overlay.is-wrong { background: var(--overlay-ng); }
.overlay.is-reveal { background: var(--overlay-reveal); }
.overlay-big { font-size: clamp(48px, 12vw, 96px); font-weight: 900; line-height: 1.1; animation: pop .35s cubic-bezier(.2, 1.4, .4, 1); }
.overlay-sub { font-size: clamp(22px, 5vw, 34px); font-weight: 800; }
.overlay-heard { font-size: 16px; }
@keyframes pop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.btn-big { padding: 16px 32px; font-size: 20px; }

/* フッター・記録・説明 */
.foot { flex-shrink: 0; display: flex; flex-direction: column; gap: 8px; margin-top: 8px; font-size: 13px; color: var(--ink-soft); }
.foot-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.panel { background: #fff; border: 2px solid var(--line); border-radius: 16px; padding: 12px 14px; font-size: 14px; color: var(--ink); }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.panel table { width: 100%; border-collapse: collapse; margin-top: 6px; }
.panel td, .panel th { padding: 5px 6px; text-align: left; border-bottom: 1px solid var(--line); font-weight: 600; }
.panel th { color: var(--ink-soft); font-weight: 700; font-size: 12px; }
.col-rate { width: 40%; }
.octave { color: var(--ink-soft); margin-left: 1px; }
.bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; min-width: 80px; }
.bar i { display: block; height: 100%; background: var(--ok); }
.note { margin: 8px 0 0; font-size: 12px; color: var(--ink-soft); }
.reset-note { margin: 6px 0 0; font-size: 12px; font-weight: 700; color: var(--overlay-ng); min-height: 1.2em; }
.info { border-top: 1px solid var(--line); padding-top: 6px; }
.info summary { cursor: pointer; font-weight: 700; }
.info ul { margin: 6px 0 4px; padding-left: 18px; line-height: 1.6; }
.policy h3 { margin: 12px 0 2px; font-size: 13px; color: var(--ink); }
.policy .policy-meta { margin: 8px 0 0; font-size: 12px; color: var(--ink-soft); }
.policy a { color: var(--accent-deep); }
.policy-company { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 6px 0 4px; font-size: 13px; line-height: 1.6; }
.policy-company dt { color: var(--ink-soft); font-weight: 700; }
.policy-company dd { margin: 0; }

/* iPhone 横向き：左に楽譜、右にこたえ */
@media (orientation: landscape) and (max-height: 500px) {
  body { padding: 8px max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left)); }
  .head { flex-direction: row; align-items: center; gap: 12px; }
  .top { flex: 0 0 auto; }
  .controls { margin: 0; flex: 1; }
  .seg { min-width: 0; }
  .seg button { padding: 6px; font-size: 14px; }
  .stage { flex-direction: row; min-height: 0; gap: 16px; }
  .staff { width: 52%; max-width: none; }
  .side { width: 48%; }
  .input { min-height: 0; }
  .keys { width: 100%; }
  .names { grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; width: 100%; }
  .names button { min-height: 48px; font-size: 18px; }
  .foot { margin-top: 2px; }
}

@media (prefers-reduced-motion: reduce) {
  .overlay-big { animation: none; }
}
