/* ダークテーマ(SoundPlayer の配色を踏襲)。
   チャート系の色はバリデータ検証済み:
   - 運動カテゴリ3色は dark surface #0b0f14 で全ペア CVD ΔE >= 9.4 / 通常視 >= 20.9
   - ヒートマップは緑1色の順次ランプ + 10h超のみ琥珀(働きすぎの状態色) */
:root {
  --bg: #0b0f14;
  --bg-elev: #131a22;
  --bg-elev2: #1a232e;
  --text: #c7d0d9;
  --text-dim: #7d8a96;
  --accent: #5b8dbf;
  --accent-soft: #2a4a66;
  --border: #232e3a;
  --danger: #b06060;

  --heat-0: #161b22;
  --heat-1: #0e4429;
  --heat-2: #006d32;
  --heat-3: #26a641;
  --heat-4: #39d353;
  --heat-5: #d29922; /* 10h超 = 働きすぎ警告(色相を変えて一目で分かるように) */

  --cat-strength: #d95926;
  --cat-stretch: #199e70;
  --cat-cardio: #3987e5;

  --work-green: #26a641;
  --sleep-pink: #d55181;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

button {
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
button:active { background: var(--bg-elev2); }

input, select {
  font-family: inherit;
  font-size: 16px; /* iOSのズーム防止 */
  color: var(--text);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  outline: none;
}
input:focus, select:focus { border-color: var(--accent-soft); }
input::placeholder { color: var(--text-dim); }

/* ---------- ヘッダー ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px;
  background: rgba(11, 15, 20, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.app-title {
  margin: 0;
  margin-right: auto;
  font-size: 17px;
  font-weight: 600;
}

.chip {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  white-space: nowrap;
}
.chip-warn { color: var(--heat-5); border-color: var(--heat-5); }

/* ---------- バナー ---------- */
.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 10px 14px 0;
  padding: 10px 12px;
  font-size: 13px;
  border-radius: 10px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
}
.banner-warn { border-color: var(--heat-5); }

/* ---------- メイン ---------- */
#main {
  padding: 10px 14px calc(70px + env(safe-area-inset-bottom));
  max-width: 640px;
  margin: 0 auto;
}

.card {
  margin-top: 14px;
  padding: 14px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.card-title {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
}

/* ---------- 業務ボタン ---------- */
.work-btn-wrap {
  display: flex;
  justify-content: center;
  padding: 22px 0 8px;
}
.work-btn {
  width: 176px;
  height: 176px;
  border-radius: 50%;
  border: 2px solid var(--accent-soft);
  background: var(--bg-elev);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 20px;
  font-weight: 600;
  transition: border-color .2s, box-shadow .2s;
}
.work-btn.working {
  border-color: var(--work-green);
  box-shadow: 0 0 24px rgba(38, 166, 65, 0.25);
}
.work-elapsed {
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--heat-4);
}
.work-btn.working .work-btn-label { color: var(--text-dim); }

/* ---------- 今日のサマリー ---------- */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.summary-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: 10px;
  border: 1px solid var(--border);
  min-width: 0;
}
.summary-label {
  font-size: 11px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}
.summary-value {
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.summary-value .dim { color: var(--text-dim); font-weight: 400; }

/* ---------- 運動クイック入力 ---------- */
.seg {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}
.seg button {
  flex: 1;
  padding: 9px 4px;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}
.seg button.active {
  border-color: var(--accent);
  background: var(--bg-elev2);
}
.presets {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}
.btn-preset {
  flex: 1;
  padding: 10px 4px;
}
.inline-input {
  display: flex;
  gap: 8px;
}
.inline-input input { flex: 1; min-width: 0; }

.btn-accent {
  background: var(--accent-soft);
  border-color: var(--accent);
  padding: 8px 18px;
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--accent);
  padding: 6px 10px;
}

/* ---------- 体重・睡眠 ---------- */
.metric-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
}
.metric-row label {
  width: 42px;
  font-size: 13px;
  color: var(--text-dim);
  flex-shrink: 0;
}
.metric-row input { width: 110px; }
.unit { font-size: 13px; color: var(--text-dim); }
.saved-flash { font-size: 12px; color: var(--heat-4); }

/* ---------- カレンダー ---------- */
.cal-head {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 0;
}
.cal-head .btn-ghost { font-size: 22px; padding: 2px 16px; }
.cal-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  min-width: 8.5em;
  text-align: center;
}

