:root {
  --bg: #f6f5f1;
  --card: #ffffff;
  --ink: #1f2328;
  --muted: #6a6f76;
  --line: #e3e1da;
  --brand: #1e6b52;
  --brand-ink: #ffffff;
  --brand-soft: #e4f1ec;
  --warn: #9a5b00;
  --warn-soft: #fff3dd;
  --bad: #c0392b;
  --body: #4b3f8f;
  --body-soft: #ecebf8;
  --bar: #9cc8b6;
  --over: #e8760c;
  --goal: #6a6f76;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --card: #1f2226;
    --ink: #eceef0;
    --muted: #a2a8af;
    --line: #33373d;
    --brand: #5fbf98;
    --brand-ink: #0d1f18;
    --brand-soft: #1d3029;
    --warn: #f0b45c;
    --warn-soft: #3a2e17;
    --bad: #ff7b6b;
    --body: #b3a8ff;
    --body-soft: #2a2740;
    --bar: #3f7f66;
    --over: #ff9a3c;
    --goal: #c3c8ce;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
/* 휴대폰: 두 번 눌러 확대되는 지연 없애기 */
button, a, label, .tile, summary { touch-action: manipulation; }
/* 변화 사진을 길게 눌러 저장하는 메뉴를 막아요(화면 캡처까지는 못 막아요) */
.tile img, .pv-img img, .thumb { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; -webkit-user-drag: none; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
main {
  max-width: 520px; margin: 0 auto; outline: none;
  padding: 8px max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left));
}
h1 { font-size: 1.35rem; margin: 12px 0 8px; }
h2 { font-size: 1.1rem; margin: 0 0 8px; }
h3 { font-size: 1rem; margin: 0 0 6px; }
a { color: var(--brand); }
button { font: inherit; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  max-width: 520px; margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 4px max(16px, env(safe-area-inset-left));
}
.brand { font-weight: 800; letter-spacing: -0.02em; }
.mode { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.mode a { text-decoration: none; color: var(--muted); padding: 6px 12px; border-radius: 999px; font-size: 0.88rem; white-space: nowrap; }
.mode a.on { background: var(--brand); color: var(--brand-ink); font-weight: 700; }

.demo-banner {
  max-width: 520px; margin: 4px auto 0; padding: 8px 16px; font-size: 0.85rem; color: var(--warn);
  background: var(--warn-soft); border-radius: 10px; width: calc(100% - 32px);
}

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  flex: 1; max-width: 130px; text-align: center; text-decoration: none; color: var(--muted);
  padding: 10px 4px 12px; font-size: 0.85rem; min-height: 56px;
}
.tabs a .ic { display: block; font-size: 1.2rem; line-height: 1.3; }
.tabs a.on { color: var(--brand); font-weight: 700; }
.tabs a.body.on { color: var(--body); }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin: 12px 0;
}
.muted { color: var(--muted); font-size: 0.9rem; }
.note { color: var(--muted); font-size: 0.85rem; margin: 8px 0; }
.error { color: var(--bad); font-size: 0.9rem; min-height: 1.2em; margin: 4px 0; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0; }
.chip {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 999px; padding: 6px 12px; font-size: 0.88rem; white-space: nowrap; cursor: pointer;
}
.chip.on { background: var(--ink); color: var(--card); border-color: var(--ink); }

.btn, .actions button, dialog button, .card button:not(.link) {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 10px; padding: 9px 12px; min-height: 44px; cursor: pointer;
}
.primary { background: var(--brand) !important; color: var(--brand-ink) !important; border-color: var(--brand) !important; font-weight: 700; }
.danger { color: var(--bad) !important; }
.link { background: none; border: none; color: var(--brand); padding: 6px; cursor: pointer; min-height: 36px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.actions button { flex: 1 1 auto; }

.slot h3 { display: flex; justify-content: space-between; }
.entry { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px dashed var(--line); }
.entry:first-of-type { border-top: none; }
.thumb { width: 56px; height: 56px; border-radius: 10px; object-fit: cover; flex: none; background: var(--line); }
.thumb.ph { display: grid; place-items: center; font-size: 0.75rem; color: var(--muted); }
.unknown { color: var(--warn); }
.skipped { margin-top: 6px; color: var(--muted); }
.tag { display: inline-block; font-size: 0.75rem; padding: 1px 8px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); vertical-align: middle; }

