:root {
  --paper: #ffffff;
  --ink: #000000;
  --tag: #ffd60a;
  --sale: #d7261e;
  --steel: #59616b;
  --rule: #e4e6e9;
  --shade: rgba(0, 0, 0, 0.62);
  --font: system-ui, -apple-system, "Segoe UI", "Noto Sans Arabic", "Noto Naskh Arabic", Tahoma, sans-serif;
  --pad: clamp(20px, 6vw, 32px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

main {
  min-height: 100%;
}

[hidden] {
  display: none !important;
}

h1,
h2,
p {
  margin: 0;
}

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

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

/* Screens ------------------------------------------------------------- */

.screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.paper {
  padding: var(--pad);
  padding-bottom: calc(var(--pad) + var(--safe-bottom));
}

/* Intro: the page opens on the job itself, set large. */

.intro {
  padding: var(--pad);
  padding-bottom: calc(var(--pad) + var(--safe-bottom));
  justify-content: flex-end;
  gap: 20px;
}

.intro-mark {
  width: clamp(96px, 30vw, 128px);
  height: auto;
  margin-top: 6vh;
  margin-bottom: auto;
  transform: rotate(-8deg);
}

h1 {
  font-size: clamp(40px, 12vw, 56px);
  line-height: 1.12;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.lead {
  color: var(--steel);
  font-size: 17px;
  max-width: 34em;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

/* Buttons ------------------------------------------------------------- */

.btn {
  min-height: 58px;
  border: 0;
  border-radius: 16px;
  padding: 0 24px;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

.btn.primary {
  background: var(--ink);
  color: var(--paper);
}

.btn.primary:active {
  transform: translateY(1px);
}

.btn.quiet {
  background: transparent;
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 6px;
  text-decoration-thickness: 1px;
  font-weight: 600;
}

.btn.glass {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  min-height: 52px;
  font-size: 16px;
}

.icon-btn {
  width: 52px;
  height: 52px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.icon-btn svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: #fff;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn[aria-pressed="true"] {
  background: var(--tag);
}

.icon-btn[aria-pressed="true"] svg {
  stroke: var(--ink);
}

/* Scanner ------------------------------------------------------------- */

.scanner {
  position: fixed;
  inset: 0;
  min-height: 0;
  background: #000;
  color: #fff;
  overflow: hidden;
}

.scanner video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* The window is a wide slot shaped like a barcode, cut out of the shade. */
.window {
  --w: min(84vw, 420px);
  --h: calc(var(--w) * 0.46);
  position: absolute;
  top: 50%;
  left: 50%;
  width: var(--w);
  height: var(--h);
  transform: translate(-50%, -50%);
  border-radius: 18px;
  box-shadow: 0 0 0 100vmax var(--shade);
}

.window i {
  position: absolute;
  width: 34px;
  height: 34px;
  border: 0 solid #fff;
  transition: border-color 0.12s, transform 0.12s;
}

.window i:nth-child(1) { top: -3px; right: -3px; border-top-width: 5px; border-right-width: 5px; border-top-right-radius: 20px; }
.window i:nth-child(2) { top: -3px; left: -3px; border-top-width: 5px; border-left-width: 5px; border-top-left-radius: 20px; }
.window i:nth-child(3) { bottom: -3px; right: -3px; border-bottom-width: 5px; border-right-width: 5px; border-bottom-right-radius: 20px; }
.window i:nth-child(4) { bottom: -3px; left: -3px; border-bottom-width: 5px; border-left-width: 5px; border-bottom-left-radius: 20px; }

.window b {
  position: absolute;
  left: 8%;
  right: 8%;
  top: 50%;
  height: 2px;
  background: var(--tag);
  border-radius: 2px;
  opacity: 0.9;
  animation: sweep 2.2s ease-in-out infinite;
}

@keyframes sweep {
  0%, 100% { transform: translateY(calc(var(--h) * -0.32)); }
  50% { transform: translateY(calc(var(--h) * 0.32)); }
}

.window.hit i {
  border-color: var(--tag);
  transform: scale(0.92);
}

.window.hit b {
  animation: none;
  opacity: 0;
}

.scanner-top,
.hint,
.scanner-bottom {
  z-index: 2;
}

.scanner-top {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 16px);
  inset-inline: 16px;
  display: flex;
  justify-content: space-between;
}

.hint {
  position: absolute;
  inset-inline: 24px;
  top: calc(50% - min(84vw, 420px) * 0.23 - 64px);
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.6);
}

.scanner-bottom {
  position: absolute;
  inset-inline: var(--pad);
  bottom: calc(var(--safe-bottom) + 24px);
  display: flex;
  justify-content: center;
}

/* Searching ------------------------------------------------------------ */

#searching {
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
}

.spinner {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 4px solid var(--rule);
  border-top-color: var(--ink);
  animation: spin 0.8s linear infinite;
}

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

.status {
  font-size: 18px;
  font-weight: 700;
}

.code {
  color: var(--steel);
  font-size: 15px;
  letter-spacing: 0.12em;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.code:empty {
  display: none;
}

/* Result: the shelf label ---------------------------------------------- */

.result {
  padding: 0;
}

.result-scroll {
  flex: 1;
  padding: var(--pad);
  padding-bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.photo {
  margin: 0;
  aspect-ratio: 1;
  max-height: 42vh;
  width: 100%;
  display: grid;
  place-items: center;
  background: #f6f7f8;
  border-radius: 24px;
  overflow: hidden;
}

.photo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
}

.no-photo {
  width: 72px;
  height: 72px;
  fill: none;
  stroke: #b8bdc4;
  stroke-width: 2;
  stroke-linejoin: round;
}

.result h2 {
  font-size: 25px;
  line-height: 1.35;
  font-weight: 800;
}

.unit {
  align-self: flex-start;
  padding: 4px 14px;
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  font-size: 15px;
  font-weight: 700;
}

/* A die-cut price tag: notched end, punched hole, price set as the hero. */
.tag {
  position: relative;
  background: var(--tag);
  padding: 18px 24px 18px 22px;
  padding-inline-start: 58px;
  clip-path: polygon(0 0, calc(100% - 26px) 0, 100% 50%, calc(100% - 26px) 100%, 0 100%);
  border-radius: 6px;
}

[dir="rtl"] .tag {
  clip-path: polygon(26px 0, 100% 0, 100% 100%, 26px 100%, 0 50%);
  padding: 18px 58px 18px 30px;
}

.tag-hole {
  position: absolute;
  top: 50%;
  inset-inline-start: 22px;
  width: 16px;
  height: 16px;
  margin-top: -8px;
  border-radius: 50%;
  background: var(--paper);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25);
}

[dir="rtl"] .tag-hole {
  inset-inline-start: auto;
  left: 34px;
}

.price {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0 10px;
}

.amount {
  font-size: clamp(52px, 17vw, 84px);
  line-height: 1;
  font-weight: 900;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums lining-nums;
}

.currency {
  font-size: 20px;
  font-weight: 800;
}

.was {
  margin-top: 6px;
  font-size: 16px;
  font-weight: 700;
}

.was s {
  color: var(--steel);
  text-decoration-color: var(--sale);
  text-decoration-thickness: 2px;
}

.was strong {
  color: var(--sale);
  margin-inline-start: 8px;
}

.description {
  color: #2b3036;
  font-size: 16px;
  line-height: 1.75;
  max-width: 36em;
}

.result .code,
.message .code {
  text-align: right;
}

.dock {
  position: sticky;
  bottom: 0;
  padding: 12px var(--pad) calc(12px + var(--safe-bottom));
  background: linear-gradient(to top, var(--paper) 70%, rgba(255, 255, 255, 0));
  display: flex;
  flex-direction: column;
}

.reveal .tag {
  animation: tag-in 0.42s cubic-bezier(0.2, 0.9, 0.25, 1.15) both;
}

@keyframes tag-in {
  from { transform: translateY(18px) rotate(-1.5deg); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* Messages (not found, camera blocked, offline) ----------------------- */

.message {
  justify-content: flex-end;
  gap: 16px;
}

.message h2 {
  font-size: 30px;
  line-height: 1.25;
  font-weight: 800;
}

.message .lead {
  color: #2b3036;
}

.steps {
  margin: 0;
  padding-inline-start: 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 16px;
}

.steps strong {
  display: block;
}

/* Manual entry sheet --------------------------------------------------- */

.sheet {
  width: 100%;
  max-width: 560px;
  margin: auto auto 0;
  border: 0;
  border-radius: 24px 24px 0 0;
  padding: 24px var(--pad) calc(20px + var(--safe-bottom));
  background: var(--paper);
  color: var(--ink);
}

.sheet::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.sheet form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sheet h2 {
  font-size: 22px;
  font-weight: 800;
}

.sheet input {
  min-height: 60px;
  border: 2px solid var(--ink);
  border-radius: 14px;
  padding: 0 16px;
  font-size: 24px;
  letter-spacing: 0.08em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.sheet input:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px var(--tag);
}

.sheet input::placeholder {
  color: #c4c8cd;
}

.field-error {
  min-height: 1.4em;
  color: var(--sale);
  font-size: 15px;
  font-weight: 600;
}

@media (min-width: 720px) {
  .intro,
  .paper,
  .result-scroll,
  .dock {
    max-width: 560px;
    width: 100%;
    margin-inline: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .window b,
  .spinner,
  .reveal .tag {
    animation: none;
  }
  .window b {
    transform: none;
  }
}
