:root {
  --approved: #14904a;
  --approved-bright: #3ddc84;
  --duplicate: #d7192d;
  --duplicate-dim: #7a0a16;
  --duplicate-bright: #ff4d5e;
  --accent: #1f6fd1;
  --panel: rgba(40, 40, 44, 0.72);
  --secondary: rgba(235, 235, 245, 0.6);
  /* The iPad sidebar. Zero on phones, where everything floats over the camera. */
  --panel-width: 0px;
  --camera-width: calc(100vw - var(--panel-width));
  --frame-width: min(calc(var(--camera-width) - 48px), 520px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: #fff;
  font: 17px/1.3 -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  -webkit-user-select: none;
  user-select: none;
}

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
button:focus:not(:focus-visible) { outline: none; }
svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

#camera { position: fixed; top: 0; left: 0; bottom: 0; width: var(--camera-width); height: 100%; object-fit: cover; background: #000; }

/* The scan frame: everything outside it is dimmed. */
.frame {
  position: fixed;
  left: calc(var(--camera-width) / 2);
  top: 42%;
  width: var(--frame-width);
  aspect-ratio: 100 / 62;
  transform: translate(-50%, -50%);
  border-radius: 20px;
  box-shadow: 0 0 0 200vmax rgba(0, 0, 0, 0.55);
  pointer-events: none;
}
.corner { position: absolute; width: 38px; height: 38px; border: 0 solid #fff; }
.corner.tl { top: 0; left: 0; border-top-width: 4px; border-left-width: 4px; border-top-left-radius: 20px; }
.corner.tr { top: 0; right: 0; border-top-width: 4px; border-right-width: 4px; border-top-right-radius: 20px; }
.corner.bl { bottom: 0; left: 0; border-bottom-width: 4px; border-left-width: 4px; border-bottom-left-radius: 20px; }
.corner.br { bottom: 0; right: 0; border-bottom-width: 4px; border-right-width: 4px; border-bottom-right-radius: 20px; }

.hint {
  position: fixed;
  left: 0; right: var(--panel-width);
  top: calc(42% + var(--frame-width) * 0.31 + 16px);
  margin: 0;
  text-align: center;
  font-weight: 600;
  pointer-events: none;
}

.camera-message {
  position: fixed; left: calc(var(--camera-width) / 2); top: 42%; transform: translate(-50%, -50%);
  width: min(90vw, 460px); text-align: center; padding: 24px;
}
.camera-message h2 { margin: 0 0 8px; font-size: 24px; }
.camera-message p { margin: 0; color: var(--secondary); }

/* On phones the panel's parts float over the camera. */
.panel { display: contents; }
.panel-title, .recent, .wide-label, .keypad { display: none; }

/* Header and footer float over the camera. */
.top, .notices, .bottom {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  width: min(calc(100vw - 32px), 720px);
}
.top {
  top: calc(env(safe-area-inset-top) + 10px);
  display: flex; align-items: center; gap: 12px;
  padding: 10px 10px 10px 18px;
  border-radius: 24px;
  background: var(--panel);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
}
.stats { display: flex; gap: 22px; flex: 1; }
.stat { display: flex; flex-direction: column; }
.count { font: 700 36px/1.05 ui-rounded, -apple-system, system-ui, sans-serif; }
.count.red { color: var(--duplicate-bright); }
.label { font-size: 15px; font-weight: 500; color: var(--secondary); white-space: nowrap; }

.round {
  width: 56px; height: 56px; flex: none;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--panel);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
}
.top .round { background: rgba(255, 255, 255, 0.15); width: 52px; height: 52px; }

.notices { top: calc(env(safe-area-inset-top) + 110px); display: flex; flex-direction: column; gap: 8px; }
.notice {
  display: flex; gap: 10px; align-items: flex-start; text-align: left;
  width: 100%; padding: 12px; border-radius: 16px;
  font-size: 15px; font-weight: 600;
}
.notice.red { background: rgba(215, 25, 45, 0.85); }
.notice.orange { background: rgba(255, 149, 0, 0.85); }
.notice.gray { background: rgba(142, 142, 147, 0.85); }

.bottom { bottom: calc(env(safe-area-inset-bottom) + 12px); display: flex; flex-direction: column; gap: 10px; }
.controls { display: flex; align-items: center; gap: 14px; }
.primary {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  flex: 1; min-height: 58px; padding: 0 22px;
  border-radius: 999px;
  background: var(--accent);
  font-size: 20px; font-weight: 700;
}
.primary:disabled { opacity: 0.4; }
.primary.wide { width: 100%; flex: none; }

.last-result {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; border-radius: 20px;
  background: var(--panel);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
}
.last-icon { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; flex: none; color: #000; font-weight: 900; }
.last-icon.approved { background: var(--approved-bright); }
.last-icon.duplicate { background: var(--duplicate-bright); border-radius: 8px; }
.last-icon svg { width: 18px; height: 18px; stroke-width: 3.5; }
.last-text { flex: 1; min-width: 0; }
.last-number { font: 600 17px ui-monospace, SFMono-Regular, Menlo, monospace; }
.last-detail { font-size: 15px; color: var(--secondary); }
.last-detail.orange { color: #ff9f0a; }
.pill-button { padding: 8px 16px; border-radius: 999px; background: rgba(255, 255, 255, 0.18); font-weight: 600; }

/* Full-screen result. */
.result {
  position: fixed; inset: 0; z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  padding: calc(env(safe-area-inset-top) + 24px) 24px calc(env(safe-area-inset-bottom) + 24px);
  text-align: center;
}
.result.approved { background: var(--approved); }
.result.duplicate { background: var(--duplicate); animation: flash 0.9s steps(1) infinite; }
@keyframes flash { 50% { background: var(--duplicate-dim); } }
@media (prefers-reduced-motion: reduce) { .result.duplicate { animation: none; } }
.result .big-icon { width: 130px; height: 130px; stroke-width: 2.4; }
.result.approved .big-icon { animation: bounce 0.35s ease-out; }
@keyframes bounce { 0% { transform: scale(0.7); } 70% { transform: scale(1.08); } 100% { transform: scale(1); } }
.result h2 { margin: 0; font-size: clamp(40px, 12vw, 64px); font-weight: 900; line-height: 1.02; }
.result p { margin: 0; font-size: 21px; font-weight: 600; }
.result .dim { opacity: 0.85; }
.result .number { margin-top: 8px; font: 700 clamp(28px, 8vw, 44px) ui-monospace, SFMono-Regular, Menlo, monospace; }
.result .times { padding: 6px 14px; border-radius: 999px; background: rgba(0, 0, 0, 0.25); font-weight: 700; }
.result .next {
  margin-top: auto; width: min(100%, 520px); min-height: 58px;
  border-radius: 999px; background: #fff; color: var(--duplicate);
  font-size: 21px; font-weight: 700;
}
.result .spacer { flex: 1; }

/* Start screen. */
.start {
  position: fixed; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  padding: 32px; text-align: center;
  background: linear-gradient(#2f86e8, #0b3f8c);
}
.start img { border-radius: 26px; }
.start h1 { margin: 12px 0 0; font-size: 34px; }
.start p { margin: 0; opacity: 0.85; }
.start .primary { flex: none; width: min(100%, 360px); margin-top: 22px; background: #fff; color: #0b3f8c; }
.start .small { font-size: 15px; opacity: 0.7; }

/* Sheets. */
dialog { color: #fff; }
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
.sheet {
  width: min(100vw, 720px); max-width: 100vw;
  height: 100%; max-height: 100%;
  margin: 0 auto; padding: 0;
  border: 0;
  background: #1c1c1e;
  -webkit-user-select: text; user-select: text;
}
.small-sheet { height: fit-content; margin: auto auto 0; border-radius: 22px 22px 0 0; padding-bottom: calc(env(safe-area-inset-bottom) + 16px); }
.sheet-bar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
}
.small-sheet .sheet-bar { padding-top: 16px; }
.sheet-bar h2 { margin: 0; font-size: 17px; }
.sheet-bar > :first-child { justify-self: start; }
.sheet-bar > :last-child { justify-self: end; }
.text-button { color: #4a9eff; padding: 8px 4px; }
.text-button.strong { font-weight: 700; }
.text-button:disabled { opacity: 0.35; }
.sheet-body { height: calc(100% - 70px - env(safe-area-inset-top)); overflow-y: auto; padding: 8px 16px calc(env(safe-area-inset-bottom) + 24px); -webkit-overflow-scrolling: touch; }
.group { background: #2c2c2e; border-radius: 14px; overflow: hidden; margin-top: 18px; }
.row { display: flex; justify-content: space-between; gap: 12px; padding: 13px 16px; border-bottom: 1px solid #3a3a3c; }
.row:last-child { border-bottom: 0; }
.row > :last-child { color: var(--secondary); text-align: right; }
.row-button { display: block; width: 100%; padding: 15px 16px; font-weight: 700; text-align: center; border-bottom: 1px solid #3a3a3c; }
.row-button:last-child { border-bottom: 0; }
.row-button.red { color: var(--duplicate-bright); }
.row-button.blue { color: #4a9eff; }
.row-button:disabled { color: var(--secondary); }
.footnote { margin: 6px 16px 0; font-size: 13px; color: var(--secondary); }
.search { width: 100%; margin-top: 22px; padding: 11px 14px; border: 0; border-radius: 12px; background: #2c2c2e; color: #fff; font: inherit; }
.entry { display: flex; align-items: center; gap: 12px; padding: 11px 16px; border-bottom: 1px solid #3a3a3c; }
.entry:last-child { border-bottom: 0; }
.entry-main { flex: 1; min-width: 0; }
.entry-number { font: 600 17px ui-monospace, SFMono-Regular, Menlo, monospace; }
.entry-detail { font-size: 13px; color: var(--secondary); }
.entry-blocked { color: var(--duplicate-bright); font-weight: 700; white-space: nowrap; }
.entry-remove { color: var(--duplicate-bright); font-size: 15px; padding: 6px 4px; }
.empty { text-align: center; color: var(--secondary); margin-top: 40px; }

.entry-input {
  display: block; width: calc(100% - 40px); margin: 4px 20px 0;
  padding: 14px; border: 0; border-radius: 14px;
  background: #2c2c2e; color: #fff;
  font: 600 30px ui-monospace, SFMono-Regular, Menlo, monospace; text-align: center;
}
.entry-input::placeholder { font: 400 22px -apple-system, system-ui, sans-serif; color: var(--secondary); }
.entry-hint { margin: 12px 20px; text-align: center; font-size: 15px; color: var(--secondary); }
.entry-hint.warn { color: #ff9f0a; }
#entry-form .primary.wide { width: calc(100% - 40px); margin: 0 20px; }

/* Confirmation, centred like an iOS alert. */
.alert {
  width: min(86vw, 320px); padding: 20px 16px 16px;
  border: 0; border-radius: 22px;
  background: #2c2c2e; text-align: center;
}
.alert h3 { margin: 0 0 6px; font-size: 17px; }
.alert p { margin: 0 0 18px; font-size: 14px; color: var(--secondary); white-space: pre-line; }
.alert-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.alert-button { padding: 12px; border-radius: 999px; background: #3a3a3c; font-weight: 600; color: #4a9eff; }
.alert-button.red { color: var(--duplicate-bright); }

/* Number pad, shown on iPads (their keyboard has no number pad). */
.keypad { grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 0 20px 16px; }
.keypad button {
  min-height: 68px; border-radius: 16px; background: #3a3a3c;
  font: 600 32px ui-rounded, -apple-system, system-ui, sans-serif;
}
.keypad button:active { background: #48484a; }
.keypad .key-word { font-size: 19px; }

/* iPad: camera on the left, a sidebar with the counts, controls and the list on the right. */
@media (min-width: 700px) {
  :root { --panel-width: 380px; }

  .panel {
    position: fixed; top: 0; right: 0; bottom: 0; width: var(--panel-width);
    display: flex; flex-direction: column; gap: 16px;
    padding: calc(env(safe-area-inset-top) + 20px) 20px calc(env(safe-area-inset-bottom) + 20px);
    background: #121212; border-left: 1px solid #2c2c2e;
  }
  .panel-title { display: block; font-size: 24px; font-weight: 700; margin-right: 140px; min-height: 40px; line-height: 40px; }
  .top, .notices, .bottom { position: static; transform: none; width: auto; }
  .top { padding: 0; background: none; -webkit-backdrop-filter: none; backdrop-filter: none; gap: 12px; flex-wrap: wrap; }
  .stats { gap: 12px; }
  .stat { flex: 1; padding: 14px; border-radius: 18px; background: #232325; }
  .count { font-size: 40px; }
  .top .round {
    position: absolute; top: calc(env(safe-area-inset-top) + 20px); right: 20px;
    width: auto; height: 40px; padding: 0 16px; gap: 8px; border-radius: 999px; display: flex;
  }
  .top .round svg { width: 20px; height: 20px; }
  .wide-label { display: inline; font-weight: 600; }
  .bottom { gap: 12px; }
  .controls { flex-wrap: wrap; gap: 12px; }
  .controls .primary { flex: 1 0 100%; order: -1; }
  .controls .round {
    flex: 1; width: auto; height: 46px; border-radius: 999px; display: flex; gap: 8px;
    align-items: center; justify-content: center;
    background: #2c2c2e; font-size: 15px;
  }
  .controls .round svg { width: 20px; height: 20px; }
  .last-result { background: #232325; }

  .recent { display: flex; flex-direction: column; flex: 1; min-height: 0; border-top: 1px solid #2c2c2e; padding-top: 14px; }
  .recent h3 { margin: 0 0 6px; font-size: 17px; color: var(--secondary); }
  #recent-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  #recent-list .entry { padding: 10px 0; }
  #recent-list .empty { margin-top: 12px; text-align: left; }

  /* Results: as large as fits the height, so they read from across the line. */
  .result .big-icon { width: min(210px, 20vh); height: min(210px, 20vh); }
  .result h2 { font-size: min(96px, 9.5vh); }
  .result p { font-size: min(32px, 3.2vh); }
  .result .number { font-size: min(64px, 6.2vh); }
  .result .times { font-size: min(26px, 2.6vh); }

  /* Sheets become centred cards. */
  .sheet { height: min(90vh, 960px); margin: auto; border-radius: 22px; overflow: hidden; }
  .sheet-bar { padding-top: 14px; }
  .sheet-body { height: calc(100% - 64px); }
  .small-sheet { width: 520px; height: fit-content; margin: auto; border-radius: 22px; padding-bottom: 20px; }
  .keypad { display: grid; }
}

/* Short and wide (a phone turned sideways): the sidebar scrolls, results and the keypad shrink to fit. */
@media (min-width: 700px) and (max-height: 560px) {
  .panel {
    gap: 10px; overflow-y: auto; -webkit-overflow-scrolling: touch;
    padding: calc(env(safe-area-inset-top) + 12px) calc(env(safe-area-inset-right) + 16px) calc(env(safe-area-inset-bottom) + 12px) 16px;
  }
  .panel-title { font-size: 20px; min-height: 36px; line-height: 36px; }
  .top .round { top: calc(env(safe-area-inset-top) + 12px); right: calc(env(safe-area-inset-right) + 16px); height: 36px; }
  .stat { padding: 10px 12px; }
  .count { font-size: 30px; }
  .primary { min-height: 50px; }
  .recent { flex: none; }
  #recent-list { overflow: visible; }

  .result { gap: 8px; padding-top: calc(env(safe-area-inset-top) + 12px); padding-bottom: calc(env(safe-area-inset-bottom) + 12px); }
  .result .big-icon { width: 64px; height: 64px; }
  .result h2 { font-size: 40px; }
  .result p { font-size: 17px; }
  .result .number { font-size: 28px; margin-top: 2px; }
  .result .times { font-size: 15px; }
  .result .next { min-height: 48px; font-size: 19px; }

  .small-sheet { width: min(760px, 94vw); }
  #entry-form {
    display: grid; grid-template-columns: 1fr 1fr; column-gap: 20px; align-items: start;
    grid-template-areas: "bar bar" "input keypad" "hint keypad" "check keypad";
    padding: 0 20px;
  }
  #entry-form .sheet-bar { grid-area: bar; padding-left: 0; padding-right: 0; }
  #entry-form .entry-input { grid-area: input; width: 100%; margin: 4px 0 0; }
  #entry-form .entry-hint { grid-area: hint; margin: 10px 0; }
  #entry-form .keypad { grid-area: keypad; margin: 0; gap: 8px; }
  #entry-form .keypad button { min-height: 50px; font-size: 26px; }
  #entry-form .keypad .key-word { font-size: 17px; }
  #entry-form .primary.wide { grid-area: check; width: 100%; margin: 0; }
}
