:root {
  color-scheme: light;
  --burgundy: #6d001a;
  --burgundy-dark: #41000f;
  --gold: #9a7412;
  --cream: #fbf8f0;
  --ink: #231b1d;
  --muted: #74696c;
  --line: #ded5d0;
  --green: #12633d;
  --red: #9f1c2e;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: linear-gradient(145deg, #f8f2e6, #fff 45%, #f6ecef);
}

button, input { font: inherit; }

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: max(1rem, env(safe-area-inset-top)) 1rem 1rem;
  color: white;
  background: linear-gradient(135deg, var(--burgundy-dark), var(--burgundy));
  border-bottom: 4px solid var(--gold);
}

.topbar h1 { margin: .15rem 0; font-size: clamp(1.55rem, 6vw, 2.25rem); }
.topbar p { margin: 0; opacity: .9; }
.eyebrow { font-size: .72rem; font-weight: 800; letter-spacing: .13em; }

main {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 1rem 1rem 3rem;
}

.panel, .result-card, .notice {
  margin: 1rem 0;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255,255,255,.94);
  box-shadow: 0 12px 30px rgba(61, 24, 32, .08);
}

.result-card {
  min-height: 175px;
  display: grid;
  place-content: center;
  text-align: center;
  border-width: 3px;
  transition: background .2s, border-color .2s, transform .2s;
}

.result-card strong {
  display: block;
  max-width: 100%;
  margin: .55rem 0;
  overflow-wrap: anywhere;
  font-size: clamp(2rem, 9vw, 4.4rem);
  line-height: 1.03;
}

.result-card span { font-weight: 900; letter-spacing: .1em; }
.result-card small { font-size: 1rem; }
.result-card.waiting { border-color: var(--gold); }
.result-card.success { color: #fff; background: var(--green); border-color: #0a4026; transform: scale(1.01); }
.result-card.repeat { color: #2c2100; background: #f5d96d; border-color: var(--gold); }

#reader {
  width: 100%;
  min-height: 80px;
  overflow: hidden;
  border-radius: 14px;
  background: #150d0f;
}

#reader video { border-radius: 14px; }

.actions { display: flex; gap: .7rem; margin-top: 1rem; flex-wrap: wrap; }
.actions.compact { margin-top: .5rem; }

.button {
  min-height: 48px;
  padding: .7rem 1rem;
  border: 0;
  border-radius: 12px;
  font-weight: 800;
  cursor: pointer;
}

.button:disabled { opacity: .45; cursor: not-allowed; }
.button.primary { flex: 1; color: #fff; background: var(--burgundy); }
.button.secondary { color: var(--burgundy-dark); background: #efe7dc; }
.button.danger { color: #fff; background: var(--red); }
.status, .empty { color: var(--muted); }

details summary { cursor: pointer; font-weight: 800; }
details form { margin-top: 1rem; }
label { display: block; margin-bottom: .4rem; font-weight: 700; }
.manual-row { display: flex; gap: .5rem; }
input { min-width: 0; flex: 1; padding: .75rem; border: 1px solid var(--line); border-radius: 10px; }

.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
h2 { margin: .15rem 0; }
.count { display: grid; place-items: center; min-width: 50px; height: 50px; border-radius: 50%; color: #fff; background: var(--burgundy); }
.history-list { margin: 1rem 0 0; padding: 0; list-style: none; }
.history-item { display: grid; grid-template-columns: 1fr auto; gap: .75rem; padding: .85rem 0; border-top: 1px solid var(--line); }
.history-item strong { overflow-wrap: anywhere; }
.history-item small { display: block; color: var(--muted); margin-top: .2rem; }
.repeat-pill { align-self: center; padding: .25rem .5rem; border-radius: 999px; background: #f5d96d; font-size: .72rem; font-weight: 900; }
.notice { border-left: 6px solid var(--gold); background: var(--cream); }
footer { padding: 1.5rem; text-align: center; color: var(--muted); }
.hidden { display: none !important; }

.toast {
  position: fixed;
  left: 50%;
  bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: 10;
  max-width: calc(100% - 2rem);
  padding: .8rem 1rem;
  border-radius: 12px;
  color: white;
  background: #241b1d;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 1rem);
  transition: .2s;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 540px) {
  .topbar { align-items: flex-start; }
  .topbar .button { min-height: 40px; padding: .55rem .7rem; }
  .manual-row { flex-direction: column; }
  .actions .button { flex: 1; }
}
