:root {
  --bg: #f6f7f5;
  --card: #ffffff;
  --text: #1d2420;
  --muted: #6b756f;
  --line: #e3e7e4;
  --accent: #1f6f4a;
  --accent-soft: #e2f1e8;
  --sun: #d23c3c;
  --sat: #2f6fca;
  --warn: #b26a00;
  --warn-soft: #fff3df;
  --danger: #c62828;
  --danger-soft: #fdeaea;
  --today: #1f6f4a;
  --radius: 14px;
  --tab-h: 62px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111513;
    --card: #1b211e;
    --text: #e7ece9;
    --muted: #94a19a;
    --line: #2c3430;
    --accent: #5cc08e;
    --accent-soft: #1d3428;
    --sun: #ff7b7b;
    --sat: #79a8ff;
    --warn: #ffb547;
    --warn-soft: #3a2c12;
    --danger: #ff6b6b;
    --danger-soft: #3a1b1b;
    --today: #5cc08e;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.boot { padding: 40vh 0; text-align: center; color: var(--muted); }

/* ---------- レイアウト ---------- */
.view {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 14px calc(var(--tab-h) + env(safe-area-inset-bottom, 0px) + 20px);
}
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tabs button {
  flex: 1; max-width: 160px; height: var(--tab-h);
  border: 0; background: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px;
}
.tabs button svg { width: 24px; height: 24px; }
.tabs button.on { color: var(--accent); font-weight: 600; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.card h2 { font-size: 14px; margin: 0 0 10px; color: var(--muted); font-weight: 600; }
.card h3 { font-size: 14px; margin: 14px 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

/* ---------- ヘッダー（月移動） ---------- */
.monthbar { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.monthbar h1 { flex: 1; font-size: 20px; margin: 0; text-align: center; font-variant-numeric: tabular-nums; }
.iconbtn {
  width: 40px; height: 40px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card);
  display: grid; place-items: center; font-size: 18px;
}
.pill {
  height: 32px; padding: 0 12px; border-radius: 16px;
  border: 1px solid var(--line); background: var(--card); font-size: 13px;
}

/* ---------- サマリ帯 ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 8px 10px; text-align: left; border-width: 1px;
}
.stat .k { font-size: 11px; color: var(--muted); }
.stat .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat .v small { font-size: 12px; font-weight: 500; margin-left: 2px; }
.stat.warn { border-color: var(--warn); background: var(--warn-soft); }
.stat.danger { border-color: var(--danger); background: var(--danger-soft); }

/* ---------- カレンダー ---------- */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal .dow { text-align: center; font-size: 11px; color: var(--muted); padding: 2px 0; }
.cal .dow.sun { color: var(--sun); }
.cal .dow.sat { color: var(--sat); }
.day {
  position: relative;
  min-height: 64px; padding: 3px 2px 4px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  overflow: hidden;
}
.day.empty { border: 0; background: none; }
.day .n { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.3; }
.day.sun .n, .day.hol .n { color: var(--sun); }
.day.sat .n { color: var(--sat); }
.day.today { outline: 2px solid var(--today); outline-offset: -2px; }
.day .hn { font-size: 9px; color: var(--sun); line-height: 1.1; text-align: center; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.day .lv {
  font-size: 10px; font-weight: 700; color: #fff; border-radius: 6px;
  padding: 1px 4px; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.day .memo { font-size: 9px; color: var(--muted); line-height: 1.15; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.day .dot { position: absolute; top: 4px; right: 4px; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 10px; margin-top: 10px; font-size: 11px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }

/* ---------- 入力シート ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-width: 640px; margin: 0 auto;
  background: var(--card); border-radius: 18px 18px 0 0;
  padding: 10px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  max-height: 88vh; overflow-y: auto;
  box-shadow: 0 -8px 30px rgba(0,0,0,.15);
}
.sheet .grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 10px; }
.sheet .head { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.sheet .head h2 { flex: 1; text-align: center; margin: 0; font-size: 18px; }
.sheet .hol { text-align: center; color: var(--sun); font-size: 13px; margin: -4px 0 8px; }
.label { font-size: 12px; color: var(--muted); margin: 12px 0 6px; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 38px; padding: 0 14px; border-radius: 19px;
  border: 1.5px solid var(--line); background: var(--card); font-size: 14px;
}
.chip.on { color: #fff; border-color: transparent; font-weight: 600; }
.chip.preset { min-height: 32px; padding: 0 12px; font-size: 13px; }
.chip.preset.on { background: var(--accent); }
input[type=text], input[type=date], input[type=number], input[type=password], select, textarea {
  width: 100%; min-height: 42px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  font-size: 16px; /* iOSのズーム防止 */
}
textarea { min-height: 64px; resize: vertical; }
.actions { display: flex; gap: 10px; margin-top: 16px; }
.btn {
  min-height: 46px; padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }

/* ---------- サマリ画面 ---------- */
.big { font-size: 40px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.big small { font-size: 16px; font-weight: 600; margin-left: 4px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.alert { border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; font-size: 14px; }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.danger { background: var(--danger-soft); color: var(--danger); }
.alert.ok { background: var(--accent-soft); color: var(--accent); }
.bar { height: 10px; border-radius: 5px; background: var(--line); overflow: hidden; margin: 8px 0 4px; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 5px; }
.bar.warn > span { background: var(--warn); }
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
tr.dim td { color: var(--muted); }
.tag { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 6px; background: var(--line); color: var(--muted); }
.counts { display: flex; flex-wrap: wrap; gap: 6px; }
.count { display: flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 10px; background: var(--bg); font-size: 13px; }
.count i { width: 8px; height: 8px; border-radius: 50%; }

/* ---------- 月別一覧 ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 10px; padding: 10px 2px; border-bottom: 1px solid var(--line); align-items: flex-start; }
.list li:last-child { border-bottom: 0; }
.list .d { width: 62px; flex-shrink: 0; font-variant-numeric: tabular-nums; font-weight: 600; }
.list .d.sun, .list .d.hol { color: var(--sun); }
.list .d.sat { color: var(--sat); }
.list .badge { font-size: 12px; color: #fff; border-radius: 6px; padding: 1px 6px; font-weight: 600; }
.list .notes { font-size: 13px; color: var(--muted); word-break: break-all; }

/* ---------- 設定 ---------- */
.field { margin-bottom: 12px; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.field .hint { font-size: 11px; color: var(--muted); margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.trow { display: grid; grid-template-columns: 1fr 110px 44px 36px; gap: 6px; align-items: center; margin-bottom: 6px; }
.trow input[type=color] { width: 44px; height: 42px; border: 1px solid var(--line); border-radius: 10px; padding: 3px; background: var(--bg); }
.lrow { display: grid; grid-template-columns: 1fr 90px 36px; gap: 6px; align-items: center; margin-bottom: 6px; }
.del { width: 36px; height: 42px; border: 0; background: none; color: var(--danger); font-size: 20px; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; }
.btns .btn { flex: 1 1 140px; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }

/* ---------- ログイン ---------- */
.login { max-width: 360px; margin: 18vh auto 0; padding: 0 20px; }
.login h1 { text-align: center; font-size: 26px; margin: 0 0 4px; }
.login p { text-align: center; margin: 0 0 24px; }
.check { display: flex; align-items: center; gap: 8px; margin: 8px 0 16px; font-size: 14px; }
.check input { width: 20px; height: 20px; }
.err { color: var(--danger); font-size: 14px; min-height: 20px; margin-bottom: 8px; }

/* ---------- トースト ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px) + 14px);
  background: #222; color: #fff; padding: 10px 16px; border-radius: 12px;
  font-size: 14px; z-index: 60; max-width: 90vw; box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.toast.error { background: var(--danger); }
