/* BassPocket
   レイアウト: 計器のパネル。電話は1画面に1つ（拍 → テンポ → 設定 → 再生）、
   iPad などの広い画面ではメトロノームとドローンを左右に並べる。
   色: 地は明るいアルミ（ライト）／黒いトーレックス（ダーク）。琥珀＝リズム、青緑＝音（ドローン）、緑＝チューナーの合格 */
:root {
  --bg: #e8eaed;
  --bg-glow: rgba(196, 106, 0, 0.07);
  --surface: #f6f7f9;
  --raised: #ffffff;
  --sunken: #dfe2e6;
  --ink: #14161a;
  --ink-2: #565c66;
  --ink-3: #737983;
  --line: rgba(20, 24, 32, 0.09);
  --line-2: rgba(20, 24, 32, 0.16);
  --amber: #df7a00;
  --amber-hi: #ffad3d;
  --amber-lo: #b15900;
  --amber-text: #a45000;
  --amber-ink: #ffffff;
  --amber-soft: rgba(223, 122, 0, 0.12);
  --amber-glow: rgba(223, 122, 0, 0.34);
  --teal: #00808a;
  --teal-hi: #22b3b6;
  --teal-lo: #00606a;
  --teal-ink: #ffffff;
  --teal-soft: rgba(0, 128, 138, 0.12);
  --teal-text: #006d76;
  --teal-glow: rgba(0, 128, 138, 0.32);
  --green: #12925a;
  --green-hi: #3cc082;
  --green-lo: #0b6f43;
  --green-ink: #ffffff;
  --green-soft: rgba(18, 146, 90, 0.14);
  --green-text: #0b7a4a;
  --green-glow: rgba(18, 146, 90, 0.32);
  --warn: #b86e00;
  --bad: #cf3b3b;
  --shadow: 0 1px 2px rgba(20, 24, 32, 0.06), 0 6px 18px rgba(20, 24, 32, 0.07);
  --shadow-lg: 0 12px 40px rgba(20, 24, 32, 0.18);
  --scrim: rgba(12, 14, 18, 0.32);
  --num: "DIN Condensed", "DIN Alternate", "Avenir Next Condensed", "Roboto Condensed", "Arial Narrow", sans-serif;
  --ui: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Segoe UI", system-ui, sans-serif;
  --r-s: 10px;
  --r-m: 16px;
  --r-l: 24px;
  --tabbar: 58px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0b0a;
    --bg-glow: rgba(255, 166, 50, 0.08);
    --surface: #161311;
    --raised: #1f1b18;
    --sunken: #0a0908;
    --ink: #f5efe8;
    --ink-2: #aca298;
    --ink-3: #8c8278;
    --line: rgba(255, 238, 220, 0.08);
    --line-2: rgba(255, 238, 220, 0.15);
    --amber: #ffab33;
    --amber-hi: #ffd07a;
    --amber-lo: #d97a00;
    --amber-text: #ffb547;
    --amber-ink: #1d1204;
    --amber-soft: rgba(255, 171, 51, 0.14);
    --amber-glow: rgba(255, 160, 40, 0.42);
    --teal: #45d4cc;
    --teal-hi: #9af0ea;
    --teal-lo: #13a39c;
    --teal-ink: #04201f;
    --teal-soft: rgba(69, 212, 204, 0.13);
    --teal-text: #5fe0d8;
    --teal-glow: rgba(69, 212, 204, 0.4);
    --green: #3fdc8b;
    --green-hi: #a2f5c8;
    --green-lo: #16a862;
    --green-ink: #062012;
    --green-soft: rgba(63, 220, 139, 0.14);
    --green-text: #5ae79c;
    --green-glow: rgba(63, 220, 139, 0.4);
    --warn: #ffb238;
    --bad: #ff6a5f;
    --shadow: inset 0 1px 0 rgba(255, 240, 225, 0.04), 0 8px 24px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.6);
    --scrim: rgba(0, 0, 0, 0.55);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; touch-action: manipulation; }
body {
  margin: 0;
  font: 15px/1.5 var(--ui);
  color: var(--ink);
  background: radial-gradient(120% 55% at 50% -12%, var(--bg-glow), transparent 70%), var(--bg);
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
button:focus-visible, [tabindex]:focus-visible, input:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
svg { width: 24px; height: 24px; flex: none; }
input, textarea { -webkit-user-select: text; user-select: text; }

/* ---------- 骨組み ---------- */
.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top, 0px);
}
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  flex: none;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(8px, env(safe-area-inset-right, 0px));
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-mark {
  display: grid; place-items: center;
  width: 26px; height: 26px; border-radius: 8px;
  background: linear-gradient(160deg, var(--amber-hi), var(--amber-lo));
  color: var(--amber-ink);
  box-shadow: 0 2px 8px var(--amber-glow);
}
.brand-mark svg { width: 17px; height: 17px; }
.brand-name { font: 700 23px/1 var(--num); letter-spacing: 0.04em; padding-top: 3px; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; color: var(--ink-2); }
.icon-btn:active { background: var(--line); }

