:root {
  --bg: #f2f2f7;
  --surface: #ffffff;
  --surface-sunken: #e9e9ee;
  --text: #1c1c1e;
  --muted: #6e6e73;
  --line: rgba(0, 0, 0, 0.08);
  --accent: #3b5bdb;
  --danger: #d64545;
  --radius: 18px;
  --pad: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-sunken: #2c2c2e;
    --text: #f5f5f7;
    --muted: #98989d;
    --line: rgba(255, 255, 255, 0.12);
    --accent: #7a91f5;
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.02em;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
}

input,
select,
textarea {
  font: inherit;
  color: var(--text);
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  appearance: none;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.page {
  min-height: 100dvh;
  padding: calc(var(--safe-top) + 12px) var(--pad) calc(var(--safe-bottom) + 96px);
  max-width: 720px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  margin-bottom: 18px;
}

.topbar h1 {
  font-size: 30px;
  flex: 1;
}

.topbar .spacer {
  flex: 1;
}

.iconbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  border-radius: 999px;
  color: var(--accent);
  font-size: 16px;
  font-weight: 600;
}

.iconbtn:active {
  background: var(--surface-sunken);
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  aspect-ratio: 8 / 5;
  padding: 14px;
  border-radius: var(--radius);
  color: #fff;
  text-align: left;
  text-decoration: none;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.16);
}

.tile:active {
  transform: scale(0.975);
}

.tile .initials {
  position: absolute;
  top: 8px;
  right: 12px;
  font-size: 44px;
  font-weight: 800;
  letter-spacing: -0.04em;
  opacity: 0.28;
  line-height: 1;
}

.tile .name {
  font-size: 16px;
  font-weight: 650;
  line-height: 1.2;
  overflow-wrap: anywhere;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

.searchbar {
  margin-bottom: 16px;
}

.empty {
  padding: 48px 8px;
  text-align: center;
  color: var(--muted);
}

.empty h2 {
  margin-bottom: 8px;
  font-size: 20px;
  color: var(--text);
}

.fab {
  position: fixed;
  right: max(var(--pad), calc(50% - 360px + var(--pad)));
  bottom: calc(var(--safe-bottom) + 20px);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 20px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 650;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.24);
}

.fab:active {
  transform: scale(0.97);
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.hint {
  margin-top: 6px;
  font-size: 14px;
  color: var(--muted);
}

.error {
  margin-top: 6px;
  font-size: 14px;
  color: var(--danger);
}

.banner {
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 15px;
  margin-bottom: 16px;
}

.banner.warn {
  border-color: color-mix(in srgb, var(--danger) 40%, transparent);
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 50px;
  padding: 0 18px;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 650;
}

.btn:disabled {
  opacity: 0.45;
}

.btn.secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
}

.btn.danger {
  background: none;
  color: var(--danger);
}

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.swatch {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 2px solid transparent;
}

.swatch[aria-pressed="true"] {
  border-color: var(--text);
  outline: 2px solid var(--bg);
  outline-offset: -5px;
}

.preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 16px;
  border-radius: var(--radius);
  background: #fff;
  min-height: 140px;
  justify-content: center;
}

.preview canvas {
  display: block;
  max-width: 100%;
}

.card-screen {
  min-height: 100dvh;
  background: #fff;
  color: #000;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 8px) 16px calc(var(--safe-bottom) + 16px);
}

.card-screen .topbar .iconbtn {
  color: #1c1c1e;
}

.card-screen h1 {
  font-size: 26px;
  text-align: center;
  margin: 4px 0 20px;
  overflow-wrap: anywhere;
}

.card-screen .stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  width: 100%;
}

.card-screen canvas {
  display: block;
  max-width: 100%;
  image-rendering: pixelated;
}

.card-number {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 20px;
  letter-spacing: 0.08em;
  text-align: center;
  overflow-wrap: anywhere;
  user-select: all;
  -webkit-user-select: all;
}

.card-note {
  font-size: 15px;
  color: #6e6e73;
  text-align: center;
  overflow-wrap: anywhere;
}

.scanner {
  position: fixed;
  inset: 0;
  background: #000;
  display: flex;
  flex-direction: column;
}

.scanner video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scanner .veil {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 24px;
  color: #fff;
  text-align: center;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}

.scanner .reticle {
  width: min(84vw, 420px);
  aspect-ratio: 3 / 2;
  border: 3px solid rgba(255, 255, 255, 0.9);
  border-radius: 16px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.45);
}

.scanner .controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(var(--safe-bottom) + 24px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0 24px;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.status .dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--muted);
}

.status.synced .dot {
  background: #34a853;
}

.status.offline .dot {
  background: #e8a33d;
}

.status.error .dot {
  background: var(--danger);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.centered {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  max-width: 420px;
  margin: 0 auto;
}

.loading-progress {
  display: block;
  width: 6rem;
  height: 6rem;
  margin: 30vh auto 0;
}

.loading-progress circle {
  fill: none;
  stroke: var(--surface-sunken);
  stroke-width: 0.5rem;
  transform-origin: 50% 50%;
  transform: rotate(-90deg);
}

.loading-progress circle:last-child {
  stroke: var(--accent);
  stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
  transition: stroke-dasharray 0.05s ease-in-out;
}

.loading-progress-text {
  margin-top: 1rem;
  text-align: center;
  color: var(--muted);
  font-weight: 600;
}

.loading-progress-text::after {
  content: var(--blazor-load-percentage-text, "Chargement");
}

#blazor-error-ui {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  padding: 14px 20px;
  background: #ffe8a8;
  color: #1c1c1e;
  box-shadow: 0 -1px 6px rgba(0, 0, 0, 0.2);
}

#blazor-error-ui .dismiss {
  float: right;
  cursor: pointer;
}
