:root {
  --bg: #0a0d14;
  --card: #111620;
  --card2: #161c28;
  --line: #252d3d;
  --text: #e8ecf4;
  --muted: #8b95a8;
  --a: #2dd4bf;
  --b: #f472b6;
  --count: #fbbf24;
  --on-acc: #0a0d14;   /* アクセント色の上に乗る文字色 */
  --glow: 24%;         /* 背景グローの濃さ */
  --toast-bg: #1f2636;
  --knob: var(--text);
  --shadow: none;
  --acc: var(--a);
  --radius: 18px;
  color-scheme: dark;
}
/* ベージュテーマ: 生成り色ベースのやわらかいライトUI */
html[data-theme="beige"] {
  --bg: #f3ece2;
  --card: #fbf7f1;
  --card2: #fffdf9;
  --line: #e3d7c6;
  --text: #3e352c;
  --muted: #8f8170;
  --a: #5f8f74;        /* セージ */
  --b: #c66b52;        /* テラコッタ */
  --count: #c49a3c;    /* マスタード */
  --on-acc: #fffdf9;
  --glow: 20%;
  --toast-bg: #fffdf9;
  --knob: #fffdf9;
  --shadow: 0 1px 2px rgba(94, 72, 48, .05), 0 8px 24px rgba(94, 72, 48, .07);
  --radius: 22px;
  color-scheme: light;
}
body[data-pattern="B"] { --acc: var(--b); }
body[data-pattern="C"] { --acc: var(--count); } /* カウントイン */

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100dvh;
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
/* パターン色の背景グロー（opacityだけをクロスフェード） */
body::before, body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  transition: opacity .5s ease;
}
body::before { background: radial-gradient(900px 520px at 50% -12%, color-mix(in srgb, var(--a) var(--glow), transparent), transparent 70%); }
body::after { background: radial-gradient(900px 520px at 50% -12%, color-mix(in srgb, var(--b) var(--glow), transparent), transparent 70%); opacity: 0; }
body[data-pattern="B"]::before,
body[data-pattern="C"]::before { opacity: 0; }
body[data-pattern="B"]::after { opacity: 1; }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }

/* Header */
.top {
  max-width: 1100px;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 16px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 19px; letter-spacing: .02em; }
