:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --text: #2a2825;
  --muted: #7a756c;
  --line: #e6e1d8;
  --accent: #2f7d6d;
  --accent-soft: #e2f0ec;
  --minami: #ffffff;
  --haru: #d8efe8;
  --scene: #8a8478;
  --done: #2f7d6d;
  --warn-bg: #fff4dc;
  --warn-line: #f0d48a;
  --tabbar-h: 58px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1b19;
    --surface: #282724;
    --text: #ecebe7;
    --muted: #a39e94;
    --line: #3a3834;
    --accent: #6cc4b0;
    --accent-soft: #23403a;
    --minami: #2f2e2a;
    --haru: #24423b;
    --scene: #a39e94;
    --done: #6cc4b0;
    --warn-bg: #3a3221;
    --warn-line: #6b5a2e;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  font-size: 16px;
  line-height: 1.7;
  -webkit-text-size-adjust: 100%;
}

a { color: inherit; text-decoration: none; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.back {
  flex: none;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 16px;
  padding: 4px 4px 4px 0;
  cursor: pointer;
}

.view {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
}

/* 画面下のボタン */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--muted);
}
.tabbar .ico { font-size: 22px; line-height: 1.2; filter: grayscale(1); opacity: .7; }
.tabbar a.active { color: var(--accent); font-weight: 700; }
.tabbar a.active .ico { filter: none; opacity: 1; }

/* カード */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 14px;
}
.card h2, .card h3 { margin: 0 0 8px; font-size: 16px; }
.card p { margin: 0 0 8px; }
.card p:last-child { margin-bottom: 0; }
.muted { color: var(--muted); font-size: 14px; }

/* ホーム */
.big-number { font-size: 40px; font-weight: 800; letter-spacing: .02em; margin: 4px 0; }
.next-card {
  display: block;
  background: var(--accent);
  color: #fff;
  border: 0;
}
.next-card .muted { color: rgba(255,255,255,.85); }
.next-card .next-title { font-size: 18px; font-weight: 700; margin-top: 2px; }

.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin: 10px 0 4px; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }

/* レッスン一覧 */
.chapter { margin: 18px 0 8px; font-size: 14px; color: var(--muted); font-weight: 700; }
.chapter:first-child { margin-top: 4px; }
.lesson-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.lesson-list li + li { border-top: 1px solid var(--line); }
.lesson-list a { display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 52px; }
.lesson-list .day { flex: none; width: 44px; font-size: 13px; color: var(--muted); }
.lesson-list .t { flex: 1; font-size: 15px; line-height: 1.5; }
.lesson-list .check { flex: none; width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; font-size: 13px; color: #fff; }
.lesson-list .check.done { background: var(--done); border-color: var(--done); }
.lesson-list a.is-next { background: var(--accent-soft); }

/* レッスン本文 */
.lesson-head { margin-bottom: 18px; }
.lesson-head .chap { font-size: 13px; color: var(--muted); }
.lesson-head h2 { margin: 2px 0 2px; font-size: 22px; line-height: 1.4; }

.notice { background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: 14px; padding: 12px 14px; margin-bottom: 16px; font-size: 15px; }

.cast ul { margin: 0; padding-left: 1.2em; }

.chat { display: flex; flex-direction: column; gap: 10px; margin: 8px 0 24px; }
.scene { align-self: center; text-align: center; color: var(--scene); font-size: 13px; margin: 10px 8px; max-width: 90%; }
.say { display: flex; gap: 8px; align-items: flex-end; max-width: 88%; }
.say .avatar { flex: none; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-size: 14px; font-weight: 700; color: #fff; }
.say .bubble { padding: 10px 14px; border-radius: 18px; font-size: 15.5px; line-height: 1.65; }
.say.minami { align-self: flex-start; }
.say.minami .avatar { background: #c9875a; }
.say.minami .bubble { background: var(--minami); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.say.haru { align-self: flex-end; flex-direction: row-reverse; }
.say.haru .avatar { background: var(--accent); }
.say.haru .bubble { background: var(--haru); border-bottom-right-radius: 6px; }
.say .name { display: block; font-size: 11px; color: var(--muted); margin-bottom: 2px; }

.points ul, .points ol, .todo ul, .todo ol { margin: 4px 0 8px; padding-left: 1.3em; }
.points li, .todo li { margin: 2px 0; }
.todo { border-color: var(--accent); }
table { width: 100%; border-collapse: collapse; font-size: 14px; margin: 6px 0; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }

.field { margin-top: 12px; }
.field label { display: block; font-size: 14px; font-weight: 700; margin-bottom: 6px; }
.field textarea, .field input {
  width: 100%;
  font: inherit;
  font-size: 16px; /* iPhoneで拡大されないように */
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}
.field textarea { min-height: 84px; resize: vertical; }
.field .row { display: flex; align-items: center; gap: 8px; }
.field .row input { flex: 1; }
.saved { font-size: 13px; color: var(--done); min-height: 1.4em; margin-top: 4px; }
.result { font-size: 15px; margin-top: 10px; }
.result strong { font-size: 22px; }

.btn {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 14px;
  padding: 14px;
  font: inherit;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  margin-top: 10px;
}
.btn.ghost { background: var(--surface); color: var(--accent); border: 1px solid var(--line); }
.btn.done { background: var(--accent-soft); color: var(--done); }

.next-line { color: var(--muted); font-size: 14px; margin-top: 16px; }
.next-line p { margin: 0; }

.empty { text-align: center; padding: 40px 16px; }
.empty .big { font-size: 44px; }

td:first-child, th:first-child { white-space: nowrap; }
.result strong { white-space: nowrap; }

/* ---- おさいふ ---- */
.money-card .big-number.over { color: #c4573a; }
.money-meta { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); }
.add-btn { font-size: 17px; }

.month-switch { display: flex; align-items: center; justify-content: space-between; margin: 18px 0 8px; }
.month-switch button { border: 0; background: none; color: var(--accent); font: inherit; font-size: 26px; line-height: 1; padding: 6px 14px; cursor: pointer; }
.month-switch .m { white-space: nowrap; font-size: 15px; }
.month-switch button:disabled { color: var(--line); cursor: default; }
.month-switch .m { font-weight: 700; }

.date-head { font-size: 13px; color: var(--muted); font-weight: 700; margin: 14px 2px 6px; }
.records { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.records li + li { border-top: 1px solid var(--line); }
/* 横にすべらせると「消す」が出る */
.swipe { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; }
.swipe::-webkit-scrollbar { display: none; }
.swipe .row { flex: 0 0 100%; scroll-snap-align: start; display: flex; align-items: center; gap: 10px; padding: 12px 14px; min-height: 56px; background: var(--surface); }
.swipe .row .shop { flex: 1; min-width: 0; }
.swipe .row .shop div:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.swipe .row .time { font-size: 12px; color: var(--muted); }
.swipe .row .amt { font-weight: 700; white-space: nowrap; }
.swipe .del { flex: 0 0 88px; scroll-snap-align: end; border: 0; background: #c4573a; color: #fff; font: inherit; font-weight: 700; cursor: pointer; }
.tag { display: inline-block; font-size: 11px; color: var(--accent); background: var(--accent-soft); border-radius: 99px; padding: 0 8px; margin-left: 6px; vertical-align: 1px; }

.menu { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.menu li + li { border-top: 1px solid var(--line); }
.menu a { display: flex; align-items: center; gap: 12px; padding: 14px; min-height: 52px; }
.menu a .t { flex: 1; }
.menu a .chev { color: var(--muted); }

/* 入力の画面 */
.form-card .field:first-of-type { margin-top: 4px; }
.yen-row { display: flex; align-items: center; gap: 8px; }
.yen-row input { flex: 1; text-align: right; }
.yen-row span { flex: none; width: 2.6em; color: var(--muted); font-size: 14px; }
.sub-fields { display: grid; grid-template-columns: 1fr; gap: 10px; margin-top: 6px; }
.sub-fields label { font-weight: 400; font-size: 14px; margin-bottom: 4px; }
.calc { background: var(--accent-soft); border-radius: 14px; padding: 12px 14px; margin-top: 14px; font-size: 14px; }
.calc .line { display: flex; justify-content: space-between; gap: 8px; }
.calc .total { font-size: 18px; font-weight: 800; border-top: 1px solid var(--line); margin-top: 6px; padding-top: 6px; }
.hint { font-size: 13px; color: var(--muted); margin-top: 4px; }

/* 金額を入れるシート */
.sheet-backdrop { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.35); display: flex; align-items: flex-end; }
.sheet-backdrop[hidden] { display: none; }
.sheet { width: 100%; max-width: 640px; margin: 0 auto; background: var(--surface); border-radius: 20px 20px 0 0; padding: 18px 16px calc(env(safe-area-inset-bottom) + 16px); }
.sheet-title { font-weight: 700; text-align: center; margin-bottom: 10px; }
.amount-input { display: flex; align-items: baseline; justify-content: center; gap: 6px; border-bottom: 2px solid var(--accent); padding: 4px 0; margin: 0 8px 6px; }
.amount-input input { width: 100%; border: 0; background: none; color: var(--text); font: inherit; font-size: 40px; font-weight: 800; text-align: right; outline: none; }
.amount-input span { font-size: 20px; font-weight: 700; }

/* お知らせ */
.toast { position: fixed; left: 16px; right: 16px; top: calc(env(safe-area-inset-top) + 12px); z-index: 40; max-width: 520px; margin: 0 auto; background: var(--text); color: var(--bg); border-radius: 14px; padding: 12px 16px; font-size: 15px; box-shadow: 0 8px 24px rgba(0,0,0,.18); }
.toast[hidden] { display: none; }

/* 自動記録の設定 */
.copy-row { display: flex; align-items: center; gap: 8px; }
.copy-val { flex: 1; min-width: 0; overflow-wrap: anywhere; font-size: 13px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; user-select: all; -webkit-user-select: all; }
.btn.small { width: auto; flex: none; margin: 0; padding: 8px 12px; font-size: 14px; }
.btn:disabled { opacity: .45; cursor: default; }
