:root {
  --bg: #1a1917;
  --card: #232120;
  --line: #333029;
  --text: #f0ede6;
  --text2: #8a857c;
  --danger: #c96a5a;
  --num: "Oswald", system-ui, sans-serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
}
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button {
  font-family: inherit;
  cursor: pointer;
  color: inherit;
}
input {
  font-family: inherit;
}
.num {
  font-family: var(--num);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  letter-spacing: -0.01em;
}

/* ---- app shell ---- */
#app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}
.topbar {
  display: flex;
  gap: 4px;
  padding: 14px 18px calc(14px + env(safe-area-inset-top));
  padding-top: max(14px, env(safe-area-inset-top));
}
.tab {
  background: none;
  border: 0;
  color: var(--text2);
  font-size: 15px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 8px;
  letter-spacing: 0.02em;
}
.tab[aria-current="true"] {
  color: var(--text);
}
.view {
  flex: 1;
  padding: 8px 18px 120px;
}

/* ---- today ---- */
.hero {
  padding: 22px 0 26px;
  text-align: center;
}
.hero .total {
  font-family: var(--num);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: clamp(72px, 26vw, 128px);
  line-height: 0.9;
  letter-spacing: -0.02em;
}
.hero .unit {
  color: var(--text2);
  font-size: 15px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-top: 6px;
}
.macros {
  display: flex;
  justify-content: center;
  gap: 22px;
  margin-top: 16px;
}
.macro {
  color: var(--text2);
  font-size: 13px;
}
.macro b {
  display: block;
  color: var(--text);
  font-family: var(--num);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  font-size: 22px;
}

.meal-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}
.meal {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
  text-align: left;
  width: 100%;
}
.thumb {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--line);
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  color: var(--text2);
}
.meal .meta {
  flex: 1;
  min-width: 0;
}
.meal .name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.meal .sub {
  color: var(--text2);
  font-size: 13px;
}
.meal .kcal {
  font-family: var(--num);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  font-size: 22px;
}
.empty {
  color: var(--text2);
  text-align: center;
  padding: 40px 0;
}

/* ---- capture button ---- */
.capture-bar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(22px + env(safe-area-inset-bottom));
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
}
.capture {
  border: 0;
  background: var(--text);
  color: var(--bg);
  font-weight: 700;
  font-size: 16px;
  height: 56px;
  padding: 0 30px;
  border-radius: 28px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}
.capture-lib {
  width: 56px;
  height: 56px;
  flex: 0 0 auto;
  border-radius: 28px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  font-size: 22px;
  display: grid;
  place-items: center;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}
.capture:active,
.capture-lib:active {
  transform: scale(0.97);
}

/* ---- sheet (review / day detail) ---- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 30;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  background: var(--bg);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  max-height: 92dvh;
  overflow-y: auto;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
}
.sheet h2 {
  margin: 4px 0 2px;
  font-size: 20px;
}
.sheet .sub {
  color: var(--text2);
  font-size: 13px;
  margin-bottom: 14px;
}
.review-photo {
  width: 100%;
  height: 190px;
  object-fit: cover;
  border-radius: 14px;
  background: var(--card);
  margin-bottom: 14px;
}
.spinner-wrap {
  height: 190px;
  display: grid;
  place-items: center;
  color: var(--text2);
  gap: 10px;
}
.spinner {
  width: 26px;
  height: 26px;
  border: 3px solid var(--line);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}
.item .iname {
  flex: 1;
  min-width: 0;
}
.item .iname .n {
  font-weight: 600;
}
.item .iname .m {
  color: var(--text2);
  font-size: 12px;
}
.badge {
  display: inline-block;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: 6px;
  padding: 1px 5px;
  margin-left: 6px;
  vertical-align: middle;
}
.grams {
  width: 76px;
  flex: 0 0 auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 10px;
  text-align: right;
  font-family: var(--num);
  font-variant-numeric: tabular-nums;
  font-size: 17px;
}
.grams:focus {
  outline: 2px solid var(--text2);
  outline-offset: 1px;
}
.gunit {
  color: var(--text2);
  font-size: 12px;
  margin-left: -8px;
}
.item .ikcal {
  width: 62px;
  text-align: right;
  font-family: var(--num);
  font-variant-numeric: tabular-nums;
  font-size: 19px;
  flex: 0 0 auto;
}

.review-total {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  border-top: 1px solid var(--line);
  padding-top: 14px;
  margin-top: 4px;
}
.review-total .rt {
  color: var(--text2);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.review-total .rv {
  font-family: var(--num);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 40px;
}
.hint-field {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  padding: 12px;
  margin-top: 12px;
  font-size: 15px;
}
.actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}
.btn {
  flex: 1;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 14px;
  padding: 15px;
  font-weight: 700;
  font-size: 16px;
}
.btn.primary {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}
.btn.ghost {
  color: var(--text2);
}
.btn:disabled {
  opacity: 0.5;
}
.notes {
  color: var(--text2);
  font-size: 13px;
  margin: 8px 0 2px;
}

/* ---- login ---- */
.login {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 26px;
  gap: 14px;
}
.login h1 {
  font-family: var(--num);
  font-weight: 600;
  font-size: 44px;
  letter-spacing: 0.02em;
  margin: 0;
}
.login p {
  color: var(--text2);
  margin: 0 0 6px;
}
.login input {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  padding: 16px;
  font-size: 17px;
}
.login .err {
  color: var(--danger);
  font-size: 14px;
  min-height: 18px;
}

