:root {
  --bg: #0f1115;
  --panel: #181b22;
  --panel-2: #20242d;
  --line: #2b303b;
  --text: #e8eaf0;
  --muted: #8a90a0;
  --accent: #7c8cff;
  --keep: #2fd38a;
  --nope: #ff5d6c;
  --similar: #f5b84a;
  --chord: #b9c2ff;
  --note: #7c8cff;
  --note-pass: #4fc3d9;
  --roll-bg: #14171d;
  --roll-black: #101217;
  --roll-fade: rgba(0, 0, 0, 0.35);
  --roll-bar: #3a4050;
  --roll-beat: #232833;
  --playhead: #ffffff;
  --acc: #f5b84a;
  --acc-bass: #e0794f;
  --radius: 20px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
body {
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  -webkit-user-select: none; user-select: none;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }
.hidden { display: none !important; }

#app {
  height: 100dvh; display: flex; flex-direction: column;
  padding-top: var(--safe-t);
  max-width: 560px; margin: 0 auto;
}

/* ヘッダー */
.top { display: flex; align-items: baseline; justify-content: space-between; padding: 10px 16px 4px; }
.brand { font-weight: 800; letter-spacing: 0.02em; }
.info { color: var(--muted); font-size: 13px; text-align: right; }

.view { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 0 16px; }

/* メロディ／伴奏 切替 */
.modeseg { display: flex; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 3px; margin-top: 4px; }
.modeseg button { flex: 1; height: 36px; border-radius: 9px; font-weight: 700; color: var(--muted); }
.modeseg button.on { background: var(--panel-2); color: var(--text); }
.modeseg button[data-mode="acc"].on { color: var(--acc); }

/* コード進行の帯 */
.progbar { display: flex; gap: 4px; margin-top: 6px; overflow-x: auto; }
.progbar button {
  flex: 1 0 auto; min-width: 44px; height: 34px; padding: 0 8px; border-radius: 8px;
  background: var(--panel); border: 1px solid var(--line); color: var(--muted); font-weight: 700; font-size: 13px;
}
.progbar button.cur { background: rgba(124, 140, 255, 0.22); border-color: var(--accent); color: var(--text); }

/* カード */
.deck { position: relative; flex: 1; min-height: 220px; margin: 8px 0 12px; }
.card {
  position: absolute; inset: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  display: flex; flex-direction: column; padding: 14px; gap: 10px;
  touch-action: none; will-change: transform;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}
