:root {
  --bg: #f2f3f5;
  --surface: #ffffff;
  --surface-2: #e9ebee;
  --text: #111418;
  --muted: #6b7280;
  --line: #dfe2e6;
  --accent: #1e5eff;
  --accent-text: #ffffff;
  --danger: #d93025;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .08);
  --radius: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1013;
    --surface: #1a1d22;
    --surface-2: #24282e;
    --text: #f1f3f5;
    --muted: #9aa1ab;
    --line: #2c3037;
    --accent: #6e9bff;
    --accent-text: #0b1530;
    --danger: #ff6b5e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  overscroll-behavior-y: none;
}
body.locked { overflow: hidden; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, select { font: inherit; color: inherit; }
svg { width: 24px; height: 24px; fill: currentColor; flex: none; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.spacer { flex: 1; }

.icon-btn {
  width: 44px; height: 44px; border-radius: 50%;
  display: inline-grid; place-items: center;
}
.icon-btn:active { background: color-mix(in srgb, currentColor 14%, transparent); }
.icon-btn.small { width: 40px; height: 40px; }
.text-btn {
  color: var(--accent); font-weight: 650; padding: 10px 14px; border-radius: 999px;
}
.text-btn:disabled { opacity: .4; }

/* ---------- Home ---------- */
.home-header {
  display: flex; align-items: flex-end; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 56px) 16px 12px 20px;
}
.home-header h1 { margin: 0; font-size: 34px; font-weight: 750; letter-spacing: -.02em; }
.home-header p { margin: 2px 0 0; font-size: 14px; }

.search-wrap {
  position: sticky; top: 0; z-index: 5;
  padding: 8px 16px 12px; background: var(--bg);
}
.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); border-radius: 999px; padding: 0 16px; height: 46px;
  color: var(--muted);
}
.search input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: none; color: var(--text); height: 100%;
}
.search input::-webkit-search-cancel-button { filter: grayscale(1); }

.grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px;
  padding: 4px 16px calc(env(safe-area-inset-bottom) + 104px);
}
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 860px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); max-width: 1000px; margin: 0 auto; } }

.tile {
  position: relative; overflow: hidden;
  aspect-ratio: 1.586; border-radius: var(--radius);
  background: var(--c, #455a64); color: var(--fg, #fff);
  display: grid; place-items: center; padding: 12px; text-align: center;
  box-shadow: var(--shadow);
  transition: transform .12s ease;
}
.tile::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(135deg, rgba(255,255,255,.18), rgba(255,255,255,0) 45%, rgba(0,0,0,.08));
}
.tile:active { transform: scale(.97); }
.tile-name {
  font-weight: 750; letter-spacing: -.01em; line-height: 1.15;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  overflow-wrap: anywhere;
}
.tile-name.l { font-size: 24px; }
.tile-name.m { font-size: 19px; }
.tile-name.s { font-size: 15px; }

.empty { text-align: center; padding: 40px 32px; }
.empty h2 { margin: 16px 0 4px; font-size: 20px; }
.empty p { margin: 0; }
.empty-art {
  width: 132px; height: 84px; margin: 0 auto; border-radius: 14px;
  background: var(--surface-2); position: relative;
}
.empty-art::before {
  content: ""; position: absolute; left: 18px; right: 18px; top: 24px; height: 36px;
  background: repeating-linear-gradient(90deg, var(--muted) 0 3px, transparent 3px 6px, var(--muted) 6px 7px, transparent 7px 11px);
  opacity: .5; border-radius: 2px;
}

.fab {
  position: fixed; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 20px); z-index: 10;
  display: flex; align-items: center; gap: 8px;
  height: 56px; padding: 0 22px 0 18px; border-radius: 18px;
  background: var(--accent); color: var(--accent-text); font-weight: 650;
  box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 40%, transparent);
}
.fab:active { transform: scale(.97); }

/* ---------- Full-screen views ---------- */
.view {
  position: fixed; inset: 0; z-index: 20; overflow-y: auto;
  background: var(--bg);
  animation: slide-in .22s cubic-bezier(.2, .8, .2, 1);
}
@keyframes slide-in { from { transform: translateY(24px); opacity: 0; } }
@keyframes fade-in { from { opacity: 0; } }

.bar {
  display: flex; align-items: center; gap: 4px;
  padding: calc(env(safe-area-inset-top) + 6px) 6px 6px;
}

