/*
 * 家計簿の見た目。色と書体の決まりは CLAUDE.md「画面の見た目」「雰囲気とキャラクター」。
 * 文字の基本は黄金色、白はアクセント。紫は使わない。
 */

/* 書体（fonts/ に同梱。Google Fonts・SIL Open Font License。決まりは fonts/OFL-*.txt）
   読み込みが終わるまでは、スマホの明朝体・Georgia で表示する */
@font-face { font-family: 'Shippori Mincho'; src: local('Shippori Mincho'), url('fonts/ShipporiMincho-Regular.ttf') format('truetype'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Cormorant Garamond'; src: local('Cormorant Garamond'), url('fonts/CormorantGaramond-Variable.ttf') format('truetype'); font-weight: 300 700; font-display: swap; }

:root {
  --ink: #0d0d0f;
  --card: #16150f;
  --panel: #121110;
  --line: #2e2a22;
  --line2: #4a4130;
  --gold: #d4b26f;
  --gold-sub: #9e8a62;
  --gold-dim: #b89a5e;
  --white: #f4efe4;
  --red: #d9534f;
  --serif: 'Shippori Mincho', 'Hiragino Mincho ProN', 'Yu Mincho', 'YuMincho', 'Noto Serif JP', serif;
  --num: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--ink); color: var(--gold); }
body {
  font-family: var(--serif);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
body.lock { overflow: hidden; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; margin: 0; cursor: pointer; text-align: inherit; }
button:focus-visible, .inp:focus-visible { outline: 1px solid var(--white); outline-offset: 2px; }

.num { font-family: var(--num); font-weight: 700; letter-spacing: 0.3px; font-variant-numeric: oldstyle-nums proportional-nums; }
.sub { font-size: 11px; color: var(--gold-sub); }
.accent { color: var(--white); }
.yen { white-space: nowrap; color: var(--gold); }
.yen .num { font-size: 16px; }
.yen .unit { font-size: 11px; margin-left: 1px; }
.yen.neg { color: var(--red); }
.row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 4px 0; width: 100%; }

#app { max-width: 480px; margin: 0 auto; padding: calc(10px + env(safe-area-inset-top)) 14px calc(96px + env(safe-area-inset-bottom)); }

/* ---------- 上の帯 ---------- */
.top { display: flex; justify-content: space-between; align-items: center; }
.cat-moon { width: 54px; height: 54px; filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.9)); }
.cat-face {
  width: 100%; height: 100%;
  background: url('assets/cat-face.jpg') center / cover;
  filter: grayscale(1) sepia(0.35) brightness(0.9) contrast(1.05);
  -webkit-mask-image: radial-gradient(circle at 50% 48%, #000 38%, transparent 70%);
  mask-image: radial-gradient(circle at 50% 48%, #000 38%, transparent 70%);
}
.float { animation: float 5s ease-in-out infinite; }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
.month-nav { display: flex; align-items: center; gap: 4px; }
.icon-btn { min-width: 44px; min-height: 44px; display: flex; align-items: center; justify-content: center; color: var(--gold-sub); font-size: 20px; }
.month-label { font-size: 24px; letter-spacing: 2px; color: var(--white); }
.top-spacer { width: 54px; }
.pin { height: 8px; margin: 6px 0 10px; background: repeating-linear-gradient(90deg, var(--gold) 0 2px, transparent 2px 7px); opacity: 0.5; }

/* ---------- カード ---------- */
.card { display: block; width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; margin-top: 8px; }
.summary { padding: 12px; margin-top: 0; }
.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; }
.hint { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 6px; font-size: 12px; letter-spacing: 2px; color: var(--white); }
.empty-budget p { margin: 0 0 10px; color: var(--white); }
.sec-title { font-size: 12px; color: var(--gold-sub); letter-spacing: 2px; margin: 0 0 4px; font-weight: 400; }
.sec { font-size: 12px; color: var(--gold-sub); margin: 22px 0 6px; letter-spacing: 2px; display: flex; align-items: center; gap: 8px; font-weight: 400; }
.sec::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* ---------- 固定費 ---------- */
.fixed-line { display: block; width: 100%; text-align: center; padding: 8px 4px; }
.fx-group { border-top: 1px solid var(--line); padding-top: 6px; margin-top: 4px; }
.fx-gname { color: var(--white); letter-spacing: 1px; }
.fx-item { padding-left: 14px; }
.total { border-top: 1px solid var(--gold); margin-top: 8px; padding-top: 6px; }

/* ---------- カレンダー ---------- */
.calendar { position: relative; margin-top: 10px; }
.ghost {
  position: absolute; inset: 4px -6px 0;
  background: url('assets/cat-branch.jpg') center 60% / contain no-repeat;
  filter: invert(1) grayscale(1) sepia(0.6);
  opacity: 0.11; pointer-events: none;
  -webkit-mask-image: radial-gradient(ellipse at center, #000 45%, transparent 78%);
  mask-image: radial-gradient(ellipse at center, #000 45%, transparent 78%);
}
.wd, .grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; position: relative; }
.wd { text-align: center; font-size: 11px; color: var(--gold-sub); margin-bottom: 3px; }
.wd .sun { color: var(--red); }
.day { height: 54px; border-radius: 4px; border: 1px solid transparent; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding-top: 3px; }
.day.sel { background: rgba(212, 178, 111, 0.16); }
.day.today { border-color: var(--white); }
.day.future { opacity: 0.4; }
.dnum { font-size: 19px; line-height: 1.2; color: var(--gold); }
.day.today .dnum { color: var(--white); }
.damt { font-size: 13.5px; line-height: 1.3; color: var(--gold-dim); }
.damt.neg { color: var(--red); }
.grin { margin-top: 3px; animation: grin 4s ease-in-out infinite; filter: drop-shadow(0 0 3px rgba(212, 178, 111, 0.6)); }
@keyframes grin { 0%, 100% { opacity: 0.55; transform: translateY(0); } 50% { opacity: 0.95; transform: translateY(-2px); } }

/* ---------- 日の中身 ---------- */
.day-panel { border-color: var(--line2); margin-top: 10px; }
.jpdate { white-space: nowrap; }
.jpdate .num { font-size: 17px; }
.item { border-radius: 4px; padding: 6px 4px; }
.item:active { background: #221d12; }
.item-main { min-width: 0; }
.memo { display: block; font-size: 11px; color: var(--gold-sub); }
.item-amt { white-space: nowrap; }
.pencil { color: #7a6a4a; margin-left: 4px; vertical-align: -1px; }
.empty-day { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.cat-branch {
  width: 90px; height: 70px; flex-shrink: 0;
  background: url('assets/cat-branch.jpg') center / cover;
  filter: grayscale(1) sepia(0.35) brightness(0.9);
  -webkit-mask-image: radial-gradient(ellipse at center, #000 40%, transparent 72%);
  mask-image: radial-gradient(ellipse at center, #000 40%, transparent 72%);
}

/* ---------- 週・カテゴリー ---------- */
.week.now { border-color: var(--gold); }
.wrange { font-size: 18px; }
.wday { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 6px; }
.cat-row { border-bottom: 1px solid var(--line); padding: 6px 0; }

/* ---------- グラフ ---------- */
.donut { display: flex; justify-content: center; }
.ring { fill: none; stroke: var(--gold); stroke-width: 0.6; }
.donut-label { font-size: 11px; fill: var(--gold-sub); text-anchor: middle; font-family: var(--serif); }
.donut-total { font-size: 20px; font-weight: 700; fill: var(--white); text-anchor: middle; font-family: var(--num); font-variant-numeric: oldstyle-nums; }
.legend { padding: 2px 0; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.bar-title { margin-top: 16px; }
.bar-item { margin-top: 12px; }
.bar { position: relative; height: 10px; margin-top: 2px; }
.bar-budget { position: absolute; left: 0; top: 0; height: 10px; background: var(--line); border: 1px solid var(--line2); border-radius: 3px; }
.bar-fill { position: absolute; left: 0; top: 0; height: 10px; border-radius: 3px 0 0 3px; }
.bar-over { position: absolute; top: 0; height: 10px; min-width: 4px; background: var(--red); border-radius: 0 3px 3px 0; }
.neg-text { font-size: 11px; color: var(--red); }
.note { margin: 12px 0 0; }

/* ---------- 一番下の帯 ---------- */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  background: var(--panel); border-top: 1px solid var(--line2);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabbar::before {
  content: ""; position: absolute; left: 0; right: 0; top: 3px; height: 4px;
  background: repeating-linear-gradient(90deg, var(--gold) 0 1px, transparent 1px 6px); opacity: 0.22; pointer-events: none;
}
.tabbar-inner { max-width: 480px; margin: 0 auto; height: 64px; display: flex; justify-content: space-around; align-items: flex-end; padding-bottom: 6px; }
.tab { display: flex; flex-direction: column; align-items: center; gap: 2px; width: 64px; font-size: 10px; letter-spacing: 1px; color: #7a6a4a; position: relative; }
.tab.on { color: var(--gold); }
.tab.on::after { content: ""; width: 18px; height: 1px; background: var(--gold); margin-top: 1px; }
.tab .tab-line { fill: none; stroke: currentColor; stroke-width: 1.2; stroke-linejoin: round; }
.tab .tab-fill { fill: currentColor; }
.tab-center { top: -16px; color: var(--gold); }
.tab-center svg { filter: drop-shadow(0 7px 9px rgba(0, 0, 0, 0.95)) drop-shadow(0 0 5px rgba(168, 141, 85, 0.35)); animation: float 5s ease-in-out infinite; }
.tab-center span { margin-top: -10px; }
.fab-paw { fill: #0b0a0c; stroke: #a88d55; stroke-width: 0.6; }
.fab-cross { fill: #e6ddc8; opacity: 0.6; }

#toast {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--card); border: 1px solid var(--gold); color: var(--white);
  padding: 8px 18px; border-radius: 20px; font-size: 13px; z-index: 40; white-space: nowrap;
}

/* ---------- 入力の画面（下から出る） ---------- */
#sheet { position: fixed; inset: 0; z-index: 30; }
.backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.65); }
.panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-width: 480px; margin: 0 auto; max-height: 92vh; overflow: auto;
  background: var(--panel); border-top: 1px solid var(--gold); border-radius: 16px 16px 0 0;
  padding: 10px 16px calc(24px + env(safe-area-inset-bottom));
}
.grip { width: 40px; height: 4px; border-radius: 2px; background: var(--line2); margin: 0 auto 8px; }
.panel-title, .set-head h1 { font-size: 15px; font-weight: 400; letter-spacing: 2px; color: var(--white); margin: 0; }
.field { display: block; margin-top: 12px; }
.inp { display: block; width: 100%; background: var(--ink); color: var(--white); border: 1px solid var(--line2); border-radius: 4px; padding: 8px 10px; font-family: inherit; font-size: 16px; margin-top: 3px; }
.inp:focus { outline: none; border-color: var(--gold); }
.inp.big { font-size: 24px; }
.inp::placeholder { color: #5e5340; }
.err { font-size: 12px; color: var(--red); min-height: 16px; margin-top: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.chip { border: 1px solid var(--line2); border-radius: 16px; padding: 5px 12px; font-size: 13px; }
.chip.on { border-color: var(--white); background: #2a2416; color: var(--white); }
.chip .x { margin-left: 6px; color: var(--gold-sub); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; align-items: center; }
.btn { border: 1px solid var(--gold); border-radius: 4px; padding: 8px 18px; font-size: 13px; letter-spacing: 1px; }
.btn.gold { background: var(--gold); color: var(--ink); }
.btn.danger { border-color: var(--red); color: var(--red); margin-left: auto; }

/* ---------- 設定 ---------- */
#settings { position: fixed; left: 0; right: 0; top: 0; bottom: calc(64px + env(safe-area-inset-bottom)); z-index: 20; background: var(--ink); overflow: auto; }
.settings-inner { max-width: 480px; margin: 0 auto; padding: calc(10px + env(safe-area-inset-top)) 14px 40px; }
.set-head { display: flex; align-items: center; justify-content: center; min-height: 54px; }
.set { margin-top: 14px; }
.set p { margin: 4px 0; }
.list-item { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; width: 100%; padding: 8px 2px; border-top: 1px solid var(--line); }
.list-item.ended { opacity: 0.5; }
.add-btn { margin-top: 10px; color: var(--white); }
.form { border-top: 1px solid var(--gold); margin-top: 8px; padding-top: 2px; }
.history { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 6px; }
.swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; margin-top: 6px; }
.swatch { height: 30px; border-radius: 4px; box-shadow: inset 0 0 0 1px rgba(244, 239, 228, 0.12); position: relative; }
.swatch.on { box-shadow: 0 0 0 2px var(--ink), 0 0 0 3px var(--white); }
.swatch.used::after { content: ""; position: absolute; right: 3px; top: 3px; width: 5px; height: 5px; border-radius: 50%; background: var(--ink); opacity: 0.7; }

/* ---------- グラフ画面の線グラフ・月ごとの棒 ---------- */
.chart { display: block; width: 100%; height: auto; margin-top: 6px; overflow: visible; }
.chart .grid { stroke: var(--line2); stroke-width: 1; stroke-dasharray: 2 4; }
.chart .base { stroke: var(--line2); stroke-width: 1; }
.chart .axis { fill: var(--gold-sub); font-size: 10px; font-family: var(--num); font-weight: 700; font-variant-numeric: oldstyle-nums; }
.chart .ideal { stroke: var(--gold-sub); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart .today-line { stroke: var(--line2); stroke-width: 1; }
.chart .actual { fill: none; stroke: var(--gold); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .actual.over { stroke: var(--red); }
.chart .dot { fill: var(--gold); stroke: var(--card); stroke-width: 2; }
.chart .dot.over { fill: var(--red); }
.chart .mbar { fill: var(--gold); }
.chart .mbar.over { fill: var(--red); }
.chart .mbar.cur { opacity: 0.55; }
.chart .mval { fill: var(--gold); font-size: 11px; font-family: var(--num); font-weight: 700; font-variant-numeric: oldstyle-nums; }
.chart .mval.over { fill: var(--red); }
.pace-msg { margin: 2px 0 0; font-size: 12px; }
.legend-line { display: flex; gap: 16px; margin-top: 6px; font-size: 11px; color: var(--gold-sub); }
.legend-line i { display: inline-block; width: 18px; height: 0; vertical-align: middle; margin-right: 6px; }
.lg-actual { border-top: 2px solid var(--gold); }
.lg-ideal { border-top: 2px dashed var(--gold-sub); }
.cmp-row { border-top: 1px solid var(--line); padding: 6px 0 4px; }
.cmp-row:first-of-type { border-top: 0; }
.cmp-row .unit { font-size: 11px; margin-left: 1px; }

@media (prefers-reduced-motion: reduce) {
  .float, .grin, .tab-center svg { animation: none; }
}

/* 入力画面から新しいカテゴリーを足す欄 */
.new-cat { border: 1px solid var(--line2); border-radius: 6px; padding: 8px 10px; margin-top: 8px; }
.new-cat .actions { margin-top: 8px; }

/* 円グラフの「固定費を含む／含まない」の切り替え */
.donut-switch { justify-content: center; margin: 0 0 8px; }
