:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e3e6eb;
  --text: #1b1f24;
  --text-2: #5b6470;
  --text-3: #8a929c;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --accent-soft: #e6eefc;
  --danger: #c62828;
  --warn-bg: #fff4e0;
  --warn-ink: #8a5300;
  --ok: #1b8a4b;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 4px 16px rgba(0, 0, 0, 0.06);
  --radius: 14px;
  --tab-h: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111315;
    --surface: #1b1e21;
    --surface-2: #24282c;
    --border: #2f3439;
    --text: #eef0f2;
    --text-2: #aab2bc;
    --text-3: #7b848e;
    --accent: #4b86f0;
    --accent-soft: #1e2b44;
    --danger: #ef5350;
    --warn-bg: #3a2c12;
    --warn-ink: #f3c27a;
    --ok: #4cc27f;
    --series-1: #3987e5;
    --series-2: #d95926;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

#app { max-width: 720px; margin: 0 auto; padding: 0 16px calc(var(--tab-h) + var(--safe-b) + 88px); }
.boot { padding: 40vh 0; text-align: center; color: var(--text-3); }

/* ヘッダー */
.head {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 0 10px;
  background: var(--bg);
}
.head h1 { font-size: 20px; margin: 0; flex: 1; min-width: 0; }
.head .sub { font-size: 13px; color: var(--text-2); font-weight: normal; }

/* 下部タブ */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: var(--safe-b);
}
.tabs a {
  flex: 1; max-width: 144px; height: var(--tab-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--text-3); text-decoration: none; font-size: 11px;
}
.tabs a svg { width: 24px; height: 24px; }
.tabs a.on { color: var(--accent); }

