@font-face {
  font-family: "Roboto Serif";
  src: url("../fonts/RobotoSerif-Light.woff2") format("woff2");
  font-weight: 300; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Roboto Serif";
  src: url("../fonts/RobotoSerif-Regular.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Roboto Serif";
  src: url("../fonts/RobotoSerif-Medium.woff2") format("woff2");
  font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Roboto Serif";
  src: url("../fonts/RobotoSerif-SemiBold.woff2") format("woff2");
  font-weight: 600; font-style: normal; font-display: swap;
}

:root {
  --rose:       #d99ea6;
  --rose-deep:  #b87c85;
  --rose-soft:  #e8bcb9;
  --rose-pale:  #f4e0de;

  --blue:   #b0c1c8;
  --sage:   #9da598;
  --yellow: #f6e4a6;

  --cream:      #fbf5ec;
  --paper:      #fefaf3;
  --ink:        #443134;
  --ink-soft:   #7c6265;

  --tint-bg:    #e6bfbb;
  --tint-text:  #402a2e;
  --backdrop:   #3a2225;

  --present:      #6e9d7a;
  --present-soft: rgba(110, 157, 122, 0.14);
  --danger:       #b0555a;
  --danger-soft:  rgba(176, 85, 90, 0.12);
  --warn:         #c48f34;
  --warn-soft:    rgba(196, 143, 52, 0.14);

  --on-dark:    #fbf1ee;

  --line:         rgba(68, 49, 52, 0.12);
  --line-on-tint: rgba(64, 42, 46, 0.16);

  --serif: "Roboto Serif", Georgia, serif;

  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
  --sp-5: 24px; --sp-6: 32px; --sp-7: 48px;

  --r-sm: 10px; --r-md: 16px; --r-lg: 22px; --r-pill: 999px;
  --shadow-card:  0 12px 30px -22px rgba(58, 34, 37, 0.4);
  --shadow-float: 0 12px 28px -10px rgba(58, 34, 37, 0.5);

  --col: 520px;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--serif);
  font-weight: 300;
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--cream);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input { font-family: inherit; }
.icon {
  width: 24px; height: 24px;
  stroke: currentColor; stroke-width: 1.6;
  fill: none; stroke-linecap: round; stroke-linejoin: round;
  flex: none;
}

.eyebrow {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 0.68rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--rose-deep);
}

/* ============ LOCK ============ */
.lock {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-5);
  background: var(--tint-bg);
  color: var(--tint-text);
  position: relative;
}
.lock::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at top, rgba(255, 255, 255, 0.28), transparent 60%);
  pointer-events: none;
}
.lock__card {
  position: relative;
  width: 100%;
  max-width: 380px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--sp-6) var(--sp-5);
  text-align: center;
  box-shadow: 0 24px 40px -18px rgba(58, 34, 37, 0.28);
}
.lock__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px; height: 56px;
  border-radius: var(--r-pill);
  background: var(--rose-pale);
  border: 1px solid var(--rose);
  color: var(--rose-deep);
  margin-bottom: var(--sp-4);
}
.lock__badge .icon { width: 26px; height: 26px; }
.lock__title {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: 1.8rem;
  margin: var(--sp-2) 0 var(--sp-1);
  color: var(--ink);
}
.lock__sub {
  color: var(--ink-soft);
  font-size: 0.92rem;
  margin-bottom: var(--sp-5);
}
.lock__label {
  display: block;
  text-align: left;
  font-size: 0.72rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--rose-deep);
  margin-bottom: var(--sp-2);
  font-weight: 500;
}
.lock__input {
  width: 100%;
  min-height: 60px;
  font-family: var(--serif);
  font-size: 1.4rem;
  font-weight: 500;
  letter-spacing: 0.4em;
  text-align: center;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 0 var(--sp-3);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.lock__input:focus {
  outline: none;
  border-color: var(--rose-deep);
  box-shadow: 0 0 0 3px rgba(184, 124, 133, 0.18);
}
.lock__submit {
  width: 100%;
  min-height: 54px;
  margin-top: var(--sp-4);
  border-radius: var(--r-pill);
  background: var(--rose-deep);
  color: var(--paper);
  font-weight: 500;
  font-size: 0.96rem;
  letter-spacing: 0.06em;
  transition: transform 0.18s var(--ease), background 0.2s var(--ease);
  touch-action: manipulation;
  box-shadow: 0 8px 24px -10px rgba(184, 124, 133, 0.5);
}
.lock__submit:active { transform: translateY(1px); background: #9a6570; }
.lock__submit[disabled] { opacity: 0.6; pointer-events: none; }
.lock__error {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  margin-top: var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-sm);
  background: var(--danger-soft);
  border: 1px solid rgba(176, 85, 90, 0.3);
  color: var(--danger);
  font-size: 0.88rem;
}
.lock__error .icon { width: 18px; height: 18px; }
.lock__error[hidden] { display: none; }

/* ============ APP ============ */
.app {
  max-width: var(--col);
  margin: 0 auto;
  min-height: 100dvh;
  padding: max(env(safe-area-inset-top), 12px) var(--sp-4) calc(env(safe-area-inset-bottom) + 110px);
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-3);
  padding-bottom: var(--sp-4);
}
.topbar__h1 {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: 1.6rem;
  color: var(--ink);
  margin-top: var(--sp-1);
}
.topbar__actions { display: flex; gap: var(--sp-2); flex: none; }
.icon-btn {
  width: 44px; height: 44px;
  border-radius: var(--r-pill);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--paper);
  color: var(--ink-soft);
  border: 1px solid var(--line);
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
  touch-action: manipulation;
}
.icon-btn:active { background: var(--rose-deep); color: var(--paper); }

