:root{
  --paper: #EEF0E2;
  --paper-deep: #E2E5D3;
  --card: #F7F8EF;
  --ink: #181811;
  --ink-soft: #57574A;
  --line: #C7C3AC;
  --line-strong: #181811;

  --green: #1F7A4D;
  --green-soft: #DCEBD8;
  --amber: #B9790A;
  --amber-soft: #F4E7CB;
  --red: #B83A2C;
  --red-soft: #F3DCD6;

  --display: "Big Shoulders Display", sans-serif;
  --body: "Inter", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;

  --radius: 2px;
  --max: 640px;
}

*{ box-sizing: border-box; }

@media (prefers-reduced-motion: reduce){
  *{ animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

html{ background: var(--paper-deep); }

body{
  margin: 0;
  font-family: var(--body);
  color: var(--ink);
  background: var(--paper);
  min-height: 100vh;
}

.sr-only{
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

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

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

/* ---------- Topbar ---------- */
.topbar{
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: var(--max);
  margin: 0 auto;
  padding: 20px 20px 0;
}

.brand{ display: flex; align-items: baseline; gap: 10px; }

.brand__mark{
  font-family: var(--mono);
  letter-spacing: -1px;
  font-size: 14px;
  color: var(--ink-soft);
}

.brand__name{
  font-family: var(--display);
  font-weight: 800;
  font-size: 22px;
  letter-spacing: 0.5px;
}

.brand__dot{ color: var(--green); }

/* ---------- Buttons ---------- */
.btn{
  font-family: var(--body);
  font-weight: 600;
  font-size: 14px;
  padding: 10px 16px;
  border-radius: var(--radius);
  border: 1.5px solid var(--ink);
  cursor: pointer;
  background: var(--card);
  color: var(--ink);
  transition: transform 0.1s ease, background 0.15s ease, color 0.15s ease;
}
.btn:hover{ transform: translateY(-1px); }
.btn:active{ transform: translateY(0); }
.btn--primary{ background: var(--ink); color: var(--paper); }
.btn--primary:hover{ background: var(--green); border-color: var(--green); }
.btn--ghost{ background: transparent; }
.btn--small{ padding: 8px 12px; font-size: 13px; }
.btn:disabled{ opacity: 0.45; cursor: not-allowed; transform: none; }

/* ---------- Hero / scan slot ---------- */
.hero{
  max-width: var(--max);
  margin: 0 auto;
  padding: 36px 20px 0;
  text-align: center;
}

.hero h1{
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(30px, 7vw, 46px);
  line-height: 1.02;
  letter-spacing: -0.5px;
  margin: 0 0 10px;
}

.hero__sub{
  color: var(--ink-soft);
  font-size: 15.5px;
  max-width: 46ch;
  margin: 0 auto 28px;
  line-height: 1.5;
}

.scan-slot{
  background: var(--card);
  border: 1.5px solid var(--ink);
  border-radius: var(--radius);
  padding: 18px 18px 22px;
}

.scan-slot__bars{ width: 100%; max-width: 220px; height: 30px; display: block; margin: 0 auto 16px; }

.scan-slot__controls{
  display: flex; gap: 8px; flex-wrap: wrap;
}

#barcodeInput{
  flex: 1; min-width: 160px;
  font-family: var(--mono);
  font-size: 16px;
  letter-spacing: 1px;
  padding: 12px 12px;
  border: 1.5px solid var(--ink);
  background: var(--paper);
  border-radius: var(--radius);
}

.scan-slot .btn--ghost{ margin-top: 10px; width: 100%; }
.scan-slot__hint{ font-size: 12.5px; color: var(--ink-soft); margin: 8px 0 0; }

.camera-wrap{
  margin-top: 14px;
  border: 1.5px solid var(--ink);
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  position: relative;
}
#cameraVideo{ width: 100%; display: block; max-height: 340px; object-fit: fill; background: #000; }
.camera-wrap .btn{ width: 100%; border-radius: 0; border-top: 1.5px solid var(--ink); border-left: none; border-right: none; border-bottom: none; }

/* Cadre de visée */
.camera-viewfinder{
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
/* Zone sombre autour du cadre */
.camera-viewfinder::before{
  content: '';
  position: absolute;
  inset: 0;
  background:
    linear-gradient(to bottom,
      rgba(0,0,0,.45) 0%,
      rgba(0,0,0,.45) calc(50% - 60px),
      transparent calc(50% - 60px),
      transparent calc(50% + 60px),
      rgba(0,0,0,.45) calc(50% + 60px),
      rgba(0,0,0,.45) 100%
    ),
    linear-gradient(to right,
      rgba(0,0,0,.45) 0%,
      rgba(0,0,0,.45) 6%,
      transparent 6%,
      transparent 94%,
      rgba(0,0,0,.45) 94%,
      rgba(0,0,0,.45) 100%
    );
}
/* Coins */
.vf-corner{
  position: absolute;
  width: 26px;
  height: 26px;
  border-color: #fff;
  border-style: solid;
  border-width: 0;
}
.vf-tl{ top: calc(50% - 60px); left: 6%; border-top-width: 3px; border-left-width: 3px; border-top-left-radius: 3px; }
.vf-tr{ top: calc(50% - 60px); right: 6%; border-top-width: 3px; border-right-width: 3px; border-top-right-radius: 3px; }
.vf-bl{ bottom: calc(50% - 60px); left: 6%; border-bottom-width: 3px; border-left-width: 3px; border-bottom-left-radius: 3px; }
.vf-br{ bottom: calc(50% - 60px); right: 6%; border-bottom-width: 3px; border-right-width: 3px; border-bottom-right-radius: 3px; }
/* Laser */
.vf-laser{
  position: absolute;
  left: 7%;
  right: 7%;
  height: 2px;
  background: linear-gradient(to right, transparent, #f00 15%, #f00 85%, transparent);
  box-shadow: 0 0 6px 1px rgba(255,0,0,.6);
  animation: laser 1.8s ease-in-out infinite;
}
@keyframes laser{
  0%   { top: calc(50% - 58px); opacity: 1; }
  50%  { top: calc(50% + 58px); opacity: 1; }
  100% { top: calc(50% - 58px); opacity: 1; }
}
.vf-label{
  position: absolute;
  bottom: calc(50% - 80px);
  font-size: 11px;
  font-weight: 600;
  color: rgba(255,255,255,.85);
  letter-spacing: .04em;
  text-transform: uppercase;
  text-shadow: 0 1px 3px rgba(0,0,0,.8);
}

.status-msg{
  min-height: 1.4em;
  font-size: 14px;
  font-weight: 600;
  margin: 16px 0 0;
}
.status-msg[data-tone="error"]{ color: var(--red); }
.status-msg[data-tone="loading"]{ color: var(--ink-soft); }
.status-msg[data-tone="ok"]{ color: var(--green); }

/* ---------- Receipt ---------- */
.receipt{
  max-width: var(--max);
  margin: 28px auto 40px;
  background: var(--card);
  padding: 30px 24px 24px;
  border: 1.5px solid var(--ink);
  border-top: none;
  clip-path: polygon(
    0% 5%, 6.25% 0%, 12.5% 5%, 18.75% 0%, 25% 5%, 31.25% 0%,
    37.5% 5%, 43.75% 0%, 50% 5%, 56.25% 0%, 62.5% 5%, 68.75% 0%,
    75% 5%, 81.25% 0%, 87.5% 5%, 93.75% 0%, 100% 5%,
    100% 100%, 0% 100%
  );
  animation: print-out 0.4s ease;
}

@keyframes print-out{
  from{ opacity: 0; transform: translateY(-14px); }
  to{ opacity: 1; transform: translateY(0); }
}

.receipt__eyebrow{
  font-family: var(--mono);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--ink-soft);
  margin: 0 0 4px;
}

.receipt__product{ display: flex; gap: 16px; align-items: center; }
.receipt__img{
  width: 72px; height: 72px;
  object-fit: contain;
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  flex-shrink: 0;
}
.receipt__img:not([src]), .receipt__img[src=""]{ visibility: hidden; }

#productName{ font-family: var(--display); font-size: 26px; font-weight: 700; margin: 0; line-height: 1.05; }
.receipt__brand{ color: var(--ink-soft); margin: 2px 0 0; font-size: 14px; }
.receipt__barcode{ font-size: 12.5px; color: var(--ink-soft); margin: 6px 0 0; letter-spacing: 1px; }

.divider{
  height: 14px;
  margin: 22px 0;
  background-image: repeating-linear-gradient(
    90deg, var(--ink) 0 1.5px, transparent 1.5px 4px,
    var(--ink) 4px 5px, transparent 5px 9px,
    var(--ink) 9px 9.5px, transparent 9.5px 13px
  );
  opacity: 0.85;
}

.mono{ font-family: var(--mono); }

/* Nutri-Score */
.nutriscore__label{ font-family: var(--mono); font-size: 11.5px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--ink-soft); display:block; margin-bottom: 8px;}
.nutriscore__row{ display: flex; gap: 4px; }
.nutri-letter{
  flex: 1;
  text-align: center;
  font-family: var(--display);
  font-weight: 800;
  font-size: 18px;
  padding: 8px 0;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink-soft);
  background: var(--paper);
}
.nutri-letter.is-active{
  border-color: var(--ink);
  transform: scale(1.12);
  color: #fff;
}
.nutri-letter[data-grade="a"].is-active{ background: #1F7A4D; }
.nutri-letter[data-grade="b"].is-active{ background: #6FAE3E; }
.nutri-letter[data-grade="c"].is-active{ background: var(--amber); }
.nutri-letter[data-grade="d"].is-active{ background: #D8631F; }
.nutri-letter[data-grade="e"].is-active{ background: var(--red); }

/* AI block */
.ai-block__head{ display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }

.stamp{
  font-family: var(--display);
  font-weight: 800;
  font-size: 26px;
  color: var(--green);
  border: 3px solid var(--green);
  border-radius: 50%;
  width: 72px; height: 72px;
  display: flex; align-items: baseline; justify-content: center; gap: 2px;
  transform: rotate(-7deg);
  flex-shrink: 0;
}
.stamp small{ font-size: 12px; font-weight: 600; }
.stamp[data-tier="moyen"]{ color: var(--amber); border-color: var(--amber); }
.stamp[data-tier="bas"]{ color: var(--red); border-color: var(--red); }

.ai-status{ font-size: 14px; color: var(--ink-soft); margin: 8px 0 0; min-height: 1.2em; }
.ai-resume{ font-size: 15px; line-height: 1.55; margin: 10px 0 0; }

.points{ display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 18px; }
.points__col h3{ font-size: 13px; text-transform: uppercase; letter-spacing: 0.5px; margin: 0 0 8px; }
.points__col--good h3{ color: var(--green); }
.points__col--bad h3{ color: var(--red); }
.points__col ul{ margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.points__col li{
  font-size: 13.5px; line-height: 1.4;
  padding: 8px 9px;
  border-radius: var(--radius);
}
.points__col--good li{ background: var(--green-soft); }
.points__col--bad li{ background: var(--red-soft); }

/* Nutrition table */
.nutrition h3, .ingredients h3, .additives h3{
  font-family: var(--display);
  font-size: 17px;
  font-weight: 700;
  margin: 0 0 12px;
}
.nutrition h3 span{ font-family: var(--body); font-weight: 400; font-size: 12.5px; color: var(--ink-soft); text-transform: none; }

#nutritionTable{ width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 13.5px; }
#nutritionTable td{ padding: 7px 4px; border-bottom: 1px solid var(--line); }
#nutritionTable tr:first-child td{ border-top: 2px solid var(--ink); }
#nutritionTable tr:last-child td{ border-bottom: 2px solid var(--ink); }
#nutritionTable td:last-child{ text-align: right; font-weight: 600; }
#nutritionTable tr.is-main td{ font-weight: 700; }

.ingredients p{ font-size: 13px; line-height: 1.6; color: var(--ink-soft); }

.additives__tags{ display: flex; flex-wrap: wrap; gap: 6px; }
.additive-tag{
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 9px;
  border-radius: var(--radius);
  border: 1.5px solid var(--ink);
  background: var(--paper);
  cursor: pointer;
}
.additive-tag[data-risque="faible"]{ background: var(--green-soft); border-color: var(--green); }
.additive-tag[data-risque="modere"]{ background: var(--amber-soft); border-color: var(--amber); }
.additive-tag[data-risque="eleve"]{ background: var(--red-soft); border-color: var(--red); }
.additives__detail{
  margin-top: 10px;
  font-size: 13.5px;
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  line-height: 1.5;
}

.receipt__footer{
  margin-top: 26px;
  font-size: 11.5px;
  color: var(--ink-soft);
  text-align: center;
  border-top: 1px dashed var(--line);
  padding-top: 14px;
}

.page-footer{
  text-align: center;
  font-size: 12px;
  color: var(--ink-soft);
  padding: 20px;
}

/* ---------- Responsive ---------- */
@media (max-width: 480px){
  .points{ grid-template-columns: 1fr; }
  .receipt__product{ flex-direction: column; align-items: flex-start; }
  #nutritionTable{ font-size: 12.5px; }
}