/* 共通部品 */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin: 10px 0; }
.section-title { font-size: 13px; color: var(--text-2); margin: 20px 4px 6px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.empty { color: var(--text-3); text-align: center; padding: 24px 0; font-size: 14px; }
.row { display: flex; align-items: center; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.wrap { flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer;
  font-weight: 600; font-size: 15px; text-decoration: none; color: var(--text);
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.icon-btn svg { width: 20px; height: 20px; }

.fab {
  position: fixed; right: max(16px, calc(50% - 344px)); bottom: calc(var(--tab-h) + var(--safe-b) + 16px); z-index: 9;
  width: 56px; height: 56px; border-radius: 28px; border: 0;
  background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.fab svg { width: 28px; height: 28px; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.chip {
  flex: none; min-height: 34px; padding: 0 14px; border-radius: 17px; border: 1px solid var(--border);
  background: var(--surface); font-size: 14px; cursor: pointer; white-space: nowrap;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; min-height: 32px; padding: 0 14px; border-radius: 8px; cursor: pointer; font-size: 14px; color: var(--text-2); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }

/* フォーム */
label.field { display: block; margin: 12px 0; }
label.field > span { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=date], input[type=time], input[type=number], select, textarea {
  width: 100%; min-height: 44px; padding: 8px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); font-size: 16px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.two > label.field { margin: 0; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.wd-pick { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.wd-pick label { display: flex; align-items: center; justify-content: center; height: 40px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; font-size: 14px; }
.wd-pick input { display: none; }
.wd-pick label:has(input:checked) { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.error { color: var(--danger); font-size: 14px; margin: 8px 0; }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--border); border-radius: 15px; transition: 0.2s; cursor: pointer; }
.switch span::before { content: ''; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px; border-radius: 50%; background: #fff; transition: 0.2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(20px); }

/* 予定の行 */
.ev {
  display: flex; gap: 10px; align-items: stretch; width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 12px; margin: 6px 0; cursor: pointer;
}
.ev .bar { width: 4px; border-radius: 2px; background: var(--text-3); flex: none; }
.ev .time { font-size: 13px; color: var(--text-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.ev .title { font-weight: 600; overflow-wrap: anywhere; }
.ev .meta { font-size: 12px; color: var(--text-2); display: flex; flex-wrap: wrap; gap: 4px 8px; margin-top: 2px; }
.ev.done .title { text-decoration: line-through; color: var(--text-3); }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 1px 8px; border-radius: 10px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge.warn { background: var(--warn-bg); color: var(--warn-ink); }
.badge.ok { color: var(--ok); }
.avatar { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border-radius: 50%; font-size: 11px; font-weight: 700; color: #fff; flex: none; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; }

/* カレンダー */
.cal-nav { display: flex; align-items: center; gap: 8px; margin: 4px 0 8px; }
.cal-nav .label { flex: 1; text-align: center; font-weight: 700; }
.month-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.month-grid .wd { text-align: center; font-size: 12px; color: var(--text-2); padding: 4px 0; }
.month-grid .cell {
  min-height: 74px; background: var(--surface); border-radius: 8px; padding: 3px; cursor: pointer;
  border: 1px solid transparent; overflow: hidden; text-align: left;
}
.month-grid .cell.other { opacity: 0.4; }
.month-grid .cell.today { border-color: var(--accent); }
.month-grid .num { font-size: 12px; font-weight: 600; padding-left: 2px; }
.month-grid .mini { display: block; font-size: 10px; line-height: 1.35; border-radius: 4px; padding: 0 3px; margin-top: 2px; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.month-grid .more { font-size: 10px; color: var(--text-2); padding-left: 2px; }
.sun { color: #d64545; } .sat { color: #2f6fd6; }
.week-day { margin: 8px 0 2px; font-weight: 700; font-size: 14px; display: flex; gap: 6px; align-items: baseline; }
.week-day.today { color: var(--accent); }
.timeline { position: relative; border-left: 1px solid var(--border); margin-left: 44px; }
.timeline .hour { position: relative; height: 48px; border-top: 1px dashed var(--border); }
.timeline .hour span { position: absolute; left: -44px; top: -9px; font-size: 11px; color: var(--text-3); width: 38px; text-align: right; }
.timeline .blk { position: absolute; left: 4px; right: 4px; border-radius: 8px; color: #fff; font-size: 12px; padding: 2px 6px; overflow: hidden; cursor: pointer; border: 1px solid rgba(255,255,255,0.6); }
.timeline .now { position: absolute; left: -4px; right: 0; height: 2px; background: var(--danger); }

/* シート（下から出るモーダル） */
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto;
  background: var(--bg); border-radius: 18px 18px 0 0; padding: 8px 16px calc(var(--safe-b) + 20px);
  animation: up 0.18s ease-out;
}
@media (min-width: 700px) { .backdrop { align-items: center; } .sheet { border-radius: 18px; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet .grab { width: 36px; height: 5px; border-radius: 3px; background: var(--border); margin: 0 auto 8px; }
.sheet h2 { font-size: 18px; margin: 4px 0 10px; }
.sheet .actions { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }

/* 進捗 */
.progress-value { font-size: 44px; font-weight: 800; text-align: center; font-variant-numeric: tabular-nums; }
input[type=range] { width: 100%; height: 36px; accent-color: var(--accent); }
.quick { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.pbar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.pbar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

/* 組み換え案 */
.plan { display: block; width: 100%; text-align: left; background: var(--surface); border: 2px solid var(--border); border-radius: 14px; padding: 12px 14px; margin: 8px 0; cursor: pointer; }
.plan.on { border-color: var(--accent); background: var(--accent-soft); }
.plan .no { font-size: 12px; color: var(--accent); font-weight: 700; }
.plan .when { font-size: 17px; font-weight: 700; }
.plan .load { font-size: 13px; color: var(--text-2); }

/* 変更の確認・履歴 */
.change { padding: 10px 0; border-top: 1px solid var(--border); }
.change:first-child { border-top: 0; }
.change .from { color: var(--text-2); font-size: 14px; text-decoration: line-through; }
.change .to { font-weight: 600; font-size: 14px; }
.warnbox { background: var(--warn-bg); color: var(--warn-ink); border-radius: 12px; padding: 10px 12px; margin: 10px 0; font-size: 14px; }
.warnbox ul { margin: 4px 0 0; padding-left: 20px; }
.hist-head { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--text-2); }
.kind { font-size: 12px; font-weight: 700; padding: 1px 8px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); }
.kind.undo { background: var(--surface-2); color: var(--text-2); }

/* 達成度 */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px; }
.kpi .v { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: 12px; color: var(--text-2); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-2); margin: 4px 0 8px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 4px; }
.hbar-row { display: grid; grid-template-columns: 76px 1fr; gap: 8px; align-items: center; padding: 6px 0; border-top: 1px solid var(--border); }
.hbar-row:first-of-type { border-top: 0; }
.hbar-row .name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-row .cnt { font-size: 11px; color: var(--text-3); }
.hbar { display: grid; grid-template-columns: 1fr 42px; align-items: center; gap: 6px; margin: 2px 0; cursor: default; }
.hbar .track { height: 12px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.hbar .fill { height: 100%; border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar .fill.tex { background-image: repeating-linear-gradient(45deg, rgba(255,255,255,0.55) 0 2px, transparent 2px 6px); }
.hbar .val { font-size: 12px; text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }
.hbar.na .val { color: var(--text-3); }
.stats-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.stats-table th, .stats-table td { padding: 4px 6px; border-top: 1px solid var(--border); text-align: right; }
.stats-table th:first-child, .stats-table td:first-child { text-align: left; }
details summary { cursor: pointer; font-size: 13px; color: var(--text-2); padding: 6px 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--safe-b) + 84px); transform: translateX(-50%);
  background: #222; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 30;
  opacity: 0; pointer-events: none; transition: opacity 0.2s; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; }

.login { max-width: 380px; margin: 0 auto; padding-top: 12vh; }
.login h1 { text-align: center; font-size: 24px; }
.login .logo { display: block; width: 64px; height: 64px; margin: 0 auto 8px; border-radius: 14px; }