.views {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 4px 10px;
}
.view { display: none; flex-direction: column; gap: 10px; max-width: 560px; margin: 0 auto; min-height: 100%; }
.app[data-tab="metronome"] #view-metronome,
.app[data-tab="drone"] #view-drone,
.app[data-tab="tuner"] #view-tuner { display: flex; }
.view > * { flex-shrink: 0; }
.view-title { display: none; }

/* ---------- 共通部品 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
  box-shadow: var(--shadow);
}
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: 0.06em; color: var(--ink-2); }
.note { margin: 0; font-size: 12.5px; line-height: 1.55; color: var(--ink-3); }
.card-head, .section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-head { margin-bottom: -4px; }

.seg {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--sunken);
  border-radius: 11px;
  border: 1px solid var(--line);
  max-width: 100%;
}
.seg button {
  flex: 1 1 auto;
  min-height: 34px;
  padding: 0 11px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-2);
  white-space: nowrap;
}
.seg button[aria-checked="true"] { background: var(--raised); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14); }
.seg-sm button { min-height: 30px; padding: 0 10px; font-size: 12.5px; }
.seg-wide { display: flex; width: 100%; margin-bottom: 4px; }
.seg-wide button { flex: 1 1 0; padding: 0 4px; font-family: var(--num); font-size: 18px; padding-top: 3px; }
.seg-wide button:first-child { font-family: var(--ui); font-size: 13.5px; padding-top: 0; }

.chip-row {
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
  margin: 0 -14px; padding: 2px 14px;
}
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  min-height: 32px;
  padding: 0 13px;
  border-radius: 17px;
  border: 1px solid var(--line-2);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  background: var(--raised);
}
.chip[aria-pressed="true"], .chip[aria-checked="true"] { background: var(--amber-soft); border-color: var(--amber); color: var(--amber-text); }

.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 28px;
  background: transparent;
  --p: 50%;
  --c: var(--amber);
}
.slider.teal { --c: var(--teal); }
.slider::-webkit-slider-runnable-track {
  height: 6px; border-radius: 3px;
  background: linear-gradient(to right, var(--c) var(--p), var(--sunken) var(--p));
  border: 1px solid var(--line);
}
.slider::-moz-range-track { height: 6px; border-radius: 3px; background: linear-gradient(to right, var(--c) var(--p), var(--sunken) var(--p)); }
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 26px; height: 26px; margin-top: -11px; border-radius: 50%;
  background: var(--raised);
  border: 1px solid var(--line-2);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.22);
}
.slider::-moz-range-thumb { width: 26px; height: 26px; border-radius: 50%; background: var(--raised); border: 1px solid var(--line-2); }

.toggle {
  min-height: 36px; padding: 0 14px; border-radius: 18px;
  border: 1px solid var(--line-2); background: var(--raised);
  font-size: 13.5px; font-weight: 600; color: var(--ink-2);
}
.toggle[aria-pressed="true"] { background: var(--teal-soft); border-color: var(--teal); color: var(--teal-text); }

.switch {
  position: relative; flex: none;
  width: 51px; height: 31px; border-radius: 16px;
  background: var(--sunken); border: 1px solid var(--line-2);
  transition: background 0.2s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 25px; height: 25px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s;
}
.switch[aria-checked="true"] { background: var(--green); border-color: transparent; }
.switch[aria-checked="true"]::after { transform: translateX(20px); }

.stepper { display: inline-flex; align-items: center; border-radius: 12px; background: var(--sunken); border: 1px solid var(--line); flex: none; }
.stepper button { width: 42px; height: 38px; display: grid; place-items: center; color: var(--ink-2); }
.stepper button svg { width: 18px; height: 18px; }
.stepper button:active { color: var(--ink); }
.stepper button:disabled { opacity: 0.3; }
.stepper output { min-width: 44px; text-align: center; font: 700 22px/1 var(--num); padding-top: 3px; font-variant-numeric: tabular-nums; }

/* ---------- メトロノーム: 拍 ---------- */
.beats { padding: 10px 12px 10px; display: flex; flex-direction: column; gap: 8px; }
.beats .card-head { min-height: 18px; padding: 0 2px; }