/* ============ EVENT SEGMENTS ============ */
.event-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-2);
  margin-bottom: var(--sp-4);
}
.event-seg {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 52px;
  padding: 0 var(--sp-3);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  color: var(--ink-soft);
  font-weight: 500;
  font-size: 0.86rem;
  letter-spacing: 0.04em;
  transition: background 0.2s var(--ease), color 0.2s var(--ease), border-color 0.2s var(--ease);
  touch-action: manipulation;
  box-shadow: var(--shadow-card);
}
.event-seg .icon { width: 20px; height: 20px; }
.event-seg.is-active {
  background: var(--rose-deep);
  color: var(--paper);
  border-color: var(--rose-deep);
}
.event-seg__count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px; height: 20px;
  padding: 0 6px;
  border-radius: var(--r-pill);
  background: rgba(0, 0, 0, 0.06);
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
}
.event-seg.is-active .event-seg__count { background: rgba(255, 255, 255, 0.24); }

/* ============ SUMMARY ============ */
.summary {
  text-align: center;
  padding: var(--sp-5) var(--sp-4);
  background: var(--rose-pale);
  border: 1px solid var(--rose-soft);
  border-radius: var(--r-md);
  margin-bottom: var(--sp-4);
  box-shadow: var(--shadow-card);
}
.summary__num {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 2.4rem;
  line-height: 1;
  color: var(--rose-deep);
  font-variant-numeric: tabular-nums;
}
.summary__label {
  margin-top: var(--sp-2);
  color: var(--ink-soft);
  font-size: 0.86rem;
}

/* ============ HISTORY CARDS ============ */
.history { position: relative; min-height: 240px; }
.cards {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}
.card {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-4);
  box-shadow: var(--shadow-card);
  position: relative;
}
.card__hand {
  width: 44px; height: 44px;
  border-radius: var(--r-pill);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--present);
  background: var(--present-soft);
  border: 1px solid rgba(110, 157, 122, 0.42);
  flex: none;
}
.card__hand .icon { width: 22px; height: 22px; stroke-width: 1.7; }
.card__body { flex: 1; min-width: 0; }
.card__name {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.02rem;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card__meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  margin-top: var(--sp-1);
  color: var(--ink-soft);
  font-size: 0.84rem;
}
.card__time {
  font-variant-numeric: tabular-nums;
  color: var(--rose-deep);
  font-weight: 500;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
}
.card__ref {
  font-family: var(--serif);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.14em;
  font-size: 0.74rem;
  color: var(--ink-soft);
  font-weight: 500;
}

/* Etats vides / erreurs / chargement */
.loading, .empty, .error {
  text-align: center;
  padding: var(--sp-6) var(--sp-4);
  color: var(--ink-soft);
}
.loading { display: flex; flex-direction: column; align-items: center; gap: var(--sp-3); }
.empty { display: flex; flex-direction: column; align-items: center; gap: var(--sp-3); }
.empty .icon { width: 44px; height: 44px; color: var(--rose); opacity: 0.7; }
.empty p { max-width: 30ch; line-height: 1.6; }
.spinner {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid var(--line);
  border-top-color: var(--rose-deep);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.error {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  margin: var(--sp-3) auto;
  background: var(--danger-soft);
  border: 1px solid rgba(176, 85, 90, 0.28);
  border-radius: var(--r-sm);
  color: var(--danger);
  font-size: 0.88rem;
}
.error .icon { width: 18px; height: 18px; }

/* ============ FAB SCANNER ============ */
.fab {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 40;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-6);
  min-height: 60px;
  border-radius: var(--r-pill);
  background: var(--rose-deep);
  color: var(--paper);
  font-weight: 500;
  font-size: 1rem;
  letter-spacing: 0.06em;
  box-shadow: 0 18px 36px -10px rgba(184, 124, 133, 0.55);
  transition: transform 0.2s var(--ease), background 0.2s var(--ease);
  touch-action: manipulation;
}
.fab .icon { width: 26px; height: 26px; }
.fab:active { transform: translateX(-50%) translateY(1px); background: #9a6570; }
.fab[hidden] { display: none; }

/* ============ SCANNER FULLSCREEN ============ */
.scanner {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #000;
  overflow: hidden;
}
.scanner[hidden] { display: none; }
.scanner video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.scanner canvas { display: none; }

.scanner__overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(env(safe-area-inset-top), 16px) var(--sp-4) max(env(safe-area-inset-bottom), 24px);
  color: var(--on-dark);
  background:
    linear-gradient(to bottom, rgba(0,0,0,0.55) 0%, rgba(0,0,0,0) 22%, rgba(0,0,0,0) 78%, rgba(0,0,0,0.6) 100%);
}
.scanner__top {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
}
.scanner__close, .scanner__flash {
  width: 48px; height: 48px;
  border-radius: var(--r-pill);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
  color: var(--paper);
  border: 1px solid rgba(255, 255, 255, 0.18);
  touch-action: manipulation;
}
.scanner__close .icon, .scanner__flash .icon { width: 22px; height: 22px; }
.scanner__flash[hidden] { display: none; }
.scanner__flash.is-on { background: var(--yellow); color: var(--ink); }