/* Card view */
.card-head {
  background: var(--c); color: var(--fg);
  padding-bottom: 88px;
}
.cv-name {
  margin: 8px 20px 0; font-size: 30px; font-weight: 750; letter-spacing: -.02em;
  overflow-wrap: anywhere;
}
.ticket-wrap { padding: 0 16px calc(env(safe-area-inset-bottom) + 24px); margin-top: -72px; }
.ticket {
  display: block; width: 100%;
  background: #fff; color: #111; border-radius: 20px;
  padding: 28px 22px 20px; box-shadow: var(--shadow);
}
.code { display: grid; place-items: center; color: #000; }
.code svg, .code-preview svg { fill: #000; }
.code svg { width: 100%; height: auto; max-height: 46vh; }
.code.two-d svg { width: min(72%, 300px); }
.code.none { display: none; }
.number {
  margin-top: 14px; text-align: center; color: #111;
  font: 600 20px/1.3 ui-monospace, "SF Mono", "Roboto Mono", monospace;
  letter-spacing: .08em; overflow-wrap: anywhere;
}
.code.none + .number { font-size: 30px; padding: 24px 0; }
.note { margin: 16px 4px 0; font-size: 15px; white-space: pre-wrap; }
.note:empty { display: none; }
.hint { margin: 16px 4px 0; font-size: 13px; text-align: center; }

/* Enlarged barcode */
.big-view { background: #fff; animation: fade-in .15s ease; }
.big-inner {
  width: 100%; min-height: 100%; display: flex; flex-direction: column; justify-content: center;
  padding: 24px 12px;
}
.big-inner .code svg { max-height: 70vh; }
.big-inner .code.two-d svg { width: min(92%, 520px); }
.big-inner .number { font-size: 24px; }

/* Edit view */
.edit-bar {
  position: sticky; top: 0; z-index: 2; background: var(--bg);
}
.edit-bar h2 { flex: 1; margin: 0 0 0 4px; font-size: 20px; font-weight: 700; }
.edit-body { padding: 8px 20px calc(env(safe-area-inset-bottom) + 40px); max-width: 560px; margin: 0 auto; }
.tile.preview { width: 62%; margin: 4px auto 24px; }
.field { display: block; margin-bottom: 18px; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 6px 4px; }
.field em { font-style: normal; font-weight: 400; }
.field input, .field select {
  width: 100%; height: 52px; padding: 0 14px;
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 14px; outline: 0;
}
.field input:focus, .field select:focus { border-color: var(--accent); }
.with-btn { position: relative; }
.with-btn input { padding-right: 52px; }
.with-btn .icon-btn { position: absolute; right: 6px; top: 6px; color: var(--accent); }
.code-preview {
  background: #fff; border-radius: 14px; padding: 16px; margin: -6px 0 18px;
  border: 1.5px solid var(--line);
}
.code-preview:empty { display: none; }
.code-preview svg { width: 100%; height: auto; max-height: 120px; display: block; margin: 0 auto; }
.code-preview.two-d svg { width: 120px; }
.error { color: var(--danger); font-size: 14px; margin: -8px 4px 18px; }
.swatches { display: grid; grid-template-columns: repeat(7, 1fr); gap: 10px; }
.swatch {
  aspect-ratio: 1; border-radius: 50%; background: var(--c);
  outline: 2px solid transparent; outline-offset: 3px;
}
.swatch[aria-checked="true"] { outline-color: var(--text); }

/* Scanner */
.scan-view { background: #000; color: #fff; animation: fade-in .15s ease; overflow: hidden; }
.scan-view video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-bar { position: relative; z-index: 2; }
.finder {
  position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none;
}
.finder span {
  width: min(78vw, 360px); aspect-ratio: 1.5; border-radius: 22px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .45);
  border: 3px solid rgba(255, 255, 255, .9);
}
.scan-view.found .finder span { border-color: #4ade80; }
.scan-foot {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 2; text-align: center;
  padding: 0 24px calc(env(safe-area-inset-bottom) + 32px);
}
.scan-foot p { margin: 0 0 16px; font-size: 15px; text-shadow: 0 1px 3px rgba(0,0,0,.6); }
.pill {
  background: rgba(255, 255, 255, .16); backdrop-filter: blur(8px);
  padding: 12px 20px; border-radius: 999px; font-weight: 600;
}

/* Sheets */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, .4);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade-in .15s ease;
}
.sheet {
  width: 100%; max-width: 560px; background: var(--surface);
  border-radius: 24px 24px 0 0; padding: 8px 12px calc(env(safe-area-inset-bottom) + 16px);
  animation: slide-up .22s cubic-bezier(.2, .8, .2, 1);
}
@keyframes slide-up { from { transform: translateY(100%); } }
.grabber { width: 36px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 12px; }
.sheet-item {
  display: flex; align-items: center; gap: 16px; width: 100%; text-align: left;
  padding: 14px 12px; border-radius: 14px;
}
.sheet-item:active { background: var(--surface-2); }
.sheet-item svg { color: var(--accent); }
.sheet-item b { display: block; font-weight: 600; }
.sheet-item small { display: block; color: var(--muted); font-size: 13px; }
.sheet-label { margin: 8px 12px 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.segmented {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin: 0 8px 12px;
  background: var(--surface-2); border-radius: 12px; padding: 4px;
}
.segmented button { padding: 9px 4px; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--muted); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* Toast */
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 92px); z-index: 50;
  margin: 0 auto; max-width: 480px;
  display: flex; align-items: center; gap: 12px;
  background: #24282e; color: #f1f3f5; padding: 12px 8px 12px 18px; border-radius: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .3);
  animation: slide-in .2s ease;
}
.toast span { flex: 1; }
.toast button { color: #8fb1ff; font-weight: 650; padding: 6px 10px; }
.toast button:empty { display: none; }
