/* ==========================================================================
   わたしの家計 — スタイル

   設計方針:
   - 影は使わない。面の区切りはヘアライン(1px)と余白で表現する。
   - 彩度は低く保つ。アクセント色は「進捗バー」と「現在地」だけに使う。
   - フォントウェイトは 400 / 500 / 600 の3段のみ。太字の多用を避ける。
   ========================================================================== */

/* --- トークン ------------------------------------------------------------ */

:root {
  --bg: #f7f6f3;          /* ページ背景。わずかに暖色の紙色 */
  --card: #ffffff;
  --ink: #2b2e2c;         /* 本文・数値 */
  --muted: #63675f;       /* 補助テキスト。白地でコントラスト比 5.8 */
  --faint: #73776f;       /* 弱いテキスト。白地でコントラスト比 4.6（AA下限） */
  --line: #e6e4de;        /* ヘアライン */
  --field: #fbfaf8;       /* 入力欄の下地 */

  --accent: #5f7d6c;      /* セージグリーン。自由費まわり */
  --accent-soft: #eaefea;
  --warm: #a8825c;        /* くすんだ砂色。食費まわり */
  --warm-soft: #f1ece4;
  --play: #6e8399;        /* くすんだ青。趣味娯楽まわり */
  --play-soft: #eaeef2;

  --radius-card: 14px;
  --radius-ctl: 10px;

  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-feature-settings: "palt";
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button { cursor: pointer; }

h1, h2, h3, p { margin-top: 0; }
h1 { font-size: 1.3rem; font-weight: 600; margin-bottom: 0; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; font-weight: 600; margin-bottom: 0; letter-spacing: -.01em; }

/* --- アイコン ------------------------------------------------------------ */

/* display:none だと <use> の参照が壊れるブラウザがあるため、潰して隠す */
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

.icon.lead {
  width: 22px;
  height: 22px;
  color: var(--warm);
}

/* --- レイアウト ---------------------------------------------------------- */

.shell {
  width: min(100%, 560px);
  margin: auto;
  padding: calc(20px + env(safe-area-inset-top)) 18px calc(104px + env(safe-area-inset-bottom));
}

.row, .topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar { margin-bottom: 18px; }

.page { display: none; }
.page.active { display: block; animation: fade .18s ease; }

@keyframes fade {
  from { opacity: 0; transform: translateY(3px); }
}

.page-title { margin: 6px 2px 16px; }

/* --- テキスト ------------------------------------------------------------ */

.eyebrow {
  font-size: .74rem;
  color: var(--muted);
  font-weight: 500;
  margin-bottom: 4px;
  letter-spacing: .02em;
}

.label {
  font-size: .8rem;
  color: var(--muted);
  font-weight: 500;
  margin-bottom: 0;
}

.muted, .meta {
  color: var(--muted);
  font-size: .8rem;
}

.big {
  display: block;
  font-size: 2.4rem;
  font-weight: 500;
  letter-spacing: -.035em;
  margin: 6px 0 16px;
  font-variant-numeric: tabular-nums;
}

.medium {
  display: block;
  font-size: 1.75rem;
  font-weight: 500;
  letter-spacing: -.025em;
  margin: 6px 0 2px;
  font-variant-numeric: tabular-nums;
}

/* --- カード -------------------------------------------------------------- */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  padding: 18px;
  margin-bottom: 12px;
}

.card-head { margin-bottom: 2px; }

.head-text {
  display: flex;
  align-items: center;
  gap: 9px;
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--warm-soft);
  color: #7a5f3e;
  font-size: .68rem;
  font-weight: 500;
}

/* ヒーローも通常のカードと同じ白面。数字の大きさだけで主役にする */
.hero .stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 16px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.stats div { padding-left: 9px; border-left: 1px solid var(--line); min-width: 0; }
.stats div:first-child { border: 0; padding-left: 0; }
.stats dt { font-size: .68rem; color: var(--muted); white-space: nowrap; }
.stats dd {
  margin: 3px 0 0;
  font-size: .8rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hero small { display: block; margin-top: 8px; }

/* --- 進捗バー ------------------------------------------------------------ */

.bar {
  height: 3px;
  background: var(--line);
  border-radius: 99px;
  overflow: hidden;
}

.bar span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  border-radius: inherit;
  transition: width .3s ease;
}