.scanner__event {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 10px var(--sp-4);
  border-radius: var(--r-pill);
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.18);
  font-weight: 500;
  font-size: 0.86rem;
  letter-spacing: 0.05em;
}
.scanner__event .icon { width: 18px; height: 18px; }

.scanner__frame {
  position: relative;
  margin-top: auto;
  margin-bottom: auto;
  width: min(72vw, 300px);
  aspect-ratio: 1 / 1;
}
.corner {
  position: absolute;
  width: 42px;
  height: 42px;
  border: 3px solid var(--rose-soft);
}
.corner.tl { top: 0; left: 0; border-right: none; border-bottom: none; border-top-left-radius: 12px; }
.corner.tr { top: 0; right: 0; border-left: none; border-bottom: none; border-top-right-radius: 12px; }
.corner.bl { bottom: 0; left: 0; border-right: none; border-top: none; border-bottom-left-radius: 12px; }
.corner.br { bottom: 0; right: 0; border-left: none; border-top: none; border-bottom-right-radius: 12px; }
.scanner__frame::after {
  content: "";
  position: absolute;
  left: 6%;
  right: 6%;
  top: 50%;
  height: 2px;
  background: var(--rose-soft);
  box-shadow: 0 0 12px var(--rose);
  opacity: 0.85;
  animation: scanline 2s ease-in-out infinite;
}
@keyframes scanline {
  0%   { transform: translateY(-46%); opacity: 0.4; }
  50%  { transform: translateY(46%);  opacity: 0.95; }
  100% { transform: translateY(-46%); opacity: 0.4; }
}

.scanner__hint {
  margin-top: var(--sp-4);
  text-align: center;
  padding: 10px var(--sp-4);
  border-radius: var(--r-pill);
  background: rgba(0, 0, 0, 0.55);
  font-size: 0.9rem;
  max-width: 90%;
}

/* ============ FEEDBACK OVERLAY ============ */
.feedback {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  animation: fadein 0.2s var(--ease);
}
.feedback[hidden] { display: none; }
.feedback__card {
  width: min(88vw, 340px);
  padding: var(--sp-6) var(--sp-5);
  text-align: center;
  border-radius: var(--r-lg);
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.55);
}
.feedback__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 72px; height: 72px;
  border-radius: var(--r-pill);
  margin-bottom: var(--sp-4);
}
.feedback__icon .icon { width: 40px; height: 40px; stroke-width: 2; }
.feedback__title {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.35rem;
  margin-bottom: var(--sp-2);
}
.feedback__sub {
  color: var(--ink-soft);
  font-size: 0.95rem;
  line-height: 1.5;
}
.feedback__card.is-success .feedback__icon { background: var(--present-soft); color: var(--present); }
.feedback__card.is-warn    .feedback__icon { background: var(--warn-soft);    color: var(--warn); }
.feedback__card.is-error   .feedback__icon { background: var(--danger-soft);  color: var(--danger); }

@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* ============ TOAST ============ */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(100px + env(safe-area-inset-bottom));
  z-index: 200;
  transform: translate(-50%, 20px);
  max-width: calc(var(--col) - 40px);
  width: max-content;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 12px var(--sp-4);
  border-radius: var(--r-pill);
  background: var(--ink);
  color: var(--paper);
  font-size: 0.86rem;
  box-shadow: var(--shadow-float);
  opacity: 0; pointer-events: none;
  transition: opacity 0.28s var(--ease), transform 0.28s var(--ease);
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast .icon { width: 18px; height: 18px; color: var(--rose-soft); }

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