:root {
  --bg: #FFFDF9;
  --border: #F0E8DC;
  --ink: #2D1F17;
  --muted: #9B8A7A;
  --muted-light: #B0A090;
  --muted-lighter: #C0AFA8;
  --orange: #E8844A;
  --track: #F5EBE0;
  --green: #4CAF75;
  --green-bg: #F0FBF5;
  --green-bg2: #E6F7ED;
  --red: #E05A5A;
  --page-bg: #EFEAE2;
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--page-bg);
  font-family: 'Noto Sans JP', sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}

input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; }

button { font-family: inherit; }

@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideUpSheet { from { transform: translateY(100%); } to { transform: translateY(0); } }

#app {
  max-width: 480px;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

/* Toast */
.toast {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 9px 22px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  z-index: 200;
  animation: slideUp 0.2s ease;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(45, 31, 23, 0.18);
}

/* Header */
.app-header {
  background: var(--bg);
  padding: 8px 4px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}
.app-header-row { display: flex; justify-content: space-between; align-items: center; }
.nav-arrow {
  background: none; border: none; font-size: 26px; color: var(--orange);
  cursor: pointer; padding: 4px 12px; line-height: 1; font-weight: 300;
}
.month-box { text-align: center; }
.month-label { font-size: 16px; font-weight: 700; color: var(--ink); letter-spacing: -0.3px; }
.month-sub { font-size: 10px; color: var(--muted-light); margin-top: 1px; }

/* Scroll content */
.scroll-content { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 14px 0; -webkit-overflow-scrolling: touch; }
.page-fade { animation: slideUp 0.25s ease; }

/* Empty state */
.empty-state { margin-top: 40px; text-align: center; padding: 0 20px; }
.empty-icon { margin-bottom: 16px; display: flex; justify-content: center; }
.empty-title { font-size: 17px; font-weight: 700; color: var(--ink); margin-bottom: 8px; }
.empty-desc { font-size: 13px; color: var(--muted); margin-bottom: 28px; line-height: 1.7; }
.btn-primary {
  background: var(--orange); color: #fff; border: none; border-radius: 14px;
  padding: 14px 32px; font-size: 15px; font-weight: 700; cursor: pointer;
  box-shadow: 0 4px 16px rgba(232, 132, 74, 0.3);
}

/* Cards */
.card {
  background: #fff; border-radius: 13px; padding: 11px 14px;
  box-shadow: 0 1px 8px rgba(45, 31, 23, 0.06); margin-bottom: 7px;
}
.card-lg { border-radius: 16px; padding: 16px; box-shadow: 0 2px 12px rgba(45, 31, 23, 0.07); margin-bottom: 12px; }

/* Summary card */
.summary-card {
  background: #fff; border-radius: 18px; padding: 16px;
  box-shadow: 0 2px 16px rgba(45, 31, 23, 0.08); margin-bottom: 10px;
  position: relative; overflow: hidden;
}
.summary-deco { position: absolute; right: -4px; bottom: -4px; opacity: 0.07; pointer-events: none; }
.summary-top { display: flex; justify-content: space-between; align-items: flex-start; }
.summary-label { font-size: 11px; color: var(--muted); font-weight: 500; margin-bottom: 4px; }
.summary-amount { font-size: 26px; font-weight: 700; line-height: 1.15; }
.summary-used { font-size: 11px; color: var(--muted); margin-top: 3px; }

.progress-track { background: var(--track); border-radius: 99px; height: 6px; overflow: hidden; }
.progress-track.thin { height: 5px; }
.progress-track.thinner { height: 4px; }
.progress-fill { height: 100%; border-radius: 99px; transition: width 0.5s ease; }
.summary-track { margin-top: 12px; }