.week .big { font-size: 1.6rem; font-weight: 800; letter-spacing: -0.02em; }
.week.dim .big, .week.dim .rate { opacity: 0.45; }
.progress { height: 10px; background: var(--line); border-radius: 999px; overflow: hidden; margin: 6px 0 10px; }
.progress > span { display: block; height: 100%; background: var(--brand); }
.warnbox { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 8px 10px; font-size: 0.9rem; margin: 8px 0; }
.bars { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; height: 160px; margin-top: 12px; }
.bars .b { display: flex; flex-direction: column; align-items: center; height: 100%; font-size: 0.72rem; color: var(--muted); min-width: 0; }
.bars .val { white-space: nowrap; }
.bars .b.is-over .val { color: var(--over); font-weight: 700; }
.bars .area { position: relative; flex: 1; width: 100%; display: flex; justify-content: center; }
.bars .stack { width: 100%; max-width: 30px; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; }
.bars .seg.base { background: var(--bar); border-radius: 6px 6px 2px 2px; min-height: 2px; }
.bars .seg.over { background: var(--over); border-radius: 6px 6px 0 0; }
.bars .b.is-over .seg.base { border-radius: 0 0 2px 2px; }
.bars .off .seg.base { background: var(--line); }
.bars .goal-line { position: absolute; left: -4px; right: -4px; border-top: 2px dashed var(--goal); z-index: 1; pointer-events: none; }
.bars .lbl { margin-top: 4px; font-weight: 700; color: var(--ink); }
.bars .off .lbl { color: var(--muted); font-weight: 400; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 0.75rem; color: var(--muted); margin-top: 6px; }
.legend .sw { display: inline-block; width: 12px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.legend .sw.base { background: var(--bar); }
.legend .sw.over { background: var(--over); }
.legend .sw.line { height: 0; border-top: 2px dashed var(--goal); border-radius: 0; vertical-align: 3px; }

/* 목표 칼로리 */
.goalbox { margin: 10px 0; padding: 10px 12px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); font-size: 0.92rem; }
.goalbox.none { color: var(--muted); }
.gbar { position: relative; display: flex; height: 12px; background: var(--line); border-radius: 999px; overflow: visible; margin: 8px 0 6px; }
.gbar .base { background: var(--bar); border-radius: 999px 0 0 999px; }
.gbar .over { background: var(--over); border-radius: 0 999px 999px 0; }
.gbar .mark { position: absolute; top: -4px; bottom: -4px; width: 0; border-left: 2px dashed var(--goal); }
.overtext { color: var(--over); font-weight: 700; font-size: 0.9rem; }
.goalnote { font-size: 0.78rem; color: var(--brand); margin-top: 4px; }
.goalnote.soft { color: var(--muted); }
.goalbtn {
  margin-top: 4px; font: inherit; font-size: 0.82rem; padding: 6px 10px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--brand); background: var(--brand-soft); color: var(--brand); min-height: 36px;
}
.bytag {
  position: absolute; margin: 6px; padding: 1px 8px; border-radius: 999px; font-size: 0.72rem;
  background: var(--body); color: #fff;
}
.bytag.me { background: var(--ink); color: var(--card); }
/* 사진 격자: 인스타그램 피드처럼 3칸 정사각형, 사진만 */
.feed { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; margin: 12px 0; }
.tile {
  position: relative; display: block; width: 100%; aspect-ratio: 1 / 1; padding: 0; margin: 0; border: 0;
  background: var(--line); overflow: hidden; cursor: pointer; border-radius: 0; min-height: 0;
}
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .ph { display: grid; place-items: center; height: 100%; font-size: 0.72rem; color: var(--muted); line-height: 1.4; text-align: center; }
.tile .mark-ic {
  position: absolute; top: 4px; right: 4px; font-style: normal; font-size: 0.75rem; line-height: 1;
  padding: 3px 4px; border-radius: 999px; background: rgba(0, 0, 0, 0.45);
}
.tile:focus-visible { outline: 3px solid var(--brand); outline-offset: -3px; }