/* 刻み: 音符の絵と名前の5択 */
.feel-seg {
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 2px;
  padding: 3px; border-radius: 13px;
  background: var(--sunken); border: 1px solid var(--line);
}
.feel-seg button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  min-height: 46px; padding: 3px 0 2px; border-radius: 10px;
  color: var(--ink-2); min-width: 0;
}
.feel-seg svg { width: 34px; height: 24px; }
.feel-seg .fl { font-size: 11.5px; font-weight: 700; white-space: nowrap; letter-spacing: -0.02em; }
.feel-seg button[aria-checked="true"] { background: var(--raised); color: var(--amber-text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.16); }
.swing-ctl .seg { flex: none; }
.swing-ctl .seg button { min-width: 54px; min-height: 26px; }
.swing-ctl .seg { padding: 2px; }
.legend { display: flex; align-items: center; gap: 4px; font-size: 11px; color: var(--ink-2); }
.legend i { display: inline-block; width: 7px; height: 12px; border-radius: 2px; margin-left: 6px; position: relative; overflow: hidden; border: 1px solid var(--line-2); }
.legend i::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; background: var(--amber); }
.legend i[data-l="3"]::after { top: 0; }
.legend i[data-l="2"]::after { top: 35%; opacity: 0.85; }
.legend i[data-l="1"]::after { top: 65%; opacity: 0.6; }
.legend i[data-l="0"] { border-style: dashed; }

.beat-grid {
  --cols: 4;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: 10px 7px;
}
.beat { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.beat-cells { display: flex; gap: 3px; height: 56px; }
.beat-grid.two-rows .beat-cells { height: 56px; }
.cell {
  flex: var(--w, 1) 1 0;
  min-width: 0;
  position: relative;
  border-radius: 8px;
  background: var(--sunken);
  border: 1px solid var(--line);
  overflow: hidden;
  transition: box-shadow 0.06s;
}
.cell .fill {
  position: absolute; left: 3px; right: 3px; bottom: 3px;
  border-radius: 5px;
  height: calc((100% - 6px) * var(--h, 0));
  background: linear-gradient(to top, var(--amber), var(--amber-hi));
  transition: height 0.15s ease;
}
.cell[data-l="3"] .fill { --h: 1; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45); }
.cell[data-l="2"] .fill { --h: 0.62; opacity: 0.8; }
.cell[data-l="1"] .fill { --h: 0.32; opacity: 0.58; }
.cell[data-l="0"] { background: transparent; border: 1.5px dashed var(--line-2); }
.cell.sub { border-radius: 6px; }
.cell.now { box-shadow: 0 0 0 2px var(--amber), 0 0 16px var(--amber-glow); }
.cell.now .fill { filter: brightness(1.25); }
.cell[data-l="0"].now { box-shadow: 0 0 0 2px var(--line-2); }
.beat-num { text-align: center; font: 700 15px/1 var(--num); color: var(--ink-3); padding-top: 2px; font-variant-numeric: tabular-nums; }
.beat.now .beat-num { color: var(--amber-text); }
.beats.muted-bar .beat-grid { opacity: 0.4; }
.beats.muted-bar .card-head .eyebrow::after { content: "　消音中"; color: var(--amber-text); }

/* ---------- メトロノーム: テンポ ---------- */
.tempo { display: grid; justify-items: center; gap: 2px; padding-top: 2px; }
.tempo-mark {
  display: flex; gap: 10px; align-items: center; min-height: 22px;
  font-size: 12px; font-weight: 600; letter-spacing: 0.22em; text-transform: uppercase; color: var(--ink-2);
}
.bar-count { letter-spacing: 0.02em; text-transform: none; color: var(--amber-text); background: var(--amber-soft); border-radius: 10px; padding: 2px 9px; font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.bar-count:empty { display: none; }
.tempo-row { display: grid; grid-template-columns: 46px 56px minmax(0, 1fr) 56px 46px; align-items: center; width: 100%; gap: 6px; }
.step10 {
  height: 40px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line-2);
  font: 700 17px/1 var(--num); padding-top: 3px; color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
.step10:active { transform: scale(0.96); background: var(--sunken); color: var(--ink); }
.round-btn {
  width: 56px; height: 56px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--raised); border: 1px solid var(--line-2); box-shadow: var(--shadow);
  color: var(--ink);
}
.round-btn:active { transform: scale(0.96); background: var(--sunken); }
.bpm-box {
  position: relative;
  display: flex; flex-direction: column; align-items: center;
  padding: 2px 0 0;
  touch-action: none;
  cursor: ns-resize;
  border-radius: var(--r-m);
}
.bpm-num {
  font: 700 96px/0.86 var(--num);
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  padding-top: 8px;
  color: var(--ink);
}
.bpm-input {
  width: 3.4ch; text-align: center;
  font: 700 92px/1 var(--num);
  color: var(--ink); background: var(--sunken);
  border: 1px solid var(--amber); border-radius: 14px;
  padding: 6px 0 0;
}
.bpm-unit { font-size: 12px; font-weight: 700; letter-spacing: 0.16em; color: var(--ink-3); margin-top: -10px; }
.bpm-box.dragging .bpm-num { color: var(--amber-text); }

