:root {
  --bg: #f2f2f7;
  --bg-elev: #ffffff;
  --bg-grouped: #f2f2f7;
  --label: #000000;
  --label-2: #3c3c43;
  --label-3: rgba(60, 60, 67, 0.6);
  --label-4: rgba(60, 60, 67, 0.3);
  --sep: rgba(60, 60, 67, 0.18);
  --sep-thin: rgba(60, 60, 67, 0.10);
  --tint: #007aff;
  --tint-bg: rgba(0, 122, 255, 0.10);
  --green: #34c759;
  --orange: #ff9500;
  --red: #ff3b30;
  --pink: #ff2d55;
  --purple: #af52de;
  --teal: #5ac8fa;
  --indigo: #5856d6;
  --yellow: #ffcc00;
  --fill-1: rgba(120, 120, 128, 0.20);
  --fill-2: rgba(120, 120, 128, 0.16);
  --fill-3: rgba(120, 120, 128, 0.12);
  --shadow: 0 1px 0 rgba(0,0,0,0.04), 0 6px 20px rgba(0,0,0,0.04);
  --radius: 14px;
  --radius-lg: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-elev: #1c1c1e;
    --bg-grouped: #000000;
    --label: #ffffff;
    --label-2: #ebebf5;
    --label-3: rgba(235, 235, 245, 0.6);
    --label-4: rgba(235, 235, 245, 0.3);
    --sep: rgba(84, 84, 88, 0.65);
    --sep-thin: rgba(84, 84, 88, 0.35);
    --tint: #0a84ff;
    --tint-bg: rgba(10, 132, 255, 0.18);
    --green: #30d158;
    --orange: #ff9f0a;
    --red: #ff453a;
    --fill-1: rgba(118, 118, 128, 0.28);
    --fill-2: rgba(118, 118, 128, 0.22);
    --fill-3: rgba(118, 118, 128, 0.16);
    --shadow: 0 1px 0 rgba(255,255,255,0.04);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; background: var(--bg-grouped); color: var(--label);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
    "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic Medium", "Noto Sans JP", sans-serif;
  font-size: 17px; line-height: 1.4; -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; font-size: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
input[type=number]::-webkit-outer-spin-button, input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; }

.screen { min-height: 100%; padding-top: var(--safe-top); }

/* Nav */
.nav {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px 0; gap: 8px;
}
.large-title { flex: 1; margin: 0; font-size: 34px; font-weight: 700; letter-spacing: -0.02em; padding: 4px 8px; }
.nav-btn { width: 36px; height: 36px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; color: var(--tint); background: var(--fill-3); transition: transform .12s ease, background .15s ease; }
.nav-btn:active { transform: scale(0.92); background: var(--fill-2); }
.nav-btn.primary { color: var(--tint); }

.content { padding: 8px 16px 40px; }

/* Summary */
.summary-card {
  margin: 12px 0 24px;
  padding: 22px 22px 18px;
  background: linear-gradient(180deg, var(--bg-elev) 0%, var(--bg-elev) 100%);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
.summary-card::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(800px 200px at 100% 0%, var(--tint-bg), transparent 50%);
  pointer-events: none;
}
.summary-label { font-size: 13px; color: var(--label-3); font-weight: 500; letter-spacing: 0.01em; }
.summary-amount { font-size: 44px; font-weight: 700; letter-spacing: -0.03em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.summary-amount .currency { font-size: 28px; font-weight: 600; margin-right: 4px; color: var(--label-2); }
.summary-sub { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--sep-thin); font-size: 14px; color: var(--label-3); }
.summary-sub-amount { color: var(--label-2); font-weight: 600; font-variant-numeric: tabular-nums; }

/* Section */
.section { margin: 22px 0 0; }
.section-header { display: flex; justify-content: space-between; align-items: baseline; padding: 0 4px 8px; font-size: 13px; color: var(--label-3); font-weight: 500; text-transform: none; letter-spacing: 0.02em; }
.section-count { color: var(--label-3); font-size: 13px; }

