:root {
  --bg: #F4EEE4;
  --card: #FBF8F2;
  --ink: #3A3328;
  --ink2: #5C5244;
  --mute: #8C8273;
  --faint: #A69B8A;
  --line: #E6DDCF;
  --line2: #D8CCB9;
  --accent: #A0856A;
  --in: #6B8F71;
  --out: #B5694E;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Thai", "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 15px/1.5 var(--sans); -webkit-tap-highlight-color: transparent; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.app { max-width: 520px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.top { display: flex; justify-content: space-between; align-items: center; padding: calc(14px + env(safe-area-inset-top)) 20px 4px; }
.brand { font-family: var(--serif); font-size: 17px; color: var(--ink2); }
.sync { border: 0; background: none; font-size: 12px; color: var(--faint); padding: 4px 0; display: inline-flex; align-items: center; gap: 6px; }
.sync::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--line2); }
.sync.cloud::before { background: var(--in); }
.sync.err::before { background: var(--out); }
main { flex: 1; padding: 0 20px 24px; }
.view { display: none; }
.view.on { display: block; }

.lb { font-size: 12px; color: var(--mute); letter-spacing: .03em; }
.sub { font-size: 12px; color: var(--faint); }
.num { font-family: var(--serif); font-variant-numeric: lining-nums tabular-nums; }
.big { font-family: var(--serif); font-size: 42px; line-height: 1.1; font-weight: 400; margin: 2px 0 4px; letter-spacing: -.01em; }
.in { color: var(--in); }
.out { color: var(--out); }
h3 { font-size: 12px; font-weight: 400; color: var(--mute); letter-spacing: .03em; margin: 26px 0 4px; }

.nav { display: flex; align-items: center; justify-content: space-between; margin: 14px 0 10px; }
.nav .title { font-family: var(--serif); font-size: 18px; }
.arrow { border: 0; background: none; width: 36px; height: 36px; border-radius: 50%; color: var(--mute); font-size: 18px; }
.arrow:active { background: var(--line); }
.arrow[disabled] { opacity: .3; }

.summary { padding: 8px 0 6px; }
.flow { display: flex; gap: 16px; font-size: 13px; }
.meter { height: 3px; background: var(--line); border-radius: 2px; overflow: hidden; margin: 14px 0 6px; }
.meter > div { height: 100%; background: var(--accent); }