/* ---------- メトロノーム: 設定の4枠 ---------- */
.tiles {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.tile {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 6px 4px 7px;
  min-height: 52px;
  min-width: 0;
}
.tile + .tile { border-left: 1px solid var(--line); }
.tile:active { background: var(--line); }
.tile-k { font-size: 11px; font-weight: 600; letter-spacing: 0.05em; color: var(--ink-3); }
.tile-v { font-size: 16px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tile-v.num { font: 700 22px/1.1 var(--num); padding-top: 2px; }
.tile.on .tile-v { color: var(--amber-text); }

/* ---------- 再生 ---------- */
.transport {
  display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center; justify-items: center;
  gap: 12px;
  margin-top: auto;
  padding-top: 4px;
}
/* 画面が低くても再生ボタンは見えるように、下に貼りつける */
.view-metro .transport {
  position: sticky; bottom: -10px; z-index: 2;
  padding-block: 10px 10px;
  margin-bottom: -10px;
  background: linear-gradient(to bottom, transparent, var(--bg) 22%);
}
.side-btn {
  width: 76px; height: 60px; border-radius: 18px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  background: var(--raised); border: 1px solid var(--line-2); box-shadow: var(--shadow);
  color: var(--ink);
}
.side-btn:active, .side-btn.hit { transform: scale(0.96); background: var(--amber-soft); border-color: var(--amber); }
.side-big { font: 700 24px/1 var(--num); letter-spacing: 0.06em; padding-top: 3px; }
.side-small { font-size: 10.5px; font-weight: 600; color: var(--ink-3); }
.side-info { font-size: 12px; color: var(--ink-3); text-align: center; font-variant-numeric: tabular-nums; }
.side-info.small { font-size: 11px; }

.play-btn {
  --c: var(--amber); --c-hi: var(--amber-hi); --c-lo: var(--amber-lo); --c-ink: var(--amber-ink); --c-glow: var(--amber-glow);
  position: relative;
  width: 82px; height: 82px; border-radius: 50%;
  display: grid; place-items: center;
  color: var(--c-ink);
  background: radial-gradient(circle at 50% 28%, var(--c-hi), var(--c) 55%, var(--c-lo));
  box-shadow: 0 10px 26px var(--c-glow), inset 0 1px 0 rgba(255, 255, 255, 0.35), inset 0 -3px 8px rgba(0, 0, 0, 0.15);
  transition: transform 0.1s;
}
.play-btn.teal { --c: var(--teal); --c-hi: var(--teal-hi); --c-lo: var(--teal-lo); --c-ink: var(--teal-ink); --c-glow: var(--teal-glow); }
.play-btn.green { --c: var(--green); --c-hi: var(--green-hi); --c-lo: var(--green-lo); --c-ink: var(--green-ink); --c-glow: var(--green-glow); }
.play-btn:active { transform: scale(0.95); }
.play-btn svg { width: 38px; height: 38px; grid-area: 1 / 1; }
.play-btn .i-play { margin-left: 4px; }
.play-btn .i-stop, .mini-play .i-stop { display: none; }
.play-btn[aria-pressed="true"] .i-play, .mini-play[aria-pressed="true"] .i-play { display: none; }
.play-btn[aria-pressed="true"] .i-stop, .mini-play[aria-pressed="true"] .i-stop { display: block; }
#tunerBtn .i-play { margin-left: 0; }
.pulse {
  position: absolute; inset: -4px; border-radius: 50%;
  border: 3px solid var(--c);
  opacity: 0; pointer-events: none;
}
.pulse.go { animation: pulse 0.32s ease-out; }
.pulse.go.strong { animation-name: pulse-strong; }
@keyframes pulse { from { opacity: 0.75; transform: scale(1); } to { opacity: 0; transform: scale(1.22); } }
@keyframes pulse-strong { from { opacity: 1; transform: scale(1); border-width: 5px; } to { opacity: 0; transform: scale(1.4); border-width: 2px; } }

/* ---------- ドローン ---------- */
.drone-display {
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px 12px;
  padding: 12px 16px 12px 20px;
}
.wave { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.drone-info { position: relative; display: flex; flex-direction: column; min-width: 0; }
.drone-note { display: flex; align-items: flex-start; gap: 6px; }
#droneName { font: 700 92px/0.86 var(--num); padding-top: 12px; color: var(--ink); }
.drone-alt { font: 700 28px/1 var(--num); color: var(--ink-3); padding-top: 14px; }
.drone-meta { font-size: 14px; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; margin-top: 6px; }
.drone-meta .dot { margin: 0 6px; color: var(--ink-3); }
.drone-sub { font-size: 12.5px; color: var(--ink-2); margin-top: 2px; }
.drone-sub b { font-weight: 700; color: var(--ink); margin-right: 6px; }
.drone-sub span { letter-spacing: 0.02em; }
.drone-display .play-btn { width: 80px; height: 80px; margin-right: 2px; }
.drone-next {
  position: relative; grid-column: 1 / -1; justify-self: start;
  font-size: 12px; font-weight: 600; color: var(--teal-text);
  background: var(--teal-soft); border-radius: 12px; padding: 3px 10px;
}
.drone-display.playing #droneName { color: var(--teal); text-shadow: 0 0 28px var(--teal-glow); }

.note-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 7px; }
.key {
  position: relative;
  min-height: 50px; border-radius: 13px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--raised); border: 1px solid var(--line-2); box-shadow: var(--shadow);
}
.key.black { background: var(--surface); }
.key-name { font: 700 27px/1 var(--num); padding-top: 4px; }
.key-alt { font: 700 13px/1 var(--num); color: var(--ink-3); min-height: 13px; }
.key[aria-pressed="true"] { background: var(--teal-soft); border-color: var(--teal); color: var(--teal-text); }
.key[aria-pressed="true"] .key-alt { color: var(--teal-text); opacity: 0.75; }
.key.sounding { background: linear-gradient(170deg, var(--teal-hi), var(--teal) 60%, var(--teal-lo)); color: var(--teal-ink); border-color: transparent; box-shadow: 0 6px 20px var(--teal-glow); }
.key.sounding .key-alt { color: var(--teal-ink); opacity: 0.7; }
.key:active { transform: scale(0.96); }

.opts { padding: 6px 14px; display: flex; flex-direction: column; }
.opt-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 50px; }
.opt-row + .opt-row, .opts .row-btn { border-top: 1px solid var(--line); }
.opts .note { padding: 0 0 10px; margin-top: -4px; }
.opt-k { font-size: 14px; font-weight: 600; flex: none; }
.opt-row .slider { flex: 1; max-width: 260px; }
.seg-2l button { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 42px; padding: 2px 12px; line-height: 1.1; }
.seg-2l b { font: 700 18px/1 var(--num); padding-top: 3px; }
.seg-2l small { font-size: 10.5px; font-weight: 600; color: var(--ink-3); }
.seg-2l button[aria-checked="true"] small { color: var(--teal-text); }
.vol { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; justify-content: flex-end; }
.vol svg { width: 20px; height: 20px; color: var(--ink-3); }
.vol .slider { flex: 1; max-width: 240px; }
.toggles { display: flex; gap: 6px; }
.row-btn { display: flex; align-items: center; gap: 8px; min-height: 50px; width: 100%; text-align: left; }
.row-btn .row-v { margin-left: auto; font-size: 14px; color: var(--ink-2); }
.row-btn.on .row-v { color: var(--teal-text); font-weight: 600; }
.row-btn svg { width: 18px; height: 18px; color: var(--ink-3); }

