/* 家計簿 v2 の見た目（SPEC §6 のトークン。モック v16 を参考） */
:root {
  --bg: #0A0A0B;
  --surface: #141416;
  --surface-2: #1E1E21;
  --line: #252529;
  --accent: #00E676;
  --danger: #FF5757;
  --warning: #FFB800;
  --muted: #9C9CA4;
  /* 黄色の3分割（同じ黄色系で、暗い背景でも見分けられる明るさの差をつける）：濃い＝返済、中＝貯蓄、薄い＝予備 */
  --yellow-rep: #E07B00;
  --yellow-evt: #FFB800;
  --yellow-res: #FFE08A;
  --dim: #7C7C84;
  --text: #F2F2F3;
  --text-2: #C8C8CE;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --sans: 'Noto Sans JP', system-ui, -apple-system, sans-serif;
  --tabbar-h: 64px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; overscroll-behavior-y: contain; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); text-decoration: none; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 0 calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}
body.no-tabs .app { padding-bottom: calc(env(safe-area-inset-bottom) + 24px); }

/* 文字・色の小物 */
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.accent { color: var(--accent); }
.danger { color: var(--danger); }
.warn { color: var(--warning); }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.mid { font-size: 20px; font-weight: 700; }
.grow { flex: 1 1 auto; }
.min0 { min-width: 0; }
.push { margin-left: auto; }
.end { align-items: flex-end; text-align: right; flex-shrink: 0; }
.stack-1 { display: flex; flex-direction: column; gap: 1px; }
.stack-2 { display: flex; flex-direction: column; gap: 2px; }
.stack-6 { display: flex; flex-direction: column; gap: 6px; }
.stack-8 { display: flex; flex-direction: column; gap: 8px; }
.line { display: flex; align-items: baseline; gap: 8px; }
.note { font-size: 11px; color: var(--muted); line-height: 1.6; padding: 2px 2px 0; }

/* 見出し */
.top {
  display: flex; align-items: center; gap: 8px;
  min-height: 56px; padding: 8px 12px 4px 16px;
}
.top .title { font-size: 16px; font-weight: 500; }
.top .title.solo { padding-left: 4px; }
.top-right { margin-left: auto; display: flex; align-items: center; }
.brand {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding-right: 8px;
  font-family: var(--mono); font-size: 13px; letter-spacing: .08em; color: var(--accent);
}
.badge-sample {
  font-family: var(--sans); letter-spacing: 0; font-size: 10px; color: var(--warning);
  border: 1px solid rgba(255,184,0,.5); border-radius: 999px; padding: 1px 7px;
}
.stamp, .close, .back {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 8px;
}
.stamp { font-size: 12px; color: var(--muted); }
.stamp.stale { color: var(--warning); }
.back { gap: 2px; font-size: 14px; color: var(--accent); margin-left: -8px; }
.close { font-size: 14px; color: var(--muted); }

.content { padding: 4px 16px 0; display: flex; flex-direction: column; gap: 12px; }

/* 面 */
.panel { background: var(--surface); border-radius: 14px; padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.panel.tight { padding: 10px 14px; flex-direction: row; align-items: center; gap: 10px; min-height: 48px; }
.panel.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }

