/* ==========================================================================
   Self-hosted faces. Google's CDN is fast but an installed PWA has to render
   correctly with no network at all, and cross-origin font files are outside
   the service worker's cache. latin-ext carries ą č ę ė į š ų ū ž, so
   Lithuanian product names set properly.
   ========================================================================== */

@font-face {
  font-family: "Anton";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/anton-400-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "Anton";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/anton-400-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Nunito";
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url("/fonts/nunito-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "Nunito";
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url("/fonts/nunito-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ==========================================================================
   Portio — "Arcade" design system
   Fat outlines, hard offset shadows, three signal colours and nothing else.
   The three macro colours are the app's entire palette: lime is protein,
   pink is carbs, cyan is fat. Every other surface is ink or paper-on-ink, so
   a coloured pixel always means something.
   ========================================================================== */

:root {
  --ink: #0C0A14;
  --bg: #1A1628;
  --surface: #241E38;
  --surface-2: #2E2647;
  --line: #3A3158;

  --lime: #C4F63C;   /* protein, and the primary readout */
  --pink: #FF5FA2;   /* carbs, and streaks */
  --cyan: #4ED9FF;   /* fat, and anything you can press */
  --warn: #FFB84D;   /* over budget — the only non-macro colour */

  --text: #FFFFFF;
  --muted: #B7AEE4;
  --dim: #8A7EC0;

  --r: 14px;
  --r-sm: 10px;
  --outline: 3px solid var(--ink);
  --drop: 5px 5px 0 var(--ink);
  --drop-sm: 3px 3px 0 var(--ink);

  --display: "Anton", "Arial Narrow", sans-serif;
  --sans: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;

  --shell: 460px;
  --tabbar: 76px;
}

* { box-sizing: border-box; }

html {
  /* Stops iOS enlarging body text on rotation, which reflows the whole diary. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* manipulation opts the whole document out of double-tap-to-zoom. This is an
     app, not a document: a stray double tap zooming the diary makes it unusable
     one-handed, which is the only way it is ever held. */
  touch-action: manipulation;
}

html, body {
  margin: 0;
  background: var(--ink);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
  overscroll-behavior-y: none;
}

body { min-height: 100dvh; }

button, input, select { font: inherit; color: inherit; }

/* manipulation opts out of double-tap-to-zoom on controls, which also removes
   the 300ms tap delay that made the meal buttons feel sticky. */
button, .tab, .chip, .result, .item .del {
  cursor: pointer;
  touch-action: manipulation;
}

:focus-visible {
  outline: 3px solid var(--cyan);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- shell ---------- */

.shell {
  max-width: var(--shell);
  margin: 0 auto;
  min-height: 100dvh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: 0 0 0 1px var(--line);
}

.view {
  flex: 1;
  padding: 14px 16px calc(var(--tabbar) + 24px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.view[hidden] { display: none !important; }

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: max(8px, env(safe-area-inset-top));
}

.topbar .title {
  font-family: var(--display);
  font-size: 26px;
  letter-spacing: 0.01em;
  line-height: 1;
  text-transform: uppercase;
}

.topbar .sub {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--dim);
  margin-top: 3px;
}

.iconbtn {
  width: 44px;
  height: 44px;
  flex: none;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: var(--outline);
  border-radius: var(--r-sm);
  box-shadow: var(--drop-sm);
  color: var(--text);
  font-size: 20px;
  line-height: 1;
  padding: 0;
}

.iconbtn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }

/* ---------- cards ---------- */

.card {
  background: var(--surface);
  border: var(--outline);
  border-radius: var(--r);
  box-shadow: var(--drop);
  padding: 14px;
}

.card.flat { box-shadow: none; }

.hero {
  background: var(--lime);
  color: var(--ink);
  padding: 16px 18px 18px;
}

.hero .k {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.hero .n {
  font-family: var(--display);
  font-size: clamp(58px, 19vw, 78px);
  line-height: 0.84;
  letter-spacing: -0.01em;
  margin-top: 4px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.hero .n small {
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.hero.over { background: var(--warn); }

.hero .math {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.02em;
  margin-top: 10px;
  opacity: 0.72;
}

.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }

.tile { padding: 11px 12px; color: var(--ink); }
.tile .k {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.tile .n {
  font-family: var(--display);
  font-size: 27px;
  line-height: 1;
  margin-top: 2px;
}
.tile.pink { background: var(--pink); }
.tile.cyan { background: var(--cyan); }

/* ---------- macro meters ---------- */

.meters { display: flex; flex-direction: column; gap: 10px; }

.meter {
  display: grid;
  grid-template-columns: 34px 1fr 58px;
  gap: 9px;
  align-items: center;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.segs { display: flex; gap: 3px; }

.segs i {
  flex: 1;
  height: 13px;
  border-radius: 2px;
  background: var(--line);
  display: block;
}

.meter .rd {
  text-align: right;
  font-size: 12px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: 0;
}
.meter .rd b { font-weight: 800; }
.meter .rd span { color: var(--dim); font-weight: 600; }

/* ---------- chips ---------- */

.chips { display: flex; flex-wrap: wrap; gap: 7px; }

.chip {
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: 22px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 800;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.chip .kc { color: var(--dim); font-weight: 700; }
.chip.on { background: var(--lime); color: var(--ink); }
.chip.on .kc { color: rgba(12, 10, 20, 0.6); }

.chip.open {
  background: transparent;
  border-style: dashed;
  border-color: var(--cyan);
  color: var(--cyan);
}

/* ---------- buttons ---------- */

.btn {
  background: var(--cyan);
  color: var(--ink);
  border: var(--outline);
  border-radius: var(--r);
  box-shadow: var(--drop);
  font-family: var(--display);
  font-size: 19px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 14px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
}

.btn small {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  opacity: 0.65;
  text-transform: none;
}

.btn:active { transform: translate(2px, 2px); box-shadow: 3px 3px 0 var(--ink); }
.btn.lime { background: var(--lime); }
.btn.pink { background: var(--pink); }
.btn.ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--line);
  box-shadow: none;
  font-family: var(--sans);
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.02em;
  text-transform: none;
}
.btn[disabled] { opacity: 0.4; pointer-events: none; }

/* ---------- meal list ---------- */

.meal {
  background: var(--surface);
  border: var(--outline);
  border-radius: var(--r);
  box-shadow: var(--drop);
  overflow: hidden;
}

.meal + .meal { margin-top: 10px; }

.mealhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 13px;
  background: var(--surface-2);
}

.mealhead .nm {
  font-family: var(--display);
  font-size: 16px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.mealhead .kc {
  font-size: 13px;
  font-weight: 800;
  color: var(--lime);
}
.mealhead .kc.none { color: var(--dim); }

.items { display: flex; flex-direction: column; }

.item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 13px;
  border-top: 2px solid var(--ink);
  font-size: 13px;
}

.item .nm { flex: 1; min-width: 0; font-weight: 700; }
.item .nm em {
  display: block;
  font-style: normal;
  font-size: 11px;
  font-weight: 600;
  color: var(--dim);
}
.item .kc { font-weight: 800; font-size: 13px; }

.item .del {
  background: none;
  border: 0;
  color: var(--dim);
  font-size: 20px;
  line-height: 1;
  padding: 4px 2px;
  min-width: 28px;
}
.item .del:hover { color: var(--pink); }

.addmeal {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  background: none;
  border: 0;
  border-top: 2px dashed var(--line);
  color: var(--cyan);
  font-weight: 800;
  font-size: 13px;
  padding: 11px;
}

/* ---------- search ---------- */

.searchbar {
  display: flex;
  gap: 9px;
  align-items: center;
  background: var(--surface);
  border: var(--outline);
  border-radius: var(--r);
  box-shadow: var(--drop);
  padding: 4px 4px 4px 14px;
}

.searchbar input {
  flex: 1;
  min-width: 0;
  background: none;
  border: 0;
  padding: 12px 0;
  /* 16px minimum: iOS Safari zooms the page in on any focused field below it. */
  font-size: 16px;
  font-weight: 700;
}
.searchbar input::placeholder { color: var(--dim); font-weight: 600; }
.searchbar input:focus { outline: none; }

.searchbar .go {
  background: var(--lime);
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: var(--r-sm);
  font-family: var(--display);
  font-size: 15px;
  letter-spacing: 0.04em;
  padding: 10px 14px;
  text-transform: uppercase;
}

.result {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: var(--outline);
  border-radius: var(--r);
  box-shadow: var(--drop-sm);
  padding: 11px 13px;
}

.result:active { transform: translate(2px, 2px); box-shadow: none; }

.result .meta { flex: 1; min-width: 0; }
.result .t {
  font-weight: 800;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.result .s {
  font-size: 11px;
  font-weight: 600;
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.result .e { text-align: right; flex: none; }
.result .e b { font-family: var(--display); font-size: 19px; line-height: 1; }
.result .e span {
  display: block;
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--dim);
}

.badge {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--line);
  color: var(--muted);
  flex: none;
}
.badge.generic { background: var(--cyan); color: var(--ink); }
.badge.mine { background: var(--pink); color: var(--ink); }

/* ---------- forms ---------- */

.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 13px;
  background: var(--surface);
  border: var(--outline);
  border-radius: var(--r-sm);
}

.field + .field { margin-top: 8px; }
.field label { font-size: 13px; font-weight: 800; color: var(--muted); }

.field input,
.field select {
  background: var(--bg);
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 8px 10px;
  /* Same rule as the search field — never below 16px on a focusable control. */
  font-size: 16px;
  font-weight: 800;
  text-align: right;
  width: 130px;
  max-width: 50%;
}
.field select { text-align: left; }
.field input:focus, .field select:focus { outline: 2px solid var(--cyan); outline-offset: 1px; }

.stepper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  border: var(--outline);
  border-radius: var(--r);
  box-shadow: var(--drop);
  padding: 10px 12px;
}

.stepper button {
  width: 48px;
  height: 48px;
  flex: none;
  background: var(--cyan);
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: var(--r-sm);
  font-family: var(--display);
  font-size: 26px;
  line-height: 1;
  padding: 0;
}
.stepper button:active { transform: translate(2px, 2px); }

.stepper .amt { text-align: center; flex: 1; }
.stepper .amt input {
  background: none;
  border: 0;
  font-family: var(--display);
  font-size: 30px;
  text-align: center;
  width: 100%;
  letter-spacing: 0.01em;
}
.stepper .amt input:focus { outline: none; }
.stepper .amt .u {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--dim);
}

/* ---------- nutrition table ---------- */

.nutri { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.nutri caption {
  text-align: left;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--dim);
  padding-bottom: 8px;
}
.nutri th, .nutri td { padding: 7px 0; border-bottom: 2px solid var(--line); text-align: right; }
.nutri th { text-align: left; font-weight: 700; color: var(--muted); }
.nutri thead th {
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--dim);
  font-weight: 800;
}
.nutri .sub th { padding-left: 14px; color: var(--dim); font-weight: 600; }
.nutri td { font-weight: 800; }
.nutri tr:last-child th, .nutri tr:last-child td { border-bottom: 0; }

/* ---------- scanner ---------- */

.cam {
  position: relative;
  border: var(--outline);
  border-radius: var(--r);
  box-shadow: var(--drop);
  overflow: hidden;
  background: var(--ink);
  aspect-ratio: 3 / 4;
  max-height: 46dvh;
}

.cam video { width: 100%; height: 100%; object-fit: cover; display: block; }

.reticle {
  position: absolute;
  left: 9%;
  right: 9%;
  top: 32%;
  height: 26%;
  border: 3px solid var(--lime);
  border-radius: 8px;
  box-shadow: 0 0 0 2000px rgba(12, 10, 20, 0.45);
}

.camnote {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 10px;
  text-align: center;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--lime);
  text-shadow: 0 1px 4px var(--ink);
}

