:root {
  --basalt: #19191a;
  --basalt-2: #2a2a2b;
  --limestone: #eceae4;
  --limestone-2: #f5f4f0;
  --grout: #cfcbc1;
  --ink: #19191a;
  --ink-2: #56544f;
  --on-basalt-2: #b9b6ae;
  --red: #a4221b;
  --wave-h: 22px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--basalt);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

::selection { background: var(--basalt); color: var(--limestone); }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

:focus-visible { outline: 2px solid currentColor; outline-offset: 3px; }

svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.app {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto var(--wave-h) 1fr auto;
  overflow: hidden;
}

.finder {
  position: relative;
  height: calc(52dvh + var(--safe-t));
  background: var(--basalt);
  color: var(--limestone);
  overflow: hidden;
  transition: height 520ms var(--ease-out);
}

.video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 360ms var(--ease-out);
}

.reticle {
  position: absolute;
  left: 50%;
  top: calc(50% + var(--safe-t) / 2);
  width: min(62vw, 34dvh);
  aspect-ratio: 1;
  translate: -50% -50%;
  opacity: 0;
  transition: opacity 300ms var(--ease-out), scale 380ms var(--ease-out);
}

.reticle i {
  position: absolute;
  width: 26px;
  height: 26px;
  border: 0 solid var(--limestone);
  filter: drop-shadow(0 1px 3px rgb(0 0 0 / 0.55));
}
.reticle i:nth-child(1) { top: 0; left: 0; border-top-width: 3px; border-left-width: 3px; border-top-left-radius: 6px; }
.reticle i:nth-child(2) { top: 0; right: 0; border-top-width: 3px; border-right-width: 3px; border-top-right-radius: 6px; }
.reticle i:nth-child(3) { bottom: 0; left: 0; border-bottom-width: 3px; border-left-width: 3px; border-bottom-left-radius: 6px; }
.reticle i:nth-child(4) { bottom: 0; right: 0; border-bottom-width: 3px; border-right-width: 3px; border-bottom-right-radius: 6px; }

.idle {
  position: absolute;
  inset: var(--safe-t) 0 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  padding: 24px 32px;
  text-align: center;
  transition: opacity 260ms var(--ease-out);
}

.idle-note {
  margin: 0;
  max-width: 30ch;
  font-size: 15px;
  line-height: 1.45;
  color: var(--on-basalt-2);
  text-wrap: balance;
}

.status {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 14px;
  margin: 0 auto;
  width: fit-content;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 6px;
  background: var(--limestone);
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  text-align: center;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 6px 18px rgb(0 0 0 / 0.28);
  opacity: 0;
  translate: 0 8px;
  transition: opacity 220ms var(--ease-out), translate 320ms var(--ease-out);
  pointer-events: none;
}
.status.on { opacity: 1; translate: 0 0; }
.status[data-tone="ok"] { background: var(--limestone); }
.status[data-tone="warn"] { background: var(--basalt-2); color: var(--limestone); outline: 1px solid #4a4946; }
.status[data-tone="error"] { background: var(--red); color: #fff; }
.app[data-state="idle"] .status { top: calc(var(--safe-t) + 14px); bottom: auto; }

.summary-title {
  position: absolute;
  left: 20px;
  bottom: 10px;
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  opacity: 0;
  transition: opacity 260ms var(--ease-out);
}

.app[data-state="scanning"] .video { opacity: 1; }
.app[data-state="scanning"] .reticle { opacity: 0.95; }
.app[data-state="scanning"] .idle { opacity: 0; pointer-events: none; }
.app.rolled .reticle { animation: catch 420ms var(--ease-out); }

.app[data-state="summary"] .finder { height: calc(48px + var(--safe-t)); }
.app[data-state="summary"] .idle,
.app[data-state="summary"] .video,
.app[data-state="summary"] .reticle { opacity: 0; pointer-events: none; }
.app[data-state="summary"] .summary-title { opacity: 1; }

.wave {
  background-color: var(--limestone);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='22' viewBox='0 0 56 22'%3E%3Cpath fill='%2319191a' d='M0 0H56V8C49 8 49 18 42 18S35 8 28 8 21 18 14 18 7 8 0 8Z'/%3E%3Cpath fill='none' stroke='%23eceae4' stroke-width='1.6' d='M0 2.5C7 2.5 7 12.5 14 12.5S21 2.5 28 2.5 35 12.5 42 12.5 49 2.5 56 2.5'/%3E%3C/svg%3E");
  background-repeat: repeat-x;
  background-size: 56px 22px;
  background-position: 0 0;
  margin-top: -1px;
}
.app.rolled .wave { animation: roll 700ms var(--ease-out); }

@keyframes roll {
  from { background-position: -28px 0; }
  to { background-position: 0 0; }
}
@keyframes catch {
  0% { scale: 1; }
  35% { scale: 0.92; }
  100% { scale: 1; }
}

.ledger {
  background: var(--limestone);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--grout) transparent;
}

.total {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  row-gap: 2px;
  padding: 14px 20px 18px;
  border-bottom: 1px solid var(--grout);
}

.total-label {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink-2);
}