.bar.warm { background: var(--warm-soft); margin-top: 14px; }
.bar.warm span { background: var(--warm); }

.meta { margin: 8px 0 16px; }

/* --- ボタン -------------------------------------------------------------- */

.primary, .secondary {
  border: 1px solid transparent;
  border-radius: var(--radius-ctl);
  padding: 13px 18px;
  font-weight: 500;
}

.primary {
  width: 100%;
  background: var(--accent);
  color: #fff;
}

/* 主要導線ではない「食費を入力」など、面で主張させたくないボタン */
.primary.quiet {
  background: var(--card);
  border-color: var(--line);
  color: var(--ink);
}

.primary.compact { width: auto; padding: 9px 15px; font-size: .88rem; }

.secondary {
  background: var(--card);
  border-color: var(--line);
  color: var(--ink);
  text-align: center;
  flex: 1;
}

.link {
  border: 0;
  background: none;
  color: var(--accent);
  font-weight: 500;
  font-size: .8rem;
  padding: 0;
}

.icon-btn {
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  border-radius: 50%;
  width: 38px;
  height: 38px;
}

/* --- 明細リスト ---------------------------------------------------------- */

.list:empty::after {
  content: "まだ記録がありません";
  display: block;
  text-align: center;
  color: var(--faint);
  font-size: .82rem;
  padding: 26px 0 8px;
}

.transaction {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
}

.transaction:last-child { border: 0; padding-bottom: 0; }

.tx-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
}

.transaction.food .tx-icon { background: var(--warm-soft); color: var(--warm); }
.transaction.hobby .tx-icon { background: var(--play-soft); color: var(--play); }
.transaction .icon { width: 17px; height: 17px; }

.transaction strong { display: block; font-weight: 500; font-size: .92rem; }
.transaction small { display: block; color: var(--muted); font-size: .74rem; margin-top: 2px; }

.tx-value { text-align: right; }
.tx-value strong { font-variant-numeric: tabular-nums; }

.delete {
  border: 0;
  background: none;
  color: var(--faint);
  font-size: .7rem;
  padding: 2px 0 0;
}

/* --- 月切り替え ---------------------------------------------------------- */

.month-switch {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--line);
  padding: 4px;
  border-radius: var(--radius-ctl);
  margin-bottom: 12px;
}

.month-switch button {
  display: grid;
  place-items: center;
  border: 0;
  background: none;
  color: var(--muted);
  padding: 7px 14px;
}

.month-switch strong { font-weight: 500; font-size: .95rem; }

/* --- レポート ------------------------------------------------------------ */

.report { display: flex; align-items: center; gap: 20px; }

.ring {
  position: relative;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: conic-gradient(var(--warm) 0%, var(--warm-soft) 0);
}

.ring::before {
  content: "";
  position: absolute;
  width: 76px;   /* 内円を大きくしてリングを細くする */
  height: 76px;
  border-radius: 50%;
  background: var(--card);
}

.ring span { z-index: 1; font-weight: 500; font-size: .95rem; }

.breakdown { margin: 10px 0 0; }

.breakdown div {
  display: flex;
  justify-content: space-between;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
  font-size: .9rem;
}

.breakdown dt { color: var(--muted); }
.breakdown dd { margin: 0; font-weight: 500; font-variant-numeric: tabular-nums; }
.breakdown .total { border: 0; padding-bottom: 0; }
.breakdown .total dt { color: var(--ink); }
.breakdown .total dd { color: var(--accent); }

/* --- フォーム ------------------------------------------------------------ */

.form, .dialog-form { display: grid; gap: 15px; }

.form label, .dialog-form > label {
  display: grid;
  gap: 7px;
  font-size: .82rem;
  font-weight: 500;
  color: var(--muted);
}

input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-ctl);
  background: var(--field);
  color: var(--ink);
}

input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.note {
  margin: 0;
  padding: 12px;
  border-radius: var(--radius-ctl);
  background: var(--field);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: .76rem;
  line-height: 1.7;
}