/* ---------- charts ---------- */

.chart { width: 100%; height: auto; display: block; overflow: visible; }

.panelhead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.panelhead .k {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--dim);
}
.panelhead .v { font-family: var(--display); font-size: 24px; line-height: 1; }
.panelhead .d { font-size: 12px; font-weight: 800; color: var(--lime); }
.panelhead .d.up { color: var(--pink); }

/* ---------- tab bar ---------- */

.tabbar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--shell);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: center;
  background: var(--surface);
  border-top: 3px solid var(--ink);
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
  z-index: 20;
}

.tab {
  background: none;
  border: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--dim);
  padding: 4px 0;
  min-height: 44px;
  justify-content: center;
}

.tab svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tab.on { color: var(--lime); }

.tab.primary { color: var(--ink); }
.tab.primary .puck {
  width: 50px;
  height: 46px;
  border-radius: 13px;
  background: var(--cyan);
  border: 3px solid var(--ink);
  box-shadow: var(--drop-sm);
  display: grid;
  place-items: center;
}
.tab.primary .puck svg { stroke: var(--ink); width: 23px; height: 23px; }

/* ---------- misc ---------- */

.note {
  font-size: 12px;
  font-weight: 600;
  color: var(--dim);
  line-height: 1.6;
}
.note b { color: var(--muted); font-weight: 800; }

.empty {
  text-align: center;
  padding: 26px 14px;
  color: var(--dim);
  font-weight: 700;
  font-size: 13px;
}

.demo {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--pink);
  color: var(--ink);
  border: var(--outline);
  border-radius: var(--r-sm);
  box-shadow: var(--drop-sm);
  padding: 9px 12px;
  font-size: 12px;
  font-weight: 800;
}
.demo button {
  margin-left: auto;
  background: var(--ink);
  color: var(--pink);
  border: 0;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar) + 16px);
  transform: translateX(-50%);
  background: var(--lime);
  color: var(--ink);
  border: var(--outline);
  border-radius: var(--r-sm);
  box-shadow: var(--drop);
  padding: 11px 16px;
  font-weight: 800;
  font-size: 13px;
  z-index: 40;
  max-width: calc(var(--shell) - 32px);
  text-align: center;
}
.toast[hidden] { display: none; }

.spinner {
  width: 20px;
  height: 20px;
  border: 3px solid var(--line);
  border-top-color: var(--lime);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 20px auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
  .spinner { animation: none; border-top-color: var(--lime); }
}

@media (max-width: 360px) {
  .view { padding-inline: 12px; }
  .meter { grid-template-columns: 30px 1fr 52px; }
}