.row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 12px 0; border-bottom: .5px solid var(--line); }
.row.tap { cursor: pointer; }
.row.tap:active { background: rgba(160,133,106,.06); }
.row .l { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .r { text-align: right; white-space: nowrap; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.row.up { color: var(--mute); border-bottom-style: dashed; }
.day { margin-top: 18px; display: flex; justify-content: space-between; }
.empty { padding: 48px 8px; text-align: center; color: var(--mute); font-family: var(--serif); font-size: 17px; line-height: 1.6; }
.empty code { font-family: var(--sans); font-size: 14px; background: var(--card); border: .5px solid var(--line2); padding: 2px 8px; border-radius: 6px; }

.dock { position: sticky; bottom: 0; background: var(--bg); padding: 8px 16px calc(6px + env(safe-area-inset-bottom)); border-top: .5px solid var(--line); z-index: 5; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 8px; }
.chips::-webkit-scrollbar { display: none; }
.chips:empty { display: none; }
.chip { flex: none; border: .5px solid var(--line2); background: transparent; border-radius: 999px; padding: 4px 12px; font-size: 13px; color: var(--ink2); }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip:active { background: var(--line); }
.rate-hint { font-size: 12px; color: var(--mute); padding: 0 4px 8px; }
.rate-hint:empty { display: none; }
.rate-hint button { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: underline; text-underline-offset: 2px; font-size: 12px; }
.entry { display: flex; align-items: center; gap: 4px; background: var(--card); border: .5px solid var(--line2); border-radius: 999px; padding: 5px 5px 5px 16px; }
.entry:focus-within { border-color: var(--accent); }
.entry input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; font-size: 16px; padding: 6px 0; }
.entry input::placeholder { color: var(--faint); }
.cur { border: 0; background: none; color: var(--mute); font-size: 14px; padding: 6px 10px; border-radius: 999px; }
.cur:active { background: var(--line); }
.send { flex: none; width: 38px; height: 38px; border: 0; border-radius: 50%; background: var(--ink); color: var(--bg); display: flex; align-items: center; justify-content: center; }
.send:active { transform: scale(.95); }
.tabs { display: flex; justify-content: space-around; padding-top: 6px; }
.tabs button { border: 0; background: none; color: var(--faint); font-size: 13px; padding: 8px 14px; }
.tabs button.on { color: var(--ink); }

.seg { display: inline-flex; gap: 2px; font-size: 13px; }
.seg button { border: 0; background: none; color: var(--faint); padding: 4px 8px; border-radius: 999px; }
.seg button.on { color: var(--ink); background: var(--card); box-shadow: inset 0 0 0 .5px var(--line2); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 18px 24px; padding: 10px 0 4px; }
.stats .v { font-family: var(--serif); font-size: 26px; line-height: 1.2; }
.cat { padding: 8px 0; }
.cat .t { display: flex; justify-content: space-between; margin-bottom: 6px; font-size: 14px; }
.track { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.track > div { height: 100%; border-radius: 2px; }
.days { display: flex; align-items: flex-end; gap: 3px; height: 84px; margin-top: 10px; }
.days > div { flex: 1; background: var(--line2); border-radius: 2px 2px 0 0; min-height: 2px; }
.days > div.max { background: var(--accent); }
.days-l { display: flex; justify-content: space-between; font-size: 11px; color: var(--faint); margin-top: 4px; }
.note { font-family: var(--serif); font-size: 16px; line-height: 1.55; color: var(--ink2); margin: 10px 0; }

.set-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 11px 0; border-bottom: .5px solid var(--line); min-height: 46px; }
.set-row.tap { cursor: pointer; }
.set-row .kw { font-size: 12px; color: var(--faint); max-width: 55%; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.swatch { width: 22px; height: 22px; border-radius: 50%; border: 0; flex: none; padding: 0; box-shadow: inset 0 0 0 .5px rgba(0,0,0,.08); }
.linkbtn { border: 0; background: none; padding: 10px 0; color: var(--accent); font-size: 14px; }
.rate-in { width: 96px; text-align: right; border: .5px solid var(--line2); background: var(--card); border-radius: 8px; padding: 6px 8px; font-family: var(--serif); font-size: 15px; }
.x { border: 0; background: none; color: var(--faint); font-size: 18px; width: 30px; height: 30px; border-radius: 50%; }
.plain-select { border: .5px solid var(--line2); background: var(--card); border-radius: 8px; padding: 6px 8px; }

.sheet { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet-bg { position: absolute; inset: 0; background: rgba(58,51,40,.28); animation: fade .2s ease; }
.panel { position: relative; width: 100%; max-width: 520px; max-height: 88vh; max-height: 88dvh; overflow-y: auto; background: var(--bg); border-radius: 20px 20px 0 0; padding: 22px 20px calc(20px + env(safe-area-inset-bottom)); animation: up .22s ease; }
.panel h2 { font-family: var(--serif); font-weight: 400; font-size: 22px; margin: 0 0 14px; }
.panel p { color: var(--ink2); margin: 0 0 14px; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 12px; color: var(--mute); margin-bottom: 5px; }
.inp { width: 100%; border: .5px solid var(--line2); background: var(--card); border-radius: 10px; padding: 10px 12px; font-size: 16px; outline: none; }
.inp:focus { border-color: var(--accent); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.actions { display: flex; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.btn { border: .5px solid var(--line2); background: var(--card); border-radius: 999px; padding: 10px 18px; font-size: 15px; }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.btn.danger { color: var(--out); }
.btn.grow { flex: 1; }
.err { color: var(--out); font-size: 13px; margin: 6px 0 0; min-height: 1em; }
.cat-pick { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.cat-pick .chip { padding: 7px 14px; font-size: 14px; }
.sw-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 10px; margin: 6px 0 14px; }
.sw-grid button { aspect-ratio: 1; border-radius: 50%; border: 0; padding: 0; }
.sw-grid button.on { box-shadow: 0 0 0 2px var(--bg), 0 0 0 3.5px var(--ink); }
.custom-color { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--mute); }
.custom-color input { width: 40px; height: 30px; border: 0; padding: 0; background: none; }
.preview-chip { display: inline-flex; align-items: center; gap: 6px; border: .5px solid var(--line2); border-radius: 999px; padding: 4px 12px; font-size: 13px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(132px + env(safe-area-inset-bottom)); z-index: 30; background: var(--ink); color: var(--bg); border-radius: 999px; padding: 10px 18px; font-size: 14px; display: flex; gap: 14px; align-items: center; max-width: calc(100% - 32px); animation: fade .2s ease; }
.toast button { border: 0; background: none; color: #E8D9C2; text-decoration: underline; text-underline-offset: 2px; padding: 0; font-size: 14px; }

@keyframes up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

@media (min-width: 900px) {
  .app { max-width: 1080px; }
  main { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 0 64px; padding: 0 32px 24px; align-items: start; }
  .top { padding: 22px 32px 4px; }
  .app[data-tab="home"] #insights, .app[data-tab="insights"] #home { display: block; }
  .app[data-tab="settings"] main { grid-template-columns: minmax(0, 560px); justify-content: center; }
  .tab-insights { display: none; }
  .dock { padding: 10px 32px 12px; }
  .entry-wrap, .tabs { max-width: 560px; margin: 0 auto; }
  .toast { bottom: 140px; }
  .sheet { align-items: center; }
  .panel { border-radius: 20px; max-width: 460px; }
}