.cal-week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 4px;
}
.cal-week span {
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
}
.cal-week .sat { color: var(--accent); }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.cal-cell {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--heat-0);
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}
.cal-cell:disabled { visibility: hidden; }
.cal-cell.heat-1 { background: var(--heat-1); }
.cal-cell.heat-2 { background: var(--heat-2); }
.cal-cell.heat-3 { background: var(--heat-3); }
.cal-cell.heat-4 { background: var(--heat-4); }
.cal-cell.heat-5 { background: var(--heat-5); }
.cal-cell.is-today { border: 2px solid var(--accent); }

.cal-daynum {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
/* 明るいマスでは数字を暗くして読めるようにする */
.cal-cell.heat-3 .cal-daynum,
.cal-cell.heat-4 .cal-daynum,
.cal-cell.heat-5 .cal-daynum { color: #0b0f14; font-weight: 600; }

/* 睡眠記録ありの日はマス上部に細ライン */
.cal-cell.has-sleep::before {
  content: '';
  position: absolute;
  top: 3px;
  left: 22%;
  right: 22%;
  height: 2px;
  border-radius: 2px;
  background: var(--sleep-pink);
}

.cal-dots {
  display: flex;
  gap: 3px;
  height: 6px;
}
.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  box-shadow: 0 0 0 1.5px rgba(11, 15, 20, 0.8); /* サーフェスリング: どの濃さのマス上でも判別できる */
}
.dot-strength { background: var(--cat-strength); }
.dot-stretch { background: var(--cat-stretch); }
.dot-cardio { background: var(--cat-cardio); }

/* ---------- 凡例 ---------- */
.legend {
  margin-top: 14px;
  padding: 10px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.legend-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.legend-label {
  width: 38px;
  font-size: 11px;
  color: var(--text-dim);
}
.legend-cell {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  border: 1px solid var(--border);
  display: inline-block;
}
.legend-cell.heat-0 { background: var(--heat-0); }
.legend-cell.heat-1 { background: var(--heat-1); }
.legend-cell.heat-2 { background: var(--heat-2); }
.legend-cell.heat-3 { background: var(--heat-3); }
.legend-cell.heat-4 { background: var(--heat-4); }
.legend-cell.heat-5 { background: var(--heat-5); }
.legend-text { font-size: 11px; color: var(--text-dim); margin-right: 6px; }
.legend-sleepline {
  width: 16px;
  height: 2px;
  border-radius: 2px;
  background: var(--sleep-pink);
  display: inline-block;
}

/* ---------- 統計 ---------- */
.stats-heading {
  margin: 10px 0 4px;
  font-size: 16px;
}
.stats-chart { margin-top: 14px; }
.stats-chart h3 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 6px;
}
.stats-chart svg { display: block; width: 100%; height: auto; }
.stats-legend {
  display: flex;
  gap: 12px;
  margin-top: 6px;
}
.stats-legend span {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-dim);
}
.stats-empty { color: var(--text-dim); font-size: 13px; margin-top: 8px; }

/* ---------- タブバー ---------- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  background: rgba(11, 15, 20, 0.95);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1;
  text-align: center;
  padding: 13px 0;
  font-size: 13px;
  color: var(--text-dim);
  text-decoration: none;
}
.tab.active {
  color: var(--text);
  font-weight: 600;
  border-top: 2px solid var(--accent);
  margin-top: -1px;
}

/* ---------- ボトムシート ---------- */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
}
.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}
.sheet-body {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 82vh;
  overflow-y: auto;
  background: var(--bg-elev);
  border-radius: 16px 16px 0 0;
  border-top: 1px solid var(--border);
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  max-width: 640px;
  margin: 0 auto;
}
.sheet-title {
  margin: 0 0 12px;
  font-size: 16px;
}
.sheet-section {
  margin-bottom: 16px;
}
.sheet-section h4 {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 6px;
}
.sheet-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.sheet-row input[type="datetime-local"] {
  flex: 1 1 120px;
  min-width: 0;
  width: 120px;
  padding: 7px 4px;
  font-size: 14px;
}
.sheet-row .tilde { color: var(--text-dim); }
.sheet-row select { padding: 7px 8px; font-size: 14px; }
.sheet-row input[type="number"] { width: 76px; padding: 7px 8px; font-size: 14px; }
.btn-del {
  color: var(--danger);
  background: transparent;
  border-color: transparent;
  font-size: 16px;
  padding: 6px 6px;
  flex-shrink: 0;
}
.btn-add-row {
  width: 100%;
  padding: 9px;
  color: var(--accent);
  background: transparent;
  border-style: dashed;
}
.sheet-note { font-size: 12px; color: var(--text-dim); }
.sheet-close { width: 100%; margin-top: 4px; padding: 11px; }
.row-live { color: var(--heat-4); font-size: 13px; }

.empty-note { color: var(--text-dim); font-size: 13px; }
