/* ---------- font: Sansation (SIL Open Font License, see fonts/Sansation-OFL.txt) ---------- */
@font-face { font-family: 'Sansation'; font-style: normal; font-weight: 400; font-display: swap;
  src: url(/fonts/sansation-latin-ext-400-normal.woff2) format('woff2'); unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: 'Sansation'; font-style: normal; font-weight: 400; font-display: swap;
  src: url(/fonts/sansation-latin-400-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Sansation'; font-style: normal; font-weight: 700; font-display: swap;
  src: url(/fonts/sansation-latin-ext-700-normal.woff2) format('woff2'); unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: 'Sansation'; font-style: normal; font-weight: 700; font-display: swap;
  src: url(/fonts/sansation-latin-700-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

/* ---------- themes ---------- */
:root, [data-theme="light"] {
  --bg: #f4f4f5; --panel: #ffffff; --field: #e4e4e7; --field-hover: #d4d4d8;
  --text: #18181b; --label: #3f3f46; --muted: #52525b; --line: #d4d4d8;
  --input-bg: #ffffff; --input-line: #d4d4d8;
  --primary: #18181b; --on-primary: #ffffff;
  --danger: #dc2626; --warn: #b45309; --focus: #2563eb;
  --glass: rgba(244, 244, 245, .9); --backdrop: rgba(24, 24, 27, .5);
  --shadow: 0 10px 40px rgba(24, 24, 27, .08);
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0e1014; --panel: #171a20; --field: #1f232b; --field-hover: #2a2f39;
  --text: #f4f4f5; --label: #d4d4d8; --muted: #a1a1aa; --line: #2e333d;
  --input-bg: #12151a; --input-line: #343a46;
  --primary: #f4f4f5; --on-primary: #18181b;
  --danger: #f87171; --warn: #fbbf24; --focus: #60a5fa;
  --glass: rgba(14, 16, 20, .88); --backdrop: rgba(0, 0, 0, .65);
  --shadow: 0 10px 40px rgba(0, 0, 0, .4);
  color-scheme: dark;
}
:root {
  --radius: 18px;
  font-family: Sansation, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text); background: var(--bg);
  transition: background-color .3s, color .3s;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
[hidden] { display: none !important; }
h1, h2 { margin: 0; }
h2 { font-size: 1.15rem; }
.muted { color: var(--muted); }
.center { text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- buttons & inputs ---------- */
.btn { font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--panel); color: var(--text);
  padding: .65rem 1rem; border-radius: 12px; cursor: pointer; }
.btn:hover { background: var(--field); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover { filter: brightness(1.15); }
[data-theme="dark"] .btn.primary:hover { filter: brightness(.9); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--field); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn.small { padding: .45rem .8rem; font-size: .85rem; }
.btn:disabled { opacity: .6; cursor: default; }
.icon-btn { border: 0; background: var(--field); color: var(--text); width: 40px; height: 40px; border-radius: 50%; font-size: 1rem;
  cursor: pointer; display: inline-grid; place-items: center; flex: none; }
.icon-btn:hover { background: var(--field-hover); }
.icon-btn.solid { background: var(--primary); color: var(--on-primary); width: 44px; height: 44px; }
.icon-btn.solid:hover { filter: brightness(1.15); }
.icon-btn.light { background: rgba(255,255,255,.9); color: #18181b; }
label { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; font-weight: 600; color: var(--label); margin-bottom: .8rem; }
input, select { font: inherit; font-weight: 400; padding: .65rem .75rem; border: 1px solid var(--input-line); border-radius: 10px;
  background: var(--input-bg); color: var(--text); width: 100%; }
input:focus, select:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: transparent; }
input[type=color] { padding: 2px; height: 44px; width: 64px; }
.error { color: var(--danger); font-size: .9rem; min-height: 1.2em; margin: .2rem 0 .6rem; }
.warn { color: var(--warn); font-size: .85rem; margin: .4rem 0 0; }
.row { display: flex; gap: .75rem; }
.row .grow { flex: 1; min-width: 0; }
.check { flex-direction: row; align-items: center; font-weight: 500; margin: 0; }
.check input { width: auto; }

/* theme toggle: show the icon for the theme you'd switch TO */
.theme-toggle .i-sun { display: none; }
[data-theme="dark"] .theme-toggle .i-sun { display: block; }
[data-theme="dark"] .theme-toggle .i-moon { display: none; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; position: relative; }
.auth-theme { position: absolute; top: max(1rem, env(safe-area-inset-top)); right: 1rem; }
.auth-box { width: 100%; max-width: 380px; background: var(--panel); padding: 2rem; border-radius: 20px; box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: .7rem; }
.brand h1 { font-size: 1.5rem; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--field); padding: 4px; border-radius: 10px; margin: 1.2rem 0; }
.tab { font: inherit; border: 0; background: transparent; padding: .55rem; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 600; }
.tab.active { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.1); }

/* ---------- wallet ---------- */
.topbar { position: sticky; top: 0; z-index: 150; display: flex; justify-content: space-between; align-items: center; gap: .5rem;
  max-width: 520px; margin: 0 auto; padding: 1rem 1.25rem .5rem; padding-top: max(1rem, env(safe-area-inset-top));
  background: var(--glass); backdrop-filter: blur(8px); }
.app-title { font-size: 2rem; font-weight: 700; letter-spacing: -.04em; }
.topbar-right { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.user-email { font-size: .85rem; max-width: 22ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wallet { max-width: 520px; margin: 0 auto; padding: .5rem 1.25rem 1.5rem; }
.search { flex-direction: row; align-items: center; gap: .5rem; height: 44px; padding: 0 .9rem; margin: 0 0 1rem;
  background: var(--field); border-radius: 12px; color: var(--muted); font-weight: 400; }
.search input { border: 0; background: transparent; padding: 0; height: 100%; color: var(--text); font-size: 15px; }
.search input:focus { outline: none; }
.search:focus-within { outline: 2px solid var(--focus); }
.offline-note { background: #fef3c7; color: #92400e; padding: .5rem .8rem; border-radius: 10px; font-size: .9rem; }
.no-match { text-align: center; padding: 3rem 1rem; }
.empty { text-align: center; padding: 3rem 1rem; }

/* the card wheel */
.wheel { position: relative; height: 580px; overflow: hidden; perspective: 1100px; perspective-origin: 50% 40%;
  touch-action: none; border-radius: 4px; outline-offset: 4px; user-select: none; -webkit-user-select: none; }
.wcard { position: absolute; left: 0; right: 0; top: 0; height: var(--card-h, 226px); padding: 12px 18px 16px; border: 0; border-radius: var(--radius);
  font: inherit; text-align: left; cursor: pointer; display: flex; flex-direction: column; transform-origin: 50% 0;
  color: #fff; box-shadow: 0 -2px 10px rgba(0,0,0,.14); -webkit-tap-highlight-color: transparent;
  transition: transform .45s cubic-bezier(.2,.8,.2,1), opacity .3s, box-shadow .3s; }
.wcard.light-bg { color: #1c1917; }
.wcard.front { box-shadow: 0 18px 40px rgba(0,0,0,.28); }
.wcard::after { content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: linear-gradient(135deg, rgba(255,255,255,.16), transparent 50%); }
.wcard-head { display: flex; justify-content: space-between; align-items: center; gap: .6rem; height: 30px; flex: none; }
.wcard-name { font-size: 18px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wcard-logo { height: 30px; max-width: 60%; object-fit: contain; object-position: left center; }
.wcard.has-logo .wcard-name { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.wcard-chip { flex: none; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: rgba(255,255,255,.22); }
.wcard.light-bg .wcard-chip { background: rgba(0,0,0,.12); }
.wcard-code { display: none; margin-top: 12px; background: #fff; color: #18181b; border-radius: 12px; padding: 10px 12px 8px;
  flex-direction: column; align-items: center; gap: 4px; }
.wcard-code canvas { max-width: 100%; max-height: var(--code-h, 104px); }
.wcard-num { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; letter-spacing: .12em; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wcard-foot { margin-top: auto; display: flex; justify-content: space-between; gap: .5rem; font-size: 13px; font-weight: 600; opacity: .85; }
.wcard.front .wcard-code { display: flex; }
.wcard.front .wcard-foot { display: none; }

.wheel-controls { display: flex; align-items: center; gap: 12px; padding-top: 12px; }
.wheel-btn { width: 48px; height: 48px; flex: none; border: 0; border-radius: 50%; background: var(--field); color: var(--text);
  display: grid; place-items: center; cursor: pointer; }
.wheel-btn:hover { background: var(--field-hover); }
.wheel-info { flex: 1; text-align: center; min-width: 0; }
.wheel-pos { font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wheel-hint { font-size: 12px; color: var(--muted); }

/* ---------- dialogs ---------- */
dialog { border: 0; padding: 0; border-radius: 20px; max-width: min(480px, calc(100vw - 1.5rem)); width: 100%;
  color: var(--text); background: var(--panel); }
dialog::backdrop { background: var(--backdrop); }
.sheet { padding: 1.2rem; max-height: calc(100dvh - 1.5rem); overflow: auto; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; gap: .5rem; }
.choices { display: grid; gap: .6rem; }
.choice { display: flex; flex-direction: row; align-items: center; gap: .9rem; text-align: left; font: inherit; width: 100%; padding: .9rem 1rem;
  border: 1px solid var(--line); border-radius: 12px; background: var(--panel); cursor: pointer; margin: 0; color: var(--text); }
.choice:hover { border-color: var(--focus); background: var(--field); }
.choice .ci { font-size: 1.6rem; }
.choice small { display: block; color: var(--muted); font-weight: 400; margin-top: 2px; }
.status { min-height: 1.2em; margin: .8rem 0 0; font-size: .9rem; color: var(--muted); }
.status.error { color: var(--danger); }
.actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .6rem; flex-wrap: wrap; }
.preview-box { background: #fff; color: #18181b; border: 1px solid var(--line); border-radius: 12px; padding: .8rem; text-align: center; margin-bottom: 1rem; }
.preview-box .warn { color: #b45309; }
.preview-box canvas { max-width: 100%; max-height: 140px; }
.photo-row { display: flex; align-items: center; gap: .8rem; margin-bottom: .6rem; }
.photo-row img { width: 72px; height: 46px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }

/* ---------- scanner ---------- */
.scanner { background: #000; max-width: 100vw; width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; }
.scan-wrap { position: relative; width: 100%; height: 100%; }
.scan-wrap video { width: 100%; height: 100%; object-fit: cover; }
.scan-frame { position: absolute; left: 50%; top: 45%; width: min(80vw, 420px); aspect-ratio: 1.6; transform: translate(-50%, -50%);
  border: 3px solid rgba(255,255,255,.9); border-radius: 16px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.45); overflow: hidden; }
.scan-line { position: absolute; left: 6%; right: 6%; height: 2px; background: #ef4444; box-shadow: 0 0 8px #ef4444; animation: sweep 2s ease-in-out infinite; }
@keyframes sweep { 0%,100% { top: 15%; } 50% { top: 85%; } }
.scan-top { position: absolute; top: max(1rem, env(safe-area-inset-top)); left: 1rem; right: 1rem; display: flex; justify-content: space-between; gap: .5rem; }
.scan-top select { width: auto; max-width: 60vw; }
.scan-hint { position: absolute; bottom: max(2rem, env(safe-area-inset-bottom)); left: 0; right: 0; text-align: center; color: #fff; font-weight: 600; text-shadow: 0 1px 4px #000; padding: 0 1rem; }

/* ---------- viewer ---------- */
.code-panel { background: #fff; color: #18181b; border-radius: 12px; padding: 1.2rem .8rem; text-align: center; border: 1px solid var(--line); }
.code-panel canvas { max-width: 100%; height: auto; image-rendering: pixelated; }
.code-text { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1.1rem; letter-spacing: .08em; margin: .6rem 0 0; word-break: break-all; }
.view-photo { width: 100%; border-radius: 12px; margin-top: .8rem; }

.toast { position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: .7rem 1.1rem;
  border-radius: 999px; font-size: .9rem; z-index: 200; box-shadow: 0 6px 20px rgba(0,0,0,.25); }

/* ---------- company logo (card form & viewer) ---------- */
.logo-row { display: flex; align-items: center; gap: .8rem; margin-bottom: .9rem; }
.logo-thumb { width: 96px; height: 60px; flex: none; border-radius: 10px; display: grid; place-items: center; overflow: hidden;
  border: 1px solid var(--line); background: #2563eb; color: rgba(255,255,255,.85); font-size: .75rem; }
.logo-thumb img { width: 84%; height: 80%; object-fit: contain; }
.logo-actions { display: flex; flex-direction: column; gap: .35rem; min-width: 0; }
.logo-buttons { display: flex; gap: .4rem; flex-wrap: wrap; }
.logo-link { margin: -.3rem 0 .9rem; }
.logo-link-inputs { display: flex; gap: .4rem; margin-bottom: .3rem; }
.logo-link-inputs input { flex: 1; min-width: 0; padding: .5rem .7rem; }
#logo-url-msg.error { color: var(--danger); }
.view-title { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.view-logo { height: 34px; max-width: 110px; object-fit: contain; }

@media (max-width: 520px) {
  .user-email { display: none; }
  .row { flex-wrap: wrap; }
  .topbar, .wallet { padding-left: 1rem; padding-right: 1rem; }
}
@media (prefers-reduced-motion: reduce) {
  .wcard { transition: none; }
}
