:root {
  --bg: #141413;
  --surface: #1f1f1e;
  --surface-2: #2a2a28;
  --border: #383835;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #8d8c85;
  --plus: #3987e5;      /* 勝ち（プラス） */
  --minus: #e5534b;     /* 負け（マイナス） */
  --plus-bg: rgba(57, 135, 229, .18);
  --minus-bg: rgba(229, 83, 75, .18);
  --accent: #f2b233;
  --grid: #2f2f2d;
  --radius: 14px;
  --tab-h: 64px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 84px);
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2 { margin: 0; }
h2 { font-size: 15px; font-weight: 700; margin-bottom: 10px; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: baseline; gap: 10px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: rgba(20, 20, 19, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 18px; letter-spacing: .04em; }
.topbar h1::first-letter { color: var(--accent); }
.topbar .sub { color: var(--muted); font-size: 12px; }

main { max-width: 760px; margin: 0 auto; padding: 12px; }
.view { display: none; }
.view.active { display: block; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.card-head h2 { margin: 0; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 4px; font-size: 13px; }

.plus { color: var(--plus); }
.minus { color: var(--minus); }

/* hero */
.hero { text-align: center; padding: 20px 14px; }
.hero-label { color: var(--text-2); font-size: 13px; }
.hero-value { font-size: 40px; font-weight: 800; letter-spacing: .01em; font-variant-numeric: tabular-nums; margin: 2px 0; }
.hero-meta { color: var(--text-2); font-size: 13px; }
.goal { margin-top: 14px; text-align: left; }
.goal-text { font-size: 12px; color: var(--text-2); margin-bottom: 4px; }
.goal-bar { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.goal-bar div { height: 100%; width: 0; background: var(--plus); border-radius: 4px; transition: width .3s; }
.goal.warn .goal-bar div { background: var(--minus); }
.goal.warn .goal-text { color: var(--minus); }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px; min-width: 0; }
.t-label { font-size: 11px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.t-value { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.t-value.small { font-size: 13px; }
@media (max-width: 380px) { .tiles { grid-template-columns: repeat(2, 1fr); } }

/* entries */
.entries { list-style: none; margin: 0; padding: 0; }
.entries li {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px;
  padding: 10px 4px; border-top: 1px solid var(--border); cursor: pointer;
}
.entries li:first-child { border-top: 0; }
.entries li:hover { background: var(--surface-2); }
.e-title { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.e-bal { font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.e-sub { font-size: 12px; color: var(--text-2); grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.badge { font-size: 10px; padding: 1px 6px; border-radius: 6px; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.empty { color: var(--muted); text-align: center; padding: 18px 0; font-size: 13px; cursor: default !important; }
.empty:hover { background: none !important; }

/* month nav + calendar */
.month-nav { display: flex; align-items: center; justify-content: space-between; }
.month-title { text-align: center; font-weight: 700; }
.month-sum { font-size: 22px; font-variant-numeric: tabular-nums; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface-2); cursor: pointer; font-size: 20px; line-height: 1;
}
.cal-head, .calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-head span { text-align: center; font-size: 11px; color: var(--muted); padding-bottom: 4px; }
.cal-head span:first-child { color: var(--minus); }
.cal-head span:last-child { color: var(--plus); }
.day {
  aspect-ratio: 1 / 1.05; border-radius: 8px; background: var(--surface-2);
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 3px 4px; font-size: 11px; cursor: pointer; border: 2px solid transparent; min-width: 0;
}
.day.out { visibility: hidden; }
.day.today { border-color: var(--accent); }
.day.sel { border-color: var(--text); }
.day .d-num { color: var(--text-2); }
.day .d-bal { font-weight: 700; text-align: right; font-size: 10.5px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; }
.day.win { background: var(--plus-bg); }
.day.lose { background: var(--minus-bg); }

/* filters */
.filters { display: flex; gap: 12px; flex-wrap: wrap; }
.filters label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); }
select, input[type=text], input[type=password], input[type=email], input[type=number], input[type=date], textarea {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 10px; width: 100%; min-width: 0;
}
.filters select { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; }

/* charts */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis-text { fill: var(--muted); font-size: 11px; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .zero-line { stroke: var(--muted); stroke-width: 1; }
.chart .chart-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 30px 0; }
.tooltip {
  position: fixed; z-index: 50; pointer-events: none; opacity: 0;
  background: #0b0b0b; border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; font-size: 12px; color: var(--text); white-space: nowrap;
  transition: opacity .1s; box-shadow: 0 4px 16px rgba(0,0,0,.4);
}
.tooltip.show { opacity: 1; }
.tooltip b { font-variant-numeric: tabular-nums; }

/* tables */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.tbl th { text-align: right; color: var(--muted); font-weight: 500; font-size: 11px; padding: 4px 6px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tbl th:first-child, .tbl td:first-child { text-align: left; }
.tbl td { text-align: right; padding: 7px 6px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tbl td:first-child { max-width: 140px; overflow: hidden; text-overflow: ellipsis; }
.tbl tr:last-child td { border-bottom: 0; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 10px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); cursor: pointer; font-weight: 600; font-size: 14px;
}
.btn.primary { background: var(--accent); color: #1a1a19; border-color: var(--accent); min-width: 120px; }
.btn.danger { color: var(--minus); border-color: rgba(229,83,75,.5); }
.btn.ghost { background: transparent; }
.btn.small { padding: 8px 10px; font-size: 13px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.btn-row.end { justify-content: space-between; }
.btn-row.end .primary { margin-left: auto; }

.field { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 10px; }
.field input, .field select, .field textarea { margin-top: 4px; color: var(--text); font-size: 16px; }
.hint { color: var(--text-2); font-size: 13px; margin: 0 0 6px; }
.version { text-align: center; color: var(--muted); font-size: 12px; }

/* fab + tabbar */
.fab {
  position: fixed; right: 18px; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 16px);
  width: 58px; height: 58px; border-radius: 50%; border: 0;
  background: var(--accent); color: #1a1a19; font-size: 30px; font-weight: 700;
  box-shadow: 0 6px 20px rgba(0,0,0,.45); cursor: pointer; z-index: 20;
}
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(20,20,19,.96); border-top: 1px solid var(--border);
}
.tabbar button {
  background: none; border: 0; color: var(--muted); font-size: 11px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.tabbar .ic { font-size: 20px; line-height: 1; }
.tabbar button.active { color: var(--accent); }

/* dialog */
dialog {
  border: 1px solid var(--border); border-radius: 18px 18px 0 0; padding: 0;
  background: var(--surface); color: var(--text);
  width: 100%; max-width: 560px; max-height: 92vh;
  margin: auto auto 0; overflow: auto;
}
@media (min-width: 600px) { dialog { border-radius: 18px; margin: auto; } }
dialog::backdrop { background: rgba(0,0,0,.6); }
#entryForm { padding: 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.sheet-head h2 { margin: 0; font-size: 17px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border-radius: 10px; padding: 3px; margin-bottom: 12px; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 8px; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--text-2); }
.seg input:checked + span { background: var(--accent); color: #1a1a19; }
.seg input:focus-visible + span { outline: 2px solid var(--text); }

.quick { display: flex; gap: 6px; margin: -4px 0 12px; }
.quick button {
  flex: 1; padding: 7px 0; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); cursor: pointer; font-size: 13px;
}
.quick button.clear { flex: .6; color: var(--muted); }

.ball-calc {
  display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: end;
  background: var(--bg); border: 1px dashed var(--border); border-radius: 10px; padding: 8px; margin: -4px 0 12px;
}
.ball-calc label { font-size: 11px; color: var(--muted); }
.ball-calc input { margin-top: 2px; padding: 7px 8px; font-size: 14px; }

.balance-preview {
  text-align: center; font-size: 22px; font-weight: 800; padding: 8px;
  border-radius: 10px; background: var(--surface-2); margin-bottom: 12px; font-variant-numeric: tabular-nums;
}

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + 90px); transform: translateX(-50%) translateY(10px);
  background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 20px; font-size: 13px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: all .2s; z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== account ===== */
.topbar { align-items: center; }
.acct-chip {
  margin-left: auto; display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 20px;
  padding: 4px 12px; font-size: 12px; cursor: pointer; max-width: 55%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.acct-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.acct-chip .dot.ok { background: #0ca30c; }
.acct-chip .dot.pending, .acct-chip .dot.syncing { background: var(--accent); }
.acct-chip .dot.offline, .acct-chip .dot.auth, .acct-chip .dot.error { background: var(--minus); }
.acct-chip.guest { color: var(--accent); border-color: rgba(242,178,51,.5); }
.banner { display: flex; flex-direction: column; gap: 10px; border-color: rgba(242,178,51,.4); }
.banner p { margin: 2px 0 0; font-size: 13px; color: var(--text-2); }
.banner-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.banner-actions .link { margin-left: auto; color: var(--muted); }
.acct-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.acct-name { font-weight: 700; font-size: 17px; }
.acct-name::before { content: "👤 "; }
.sync-state { font-size: 12px; color: var(--text-2); }
.sync-state.auth, .sync-state.error { color: var(--minus); }
.small-dialog { max-width: 420px; }
@media (min-width: 0px) { .small-dialog { border-radius: 18px; margin: auto; } }
#authForm, #pwForm { padding: 16px; }
.check { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); margin: -2px 0 10px; }
.form-error { color: var(--minus); font-size: 13px; min-height: 1em; margin: 4px 0 0; }
.btn:disabled { opacity: .5; cursor: wait; }

.acct-email { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); margin-top: 6px; flex-wrap: wrap; }
.acct-email b { color: var(--text); font-weight: 600; word-break: break-all; }
.pending-mail { color: var(--accent); font-size: 12px; }
.hint.warn { color: var(--accent); margin-top: 8px; }
.hint.ok { color: #4fc44f; }
#forgotForm, #resetForm, #emailForm { padding: 16px; }
#forgotLink { margin-right: auto; }
