/* 飲控手帳：Risograph（孔版印刷）手帳風
   米色紙張 + 顆粒、番茄紅 / 墨藍雙色油墨、印刷錯位陰影 */

@font-face {
  font-family: "DM Serif Display";
  src: url("dm-serif-display.woff2") format("woff2");
  font-display: swap;
}

:root {
  --paper: #F3EBDD; --sheet: #FBF6EC; --ink: #2A2420; --muted: #85786A; --rule: #D9CDB8;
  --red: #E5533D; --blue: #2B5D86; --yellow: #F4C04E;
  --display: "DM Serif Display", ui-serif, Georgia, serif;
  --body: ui-serif, "New York", Georgia, "PingFang TC", "Noto Serif TC", "Songti TC", serif;
  --grain-opacity: .35;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --paper: #1E1B18; --sheet: #28241F; --ink: #EFE6D6; --muted: #A39684; --rule: #3D372F;
          --red: #F06A52; --blue: #6F9FCB; --yellow: #E8B444; --grain-opacity: .12; }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; background: var(--paper); color: var(--ink);
  font: 16px/1.55 var(--body); }

/* 紙張顆粒 */
body::before { content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 100;
  opacity: var(--grain-opacity); mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .3 0 0 0 0 .25 0 0 0 0 .2 0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"); }
@media (prefers-color-scheme: dark) { body::before { mix-blend-mode: screen; } }

.hidden { display: none !important; }
main { max-width: 560px; margin: 0 auto; padding: 14px 16px calc(96px + env(safe-area-inset-bottom)); }

/* ---------- 文字 ---------- */
.kicker { display: block; font-family: var(--display); font-style: italic; font-size: .85rem;
  letter-spacing: .06em; color: var(--muted); margin: 0; }
.riso { font-weight: 800; letter-spacing: .04em; text-shadow: 2px 2px 0 color-mix(in srgb, var(--red) 55%, transparent); }
h2 { font-size: 1.9rem; margin: 0 0 14px; line-height: 1.15; }
h3 { font-size: 1.05rem; margin: 0 0 12px; display: inline-block;
  background: linear-gradient(transparent 58%, color-mix(in srgb, var(--yellow) 70%, transparent) 58%); padding: 0 2px; }
.meta, .empty { color: var(--muted); font-size: .9rem; margin: 6px 0 0; }
.empty { text-align: center; padding: 36px 0; font-style: italic; }
.err { color: var(--red); min-height: 1.2em; margin: 8px 0 0; }

/* ---------- 卡片 ---------- */
.card { background: var(--sheet); border: 2px solid var(--ink); border-radius: 6px;
  padding: 16px; margin-bottom: 16px; box-shadow: 4px 4px 0 var(--blue); }
.card.note { border-style: dashed; box-shadow: none; background: transparent; font-size: .95rem; }

/* ---------- 表單 ---------- */
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 12px; }
input, select { display: block; width: 100%; margin-top: 4px; padding: 10px 12px; font: 16px var(--body);
  border: 2px solid var(--ink); border-radius: 4px; background: var(--paper); color: var(--ink); appearance: none; }
input:focus, select:focus { outline: none; box-shadow: 3px 3px 0 var(--red); }
select { background-image: linear-gradient(45deg, transparent 50%, var(--ink) 50%), linear-gradient(135deg, var(--ink) 50%, transparent 50%);
  background-position: calc(100% - 18px) 55%, calc(100% - 12px) 55%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 32px; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: .9rem; margin: 0; }
label.check input { width: 20px; height: 20px; margin: 0; padding: 0; flex: none; appearance: auto; accent-color: var(--red); }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }

/* ---------- 按鈕 ---------- */
button { font: 600 1rem var(--body); border: 2px solid var(--ink); border-radius: 4px; padding: 11px 14px;
  cursor: pointer; background: var(--sheet); color: var(--ink); transition: transform .08s, box-shadow .08s; }