/* Category card */
.cat-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.cat-head-left { display: flex; align-items: center; gap: 8px; }
.cat-badge {
  width: 26px; height: 26px; border-radius: 7px; display: flex;
  align-items: center; justify-content: center; flex-shrink: 0;
  font-size: 12px; font-weight: 700;
}
.cat-name { font-size: 13px; font-weight: 600; color: var(--ink); }
.cat-rem { font-size: 12px; font-weight: 700; }
.cat-foot { display: flex; justify-content: space-between; margin-top: 5px; }
.cat-used { font-size: 10px; color: var(--muted); }
.cat-budget { font-size: 10px; color: var(--muted-lighter); }
.cat-sub { margin-top: 7px; padding-top: 7px; border-top: 1px solid var(--track); display: flex; gap: 16px; }
.cat-sub span { font-size: 10px; color: var(--muted); }
.cat-weekly { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--track); }
.cat-weekly-title { font-size: 10px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.cat-weekly-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 3px; }
.cat-weekly-used { font-size: 10px; color: var(--muted); }
.cat-weekly-rem { font-size: 11px; font-weight: 700; }

/* Weekly summary */
.section-title { font-size: 11px; font-weight: 600; color: var(--muted); margin-bottom: 10px; }
.week-row { margin-bottom: 9px; }
.week-row-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 3px; }
.week-label { font-size: 11px; color: var(--ink); font-weight: 500; }
.week-total { font-size: 12px; font-weight: 700; }

/* Insights */
.insights-title { font-size: 11px; font-weight: 600; color: var(--muted); margin-bottom: 8px; display: flex; align-items: center; gap: 5px; }
.insight-row { display: flex; align-items: flex-start; gap: 8px; padding: 5px 0; }
.insight-icon { font-size: 14px; flex-shrink: 0; }
.insight-text { font-size: 12px; line-height: 1.5; font-weight: 500; }