.card {
  background: var(--bg-elev);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.card.pad { padding: 14px 16px; }
.about p { margin: 0 0 6px; font-size: 15px; }
.about .muted { color: var(--label-3); font-size: 13px; }

/* Breakdown */
.breakdown { padding: 14px 16px; }
.bd-row { display: grid; grid-template-columns: 18px 1fr auto; gap: 10px; align-items: center; padding: 8px 0; }
.bd-row + .bd-row { border-top: 1px solid var(--sep-thin); }
.bd-dot { width: 10px; height: 10px; border-radius: 50%; }
.bd-name { font-size: 15px; }
.bd-meta { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.bd-monthly { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.bd-unit { font-size: 11px; color: var(--label-3); font-weight: 500; margin-left: 1px; }
.bd-yearly { font-size: 11px; color: var(--label-3); font-variant-numeric: tabular-nums; }
.bd-bar { grid-column: 1 / -1; height: 4px; background: var(--fill-3); border-radius: 4px; overflow: hidden; }
.bd-bar > span { display: block; height: 100%; border-radius: 4px; transition: width .4s cubic-bezier(.2,.7,.2,1); }

/* Item list grouped by category */
.group { margin-top: 18px; }
.group-title { display: flex; align-items: center; gap: 8px; padding: 0 4px 6px; font-size: 13px; color: var(--label-3); font-weight: 500; }
.group-dot { width: 8px; height: 8px; border-radius: 50%; }
.group-card { background: var(--bg-elev); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.item { display: grid; grid-template-columns: 1fr auto 18px; gap: 14px; align-items: center; padding: 14px 16px; }
.item + .item { border-top: 1px solid var(--sep-thin); }
.item:active { background: var(--fill-3); }
.item-name { font-size: 16px; font-weight: 500; }
.item-meta { font-size: 13px; color: var(--label-3); margin-top: 2px; display: flex; gap: 6px; align-items: center; }
.item-stars { color: var(--orange); letter-spacing: 1px; font-size: 11px; }
.item-right { text-align: right; }
.item-monthly { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
.item-yearly { font-size: 12px; color: var(--label-3); margin-top: 2px; font-variant-numeric: tabular-nums; }
.item-chev { color: var(--label-4); }

/* Empty */
.empty { background: var(--bg-elev); border-radius: var(--radius); padding: 40px 20px; text-align: center; box-shadow: var(--shadow); }
.empty-emoji { font-size: 36px; margin-bottom: 8px; }
.empty-title { font-size: 17px; font-weight: 600; }
.empty-sub { font-size: 14px; color: var(--label-3); margin-top: 4px; margin-bottom: 18px; }
.ghost-btn { background: var(--tint-bg); color: var(--tint); padding: 10px 18px; border-radius: 999px; font-weight: 600; font-size: 15px; }
.ghost-btn.full { display: block; margin-top: 10px; width: 100%; padding: 12px; border-radius: var(--radius); background: var(--bg-elev); color: var(--tint); box-shadow: var(--shadow); }

/* Primary CTA button */
.primary-btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  background: var(--tint); color: #fff;
  padding: 14px 22px;
  border-radius: 999px;
  font-weight: 600; font-size: 17px;
  box-shadow: 0 8px 24px rgba(0, 122, 255, 0.28);
  transition: transform .12s ease, box-shadow .15s ease, background .15s ease;
}
.primary-btn:active { transform: scale(0.97); box-shadow: 0 4px 14px rgba(0, 122, 255, 0.20); }
.primary-btn.big { margin: 6px auto 12px; padding: 16px 28px; font-size: 17px; }

/* Sticky bottom bar */
.bottom-spacer { height: calc(var(--safe-bottom) + 92px); }
.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0;
  padding: 14px 20px calc(var(--safe-bottom) + 14px);
  background: linear-gradient(180deg, transparent, var(--bg-grouped) 38%);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  z-index: 20;
  pointer-events: none;
}
.bottom-bar .primary-btn {
  display: flex; width: 100%;
  pointer-events: auto;
  padding: 16px;
  font-size: 17px;
  letter-spacing: 0.02em;
}
@supports not (backdrop-filter: blur(20px)) {
  .bottom-bar { background: var(--bg-grouped); border-top: 1px solid var(--sep-thin); }
}

/* Sheet */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet[hidden] { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.35); opacity: 0; transition: opacity .25s ease; }
.sheet.open .sheet-backdrop { opacity: 1; }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--bg-grouped);
  border-radius: 16px 16px 0 0;
  max-height: 92vh;
  display: flex; flex-direction: column;
  transform: translateY(100%);
  transition: transform .32s cubic-bezier(.2,.8,.2,1);
  padding-bottom: var(--safe-bottom);
  box-shadow: 0 -10px 40px rgba(0,0,0,0.25);
}
.sheet.open .sheet-panel { transform: translateY(0); }
.sheet-handle { width: 36px; height: 5px; background: var(--label-4); border-radius: 3px; margin: 8px auto 0; }
.sheet-nav { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px 4px; gap: 8px; }
.sheet-title { font-size: 17px; font-weight: 600; }
.sheet-body { overflow-y: auto; padding: 12px 16px 30px; -webkit-overflow-scrolling: touch; }
.link-btn { color: var(--tint); font-size: 17px; padding: 6px 4px; }
.link-btn.primary { font-weight: 600; }
.link-btn.small { font-size: 14px; margin-top: 8px; }

