:root {
  color-scheme: light dark;
  --bg: #f5f3ee;
  --card: #ffffff;
  --ink: #1d211f;
  --muted: #68706b;
  --line: #e2dfd7;
  --accent: #1f6f54;
  --accent-ink: #ffffff;
  --soft: #e3f0ea;
  --over: #b5482a;
  --gym: #3d5fb0;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131614;
    --card: #1d211f;
    --ink: #ecefec;
    --muted: #9aa39e;
    --line: #2e3431;
    --accent: #58c09a;
    --accent-ink: #0f1a15;
    --soft: #20362d;
    --over: #ec8a6c;
    --gym: #8fa9ec;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
}
main { max-width: 640px; margin: 0 auto; padding: 20px 16px 104px; }
h1 { font-size: 1.5rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1rem; margin: 0; }
p { margin: 0; }
.muted { color: var(--muted); font-size: .875rem; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn {
  border: 0; border-radius: 10px; padding: 11px 16px; min-height: 44px;
  background: var(--accent); color: var(--accent-ink); font-weight: 600;
}
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--over); border: 1px solid currentColor; }
.btn.small { padding: 6px 12px; min-height: 36px; font-size: .875rem; }
.link { background: none; border: 0; padding: 4px; color: var(--muted); font-size: .875rem; text-decoration: underline; }
.icon {
  width: 44px; height: 44px; border-radius: 10px; flex: none;
  border: 1px solid var(--line); background: var(--card); font-size: 1.15rem; line-height: 1;
}

.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.nav { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.nav .label { flex: 1; text-align: center; font-weight: 600; }
.nav .label::first-letter { text-transform: uppercase; }
.nav .label small { display: block; font-weight: 400; color: var(--muted); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.summary { display: flex; align-items: center; gap: 20px; }
.ring { width: 116px; height: 116px; flex: none; }
.ring .track { stroke: var(--soft); }
.ring .value { stroke: var(--accent); transition: stroke-dasharray .25s; }
.ring.over .value { stroke: var(--over); }
.ring text { fill: var(--ink); text-anchor: middle; }
.ring .big { font-size: 22px; font-weight: 700; }
.ring .sub { font-size: 11px; fill: var(--muted); }
.stats { flex: 1; min-width: 0; }
.remaining { font-weight: 600; font-size: 1.05rem; }
.remaining.over { color: var(--over); }
.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.macros b { display: block; font-size: 1rem; }

.items { list-style: none; margin: 8px 0 0; padding: 0; }
.items button {
  display: flex; justify-content: space-between; gap: 12px; width: 100%;
  background: none; border: 0; border-top: 1px solid var(--line);
  padding: 11px 0; text-align: left;
}
.items .name { overflow-wrap: anywhere; }
.items .kcal { flex: none; color: var(--muted); }

.workout { width: 100%; text-align: left; display: block; }
.workout .ex { margin-top: 6px; font-size: .875rem; color: var(--muted); overflow-wrap: anywhere; }
.tag { color: var(--gym); font-weight: 600; font-size: .875rem; }
.empty { text-align: center; padding: 32px 16px; color: var(--muted); }

.grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.dow { text-align: center; font-size: .75rem; color: var(--muted); padding-bottom: 2px; }
.day {
  position: relative; min-height: 60px; padding: 5px 2px; border-radius: 9px;
  border: 1px solid transparent; background: var(--card);
  display: flex; flex-direction: column; align-items: center; gap: 1px;
}
.day .n { font-size: .875rem; font-weight: 600; }
.day .k { font-size: .6875rem; color: var(--accent); }
.day .k.over { color: var(--over); }
.day .g { width: 16px; height: 4px; border-radius: 2px; background: var(--gym); margin-top: auto; }
.day.today .n { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.day.sel { border-color: var(--accent); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 10px; font-size: .75rem; color: var(--muted); }
.legend i { display: inline-block; width: 12px; height: 4px; border-radius: 2px; margin-right: 5px; vertical-align: middle; background: var(--gym); }
.legend i.a { background: var(--accent); }
.legend i.o { background: var(--over); }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pair b { display: block; font-size: 1.25rem; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.row .btn { flex: 1; white-space: nowrap; }

#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabs[hidden], #toast[hidden] { display: none; }
#tabs button { flex: 1; max-width: 214px; min-height: 58px; background: none; border: 0; color: var(--muted); font-size: .875rem; font-weight: 600; border-top: 2px solid transparent; }
#tabs button[aria-current] { color: var(--accent); border-top-color: var(--accent); }

dialog {
  width: min(520px, calc(100vw - 24px)); max-height: 88dvh; padding: 18px;
  background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 16px;
}
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog h2 { font-size: 1.15rem; margin-bottom: 14px; }
label { display: block; font-size: .875rem; font-weight: 600; margin-bottom: 12px; }
.spaced { margin-top: 12px; }
.picks { list-style: none; margin: -6px 0 6px; padding: 0; max-height: 264px; overflow-y: auto; border: 1px solid var(--line); border-radius: 9px; }
.picks button { display: flex; justify-content: space-between; gap: 10px; width: 100%; padding: 10px; min-height: 44px; background: none; border: 0; text-align: left; font-size: .9375rem; }
.picks li + li button { border-top: 1px solid var(--line); }
.picks .name { overflow-wrap: anywhere; min-width: 0; }
.picks .kcal { flex: none; color: var(--muted); font-size: .8125rem; }
.picks-msg { margin: -6px 0 6px; }
.per100 { margin: -6px 0 0; }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 10px; min-height: 44px;
  border: 1px solid var(--line); border-radius: 9px; background: var(--bg); font-size: 16px; font-weight: 400;
}
.fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.fields.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
details { margin-bottom: 12px; }
summary { cursor: pointer; font-size: .875rem; color: var(--muted); margin-bottom: 10px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.actions .grow { flex: 1; }
.ex-box { border: 1px solid var(--line); border-radius: 11px; padding: 10px; margin-bottom: 10px; }
.ex-top { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.ex-top input { margin: 0; }
.set { display: grid; grid-template-columns: 22px 1fr 1fr 36px; gap: 6px; align-items: center; margin-bottom: 6px; }
.set input { margin: 0; }
.set .i { color: var(--muted); font-size: .8125rem; text-align: center; }
.set-head { display: grid; grid-template-columns: 22px 1fr 1fr 36px; gap: 6px; font-size: .75rem; color: var(--muted); margin-bottom: 3px; }
.set-head span:nth-child(1), .set-head span:nth-child(4) { visibility: hidden; }
.x { width: 36px; height: 36px; background: none; border: 0; color: var(--muted); font-size: 1.1rem; }
.detail-ex { border-top: 1px solid var(--line); padding: 10px 0; }
.detail-ex p { color: var(--muted); font-size: .875rem; }
.notes { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 8px; }

.login { max-width: 340px; margin: 14vh auto 0; }
.login h1 { margin-bottom: 4px; }
.login form { margin-top: 20px; }
.login .btn { width: 100%; }
.error { color: var(--over); font-size: .875rem; min-height: 1.3em; margin-bottom: 8px; }

#toast {
  position: fixed; left: 50%; bottom: 76px; transform: translateX(-50%); z-index: 20;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-size: .875rem; max-width: calc(100vw - 32px);
}
