/* Megumareta Financial OS — v3: Japanese home, bright & playful, professional */
:root {
  --bg: #fbf7f0;
  --bg-pattern: radial-gradient(rgba(232, 72, 63, 0.045) 1.2px, transparent 1.2px);
  --surface: #ffffff;
  --surface-2: #faf3e7;
  --surface-3: #f3e9d8;
  --border: #eee0cb;
  --border-strong: #e0cda9;
  --ink: #33261f;
  --text: #33261f;
  --muted: #8a7a6d;
  --faint: #b5a695;
  --red: #e8483f;            /* vermilion — CTA */
  --red-dark: #d13a31;
  --red-soft: #fdecea;
  --accent: #2f9e63;         /* matcha green — positive */
  --accent-soft: #e5f5ec;
  --gold: #dd9522;
  --gold-soft: #fdf3df;
  --danger: #d64545;
  --danger-soft: #fdecec;
  --info: #3d6fb4;
  --info-soft: #e9f1fb;
  --sakura: #f27d9d;
  --radius: 20px;
  --shadow: 0 6px 22px rgba(176, 120, 60, 0.12);
  --shadow-lg: 0 10px 32px rgba(176, 120, 60, 0.16);
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: var(--bg);
  background-image: var(--bg-pattern);
  background-size: 22px 22px;
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, .font-display { font-family: 'M PLUS Rounded 1c', 'Inter', sans-serif; letter-spacing: -0.01em; }
a { color: var(--red); }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea {
  font-family: inherit; font-size: 15px; color: var(--text);
  background: var(--surface); border: 1.5px solid var(--border-strong);
  border-radius: 14px; padding: 11px 14px; width: 100%; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(232, 72, 63, 0.12); }
input::placeholder { color: var(--faint); }
select {
  appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a7a6d' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
label { display: block; font-size: 11.5px; font-weight: 700; color: var(--muted); margin: 14px 0 6px; text-transform: uppercase; letter-spacing: .07em; }
svg.ic { width: 18px; height: 18px; flex: none; }
.kanji { font-family: 'M PLUS Rounded 1c', sans-serif; }

/* ---------- shell ---------- */
#app { max-width: 540px; margin: 0 auto; min-height: 100dvh; padding: 0 18px 116px; position: relative; }
.app-header { display: flex; align-items: center; justify-content: space-between; padding: 22px 0 14px; }
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 14px; flex: none;
  background: linear-gradient(145deg, #f0564c, #d13a31);
  display: grid; place-items: center;
  font-family: 'M PLUS Rounded 1c'; font-weight: 800; font-size: 20px; color: #fff7ec;
  box-shadow: 0 5px 14px rgba(232, 72, 63, .35);
  border: 2px solid #fff;
}
.brand-name { font-family: 'M PLUS Rounded 1c'; font-weight: 800; font-size: 18px; color: var(--ink); }
.brand-sub { font-size: 10px; color: var(--muted); letter-spacing: .16em; text-transform: uppercase; margin-top: -3px; }
.header-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 13px; display: grid; place-items: center;
  background: var(--surface); border: 1.5px solid var(--border); color: var(--muted); position: relative;
  box-shadow: 0 2px 8px rgba(176,120,60,.07);
}
.icon-btn:active { transform: scale(.94); }
.avatar-btn {
  width: 40px; height: 40px; border-radius: 13px; display: grid; place-items: center;
  background: linear-gradient(145deg, #f7b267, #e88f3c); color: #fff;
  font-family: 'M PLUS Rounded 1c'; font-weight: 800; font-size: 16px;
  box-shadow: 0 3px 10px rgba(232, 143, 60, .3); border: 2px solid #fff;
}
.badge-dot { position: absolute; top: 9px; right: 9px; width: 9px; height: 9px; border-radius: 50%; background: var(--red); border: 2px solid var(--surface); display: none; }
.badge-dot.on { display: block; }

/* ---------- nav ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: min(540px, 100%); display: flex; gap: 4px; padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
  background: rgba(255, 253, 248, .92); backdrop-filter: blur(18px);
  border-top: 1.5px solid var(--border); z-index: 40;
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 7px 0; border-radius: 14px; color: var(--faint); font-size: 10.5px; font-weight: 700;
  transition: color .15s, background .15s;
}
.tab svg { width: 21px; height: 21px; }
.tab.active { color: var(--red); background: var(--red-soft); }
.fab {
  position: fixed; bottom: 92px; left: 50%; transform: translateX(-50%); z-index: 41;
  height: 52px; padding: 0 26px; border-radius: 999px;
  background: linear-gradient(145deg, #f0564c, #d13a31); color: #fff7ec;
  display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 15px;
  font-family: 'M PLUS Rounded 1c';
  box-shadow: 0 10px 26px rgba(232, 72, 63, .4);
  border: 3px solid #fffdf8;
}
.fab:active { transform: translateX(-50%) scale(.94); }
.fab svg { width: 22px; height: 22px; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: 0 2px 10px rgba(176,120,60,.06); }
.card + .card, .section + .section { margin-top: 14px; }
.section-title { display: flex; align-items: center; gap: 8px; justify-content: space-between; margin: 22px 2px 10px; }
.section-title h2 { font-size: 15.5px; color: var(--ink); display: flex; align-items: center; gap: 7px; }
.section-title h2 .kbadge {
  font-size: 12px; background: var(--red-soft); color: var(--red);
  border-radius: 7px; padding: 1px 6px; font-weight: 800;
}
.section-title .link { font-size: 12.5px; color: var(--red); font-weight: 700; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.tiny { font-size: 11.5px; }
.small { font-size: 13px; }
.amount { font-variant-numeric: tabular-nums; }
.pos { color: var(--accent); }
.neg { color: var(--danger); }
.gold { color: var(--gold); }

.chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 800; }
.chip.ok { background: var(--accent-soft); color: var(--accent); }
.chip.warn { background: var(--gold-soft); color: var(--gold); }
.chip.bad { background: var(--danger-soft); color: var(--danger); }
.chip.info { background: var(--info-soft); color: var(--info); }
.chip.dim { background: var(--surface-2); color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 18px; border-radius: 15px; font-weight: 800; font-size: 14px;
  background: var(--surface-2); color: var(--text); border: 1.5px solid var(--border-strong);
  transition: transform .1s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(145deg, #f0564c, #d13a31); color: #fff7ec; border: none; box-shadow: 0 5px 16px rgba(232,72,63,.3); }
.btn.danger { background: var(--danger-soft); color: var(--danger); border: none; }
.btn.ghost { background: transparent; border: 2px dashed var(--border-strong); color: var(--muted); }
.btn.block { width: 100%; }
.btn.sm { padding: 8px 13px; font-size: 12.5px; border-radius: 11px; }
.btn:disabled { opacity: .5; }

.progress { height: 9px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.progress > div { height: 100%; border-radius: 99px; background: linear-gradient(90deg, #2f9e63, #7cd3a5); transition: width .5s; }
.progress.gold > div { background: linear-gradient(90deg, #dd9522, #f6c063); }

/* ---------- hero ---------- */
.hero {
  border-radius: 26px; padding: 24px; position: relative; overflow: hidden;
  background: linear-gradient(160deg, #fff6e8, #ffefd8);
  border: 2px solid #f5ddb8;
  box-shadow: var(--shadow);
}
.hero::after {
  content: '家'; position: absolute; right: -6px; bottom: -26px;
  font-family: 'M PLUS Rounded 1c'; font-size: 130px; font-weight: 800;
  color: rgba(232, 72, 63, .07); line-height: 1; pointer-events: none;
}
.hero-label { font-size: 11px; letter-spacing: .16em; text-transform: uppercase; color: var(--gold); font-weight: 800; display: flex; align-items: center; gap: 6px; }
.hero-label::before { content: ''; width: 10px; height: 10px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #f97e6e, #e8483f); box-shadow: 0 0 0 3px rgba(232,72,63,.15); }
.hero-amount { font-size: 35px; font-weight: 800; margin-top: 4px; color: var(--ink); font-family: 'M PLUS Rounded 1c'; letter-spacing: -.02em; }
.hero-row { display: flex; align-items: center; gap: 15px; margin-top: 16px; flex-wrap: wrap; position: relative; z-index: 1; }
.hero-stat { min-width: 88px; background: rgba(255,255,255,.75); border-radius: 14px; padding: 8px 10px; border: 1.5px solid rgba(245, 221, 184, .8); }
.hero-stat .v { font-weight: 800; font-size: 15px; color: var(--ink); }
.hero-stat .k { font-size: 10.5px; color: var(--muted); font-weight: 600; }
.score-ring { position: relative; width: 76px; height: 76px; flex: none; margin-left: auto; }
.score-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.score-ring .val { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
.score-ring .val b { font-size: 20px; font-family: 'M PLUS Rounded 1c'; display: block; line-height: 1; color: var(--ink); }
.score-ring .val span { font-size: 8.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; font-weight: 700; }

/* ---------- pockets ---------- */
.pocket-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pocket-card {
  border-radius: var(--radius); padding: 16px; border: 2px solid var(--border);
  background: var(--surface); position: relative; overflow: hidden; text-align: left; color: var(--text);
  min-height: 130px; display: flex; flex-direction: column; box-shadow: 0 3px 12px rgba(176,120,60,.08);
  transition: transform .12s;
}
.pocket-card:active { transform: scale(.97); }
.pocket-card::before {
  content: ''; position: absolute; inset: 0 0 auto 0; height: 64px;
  background: var(--pg, linear-gradient(135deg, #ffd9a0, #f7b267));
  border-radius: 18px 18px 60% 60% / 18px 18px 26px 26px;
  opacity: .9;
}
.pocket-card > * { position: relative; }
.pocket-top { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; }
.pocket-ico {
  width: 32px; height: 32px; border-radius: 11px; display: grid; place-items: center;
  background: rgba(255, 255, 255, .85); color: var(--ink); border: 1.5px solid rgba(255,255,255,.9);
  box-shadow: 0 2px 6px rgba(120, 80, 30, .12);
}
.pocket-name { font-weight: 800; font-size: 13.5px; color: #3d2f24; }
.pocket-mask { font-size: 10px; color: #6b594a; font-weight: 600; }
.pocket-bal { margin-top: auto; font-size: 19px; font-weight: 800; font-family: 'M PLUS Rounded 1c'; color: var(--ink); letter-spacing: -.02em; }
.pocket-target { margin-top: 7px; }
.pocket-target .tiny { display: flex; justify-content: space-between; margin-bottom: 4px; color: var(--muted); }

/* ---------- rows ---------- */
.row { display: flex; align-items: center; gap: 12px; padding: 13px 2px; border-bottom: 1.5px dashed var(--border); }
.row:last-child { border-bottom: none; }
.row-ico { width: 38px; height: 38px; border-radius: 13px; display: grid; place-items: center; flex: none; background: var(--surface-2); color: var(--muted); }
.row-ico.in { background: var(--accent-soft); color: var(--accent); }
.row-ico.out { background: var(--red-soft); color: var(--red); }
.row-ico.swap { background: var(--gold-soft); color: var(--gold); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink); }
.row-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-amt { text-align: right; font-weight: 800; font-size: 14px; font-variant-numeric: tabular-nums; color: var(--ink); }
.row-amt .tiny { display: block; font-weight: 500; }

/* ---------- allocation instances ---------- */
.inst { display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: 17px; background: var(--surface); border: 2px solid var(--border); margin-bottom: 10px; box-shadow: 0 2px 8px rgba(176,120,60,.05); }
.inst.due { border-color: #f2c069; background: linear-gradient(180deg, #fdf3df, #fff); }
.inst.overdue { border-color: #ef9d97; background: linear-gradient(180deg, #fdecea, #fff); }
.inst.paid { opacity: .6; }
.inst-main { flex: 1; min-width: 0; }
.date-pill {
  display: grid; place-items: center; width: 46px; height: 50px; border-radius: 14px; flex: none;
  background: var(--red-soft); border: 1.5px solid rgba(232,72,63,.2);
}
.date-pill b { font-size: 17px; font-family: 'M PLUS Rounded 1c'; color: var(--red); }
.date-pill span { font-size: 9px; text-transform: uppercase; color: var(--red); letter-spacing: .05em; font-weight: 700; }
.inst.paid .date-pill { background: var(--accent-soft); border-color: rgba(47,158,99,.2); }
.inst.paid .date-pill b, .inst.paid .date-pill span { color: var(--accent); }

/* ---------- month nav ---------- */
.month-nav { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 14px; background: var(--surface); border: 2px solid var(--border); border-radius: 17px; padding: 6px 8px; box-shadow: 0 2px 8px rgba(176,120,60,.05); }
.month-nav h2 { font-size: 16px; color: var(--ink); }
.month-nav button { width: 36px; height: 36px; border-radius: 12px; background: var(--surface-2); color: var(--muted); display: grid; place-items: center; }

/* ---------- analytics ---------- */
.metric-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.metric { background: var(--surface); border: 2px solid var(--border); border-radius: 17px; padding: 14px; box-shadow: 0 2px 8px rgba(176,120,60,.05); }
.metric .k { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; font-weight: 800; }
.metric .v { font-size: 19px; font-weight: 800; margin-top: 3px; font-family: 'M PLUS Rounded 1c'; color: var(--ink); }
.metric .d { font-size: 11.5px; margin-top: 2px; }
.cat-bar { margin: 11px 0; }
.cat-bar .lbl { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; color: var(--ink); }
.split { display: flex; height: 14px; border-radius: 99px; overflow: hidden; background: var(--surface-3); }
.split > div:first-child { background: linear-gradient(90deg, #2f9e63, #7cd3a5); }
.split > div:last-child { background: linear-gradient(90deg, #dd9522, #f6c063); }
.score-row { margin: 10px 0; }
.score-row .lbl { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; color: var(--ink); }
.insight { display: flex; gap: 10px; padding: 11px 0; border-bottom: 1.5px dashed var(--border); font-size: 13.5px; color: #5d4d40; }
.insight:last-child { border-bottom: none; }
.insight svg { color: var(--red); flex: none; margin-top: 2px; }

/* ---------- notifications ---------- */
.notif { display: flex; gap: 11px; align-items: flex-start; padding: 12px 14px; border-radius: 15px; margin-bottom: 8px; font-size: 13.5px; border: 2px solid; }
.notif.overdue { background: #fdecea; border-color: #f2b3ad; color: #8c2f28; }
.notif.due { background: #fdf3df; border-color: #f2cfa0; color: #7a5514; }
.notif.target { background: #e9f1fb; border-color: #b8cfec; color: #2c4a77; }

/* ---------- modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(61, 42, 28, .45); backdrop-filter: blur(6px); z-index: 50; display: grid; place-items: end center; animation: fade .18s; }
@keyframes fade { from { opacity: 0; } }
.modal {
  width: min(540px, 100%); max-height: 88dvh; overflow-y: auto;
  background: var(--bg); border: 2px solid var(--border); border-bottom: none;
  border-radius: 26px 26px 0 0; padding: 20px 20px calc(24px + env(safe-area-inset-bottom));
  animation: slideUp .22s cubic-bezier(.2, .9, .3, 1);
}
@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.modal-head h3 { font-size: 18px; color: var(--ink); }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions .btn { flex: 1; }
.seg { display: flex; background: var(--surface-2); border-radius: 14px; padding: 4px; gap: 4px; margin-top: 14px; border: 1.5px solid var(--border); }
.seg button { flex: 1; padding: 9px; border-radius: 11px; font-weight: 800; font-size: 13px; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 2px 8px rgba(176,120,60,.15); }
.seg button.on.in { color: var(--accent); }
.seg button.on.out { color: var(--red); }
.seg button.on.sw { color: var(--gold); }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; padding: 32px 24px; max-width: 420px; margin: 0 auto; }
.login-logo {
  width: 84px; height: 84px; border-radius: 28px; margin: 0 auto 22px;
  background: linear-gradient(145deg, #f0564c, #d13a31);
  display: grid; place-items: center; box-shadow: 0 16px 40px rgba(232, 72, 63, .35);
  border: 4px solid #fff;
  font-family: 'M PLUS Rounded 1c'; font-size: 38px; font-weight: 800; color: #fff7ec;
}
.login-title { text-align: center; font-size: 27px; color: var(--ink); font-family: 'M PLUS Rounded 1c'; font-weight: 800; }
.login-sub { text-align: center; color: var(--muted); font-size: 13.5px; margin: 6px 0 24px; }
.error-note { background: var(--danger-soft); color: var(--danger); border-radius: 12px; padding: 10px 14px; font-size: 13px; margin-top: 14px; display: none; }

/* ---------- pocket detail ---------- */
.detail-head { border-radius: 24px; padding: 22px; position: relative; overflow: hidden; border: 2px solid var(--border); }
.detail-head::before { content: ''; position: absolute; inset: 0 0 auto 0; height: 100%; background: var(--pg, linear-gradient(135deg, #ffd9a0, #f7b267)); opacity: .35; }
.detail-head > * { position: relative; }
.detail-head .big { font-size: 31px; font-weight: 800; font-family: 'M PLUS Rounded 1c'; color: var(--ink); letter-spacing: -.02em; margin-top: 2px; }
.back-btn { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 800; margin-bottom: 12px; }
.empty { text-align: center; color: var(--faint); padding: 34px 10px; font-size: 13.5px; }
.empty svg { width: 30px; height: 30px; margin-bottom: 8px; opacity: .5; }
.action-row { display: flex; gap: 9px; margin: 14px 0; }
.action-row .btn { flex: 1; }

.toast {
  position: fixed; bottom: 112px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff7ec; padding: 11px 20px; border-radius: 99px;
  font-size: 13.5px; font-weight: 700; z-index: 60; box-shadow: var(--shadow-lg);
  animation: slideUp .2s; white-space: nowrap;
}
.toast.err { background: #8c2f28; }

@media (min-width: 640px) {
  .fab { bottom: 30px; }
}
