/* Tabulated — base stylesheet.
 * Theme tokens live HERE and only here: one light block (:root) and one dark
 * @media block. Any token added to one MUST be added to the other (house rule);
 * mirror changes into docs/style-guide.md in the same commit.
 *
 * The palette is exactly three colors (docs/design/iOS.png is the source
 * comp): paper, ink, and red. Dark mode is a strict paper<->ink swap done via
 * the --bg/--fg pair; --red never changes. Everything on a red surface derives
 * from the same pair: structural text (wordmark, icons, labels) uses --bg,
 * data values use --fg, buttons are --fg fills with --bg text. */

@font-face {
  font-family: "Bungee";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/bungee.woff2") format("woff2");
}

@font-face {
  font-family: "Hack";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/hack-regular.woff2") format("woff2");
}

@font-face {
  font-family: "Hack";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("../fonts/hack-bold.woff2") format("woff2");
}

:root {
  /* palette constants — never redefined per mode */
  --paper: #e6e3d7;
  --ink: #272725;
  --red: #d24f3e;

  /* mode pair — light */
  --bg: var(--paper);
  --fg: var(--ink);

  /* type */
  --font-display: "Bungee", "Arial Black", system-ui, sans-serif;
  --font-data: "Hack", ui-monospace, "SF Mono", Menlo, monospace;
  --fs-data: 0.875rem; /* 14px — every table/data cell */
  --fs-label: 1.125rem; /* 18px — wordmark, settings labels */
  --fs-caption: 0.75rem; /* 12px — footer, hints, squeezed cells */

  /* poster design unit: 1px of the 402x874 comp, scaled to fit the viewport */
  --u: min(0.2488vw, 0.1144dvh);
}

@media (prefers-color-scheme: dark) {
  :root {
    /* mode pair — dark (keep pair-for-pair in sync with the light block) */
    --bg: var(--ink);
    --fg: var(--paper);
  }
}

* {
  box-sizing: border-box;
}

/* SVG elements don't honor the HTML `hidden` attribute — hide the sprite explicitly */
svg[hidden] {
  display: none;
}

html {
  color-scheme: light dark;
}

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-data);
  font-size: var(--fs-data);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--red);
}

:focus-visible {
  outline: 3px solid var(--red);
  outline-offset: 2px;
}

.icon {
  width: 1.25em;
  height: 1.25em;
  fill: currentColor;
  vertical-align: -0.25em;
}

/* numeric table cells opt in to tabular figures */
.num {
  font-variant-numeric: tabular-nums;
}

/* ---- intro poster (the empty state) --------------------------------------
 * A fixed-aspect frame reproducing the 402x874 comp; every position and font
 * size is in --u so the whole composition scales together on any screen. */

.poster {
  position: relative;
  flex: 1;
  min-height: 100dvh;
  background: var(--bg);
}

.poster > * {
  position: absolute;
}

/* the X: two red wedges meeting at (50%, 49%) of the frame */
.poster-x {
  inset: 0;
  margin: auto;
  width: calc(402 * var(--u));
  height: calc(874 * var(--u));
}

.poster-x::before,
.poster-x::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--red);
}

.poster-x::before {
  clip-path: polygon(0% 22%, 50% 49%, 0% 76%);
}

.poster-x::after {
  clip-path: polygon(100% 22%, 50% 49%, 100% 76%);
}

/* frame-relative placement: the frame is centered, so anchor each child to
 * the viewport center and offset by comp coordinates (origin 201,437) */
.poster-barcode {
  top: calc(50% + (56 - 437) * var(--u));
  left: 50%;
  transform: translateX(-50%);
  width: calc(254 * var(--u));
  height: calc(50 * var(--u));
  fill: var(--fg);
}

.hero {
  top: calc(50% + (104 - 437) * var(--u));
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  width: calc(402 * var(--u));
  text-align: center;
  font-family: var(--font-display);
  font-weight: 400;
  color: var(--fg);
  line-height: 1.05;
}

.hero span {
  display: block;
}

.hero-big {
  font-size: calc(96 * var(--u));
  line-height: 0.95;
}

.hero-line {
  font-size: calc(32 * var(--u));
}

.poster-bottle {
  top: calc(50% + (280 - 437) * var(--u));
  left: 50%;
  transform: translateX(-50%);
  width: auto;
  height: calc(110 * var(--u));
}

