:root {
  --bg: #f4f2ec;
  --surface: #ffffff;
  --ink: #1f2a24;
  --muted: #6b7069;
  --line: #e2dfd6;
  --brand: #1f6f4a;
  --brand-2: #2f9467;
  --brand-soft: #e3f1e9;
  --warn: #c8641d;
  --warn-soft: #fbeadc;
  --danger: #b6382e;
  --heat-0: #eef0ea;
  --heat-1: #cfe6d8;
  --heat-2: #8fcbaa;
  --heat-3: #43a072;
  --heat-4: #1a6b45;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(30, 40, 35, 0.06);
  --tabs-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121714;
    --surface: #1b221e;
    --ink: #e8ece8;
    --muted: #98a19a;
    --line: #2c3530;
    --brand: #4cc28a;
    --brand-2: #6fd4a3;
    --brand-soft: #1d3328;
    --warn: #f0a060;
    --warn-soft: #3a2a1c;
    --danger: #f07a70;
    --heat-0: #222a25;
    --heat-1: #1f4632;
    --heat-2: #24704a;
    --heat-3: #35a06b;
    --heat-4: #6fdca2;
    --shadow: none;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: clamp(14px, 4vw, 16px); -webkit-text-size-adjust: 100%; }
body {
  font-family: "Zen Kaku Gothic New", "Hiragino Sans", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  font-size: .94rem;
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px);
  -webkit-font-smoothing: antialiased;
}
.num, .kpi-val, .big-timer { font-family: "Outfit", "Zen Kaku Gothic New", sans-serif; font-variant-numeric: tabular-nums; }

/* ヘッダー */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 14px 16px 10px; background: var(--bg);
}
.brand { font-weight: 700; font-size: 1.15rem; letter-spacing: .02em; }
.brand::before { content: "●"; color: var(--brand); margin-right: 6px; font-size: .8em; }
.top-sub { font-size: .8rem; color: var(--muted); }

main { max-width: 640px; margin: 0 auto; padding: 0 clamp(10px, 4vw, 16px); }
.view { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
.view[hidden] { display: none; }

/* カード */
.card { background: var(--surface); border-radius: var(--radius); padding: clamp(12px, 4vw, 16px); min-width: 0; box-shadow: var(--shadow); }
.card h2 { font-size: .95rem; margin-bottom: 12px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card h2 small { font-weight: 400; color: var(--muted); font-size: .78rem; }
.hint { font-size: .78rem; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 18px 0; font-size: .9rem; }

/* タイマー */
.timer-card { background: var(--ink); color: var(--bg); }
@media (prefers-color-scheme: dark) { .timer-card { background: var(--brand-soft); color: var(--ink); } }
.timer-card .hint { color: inherit; opacity: .7; }
.big-timer { font-size: clamp(2rem, 11vw, 2.6rem); font-weight: 700; letter-spacing: .02em; line-height: 1.1; margin: 4px 0 12px; }
.timer-row { display: flex; gap: 10px; align-items: center; }
.timer-row select { flex: 1; min-width: 0; }
.timer-row .btn { flex: none; }

/* ボタン */
button { font: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px clamp(10px, 3.5vw, 18px); border-radius: 12px; font-weight: 700; white-space: nowrap;
  background: var(--brand); color: #fff; min-height: 46px;
}
.btn:active { transform: scale(.98); }
.btn.block { width: 100%; }
.btn .i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.warn { background: var(--warn); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid currentColor; }
.btn.small { padding: 6px 12px; min-height: 34px; font-size: .85rem; font-weight: 500; }
.link-btn { color: var(--brand); font-size: .82rem; font-weight: 700; }

/* フォーム */
.form { display: grid; gap: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.grid3 input { padding-inline: 8px; font-size: 15px; }
label.f { display: grid; gap: 4px; font-size: .78rem; color: var(--muted); font-weight: 500; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; width: 100%; min-width: 0; min-height: 44px; font-size: 16px;
}
/* iPhone の日付・時刻欄がはみ出さないように */
input[type="date"], input[type="time"] { -webkit-appearance: none; appearance: none; display: block; text-align: left; }
input::-webkit-date-and-time-value { text-align: left; }
label.f { grid-template-columns: minmax(0, 1fr); min-width: 0; }
.form { grid-template-columns: minmax(0, 1fr); }
.yen-input { display: block; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); border-color: transparent; }
.timer-card select { background: rgba(255,255,255,.1); color: inherit; border-color: rgba(255,255,255,.2); }
@media (prefers-color-scheme: dark) { .timer-card select { background: var(--surface); } }
.yen-input { position: relative; }
.yen-input input { padding-left: 26px; }
.yen-input::before { content: "¥"; position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: .9rem; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line);
  font-size: .85rem; background: var(--bg);
}
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 700; }