.card.behind { transform: scale(0.95) translateY(10px); opacity: 0.55; pointer-events: none; }
.card.fly { transition: transform 0.28s ease-in, opacity 0.28s ease-in; }
.card.back { transition: transform 0.2s ease-out; }
.card-head { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.tag { padding: 3px 9px; border-radius: 999px; background: var(--panel-2); color: var(--text); font-size: 12px; font-weight: 600; }
.tag.rhythm { color: #ffd17a; }
.tag.pitch { color: #8fe3ff; }
.tag.partial { color: #c9a6ff; }
.tag.repeat, .tag.ending { color: var(--keep); }
.tag.acc { color: var(--acc); }
.card-head .ctx { font-size: 12px; }
.card-head .num { margin-left: auto; }
.card canvas { flex: 1; width: 100%; min-height: 0; border-radius: 12px; display: block; }
.card-foot { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }
.stamp {
  position: absolute; top: 18px; padding: 6px 14px; border: 3px solid; border-radius: 10px;
  font-weight: 900; font-size: 22px; opacity: 0; pointer-events: none;
}
.stamp.keep { left: 18px; color: var(--keep); transform: rotate(-12deg); }
.stamp.nope { right: 18px; color: var(--nope); transform: rotate(12deg); }

/* 直前のキープ（くり返し操作） */
.lastbar { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.lastbar canvas { flex: 1; min-width: 0; height: 44px; border-radius: 10px; display: block; }
.lastinfo { display: flex; flex-direction: column; align-items: center; font-size: 11px; color: var(--muted); min-width: 30px; }
.lastinfo b { font-size: 15px; color: var(--text); }
.lastbar .chip { padding: 0 12px; }

/* トグル */
.toggles { display: flex; gap: 8px; justify-content: center; margin-bottom: 10px; }
.chip {
  min-height: 44px; padding: 0 16px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line); color: var(--muted); font-size: 14px; font-weight: 600;
}
.chip[aria-pressed="true"] { background: rgba(124, 140, 255, 0.18); border-color: var(--accent); color: var(--text); }
.chip.danger { color: var(--nope); }
.chip:active { transform: scale(0.96); }

/* 主要ボタン（親指の届く下部） */
.actions { display: grid; grid-template-columns: 1fr 1.15fr 1fr; gap: 12px; align-items: center; padding-bottom: 12px; }
.act {
  height: 84px; border-radius: 26px; font-size: 34px; font-weight: 800;
  background: var(--panel); border: 2px solid var(--line);
  transition: transform 0.08s;
}
.act:active { transform: scale(0.94); }
.act.nope { color: var(--nope); border-color: rgba(255, 93, 108, 0.45); }
.act.keep { color: var(--keep); border-color: rgba(47, 211, 138, 0.45); }
.act.similar { color: var(--similar); border-color: rgba(245, 184, 74, 0.45); font-size: 16px; line-height: 1.25; }

/* タブ */
.tabs {
  display: grid; grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--line); background: var(--bg);
  padding-bottom: var(--safe-b);
}
.tab { height: 58px; font-size: 15px; font-weight: 700; color: var(--muted); }
.tab.active { color: var(--text); box-shadow: inset 0 3px 0 var(--accent); }
.badge { display: inline-block; min-width: 22px; padding: 1px 6px; border-radius: 999px; background: var(--panel-2); font-size: 12px; }

/* 棚 */
.shelf-head { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; padding: 6px 2px; }
.shelf { list-style: none; margin: 0; padding: 0; flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.shelf-empty { flex: 1; color: var(--muted); text-align: center; padding-top: 40px; line-height: 1.8; }
.row {
  display: grid; grid-template-columns: 36px 1fr 40px 40px 40px; align-items: center; gap: 2px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 6px; margin-bottom: 8px; position: relative;
}
.row.playing { border-color: var(--accent); }
.row.dragging { z-index: 5; box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5); opacity: 0.95; }
.row .handle { height: 68px; font-size: 22px; color: var(--muted); touch-action: none; }
.row canvas { width: 100%; height: 68px; border-radius: 8px; display: block; }
.row .del, .row .dup, .row .accbtn { height: 68px; font-size: 18px; color: var(--muted); }
.row .accbtn { color: var(--acc); font-size: 20px; }
.row .dup { color: var(--chord); font-size: 20px; }
.row .idx { position: absolute; left: 44px; bottom: 8px; font-size: 10px; color: var(--muted); pointer-events: none; }
.shelf-actions { display: flex; gap: 8px; justify-content: center; padding: 10px 0; flex-wrap: wrap; }
.wide { width: 100%; height: 64px; border-radius: 20px; font-size: 18px; font-weight: 800; margin-bottom: 12px; }
.primary { background: var(--accent); color: #0b0d12; }
.primary:active { transform: scale(0.98); }
.primary:disabled { opacity: 0.4; }

/* 設定シート */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  max-width: 560px; margin: 0 auto; max-height: 88dvh; overflow-y: auto;
  background: var(--panel); border-radius: 22px 22px 0 0; border-top: 1px solid var(--line);
  padding: 8px 16px calc(16px + var(--safe-b));
  transform: translateY(105%); transition: transform 0.25s ease;
}
.sheet.open { transform: translateY(0); }
.sheet-grip { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 8px; }
.sheet h2 { margin: 4px 0 8px; font-size: 18px; }
.field { display: block; margin: 14px 0; font-size: 14px; color: var(--muted); font-weight: 600; }
.field output { color: var(--text); margin-left: 6px; }
.seg { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.seg button {
  flex: 1; min-width: 44px; height: 46px; border-radius: 12px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text); font-weight: 700;
}
.seg.keys button { flex: 0 0 calc((100% - 30px) / 6); }
.seg button.on { background: var(--accent); color: #0b0d12; border-color: var(--accent); }
input[type="range"] { width: 100%; height: 40px; margin-top: 4px; accent-color: var(--accent); }
input[type="text"] {
  width: 100%; height: 50px; margin-top: 8px; padding: 0 14px; border-radius: 12px;
  background: var(--bg); color: var(--text); border: 1px solid var(--line); font-size: 18px; font-weight: 700;
  -webkit-user-select: text; user-select: text;
}
.seg.starts button { flex: 0 0 calc((100% - 30px) / 6); height: 54px; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.2; }
.seg.starts small { font-size: 11px; font-weight: 600; opacity: 0.75; }
.prog-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.prog-list button {
  display: flex; align-items: baseline; gap: 10px; min-height: 48px; padding: 8px 14px; border-radius: 12px; text-align: left;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
}
.prog-list button b { font-size: 15px; min-width: 112px; }
.prog-list button span { color: var(--chord); font-size: 13px; }
.prog-list button em { margin-left: auto; font-style: normal; font-size: 11px; color: var(--muted); }
.prog-list button.on { border-color: var(--accent); background: rgba(124, 140, 255, 0.18); }
.prog-preview { margin-top: 8px; color: var(--chord); font-size: 13px; min-height: 18px; }
.prog-preview.err { color: var(--nope); }
.version { text-align: center; color: var(--muted); font-size: 11px; }

/* 起動オーバーレイ（iOS の音声有効化） */
.unlock {
  position: fixed; inset: 0; z-index: 50; background: var(--bg);
  display: flex; align-items: flex-end; justify-content: center; padding-bottom: calc(60px + var(--safe-b));
}
.unlock-inner { text-align: center; }
.logo { font-size: 64px; color: var(--accent); }
.unlock-title { font-size: 28px; font-weight: 900; margin-top: 4px; }
.unlock-text { color: var(--muted); margin-top: 6px; }
.unlock-tap {
  margin-top: 40px; padding: 20px 44px; border-radius: 999px; background: var(--accent); color: #0b0d12;
  font-weight: 800; font-size: 18px; animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 50% { transform: scale(1.05); } }

.toast {
  position: fixed; left: 50%; top: calc(48px + var(--safe-t)); transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 999px;
  font-size: 14px; z-index: 40; opacity: 0; transition: opacity 0.2s; pointer-events: none; white-space: nowrap;
}
.toast.show { opacity: 1; }

@media (max-height: 640px) {
  .act { height: 70px; }
  .wide { height: 56px; }
}