.gap { gap: 10px; }
.file input { display: none; }

/* --- ナビゲーション ------------------------------------------------------ */

.nav {
  position: fixed;
  z-index: 10;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(100%, 560px);
  height: calc(70px + env(safe-area-inset-bottom));
  padding: 9px 14px env(safe-area-inset-bottom);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--card);
  border-top: 1px solid var(--line);
}

.nav button {
  display: grid;
  justify-items: center;
  gap: 3px;
  border: 0;
  background: none;
  color: var(--faint);
  font-size: .66rem;
  font-weight: 500;
}

.nav .active { color: var(--accent); }

.fab {
  position: fixed;
  z-index: 11;
  right: max(20px, calc((100vw - 560px) / 2 + 20px));
  bottom: calc(84px + env(safe-area-inset-bottom));
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
}

.fab .icon { width: 24px; height: 24px; stroke-width: 1.75; }

/* --- ダイアログ ---------------------------------------------------------- */

dialog {
  width: min(calc(100% - 24px), 520px);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0;
  color: var(--ink);
  background: var(--card);
}

dialog::backdrop { background: #1b201d5c; }

.dialog-form { padding: 20px; }

.segments {
  border: 1px solid var(--line);
  margin: 0;
  padding: 3px;
  background: var(--field);
  border-radius: var(--radius-ctl);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}

.segments input { display: none; }

.segments span {
  display: block;
  text-align: center;
  padding: 9px 4px;
  border-radius: 7px;
  font-weight: 500;
  font-size: .85rem;
  color: var(--muted);
  white-space: nowrap;
}

.segments input:checked + span { background: var(--card); color: var(--ink); }

.amount div { display: flex; align-items: center; font-size: 1.4rem; color: var(--muted); }

.amount input {
  border: 0;
  background: none;
  font-size: 1.9rem;
  font-weight: 500;
  color: var(--ink);
  padding: 3px;
  letter-spacing: -.02em;
}

.amount input:focus { box-shadow: none; }

.tax { border: 0; margin: 0; padding: 0; display: grid; gap: 8px; }
.tax legend { font-size: .82rem; font-weight: 500; color: var(--muted); margin-bottom: 7px; }

.tax label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: var(--radius-ctl);
  font-size: .88rem;
}

.tax input { width: auto; }

/* --- 更新通知・トースト -------------------------------------------------- */

.update {
  position: sticky;
  top: calc(8px + env(safe-area-inset-top));
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding: 11px 14px;
  border-radius: var(--radius-ctl);
  background: var(--warm-soft);
  border: 1px solid #e2d6c3;
  color: #7a5f3e;
  font-size: .85rem;
}

.update .link { color: #7a5f3e; text-decoration: underline; }

#toast {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: 106px;
  transform: translate(-50%, 12px);
  padding: 10px 18px;
  border-radius: 99px;
  background: var(--ink);
  color: var(--bg);
  font-size: .85rem;
  opacity: 0;
  transition: .2s;
  pointer-events: none;
}

#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* --- ユーティリティ ------------------------------------------------------ */

.hidden { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

/* --- 小さい画面 ---------------------------------------------------------- */

@media (max-width: 370px) {
  .shell { padding-left: 13px; padding-right: 13px; }
  .big { font-size: 2.05rem; }
  .stats dt { font-size: .63rem; }
  .stats dd { font-size: .72rem; }
  .stats div { padding-left: 7px; }
  .segments span { font-size: .8rem; }
}

/* --- ダークモード -------------------------------------------------------- */

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141614;
    --card: #1c1f1d;
    --ink: #e9ece8;
    --muted: #949a93;
    --faint: #858b84;
    --line: #2b2f2c;
    --field: #212523;

    --accent: #86a794;
    --accent-soft: #263029;
    --warm: #c3a179;
    --warm-soft: #322a20;
    --play: #93a8bd;
    --play-soft: #232b33;
  }

  .badge { color: #d9bd95; }
  .primary { color: #141614; }
  .fab { color: #141614; }
  .update { border-color: #453724; color: #d9bd95; }
  .update .link { color: #d9bd95; }
  dialog::backdrop { background: #0b0d0ca8; }
}