/* ---- progress chart ---- */
.chart-wrap {
  margin-top: 8px;
}
.chart {
  width: 100%;
  height: 240px;
  display: block;
}
.chart .bar {
  fill: var(--line);
}
.chart .bar.tap {
  cursor: pointer;
}
.chart .avg {
  fill: none;
  stroke: var(--text);
  stroke-width: 2;
  stroke-linejoin: round;
}
.legend {
  display: flex;
  gap: 18px;
  color: var(--text2);
  font-size: 12px;
  margin-top: 6px;
}
.legend .k {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.swatch {
  width: 14px;
  height: 3px;
  border-radius: 2px;
  background: var(--text);
  display: inline-block;
}
.swatch.bar {
  height: 10px;
  width: 8px;
  background: var(--line);
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 1.6s;
  }
  .capture:active,
  .capture-lib:active {
    transform: none;
  }
}

/* ---- today: budget / exercise / manual ---- */
.hero .total.over {
  color: var(--danger);
}
.budget {
  color: var(--text2);
  font-size: 13px;
  margin-top: 8px;
}
.setgoal {
  background: none;
  border: 0;
  color: var(--text2);
  font-size: 14px;
  margin-top: 8px;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.exercise {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 14px;
  margin: 4px 0 14px;
}
.ex-label {
  font-weight: 600;
}
.ex-input {
  width: 72px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 8px 10px;
  text-align: right;
  font-size: 16px;
}
.ex-unit {
  color: var(--text2);
  font-size: 13px;
}
.add-manual {
  margin-top: 14px;
}

/* ---- editor: editable items ---- */
.items {
  display: flex;
  flex-direction: column;
}
.item.edit {
  display: block;
  border-top: 1px solid var(--line);
  padding: 12px 0;
}
.item-top {
  display: flex;
  align-items: center;
  gap: 8px;
}
.n-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  padding: 4px 0;
}
.n-input:focus {
  outline: none;
  border-bottom-color: var(--text2);
}
.rm {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 15px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text2);
  font-size: 13px;
  line-height: 1;
}
.item-bottom {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.item-bottom .field {
  color: var(--text2);
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.item-bottom .grams,
.item-bottom .kcal-input {
  width: 64px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 8px 8px;
  text-align: right;
  font-size: 16px;
}
.item-bottom .m {
  margin-left: auto;
  color: var(--text2);
  font-size: 12px;
}
.edit-tools {
  display: flex;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
  margin-top: 4px;
}
.ghost-btn {
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 14px;
  font-weight: 600;
}
.err-box {
  color: var(--text2);
  text-align: center;
  padding: 24px 8px;
  font-size: 15px;
}

/* ---- goal calculator ---- */
.goal-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.seg {
  display: flex;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
}
.seg button {
  flex: 1;
  background: none;
  border: 0;
  color: var(--text2);
  font-weight: 600;
  font-size: 15px;
  padding: 10px;
  border-radius: 9px;
}
.seg button.on {
  background: var(--text);
  color: var(--bg);
}
.gl {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--text2);
  font-size: 15px;
}
.gl .hh {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text2);
  font-size: 13px;
}
.gl input {
  width: 68px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 11px 10px;
  text-align: right;
  font-size: 16px;
}
.gl select {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 11px 10px;
  font-size: 15px;
  max-width: 62%;
}
.goal-result {
  text-align: center;
  margin-top: 22px;
}
.goal-num {
  font-family: var(--num);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: clamp(56px, 20vw, 96px);
  line-height: 0.95;
}
.goal-breakdown {
  color: var(--text2);
  font-size: 14px;
  margin: 6px 0 18px;
}
.goal-result .btn {
  max-width: 260px;
  margin: 0 auto;
}

/* ---- progress dashboard: today log ---- */
.sec-label {
  color: var(--text2);
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin: 22px 0 8px;
}
.log-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  margin-top: 8px;
}
.log-title {
  font-weight: 700;
  margin-bottom: 10px;
}
.log-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.log-label {
  color: var(--text2);
  font-size: 15px;
}
.log-row .hh {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text2);
  font-size: 13px;
}
.w-input {
  width: 80px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 9px 10px;
  text-align: right;
  font-size: 16px;
}
.note-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 10px;
  font-size: 15px;
  font-family: inherit;
  resize: vertical;
}
.body-photos {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.bthumb {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 12px;
  overflow: hidden;
  flex: 0 0 auto;
}
.bthumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.bthumb.add {
  border: 1px dashed var(--line);
  background: var(--bg);
  color: var(--text2);
  font-size: 24px;
  display: grid;
  place-items: center;
}
.brm {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 22px;
  height: 22px;
  border-radius: 11px;
  border: 0;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 12px;
  line-height: 1;
}

/* ---- weight chart ---- */
.wchart-top {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 4px;
}
.wnow {
  font-family: var(--num);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 26px;
}
.wchart {
  height: 150px;
}
.wchart .wline {
  fill: none;
  stroke: var(--text);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.wchart circle {
  fill: var(--text);
}

/* ---- history timeline ---- */
.timeline {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.jentry {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
}
.jhead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}
.jdate {
  font-weight: 600;
}
.jweight {
  font-family: var(--num);
  font-variant-numeric: tabular-nums;
  color: var(--text2);
  font-size: 16px;
}
.jnote {
  color: var(--text2);
  font-size: 14px;
  margin-top: 6px;
  white-space: pre-wrap;
}
.jphotos {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.jthumb {
  width: 84px;
  height: 84px;
  object-fit: cover;
  border-radius: 12px;
}