.logo-mark {
  width: 22px; height: 22px; border-radius: 7px;
  background: linear-gradient(135deg, var(--a), var(--b));
}
.top-right { display: flex; align-items: center; gap: 10px; }
.theme-btn {
  height: 40px;
  padding: 0 14px 0 10px;
  display: flex; align-items: center; gap: 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card2);
  color: var(--muted);
  font-size: 13px; font-weight: 700;
  box-shadow: var(--shadow);
}
.theme-btn:hover { color: var(--text); }
.theme-btn .swatch {
  width: 18px; height: 18px; border-radius: 50%;
  background: linear-gradient(135deg, #f3ece2 50%, #0a0d14 50%);
  border: 1px solid var(--line);
}
.pat-badge {
  width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center;
  font-weight: 800; font-size: 20px;
  color: var(--on-acc); background: var(--acc);
  box-shadow: 0 0 22px color-mix(in srgb, var(--acc) 55%, transparent);
  transition: background-color .4s, box-shadow .4s;
}

/* Layout */
.layout {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px 24px;
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(0, 1fr);
}
@media (min-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
  .main-card { position: sticky; top: 14px; grid-row: span 6; }
}

.card {
  background: linear-gradient(180deg, var(--card2), var(--card));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card h2 {
  margin: 0 0 12px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.hint { margin: 12px 0 0; font-size: 12px; color: var(--muted); line-height: 1.6; }

.main-card {
  border-color: color-mix(in srgb, var(--acc) 35%, var(--line));
  transition: border-color .4s;
}

/* Status */
.status { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chip {
  padding: 4px 10px; border-radius: 999px;
  font-size: 13px; font-weight: 700;
  color: var(--on-acc); background: var(--acc);
  transition: background-color .4s;
}
.bar-info { font-size: 14px; font-variant-numeric: tabular-nums; }
.next-info { margin-left: auto; font-size: 12px; color: var(--muted); }
.progress { margin-top: 10px; height: 4px; border-radius: 4px; background: var(--line); overflow: hidden; }
.progress-fill {
  height: 100%; width: 0;
  background: var(--acc);
  transition: width .25s ease, background-color .4s;
}

/* A⇄B アニメーション */
.stage { position: relative; }
.viz { position: relative; height: 64px; margin: 16px 0 8px; transition: opacity .3s; }
.cells { transition: opacity .3s; }
.blind .viz, .blind .cells { opacity: 0; }
.blind-note {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 700; letter-spacing: .08em;
  color: var(--acc);
  opacity: 0; pointer-events: none;
  transition: opacity .3s;
}
.blind .blind-note { opacity: .8; }
.rail {
  position: absolute; left: 11px; right: 11px; top: 50%;
  height: 2px; margin-top: -1px; border-radius: 2px;
  background: var(--line);
}
.pt {
  position: absolute; top: 50%;
  width: 14px; height: 14px; margin-top: -7px;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--acc) 60%, var(--line));
  background: var(--bg);
  transition: border-color .4s;
}
#ptL { left: 4px; }
#ptR { right: 4px; }
.dot {
  position: absolute; left: 0; top: 50%;
  width: 22px; height: 22px; margin-top: -11px;
  border-radius: 50%;
  background: var(--acc);
  box-shadow: 0 0 18px var(--acc);
  will-change: transform;
  transition: background-color .4s, box-shadow .4s;
}

.cells { display: flex; gap: 6px; justify-content: center; align-items: center; height: 14px; margin: 4px 0 18px; }
.cell { flex: 1; max-width: 44px; height: 10px; border-radius: 5px; background: var(--line); }
.cell.off { height: 5px; }
.cell.head { height: 14px; }
.cell.gs { margin-left: 6px; } /* グルーピングの区切り */
.cell.on { background: var(--acc); box-shadow: 0 0 10px var(--acc); }

/* BPM */
.bpm-num { display: flex; align-items: baseline; justify-content: center; gap: 6px; }
.bpm-num input {
  width: 3.4ch;
  padding: 0;
  font-size: clamp(56px, 16vw, 80px);
  font-weight: 800;
  line-height: 1;
  text-align: center;
  font-variant-numeric: tabular-nums;
  background: none; border: 0; outline: none;
  -moz-appearance: textfield;
  appearance: textfield;
}
.bpm-num input::-webkit-outer-spin-button,
.bpm-num input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.bpm-num input:focus { color: var(--acc); }
.bpm-num span { font-size: 14px; color: var(--muted); font-weight: 700; }

.tempo-note {
  min-height: 18px; margin-top: 4px;
  text-align: center; font-size: 13px; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.tempo-note.on { color: var(--b); font-weight: 700; }

.bpm-steps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 12px; }

.btn {
  height: 48px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card2);
  font-weight: 700;
  font-size: 16px;
  transition: background-color .15s, border-color .15s, transform .05s;
}
.btn:hover { border-color: color-mix(in srgb, var(--acc) 50%, var(--line)); }
.btn:active { transform: scale(.97); background: var(--line); }
.btn.small { height: 34px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn.ghost { background: transparent; color: var(--muted); }

input[type="range"] { width: 100%; accent-color: var(--acc); margin: 0; height: 24px; }
.bpm-slider { margin-top: 14px; }

.transport {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  margin-top: 16px;
}
.tap { height: 56px; letter-spacing: .1em; }
.play {
  width: 80px; height: 80px;
  border-radius: 50%;
  border: 0;
  display: grid; place-items: center;
  background: var(--acc);
  color: var(--on-acc);
  box-shadow: 0 6px 28px color-mix(in srgb, var(--acc) 45%, transparent);
  transition: background-color .4s, box-shadow .4s, transform .08s;
}
.play:active { transform: scale(.95); }
.play svg { width: 38px; height: 38px; fill: currentColor; }
.play .i-stop { display: none; }
.playing .play .i-play { display: none; }
.playing .play .i-stop { display: block; }
.sig-mini {
  height: 56px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-radius: 12px; border: 1px dashed var(--line);
  font-weight: 800; font-size: 20px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.sig-mini.dual #sigMain { font-size: 15px; }
.sig-mini small { font-size: 11px; font-weight: 700; line-height: 1.2; }
.sig-mini small:empty { display: none; }

/* Forms */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.form-grid .full { grid-column: 1 / -1; }
.form-grid .pa, .form-grid .pb { font-size: 12px; font-weight: 800; }
.form-grid .pa { color: var(--a); }
.form-grid .pb { color: var(--b); }
.row { display: flex; align-items: center; gap: 8px; }
.row select { flex: 1; min-width: 0; }
output { min-width: 36px; text-align: right; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

select {
  height: 38px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  width: 100%;
}

/* Volume grid */
.vol-grid {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px 12px;
  align-items: center;
}
.vol-grid .lbl { font-size: 13px; color: var(--muted); white-space: nowrap; }
.col-h {
  text-align: center;
  font-size: 12px; font-weight: 800;
  padding: 5px 0; border-radius: 8px;
  border: 1px solid transparent;
  transition: background-color .4s, border-color .4s;
}
.col-h.a { color: var(--a); }
.col-h.b { color: var(--b); }
body[data-pattern="A"] .col-h.a { background: color-mix(in srgb, var(--a) 12%, transparent); border-color: color-mix(in srgb, var(--a) 40%, transparent); }
body[data-pattern="B"] .col-h.b { background: color-mix(in srgb, var(--b) 12%, transparent); border-color: color-mix(in srgb, var(--b) 40%, transparent); }
.vcell { display: flex; align-items: center; gap: 6px; min-width: 0; }
.vcell output { min-width: 30px; font-size: 12px; }
.vcell.a input { accent-color: var(--a); }
.vcell.b input { accent-color: var(--b); }

/* Rhythm */
.rhythm-grid {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px 10px;
  align-items: center;
}
.rhythm-grid .lbl { font-size: 13px; color: var(--muted); white-space: nowrap; }
.rhythm-grid select { height: 34px; padding: 0 6px; font-size: 13px; }
.rhythm-grid select:disabled { opacity: .45; }
.rhythm-grid .fixed { font-size: 12px; color: var(--muted); text-align: center; }
.vol-sep {
  grid-column: 1 / -1;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  font-size: 11px; font-weight: 700; letter-spacing: .08em;
  color: var(--muted);
}

/* Schedule */
.seg {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  padding: 4px; margin-bottom: 12px;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg);
}
.seg button {
  height: 34px; border: 0; border-radius: 9px;
  background: transparent; color: var(--muted);
  font-size: 13px; font-weight: 700;
}
.seg button.on { background: var(--acc); color: var(--on-acc); }
.sched-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sched-col {
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  display: grid; gap: 8px;
  transition: border-color .4s, background-color .4s;
}
.sched-col h3 { margin: 0; font-size: 14px; }
.sched-col[data-p="A"] h3 { color: var(--a); }
.sched-col[data-p="B"] h3 { color: var(--b); }
body[data-pattern="A"] .sched-col[data-p="A"] { border-color: color-mix(in srgb, var(--a) 45%, transparent); background: color-mix(in srgb, var(--a) 6%, transparent); }
body[data-pattern="B"] .sched-col[data-p="B"] { border-color: color-mix(in srgb, var(--b) 45%, transparent); background: color-mix(in srgb, var(--b) 6%, transparent); }
.sched-col label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.rand { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.rand[hidden] { display: none; }
.sched-grid.disabled { opacity: .45; }

.opt-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-top: 14px; padding-top: 14px;
  border-top: 1px solid var(--line);
}
.opt-row b { display: block; font-size: 14px; }
.opt-row small { display: block; margin-top: 2px; font-size: 12px; color: var(--muted); line-height: 1.5; }
.opt-row .switch { flex-shrink: 0; }

/* Presets */
.preset-list { display: grid; gap: 8px; }
.preset { display: flex; gap: 6px; }
.preset-apply {
  flex: 1; min-width: 0;
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  padding: 10px 12px;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg);
  text-align: left; font-weight: 700; font-size: 14px;
  transition: border-color .15s;
}
.preset-apply:hover { border-color: color-mix(in srgb, var(--acc) 50%, var(--line)); }
.preset-apply span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preset-apply small { flex-shrink: 0; font-size: 12px; font-weight: 400; color: var(--muted); }
.preset-del {
  width: 42px; border-radius: 12px;
  border: 1px solid var(--line); background: transparent;
  color: var(--muted); font-size: 18px;
}
.preset-del:hover { color: var(--text); }
.preset-empty { margin: 0; font-size: 13px; color: var(--muted); }

/* Switch */
.switch { position: relative; display: inline-flex; align-items: center; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .slider {
  width: 46px; height: 26px; border-radius: 999px;
  background: var(--line);
  position: relative;
  transition: background-color .2s;
}
.switch .slider::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--knob);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .18);
  transition: transform .2s;
}
.switch input:checked + .slider { background: var(--acc); }
.switch input:checked + .slider::after { transform: translateX(20px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--acc); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Practice log */
.log-top { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.log-label { font-size: 12px; color: var(--muted); }
.log-big { font-size: 40px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }
.log-mid { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.week {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px;
  height: 120px; margin-top: 14px;
}
.wd { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; min-width: 0; }
.wd .bar {
  width: 100%; max-width: 30px; min-height: 2px;
  border-radius: 6px 6px 2px 2px;
  background: color-mix(in srgb, var(--acc) 55%, var(--line));
  transition: height .3s, background-color .4s;
}
.wd.today .bar { background: var(--acc); }
.wd .v { font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }
.wd .d { font-size: 11px; color: var(--muted); }
.wd.today .d { color: var(--text); font-weight: 700; }
.log-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.log-stats > div { display: grid; gap: 2px; padding: 10px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); }
.log-stats b { font-size: 16px; font-variant-numeric: tabular-nums; }

/* Footer / toast */
.foot {
  max-width: 1100px; margin: 0 auto;
  padding: 0 16px max(24px, env(safe-area-inset-bottom));
  display: flex; flex-wrap: wrap; gap: 14px; justify-content: center;
  font-size: 12px; color: var(--muted);
}
@media (hover: none) { .foot { display: none; } }
kbd {
  display: inline-block; min-width: 20px; padding: 1px 5px; margin-right: 2px;
  border: 1px solid var(--line); border-radius: 5px;
  font-family: inherit; font-size: 11px; text-align: center;
}
.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  padding: 10px 16px; border-radius: 12px;
  background: var(--toast-bg); border: 1px solid var(--line); box-shadow: var(--shadow);
  font-size: 13px;
  opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 説明書モーダル ---------- */
.help-btn { padding: 0 14px 0 8px; }
.help-mark {
  width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--acc); color: var(--on-acc);
  font-size: 13px; font-weight: 800;
}
@media (max-width: 420px) {
  .help-btn { padding: 0 9px; }
  .help-label { display: none; }
}
body.modal-open { overflow: hidden; }
.manual {
  width: min(640px, calc(100% - 24px));
  max-height: min(86vh, 860px);
  margin: auto; padding: 0;
  display: none; flex-direction: column;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); color: var(--text);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .35);
}
.manual[open] { display: flex; animation: manual-in .22s ease-out; }
.manual::backdrop { background: rgba(0, 0, 0, .5); backdrop-filter: blur(3px); }
@keyframes manual-in { from { opacity: 0; transform: translateY(14px) scale(.98); } }
.manual-head {
  display: flex; align-items: center; justify-content: space-between;
  flex: none; padding: 14px 16px 10px;
}
.manual-head h2 { margin: 0; font-size: 18px; }
.manual-close {
  width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--card2); color: var(--muted);
  font-size: 15px; cursor: pointer;
}
.manual-close:hover { color: var(--text); }
.manual-toc {
  display: flex; gap: 6px; overflow-x: auto;
  flex: none; padding: 0 16px 12px; border-bottom: 1px solid var(--line);
  scrollbar-width: none;
}
.manual-toc::-webkit-scrollbar { display: none; }
.manual-toc a {
  flex: none; padding: 6px 11px; border-radius: 999px;
  background: var(--card2); border: 1px solid var(--line);
  color: var(--muted); font-size: 12px; font-weight: 700; text-decoration: none;
}
.manual-toc a:hover { color: var(--text); border-color: var(--acc); }
.manual-body {
  overflow-y: auto; overscroll-behavior: contain;
  padding: 4px 16px 20px;
  font-size: 14px; line-height: 1.75;
}
.manual-body section { padding-top: 14px; scroll-margin-top: 4px; }
.manual-body section + section { border-top: 1px dashed var(--line); margin-top: 16px; }
.manual-body h3 { margin: 0 0 6px; font-size: 15px; color: var(--acc); }
.manual-body p { margin: 0 0 8px; }
.manual-body .ta { color: var(--a); }
.manual-body .tb { color: var(--b); }
.manual-body .tip {
  padding: 8px 12px; border-radius: 12px;
  background: color-mix(in srgb, var(--acc) 12%, transparent);
  font-size: 13px;
}
.manual-body .tip::before { content: '💡 '; }
.steps { margin: 6px 0 10px; padding-left: 1.4em; }
.steps li { margin: 2px 0; }
.defs { margin: 4px 0 8px; display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; }
.defs dt { font-weight: 700; white-space: nowrap; }
.defs dd { margin: 0; color: var(--muted); }
@media (max-width: 520px) {
  .defs { grid-template-columns: 1fr; gap: 0; }
  .defs dd { margin-bottom: 8px; }
}
.ab-demo { display: flex; align-items: stretch; gap: 8px; margin: 8px 0; }
.ab {
  flex: 1; padding: 10px 12px; border-radius: 14px;
  font-size: 13px; line-height: 1.6; text-align: center;
  border: 1px solid var(--line);
}
.ab.a { background: color-mix(in srgb, var(--a) 16%, transparent); border-color: color-mix(in srgb, var(--a) 45%, transparent); }
.ab.b { background: color-mix(in srgb, var(--b) 16%, transparent); border-color: color-mix(in srgb, var(--b) 45%, transparent); }
.ab b { font-size: 16px; }
.ab small { color: var(--muted); }
.ab-arrow { align-self: center; color: var(--muted); font-size: 18px; }
