:root {
  --paper: #fbf7ee;
  --rule: #dfe7f1;
  --margin: #f0b7b0;
  --ink: #2f3b52;
  --ink-soft: #6b7487;
  --blue: #3a6ea5;
  --green: #4f9a6b;
  --green-bg: #e3f2e7;
  --red: #c8483c;
  --red-bg: #fbe7e4;
  --yellow: #fff2b8;
  --card: rgba(255, 255, 255, .78);
  --line: #e3dccb;
  --hand: "Klee One", "Hiragino Maru Gothic ProN", "Hiragino Sans", sans-serif;
  --sans: -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  --tabbar-h: 68px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.6;
  background-color: var(--paper);
  background-image:
    linear-gradient(90deg, transparent 27px, var(--margin) 27px, var(--margin) 28.5px, transparent 28.5px),
    repeating-linear-gradient(180deg, transparent 0 31px, var(--rule) 31px 32px);
  min-height: 100vh;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 8px 40px;
  background: linear-gradient(var(--paper) 80%, rgba(251, 247, 238, 0));
}
.topbar h1 { margin: 0; font-family: var(--hand); font-weight: 600; font-size: 22px; }
.sync-badge {
  border: 1px solid var(--line); background: #fff; border-radius: 999px;
  font-size: 12px; padding: 3px 10px; color: var(--ink-soft);
}
.sync-badge.ok { color: var(--green); border-color: #bfdcc8; }
.sync-badge.bad { color: var(--red); border-color: #efc2bc; }

main { padding: 4px 16px 0 40px; max-width: 560px; margin: 0 auto; }
h2 { font-family: var(--hand); font-weight: 600; font-size: 20px; margin: 22px 0 8px; }
h2 small { font-family: var(--sans); font-weight: 400; font-size: 13px; color: var(--ink-soft); margin-left: 6px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 16px; margin: 10px 0;
  box-shadow: 0 1px 0 rgba(0, 0, 0, .03);
}
.muted { color: var(--ink-soft); font-size: 14px; }
.small { font-size: 13px; }
.red { color: var(--red); }
.green { color: var(--green); }

/* ホーム */
.today-money .label { font-family: var(--hand); font-size: 17px; }
.today-money .big { font-family: var(--hand); font-weight: 600; font-size: 46px; line-height: 1.2; margin: 2px 0 4px; }
.today-money .big.minus { color: var(--red); }
.today-money .big .yen { font-size: 26px; margin-right: 2px; }
.marker { background: linear-gradient(transparent 60%, var(--yellow) 60%); }

.streak { display: flex; align-items: baseline; gap: 8px; }
.streak .num { font-family: var(--hand); font-weight: 600; font-size: 34px; }
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; margin-top: 10px; }
.week .wd { font-size: 12px; color: var(--ink-soft); }
.dot {
  width: 36px; height: 36px; margin: 2px auto 0; border-radius: 50%;
  border: 2px dashed #c9cfda; display: grid; place-items: center;
  font-size: 11px; color: var(--ink-soft); background: #fff;
}
.dot.zero { border: 2px solid var(--green); background: var(--green-bg); color: var(--green); font-size: 15px; }
.dot.spent { border: 2px solid var(--blue); background: #e6eef7; color: var(--blue); }
.dot.today { outline: 3px solid var(--yellow); outline-offset: 1px; }
.week .amt { font-size: 10px; color: var(--ink-soft); min-height: 14px; }

.btn {
  display: block; width: 100%; border: 1.5px solid var(--ink); background: #fff;
  border-radius: 12px; padding: 12px 14px; font-weight: 600; margin: 10px 0;
}
.btn.primary { background: var(--ink); color: #fff; }
.btn.green { border-color: var(--green); color: var(--green); background: #fff; }
.btn.danger { border-color: var(--red); color: var(--red); background: #fff; font-weight: 400; }
.btn.big { padding: 15px; font-size: 18px; }
.btn.inline { display: inline-block; width: auto; padding: 6px 12px; margin: 0; font-size: 14px; white-space: nowrap; flex-shrink: 0; }
.btn:disabled { opacity: .45; }
.link { border: none; background: none; color: var(--blue); padding: 6px; }
.done-note { text-align: center; font-family: var(--hand); color: var(--green); font-size: 18px; margin: 10px 0; }

/* 1か月 */
.month-nav { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.month-nav h2 { margin: 0; }
.month-nav button { border: 1px solid var(--line); background: #fff; border-radius: 10px; width: 44px; height: 40px; font-size: 18px; }
.sum3 { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; gap: 6px; }
.sum3 .k { font-size: 12px; color: var(--ink-soft); }
.sum3 .v { font-weight: 700; font-size: 16px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal .h { text-align: center; font-size: 12px; color: var(--ink-soft); }
.cal .h:first-child { color: var(--red); }
.cal .h:last-child { color: var(--blue); }
.cal .d {
  border: 1px solid var(--line); background: #fff; border-radius: 8px;
  min-height: 52px; padding: 2px 1px; text-align: center; font-size: 12px; line-height: 1.25;
}
.cal .d.empty { border: none; background: none; }
.cal .d .n { font-size: 12px; color: var(--ink-soft); }
.cal .d .a { font-size: 11px; font-weight: 600; word-break: break-all; }
.cal .d .o { color: var(--green); font-size: 17px; font-weight: 700; line-height: 1.1; }
.cal .d.over .a { color: var(--red); }
.cal .d.today { border: 2px solid var(--ink); }
.cal .d.sel { background: var(--yellow); }
.cal .d.future { opacity: .55; }

/* 帳簿 */
.day-group { margin: 12px 0; }
.day-head { display: flex; justify-content: space-between; font-family: var(--hand); font-weight: 600; border-bottom: 1.5px solid var(--ink); padding-bottom: 2px; }
.day-head .t { font-family: var(--sans); font-size: 14px; font-weight: 600; }
.rec {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: none; border: none; border-bottom: 1px dotted #c9cfda; padding: 10px 2px; min-height: 48px;
}
.rec .cat { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: #eef1f6; white-space: nowrap; }
.rec .cat.inc { background: var(--green-bg); color: var(--green); }
.rec .memo { flex: 1; color: var(--ink-soft); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rec .yen { font-weight: 700; white-space: nowrap; }
.rec .yen.inc { color: var(--green); }
.empty-note { text-align: center; color: var(--ink-soft); padding: 24px 0; font-family: var(--hand); }

/* 予定・固定費 */
.field { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px dotted #c9cfda; }
.field:last-child { border-bottom: none; }
.field .name { flex: 1; }
.yen-input { display: flex; align-items: center; gap: 4px; }
.yen-input input, .text-input {
  width: 130px; text-align: right; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; background: #fff; font-size: 17px;
}
.text-input { text-align: left; width: 100%; }
.x { border: none; background: none; color: var(--ink-soft); font-size: 20px; width: 36px; height: 36px; }
.calc { font-size: 15px; }
.calc .row { display: flex; justify-content: space-between; padding: 3px 0; }
.calc .row.total { border-top: 1.5px solid var(--ink); margin-top: 4px; padding-top: 6px; font-weight: 700; font-size: 18px; }
.suggest { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.suggest button { border: 1px dashed #b9c1cf; background: #fff; border-radius: 999px; padding: 4px 10px; font-size: 13px; }
details { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px; margin: 10px 0; }
details summary { font-weight: 600; cursor: pointer; }
details p, details ol { font-size: 15px; }

/* 記入シート */
.sheet-back { position: fixed; inset: 0; background: rgba(30, 36, 50, .35); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  max-height: 92vh; overflow-y: auto;
  background: var(--paper); border-radius: 18px 18px 0 0;
  padding: 14px 16px calc(env(safe-area-inset-bottom) + 16px);
  box-shadow: 0 -8px 30px rgba(0, 0, 0, .15);
  max-width: 560px; margin: 0 auto;
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.seg { display: inline-flex; border: 1.5px solid var(--ink); border-radius: 10px; overflow: hidden; }
.seg button { border: none; background: #fff; padding: 6px 18px; }
.seg button.on { background: var(--ink); color: #fff; }
.amount { display: flex; align-items: center; gap: 6px; border-bottom: 2px solid var(--ink); margin: 14px 0 12px; }
.amount span { font-family: var(--hand); font-size: 30px; }
.amount input { border: none; background: none; font-size: 38px; font-weight: 700; width: 100%; outline: none; padding: 4px 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button {
  border: 1.5px solid #c9cfda; background: #fff; border-radius: 999px;
  padding: 8px 14px; font-size: 15px; min-height: 42px;
}
.chips button.on { border-color: var(--ink); background: var(--ink); color: #fff; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.row2 label { font-size: 13px; color: var(--ink-soft); display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.row2 input { border: 1px solid var(--line); border-radius: 8px; padding: 9px 8px; background: #fff; font-size: 16px; width: 100%; min-width: 0; color: var(--ink); }
.warn { background: var(--red-bg); color: var(--red); border-radius: 8px; padding: 8px 10px; font-size: 14px; margin: 10px 0 0; }
.hint { color: var(--ink-soft); font-size: 13px; margin: 8px 0 0; }

/* 読み取り */
.scan-btn { margin: 10px 0 0; border-style: dashed; font-weight: 400; font-size: 15px; }
.scan-row { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin: 10px 0; }
.scan-row.off { opacity: .6; }
.scan-top, .scan-bottom { display: flex; align-items: center; gap: 8px; }
.scan-bottom { margin-top: 8px; }
.scan-top input[type=date] { border: 1px solid var(--line); border-radius: 8px; padding: 8px 6px; background: #fff; font-size: 15px; min-width: 0; flex: 1; color: var(--ink); }
.scan-top .yen-input input { width: 100px; }
.scan-bottom .text-input { flex: 1; width: auto; min-width: 0; }
.scan-bottom select { border: 1px solid var(--line); border-radius: 8px; padding: 9px 6px; background: #fff; font-size: 15px; }
.chk input { width: 26px; height: 26px; accent-color: var(--ink); }
.bar { height: 10px; border-radius: 999px; background: #e8e2d2; overflow: hidden; margin: 8px 0; }
.bar div { height: 100%; background: var(--green); transition: width .2s; }
.ocr-text { white-space: pre-wrap; font-size: 13px; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px; max-height: 200px; overflow: auto; }

/* 下のタブ */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: end;
  background: #fffdf7; border-top: 1px solid var(--line);
  padding: 6px 4px calc(env(safe-area-inset-bottom) + 6px);
}
.tab { border: none; background: none; font-size: 11px; color: var(--ink-soft); display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 4px 0; min-height: 50px; justify-content: flex-end; }
.tab .ico { font-size: 20px; line-height: 1.1; }
.tab.on { color: var(--ink); font-weight: 700; }
.tab.add { align-self: center; }
.tab.add span {
  width: 58px; height: 58px; border-radius: 50%; background: var(--red); color: #fff;
  font-size: 34px; line-height: 58px; margin-top: -26px; box-shadow: 0 4px 12px rgba(200, 72, 60, .4);
}

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; z-index: 30; font-size: 15px;
  max-width: calc(100% - 32px); text-align: center;
}

@media (max-width: 360px) {
  main { padding-left: 34px; }
  .today-money .big { font-size: 40px; }
  .yen-input input { width: 110px; }
}