/* ---------- チューナー ---------- */
.tuner-display {
  --state: var(--ink-3);
  display: flex; flex-direction: column; align-items: center;
  padding: 14px 18px 14px;
}
.tuner-display[data-state="ok"] { --state: var(--green); }
.tuner-display[data-state="near"] { --state: var(--warn); }
.tuner-display[data-state="far"] { --state: var(--bad); }
.tn-target { font-size: 12px; font-weight: 600; letter-spacing: 0.06em; color: var(--ink-3); min-height: 18px; }
.tn-note { position: relative; display: flex; align-items: flex-end; justify-content: center; gap: 2px; min-height: 104px; }
.tn-idle { display: none; width: 64px; height: 64px; color: var(--ink-3); opacity: 0.45; align-self: center; }
.tuner-display.empty .tn-idle { display: block; }
.tuner-display.empty #tnName, .tuner-display.empty .tn-oct { display: none; }
#tnName { font: 700 118px/0.86 var(--num); padding-top: 14px; color: var(--ink); transition: color 0.15s, text-shadow 0.15s; }
.tn-oct { font: 700 30px/1 var(--num); color: var(--ink-3); padding-bottom: 6px; }
.tuner-display[data-state="ok"] #tnName { color: var(--green); text-shadow: 0 0 30px var(--green-glow); }
.tuner-display[data-state="off"] #tnName, .tuner-display[data-state="wait"] #tnName { color: var(--ink-3); }
.tuner-display.stale #tnName { opacity: 0.45; }
.tn-cents { min-height: 22px; font-size: 14px; font-weight: 600; color: var(--state); text-align: center; font-variant-numeric: tabular-nums; }
.tuner-display[data-state="off"] .tn-cents, .tuner-display[data-state="wait"] .tn-cents { color: var(--ink-2); font-weight: 500; font-size: 13px; }

