:root {
  --brown:   #7c5a3a;
  --brown-d: #5f4630;
  --cream:   #fff6e6;
  --line:    #f0d9c2;
  --card:    #fffdf8;
  --gold:    #e8b54a;
  --gold-d:  #c98f2d;
  --in:      #2f9d8a;   /* 収入（青緑） */
  --out:     #e0533c;   /* 支出（赤橙） */
  --shadow:  0 4px 14px rgba(95, 70, 48, 0.16);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; min-height: 100%; }

body {
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", system-ui, sans-serif;
  color: var(--brown-d);
  background:
    radial-gradient(circle at 50% -8%, rgba(232, 181, 74, 0.25) 0%, transparent 60%),
    linear-gradient(170deg, #fbf1e0 0%, #f3e0c2 100%);
  background-attachment: fixed;
  -webkit-user-select: none; user-select: none;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) 16px 0;
  display: flex;
  flex-direction: column;
}

/* ---- ヘッダー ---- */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 12px 2px 6px; }
.logo { font-size: 1.18rem; margin: 0; letter-spacing: .01em; }
.paw { filter: drop-shadow(0 1px 1px rgba(0,0,0,.12)); }
.top-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 38px; height: 38px; border: none; border-radius: 50%;
  background: #fff; color: var(--brown);
  font-size: 1.05rem; box-shadow: var(--shadow); cursor: pointer;
}
.icon-btn:active { transform: scale(.92); }

/* ---- 月ナビ ---- */
.month-nav {
  display: flex; align-items: center; justify-content: space-between;
  background: #fff; border-radius: 999px; box-shadow: var(--shadow);
  padding: 4px; margin: 8px 0 4px;
}
.month-btn {
  width: 40px; height: 40px; border: none; border-radius: 50%;
  background: var(--cream); color: var(--brown);
  font-size: .9rem; cursor: pointer;
}
.month-btn:active { transform: scale(.92); }
.month-label { font-weight: 800; font-size: 1.05rem; }

/* ---- コンテンツ ---- */
.content { flex: 1; padding: 8px 0 calc(env(safe-area-inset-bottom) + 92px); }
.view { display: flex; flex-direction: column; gap: 10px; }

.step-cap {
  margin: 8px 2px 0;
  font-size: .82rem; font-weight: 800; color: var(--brown);
}

