/* Scanner: lean, phone first. Colours meet WCAG AA (text ≥ 4.5:1, borders/controls ≥ 3:1) in both themes. */
:root {
  --bg: #fff; --surface: #f3f4f6; --text: #111827; --muted: #4b5563; --line: #6b7280;
  --accent: #1d4ed8; --accent-ink: #fff; --ok: #166534; --error: #b91c1c; --focus: #b45309;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111317; --surface: #1d2027; --text: #f3f4f6; --muted: #b6bcc6; --line: #8a919c;
    --accent: #8cb4ff; --accent-ink: #0d1626; --ok: #6ee7a0; --error: #ff9b8f; --focus: #ffd166; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 1rem/1.45 system-ui, -apple-system, sans-serif; }
main { max-width: 34rem; margin: 0 auto; padding: 0 16px 32px; }
h1 { font-size: 1.15rem; margin: 0; flex: 1; }
h2 { font-size: 1.1rem; margin: 0 0 4px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

button, input { font: inherit; color: inherit; }
button {
  min-height: 44px; min-width: 44px; padding: 0 14px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer;
}
button[type=submit], button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button:disabled { opacity: .45; cursor: default; pointer-events: none; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.bar { position: sticky; top: 0; z-index: 2; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 16px; background: var(--bg); border-bottom: 1px solid var(--line); }
.toggle[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.toggle .off, .toggle[aria-pressed="false"] .on { display: none; }
.toggle[aria-pressed="false"] .off { display: inline; }

/* Camera with a wide, flat guide (1D barcodes); the border shows the result: colour + mark. */
/* The camera shows only the guide: wide and flat for barcodes, square for the session's QR code.
   What is inside the dashed line is what gets read (scanner.js, guideArea). */
.frame { position: relative; margin: 12px 0 8px; border: 4px solid var(--line); border-radius: 14px; overflow: hidden; background: #000; aspect-ratio: 5 / 2; }
.frame.qr { aspect-ratio: 1; max-width: 20rem; margin-inline: auto; }
.frame video { width: 100%; height: 100%; object-fit: cover; display: block; }
.guide { position: absolute; inset: 6px; border: 2px dashed rgba(255, 255, 255, .85); border-radius: 8px; }
.frame.ok { border-color: var(--ok); }
.frame.error { border-color: var(--error); }
.frame.busy { border-color: var(--accent); }
.frame-mark { position: absolute; top: 8px; right: 10px; margin: 0; font-size: 2rem; font-weight: 700; line-height: 1; color: #fff; text-shadow: 0 0 4px #000; }

.status { min-height: 1.45em; margin: 0 0 10px; font-weight: 600; overflow-wrap: anywhere; }
.status.ok { color: var(--ok); }
.status.error { color: var(--error); }
.status.busy { color: var(--muted); }
.notice { margin: 12px 0; padding: 10px 12px; border: 2px solid var(--error); border-radius: 10px; color: var(--error); font-weight: 600; }

.row { display: flex; gap: 8px; flex-wrap: wrap; }

/* Start page */
#home { padding-top: 24px; }
.big { width: 100%; min-height: 64px; font-size: 1.2rem; }
.big svg { width: 28px; height: 28px; }
#home .hint { margin: 10px 0 0; }

/* Profile: the name (start page only) */
.profile { margin: 0 0 24px; }
.profile label[for=name] { display: block; font-weight: 600; margin: 8px 0 4px; }
.profile #name { width: 100%; min-height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.avatars { display: grid; grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); gap: 6px; }
.avatar-choice { display: flex; align-items: center; justify-content: center; min-height: 60px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); cursor: pointer; }
.avatar-choice .face { font-size: 2.4rem; line-height: 1; }
.avatar-choice:disabled { opacity: .35; }
.lobby { grid-template-columns: repeat(5, 1fr); }
.lobby .avatar-choice { flex-direction: column; gap: 2px; min-height: 78px; padding: 4px 2px; }
.lobby .avatar-choice[aria-pressed="true"] { border: 3px solid var(--accent); background: var(--surface); }
.lobby .owner { max-width: 100%; font-size: .7rem; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lobby .owner:empty { display: none; }

/* Lobby: choose a free avatar for this session */
.avatar-dialog { width: min(30rem, calc(100% - 32px)); padding: 18px; border: 2px solid var(--line); border-radius: 14px; background: var(--bg); color: var(--text); }
.avatar-dialog::backdrop { background: rgba(0, 0, 0, .5); }
.avatar-dialog h2 { margin-bottom: 8px; }
.avatar-dialog button.avatar-choice { padding: 0; }

/* Players with their points: while scanning and in the running scans */
.players { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.players li { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 6px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); }
.players li.me { border: 2px solid var(--accent); }
.players .avatar { font-size: 1.9rem; line-height: 1; }
.players .who { font-weight: 600; overflow-wrap: anywhere; }
.players .score { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Running scans on the start page */
#running { margin-top: 28px; }
.sessions { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 12px; }
.session { padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.session > p { margin: 0 0 8px; }
.session .players li { background: var(--bg); }

/* While scanning the players float over the page as bubbles (avatar + points), so they take no
   room from the cart: drag them aside, tap to show the names. */
#players-section { position: fixed; left: 8px; bottom: 12px; z-index: 3; touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; }
#players-section .players { flex-direction: column; flex-wrap: nowrap; margin: 0; }
#players-section li { position: relative; width: 58px; height: 58px; padding: 0; justify-content: center; border-width: 2px; box-shadow: 0 2px 8px rgba(0, 0, 0, .35); }
#players-section .avatar { font-size: 2.2rem; }
#players-section .score { position: absolute; right: -6px; bottom: -4px; min-width: 22px; height: 22px; padding: 0 5px; border-radius: 11px;
  display: flex; align-items: center; justify-content: center; background: var(--accent); color: var(--accent-ink); font-size: .8rem; font-weight: 700; }
#players-section .unit, #players-section:not(.open) .who { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
#players-section.open li { width: auto; padding: 0 30px 0 6px; justify-content: flex-start; }
#players-section.open .who { max-width: 12rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session .hint { margin: 8px 0 10px; }
.session button { width: 100%; }
.manual { margin-top: 18px; }
.manual label { display: block; font-weight: 600; margin-bottom: 4px; }
.manual input { flex: 1; min-width: 0; min-height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  font-family: ui-monospace, monospace; font-size: 1.1rem; letter-spacing: .05em; }
.manual input[aria-invalid="true"] { border: 2px solid var(--error); }
.hint { margin: 4px 0 0; color: var(--muted); font-size: .9rem; }
.field-error { margin: 4px 0 0; color: var(--error); font-weight: 600; }
.field-error::before { content: "✕ "; }

/* The product just scanned. */
.card { margin: 18px 0; padding: 14px; border: 2px solid var(--ok); border-radius: 14px; background: var(--surface); }
.card .info { margin: 0 0 10px; color: var(--muted); overflow-wrap: anywhere; }
.qty { display: flex; align-items: center; gap: 6px; }
.step { font-size: 1.4rem; font-weight: 700; padding: 0; width: 48px; }
.count { min-width: 3ch; text-align: center; font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.remove { margin-left: auto; }
.remove.icon { padding: 0; width: 44px; }

.list { list-style: none; margin: 8px 0 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list .what { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.list .name { overflow-wrap: anywhere; }
.list .info { color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }
.list .qty { flex: none; }
.others { margin: 0; color: var(--muted); font-size: .9rem; min-height: 0; }
#list-section { margin-top: 24px; }
#list-title { scroll-margin-top: 70px; }

@media (prefers-reduced-motion: no-preference) {
  .frame { transition: border-color .15s; }
}