.gauge { position: relative; width: 100%; height: 62px; margin-top: 10px; }
.gauge-zone {
  position: absolute; top: 4px; bottom: 4px; left: 47%; width: 6%;
  background: var(--green-soft); border-radius: 6px;
}
.tuner-display[data-state="ok"] .gauge-zone { background: var(--green); opacity: 0.28; }
.gauge-ticks { position: absolute; inset: 0; }
.gauge-ticks i { position: absolute; bottom: 14px; width: 1.5px; height: 14px; margin-left: -0.75px; background: var(--ink-3); opacity: 0.55; border-radius: 1px; }
.gauge-ticks i.major { height: 24px; opacity: 0.85; }
.gauge-ticks i.zero { height: 40px; width: 2.5px; margin-left: -1.25px; background: var(--ink-2); opacity: 1; }
.needle {
  position: absolute; left: 50%; top: 0; bottom: 8px; width: 4px; margin-left: -2px;
  border-radius: 2px;
  background: var(--state);
  box-shadow: 0 0 12px var(--state);
  transform: translateX(0);
  transition: transform 0.12s linear, opacity 0.2s;
  opacity: 0;
}
.tuner-display[data-state="ok"] .needle, .tuner-display[data-state="near"] .needle, .tuner-display[data-state="far"] .needle { opacity: 1; }
.gauge-labels { display: flex; justify-content: space-between; width: 100%; font-size: 11.5px; font-weight: 600; color: var(--ink-3); margin-top: -4px; }
.gauge-labels .mid { font: 700 14px/1 var(--num); padding-top: 2px; }
.tn-foot { display: flex; align-items: center; justify-content: space-between; width: 100%; margin-top: 10px; font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.level { width: 90px; height: 6px; border-radius: 3px; background: var(--sunken); overflow: hidden; border: 1px solid var(--line); }
.level i { display: block; height: 100%; width: 0; background: var(--green); transition: width 0.08s; }

.string-row { display: grid; grid-template-columns: repeat(var(--n, 5), minmax(0, 1fr)); gap: 7px; }
.string {
  min-height: 62px; border-radius: 14px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  background: var(--raised); border: 1px solid var(--line-2); box-shadow: var(--shadow);
}
.string-name { font: 700 26px/1 var(--num); padding-top: 4px; }
.string-sub { font-size: 10.5px; font-weight: 600; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.string.auto .string-name { font: 700 15px/1.2 var(--ui); padding-top: 0; }
.string[aria-checked="true"] { border-color: var(--green); background: var(--green-soft); color: var(--green-text); }
.string[aria-checked="true"] .string-sub { color: var(--green-text); }
.string.near { box-shadow: 0 0 0 2px var(--green), var(--shadow); }

/* ---------- 下の帯（もう一方の音）とタブ ---------- */
.mini {
  flex: none;
  display: flex; gap: 8px;
  padding: 6px max(12px, env(safe-area-inset-right, 0px)) 6px max(12px, env(safe-area-inset-left, 0px));
}
.mini-item {
  flex: 1 1 0; min-width: 0;
  display: flex; align-items: center; gap: 4px;
  height: 46px; padding: 0 5px 0 12px;
  background: var(--raised); border: 1px solid var(--line-2); border-radius: 23px; box-shadow: var(--shadow);
}
.mini-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; height: 100%; text-align: left; font-size: 14px; font-weight: 600; }
.mini-main span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.mini-main svg { width: 20px; height: 20px; color: var(--ink-3); }
.mini-item.playing .mini-main svg { color: var(--c); }
#miniMetro { --c: var(--amber); }
#miniDrone { --c: var(--teal); }
.mini-play {
  width: 36px; height: 36px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--sunken); color: var(--ink);
}
.mini-play svg { width: 18px; height: 18px; grid-area: 1 / 1; }
.mini-play.amber[aria-pressed="true"] { background: var(--amber); color: var(--amber-ink); }
.mini-play.teal[aria-pressed="true"] { background: var(--teal); color: var(--teal-ink); }
.app[data-tab="metronome"] #miniMetro, .app[data-tab="drone"] #miniDrone { display: none; }

.tabs {
  flex: none;
  display: flex;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  padding: 0 max(4px, env(safe-area-inset-right, 0px)) env(safe-area-inset-bottom, 0px) max(4px, env(safe-area-inset-left, 0px));
}
.tab {
  flex: 1 1 0;
  height: var(--tabbar);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 10.5px; font-weight: 600; color: var(--ink-3);
}
.tab-ic { position: relative; display: grid; place-items: center; }
.tab .run { position: absolute; top: -2px; right: -7px; width: 8px; height: 8px; border-radius: 50%; display: none; box-shadow: 0 0 0 2px var(--surface); }
.tab .run.amber { background: var(--amber); }
.tab .run.teal { background: var(--teal); }
.tab .run.green { background: var(--green); }
.tab.running .run { display: block; }
.app[data-tab="metronome"] .tab[data-tab="metronome"] { color: var(--amber-text); }
.app[data-tab="drone"] .tab[data-tab="drone"] { color: var(--teal-text); }
.app[data-tab="tuner"] .tab[data-tab="tuner"] { color: var(--green-text); }
.wide-only { display: none !important; }