.aside-note {
  top: calc(50% + (428 - 437) * var(--u));
  transform: translateY(-50%);
  margin: 0;
  width: calc(120 * var(--u));
  text-align: center;
  font-family: var(--font-display);
  font-size: calc(21 * var(--u));
  line-height: 1.3;
  color: var(--bg);
}

.aside-left {
  left: calc(50% - 185 * var(--u));
}

.aside-right {
  left: calc(50% + 85 * var(--u));
  width: calc(80 * var(--u));
}

.pitch {
  top: calc(50% + (549 - 437) * var(--u));
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  width: calc(402 * var(--u));
  text-align: center;
  font-family: var(--font-display);
  color: var(--fg);
  line-height: 1.2;
}

.pitch span {
  display: block;
}

.pitch-line {
  font-size: calc(24 * var(--u));
}

.pitch-big {
  font-size: calc(44 * var(--u));
  line-height: 1.1;
}

.pitch-plus {
  font-size: calc(22 * var(--u));
  line-height: 0.9;
}

.btn-scan {
  top: calc(50% + (769 - 437) * var(--u));
  left: 50%;
  transform: translateX(-50%);
  width: calc(276 * var(--u));
  padding: calc(14 * var(--u)) 0;
  border: none;
  border-radius: calc(14 * var(--u));
  background: var(--fg);
  color: var(--bg);
  font-family: var(--font-display);
  font-size: calc(24 * var(--u));
  cursor: pointer;
  transition: filter 120ms ease;
}

.btn-scan:disabled {
  cursor: not-allowed;
}

.btn-scan:not(:disabled):hover {
  filter: brightness(1.15);
}

/* Account entry on the poster: sign-in (and the shared-device "clear this
 * device" control) must be reachable with an EMPTY stack — the app chrome
 * only exists once a product is added, and gating auth behind owning a
 * product locks new users out entirely. Same comp coordinate system as the
 * scan button, sitting just below it. */
.poster-account {
  top: calc(50% + (833 - 437) * var(--u));
  left: 50%;
  transform: translateX(-50%);
  border: none;
  background: none;
  padding: calc(4 * var(--u));
  color: var(--fg);
  font-family: var(--font-display);
  font-size: calc(14 * var(--u));
  text-decoration: underline;
  cursor: pointer;
}

.site-footer {
  padding: 1rem 1.5rem;
  border-top: 2px solid var(--fg);
  font-size: var(--fs-caption);
  text-align: center;
}

.site-footer p {
  margin: 0.25rem 0;
}

/* ---- app views (table / scanner / card / search / stack) ----------------- */

/* view switching is driven by the hidden attribute; nothing may override it */
[hidden] {
  display: none !important;
}

/* visually hidden, exposed to screen readers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Full-width flex column so the red chrome bars bleed edge-to-edge; each view
 * section keeps the centered content column. */
#app {
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
}

#app > section {
  width: min(28rem, 100%);
  margin: 0 auto;
  padding: 1.5rem 1.25rem;
}

/* ---- red app chrome (comp: table/settings views; red in BOTH modes) ------ */

#app-chrome {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--red);
  padding: 0.9rem 1.25rem;
  padding-top: max(0.9rem, env(safe-area-inset-top));
}

#chrome-home {
  border: none;
  background: none;
  padding: 0;
  color: var(--bg);
  font-family: var(--font-display);
  font-size: var(--fs-label);
  cursor: pointer;
}

#chrome-stack {
  border: none;
  background: none;
  padding: 0.25rem;
  color: var(--bg);
  cursor: pointer;
}

#chrome-stack .icon {
  width: 1.5em;
  height: 1.5em;
}

#action-bar {
  margin-top: auto;
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 1rem;
  justify-content: center;
  background: var(--red);
  padding: 0.9rem 1.25rem;
  padding-bottom: max(0.9rem, env(safe-area-inset-bottom));
}

.btn-bar {
  flex: 1;
  max-width: 12rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6em;
  padding: 0.8em 1em;
  border: none;
  border-radius: 999px;
  background: var(--fg);
  color: var(--bg);
  font-family: var(--font-display);
  font-size: var(--fs-data);
  cursor: pointer;
  transition: filter 120ms ease;
}

.btn-bar:not(:disabled):hover {
  filter: brightness(1.15);
}