.total-count {
  grid-column: 2;
  grid-row: 1;
  font-size: 15px;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

.total-amount {
  grid-column: 1 / -1;
  font-size: clamp(44px, 13vw, 60px);
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}

.list {
  list-style: none;
  margin: 0;
  padding: 0 0 12px;
}

.row {
  display: grid;
  grid-template-columns: 24px 1fr auto 40px;
  align-items: start;
  column-gap: 10px;
  padding: 14px 6px 14px 20px;
  border-bottom: 1px solid var(--grout);
}

.row.new { animation: settle 560ms var(--ease-out); }

@keyframes settle {
  from { translate: 0 -14px; opacity: 0; background: var(--limestone-2); }
  to { translate: 0 0; opacity: 1; }
}

.row-n {
  padding-top: 2px;
  font-size: 13px;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

.row-ref {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.row-number {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.row-atcud {
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.row-meta {
  font-size: 13px;
  color: var(--ink-2);
  line-height: 1.35;
}

.row-amount {
  font-size: 17px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.row.credit .row-amount { color: var(--red); }

.remove {
  width: 40px;
  height: 40px;
  margin-top: -9px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-2);
}
.remove svg { width: 18px; height: 18px; }
.remove:active { background: var(--grout); color: var(--ink); }

.empty {
  margin: 0;
  padding: 22px 20px;
  max-width: 36ch;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink-2);
}
.app.has-items .empty { display: none; }

.bar {
  background: var(--limestone);
  border-top: 1px solid var(--grout);
  padding: 12px 16px calc(12px + var(--safe-b));
}

.bar-summary { display: none; grid-template-columns: 1fr 1fr; gap: 10px; }
.bar-summary .copy:only-of-type { grid-column: 1 / -1; }
.app[data-state="summary"] .bar-scan { display: none; }
.app[data-state="summary"] .bar-summary { display: grid; }
.bar-summary .share[hidden] { display: none; }
.bar-summary:has(.share[hidden]) .copy { grid-column: 1 / -1; }

.slab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 50px;
  width: 100%;
  padding: 0 18px;
  border-radius: 8px;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  transition: scale 160ms var(--ease-out), opacity 200ms;
}
.slab:active { scale: 0.98; }

.slab-dark {
  background: var(--basalt);
  color: var(--limestone);
  border: 1px solid var(--basalt);
}

.slab-light {
  background: var(--limestone);
  color: var(--basalt);
  border: 1px solid var(--basalt);
}

.finder .slab-light { width: auto; border-color: var(--limestone); padding: 0 24px; }

.slab:disabled {
  background: transparent;
  color: var(--ink-2);
  border-color: var(--grout);
  cursor: default;
}
.slab:disabled:active { scale: 1; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: 1ms !important; }
}