/* ---------- シート ---------- */
.backdrop { position: fixed; inset: 0; z-index: 20; background: var(--scrim); opacity: 0; transition: opacity 0.22s; }
.backdrop.open { opacity: 1; }
.sheet {
  position: fixed; z-index: 21;
  left: 0; right: 0; bottom: 0;
  max-height: 86%;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--raised);
  border-radius: var(--r-l) var(--r-l) 0 0;
  box-shadow: var(--shadow-lg);
  padding: 0 max(18px, env(safe-area-inset-right, 0px)) calc(18px + env(safe-area-inset-bottom, 0px)) max(18px, env(safe-area-inset-left, 0px));
  transform: translateY(105%);
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet.open { transform: none; }
.sheet::before { content: ""; display: block; width: 38px; height: 5px; border-radius: 3px; background: var(--line-2); margin: 8px auto 0; }
.sheet-head {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: center; justify-content: space-between;
  min-height: 52px; background: var(--raised);
}
.sheet-head h3 { margin: 0; font-size: 17px; font-weight: 700; }
.sheet-done { min-height: 44px; padding: 0 4px 0 12px; font-weight: 700; color: var(--amber-text); }
.sheet-body { display: flex; flex-direction: column; gap: 14px; padding-bottom: 6px; }
.form-row { display: flex; align-items: center; gap: 12px; min-height: 48px; }
.form-row .form-k { flex: 1; min-width: 0; font-size: 15px; display: flex; flex-direction: column; gap: 2px; }
.form-row .form-k small { font-size: 12.5px; line-height: 1.5; color: var(--ink-3); }
.form-row.sub { padding-left: 14px; min-height: 44px; }
.form-row.disabled { opacity: 0.38; pointer-events: none; }
.unit { font-size: 13px; color: var(--ink-3); min-width: 3.5em; }
.block { display: flex; flex-direction: column; gap: 4px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.block:last-child { border-bottom: 0; }
.chip-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.chip-grid .chip { min-height: 48px; border-radius: 14px; font: 700 22px/1 var(--num); padding-top: 4px; }

.list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--r-m); overflow: hidden; }
.list:empty { display: none; }
.list-item { display: flex; align-items: center; gap: 12px; min-height: 58px; padding: 8px 14px; text-align: left; width: 100%; background: var(--surface); }
.list-item + .list-item { border-top: 1px solid var(--line); }
.list-item .li-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.list-item .li-title { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .li-sub { font-size: 12.5px; line-height: 1.45; color: var(--ink-3); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.list-item .li-ic { width: 46px; flex: none; text-align: center; font: 700 22px/1 var(--num); color: var(--ink-2); padding-top: 3px; }
.list-item[aria-checked="true"] { background: var(--amber-soft); }
.list-item[aria-checked="true"] .li-ic, .list-item[aria-checked="true"] .li-title { color: var(--amber-text); }
.list-item .check { width: 22px; height: 22px; color: var(--amber-text); visibility: hidden; }
.list-item[aria-checked="true"] .check { visibility: visible; }
.li-del { width: 40px; height: 40px; flex: none; display: grid; place-items: center; border-radius: 50%; color: var(--ink-3); }
.li-del svg { width: 20px; height: 20px; }
.li-del.armed { background: var(--bad); color: #fff; width: auto; padding: 0 12px; border-radius: 20px; font-size: 13px; font-weight: 700; }
.empty { text-align: center; font-size: 13px; color: var(--ink-3); padding: 18px 8px; border: 1.5px dashed var(--line-2); border-radius: var(--r-m); }

.save-row { display: flex; gap: 8px; }
.text-input {
  flex: 1; min-width: 0; height: 46px; padding: 0 14px;
  font: 16px var(--ui); color: var(--ink);
  background: var(--sunken); border: 1px solid var(--line-2); border-radius: 12px;
}
.btn-primary { flex: none; height: 46px; padding: 0 16px; border-radius: 12px; background: var(--amber); color: var(--amber-ink); font-weight: 700; font-size: 14px; }
.btn-quiet { min-height: 40px; padding: 0 12px; border-radius: 10px; color: var(--ink-2); font-size: 14px; font-weight: 600; }
.btn-danger { min-height: 40px; padding: 0 14px; border-radius: 10px; background: var(--bad); color: #fff; font-weight: 700; font-size: 14px; }
.test-sound { padding-bottom: 8px; }
.test-sound .note { padding-left: 2px; font-variant-numeric: tabular-nums; }
.about { font-size: 12.5px; color: var(--ink-3); line-height: 1.6; border-top: 1px solid var(--line); padding-top: 10px; }
.about p { margin: 0 0 6px; }
.about b { color: var(--ink); font: 700 17px/1 var(--num); letter-spacing: 0.04em; }
.danger { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.confirm { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); }

.toast {
  position: fixed; z-index: 30; left: 50%;
  bottom: calc(var(--tabbar) + 70px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px; border-radius: 20px;
  background: var(--ink); color: var(--bg);
  font-size: 13.5px; font-weight: 600;
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.2s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---------- 小さい電話（iPhone SE など） ---------- */
@media (max-height: 700px) {
  .views { padding-bottom: 8px; }
  .view { gap: 10px; }
  .beats { gap: 7px; padding-block: 8px; }
  #beatsHead { display: none; }
  .feel-seg button { min-height: 40px; }
  .feel-seg svg { width: 30px; height: 20px; }
  .beat-cells { height: 44px; }
  .beat-num { font-size: 13px; padding-top: 0; }
  .chip { min-height: 28px; }
  .beats .chip-row { padding-block: 0; }
  .bpm-num { font-size: 76px; padding-top: 8px; }
  .bpm-unit { margin-top: -6px; }
  .tempo-row { grid-template-columns: 42px 50px minmax(0, 1fr) 50px 42px; }
  .round-btn { width: 50px; height: 50px; }
  .slider { height: 26px; }
  /* 小さい iPhone ではテンポのスライダーを外す（±・数字のドラッグ・TAP で変えられる） */
  #bpmSlider { display: none; }
  .tempo-mark .tempo-name { display: none; }
  .tile { min-height: 44px; padding-block: 6px; }
  .play-btn { width: 68px; height: 68px; }
  .play-btn svg { width: 30px; height: 30px; }
  .side-btn { height: 52px; width: 72px; }
  #droneName { font-size: 80px; }
  .drone-display .play-btn { width: 64px; height: 64px; }
  .key { min-height: 46px; }
  #tnName { font-size: 88px; }
  .tn-note { min-height: 78px; }
  .gauge { height: 50px; margin-top: 6px; }
  .string { min-height: 54px; }
}
@media (max-width: 360px) {
  .note-grid { gap: 5px; }
  .key-name { font-size: 23px; }
  .seg button { padding: 0 8px; }
}

/* ---------- 広い画面（iPad）: メトロノームとドローンを左右に ---------- */
@media (min-width: 760px) and (min-height: 540px) {
  .wide-only { display: flex !important; }
  .tab[data-tab="metronome"], .tab[data-tab="drone"] { display: none; }
  .app[data-tab="metronome"] .tab[data-tab="practice"],
  .app[data-tab="drone"] .tab[data-tab="practice"] { color: var(--amber-text); }
  .app[data-tab="metronome"] .views, .app[data-tab="drone"] .views {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 28px;
    align-content: start;
  }
  .app[data-tab="metronome"] #view-drone, .app[data-tab="drone"] #view-metronome { display: flex; }
  .view { max-width: 600px; width: 100%; margin: 0; }
  .app[data-tab="metronome"] #view-metronome, .app[data-tab="drone"] #view-metronome { justify-self: end; }
  .app[data-tab="tuner"] .views { display: flex; justify-content: center; }
  .views { padding-top: 8px; padding-bottom: 20px; }
  .view-title { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 15px; font-weight: 700; color: var(--ink-2); }
  .view-title svg { width: 20px; height: 20px; }
  #view-metronome .view-title svg { color: var(--amber); }
  #view-drone .view-title svg { color: var(--teal); }
  #view-tuner .view-title svg { color: var(--green); }
  .app[data-tab="metronome"] .mini, .app[data-tab="drone"] .mini { display: none; }
  .app[data-tab="tuner"] .mini { justify-content: center; }
  .app[data-tab="tuner"] .mini-item { max-width: 300px; }
  .tabs { justify-content: center; }
  .tab { flex: 0 1 180px; flex-direction: row; gap: 8px; font-size: 13px; }
  .sheet {
    left: 50%; right: auto; top: 50%; bottom: auto;
    width: 460px; max-height: 80%;
    border-radius: var(--r-l);
    padding-bottom: 20px;
    transform: translate(-50%, -46%) scale(0.98);
    opacity: 0;
    transition: transform 0.22s ease, opacity 0.22s ease;
  }
  .sheet.open { transform: translate(-50%, -50%); opacity: 1; }
  .sheet::before { display: none; }
  .toast { bottom: calc(var(--tabbar) + 24px + env(safe-area-inset-bottom, 0px)); }
}

/* 横向きの iPad: 高さが足りないので見出しを外す */
@media (min-width: 760px) and (min-height: 540px) and (max-height: 820px) {
  .view-title { display: none !important; }
  .views { padding-top: 4px; }
}

/* 縦長の iPad: 部品を大きくして画面を埋める */
@media (min-width: 760px) and (min-height: 1000px) {
  .view { gap: 18px; }
  .beat-cells { height: 112px; }
  .bpm-num { font-size: 148px; }
  .tile { min-height: 74px; padding-top: 12px; }
  .tile-v { font-size: 18px; }
  .play-btn { width: 104px; height: 104px; }
  .play-btn svg { width: 44px; height: 44px; }
  .side-btn { width: 88px; height: 72px; }
  .drone-display { min-height: 200px; padding: 18px 22px 18px 26px; }
  #droneName { font-size: 128px; }
  .drone-display .play-btn { width: 96px; height: 96px; }
  .note-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
  .key { min-height: 76px; }
  .key-name { font-size: 34px; }
  .key-alt { font-size: 15px; }
  .opt-row, .row-btn { min-height: 58px; }
  #view-tuner { max-width: 620px; justify-content: center; }
  #view-tuner .transport { margin-top: 12px; }
  #tnName { font-size: 160px; }
  .tn-note { min-height: 140px; }
  .gauge { height: 84px; }
  .string { min-height: 80px; }
  .string-name { font-size: 32px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
  .needle { transition: none; }
}
