:root {
  --bg: #12110e;
  --ink: #f6f0e6;
  --muted: #c4b8a6;
  --line: #3a342b;
  --elev: #1c1914;
  --paper: #f7f1e6;
  --paper-ink: #1a1612;
  --paper-muted: #5e574c;
  --paper-line: #e4d9c6;
  --cal: #e23b2f;
  --pro: #2f7d4a;
  --carb: #e09a12;
  --fat: #c46b3a;
  --focus: #e09a12;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: ui-sans-serif, system-ui, "Segoe UI", sans-serif;
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #efe8da;
  --ink: #1a1612;
  --muted: #5e574c;
  --line: #ddd2c0;
  --elev: #f7f1e6;
  --cal: #c43228;
  --focus: #9a6b00;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(900px 420px at 0% -10%, rgba(226, 59, 47, 0.18), transparent 55%),
    radial-gradient(700px 380px at 100% 0%, rgba(224, 154, 18, 0.12), transparent 50%),
    var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--sans);
}
[data-theme="light"] body {
  background:
    radial-gradient(900px 420px at 0% -10%, rgba(226, 59, 47, 0.12), transparent 55%),
    radial-gradient(700px 380px at 100% 0%, rgba(224, 154, 18, 0.16), transparent 50%),
    var(--bg);
}
h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -0.03em; margin: 0; }
button, input, textarea { font: inherit; color: inherit; }
:focus { outline: none; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.skip {
  position: absolute;
  left: 12px;
  top: -40px;
  background: var(--paper);
  color: var(--paper-ink);
  padding: 8px 12px;
  border-radius: 8px;
  z-index: 5;
}
.skip:focus { top: 12px; }
.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}
.wrap { width: min(980px, 100%); margin: 0 auto; padding: 20px 20px 64px; }
header { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.eyebrow { margin: 0 0 2px; color: var(--muted); font-size: 0.75rem; letter-spacing: 0.14em; text-transform: uppercase; }
h1 { font-size: clamp(2.2rem, 5vw, 3.2rem); line-height: 0.95; }
h1 span { color: var(--cal); }
.tag { margin: 6px 0 0; color: var(--muted); }
.header-actions { display: flex; gap: 8px; }
button {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
}
button:hover { border-color: var(--ink); }
.primary, .ink {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
  font-weight: 650;
}
[data-theme="light"] .primary, [data-theme="light"] .ink { color: #f7f1e6; }
.ink { background: var(--paper-ink); color: var(--paper); border-color: var(--paper-ink); }
.text { border-color: transparent; background: transparent; padding-inline: 8px; }
.text:hover { border-color: transparent; text-decoration: underline; }
.today, .composer, .empty-label {
  background: var(--elev);
  border: 1px solid var(--line);
  border-radius: 18px;
}
.today { padding: 14px 16px 12px; margin-bottom: 12px; }
.today-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.today-head h2 { font-size: 1.35rem; }
.today-head p { margin: 0; color: var(--muted); }
.stats { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr; gap: 14px; }
.stat-top { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; }
.stat-top span { color: var(--muted); font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; }
.stat-top strong { font-family: var(--serif); font-size: 1.45rem; line-height: 1.1; font-variant-numeric: tabular-nums; letter-spacing: -0.03em; }
.stat.cal .stat-top strong { font-size: 1.9rem; }
.over { color: var(--cal); }
.track { height: 8px; border-radius: 99px; background: color-mix(in srgb, var(--ink) 12%, transparent); margin: 6px 0 4px; overflow: hidden; }
.fill { height: 100%; width: 0; border-radius: inherit; background: var(--muted); }
.cal .fill { background: var(--cal); }
.pro .fill { background: var(--pro); }
.carb .fill { background: var(--carb); }
.fat .fill { background: var(--fat); }
.goal-line { margin: 0; color: var(--muted); font-size: 0.82rem; }
.layout { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.composer, .empty-label, .label { padding: 14px 16px; }
.composer h2, .history h2 { font-size: 1.45rem; margin-bottom: 10px; }
textarea, .paper-input {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  padding: 12px;
  resize: vertical;
  min-height: 96px;
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.chip { padding: 6px 10px; border-radius: 999px; color: var(--muted); }
.actions { display: flex; gap: 8px; }
.actions button { flex: 1; border-radius: 12px; min-height: 44px; }
.hint { color: var(--muted); font-size: 0.86rem; margin: 10px 0 0; }
kbd { font-family: inherit; border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
figure { margin: 12px 0 0; }
#preview-img { width: 100%; max-height: 200px; object-fit: cover; border-radius: 12px; display: block; }
.empty-label { color: var(--muted); background: transparent; border-style: dashed; }
.empty-label p { margin: 8px 0 0; }
.empty-label .nf { margin-top: 0; }
.nf { font-size: 0.78rem; letter-spacing: 0.16em; text-transform: uppercase; font-family: var(--sans); font-weight: 700; }
.label {
  background: var(--paper);
  color: var(--paper-ink);
  border-radius: 18px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}
.label .nf span { font-weight: 500; letter-spacing: 0.08em; color: var(--paper-muted); }
.meal-name {
  width: 100%;
  border: 0;
  background: transparent;
  font-family: var(--serif);
  font-size: 1.5rem;
  line-height: 1.15;
  letter-spacing: -0.03em;
  padding: 2px 0 0;
  color: var(--paper-ink);
}
.label input:focus-visible,
dialog input:focus-visible {
  outline: 2px solid var(--paper-ink);
  outline-offset: 2px;
  border-radius: 4px;
}
.rule { height: 0; border: 0; border-top: 1px solid var(--paper-ink); margin: 6px 0; }
.rule.fat { border-top-width: 8px; }
.rule.thin { border-top-color: var(--paper-line); }
.cal-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.cal-row label { font-family: var(--serif); font-size: 1.35rem; }
#kcal {
  width: 7ch;
  border: 0;
  background: transparent;
  text-align: right;
  font-family: var(--serif);
  font-size: 2.1rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  color: var(--paper-ink);
  font-variant-numeric: tabular-nums;
}
.macro-edit { display: grid; gap: 2px; }
.macro-edit label { display: flex; align-items: baseline; gap: 8px; font-weight: 700; padding: 4px 0; border-bottom: 1px solid var(--paper-line); }
.macro-edit input {
  margin-left: auto;
  width: 6ch;
  border: 0;
  background: transparent;
  text-align: right;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--paper-ink);
  font-size: 1.05rem;
}
.macro-edit span { color: var(--paper-muted); font-weight: 600; }
#breakdown { list-style: none; margin: 0; padding: 0; }
#breakdown li { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; color: var(--paper-muted); font-size: 0.92rem; }
.match-note { color: var(--paper-muted); font-size: 0.86rem; margin: 6px 0 0; }
.label-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.label .text { color: var(--paper-ink); }
.history { margin-top: 28px; }
.history h3 { font-size: 1rem; margin: 16px 0 8px; color: var(--muted); }
.empty { color: var(--muted); margin: 8px 0 0; }
.hrow {
  display: grid;
  grid-template-columns: 5.2rem minmax(0, 1fr) auto auto auto;
  gap: 8px 12px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.hname { margin: 0; overflow-wrap: anywhere; }
.hkcal, .hmacros, time { margin: 0; font-variant-numeric: tabular-nums; }
.hmacros, time { color: var(--muted); }
.status { min-height: 1.3em; color: var(--muted); margin: 0 0 12px; }
footer p { color: var(--muted); font-size: 0.82rem; margin: 18px 0 0; }
dialog {
  border: 0;
  padding: 0;
  border-radius: 18px;
  background: var(--paper);
  color: var(--paper-ink);
  width: min(440px, calc(100% - 24px));
}
dialog::backdrop { background: rgba(20, 16, 12, 0.62); }
#goals-form { padding: 18px; }
#goals-form h2 { font-size: 1.6rem; margin-bottom: 4px; }
.goal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.goal-grid label { display: grid; gap: 4px; font-size: 0.85rem; font-weight: 650; }
.goal-grid input, #goals-form .hint { color: var(--paper-ink); }
.goal-grid input {
  border: 1px solid var(--paper-line);
  border-radius: 10px;
  padding: 8px 10px;
  background: #fffdf8;
  font-variant-numeric: tabular-nums;
}
#goals-form .hint { color: var(--paper-muted); }
.close-x { margin-top: 8px; }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
@media (max-width: 800px) {
  .layout, .stats { grid-template-columns: 1fr 1fr; }
  .stat.cal { grid-column: 1 / -1; }
}
@media (max-width: 560px) {
  .wrap { padding: 18px 14px 48px; }
  .layout { grid-template-columns: 1fr; }
  .actions { flex-direction: column; }
  .hrow { grid-template-columns: auto minmax(0, 1fr) auto; }
  .hmacros { grid-column: 1 / -1; }
  .hkcal { justify-self: end; }
  h1 { font-size: 2.3rem; }
  #kcal { font-size: 2rem; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}
