:root {
  --bg: #0E1013;
  --card: #191C21;
  --line: #2A2E35;
  --edge: #3A3F48;
  --text: #F2F3F5;
  --muted: #A3AAB5;
  --orange: #FF7A45;
  --blue: #4DB8FF;
  --lime: #C8F03C;
  --cond: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  --body: 'Barlow', system-ui, -apple-system, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--lime); }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
input { color-scheme: dark; }
input::placeholder { color: #8A919C; }
:focus-visible { outline: 2px solid var(--lime); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.wrap {
  max-width: 480px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 24px) 18px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
body.has-nav .wrap { padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 110px); }

/* type */
.h1 {
  margin: 0;
  font-family: var(--cond);
  font-weight: 700;
  font-size: 44px;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: 0.01em;
}
.h1.big { font-size: 46px; margin-top: 4px; }
.h1.sm { font-size: 24px; letter-spacing: 0.04em; }
.h2 { margin: 0; font-family: var(--cond); font-weight: 700; font-size: 24px; line-height: 1.05; text-transform: uppercase; }
.lbl {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.lbl.hi { color: var(--text); }
.date { margin: 0; font-size: 13px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.num { font-family: var(--cond); font-weight: 700; line-height: 1; }
.num.xl { font-size: 64px; }
.num.lg { font-size: 44px; margin-top: 4px; }
.num.md { font-size: 26px; }
.num.sm { font-size: 20px; }
.num small { font-family: var(--body); font-weight: 500; font-size: 13px; color: var(--muted); }
.of { font-size: 22px; color: var(--muted); }
.small { font-size: 14px; }
.xs { font-size: 12px; font-weight: 600; }
.strong { font-weight: 600; }
.muted { color: var(--muted); }
.orange { color: var(--orange); }
.blue { color: var(--blue); }
.tcenter { text-align: center; }
.nowrap { white-space: nowrap; }
.empty { margin: 8px 0 12px; color: var(--muted); font-size: 15px; }

/* layout */
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack-sm { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; }
.row.between { justify-content: space-between; }
.row.center { align-items: center; }
.row.end { align-items: flex-end; }
.row.start { align-items: flex-start; }
.row.gap { gap: 10px; }
.gap-sm { gap: 10px; }
.wrapflex { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.right { text-align: right; white-space: nowrap; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }

.card { background: var(--card); border-radius: 22px; }
.card.pad { padding: 20px; }
.card.list { padding: 18px 20px 6px; }
.card.list > .lbl { margin-bottom: 6px; }

/* calorie ring */
.cal { padding: 24px 20px 20px; display: flex; flex-direction: column; align-items: center; gap: 18px; }
.ring { position: relative; width: 210px; height: 210px; }
.ring circle { fill: none; stroke-width: 14; }
.ring .track { stroke: var(--line); }
.ring .fill { stroke: var(--orange); stroke-linecap: round; transition: stroke-dasharray .5s ease; }
.ring-mid { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.split { display: grid; grid-template-columns: 1fr 1fr; width: 100%; border-top: 1px solid var(--line); padding-top: 14px; text-align: center; }
.split > div + div { border-left: 1px solid var(--line); }

/* bars */
.bar { display: block; height: 10px; border-radius: 999px; background: var(--line); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 999px; }
.bar.thin { height: 6px; }
.blue-bg { background: var(--blue); }
.orange-bg { background: var(--orange); }
.lime-bg { background: var(--lime); color: var(--bg); }

/* buttons */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 56px;
  padding: 0 18px;
  border: none;
  border-radius: 14px;
  text-decoration: none;
}
.btn.primary {
  background: var(--orange);
  color: var(--bg);
  font-family: var(--cond);
  font-weight: 700;
  font-size: 21px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.btn.primary:active { transform: translateY(1px); }
.btn.secondary {
  min-height: 50px;
  background: transparent;
  color: var(--text);
  border: 1.5px solid var(--edge);
  font-weight: 600;
  font-size: 15px;
}
.btn[disabled] { opacity: .6; }
.iconbtn {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border: 1.5px solid var(--edge);
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 22px;
  font-weight: 600;
  text-decoration: none;
}
.iconbtn.star.on { background: var(--lime); border-color: var(--lime); color: var(--bg); }
.iconbtn.star.on svg { fill: var(--bg); }
.addbtn {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border: none;
  border-radius: 12px;
  background: var(--orange);
  color: var(--bg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.addbtn svg { stroke-width: 3; }
.link { font-size: 14px; font-weight: 600; padding: 10px 0; }
.textlink {
  align-self: center;
  background: none;
  border: none;
  color: var(--lime);
  font-weight: 600;
  font-size: 14px;
  text-decoration: underline;
  min-height: 44px;
  padding: 0 4px;
  display: inline-flex;
  align-items: center;
}
.back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  align-self: flex-start;
  min-height: 44px;
  margin-bottom: -6px;
  color: var(--text);
  font-weight: 600;
  font-size: 15px;
  text-decoration: none;
}

/* list rows */
.item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
  color: var(--text);
  text-decoration: none;
  min-height: 44px;
}
.name { font-weight: 600; font-size: 16px; overflow-wrap: anywhere; }
.meta { margin-top: 6px; }
.item.meal .ic.muted { color: var(--muted); flex-shrink: 0; }

.check {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 999px;
  border: 2px solid #4A505B;
  background: transparent;
  color: var(--bg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background-color .15s ease, border-color .15s ease;
}
.check svg { opacity: 0; stroke-width: 3.2; }
.check.done { background: var(--lime); border-color: var(--lime); }
.check.done svg { opacity: 1; }
.check:active { transform: scale(.94); }
.check.busy { opacity: .6; }
.streak { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.flame { fill: var(--orange); stroke: var(--orange); stroke-width: 1.6; }

.pill {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--line);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}
.pill.lime { background: var(--lime); color: var(--bg); }
.pill.outline { background: transparent; border: 1px solid var(--edge); color: var(--muted); padding: 3px 8px; letter-spacing: 0.1em; }

/* forms */
.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.field input, .timeinput {
  width: 100%;
  min-width: 0;
  min-height: 52px;
  padding: 0 14px;
  border: 1.5px solid var(--edge);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font-size: 17px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
}
.field input:focus, .timeinput:focus, .searchbox:focus-within { outline: none; border-color: var(--lime); }
.bignum { font-family: var(--cond) !important; font-size: 28px !important; font-weight: 700 !important; min-height: 56px !important; }
.bignum.orange { color: var(--orange); }
.bignum.blue { color: var(--blue); }
.unit { width: 52px; flex-shrink: 0; font-size: 13px; color: var(--muted); letter-spacing: 0; text-transform: none; font-weight: 500; }
.timeinput { width: auto; min-height: 48px; font-family: var(--cond); font-size: 22px; font-weight: 700; }
.alert {
  margin: 0;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1.5px solid var(--orange);
  color: var(--text);
  font-size: 15px;
  letter-spacing: 0;
  text-transform: none;
  font-weight: 500;
}

.savetoggle {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  position: relative;
}
.savetoggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.savetoggle .box {
  width: 30px;
  height: 30px;
  border: 1.5px solid #4A505B;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}
.savetoggle input:checked + .box { background: var(--lime); border-color: var(--lime); color: var(--bg); }
.savetoggle input:checked + .box svg { fill: var(--bg); }
.savetoggle input:focus-visible + .box { outline: 2px solid var(--lime); outline-offset: 2px; }

/* tabs */
.tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; padding: 4px; background: var(--card); border-radius: 14px; }
.tabs button {
  min-height: 44px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.tabs button[aria-selected="true"] { background: var(--lime); color: var(--bg); }

/* search */
.searchbox {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 54px;
  padding: 0 14px;
  background: var(--card);
  border: 1.5px solid transparent;
  border-radius: 14px;
}
.searchbox input { flex: 1; min-width: 0; min-height: 44px; border: none; background: transparent; font-size: 17px; font-weight: 500; outline: none; -webkit-appearance: none; }
.scanbtn {
  width: 54px;
  height: 54px;
  flex-shrink: 0;
  border-radius: 14px;
  background: var(--lime);
  color: var(--bg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.status { margin: -4px 0 0; }
.result { background: var(--card); border: 1.5px solid transparent; border-radius: 22px; overflow: hidden; }
.result.open { border-color: var(--edge); }
.result > button {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: transparent;
  border: none;
  text-align: left;
  color: var(--text);
}
.result .more { border-top: 1px solid var(--line); padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 12px; }
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper .iconbtn { color: var(--text); }
.stepper .num { min-width: 44px; text-align: center; }

/* habits form */
.days { border: 0; margin: 0; padding: 0; min-width: 0; }
.days legend { padding: 0; margin-bottom: 10px; }
.daygrid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px; }
.daychip { position: relative; cursor: pointer; }
.daychip input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.daychip span[aria-hidden] {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border: 1.5px solid var(--edge);
  border-radius: 10px;
  color: var(--muted);
  font-weight: 700;
  font-size: 14px;
}
.daychip input:checked + span { background: var(--lime); border-color: var(--lime); color: var(--bg); }
.daychip input:focus-visible + span { outline: 2px solid var(--lime); outline-offset: 2px; }

/* switch */
.switch {
  width: 60px;
  height: 36px;
  flex-shrink: 0;
  border: none;
  border-radius: 999px;
  background: var(--line);
  padding: 4px;
  display: flex;
  justify-content: flex-start;
  transition: background-color .2s ease;
}
.switch span { width: 28px; height: 28px; border-radius: 999px; background: var(--muted); transition: transform .2s ease, background-color .2s ease; }
.switch[aria-checked="true"] { background: var(--lime); }
.switch[aria-checked="true"] span { transform: translateX(24px); background: var(--bg); }

.install { border: 1.5px solid var(--lime); }
.tile { width: 44px; height: 44px; flex-shrink: 0; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; }
.steps { margin: 0; padding-left: 22px; font-size: 15px; line-height: 1.6; }

/* history */
.day { border: 1.5px solid transparent; overflow: hidden; }
.day[open] { border-color: var(--edge); }
.day summary { list-style: none; cursor: pointer; padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; }
.day summary::-webkit-details-marker { display: none; }
.dayname { font-family: var(--cond); font-weight: 700; font-size: 22px; text-transform: uppercase; }
.stat { display: flex; flex-direction: column; gap: 6px; }
.daydetail { border-top: 1px solid var(--line); padding: 12px 16px 14px; display: flex; flex-direction: column; gap: 14px; }
.daydetail .lbl { margin-bottom: 4px; }
.line { padding: 5px 0; font-size: 14px; gap: 10px; }
.dot {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  border-radius: 999px;
  border: 1.5px solid #4A505B;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--bg);
}
.dot svg { stroke-width: 3.6; }
.dot.done { background: var(--lime); border-color: var(--lime); }
.dot.off { border-color: var(--line); }

/* scan */
body[data-page="scan"] .wrap { padding-left: 0; padding-right: 0; padding-bottom: 0; min-height: 100vh; min-height: 100dvh; }
.scan { display: flex; flex-direction: column; gap: 16px; min-height: calc(100dvh - 24px - env(safe-area-inset-top, 0px)); }
.scanbar { padding: 0 18px; }
.spacer { width: 44px; }
.viewfinder { position: relative; margin: 0 18px; height: 300px; border-radius: 22px; overflow: hidden; background: #000; }
#reader, #reader > div { width: 100%; height: 100%; }
#reader video { width: 100% !important; height: 100% !important; object-fit: cover; }
#reader img, #reader #qr-shaded-region, #reader__dashboard, #reader__header_message { display: none !important; }
#reader { border: none !important; }
.frame { position: absolute; left: 50%; top: 50%; width: 280px; height: 170px; transform: translate(-50%, -50%); pointer-events: none; }
.frame i { position: absolute; width: 40px; height: 40px; border: 4px solid var(--lime); }
.frame i:nth-child(1) { left: 0; top: 0; border-right: 0; border-bottom: 0; border-top-left-radius: 14px; }
.frame i:nth-child(2) { right: 0; top: 0; border-left: 0; border-bottom: 0; border-top-right-radius: 14px; }
.frame i:nth-child(3) { left: 0; bottom: 0; border-right: 0; border-top: 0; border-bottom-left-radius: 14px; }
.frame i:nth-child(4) { right: 0; bottom: 0; border-left: 0; border-top: 0; border-bottom-right-radius: 14px; }
.frame b { position: absolute; left: 22px; right: 22px; top: 83px; height: 3px; border-radius: 3px; background: var(--orange); }
.sheet {
  margin-top: auto;
  background: var(--card);
  border-radius: 28px 28px 0 0;
  padding: 22px 20px calc(env(safe-area-inset-bottom, 0px) + 22px);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.foundname { margin: 8px 0 0; font-family: var(--cond); font-weight: 700; font-size: 24px; line-height: 1.1; text-transform: uppercase; }

/* sign in */
.signin { display: flex; flex-direction: column; gap: 20px; padding-top: 12vh; }

/* nav */
.nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  padding: 8px 4px calc(env(safe-area-inset-bottom, 0px) + 8px);
  background: #15171B;
  border-top: 1px solid var(--line);
}
.nav a {
  flex: 1;
  max-width: 96px;
  min-height: 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-decoration: none;
}
.nav a.on { color: var(--lime); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
.scanstatus { margin: 0; padding: 0 18px; }
