/* SkinnyFat Mini App — «прибор + этикетка». Токены: docs/design-system.md */
:root {
  --chrome: #191C1F;
  --chrome-soft: #2A2F34;
  --chrome-text: #E8E4DC;
  --paper: #F6F3EB;
  --ink: #17150F;
  --ink-soft: #6E6A5E;
  --protein: #3E8E4B;
  --fat: #E3A72F;
  --carb: #D96F32;
  --laser: #E5342E;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  font-family: 'PT Sans', system-ui, sans-serif;
  background: var(--chrome);
  color: var(--chrome-text);
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
}

#device { position: fixed; inset: 0; }
#cam { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #0D0F11; }

/* верхняя панель */
.topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: linear-gradient(180deg, rgba(13,15,17,.82), rgba(13,15,17,0));
}
.brand {
  font-family: 'PT Sans Narrow', sans-serif; font-weight: 700;
  letter-spacing: .18em; font-size: 15px;
}
.status { font-family: 'PT Mono', monospace; font-size: 12px; opacity: .75; text-align: right; }
.status.busy { color: var(--laser); opacity: 1; }

/* видоискатель */
.finder { position: absolute; inset: 18% 9% 34%; z-index: 4; pointer-events: none; }
.finder .c { position: absolute; width: 26px; height: 26px; border: 2px solid rgba(232,228,220,.65); }
.c.tl { top: 0; left: 0; border-right: 0; border-bottom: 0; }
.c.tr { top: 0; right: 0; border-left: 0; border-bottom: 0; }
.c.bl { bottom: 0; left: 0; border-right: 0; border-top: 0; }
.c.br { bottom: 0; right: 0; border-left: 0; border-top: 0; }
.laser {
  position: absolute; left: 4px; right: 4px; top: 0; height: 2px;
  background: var(--laser);
  box-shadow: 0 0 12px 2px rgba(229,52,46,.8);
  opacity: 0; border-radius: 1px;
}
.finder.scanning .laser { opacity: 1; animation: sweep 1.6s ease-in-out infinite alternate; }
@keyframes sweep { from { top: 0; } to { top: calc(100% - 2px); } }

/* нет камеры */
.nocam {
  position: absolute; inset: 0 0 30%; z-index: 4;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  gap: 10px; padding: 0 32px; text-align: center;
}
.nocam-title { font-family: 'PT Sans Narrow', sans-serif; font-weight: 700; font-size: 24px; letter-spacing: .06em; }
.nocam-text { font-size: 14px; opacity: .75; line-height: 1.45; max-width: 300px; }

/* нижняя панель */
.controls {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 5;
  padding: 10px 16px calc(18px + env(safe-area-inset-bottom));
  background: linear-gradient(0deg, rgba(13,15,17,.88), rgba(13,15,17,0));
  display: flex; flex-direction: column; gap: 12px;
}
.history { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; min-height: 30px; }
.history::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; font-family: 'PT Mono', monospace; font-size: 12px;
  color: var(--chrome-text); background: rgba(42,47,52,.85);
  border: 1px solid rgba(232,228,220,.18); border-radius: 999px;
  padding: 6px 12px; cursor: pointer;
}
.ctl-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; }
.auto {
  justify-self: start;
  font-family: 'PT Sans Narrow', sans-serif; font-weight: 700; letter-spacing: .12em; font-size: 14px;
  color: var(--chrome-text); background: var(--chrome-soft);
  border: 1px solid rgba(232,228,220,.25); border-radius: 999px;
  padding: 9px 16px; cursor: pointer;
}
.auto[aria-pressed="true"] { background: var(--chrome-text); color: var(--chrome); border-color: var(--chrome-text); }
.shutter {
  width: 74px; height: 74px; border-radius: 50%;
  background: none; border: 3px solid var(--chrome-text); cursor: pointer;
  display: grid; place-items: center; transition: transform .12s;
}
.shutter:active { transform: scale(.93); }
.shutter i { display: block; width: 56px; height: 56px; border-radius: 50%; background: var(--chrome-text); }
.shutter[disabled] { opacity: .45; }
.ctl-spacer { justify-self: end; width: 64px; }

/* этикетка */
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 8;
  transform: translateY(0); animation: printout .24s cubic-bezier(.2,.9,.3,1);
}
@keyframes printout { from { transform: translateY(102%); } to { transform: translateY(0); } }
.label {
  background: var(--paper); color: var(--ink);
  border-radius: 2px 2px 0 0;
  padding: 14px 18px calc(16px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 28px rgba(0,0,0,.45);
  max-height: 72vh; overflow-y: auto;
}
.label-head {
  display: flex; justify-content: space-between;
  font-family: 'PT Sans Narrow', sans-serif; font-weight: 700;
  font-size: 13px; letter-spacing: .08em;
}
.rule { height: 6px; background: var(--ink); margin: 6px 0 12px; }
.prod {
  font-family: 'PT Sans Narrow', sans-serif; font-weight: 700;
  font-size: 34px; line-height: 1.05; text-transform: uppercase; letter-spacing: .02em;
}
.prod-state { font-family: 'PT Mono', monospace; font-size: 12px; color: var(--ink-soft); margin-top: 3px; }
.kcal-row { display: flex; align-items: baseline; gap: 8px; margin: 10px 0 4px; }
.kcal-big { font-family: 'PT Sans Narrow', sans-serif; font-weight: 700; font-size: 64px; line-height: 1; }
.kcal-unit { font-family: 'PT Mono', monospace; font-size: 14px; color: var(--ink-soft); }
.macros { width: 100%; border-collapse: collapse; margin-top: 8px; }
.macros td { padding: 8px 0; border-top: 1px solid rgba(23,21,15,.15); font-size: 15px; }
.macros td:first-child { width: 34%; }
.macros .num { font-family: 'PT Mono', monospace; width: 20%; }
.macros .bar { width: 46%; }
.macros .bar i { display: block; height: 10px; border-radius: 2px; min-width: 2px; }
.label-note {
  font-family: 'PT Mono', monospace; font-size: 12px; color: var(--ink-soft);
  border-top: 1px solid rgba(23,21,15,.15); margin-top: 2px; padding-top: 10px; line-height: 1.5;
}
.label-actions { margin-top: 14px; }
.btn-primary {
  width: 100%; font-family: 'PT Sans', sans-serif; font-weight: 700; font-size: 16px;
  color: var(--paper); background: var(--ink); border: 0; border-radius: 10px;
  padding: 14px; cursor: pointer;
}
.btn-primary:active { opacity: .85; }

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

@media (prefers-reduced-motion: reduce) {
  .sheet { animation: fadein .15s; }
  .finder.scanning .laser { animation: none; opacity: .9; top: 50%; }
  @keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
}
