/* style.css — 明るく親しみやすいメトロノームUI（ライトテーマ・丸み・やさしい配色） */

:root {
  --bg: #eef1f8;            /* やわらかい薄いブルーグレー */
  --bg-2: #e4e9f5;
  --card: #ffffff;
  --card-soft: #f4f6fc;    /* カード内の一段淡い面 */
  --text: #2d3340;         /* やわらかい濃紺グレー */
  --text-dim: #7a8397;
  --primary: #4a7dff;      /* 親しみやすいブルー */
  --primary-soft: #e7eeff;
  --strong: #ff7a4d;       /* 強拍：あたたかいオレンジ */
  --strong-soft: #ffe9e0;
  --beat: #43b6ff;         /* 通常拍：さわやかな水色 */
  --start: #28c76f;        /* スタート：やさしいグリーン */
  --stop: #ff5b6a;         /* ストップ：やわらかい赤 */
  --border: #e2e7f2;
  --radius: 22px;
  --radius-sm: 14px;
  --shadow: 0 6px 20px rgba(45, 70, 130, 0.08);
  --shadow-btn: 0 4px 12px rgba(45, 70, 130, 0.12);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, "Hiragino Maru Gothic ProN", "M PLUS Rounded 1c",
    "Segoe UI", "Yu Gothic UI", "Noto Sans JP", sans-serif;
  -webkit-user-select: none;
  user-select: none;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 14px 14px calc(28px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ---- アプリ見出し ---- */
.app-header {
  text-align: center;
  padding: 6px 0 2px;
}
.app-header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.02em;
}
.app-header .sub {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

/* ---- パネル共通 ---- */
.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.panel-title {
  margin: 0 0 14px;
  font-size: 16px;
  font-weight: 800;
  color: var(--text);
}
.panel-head .panel-title { margin-bottom: 0; }
.hint {
  font-size: 12px;
  color: var(--text-dim);
  background: var(--card-soft);
  padding: 4px 10px;
  border-radius: 999px;
}

/* ---- 再生エリア ---- */
.play-panel {
  text-align: center;
  padding-top: 22px;
  background: linear-gradient(180deg, #ffffff 0%, #f7f9ff 100%);
}
.bpm-display {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
}
#bpm-value {
  font-size: 78px;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--primary);
}
.bpm-unit { font-size: 18px; color: var(--text-dim); font-weight: 700; }
.tempo-marking {
  display: inline-block;
  margin-top: 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 4px 12px;
  border-radius: 999px;
  min-height: 14px;
}

/* 拍ドット */
.beat-dots {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin: 22px 0 8px;
  min-height: 30px;
}
.dot {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--border);
  transition: transform 0.06s ease, background 0.06s ease, box-shadow 0.06s ease, border-color 0.06s ease;
  cursor: pointer;
}
.dot.strong { border-color: var(--strong); width: 30px; height: 30px; }
.dot.off { opacity: 0.4; border-style: dashed; }
.dot.active { background: var(--beat); border-color: var(--beat); box-shadow: 0 0 0 6px rgba(67,182,255,0.22); transform: scale(1.2); }
.dot.strong.active { background: var(--strong); border-color: var(--strong); box-shadow: 0 0 0 7px rgba(255,122,77,0.24); }

.measure-indicator {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  min-height: 16px;
  margin-bottom: 16px;
}

/* スタート/ストップ */
.start-stop {
  width: 100%;
  padding: 20px;
  font-size: 22px;
  font-weight: 800;
  color: #fff;
  background: var(--start);
  border: none;
  border-radius: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  box-shadow: 0 6px 16px rgba(40,199,111,0.35);
  transition: transform 0.08s ease, box-shadow 0.1s ease, background 0.1s ease;
}
.start-stop:active { transform: translateY(2px) scale(0.99); }
.start-stop.playing {
  background: var(--stop);
  box-shadow: 0 6px 16px rgba(255,91,106,0.35);
}
.ss-icon { font-size: 18px; }

/* ---- スライダー共通 ---- */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: var(--bg-2);
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary);
  border: 4px solid #fff;
  box-shadow: var(--shadow-btn);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--primary); border: 4px solid #fff;
  box-shadow: var(--shadow-btn); cursor: pointer;
}
.bpm-slider { margin-bottom: 16px; }