/* Form */
.form-group { margin-top: 16px; }
.form-row { display: flex; gap: 12px; }
.form-row .flex { flex: 1; }
.form-label { display: block; font-size: 13px; color: var(--label-3); font-weight: 500; padding: 0 4px 6px; }
input[type=text], input[type=number], textarea, select {
  width: 100%;
  background: var(--bg-elev);
  border: 0;
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 17px;
  outline: none;
  box-shadow: var(--shadow);
  -webkit-appearance: none;
  appearance: none;
}
textarea { resize: none; }
.amount-input { position: relative; }
.amount-yen { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); font-size: 17px; color: var(--label-3); font-weight: 500; pointer-events: none; }
.amount-input input { padding-left: 32px; font-variant-numeric: tabular-nums; }
.select-wrap { position: relative; }
.select-wrap .chev { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--label-3); pointer-events: none; }

/* Segmented control */
.segmented { display: flex; background: var(--fill-2); border-radius: 10px; padding: 2px; }
.seg { flex: 1; padding: 9px 8px; font-size: 14px; font-weight: 500; color: var(--label); border-radius: 8px; transition: background .15s ease, transform .12s; }
.seg.active { background: var(--bg-elev); box-shadow: 0 1px 2px rgba(0,0,0,0.06); font-weight: 600; }
.seg:active { transform: scale(0.98); }

/* Stars */
.stars { display: flex; gap: 4px; padding: 4px; }
.stars button { font-size: 28px; color: var(--label-4); padding: 4px 6px; transition: transform .12s; }
.stars button.on { color: var(--orange); }
.stars button:active { transform: scale(1.15); }

/* Danger */
.danger-btn { width: 100%; margin-top: 24px; padding: 14px; border-radius: var(--radius); background: var(--bg-elev); color: var(--red); font-weight: 500; box-shadow: var(--shadow); }

/* Settings rows */
.row-btn { display: flex; width: 100%; align-items: center; justify-content: space-between; padding: 14px 16px; font-size: 16px; color: var(--label); }
.row-btn + .row-btn { border-top: 1px solid var(--sep-thin); }
.row-btn:active { background: var(--fill-3); }
.row-btn.danger { color: var(--red); }
.row-btn svg { color: var(--label-4); }

.cat-row { display: flex; align-items: center; padding: 12px 14px; gap: 10px; }
.cat-row + .cat-row { border-top: 1px solid var(--sep-thin); }
.cat-color { width: 22px; height: 22px; border-radius: 6px; flex-shrink: 0; }
.cat-name { flex: 1; font-size: 16px; }
.cat-del { color: var(--red); font-size: 14px; }

/* iOS select native styling reset */
select { background-image: none; }