/* Calendar */
.calendar-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; padding: 0 2px; }
.calendar-hint { font-size: 12px; color: var(--muted); }
.calendar-range { font-size: 11px; background: var(--track); border-radius: 99px; padding: 3px 10px; color: var(--muted); }
.calendar-card { background: #fff; border-radius: 16px; overflow: hidden; box-shadow: 0 2px 12px rgba(45, 31, 23, 0.07); }
.calendar-dow-row { display: grid; grid-template-columns: repeat(7, 1fr); background: var(--bg); }
.calendar-dow { text-align: center; padding: 8px 0; font-size: 11px; font-weight: 700; color: var(--muted); }
.calendar-dow.sun { color: var(--red); }
.calendar-dow.sat { color: #4A90D9; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; background: var(--border); }
.calendar-day {
  background: #fff; padding: 5px 3px 4px; cursor: pointer; min-height: 64px;
  display: flex; flex-direction: column; align-items: center; border: none; font-family: inherit;
}
.calendar-day.today { background: #FFF3E0; }
.calendar-day.future { opacity: 0.38; cursor: default; }
.calendar-day-num { font-size: 12px; font-weight: 400; line-height: 1.2; color: var(--ink); }
.calendar-day-num.today { font-weight: 700; }
.calendar-day-num.sun { color: var(--red); }
.calendar-day-num.sat { color: #4A90D9; }
.calendar-day-amount { margin-top: 2px; font-size: 9px; font-weight: 700; color: var(--orange); line-height: 1.2; }
.calendar-day-nospend {
  margin-top: 3px; width: 22px; height: 22px; border-radius: 50%; border: 1.5px solid var(--green);
  display: flex; align-items: center; justify-content: center; transform: rotate(-15deg); opacity: 0.8;
}
.calendar-day-nospend span { font-size: 11px; color: var(--green); font-weight: 700; transform: rotate(15deg); display: block; }
.calendar-day-dots { display: flex; gap: 2px; flex-wrap: wrap; justify-content: center; margin-top: auto; padding-top: 2px; }
.calendar-day-dot { width: 5px; height: 5px; border-radius: 50%; flex-shrink: 0; }
.calendar-legend { display: flex; gap: 10px; flex-wrap: wrap; padding: 10px 4px 4px; }
.calendar-legend-item { display: flex; align-items: center; gap: 4px; }
.calendar-legend-dot { width: 7px; height: 7px; border-radius: 50%; }
.calendar-legend-text { font-size: 10px; color: var(--muted); }
.calendar-legend-nospend {
  width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--green);
  display: flex; align-items: center; justify-content: center; transform: rotate(-15deg);
}
.calendar-legend-nospend span { font-size: 8px; color: var(--green); font-weight: 700; transform: rotate(15deg); display: block; }

/* Review */
.review-tabs { display: flex; gap: 0; margin-bottom: 14px; background: var(--border); border-radius: 12px; padding: 3px; }
.review-tab {
  flex: 1; padding: 8px 4px; border: none; border-radius: 10px; font-size: 11px;
  font-weight: 600; cursor: pointer; background: transparent; color: var(--muted);
}
.review-tab.active { background: #fff; color: var(--ink); box-shadow: 0 1px 4px rgba(45, 31, 23, 0.1); }
.review-card-title { font-size: 13px; font-weight: 700; color: var(--ink); margin-bottom: 14px; }
.review-cat-row { margin-bottom: 13px; }
.review-cat-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.review-cat-left { display: flex; align-items: center; gap: 6px; }
.review-dot { width: 8px; height: 8px; border-radius: 50%; }
.review-cat-name { font-size: 12px; font-weight: 600; color: var(--ink); }
.review-cat-vals { font-size: 11px; color: var(--muted); }
.compare-title { font-size: 13px; font-weight: 700; color: var(--ink); margin-bottom: 3px; }
.compare-sub { font-size: 11px; color: var(--muted); margin-bottom: 14px; }
.compare-row { padding: 10px 0; border-bottom: 1px solid var(--track); }
.compare-head { display: flex; align-items: center; gap: 6px; margin-bottom: 7px; }
.compare-vals { display: flex; justify-content: space-between; align-items: center; }
.compare-col { text-align: center; }
.compare-col-label { font-size: 10px; color: var(--muted); margin-bottom: 2px; }
.compare-col-val { font-size: 13px; font-weight: 600; color: var(--muted); }
.compare-col-val.current { font-size: 14px; font-weight: 700; color: var(--ink); }
.compare-arrow { font-size: 16px; color: #E0D5C8; }
.compare-diff { text-align: right; min-width: 60px; }
.compare-diff-val { font-size: 13px; font-weight: 700; }

/* Settings */
.settings-title { font-size: 15px; font-weight: 700; color: var(--ink); margin-bottom: 3px; }
.settings-sub { font-size: 12px; color: var(--muted); margin-bottom: 14px; }
.settings-cat { margin-bottom: 14px; }
.settings-cat-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.settings-badge {
  width: 24px; height: 24px; border-radius: 6px; display: flex; align-items: center;
  justify-content: center; flex-shrink: 0; font-size: 11px; font-weight: 700;
}
.input-row {
  display: flex; align-items: center; background: var(--bg); border: 1.5px solid var(--border);
  border-radius: 10px; padding: 10px 14px; gap: 6px;
}
.input-row.small { padding: 9px 14px; }
.input-yen { font-size: 14px; color: var(--muted); }
.input-row input {
  flex: 1; background: none; border: none; outline: none; font-size: 19px; font-weight: 700;
  color: var(--ink); font-family: inherit; min-width: 0;
}
.input-row.small input { font-size: 18px; }
.week-input-block { margin-bottom: 8px; }
.week-input-label { font-size: 10px; color: var(--muted); margin-bottom: 4px; }
.shokuhi-total-row {
  display: flex; justify-content: space-between; align-items: center; background: var(--green-bg);
  border-radius: 8px; padding: 10px 14px; margin-top: 2px;
}
.shokuhi-total-label { font-size: 11px; color: #7BA68A; font-weight: 500; }
.shokuhi-total-val { font-size: 16px; font-weight: 700; color: var(--green); }
.settings-grand-total {
  background: var(--bg); border-radius: 10px; padding: 12px 14px; margin-bottom: 18px;
  display: flex; justify-content: space-between; align-items: center;
}
.settings-grand-total-label { font-size: 13px; font-weight: 700; color: var(--ink); }
.settings-grand-total-val { font-size: 22px; font-weight: 700; color: var(--orange); }
.btn-save {
  width: 100%; background: var(--orange); color: #fff; border: none; border-radius: 12px;
  padding: 14px; font-size: 15px; font-weight: 700; cursor: pointer;
  box-shadow: 0 3px 12px rgba(232, 132, 74, 0.25);
}

/* Bottom nav */
.nav-spacer { height: 64px; flex-shrink: 0; }
.bottom-nav {
  position: absolute; bottom: 0; left: 0; right: 0; background: #fff; border-top: 1px solid var(--border);
  display: flex; z-index: 10; padding-bottom: max(4px, env(safe-area-inset-bottom));
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; padding: 8px 4px 4px;
  background: none; border: none; cursor: pointer; gap: 2px;
}
.nav-btn-text { font-size: 9px; font-weight: 600; }

/* Day entry modal */
.modal-overlay { position: absolute; inset: 0; z-index: 50; display: flex; flex-direction: column; justify-content: flex-end; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(45, 31, 23, 0.45); border: none; padding: 0; }
.modal-sheet {
  position: relative; background: #fff; border-radius: 22px 22px 0 0; padding: 0 16px 32px;
  z-index: 1; animation: slideUpSheet 0.25s ease; max-height: 88%; overflow-y: auto;
}
.modal-handle-row { display: flex; justify-content: center; padding: 12px 0 6px; }
.modal-handle { width: 36px; height: 4px; background: #E0D5C8; border-radius: 99px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-date { font-size: 16px; font-weight: 700; color: var(--ink); }
.modal-dow { font-size: 11px; color: var(--muted); }
.nospend-btn {
  border-radius: 20px; padding: 7px 14px; font-size: 11px; font-weight: 600; cursor: pointer; font-family: inherit;
  background: #fff; border: 1.5px solid #E0D5C8; color: var(--muted);
}
.nospend-btn.active { background: var(--green-bg2); border-color: var(--green); color: var(--green); }
.nospend-state { text-align: center; padding: 24px 0; background: var(--green-bg); border-radius: 14px; margin-bottom: 16px; }
.nospend-state-icon { margin-bottom: 8px; display: flex; justify-content: center; }
.nospend-state-circle {
  width: 48px; height: 48px; border-radius: 50%; border: 2.5px solid var(--green); display: flex;
  align-items: center; justify-content: center; transform: rotate(-12deg);
}
.nospend-state-circle span { font-size: 22px; color: var(--green); font-weight: 700; transform: rotate(12deg); display: block; }
.nospend-state-title { font-size: 15px; font-weight: 700; color: var(--green); }
.nospend-state-sub { font-size: 12px; color: #7BA68A; margin-top: 4px; }
.modal-cat-row { margin-bottom: 11px; }
.modal-cat-head { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.modal-badge {
  width: 22px; height: 22px; border-radius: 6px; display: flex; align-items: center;
  justify-content: center; flex-shrink: 0; font-size: 10px; font-weight: 700;
}
.modal-cat-name { font-size: 12px; font-weight: 600; color: var(--ink); }
.modal-total-row {
  background: var(--bg); border-radius: 10px; padding: 11px 14px; margin-bottom: 14px;
  display: flex; justify-content: space-between; align-items: center;
}
.modal-total-label { font-size: 12px; font-weight: 600; color: var(--ink); }
.modal-total-val { font-size: 18px; font-weight: 700; color: var(--orange); }