/* KPI */
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi { background: var(--bg); border-radius: 12px; padding: 10px 12px; }
.kpi-label { font-size: .74rem; color: var(--muted); }
.kpi-val { font-size: clamp(1.1rem, 5.5vw, 1.35rem); overflow-wrap: anywhere; font-weight: 700; line-height: 1.3; }
.kpi-val small { font-size: .75rem; font-weight: 500; color: var(--muted); margin-left: 2px; }
.kpi.hero { grid-column: 1 / -1; background: var(--brand-soft); }
.kpi.hero .kpi-val { font-size: clamp(1.5rem, 8vw, 1.9rem); color: var(--brand); }

/* 数値カード */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.stat {
  display: flex; flex-direction: column; align-items: stretch; gap: 2px; text-align: left;
  background: var(--surface); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow);
  border: 1px solid transparent; transition: border-color .15s, transform .1s; min-width: 0;
}
.stat:hover { border-color: var(--line); }
.stat:active { transform: scale(.98); }
.stat-label { display: flex; justify-content: space-between; font-size: .76rem; color: var(--muted); }
.chev { font-size: 1rem; line-height: 1; opacity: .6; }
.stat-val { font-size: clamp(1.25rem, 6vw, 1.6rem); font-weight: 700; line-height: 1.25; overflow-wrap: anywhere; }
.diff { font-size: .8rem; font-weight: 700; }
.diff small { font-weight: 400; color: var(--muted); margin-left: 4px; font-size: .7rem; }
.diff.up { color: #1f8a52; }
.diff.down { color: #c8372d; }
.diff.flat { color: var(--muted); font-weight: 400; font-size: .72rem; }
@media (prefers-color-scheme: dark) { .diff.up { color: #5fd398; } .diff.down { color: #ff7d73; } }
.spark { width: 100%; height: 24px; margin-top: 6px; }
.spark polyline { fill: none; stroke: var(--brand-2); stroke-width: 1.8; vector-effect: non-scaling-stroke; stroke-linejoin: round; stroke-linecap: round; }
.stat .bar { margin: 8px 0 2px; height: 7px; }
.stat-note { font-size: .7rem; color: var(--muted); }
.bar.over > i { background: #c8372d; }
.sub-stats { font-size: .8rem; color: var(--muted); text-align: center; margin-top: -4px; }
.sub-stats b { color: var(--ink); font-family: "Outfit", sans-serif; }

/* 進捗バー */
.bar { height: 10px; background: var(--bg); border-radius: 99px; overflow: hidden; margin: 8px 0 6px; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 99px; transition: width .4s; }
.bar.warn > i { background: var(--warn); }
.bar-meta { display: flex; justify-content: space-between; font-size: .8rem; color: var(--muted); }

/* リスト */
.list { display: grid; }
.row {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: center;
  padding: 10px 0; border-top: 1px solid var(--line);
}
.row:first-child { border-top: 0; }
.row-main { font-weight: 700; font-size: .92rem; }
.row-sub { font-size: .76rem; color: var(--muted); grid-column: 1; }
.row-amt { font-weight: 700; text-align: right; }
.row-actions { grid-row: span 2; display: flex; gap: 4px; align-items: center; }
.row-right { grid-row: 1 / span 2; grid-column: 2; display: flex; align-items: center; gap: 8px; }
.icon-btn { width: 32px; height: 32px; border-radius: 8px; color: var(--muted); font-size: 1rem; }
.icon-btn:hover { background: var(--bg); color: var(--ink); }
/* サービスの色分け */
.pc0 { --pc-bg: #e3f1e9; --pc-fg: #1f6f4a; }
.pc1 { --pc-bg: #fde6dc; --pc-fg: #b8461f; }
.pc2 { --pc-bg: #e1ecfb; --pc-fg: #2459a8; }
.pc3 { --pc-bg: #ece5f8; --pc-fg: #6a3fb0; }
.pc4 { --pc-bg: #fbf0d4; --pc-fg: #876000; }
.pc5 { --pc-bg: #dcf3f3; --pc-fg: #17716f; }
.pc6 { --pc-bg: #fbe3ee; --pc-fg: #a83266; }
.pc7 { --pc-bg: #e8eaed; --pc-fg: #4a5563; }
@media (prefers-color-scheme: dark) {
  .pc0 { --pc-bg: #1d3328; --pc-fg: #6fd4a3; }
  .pc1 { --pc-bg: #3d2219; --pc-fg: #f59a78; }
  .pc2 { --pc-bg: #1a2a42; --pc-fg: #86b3f2; }
  .pc3 { --pc-bg: #2b2240; --pc-fg: #bba0f0; }
  .pc4 { --pc-bg: #3a3015; --pc-fg: #f0c75e; }
  .pc5 { --pc-bg: #15393a; --pc-fg: #6ad6d2; }
  .pc6 { --pc-bg: #3e1d2c; --pc-fg: #f290bd; }
  .pc7 { --pc-bg: #2a2f36; --pc-fg: #b5bcc6; }
}
.tag[class*="pc"] { background: var(--pc-bg); color: var(--pc-fg); }
.row.svc { border-left: 4px solid var(--pc-fg); padding-left: 10px; margin-left: -4px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--pc-fg); margin-right: 6px; vertical-align: 1px; }
.tag { display: inline-block; font-size: .7rem; padding: 1px 7px; border-radius: 99px; background: var(--brand-soft); color: var(--brand); font-weight: 700; margin-right: 4px; }

/* テーブル */
table { width: 100%; border-collapse: collapse; font-size: .86rem; }
th { text-align: left; color: var(--muted); font-weight: 500; font-size: .74rem; padding: 6px 4px; border-bottom: 1px solid var(--line); }
td { padding: 8px 4px; border-bottom: 1px solid var(--line); }
td.r, th.r { text-align: right; }
tr.total td { font-weight: 700; border-bottom: 0; }
/* 移動先の金額を2秒だけ薄く光らせる */
:root { --flash: rgba(255, 214, 102, .45); }
@media (prefers-color-scheme: dark) { :root { --flash: rgba(255, 214, 102, .22); } }
@keyframes flash { 0%, 100% { background-color: transparent; } 15%, 70% { background-color: var(--flash); } }
.flash, tr.flash td { animation: flash 2s ease; border-radius: 6px; }
#daily-total { padding: 1px 4px; }
.exp-total-card .cur { text-align: center; }
.cur-label { font-size: .78rem; color: var(--muted); font-weight: 500; }
.cur-amt { font-size: clamp(1.5rem, 7vw, 1.8rem); font-weight: 700; color: var(--brand); padding: 0 8px; display: inline-block; }

/* チャート */
.chart svg { width: 100%; height: auto; display: block; }
.chart .axis { fill: var(--muted); font-size: 9px; font-family: "Outfit", sans-serif; }
.chart .barfill { fill: var(--brand-2); }
.chart .goal-line { stroke: var(--warn); stroke-dasharray: 4 3; stroke-width: 1; }

.heat { display: grid; grid-template-columns: 18px repeat(24, minmax(0, 1fr)); gap: 1.5px; font-size: 9px; }
.heat .hl { color: var(--muted); display: flex; align-items: center; font-family: "Outfit", sans-serif; }
.heat .hh { color: var(--muted); text-align: left; overflow: visible; white-space: nowrap; font-family: "Outfit", sans-serif; }
.heat .c { aspect-ratio: 1 / 1.25; border-radius: 3px; background: var(--heat-0); }
.heat .c[data-l="1"] { background: var(--heat-1); }
.heat .c[data-l="2"] { background: var(--heat-2); }
.heat .c[data-l="3"] { background: var(--heat-3); }
.heat .c[data-l="4"] { background: var(--heat-4); }
.legend { display: flex; align-items: center; gap: 4px; justify-content: flex-end; font-size: .72rem; color: var(--muted); margin-top: 8px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.best { margin-top: 10px; font-size: .86rem; background: var(--brand-soft); padding: 10px 12px; border-radius: 10px; }
.best b { color: var(--brand); }

.month-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.month-nav .cur { font-weight: 700; font-size: 1.05rem; }

.notice { font-size: .78rem; color: var(--muted); background: var(--bg); border-radius: 10px; padding: 10px 12px; line-height: 1.7; }
.alert { background: var(--warn-soft); color: var(--warn); font-size: .85rem; padding: 10px 12px; border-radius: 10px; font-weight: 700; }

/* 設定の一覧編集 */
.edit-rows { display: grid; gap: 8px; }
.edit-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; align-items: center; }
.edit-row:has(.er-ratio) { grid-template-columns: minmax(0, 1fr) 84px auto; }
.chip small { opacity: .7; }

/* タブ */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  bottom: var(--badge-h, 0px);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabs button { display: grid; place-items: center; align-content: center; gap: 0; font-size: .7rem; color: var(--muted); }
.tabs .ti { font-size: 1.2rem; line-height: 1.2; }
.tabs button.active { color: var(--brand); font-weight: 700; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + 20px); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 99px; font-size: .88rem;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 20; white-space: nowrap;
}
/* Netlify のバッジ用の余白（バッジの上にタブを置く） */
body.has-badge { --badge-h: 64px; padding-bottom: calc(var(--tabs-h) + 64px + env(safe-area-inset-bottom) + 16px); }
body.has-badge::after { content: ""; position: fixed; left: 0; right: 0; bottom: 0; height: 64px; background: var(--surface); z-index: 9; }
body.has-badge .tabs { padding-bottom: 0; height: var(--tabs-h); }
body.has-badge .toast { bottom: calc(var(--tabs-h) + 84px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 359px) {
  .timer-row { flex-direction: column; align-items: stretch; }
  .kpis { grid-template-columns: minmax(0, 1fr); }
  .edit-row:has(.er-ratio) { grid-template-columns: minmax(0, 1fr) 74px auto; }
  .tabs button { font-size: .62rem; }
}

@media (min-width: 700px) {
  .kpis { grid-template-columns: repeat(4, 1fr); }
  .kpi.hero { grid-column: span 2; }
}