button.primary { background: var(--red); color: #fff; width: 100%; letter-spacing: .1em; box-shadow: 3px 3px 0 var(--ink); }
button.primary:active { transform: translate(3px, 3px); box-shadow: none; }
button.danger { background: transparent; color: var(--red); border-color: transparent; }
button.ghost { background: transparent; color: var(--muted); width: 100%; border-style: dashed; border-color: var(--rule); margin-bottom: 12px; }
button.icon { background: transparent; border: 0; font-size: 1.5rem; padding: 6px 10px; color: var(--ink); }
button:disabled { opacity: .3; }

/* ---------- 登入 ---------- */
.screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 340px; text-align: center; padding: 28px 22px; }
.login-card h1 { font-size: 2.2rem; margin: 2px 0 22px; }
.login-card input { margin-bottom: 14px; text-align: center; }

/* ---------- 今天 ---------- */
.masthead { display: flex; align-items: center; justify-content: space-between;
  border-bottom: 3px double var(--ink); padding-bottom: 8px; margin-bottom: 18px; }
.masthead-date { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; justify-content: center; text-align: center; }
.masthead-date .kicker { width: 100%; }
.big-date { font-family: var(--display); font-size: 3.4rem; line-height: .9; color: var(--red); }
.day-title { font-size: 1.4rem; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 4px; }
.stat { display: flex; flex-direction: column; padding: 14px; }
.stat-protein { box-shadow: 4px 4px 0 var(--red); }
.stat-num { font-family: var(--display); font-size: 2.6rem; line-height: 1.05; margin-top: 4px; }
.stat-kcal .stat-num { color: var(--red); }
.stat-protein .stat-num { color: var(--blue); }
.stat-num.over { text-decoration: underline wavy var(--red) 2px; text-underline-offset: 6px; }
.stat-sub { font-size: .8rem; color: var(--muted); }
.stat-foot { font-size: .8rem; color: var(--muted); margin-top: 6px; font-variant-numeric: tabular-nums; }
.bar { height: 12px; border: 2px solid var(--ink); border-radius: 2px; margin-top: 10px; background: var(--paper); overflow: hidden; }
.bar > div { height: 100%; width: 0; transition: width .4s;
  background: repeating-linear-gradient(-45deg, var(--red) 0 5px, color-mix(in srgb, var(--red) 55%, transparent) 5px 8px); }
.stat-protein .bar > div { background: repeating-linear-gradient(-45deg, var(--blue) 0 5px, color-mix(in srgb, var(--blue) 55%, transparent) 5px 8px); }
.bar > div.over { background: var(--red); }

.meal-group { margin-top: 22px; }
.meal-head { display: flex; justify-content: space-between; align-items: baseline;
  border-bottom: 2px solid var(--ink); padding-bottom: 4px; margin-bottom: 2px; }
.meal-head b { font-size: 1.15rem; letter-spacing: .08em; }
.meal-head span { font-family: var(--display); font-size: .95rem; color: var(--muted); }

/* ---------- 清單（橫線筆記本） ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list.ruled li, .meal-group li { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 2px; border-bottom: 1px dashed var(--rule); }
.list li.tap, .meal-group li.tap { cursor: pointer; }
.list li.tap:active, .meal-group li.tap:active { background: color-mix(in srgb, var(--yellow) 25%, transparent); }
.name { font-weight: 600; word-break: break-word; }
.nums { color: var(--muted); font-size: .9rem; white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }
.nums b { font-family: var(--display); font-weight: 400; color: var(--ink); font-size: 1.1rem; }
.add-stamp { flex: none; width: 34px; height: 34px; padding: 0; border-radius: 50%; font-size: 1.2rem; line-height: 1;
  color: var(--red); border-color: var(--red); background: transparent; }
.del-x { flex: none; padding: 4px 6px; border: 0; background: transparent; color: var(--muted); font-size: .9rem; }

/* ---------- 新增 ---------- */
.page-head { border-bottom: 3px double var(--ink); margin-bottom: 18px; }
.page-head h2 { margin-bottom: 8px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 4px 10px 2px; margin-bottom: 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; font-size: .95rem; padding: 7px 16px; border-radius: 999px; background: transparent; }
.chip.active { background: var(--ink); color: var(--paper); box-shadow: 2px 2px 0 var(--red); }

