:root {
  --bg: #f7f6f3;
  --elevated: #ffffff;
  --subtle: #f1efe9;
  --ink: #1c1917;
  --muted: #57534e;
  --tertiary: #a8a29e;
  --line: #e7e5e4;
  --line-strong: #d6d3d1;
  --line-subtle: #f5f5f4;
  --focus: #1c1917;
  --accent: #b45309;
  --accent-subtle: #fff7ed;
  --primary: #1c1917;
  --on-primary: #ffffff;
  --secondary: #f5f5f4;
  --success: #166534;
  --success-bg: #dcfce7;
  --warning: #b45309;
  --danger: #b91c1c;
  --bin: #d97706;
  --shadow: 0 12px 40px rgba(28, 25, 23, 0.12);
  --radius-lg: 12px;
  --radius-xl: 16px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141210;
    --elevated: #1f1c19;
    --subtle: #2a2622;
    --ink: #f5f5f4;
    --muted: #a8a29e;
    --tertiary: #78716c;
    --line: #3f3a36;
    --line-strong: #57534e;
    --line-subtle: #292524;
    --focus: #f5f5f4;
    --accent: #fbbf24;
    --accent-subtle: #3b2a12;
    --primary: #f5f5f4;
    --on-primary: #1c1917;
    --secondary: #292524;
    --success: #4ade80;
    --success-bg: #052e16;
    --warning: #fbbf24;
    --danger: #f87171;
    --bin: #f59e0b;
    --shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: not-allowed; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.shell {
  max-width: 460px;
  margin: 0 auto;
  padding: 12px 16px 32px;
  position: relative;
}

.note {
  font-size: 13px;
  line-height: 1.35;
  color: var(--muted);
  background: var(--secondary);
  border-radius: var(--radius-lg);
  padding: 10px 12px;
  margin: 0 0 12px;
}
.note.testing {
  background: #fff7ed;
  color: #9a3412;
  border: 1px solid #fdba74;
  font-weight: 650;
}
.note.sample {
  background: var(--accent-subtle);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  margin-top: 8px;
}
.note.sample .btn { margin-top: 8px; min-height: 44px; }

.header {
  margin-bottom: 12px;
  position: sticky;
  top: 0;
  z-index: 5;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  padding: 4px 0;
}
.header-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.brand { font-size: 17px; font-weight: 650; }
.header-side { display: flex; align-items: center; gap: 8px; position: relative; }
.badge {
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--secondary);
  white-space: nowrap;
}
.header .badge { margin-top: 6px; }
.header-top .badge { margin-top: 0; }
.badge.testing {
  background: #b45309;
  color: #fff;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.menu-btn {
  min-height: 44px;
  width: 44px;
  padding: 0;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: transparent;
  font-size: 20px;
  line-height: 1;
}
.menu {
  position: absolute;
  right: 0;
  top: 52px;
  z-index: 6;
  min-width: 280px;
  max-height: min(70vh, 520px);
  overflow: auto;
  background: var(--elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.menu .btn { border: none; width: 100%; text-align: left; min-height: 48px; background: transparent; }
.menu-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 10px 10px 2px;
}
.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 48px;
  padding: 8px 10px;
  border: none;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  font-size: 16px;
}
.switch-ui {
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: var(--line-strong);
  position: relative;
  flex: 0 0 auto;
}
.switch-ui::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
}
.switch[aria-checked="true"] .switch-ui { background: #b45309; }
.switch[aria-checked="true"] .switch-ui::after { left: 21px; }
.field-label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin: 14px 0 6px;
}