/* しゅるい切り替え */
.type-tabs {
  display: flex; gap: 6px; background: #fff;
  padding: 5px; border-radius: 999px; box-shadow: var(--shadow);
}
.type-tab {
  flex: 1; border: none; background: none; cursor: pointer;
  padding: 11px 4px; border-radius: 999px;
  font-size: 1rem; font-weight: 800; color: var(--brown);
  transition: background .2s, color .2s;
}
.type-tab.out.active { background: var(--out); color: #fff; }
.type-tab.in.active  { background: var(--in);  color: #fff; }

/* カテゴリ */
.cat-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
}
.cat-btn {
  border: 2px solid transparent; border-radius: 16px;
  background: #fff; box-shadow: var(--shadow); cursor: pointer;
  padding: 10px 2px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-family: inherit;
}
.cat-btn .cat-emoji { font-size: 1.5rem; }
.cat-btn .cat-name { font-size: .72rem; font-weight: 800; color: var(--brown); }
.cat-btn.active { border-color: var(--gold); background: #fff8e8; }
.cat-btn:active { transform: scale(.94); }

/* 金額 */
.amount-row {
  display: flex; align-items: center; gap: 8px;
  background: #fff; border-radius: 18px; box-shadow: var(--shadow);
  padding: 10px 16px;
}
.yen { font-size: 1.5rem; font-weight: 800; color: var(--brown); }
.amount-input {
  flex: 1; min-width: 0; border: none; outline: none; background: none;
  font-family: inherit; font-size: 2rem; font-weight: 800; color: var(--brown-d);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.amount-input::placeholder { color: #d9c7ab; }

.date-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: #fff; border-radius: 16px; box-shadow: var(--shadow);
  padding: 8px 16px;
}
.date-cap { font-size: .85rem; font-weight: 800; color: var(--brown); }
.date-input {
  border: none; outline: none; background: none;
  font-family: inherit; font-size: 1rem; font-weight: 700; color: var(--brown-d);
}
.memo-input {
  flex: 1; min-width: 0; border: none; outline: none; background: none;
  font-family: inherit; font-size: .95rem; font-weight: 700; color: var(--brown-d);
  text-align: right;
}
.memo-input::placeholder { color: #d9c7ab; font-weight: 600; }

.btn-save { font-size: 1.15rem; padding: 15px; margin-top: 4px; }

.cat-msg {
  margin: 4px auto 0; padding: 8px 18px;
  background: #fff; border-radius: 999px; box-shadow: var(--shadow);
  font-size: .92rem; font-weight: 700; color: var(--brown);
  text-align: center; width: fit-content; max-width: 100%;
}

/* ---- まとめ ---- */
.stats { display: flex; gap: 8px; }
.stat-box {
  flex: 1; background: var(--card); border-radius: 16px;
  box-shadow: var(--shadow); padding: 10px 6px; text-align: center;
}
.stat-cap { font-size: .75rem; font-weight: 800; color: var(--brown); }
.stat-num {
  font-size: 1.02rem; font-weight: 800; margin-top: 2px;
  font-variant-numeric: tabular-nums; word-break: break-all;
}
.in-color  { color: var(--in); }
.out-color { color: var(--out); }
.minus-color { color: var(--out); }

.card {
  background: var(--card); border-radius: 18px;
  box-shadow: var(--shadow); padding: 14px 16px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; }
.card-title { margin: 0 0 10px; font-size: .95rem; color: var(--brown); }
.card-head .card-title { margin-bottom: 10px; }
.btn-mini {
  border: none; border-radius: 999px; cursor: pointer;
  background: var(--cream); color: var(--brown);
  font-size: .8rem; font-weight: 800; padding: 6px 14px;
}
.btn-mini:active { transform: scale(.94); }

/* 収支バランス（棒グラフ） */
.bar-row {
  display: grid; grid-template-columns: 2.6em 1fr auto; align-items: center;
  gap: 8px; margin-bottom: 8px;
}
.bar-row:last-child { margin-bottom: 0; }
.bar-label { font-size: .82rem; font-weight: 800; color: var(--brown); }
.bar-track {
  height: 14px; border-radius: 7px; background: var(--cream); overflow: hidden;
}
.bar {
  height: 100%; border-radius: 7px;
  transition: width .5s ease;
  min-width: 2px;
}
.in-bg  { background: var(--in); }
.out-bg { background: var(--out); }
.bar-val { font-size: .85rem; font-weight: 800; font-variant-numeric: tabular-nums; }

/* 目標 */
.goal-none { margin: 0; font-size: .88rem; color: var(--brown); }
.goal-progress-row {
  display: flex; align-items: center; justify-content: space-between;
  font-size: .85rem; font-weight: 800; color: var(--brown); margin-bottom: 6px;
}
.goal-track {
  height: 18px; border-radius: 9px; background: var(--cream);
  overflow: hidden; position: relative;
}
.goal-bar {
  height: 100%; border-radius: 9px; background: var(--gold);
  transition: width .5s ease;
}
.goal-msg { margin: 8px 0 0; font-size: .9rem; font-weight: 700; color: var(--brown-d); text-align: center; }
.goal-msg.achieved { color: var(--gold-d); }

/* 支出の内訳 */
.cat-row {
  display: grid; grid-template-columns: auto 4.2em 1fr auto; align-items: center;
  gap: 8px; margin-bottom: 8px;
}
.cat-row:last-child { margin-bottom: 0; }
.cat-row-emoji { font-size: 1.05rem; }
.cat-row-name { font-size: .82rem; font-weight: 800; color: var(--brown); }
.cat-row .bar-track { height: 12px; border-radius: 6px; }
.cat-row .bar { background: var(--out); opacity: .85; border-radius: 6px; }
.cat-row-val { font-size: .82rem; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--brown-d); }

.empty-note { margin: 4px 0; font-size: .88rem; color: var(--brown); text-align: center; }

/* ---- りれき ---- */
.history-list { display: flex; flex-direction: column; gap: 8px; }
.day-head {
  margin: 6px 2px 0; font-size: .8rem; font-weight: 800; color: var(--brown);
}
.entry {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border-radius: 14px; box-shadow: var(--shadow);
  padding: 10px 12px;
}
.entry-emoji { font-size: 1.3rem; }
.entry-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.entry-name { font-size: .9rem; font-weight: 800; color: var(--brown-d); }
.entry-memo {
  font-size: .75rem; font-weight: 600; color: var(--brown);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.entry-amount { font-size: .95rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.entry-del {
  border: none; background: var(--cream); color: var(--brown);
  width: 30px; height: 30px; border-radius: 50%; cursor: pointer;
  font-size: .85rem; font-weight: 800;
}
.entry-del:active { transform: scale(.9); }

/* ---- 下部ナビ ---- */
.bottom-nav {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 14px);
  width: min(calc(100% - 32px), 448px);
  display: flex; gap: 4px;
  background: #fff; border-radius: 999px; box-shadow: 0 6px 20px rgba(95,70,48,.25);
  padding: 6px; z-index: 20;
}
.nav-btn {
  flex: 1; border: none; background: none; cursor: pointer;
  border-radius: 999px; padding: 8px 4px;
  font-family: inherit; font-size: .82rem; font-weight: 800; color: var(--brown);
  display: flex; flex-direction: column; align-items: center; gap: 1px;
}
.nav-icon { font-size: 1.15rem; }
.nav-btn.active { background: var(--gold); color: #fff; }

/* ---- モーダル ---- */
.modal { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(95, 70, 48, 0.45); }
.modal-card {
  position: relative;
  background: var(--card); border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 22px 20px; margin: 20px;
  max-width: 360px; width: calc(100% - 40px);
  max-height: 80dvh; overflow-y: auto;
}
.modal-card h2 { margin: 0 0 10px; font-size: 1.2rem; }
.modal-note { margin: 0 0 12px; font-size: .88rem; color: var(--brown); }
.modal-actions { display: flex; gap: 8px; margin-top: 14px; }
.modal-actions .btn { flex: 1; }

.howto { margin: 0 0 16px; padding-left: 1.2em; font-size: .92rem; line-height: 1.7; }
.howto li { margin-bottom: 6px; }

.btn {
  border: none; border-radius: 999px;
  padding: 12px 22px;
  font-family: inherit; font-size: 1rem; font-weight: 800; cursor: pointer;
}
.btn:active { transform: scale(.96); }
.btn-primary {
  background: var(--gold); color: #fff;
  box-shadow: 0 4px 0 var(--gold-d);
}
.btn-primary:active { box-shadow: 0 1px 0 var(--gold-d); translate: 0 3px; }
.btn-ghost { background: var(--cream); color: var(--brown); }

/* ---- トースト ---- */
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 84px);
  transform: translateX(-50%);
  background: var(--brown-d); color: #fff;
  padding: 10px 18px; border-radius: 999px;
  font-size: .9rem; font-weight: 700;
  box-shadow: var(--shadow); z-index: 50;
  max-width: calc(100vw - 40px); text-align: center;
}

.hidden { display: none !important; }