/* barcode marks flanking the SCAN label (comp) */
.scan-bars {
  width: 1.1em;
  height: 0.9em;
  background: repeating-linear-gradient(90deg, currentColor 0 2px, transparent 2px 4px);
}

/* ---- nutrient table (comp: NUTRIENT / TOTAL / TARGET) -------------------- */

.nutrient-table {
  width: 100%;
  /* fixed layout: column widths hold no matter how long a name or total
   * gets, so the table can never push past the phone viewport */
  table-layout: fixed;
  border-collapse: collapse;
  font-size: var(--fs-data);
}

.nutrient-table th:nth-child(2) {
  width: 36%;
}

.nutrient-table th:nth-child(3) {
  width: 26%;
}

.nutrient-table th {
  font-family: var(--font-display);
  font-weight: 400;
  text-align: left;
  padding: 0 0 0.4rem;
  border-bottom: 1px solid var(--fg);
}

.nutrient-table td {
  padding: 0.6rem 0 0;
  vertical-align: baseline;
  /* break-word, not anywhere: "Riboflavin" wraps whole, never "Riboflavi/n" */
  overflow-wrap: break-word;
}

.nutrient-table .cell-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  padding-left: 0.75rem;
}

/* headers stay on one line; data cells may wrap between number and unit on
 * the narrowest screens rather than overflow the fixed column */
.nutrient-table th.cell-num {
  white-space: nowrap;
}

#table-unquantified {
  margin-top: 2rem;
}

#table-unquantified h3 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: var(--fs-data);
}

.unquantified-list {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
}

.unquantified-list li {
  padding: 0.35rem 0;
  overflow-wrap: anywhere;
}

.unquantified-product {
  opacity: 0.7;
  font-size: var(--fs-caption);
}

.table-note {
  margin-top: 1.5rem;
  font-size: var(--fs-caption);
}

/* UL-exceeded rows: red does double duty (ruled 2026-08-09); treatment B —
 * only the target cell goes red (ruled 2026-08-13) — same red in both
 * modes, and the flag is also stated in text, never color alone */
.ul-exceeded td:last-child {
  color: var(--red);
}

.ul-flag {
  display: block;
  font-family: var(--font-display);
  font-size: var(--fs-caption);
  line-height: 1.4;
}

.ul-note {
  color: var(--red);
}

#app h2 {
  margin: 0 0 1rem;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.5rem;
}

.muted {
  opacity: 0.7;
}

.view-status {
  font-size: var(--fs-data);
  margin: 0.75rem 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  padding: 0.7em 1.4em;
  border: none;
  border-radius: 999px;
  background: var(--fg);
  color: var(--bg);
  font-family: var(--font-display);
  font-size: var(--fs-data);
  cursor: pointer;
  transition: filter 120ms ease;
}

.btn:not(:disabled):hover {
  filter: brightness(1.15);
}

.btn-quiet {
  background: transparent;
  color: var(--fg);
  border: 2px solid var(--fg);
  margin-top: 1.25rem;
}

.video-wrap {
  position: relative;
  aspect-ratio: 4 / 3;
  background: var(--ink);
  border: 2px solid var(--fg);
  overflow: hidden;
}

.video-wrap video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.reticle {
  position: absolute;
  inset: 30% 12%;
  border: 2px dashed var(--red);
}

.manual-entry {
  margin-top: 1.25rem;
}

.manual-entry label {
  display: block;
  font-size: var(--fs-caption);
  margin-bottom: 0.5rem;
  opacity: 0.7;
}

.manual-row {
  display: flex;
  gap: 0.5rem;
}

.manual-row input {
  flex: 1;
  min-width: 0;
  padding: 0.55em 0.7em;
  border: 2px solid var(--fg);
  border-radius: 0;
  background: transparent;
  color: var(--fg);
  font-family: var(--font-data);
  font-size: var(--fs-data);
}

.product-card {
  border: 2px solid var(--fg);
  padding: 1.5rem 1.25rem;
  text-align: center;
}

.card-thumb {
  width: auto;
  height: 5.5rem;
}

.product-card h3 {
  margin: 0.75rem 0 0.25rem;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.3rem;
}

.product-card p {
  margin: 0.25rem 0;
  font-size: var(--fs-data);
}

.stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 1.25rem;
}

