:root {
  --accent: #e11d2e;
  --accent-dim: #8f1420;
  --bg: #101216;
  --surface: #1a1d23;
  --surface-2: #23272f;
  --line: #2e333d;
  --text: #eceef1;
  --muted: #99a1ae;
  --radius: 14px;
  --tap: 44px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

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

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---------- top bar ---------- */

.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.bar__title {
  flex: 1;
  margin: 0;
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.bar__title mark {
  background: none;
  color: var(--accent);
}

.icon-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.icon-btn:active { background: var(--surface-2); }
.icon-btn--accent { color: var(--accent); }
.icon-btn svg { width: 24px; height: 24px; }

.page {
  flex: 1;
  padding: 16px 16px calc(env(safe-area-inset-bottom) + 32px);
}

/* ---------- card grid ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.tile {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1.586;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface-2) center / cover no-repeat;
  color: #fff;
  text-align: left;
  cursor: pointer;
  transition: transform 0.12s ease;
}

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

.tile__shade {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgb(0 0 0 / 72%) 0%, rgb(0 0 0 / 12%) 55%, transparent 100%);
}

.tile__name {
  position: absolute;
  right: 10px;
  bottom: 8px;
  left: 10px;
  font-size: 15px;
  font-weight: 650;
  line-height: 1.25;
  text-shadow: 0 1px 3px rgb(0 0 0 / 55%);
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.tile__tail {
  position: absolute;
  top: 8px;
  left: 10px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
  color: rgb(255 255 255 / 72%);
  text-shadow: 0 1px 3px rgb(0 0 0 / 55%);
}

/* ---------- empty state ---------- */

.empty {
  margin-top: 12vh;
  text-align: center;
}

.empty h2 {
  margin: 0 0 8px;
  font-size: 19px;
}

.empty p {
  max-width: 34ch;
  margin: 0 auto 20px;
  color: var(--muted);
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 550;
  cursor: pointer;
}

.btn:active { filter: brightness(1.25); }

.btn--primary {
  border-color: transparent;
  background: var(--accent);
  color: #fff;
}

.btn--ghost {
  background: transparent;
}

.btn--danger {
  border-color: transparent;
  background: color-mix(in srgb, var(--accent) 18%, var(--surface));
  color: #ff8e98;
}

.btn--block {
  width: 100%;
}

.btn[disabled] {
  opacity: 0.45;
  cursor: default;
}

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

/* ---------- card display ---------- */

.show {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: stretch;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
}

.face {
  /* Grows to fill the screen so the barcode is as physically large as it can
     be. Size is what makes a scanner read it off glass. */
  flex: 1;
  display: grid;
  /* minmax(0, 1fr) stops an oversized child (a rotated barcode, a long number)
     from stretching the track and pushing the layout sideways. */
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  align-content: center;
  gap: 18px;
  padding: 20px 14px 16px;
  overflow: hidden;
  border-radius: var(--radius);
  background: #fff;
  color: #000;
}

.face__code {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 120px;
}

.face__code svg {
  display: block;
  width: 100%;
  height: auto;
}

/* Rotated so a 1D barcode uses the long axis of the screen, which makes it
   physically bigger and easier for a scanner to read. Absolutely positioned
   because a rotated box keeps its original layout size, and letting that size
   participate in the grid pushes the barcode off centre. */
.face--rotated {
  position: relative;
}

.face--rotated .face__code {
  position: absolute;
  top: 50%;
  left: 50%;
  /* This is the barcode's length once rotated, so it stays inside the panel
     rather than pushing the controls off screen. */
  width: 68dvh;
  transform: translate(-50%, -50%) rotate(90deg);
}

.face--qr .face__code {
  max-width: min(320px, 76vw);
}

.face__digits {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: clamp(17px, 5.2vw, 26px);
  font-weight: 600;
  letter-spacing: 0.14em;
  text-align: center;
  word-break: break-all;
}

.face--rotated .face__digits { display: none; }

.face__error {
  padding: 8px 0;
  color: var(--accent-dim);
  text-align: center;
}

.face__photo {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
}

.show__name {
  margin: 0;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.show__note {
  margin: 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--surface);
  color: var(--muted);
  white-space: pre-wrap;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

/* ---------- forms ---------- */

.field {
  margin-bottom: 16px;
}

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

input[type="text"],
select,
textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  /* 16px minimum stops iOS Safari zooming the page on focus. */
  font-size: 16px;
}

textarea { resize: vertical; }

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

.field--inline {
  display: flex;
  gap: 8px;
}

.field--inline input { flex: 1; }

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.04em;
}

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

.swatch {
  width: 36px;
  height: 36px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 50%;
  cursor: pointer;
}

.swatch[aria-pressed="true"] {
  border-color: var(--text);
  box-shadow: 0 0 0 2px var(--bg) inset;
}

.preview {
  margin-bottom: 16px;
  padding: 14px;
  border-radius: var(--radius);
  background: #fff;
}

.preview__empty {
  padding: 20px 0;
  color: #666;
  text-align: center;
}

.thumb {
  display: block;
  width: 100%;
  max-width: 220px;
  margin-bottom: 10px;
  border-radius: 10px;
}

/* ---------- settings ---------- */

.section {
  margin-bottom: 28px;
}

.section h2 {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.section p {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 14px;
}

.banner {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--line));
  border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  font-size: 14px;
}

.banner span { flex: 1; }

.banner a {
  color: var(--text);
  font-weight: 600;
  white-space: nowrap;
}

/* ---------- toast ---------- */

#toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  left: 50%;
  z-index: 50;
  max-width: 80vw;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgb(0 0 0 / 45%);
  transform: translateX(-50%);
  font-size: 14px;
  animation: toast-in 0.18s ease;
}

#toast[hidden] { display: none; }

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
