:root {
  --bg: #f5f5f4;
  --surface: #ffffff;
  --text: #1c1917;
  --muted: #78716c;
  --border: #d6d3d1;
  --accent: #b45309;
  --accent-text: #ffffff;
  --beat: #e7e5e4;
  --beat-on: #f59e0b;
  --beat-strong: #b45309;
  --danger: #b91c1c;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1917;
    --surface: #292524;
    --text: #f5f5f4;
    --muted: #a8a29e;
    --border: #44403c;
    --accent: #f59e0b;
    --accent-text: #1c1917;
    --beat: #44403c;
    --beat-on: #fbbf24;
    --beat-strong: #f59e0b;
    --danger: #f87171;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}

.app-header {
  display: flex;
  align-items: center;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: linear-gradient(135deg, #26213b, #0e0c17);
  color: #fef3c7;
}
.brand { display: flex; align-items: flex-end; gap: 12px; margin: 0; }
.brand-logo { height: 52px; width: auto; display: block; }
.brand-sub { font-size: 12px; font-weight: 600; letter-spacing: 0.12em; color: #fbbf24; opacity: 0.85; }

main { position: relative; max-width: 560px; margin: 0 auto; padding: 16px; }

.panel { display: none; }
.panel.active { display: block; }

h2 { font-size: 16px; margin: 24px 0 8px; }
h2:first-child { margin-top: 0; }

.note { font-size: 13px; color: var(--muted); line-height: 1.6; }
.coming-soon { text-align: center; color: var(--muted); padding: 48px 0; }

/* ボタン */
.btn {
  font: inherit;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.big { flex: 1; font-size: 18px; padding: 16px; }
.btn.small { font-size: 13px; padding: 6px 12px; }

.round-btn {
  width: 56px; height: 56px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 28px;
  cursor: pointer;
}

.row { display: flex; gap: 12px; align-items: center; margin: 16px 0; flex-wrap: wrap; }

select, input[type="text"] {
  font: inherit;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
select.full { width: 100%; }
label { display: flex; gap: 8px; align-items: center; }
label.checkbox { font-size: 15px; }

/* メトロノーム */
.bpm-display {
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: center;
  margin: 8px 0 16px;
}
.bpm-value { font-size: 72px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.bpm-label { font-size: 14px; color: var(--muted); }
.bpm-slider { width: 100%; accent-color: var(--accent); }

.beat-dots { display: flex; justify-content: center; gap: 12px; margin: 24px 0; min-height: 28px; }
.beat-dot {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--beat);
  transition: background 0.05s;
}
.beat-dot.on { background: var(--beat-on); }
.beat-dot.on.strong { background: var(--beat-strong); transform: scale(1.15); }

/* 音階 */
.key-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.key-btn {
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  padding: 10px 0;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.key-btn.selected { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

.scale-view {
  margin: 16px 0;
  padding: 12px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.scale-title { font-size: 18px; font-weight: 700; }
.scale-start { font-size: 13px; color: var(--muted); margin: 4px 0 12px; }
.note-chips { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font: inherit;
  min-width: 40px;
  padding: 8px;
  border: none;
  border-radius: 8px;
  background: var(--beat);
  color: var(--text);
  text-align: center;
  font-size: 15px;
  cursor: pointer;
}
.chip.playing { background: var(--beat-on); color: #1c1917; font-weight: 700; }

.tempo-row { display: flex; align-items: center; justify-content: space-between; }
.tempo-value { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.round-btn.small { width: 44px; height: 44px; font-size: 22px; }

.options { display: flex; flex-direction: column; gap: 10px; margin: 16px 0; }
.full-width { width: 100%; }


/* 下のタブ */
.tab-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1;
  font: inherit;
  font-size: 11px;
  padding: 14px 2px;
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.tab.active { color: var(--accent); font-weight: 700; }

/* チューナー */
:root { --good: #15803d; --warn: #b45309; --bad: #b91c1c; }
@media (prefers-color-scheme: dark) {
  :root { --good: #4ade80; --warn: #fbbf24; --bad: #f87171; }
}

.tuner-display {
  text-align: center;
  padding: 24px 16px 16px;
  margin-bottom: 16px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  --state: var(--muted);
}
.tuner-display.good { --state: var(--good); }
.tuner-display.warn { --state: var(--warn); }
.tuner-display.bad { --state: var(--bad); }

.tuner-note { font-size: 80px; font-weight: 700; line-height: 1; color: var(--state); }
.tuner-octave { font-size: 28px; margin-left: 4px; }
.tuner-freq { font-size: 14px; color: var(--muted); margin: 8px 0 20px; font-variant-numeric: tabular-nums; }

.tuner-meter {
  position: relative;
  height: 48px;
  margin: 0 12px;
  border-bottom: 2px solid var(--border);
}
.meter-tick {
  position: absolute;
  bottom: 0;
  width: 2px;
  height: 12px;
  margin-left: -1px;
  background: var(--border);
}
.meter-tick.center { height: 24px; background: var(--good); }
.meter-needle {
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 4px;
  height: 44px;
  margin-left: -2px;
  border-radius: 2px;
  background: var(--state);
  transition: left 0.08s linear;
}
.meter-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
}
.tuner-cents { font-size: 20px; font-weight: 700; color: var(--state); font-variant-numeric: tabular-nums; }

.error { color: var(--bad); font-size: 14px; }

/* 録音 */
.rec-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 24px 16px;
  margin-bottom: 16px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.rec-time { font-size: 48px; font-weight: 700; font-variant-numeric: tabular-nums; }
.level-meter {
  width: 100%;
  height: 8px;
  border-radius: 4px;
  background: var(--beat);
  overflow: hidden;
}
.level-bar { width: 0%; height: 100%; background: var(--good); transition: width 0.05s linear; }
.rec-button {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 4px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.rec-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #dc2626;
  transition: all 0.15s;
}
.rec-button.recording .rec-icon { width: 28px; height: 28px; border-radius: 6px; }
.rec-status { font-size: 13px; color: var(--muted); }

.rec-item {
  padding: 12px;
  margin-bottom: 10px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.rec-head { display: flex; justify-content: space-between; margin-bottom: 8px; }
.rec-title { font-weight: 600; }
.rec-dur { color: var(--muted); font-variant-numeric: tabular-nums; }
.rec-item audio { width: 100%; }
.rec-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.rec-actions a { text-decoration: none; }

.tab.recording .tab-icon::after { content: ""; position: absolute; top: 2px; right: 10px; width: 8px; height: 8px; border-radius: 50%; background: #dc2626; }

/* 書の透かし（画面の右下にうっすら） */
body::before {
  content: "";
  position: fixed;
  right: -6vmin;
  bottom: calc(40px + env(safe-area-inset-bottom));
  width: min(80vmin, 520px);
  aspect-ratio: 1629 / 1505;
  background: url("icons/watermark-light.png") no-repeat center / contain;
  opacity: 0.06;
  pointer-events: none;
  z-index: 0;
}
@media (prefers-color-scheme: dark) {
  body::before { background-image: url("icons/watermark-dark.png"); opacity: 0.07; }
}
.app-header, main { position: relative; z-index: 1; }
.tab-bar { z-index: 2; }

/* チューナーの感度 */
.sensitivity-row { display: flex; align-items: center; gap: 12px; }
.sensitivity-row .note { margin: 0; white-space: nowrap; }
.input-meter {
  position: relative;
  height: 10px;
  margin: 12px 0 4px;
  border-radius: 5px;
  background: var(--beat);
}
.input-meter .level-bar { border-radius: 5px; }
.level-mark {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 2px;
  margin-left: -1px;
  background: var(--text);
}

/* iPhone で、すばやく2回タップしたときに画面が拡大されないようにする（指2本の拡大はそのまま使える） */
html { touch-action: manipulation; }
button, .tab, .chip, .key-btn {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* ホーム画面に追加の案内 */
.install-banner {
  position: relative;
  padding: 14px 40px 14px 14px;
  margin-bottom: 16px;
  border-radius: 12px;
  background: var(--surface);
  border: 2px solid var(--accent);
  font-size: 14px;
  line-height: 1.6;
}
.install-title { font-weight: 700; margin-bottom: 4px; }
.install-body ol { margin: 4px 0 0; padding-left: 20px; }
.install-banner .btn { margin-top: 10px; }
.install-close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
}

/* メトロノームのリズム */
.rhythm-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 4px 0 16px; }
.rhythm-btn {
  font: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 4px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.rhythm-btn.selected { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.rhythm-icon { width: 56px; height: 38px; }
.rhythm-name { font-size: 11px; line-height: 1.3; text-align: center; white-space: pre-line; }

/* 音・光のオン・オフ */
.toggle {
  font: inherit;
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}
.toggle::after { content: " オフ"; }
.toggle[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.toggle[aria-pressed="true"]::after { content: " オン"; }

/* 大きな表示（明るい・暗いの設定に関係なく、いつも暗い背景） */
.big-view {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  background: #0e0c17;
  color: #fef3c7;
  overflow: hidden;
}
.big-view[hidden] { display: none; }
.big-view > :not(.big-flash) { position: relative; z-index: 1; }
.big-flash { position: absolute; inset: 0; opacity: 0; pointer-events: none; }
.big-flash.flash { background: #fef3c7; animation: big-flash 0.3s ease-out forwards; --peak: 0.28; }
.big-flash.flash-strong { background: #f59e0b; animation: big-flash 0.3s ease-out forwards; --peak: 0.7; }
@keyframes big-flash {
  from { opacity: var(--peak); }
  to { opacity: 0; }
}
.big-close {
  position: absolute !important;
  top: calc(8px + env(safe-area-inset-top));
  right: 8px;
  width: 48px;
  height: 48px;
  border: none;
  background: none;
  color: #a8a29e;
  font-size: 32px;
  cursor: pointer;
}
.big-beat {
  font-size: min(60vw, 42vh);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.big-beat.strong { color: #ffffff; }
.big-dots { display: flex; gap: 14px; }
.big-dots .beat-dot { width: 22px; height: 22px; background: #2c2840; }
.big-dots .beat-dot.on { background: #fef3c7; }
.big-dots .beat-dot.on.strong { background: #f59e0b; }
.big-info { font-size: 24px; color: #d6cfc0; font-variant-numeric: tabular-nums; }
.big-info span { font-size: 40px; font-weight: 700; color: #fef3c7; }
.big-controls { display: flex; align-items: center; gap: 20px; }
.big-round {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 1px solid #44403c;
  background: #1c1a28;
  color: #fef3c7;
  font-size: 30px;
  cursor: pointer;
}
.big-start {
  font: inherit;
  font-size: 22px;
  font-weight: 700;
  min-width: 140px;
  padding: 18px 24px;
  border-radius: 14px;
  border: none;
  background: #f59e0b;
  color: #1c1917;
  cursor: pointer;
}
.big-toggles { display: flex; gap: 12px; }
.big-toggles .toggle { background: #1c1a28; border-color: #44403c; color: #a8a29e; }
.big-toggles .toggle[aria-pressed="true"] { background: #f59e0b; border-color: #f59e0b; color: #1c1917; }

/* みんなで合わせる */
.sync-card {
  margin: 24px 0 8px;
  padding: 14px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.sync-card h2 { margin-top: 0; }
.sync-join { display: flex; gap: 8px; margin-top: 10px; }
.code-input {
  flex: 1;
  min-width: 0;
  font-size: 20px;
  letter-spacing: 0.2em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.note.invited { color: var(--accent); font-weight: 700; }
.sync-room { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sync-code { font-size: 28px; letter-spacing: 0.12em; font-variant-numeric: tabular-nums; }
.sync-qr { margin: 10px 0; text-align: center; }
.qr-image { display: inline-block; padding: 8px; border-radius: 10px; background: #ffffff; line-height: 0; }
.qr-image svg { width: 200px; height: 200px; }
.sync-me { margin: 10px 0 6px; }
.sync-members { display: flex; flex-wrap: wrap; gap: 6px; }
.member { padding: 4px 10px; border-radius: 999px; background: var(--beat); font-size: 14px; }
.member.me { background: var(--accent); color: var(--accent-text); font-weight: 700; }
.sync-message { min-height: 1.6em; margin: 10px 0; font-size: 15px; font-weight: 600; }
.sync-message.fresh { animation: sync-fresh 1.5s ease-out; }
@keyframes sync-fresh {
  from { color: var(--accent); transform: scale(1.04); }
  to { color: var(--text); transform: scale(1); }
}
.sync-offset { flex-direction: column; align-items: stretch; gap: 4px; font-size: 14px; margin-top: 8px; }

/* 大きな表示の部屋の情報 */
.big-room {
  position: absolute !important;
  top: calc(16px + env(safe-area-inset-top));
  left: 16px;
  right: 64px;
  font-size: 14px;
  line-height: 1.6;
  color: #d6cfc0;
  white-space: pre-line;
}

/* 録音の再生プレーヤー */
.player {
  margin: 16px 0;
  padding: 16px;
  border-radius: 16px;
  background: var(--surface);
  border: 2px solid var(--accent);
}
.player-title { font-size: 17px; font-weight: 700; margin-bottom: 8px; overflow-wrap: anywhere; }
.seek-wrap { position: relative; }
.player-seek { position: relative; z-index: 1; margin: 6px 0; }
.loop-region {
  position: absolute;
  top: 50%;
  height: 14px;
  margin-top: -7px;
  border-radius: 4px;
  background: var(--accent);
  opacity: 0.3;
}
.loop-region.pending { opacity: 0.15; }
.player-times { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.player-controls { display: flex; align-items: center; justify-content: center; gap: 24px; margin: 12px 0 16px; }
.skip-btn { font-size: 14px; font-weight: 600; }
.player-play {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--accent-text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.player-play svg { width: 40px; height: 40px; }
.player-row { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.player-label { width: 64px; font-size: 14px; color: var(--muted); flex-shrink: 0; }
.seg { display: flex; flex: 1; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg button {
  flex: 1;
  font: inherit;
  font-size: 14px;
  padding: 9px 4px;
  border: none;
  border-left: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.seg button:first-child { border-left: none; }
.seg button.selected { background: var(--accent); color: var(--accent-text); font-weight: 700; }

/* 録音の一覧 */
.list-head { display: flex; align-items: center; justify-content: space-between; margin: 24px 0 10px; }
.list-head h2 { margin: 0; }
.rec-item.selected { border-color: var(--accent); }
.rec-main {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  padding: 0;
  border: none;
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.rec-main .rec-title { overflow-wrap: anywhere; }
.rec-meta { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* 録音の名前の書き換え */
.rename-form { display: flex; flex-direction: column; gap: 8px; }
.rename-input { width: 100%; font-size: 16px; } /* 16px 未満だと iPhone が自動で拡大するため */

/* hidden を付けた要素は、display の指定があっても必ず隠す */
[hidden] { display: none !important; }

/* 新しい版のお知らせ */
.update-banner {
  position: relative;
  z-index: 3;
  padding: 10px 16px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
}
.update-banner.done { background: var(--good); color: #ffffff; }

/* 下のタブのアイコン */
:root { --accent-soft: rgba(180, 83, 9, 0.14); }
@media (prefers-color-scheme: dark) {
  :root { --accent-soft: rgba(245, 158, 11, 0.2); }
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 2px 10px;
  font-size: 10.5px;
}
.tab-icon {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 54px;
  height: 30px;
  border-radius: 15px;
  transition: background 0.2s;
}
.tab-icon svg { width: 24px; height: 24px; }
.tab-icon .line { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab-icon .beam { fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; }
.tab-icon .dot { fill: currentColor; }
.tab.active .tab-icon { background: var(--accent-soft); }
.tab.active .tab-icon svg { animation: tab-pop 0.35s ease-out; }
@keyframes tab-pop {
  0% { transform: scale(0.8); }
  60% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

/* iPhone のホーム画面アプリでは、中身が短い画面で表示範囲が短く計算され、
   下のタブの下にすき間ができることがある。タブの背景を下に伸ばして、すき間を隠す */
.tab-bar::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  height: 120px;
  background: var(--surface);
}

/* 基準音 */
.drone-card {
  margin: 20px 0;
  padding: 14px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.drone-card h2 { margin-top: 0; }
.drone-main { display: flex; align-items: center; gap: 10px; }
.drone-note { flex: 1; text-align: center; }
.drone-name { font-size: 34px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.drone-freq { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.drone-toggle { min-width: 84px; padding: 12px 14px; font-weight: 700; }
.drone-toggle.playing { background: var(--surface); color: var(--accent); }
.drone-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.drone-row .player-label { width: auto; }
.drone-row .seg { flex: 1; }
.drone-quick { flex: 0 0 110px !important; }
.drone-oct { flex: 0 0 96px !important; }
.drone-row input[type="range"] { flex: 1; }
.round-btn:disabled, .seg button:disabled { opacity: 0.35; cursor: default; }

/* チューナー画面：上下の区切り */
.tool-section {
  margin-bottom: 16px;
  padding: 14px;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.section-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.section-head h2 { margin: 0; font-size: 18px; }
.section-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
}
.section-icon svg { width: 22px; height: 22px; }
.section-icon .line { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.section-icon .dot { fill: currentColor; }
.tool-section .tuner-display { margin-bottom: 12px; border: none; background: var(--bg); }
.tool-section .sensitivity-row { margin-top: 14px; }
.sub-label { font-size: 14px; font-weight: 700; white-space: nowrap; }
.small-note { font-size: 12px; margin: 6px 0 0; }
.drone-card { all: unset; } /* 以前の枠は使わない */
.common-setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px dashed var(--border);
}
.a4-control { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.a4-value { font-size: 22px; font-weight: 700; min-width: 64px; text-align: center; font-variant-numeric: tabular-nums; }
.a4-value small { font-size: 12px; font-weight: 400; margin-left: 2px; color: var(--muted); }
.common-setting .round-btn.small { width: 38px; height: 38px; font-size: 20px; }

/* 音階の音の長さ */
.note-length-head { font-size: 14px; font-weight: 700; margin: 16px 0 6px; }
.note-lengths { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.note-lengths .rhythm-name { font-size: 12px; }

/* 録音しながら鳴らすボタン */
.rec-along { margin-top: 10px; display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 700; }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: #dc2626; flex-shrink: 0; }
.rec-along.recording { border-color: #dc2626; color: #dc2626; }
.rec-along.recording .rec-dot { border-radius: 2px; animation: rec-blink 1s ease-in-out infinite; }
@keyframes rec-blink { 50% { opacity: 0.3; } }

/* ===== 全体の見た目の調整（各画面をアイコン付きの枠でまとめる） ===== */
.panel > .tool-section:first-child { margin-top: 0; }
.section-icon .beam { fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; }
.section-icon .knob { fill: var(--surface); stroke: currentColor; stroke-width: 1.8; }
.section-head h2 { overflow-wrap: anywhere; }

/* 枠の中の小見出し */
.sub-head { font-size: 13px; font-weight: 700; color: var(--muted); margin: 16px 0 8px; }
.section-head + .sub-head { margin-top: 4px; }

/* 1行の設定（左に名前、右にスイッチや選択） */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
  cursor: pointer;
}
.section-head + .setting-row { border-top: none; padding-top: 4px; }
.setting-row .sub-label { font-weight: 600; white-space: normal; }
.setting-row select { min-width: 96px; }

/* オン・オフのスイッチ（チェックボックスを大きく押しやすく） */
input.switch {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  flex-shrink: 0;
  width: 50px;
  height: 30px;
  margin: 0;
  border-radius: 15px;
  background: var(--beat);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}
input.switch::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s;
}
input.switch:checked { background: var(--accent); border-color: var(--accent); }
input.switch:checked::before { transform: translateX(20px); }

/* 押して選ぶボタン（音階の種類など） */
.chip-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.chip-btn {
  font: inherit;
  font-size: 13px;
  padding: 10px 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.chip-btn.selected, .key-btn.selected { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 700; }

/* ボタンの並び */
.action-row { display: flex; gap: 10px; margin-top: 14px; }
.action-row .btn.big { flex: 1; }
.action-row.compact { align-items: center; }
.action-row.compact .btn { flex: 1; }

/* メトロノーム */
.tool-section .bpm-display { margin: 0 0 8px; }
.tool-section .beat-dots { margin: 16px 0 4px; }
.tool-section .rhythm-grid { margin: 12px 0 0; }

/* 音階 */
.tool-section #scaleTitle { font-size: 18px; }
.tool-section .scale-start { margin: 2px 0 0; }
.tool-section .note-chips { margin: 4px 0 0; }
.tool-section #scaleStartStop { margin-top: 14px; }
.tool-section .note-lengths { margin-bottom: 4px; }

/* 録音（枠の中に入れた録音ボタンは、枠を二重にしない） */
.tool-section .rec-panel { margin: 0 0 4px; padding: 8px 0 12px; border: none; background: none; }
.chip-btn { white-space: pre-line; line-height: 1.3; }
/* 音名は1段に8つ並べる（上りと下りがそれぞれ1段に収まる） */
.tool-section .chip-row { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }
.tool-section .chip { min-width: 0; padding: 8px 0; font-size: 14px; }

/* 画面を切り替えたとき、横からすっと入ってくる */
.panel.enter-right { animation: panel-in-right 0.25s ease-out; }
.panel.enter-left { animation: panel-in-left 0.25s ease-out; }
@keyframes panel-in-right {
  from { opacity: 0.3; transform: translateX(40px); }
  to { opacity: 1; transform: none; }
}
@keyframes panel-in-left {
  from { opacity: 0.3; transform: translateX(-40px); }
  to { opacity: 1; transform: none; }
}
main { overflow-x: clip; } /* 入ってくる途中の画面で、横にはみ出さないように */

/* iPhone のホーム画面アプリでは、中身が画面より短い画面（録音など）で、表示範囲が上の時計・電波表示の
   高さ分だけ短くなり、下にアプリの描けないすき間ができる。そのすき間はページ全体の背景色で塗られるので、
   ページ全体の背景をタブと同じ色にして、タブが下まで続いて見えるようにする（各画面の背景は body の色） */
html { background-color: var(--surface); overscroll-behavior-y: none; }
body { min-height: 100vh; }

/* 上のロゴの部分（ヘッダー）を、スクロールしても画面の上に固定する */
.app-header { position: sticky; top: 0; z-index: 4; }

/* 音階の解説 */
.guide-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 2px 0 10px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.guide-link svg { width: 16px; height: 16px; }
.guide-view {
  position: fixed;
  inset: 0;
  z-index: 10;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background: var(--bg);
  color: var(--text);
}
.guide-top {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.guide-top-row { display: flex; align-items: center; justify-content: space-between; }
.guide-top h2 { margin: 0; font-size: 18px; }
.guide-close { width: 44px; height: 44px; border: none; background: none; color: var(--muted); font-size: 30px; cursor: pointer; }
.guide-tabs { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0 2px; scrollbar-width: none; }
.guide-tabs::-webkit-scrollbar { display: none; }
.guide-tabs .chip-btn { flex-shrink: 0; padding: 8px 12px; white-space: nowrap; }
.guide-body {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px calc(32px + env(safe-area-inset-bottom));
  line-height: 1.75;
  font-size: 15px;
}
.guide-body h3 { font-size: 24px; margin: 4px 0 6px; }
.guide-lead { font-size: 16px; font-weight: 600; margin: 0 0 16px; }
.guide-body h4 {
  margin: 22px 0 8px;
  padding-left: 10px;
  border-left: 4px solid var(--accent);
  font-size: 16px;
}
.guide-body ul { margin: 0; padding-left: 20px; }
.guide-body li { margin-bottom: 10px; }
.guide-body b { color: var(--accent); }
.guide-facts {
  margin: 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.guide-facts dt { font-size: 13px; font-weight: 700; color: var(--muted); }
.guide-facts dd { margin: 2px 0 10px; }
.guide-facts dd:last-child { margin-bottom: 0; }
.guide-body #guidePractice { margin-top: 20px; }

/* 解説：世界の音楽院・名教師の囲み、用語メモ */
.guide-world {
  margin: 22px 0 0;
  padding: 2px 14px 6px;
  border-radius: 14px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
}
.guide-world h4 { border-left: none; padding-left: 0; display: flex; align-items: center; gap: 6px; margin-top: 14px; }
.guide-terms {
  margin-top: 22px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px dashed var(--border);
  font-size: 14px;
}
.guide-terms-head { font-weight: 700; margin-bottom: 6px; }
.guide-terms dl { margin: 0; }
.guide-terms dt { font-weight: 700; color: var(--accent); }
.guide-terms dd { margin: 0 0 8px; }
.guide-terms dd:last-child { margin-bottom: 0; }
.guide-foot { margin-top: 16px; }

/* 上の小さなメトロノームのボタン（どの画面からでも押せる） */
.mini-metro {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px 5px 6px;
  border-radius: 999px;
  border: 1px solid rgba(251, 191, 36, 0.55);
  background: rgba(255, 255, 255, 0.07);
  color: #fef3c7;
  font: inherit;
  cursor: pointer;
}
.mini-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #f59e0b;
  color: #1c1917;
}
.mini-icon svg { width: 16px; height: 16px; }
.mini-bpm { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; }
.mini-bpm small { font-size: 9px; font-weight: 600; margin-left: 2px; opacity: 0.7; }
.mini-dot { width: 7px; height: 7px; border-radius: 50%; background: rgba(254, 243, 199, 0.25); order: 3; }
.mini-dot.on { animation: mini-flash 0.25s ease-out; }
.mini-dot.on.strong { animation-name: mini-flash-strong; }
@keyframes mini-flash { from { background: #fef3c7; transform: scale(1.5); } }
@keyframes mini-flash-strong { from { background: #f59e0b; transform: scale(1.8); } }
.mini-metro.running { background: rgba(245, 158, 11, 0.2); border-color: #f59e0b; }

/* テンポの数字を押して入力 */
.tempo-edit {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-decoration: underline dotted;
  text-decoration-thickness: 2px;
  text-underline-offset: 6px;
  text-decoration-color: var(--border);
}
.tempo-input {
  font: inherit;
  width: 3.4ch;
  padding: 0;
  text-align: center;
  color: var(--text);
  background: var(--surface);
  border: 2px solid var(--accent);
  border-radius: 12px;
  outline: none;
}
.tempo-value .tempo-input { font-size: 28px; font-weight: 700; } /* 16px 以上なので iPhone が自動で拡大しない */

/* タップボタン：スタートと押し間違えないよう、小さめの丸い点線のボタンにする */
.action-row { align-items: center; }
.tap-btn {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px dashed var(--accent);
  background: var(--surface);
  color: var(--accent);
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
.tap-btn svg { width: 22px; height: 22px; }
.tap-btn:active { transform: scale(0.92); background: var(--accent-soft); }
/* 押して入力できるようにした大きなテンポの数字は、元の大きさのまま */
.bpm-value.tempo-edit, .bpm-value.tempo-input { font-size: 72px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.bpm-value.tempo-input { width: 3.2ch; }