/* ---- テンポ操作 ---- */
.nudge-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
.nudge {
  padding: 16px 0;
  font-size: 17px;
  font-weight: 800;
  color: var(--text);
  background: var(--card-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 0.08s ease, background 0.1s ease;
}
.nudge:active { transform: translateY(1px); background: var(--bg-2); }

.tap-tempo {
  width: 100%;
  padding: 18px;
  border-radius: var(--radius-sm);
  border: 2px dashed var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: transform 0.08s ease;
}
.tap-tempo:active { transform: scale(0.99); }
.tap-main { font-size: 17px; font-weight: 800; }
.tap-hint { font-size: 12px; color: var(--text-dim); }

/* ---- 音色・音量 ---- */
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.seg-btn {
  padding: 16px 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-dim);
  background: var(--card-soft);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.1s ease;
}
.seg-btn.active {
  color: #fff;
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: var(--shadow-btn);
}
.volume-row { display: flex; align-items: center; gap: 12px; }
.vol-icon { font-size: 20px; }

/* ---- 小節エディタ ---- */
.measures-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; }
.measure-card {
  background: var(--card-soft);
  border: 2px solid var(--border);
  border-radius: 18px;
  padding: 14px;
  transition: border-color 0.1s ease, box-shadow 0.1s ease;
}
.measure-card.current {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.measure-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.measure-no {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  background: var(--primary);
  padding: 4px 10px;
  border-radius: 999px;
}

/* 拍子の選択：「8分音符 を 6 回」 */
.sig-select {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 15px;
  font-weight: 700;
  flex-wrap: wrap;
}
.sig-select select {
  background: #fff;
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 8px 10px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.note-select { min-width: 96px; }
.count-select { min-width: 56px; }
.sig-conn, .sig-times { color: var(--text-dim); font-weight: 700; }

.measure-actions { margin-left: auto; display: flex; gap: 6px; }
.icon-btn {
  width: 38px; height: 38px;
  display: inline-flex; align-items: center; justify-content: center;
  background: #fff;
  border: 2px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
  transition: background 0.1s ease, transform 0.08s ease;
}
.icon-btn:active { transform: translateY(1px); background: var(--bg-2); }
.icon-btn.danger { color: var(--stop); }
.icon-btn:disabled { opacity: 0.3; cursor: default; }

/* 小節内の拍ボタン（アクセント設定） */
.beat-edit-row { display: flex; flex-wrap: wrap; gap: 8px; }
.beat-pill {
  min-width: 42px;
  height: 42px;
  padding: 0 6px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: #fff;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.1s ease;
}
.beat-pill.normal { border-color: var(--beat); color: var(--beat); background: #eef9ff; }
.beat-pill.strong { border-color: var(--strong); color: #fff; background: var(--strong); }
.beat-pill.off { border-style: dashed; opacity: 0.5; }

.add-measure {
  width: 100%;
  padding: 16px;
  border-radius: var(--radius-sm);
  border: 2px dashed var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
}
.add-measure:active { transform: translateY(1px); }

/* ---- プリセット ---- */
.preset-save-row { display: flex; gap: 10px; margin-bottom: 14px; }
.preset-name {
  flex: 1;
  padding: 14px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: var(--card-soft);
  color: var(--text);
  font-size: 16px;
  -webkit-user-select: text;
  user-select: text;
}
.preset-name:focus { outline: none; border-color: var(--primary); background: #fff; }
.save-preset {
  padding: 14px 20px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: var(--shadow-btn);
}
.save-preset:active { transform: translateY(1px); }
.presets-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.preset-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card-soft);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.preset-info { flex: 1; min-width: 0; cursor: pointer; }
.preset-title { font-size: 16px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preset-meta { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.preset-empty { font-size: 13px; color: var(--text-dim); text-align: center; padding: 10px; }

/* ---- フッター ---- */
.app-footer { padding: 4px 6px 0; }
.wakelock { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text-dim); cursor: pointer; }
.wakelock input { width: 20px; height: 20px; accent-color: var(--primary); }

/* ---- トースト ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 13px 20px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