h1 {
  font-size: 26px;
  line-height: 32px;
  font-weight: 650;
  margin: 8px 0 4px;
}
h1.tight { font-size: 22px; }
.sub { font-size: 15px; color: var(--muted); margin: 0 0 18px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.center { text-align: center; }

.btn {
  width: 100%;
  min-height: 64px;
  padding: 14px 18px;
  border-radius: var(--radius-xl);
  border: 1px solid var(--line);
  background: var(--elevated);
  font-size: 19px;
  font-weight: 650;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.btn:active:not(:disabled) { transform: scale(0.99); }
.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
  justify-content: center;
  text-align: center;
}
.btn.selected { background: var(--accent-subtle); border-color: var(--focus); }
.btn:disabled { opacity: 0.5; }
.btn.quiet {
  min-height: 48px;
  width: auto;
  background: transparent;
  font-size: 16px;
  font-weight: 550;
  justify-content: center;
}
.btn.small {
  min-height: 44px;
  width: auto;
  padding: 6px 14px;
  font-size: 14px;
  font-weight: 550;
  border-radius: var(--radius-lg);
  background: transparent;
  justify-content: center;
}
.btn.link {
  width: auto;
  min-height: 44px;
  padding: 10px 4px;
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 15px;
  font-weight: 550;
  justify-content: flex-start;
}
.btn.danger { color: var(--danger); }
.side { font-size: 14px; color: var(--muted); font-weight: 450; white-space: nowrap; }
.store-code { font-size: 15px; color: var(--muted); font-weight: 450; }
.ticket-num { font-size: 13px; color: var(--muted); font-weight: 450; }

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  padding: 16px;
  background: var(--elevated);
}
.item-name { font-size: 20px; font-weight: 650; line-height: 26px; }
.muted { color: var(--muted); font-size: 15px; }
.small { font-size: 13px; color: var(--muted); }
.ok { color: var(--success); font-size: 13px; margin-top: 8px; }
.warn { color: var(--warning); }
.banner { margin-bottom: 18px; }

input[type="text"], input[type="search"], input[type="url"], input[type="password"] {
  width: 100%;
  min-height: 52px;
  font-size: 18px;
  padding: 12px 14px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line-strong);
  background: var(--bg);
  color: var(--ink);
}
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row input { flex: 1 1 120px; width: auto; min-width: 0; }
.row .btn { width: auto; min-height: 52px; }

.finder {
  border-radius: var(--radius-xl);
  border: 2px dashed var(--line-strong);
  background: var(--subtle);
  min-height: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 20px;
  text-align: center;
}
.stripes { display: flex; gap: 3px; align-items: stretch; height: 54px; }
.stripes i { display: block; background: var(--tertiary); border-radius: 1px; }
.finder .btn { min-width: 220px; }

.cam {
  position: relative;
  border-radius: var(--radius-xl);
  overflow: hidden;
  background: #000;
  aspect-ratio: 4 / 3;
  max-height: 46vh;
  margin-bottom: 10px;
}
.cam video { width: 100%; height: 100%; object-fit: cover; display: block; transform-origin: center center; }
.cam-tools {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  z-index: 2;
  display: flex;
  gap: 8px;
  align-items: center;
}
.cam-tool, .cam-zoom {
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  border: none;
  border-radius: 999px;
  min-height: 40px;
  padding: 0 12px;
  font-size: 14px;
}
.cam-tool[aria-pressed="true"] { background: #fbbf24; color: #1c1917; font-weight: 700; }
.cam-zoom { flex: 1; display: flex; align-items: center; gap: 8px; }
.cam-zoom input { flex: 1; min-width: 0; accent-color: #fbbf24; }
.guide {
  position: absolute;
  left: 8%;
  right: 8%;
  top: 38%;
  height: 24%;
  border: 3px solid rgba(255, 255, 255, 0.9);
  border-radius: 10px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.28);
}
#flash {
  position: absolute;
  inset: 0;
  background: #1a7f37;
  opacity: 0;
  transition: opacity 0.25s;
  pointer-events: none;
}
#camMsg {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
  font-size: 14px;
  text-align: center;
}
.engine { font-size: 13px; color: var(--muted); min-height: 1.2em; margin: 8px 0 0; }
.suggest { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; max-height: 280px; overflow-y: auto; }
.suggest .btn { min-height: 56px; font-size: 16px; font-weight: 550; }
.suggest .btn.primary { min-height: 56px; font-size: 17px; font-weight: 650; justify-content: center; }
.block-warn {
  font-size: 14px;
  color: var(--warning);
  background: var(--accent-subtle);
  border-radius: var(--radius-lg);
  padding: 10px 12px;
  margin-top: 10px;
}