.stepper button {
  width: 2.4rem;
  height: 2.4rem;
  border: none;
  border-radius: 999px;
  background: var(--fg);
  color: var(--bg);
  font-family: var(--font-display);
  font-size: 1.1rem;
  cursor: pointer;
}

.stepper output {
  font-family: var(--font-data);
  font-size: 1.3rem;
  min-width: 2ch;
  text-align: center;
}

.stepper-label {
  font-size: var(--fs-caption);
  opacity: 0.7;
}

.product-card .btn-primary {
  margin-top: 1rem;
  width: 100%;
}

#card-versions {
  margin-top: 1.25rem;
  text-align: left;
}

#card-versions summary {
  font-family: var(--font-display);
  font-size: var(--fs-caption);
  color: var(--red);
  cursor: pointer;
}

.pick-list {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
}

.pick-list li {
  margin-bottom: 0.5rem;
}

.pick-list button {
  width: 100%;
  text-align: left;
  padding: 0.6em 0.8em;
  border: 2px solid var(--fg);
  background: transparent;
  color: var(--fg);
  font-family: var(--font-data);
  font-size: var(--fs-data);
  cursor: pointer;
}

.pick-list button:hover {
  background: var(--fg);
  color: var(--bg);
}

#stack-list {
  list-style: none;
  margin: 1rem 0 1.5rem;
  padding: 0;
  border-top: 2px solid var(--fg);
}

.stack-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0;
  border-bottom: 2px solid var(--fg);
}

.stack-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.stack-name {
  font-size: var(--fs-data);
  overflow-wrap: anywhere;
}

.stack-brand {
  font-size: var(--fs-caption);
  opacity: 0.7;
}

.stepper-inline {
  margin-top: 0;
  gap: 0.5rem;
}

.stepper-inline button {
  width: 1.8rem;
  height: 1.8rem;
  font-size: 0.9rem;
}

.stepper-inline output {
  font-size: var(--fs-data);
}

.stack-remove {
  border: none;
  background: transparent;
  color: var(--red);
  font-size: 1rem;
  cursor: pointer;
  padding: 0.4rem;
}

/* ---- account view (phase 3) ------------------------------------------------
 * All colors come from the shared tokens, so light and dark stay in sync by
 * construction. */

.chrome-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

#chrome-account {
  border: none;
  background: none;
  padding: 0.25rem;
  color: var(--bg);
  cursor: pointer;
}

#chrome-account .icon {
  width: 1.5em;
  height: 1.5em;
}

/* inline text button (the profile nudge) — a real <button> for a11y, styled
 * as a link so the sentence reads naturally */
.link-btn {
  border: none;
  background: none;
  padding: 0;
  color: var(--red);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.account-blurb {
  font-size: var(--fs-data);
  margin: 0 0 1.25rem;
}

/* sign-in code disclosure (#61) — same summary idiom as the card's
 * "Wrong product?" toggle; tokens only, so both themes stay in sync */
.code-entry {
  margin: 1rem 0 1.5rem;
}

.code-entry summary {
  font-family: var(--font-display);
  font-size: var(--fs-caption);
  color: var(--red);
  cursor: pointer;
}

/* visual echo of the XXXX-XXXX mail formatting; the server uppercases and
 * strips separators anyway */
.code-entry input {
  text-transform: uppercase;
}

.account-subhead {
  margin: 2rem 0 0.5rem;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.2rem;
}

.account-floor-note {
  margin-top: 0;
}

.profile-form {
  margin-top: 1.25rem;
}

.profile-field {
  margin: 0 0 1.25rem;
  border: none;
  padding: 0;
}

.profile-field legend,
.profile-field label {
  display: block;
  font-size: var(--fs-data);
  margin-bottom: 0.4rem;
}

/* specificity ties the display:block label rule above — keep this one ahead */
.profile-field label.radio-label {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  margin-right: 1.5rem;
  margin-bottom: 0;
  cursor: pointer;
}

.profile-field input[type="radio"] {
  accent-color: var(--red);
  width: 1.1rem;
  height: 1.1rem;
}

.profile-field input[type="number"],
.profile-field select {
  width: 100%;
  max-width: 12rem;
  padding: 0.55em 0.7em;
  border: 2px solid var(--fg);
  border-radius: 0;
  background: transparent;
  color: var(--fg);
  font-family: var(--font-data);
  font-size: var(--fs-data);
}

/* House rule: decorative motion is suppressed under prefers-reduced-motion. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
