:root {
  color-scheme: light dark;
  --bg: #f2f2f7;
  --cell: #ffffff;
  --label: #000000;
  --label2: rgba(60, 60, 67, 0.6);
  --label3: rgba(60, 60, 67, 0.3);
  --sep: rgba(60, 60, 67, 0.29);
  --fill: rgba(118, 118, 128, 0.12);
  --tint: #007aff;
  --red: #ff3b30;
  --seg-on: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --cell: #1c1c1e;
    --label: #ffffff;
    --label2: rgba(235, 235, 245, 0.6);
    --label3: rgba(235, 235, 245, 0.3);
    --sep: rgba(84, 84, 88, 0.6);
    --fill: rgba(118, 118, 128, 0.24);
    --tint: #0a84ff;
    --red: #ff453a;
    --seg-on: #636366;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--label);
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Hiragino Sans", sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.wrap { max-width: 640px; margin: 0 auto; padding: 0 16px 40px; }
h1 { font-size: 34px; font-weight: 700; letter-spacing: 0.01em; margin: 12px 0 8px; }
.sub { color: var(--label2); font-size: 15px; margin: 0 0 20px; }
.hidden { display: none !important; }

/* 中央寄せの画面（サインイン・登録） */
.center { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: 24px; }
.center .icon { width: 88px; height: 88px; border-radius: 20px; background: var(--tint); display: grid; place-items: center; margin-bottom: 20px; }
.center .icon svg { width: 48px; height: 48px; fill: #fff; }
.center h1 { font-size: 28px; margin: 0 0 8px; }
.center .sub { max-width: 320px; }
.center .btn { width: 100%; max-width: 320px; }

/* ボタン */
.btn {
  appearance: none; border: 0; border-radius: 14px; min-height: 50px; padding: 0 20px;
  font: 600 17px -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--tint); color: #fff; cursor: pointer;
}
.btn:active { opacity: 0.7; }
.btn:disabled { opacity: 0.4; }
.btn.plain { background: transparent; color: var(--tint); font-weight: 400; min-height: 44px; }
.btn.danger { background: transparent; color: var(--red); font-weight: 400; }
.msg { min-height: 22px; margin-top: 14px; font-size: 15px; color: var(--label2); }
.msg.err { color: var(--red); }

/* 上の帯 */
.top { display: flex; justify-content: flex-end; padding-top: 8px; }
.stats { display: flex; gap: 12px; margin: 4px 0 16px; }
.stat { flex: 1; background: var(--cell); border-radius: 14px; padding: 12px 14px; }
.stat .n { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 13px; color: var(--label2); }

/* セグメント */
.seg { display: flex; background: var(--fill); border-radius: 9px; padding: 2px; margin-bottom: 16px; }
.seg button {
  flex: 1; appearance: none; border: 0; background: transparent; color: var(--label);
  font: 500 14px -apple-system, sans-serif; min-height: 32px; border-radius: 7px; cursor: pointer;
}
.seg button[aria-selected="true"] { background: var(--seg-on); box-shadow: 0 3px 8px rgba(0,0,0,0.12), 0 3px 1px rgba(0,0,0,0.04); font-weight: 600; }

/* 年の絞り込み */
.chips { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 8px; }
.chips button {
  appearance: none; border: 0; border-radius: 999px; padding: 6px 14px; min-height: 32px;
  background: var(--fill); color: var(--label); font: 15px -apple-system, sans-serif; cursor: pointer; white-space: nowrap;
}
.chips button[aria-pressed="true"] { background: var(--tint); color: #fff; }

/* 角丸の一覧 */
.section-h { font-size: 13px; color: var(--label2); text-transform: uppercase; margin: 22px 16px 6px; }
.list { background: var(--cell); border-radius: 12px; overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 11px 16px; position: relative;
  width: 100%; border: 0; background: transparent; color: inherit; font: inherit; text-align: left;
}
button.row { cursor: pointer; }
button.row:active { background: var(--fill); }
.row + .row::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: 0.5px solid var(--sep); }
.row .main { flex: 1; min-width: 0; }
.row .date { color: var(--label2); font-variant-numeric: tabular-nums; min-width: 92px; }
.row .val { color: var(--label2); font-variant-numeric: tabular-nums; }
.row .chev { color: var(--label3); font-size: 15px; }
.row .bar { height: 6px; border-radius: 3px; background: var(--tint); margin-top: 6px; opacity: 0.85; }
.row .small { font-size: 13px; color: var(--label2); }

/* フォーム */
.field { display: flex; align-items: center; min-height: 44px; padding: 6px 16px; position: relative; gap: 12px; }
.field + .field::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: 0.5px solid var(--sep); }
.field label { flex: 0 0 72px; }
.field input, .field select {
  flex: 1; min-width: 0; appearance: none; -webkit-appearance: none; border: 0; background: transparent;
  color: var(--label); font: 17px -apple-system, sans-serif; text-align: right; min-height: 32px;
}
.field select { direction: rtl; }
.field input:focus, .field select:focus { outline: none; }
.form-actions { margin-top: 20px; display: flex; flex-direction: column; gap: 10px; }
.form-actions .btn { width: 100%; }

/* シート */
dialog {
  border: 0; padding: 0; width: 100%; max-width: 640px; margin: auto auto 0; border-radius: 16px 16px 0 0;
  background: var(--bg); color: var(--label); max-height: 90dvh;
}
@media (min-width: 700px) { dialog { margin: auto; border-radius: 16px; } }
dialog::backdrop { background: rgba(0,0,0,0.35); }
.sheet { padding: 8px 16px calc(24px + env(safe-area-inset-bottom)); }
.sheet-bar { display: flex; justify-content: space-between; align-items: center; min-height: 52px; }
.sheet-bar h2 { font-size: 17px; font-weight: 600; margin: 0; }
.empty { text-align: center; color: var(--label2); padding: 40px 0; }
#edit-save { font-weight: 600; }
#edit-delete { background: var(--cell); }