.pick-list { max-height: 420px; overflow-y: auto; margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.pick-list .btn { min-height: 56px; font-size: 16px; font-weight: 550; }
.pick-list .btn.primary { min-height: 64px; font-size: 19px; font-weight: 650; justify-content: center; }

.fields { display: flex; gap: 10px; flex-wrap: wrap; }
.field {
  flex: 1 1 120px;
  min-height: 84px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: var(--elevated);
  color: var(--ink);
  padding: 8px 8px 10px;
}
.field.on { border: 2px solid var(--focus); }
.field .num { font-size: 34px; font-weight: 650; font-variant-numeric: tabular-nums; }
.field .lbl { font-size: 14px; color: var(--muted); font-weight: 450; line-height: 1.25; }
.math { font-size: 16px; text-align: center; margin-top: 12px; color: var(--muted); }
.math strong { color: var(--ink); font-size: 20px; }
.figure {
  font-size: 48px;
  font-weight: 650;
  text-align: center;
  padding: 10px 0;
  border-bottom: 2px solid var(--focus);
  font-variant-numeric: tabular-nums;
  min-height: 60px;
}

.pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 14px;
}
.pad button {
  min-height: 60px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: var(--elevated);
  font-size: 24px;
}
.pad.ops { grid-template-columns: repeat(6, 1fr); }
.pad.ops button { font-size: 22px; min-height: 52px; }
.toast {
  margin: 0 0 12px;
  padding: 12px 14px;
  border-radius: var(--radius-lg);
  background: var(--ink);
  color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.toast .link { color: #fff; min-height: 44px; }
.link-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.save { margin-top: 16px; justify-content: center; }

.bins { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.unit-row { display: flex; gap: 8px; margin: 0 0 10px; }
.unit-row .btn { flex: 1; min-height: 52px; }
.bin {
  min-height: 118px;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 10px;
  text-align: center;
}
.jar {
  width: 44px;
  height: 56px;
  border: 2px solid var(--line-strong);
  border-radius: 6px;
  display: flex;
  align-items: flex-end;
  overflow: hidden;
}
.jar span { display: block; width: 100%; background: var(--bin); }

.check {
  width: 64px;
  height: 64px;
  border-radius: 999px;
  background: var(--success-bg);
  color: var(--success);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  margin: 0 auto;
}
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.actions .btn.primary { flex: 2 1 200px; width: auto; }
.actions .btn.quiet { flex: 1 1 100px; min-height: 64px; }

.session { margin-top: 24px; }
.session h2 { font-size: 15px; font-weight: 650; margin: 0 0 8px; }
.group { padding: 14px; }
.group.fresh { border-color: var(--focus); }
.group-top, .sec-top, .entry {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.group-name { font-size: 16px; font-weight: 650; line-height: 21px; flex: 1 1 180px; }
.group-total { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
.sec { padding-top: 10px; }
.sec-top { font-size: 14px; font-weight: 650; }
.rules { margin-top: 10px; border-top: 1px solid var(--line-subtle); }
.entry {
  padding: 6px 0 6px 10px;
  border-left: 2px solid var(--line-subtle);
  margin-top: 6px;
}
.entry.fresh { border-left-color: var(--focus); }
.entry p { margin: 0; font-size: 13px; color: var(--muted); flex: 1 1 160px; }
.entry p b { color: var(--ink); font-weight: 550; }
.entry .btns { display: flex; gap: 6px; flex-wrap: wrap; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.backdrop { position: absolute; inset: 0; background: var(--bg); opacity: 0.9; }
.dialog {
  position: relative;
  width: 100%;
  max-width: 400px;
  max-height: calc(100vh - 32px);
  overflow: auto;
  background: var(--elevated);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-xl);
  padding: 20px;
  box-shadow: var(--shadow);
}
.dialog h2 { font-size: 20px; line-height: 26px; margin: 0; }
.dialog .stack { margin-top: 16px; }
.dialog .btn.quiet { width: 100%; min-height: 52px; }

@media (prefers-color-scheme: dark) {
  .note.testing {
    background: #3b2a12;
    color: #fdba74;
    border-color: #9a3412;
  }
}

@media (min-width: 800px) {
  .shell { padding-top: 28px; }
}