/* ホーム：メインカード */
.hero { gap: 12px; padding: 16px 18px 14px; }
.hero-head { display: flex; align-items: center; gap: 8px; }
.label { font-size: 13px; color: var(--muted); }
.sub { font-size: 11px; color: var(--muted); }
.pill {
  margin-left: auto; display: inline-flex; align-items: center; gap: 4px;
  min-height: 44px; padding: 0 12px; border-radius: 10px;
  background: var(--surface-2); color: var(--text-2); font-size: 12px; flex-shrink: 0;
}
.big { display: flex; align-items: baseline; gap: 4px; font-family: var(--mono); }
.big .yen { font-size: 20px; font-weight: 500; }
.big-num { font-size: 50px; font-weight: 700; line-height: 1; letter-spacing: -.02em; }
.bar {
  position: relative; display: flex; height: 12px; border-radius: 4px; overflow: hidden;
  background: #252529; border-right: 3px solid var(--danger);
}
.seg.used { background: var(--accent); }
.seg.rest { background: rgba(0,230,118,.28); }
.seg.sav { background: repeating-linear-gradient(135deg, rgba(255,184,0,.55) 0 6px, rgba(255,184,0,.30) 6px 12px); }
/* 黄の斜線を3色に（左から 返済・貯蓄・予備）。区切りが見えるよう、間に細いすき間 */
.seg.rep, .seg.evt, .seg.res { box-shadow: inset -1px 0 0 var(--surface); }
.seg.rep { background: repeating-linear-gradient(135deg, var(--yellow-rep) 0 6px, rgba(224,123,0,.70) 6px 12px); }
.seg.evt { background: repeating-linear-gradient(135deg, rgba(255,184,0,.85) 0 6px, rgba(255,184,0,.55) 6px 12px); }
.seg.res { background: repeating-linear-gradient(135deg, rgba(255,224,138,.55) 0 6px, rgba(255,224,138,.28) 6px 12px); }
.legend { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; font-size: 11px; color: var(--muted); }
.legend.four { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
.legend.four b { font-size: 12px; }
.short-note {
  display: block; min-height: 32px; padding: 7px 10px; border-radius: 8px; line-height: 1.5;
  background: rgba(255,184,0,.10); color: var(--warning); font-size: 12px;
}
.legend > div { display: flex; flex-direction: column; gap: 1px; }
.legend b { font-size: 13px; font-weight: 500; color: var(--text); }
.legend b.warn { color: var(--warning); }
.sw { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; vertical-align: 1px; }
.sw.used { background: var(--accent); }
.sw.sav { background: var(--warning); }
.sw.rep { background: var(--yellow-rep); }
.sw.evt { background: var(--yellow-evt); }
.sw.res { background: var(--yellow-res); }
.hero-foot { display: flex; flex-direction: column; gap: 6px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 13px; }
.hero-foot b { font-weight: 500; }

/* ホーム：警告カード */
.warn-card {
  display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 12px 14px;
  border-radius: 13px; background: rgba(255,87,87,.09); color: var(--text);
}
.warn-ic { display: inline-flex; color: var(--danger); flex-shrink: 0; }
.warn-ic.warn { color: var(--warning); }
.warn-title { font-size: 13px; font-weight: 500; color: var(--danger); }
.warn-sub { font-size: 11px; color: var(--muted); }

/* ホーム：カード別 */
.sec-head { display: flex; align-items: center; }
.sec-head h2 { font-size: 13px; font-weight: 500; }
.sec-head .link { margin-left: auto; min-height: 44px; display: inline-flex; align-items: center; padding: 0 4px 0 12px; font-size: 12px; }
.card-row {
  display: flex; align-items: center; gap: 12px; min-height: 60px; padding: 10px 14px;
  border-radius: 12px; background: var(--surface); color: var(--text);
}
.card-row .rule { width: 3px; align-self: stretch; border-radius: 2px; background: #4A4A52; flex-shrink: 0; }
.card-row .rule.low { background: var(--danger); }
.card-row .name { font-size: 13px; font-weight: 500; }
.card-row b { font-size: 14px; }
.card-row .tiny { font-size: 10px; }

/* 内訳 */
.sec-label { font-size: 11px; font-weight: 500; padding: 10px 2px 0; }
.sec-label:first-child { padding-top: 0; }
.row {
  display: flex; align-items: center; gap: 10px; min-height: 46px; padding: 11px 14px;
  border-radius: 10px; background: var(--surface); font-size: 13px; text-align: left; width: 100%;
}
.row .mono { font-size: 15px; font-weight: 500; flex-shrink: 0; }
.row .sp { width: 14px; flex-shrink: 0; }
.row .op { color: var(--muted); margin-right: 2px; }
.row.total { background: transparent; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.row.total b, .row.strong b { font-size: 18px; font-weight: 700; }
.row.strong { font-weight: 500; }
.row.sub-row { min-height: 40px; padding: 8px 14px 8px 26px; background: transparent; }
.row.sub-row .mono { font-size: 14px; }
.row.sub-row .tiny { margin-left: 6px; }
.note.warn { color: var(--warning); }
.danger-bg { background: rgba(255,87,87,.09); }
.accent-bg { background: rgba(0,230,118,.10); }
.warn-bg { background: rgba(255,184,0,.10); }
.btn-row { border: none; color: var(--text); }
.chev { display: inline-flex; color: var(--dim); width: 14px; flex-shrink: 0; transition: transform .15s ease; }
.acc.open .chev { transform: rotate(90deg); }
.acc-body { padding: 6px 38px 8px 14px; display: flex; flex-direction: column; gap: 7px; }
.detail { display: flex; align-items: baseline; gap: 8px; font-size: 12px; color: var(--text-2); }
.d-date { font-size: 11px; width: 38px; flex-shrink: 0; }
.d-name { min-width: 0; }
.d-tag { font-size: 10px; color: var(--dim); margin-left: 6px; white-space: nowrap; }
.mark { display: inline-block; font-size: 10px; line-height: 1; padding: 2px 5px; border-radius: 4px; margin-left: 6px; vertical-align: 1px; white-space: nowrap; }
.mark.est { color: var(--warning); background: rgba(255,184,0,.14); }
.mark.tent { color: var(--muted); border: 1px solid #3A3A40; }

/* 支払い予定 */
.acct .name { font-size: 13px; font-weight: 500; }
.acct b { font-size: 15px; }
.transfer { align-items: flex-start; }
.transfer b { font-size: 14px; }
.days, .day-wrap { display: flex; flex-direction: column; gap: 8px; }
.month { font-size: 12px; font-weight: 500; color: var(--muted); padding: 8px 2px 0; }
.day { background: var(--surface); border-radius: 12px; padding: 10px 14px; display: flex; flex-direction: column; gap: 6px; }
.day-head { display: flex; align-items: baseline; gap: 2px; font-size: 13px; }
.ev { display: flex; align-items: baseline; gap: 10px; font-size: 12px; color: var(--text-2); }
.ev .mono { flex-shrink: 0; }
.more { width: 100%; }

/* カード */
.card-block { padding: 12px; gap: 8px; }
.card-block.low { outline: 1px solid rgba(255,87,87,.35); }
.card-head { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 8px; padding: 0 2px; }
.card-head .name { font-size: 14px; font-weight: 500; }
.chip-mini { font-size: 10px; color: var(--muted); background: var(--surface-2); padding: 2px 7px; border-radius: 4px; }
.tag { font-size: 11px; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.tag.accent { background: rgba(0,230,118,.12); }
.tag.danger { background: rgba(255,87,87,.12); }
.tag.warn { background: rgba(255,184,0,.12); }
.inner { background: var(--bg); border-radius: 10px; padding: 11px 12px; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.btn-row.plain { background: transparent; padding: 0 2px; min-height: 44px; gap: 6px; }
.ftable { display: flex; flex-direction: column; gap: 4px; }
.fh, .fr { display: grid; grid-template-columns: minmax(0, 1fr) 52px 96px; gap: 6px; align-items: center; padding: 0 8px; }
.fh { font-size: 10px; color: var(--dim); }
.fr { font-size: 12px; color: var(--text-2); background: var(--bg); border-radius: 8px; padding: 8px; }
.r { text-align: right; }

/* 入力 */
.input { gap: 14px; }
.seg-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: var(--surface); border-radius: 12px; padding: 4px; }
.seg-tabs button { min-height: 44px; border: none; border-radius: 9px; background: transparent; color: var(--muted); font-size: 13px; }
.seg-tabs button.on { background: var(--surface-2); color: var(--text); font-weight: 500; }
.amount-box { gap: 2px; padding: 12px 18px; }
.amount { display: flex; align-items: baseline; gap: 6px; }
.amount .yen { font-family: var(--mono); font-size: 20px; color: var(--muted); }
.amount-num { font-size: 38px; font-weight: 700; line-height: 1.15; letter-spacing: -.02em; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips.col { flex-direction: column; align-items: stretch; }
.chip {
  min-height: 44px; padding: 0 16px; border-radius: 999px; font-size: 13px;
  border: 1px solid #2A2A30; background: var(--surface); color: var(--text-2); text-align: left;
}
.chip.on { border-color: var(--accent); background: rgba(0,230,118,.14); color: var(--accent); font-weight: 500; }
.preview { background: var(--surface); border-radius: 12px; padding: 10px 14px; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.key {
  min-height: 48px; border: none; border-radius: 10px; background: var(--surface);
  font-size: 20px; display: flex; align-items: center; justify-content: center;
}
.key:active { background: var(--surface-2); }
.btn {
  min-height: 48px; border-radius: 12px; border: 1px solid #2A2A30; background: var(--surface);
  font-size: 15px; font-weight: 500; display: inline-flex; align-items: center; justify-content: center; padding: 0 16px;
}
.btn.primary { background: var(--accent); color: #04140B; border: none; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn:disabled { opacity: .5; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field input {
  min-height: 46px; border-radius: 10px; border: 1px solid #2A2A30; background: var(--surface);
  padding: 0 12px; font-size: 16px; font-family: var(--mono);
}

/* 下のタブ */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(10,10,11,.96); border-top: 1px solid var(--surface-2);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.tab {
  flex: 1 1 0; max-width: 120px; min-width: 0; text-align: center; white-space: nowrap; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; font-size: 10px; color: var(--dim);
}
.tab.on { color: var(--accent); }

/* 返済と貯金（準備中） */
.soon { gap: 6px; }
.soon b { font-size: 13px; font-weight: 500; color: var(--text-2); }

/* 下に引っ張って計算し直す */
.ptr {
  position: fixed; top: calc(env(safe-area-inset-top) + 8px); left: 50%; z-index: 30;
  width: 36px; height: 36px; border-radius: 50%; display: none; align-items: center; justify-content: center;
  background: var(--surface-2); color: var(--accent); box-shadow: 0 2px 10px rgba(0,0,0,.5);
  transform: translate(-50%, -44px); opacity: 0; transition: transform .2s ease, opacity .2s ease;
  pointer-events: none;
}
.ptr.on { display: flex; }
.ptr-ic { display: inline-flex; }
.ptr-arrow { transition: transform .15s ease; color: var(--muted); }
.ptr.ready .ptr-arrow { transform: rotate(180deg); color: var(--accent); }
.ptr-spin { display: none; }
.ptr.spinning .ptr-arrow { display: none; }
.ptr.spinning .ptr-spin { display: inline-flex; animation: ptr-rot .8s linear infinite; }
@keyframes ptr-rot { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .ptr.spinning .ptr-spin { animation-duration: 2s; } }

/* その他 */
.loading { padding: 40px 16px; text-align: center; color: var(--muted); font-size: 13px; }
.error-box { margin: 40px 16px; padding: 16px; border-radius: 14px; background: var(--surface); display: flex; flex-direction: column; gap: 10px; }
.error-box p { color: var(--danger); font-size: 13px; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px); z-index: 20;
  transform: translate(-50%, 8px); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  background: #2A2A30; color: var(--text); font-size: 13px; padding: 10px 16px; border-radius: 10px;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.ic { flex-shrink: 0; }