.seg { display: flex; border: 2px solid var(--ink); border-radius: 4px; margin-bottom: 16px; overflow: hidden; }
.seg button { flex: 1; border: 0; border-radius: 0; background: transparent; padding: 9px 4px; font-size: .95rem; }
.seg button + button { border-left: 2px solid var(--ink); }
.seg button.active { background: var(--blue); color: #fff; }

.search { margin: 0 0 4px; }
.photo-pick { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 34px 16px; margin-bottom: 16px;
  border: 2px dashed var(--ink); border-radius: 6px; color: var(--ink); font-size: 1.1rem; font-weight: 600; cursor: pointer;
  background: repeating-linear-gradient(45deg, transparent 0 10px, color-mix(in srgb, var(--blue) 7%, transparent) 10px 20px); }
.photo-pick small { color: var(--muted); font-size: .8rem; font-weight: normal; }
.photo-icon { font-size: 2.4rem; color: var(--red); line-height: 1; }
#photo-busy { display: flex; align-items: center; gap: 12px; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--rule); border-top-color: var(--red);
  border-radius: 50%; animation: spin 1s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.photo-item { background: var(--sheet); border: 2px solid var(--ink); border-radius: 6px; padding: 12px; margin-bottom: 12px; }
.photo-item .portion { color: var(--muted); font-size: .85rem; margin: 2px 0 10px 28px; }
.photo-item label { margin-bottom: 8px; }
.photo-item .save { margin-top: 4px; color: var(--muted); }

/* ---------- 圖表 ---------- */
.chart svg { display: block; width: 100%; height: 160px; }
.chart .grid { stroke: var(--rule); stroke-width: 1; stroke-dasharray: 2 3; }
.chart .axis { fill: var(--muted); font-size: 10px; font-family: var(--display); }
.chart .target { stroke: var(--ink); stroke-dasharray: 5 4; stroke-width: 1.2; }
.chart .bar-kcal { fill: var(--red); }
.chart .bar-protein { fill: var(--blue); }
.chart .bar-over { fill: url(#hatch); stroke: var(--red); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--blue); stroke-width: 2.2; }
.chart .dot { fill: var(--sheet); stroke: var(--blue); stroke-width: 2; }

/* ---------- 設定 ---------- */
.targets { display: flex; gap: 12px; }
.targets > div { flex: 1; text-align: center; border: 2px solid var(--ink); border-radius: 4px; padding: 10px; background: var(--paper); }
.targets b { display: block; font-family: var(--display); font-weight: 400; font-size: 2.2rem; line-height: 1.1; color: var(--red); }
.targets > div + div b { color: var(--blue); }
.targets span { color: var(--muted); font-size: .85rem; }
.meal-rows { list-style: none; margin: 12px 0; padding: 0; }
.meal-rows li { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.meal-rows input { margin: 0; }
.meal-rows input[type=time] { width: 138px; flex: none; }

/* ---------- 底部分頁 ---------- */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; display: flex; z-index: 50; background: var(--paper);
  border-top: 2px solid var(--ink); padding-bottom: env(safe-area-inset-bottom); }
.tabbar button { flex: 1; border: 0; border-radius: 0; background: transparent; padding: 9px 0 7px;
  display: flex; flex-direction: column; align-items: center; gap: 0; color: var(--muted); }
.tabbar b { font-size: .95rem; letter-spacing: .1em; }
.tabbar i { font-family: var(--display); font-size: .7rem; }
.tabbar button.active { color: var(--ink); }
.tabbar button.active b { background: linear-gradient(transparent 55%, var(--yellow) 55%); padding: 0 3px; }

/* ---------- 對話框 / 提示 ---------- */
dialog { border: 2px solid var(--ink); border-radius: 6px; background: var(--sheet); color: var(--ink);
  width: min(92vw, 420px); padding: 20px; box-shadow: 6px 6px 0 var(--red); }
dialog::backdrop { background: rgba(30, 24, 20, .45); }
dialog .row button { width: auto; }
.toast { position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translateX(-50%) rotate(-1.5deg);
  background: var(--ink); color: var(--paper); padding: 9px 18px; border-radius: 3px; font-size: .95rem; z-index: 60;
  box-shadow: 3px 3px 0 var(--red); }
