:root {
  color-scheme: light dark;
  --bg: #f6f6f4;
  --card: #ffffff;
  --fg: #1c1c1a;
  --muted: #6b6b66;
  --line: #e2e2dd;
  --accent: #2e86ab;
  --danger: #c0392b;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --card: #212327;
    --fg: #ececea;
    --muted: #9a9a95;
    --line: #33353a;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Noto Sans JP", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  padding-bottom: 76px;
}
header {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
  padding: 14px 16px 8px;
  border-bottom: 1px solid var(--line);
}
header h1 { font-size: 1.05rem; margin: 0; font-weight: 600; letter-spacing: .02em; }
header .status { font-size: .8rem; color: var(--muted); }
main { padding: 16px; max-width: 720px; margin: 0 auto; }
section[hidden] { display: none; }
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin-bottom: 14px;
}
.card h2 { font-size: .95rem; margin: 0 0 10px; font-weight: 600; }
.muted { color: var(--muted); font-size: .85rem; }

/* 科目ボタン */
.subject-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.subject-btn {
  display: flex; flex-direction: column; gap: 4px; align-items: flex-start;
  border: 1px solid var(--line); background: var(--card); color: var(--fg);
  border-radius: var(--radius); padding: 14px; cursor: pointer; text-align: left;
  font-size: 1rem; min-height: 76px; transition: transform .08s ease;
}
.subject-btn:active { transform: scale(.97); }
.subject-btn .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.subject-btn .sub { font-size: .75rem; color: var(--muted); }

/* 計測中 */
.running { border-left: 4px solid var(--accent); }
.timer { font-size: 2.6rem; font-variant-numeric: tabular-nums; font-weight: 600; margin: 4px 0; }

button, .btn {
  font: inherit; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--fg); padding: 10px 14px; cursor: pointer;
}
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.danger { color: var(--danger); }
button:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

label { display: block; font-size: .85rem; color: var(--muted); margin: 10px 0 4px; }
input, select, textarea {
  font: inherit; width: 100%; padding: 10px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--fg);
}
textarea { min-height: 64px; resize: vertical; }

/* 理解度 */
.rating { display: flex; gap: 8px; }
.rating button { flex: 1; padding: 12px 0; font-size: 1.05rem; }
.rating button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ヒートマップ */
.heatmap-wrap { overflow-x: auto; padding-bottom: 6px; }
.heatmap { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 12px); gap: 3px; }
.heatmap i { width: 12px; height: 12px; border-radius: 3px; background: var(--line); display: block; }
.legend { display: flex; gap: 4px; align-items: center; font-size: .75rem; color: var(--muted); margin-top: 8px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: block; }

/* 進捗バー */
.bar { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; margin-top: 4px; }
.bar > span { display: block; height: 100%; border-radius: 4px; }
.subject-row { padding: 10px 0; border-bottom: 1px solid var(--line); }
.subject-row:last-child { border-bottom: none; }
.subject-row .head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.subject-row .name { font-weight: 600; font-size: .95rem; }

/* 一覧 */
.session { padding: 10px 0; border-bottom: 1px solid var(--line); }
.session:last-child { border-bottom: none; }
.session .top { display: flex; justify-content: space-between; gap: 8px; }
.session .note { font-size: .85rem; color: var(--muted); white-space: pre-wrap; }
.day-head { font-size: .8rem; color: var(--muted); margin: 14px 0 2px; font-weight: 600; }

/* 下部ナビ */
nav {
  position: fixed; bottom: 0; left: 0; right: 0; display: flex;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
nav button {
  flex: 1; border: none; border-radius: 0; background: none; color: var(--muted);
  padding: 12px 0 14px; font-size: .78rem;
}
nav button[aria-current="page"] { color: var(--accent); font-weight: 600; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 88px;
  background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 999px;
  font-size: .85rem; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 20;
}
.toast.show { opacity: .95; }
.offline-badge { color: #b26a00; font-size: .8rem; }
