:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --border: #e3e2de;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7974;
  --accent: #2a78d6;
  --series-1: #2a78d6;  /* 距離最短 */
  --series-2: #eb6834;  /* 体感最短 */
  --empty: #f0efec;
  --grid: #e9e8e4;
  --now: #0b0b0b;
  --tip-bg: #0b0b0b;
  --tip-text: #f0efec;
  --critical: #d03b3b;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --border: #2e2e2c;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #8f8e86;
    --accent: #3987e5;
    --series-1: #3987e5;
    --series-2: #d95926;
    --empty: #242422;
    --grid: #2a2a28;
    --now: #f0efec;
    --tip-bg: #f0efec;
    --tip-text: #0b0b0b;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110;
  --surface: #1a1a19;
  --border: #2e2e2c;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #8f8e86;
  --accent: #3987e5;
  --series-1: #3987e5;
  --series-2: #d95926;
  --empty: #242422;
  --grid: #2a2a28;
  --now: #f0efec;
  --tip-bg: #f0efec;
  --tip-text: #0b0b0b;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}
button { font: inherit; color: inherit; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 16px; margin: 0; font-weight: 700; }
.user { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 12px; min-width: 0; }
.user span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; min-width: 0; }

.btn {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px;
  padding: 6px 12px; cursor: pointer;
}
.btn-quiet { padding: 4px 10px; font-size: 12px; }

/* ---- 現在値 ---- */
.now { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 16px; }
.tile .k { font-size: 12px; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.tile .v { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.tile .v small { font-size: 14px; font-weight: 500; margin-left: 2px; }
.tile .s { font-size: 12px; color: var(--muted); }
@media (max-width: 600px) { .now .tile.wide { grid-column: 1 / -1; } }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }

/* ---- コントロール ---- */
.controls { display: flex; flex-wrap: wrap; gap: 10px 20px; margin-bottom: 12px; }
.ctl { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ctl-label { font-size: 12px; color: var(--text-2); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; flex-wrap: wrap; }
.seg button {
  border: 0; background: transparent; padding: 6px 10px; cursor: pointer; font-size: 13px;
  border-right: 1px solid var(--border); min-height: 32px;
}
.seg button:last-child { border-right: 0; }
.seg button.active { background: var(--accent); color: #fff; }

.hm-title { font-size: 15px; margin: 4px 0 8px; }
.status { color: var(--text-2); font-size: 13px; min-height: 0; }
.status.err { color: var(--critical); }
.note { color: var(--muted); font-size: 12px; margin: 8px 0 0; }

/* ---- 凡例 ---- */
.legend { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 12px; font-size: 12px; color: var(--text-2); margin-bottom: 8px; }
.ramp { display: inline-flex; gap: 2px; }
.ramp i { width: 22px; height: 12px; display: inline-block; border-radius: 2px; }
.legend .item { display: inline-flex; align-items: center; gap: 6px; }

/* ---- ヒートマップ ---- */
.hm-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.heatmap { border-collapse: separate; border-spacing: 2px; width: 100%; min-width: 360px; font-variant-numeric: tabular-nums; }
.heatmap th { font-weight: 500; color: var(--text-2); font-size: 12px; padding: 2px 4px; white-space: nowrap; }
.heatmap thead th { position: sticky; top: 0; background: var(--surface); }
.heatmap thead th.weekend { background: var(--empty); border-radius: 4px; }
.heatmap th.today { color: var(--text); font-weight: 700; }
.heatmap tbody th { text-align: right; width: 48px; }
.heatmap tr.now-row th { color: var(--text); font-weight: 700; }
.heatmap tr.now-row th::before { content: "▶ "; font-size: 9px; }
.heatmap td {
  text-align: center; font-size: 12px; height: 26px; min-width: 40px; border-radius: 4px;
  background: var(--empty); color: var(--muted); cursor: default;
}
.heatmap td.has { cursor: pointer; }
.heatmap tr.spacer td { background: transparent; height: 22px; font-size: 11px; color: var(--muted); text-align: left; padding-left: 4px; border-top: 1px dashed var(--border); border-radius: 0; }
.heatmap td.few { font-style: italic; }
.heatmap td.today-now { outline: 2px solid var(--now); outline-offset: -2px; }
.heatmap td:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---- 1日の推移 ---- */
.day-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.date-pick { font-size: 12px; color: var(--text-2); display: inline-flex; align-items: center; gap: 6px; }
.date-pick input { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 4px 6px; }
.day-chart { width: 100%; position: relative; }
.day-chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.day-chart .axis text { fill: var(--muted); font-size: 11px; }
.day-chart .grid line { stroke: var(--grid); stroke-width: 1; }
.day-chart .cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.day-chart .empty { fill: var(--muted); font-size: 13px; }

/* ---- ツールチップ ---- */
.tip {
  position: fixed; z-index: 20; pointer-events: none;
  background: var(--tip-bg); color: var(--tip-text);
  border-radius: 8px; padding: 8px 10px; font-size: 12px; line-height: 1.5;
  max-width: 260px; box-shadow: 0 4px 16px rgba(0,0,0,.18);
  font-variant-numeric: tabular-nums;
}
.tip b { font-weight: 700; }
.tip .row { display: flex; align-items: center; gap: 6px; }

.foot { color: var(--muted); font-size: 11px; text-align: center; padding: 8px 0 24px; }

.login-wrap { min-height: 100vh; display: grid; place-content: center; gap: 12px; text-align: center; color: var(--text-2); }

@media (max-width: 600px) {
  .wrap { padding: 12px 16px; gap: 12px; }
  .card { padding: 12px; }
  .heatmap { min-width: 0; border-spacing: 1px; }
  .heatmap td { min-width: 0; font-size: 11px; height: 24px; }
  .heatmap th { padding: 2px 2px; font-size: 11px; }
  .heatmap tbody th { width: 40px; }
  .tile { padding: 10px 12px; }
  .tile .v { font-size: 24px; }
}