/* 사진 크게 보기 */
.photo-dlg { padding: 0; width: min(520px, 100vw); max-width: 100vw; max-height: 100dvh; background: #000; color: #fff; border-radius: 0; }
.pv-top { padding: 10px 12px; font-size: 0.9rem; flex-wrap: nowrap; }
.photo-dlg .pv-top button { background: transparent; color: #fff; border: 1px solid rgba(255, 255, 255, 0.35); }
.pv-stage { position: relative; display: flex; align-items: center; justify-content: center; min-height: 45vh; background: #000; }
.pv-img img { display: block; max-width: 100%; max-height: 65dvh; }
.pv-img .ph.big { display: grid; place-items: center; width: min(360px, 80vw); aspect-ratio: 3 / 4; background: #222; color: #aaa; }
.photo-dlg .pv-nav {
  position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 64px; padding: 0;
  font-size: 2rem; border: 0; border-radius: 0; background: rgba(0, 0, 0, 0.35); color: #fff; cursor: pointer;
}
.pv-nav.prev { left: 0; }
.pv-nav.next { right: 0; }
.photo-dlg .pv-nav:disabled { opacity: 0.2; cursor: default; }
.pv-actions { display: flex; flex-direction: column; gap: 8px; padding: 12px; background: var(--card); color: var(--ink); }
.pv-actions:empty { display: none; }
.sharebtn.big { width: 100%; margin: 0; min-height: 48px; font-size: 0.95rem; }

.grid figure { position: relative; }
.grid figure.shared { border-color: var(--body); box-shadow: 0 0 0 1px var(--body); }
.sharebtn {
  display: block; width: calc(100% - 12px); margin: 0 6px 6px; min-height: 40px; cursor: pointer; font: inherit; font-size: 0.85rem;
  border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--muted);
}
.sharebtn.on { background: var(--body); border-color: var(--body); color: #fff; font-weight: 700; }
.check { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 0.9rem; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--body); }
.actions button:disabled { opacity: 0.45; cursor: default; }

.bodycard { border-color: var(--body); background: var(--body-soft); }
.bodycard h2, .bodycard .bodyc { color: var(--body); }
.bodybtn { background: var(--body) !important; color: #fff !important; border-color: var(--body) !important; font-weight: 700; width: 100%; }
.share { margin-top: 12px; padding: 12px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); }
.share.on { border-color: var(--body); }
.share button { margin-top: 8px; width: 100%; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.grid figure { margin: 0; background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.grid img, .grid .ph { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; display: grid; place-items: center; background: var(--line); color: var(--muted); font-size: 0.8rem; }
.grid figcaption { display: flex; justify-content: space-between; align-items: center; padding: 4px 8px; font-size: 0.85rem; }

.member { display: block; text-decoration: none; color: inherit; }
.member .name { font-weight: 700; }
.stat { display: flex; gap: 12px; flex-wrap: wrap; font-size: 0.9rem; color: var(--muted); margin-top: 4px; }
.stat b { color: var(--ink); }
.st { font-size: 0.78rem; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.st.pass, .st.success { background: var(--brand-soft); color: var(--brand); }
.st.fail { background: #fde7e4; color: var(--bad); }
.st.ongoing, .st.future { background: var(--line); color: var(--muted); }
@media (prefers-color-scheme: dark) { .st.fail { background: #3d1f1b; } }

.board { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.board th, .board td { border-bottom: 1px solid var(--line); padding: 8px 4px; text-align: center; }
.board th:first-child, .board td:first-child { text-align: left; }
.board .mark { font-size: 1.1rem; font-weight: 800; }
.board .mark.pass { color: var(--brand); }
.board .mark.fail { color: var(--bad); }
.board .mark.ongoing, .board .mark.future { color: var(--muted); font-weight: 400; }
.scroll { overflow-x: auto; }

dialog {
  border: none; border-radius: 16px; padding: 18px; width: min(440px, calc(100vw - 32px));
  background: var(--card); color: var(--ink);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog label { display: block; margin: 10px 0; font-size: 0.92rem; }
dialog input {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px; font: inherit; font-size: 16px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink);
}
.dlg-photo { width: 100%; max-height: 220px; object-fit: contain; border-radius: 10px; background: var(--line); }

.toast {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--card); padding: 10px 16px; border-radius: 999px; font-size: 0.9rem;
  opacity: 0; pointer-events: none; transition: opacity 0.2s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; }

.tabs a { position: relative; }
.tabs a .badge { top: 4px; left: 50%; right: auto; margin-left: 6px; }
.badge {
  position: absolute; top: -4px; right: -12px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px; background: var(--bad); color: #fff; font-size: 0.7rem; font-weight: 700; line-height: 18px;
}
.badge.static { position: static; display: inline-block; vertical-align: middle; }
.chatbtn { position: relative; white-space: nowrap; }
.chatbtn.new { font-weight: 700; }
.chatbtn .dot { position: absolute; top: 4px; right: 0; width: 8px; height: 8px; border-radius: 50%; background: var(--bad); }
/* 대화방 */
.room { padding: 4px 0 8px; }
.daysep { text-align: center; font-size: 0.78rem; color: var(--muted); margin: 14px 0 6px; }
.daysep::before, .daysep::after { content: ' — '; opacity: 0.5; }
.msg { margin: 6px 0; display: flex; flex-direction: column; }
.msg .who { font-size: 0.78rem; color: var(--muted); margin-bottom: 2px; }
.msg .bubble { max-width: 80%; padding: 8px 12px; border-radius: 16px; white-space: pre-wrap; word-break: break-word; }
.msg .time { font-size: 0.7rem; color: var(--muted); margin-top: 2px; }
.msg.theirs { align-items: flex-start; }
.msg.theirs .bubble { background: var(--card); border: 1px solid var(--line); border-top-left-radius: 4px; }
.msg.mine { align-items: flex-end; }
.msg.mine .bubble { background: var(--brand); color: var(--brand-ink); border-top-right-radius: 4px; }
.ref {
  display: flex; gap: 8px; align-items: center; max-width: 80%; margin-bottom: 4px; padding: 6px 8px;
  border: 1px dashed var(--line); border-radius: 10px; background: var(--card); font-size: 0.85rem;
}
.ref.gone { color: var(--muted); }
.thumb.sm { width: 40px; height: 40px; border-radius: 8px; }
.composer {
  position: sticky; bottom: calc(60px + env(safe-area-inset-bottom)); z-index: 2;
  background: var(--bg); padding: 8px 0 4px; border-top: 1px solid var(--line);
}
.composer .row.nowrap { flex-wrap: nowrap; align-items: flex-end; }
.composer textarea {
  flex: 1; min-width: 0; font: inherit; font-size: 16px; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 12px; background: var(--card); color: var(--ink); resize: none; max-height: 120px;
}
.composer .primary { flex: none; }
.composer .error { margin: 2px 0 0; min-height: 0; }
.attach {
  display: flex; align-items: center; gap: 6px; font-size: 0.85rem; padding: 4px 8px; margin-bottom: 6px;
  background: var(--brand-soft); color: var(--brand); border-radius: 10px;
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* 손가락으로 누르기 쉽게(44px 안팎) */
.navlinks { margin: 4px 0; }
.navlinks a { display: inline-block; padding: 12px 2px; }
.composer button { min-height: 44px; padding: 9px 14px; border-radius: 12px; border: 1px solid var(--line); cursor: pointer; }
.chips { flex-wrap: wrap; }

/* 휴대폰에서 글 쓰는 동안: 아래 메뉴를 숨기고 입력칸을 맨 아래로 */
body.typing .tabs { display: none; }
body.typing { padding-bottom: env(safe-area-inset-bottom); }
body.typing .composer { bottom: 0; }
body.typing .toast { bottom: 16px; }

/* 창이 화면보다 길면 창 안에서 내려 봐요 */
dialog { max-height: calc(100dvh - 24px); overflow-y: auto; overscroll-behavior: contain; }
.photo-dlg { max-height: 100dvh; }

/* 작은 휴대폰(가로 360px 이하) */
@media (max-width: 360px) {
  body { font-size: 15px; }
  .brand { font-size: 0.95rem; }
  .mode a { padding: 6px 9px; font-size: 0.8rem; }
  .tabs a { font-size: 0.74rem; padding: 8px 2px 10px; }
  .big { font-size: 1.4rem !important; }
  .bars { gap: 4px; }
  .bars .val { font-size: 0.62rem; }
}

ul.plain { padding-left: 18px; margin: 6px 0; }
ul.plain li { margin: 4px 0; }
