/* ---------- Design tokens ---------- */
:root {
  --accent: #4F46E5;
  --accent-ink: #ffffff;           /* text on accent; set by app.js for contrast */
  --radius: 14px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --bg: #F7F7F8;
  --surface: #FFFFFF;
  --surface-hover: #FAFAFB;
  --border: #E6E6EA;
  --border-strong: #D4D4DA;
  --text: #111114;
  --muted: #5E5E68;                /* 6.3:1 on --bg */
  --tile: #F2F2F5;
  --shadow: 0 1px 2px rgba(16,16,20,.04), 0 1px 1px rgba(16,16,20,.03);
  --shadow-hover: 0 6px 20px -6px rgba(16,16,20,.12), 0 2px 4px rgba(16,16,20,.04);
  --glow: color-mix(in srgb, var(--accent) 14%, transparent);
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0B0B0E;
  --surface: #15151A;
  --surface-hover: #1B1B21;
  --border: #26262E;
  --border-strong: #34343E;
  --text: #F4F4F6;
  --muted: #A1A1AC;                /* 7.4:1 on --bg */
  --tile: #202027;
  --shadow: none;
  --shadow-hover: 0 8px 24px -8px rgba(0,0,0,.6);
  --glow: color-mix(in srgb, var(--accent) 22%, transparent);
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img { display: block; max-width: 100%; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 8px; }

.bg {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: radial-gradient(60rem 28rem at 50% -8rem, var(--glow), transparent 70%);
}
.skip {
  position: absolute; left: 12px; top: -48px; z-index: 10;
  padding: 8px 12px; border-radius: 8px; background: var(--text); color: var(--bg);
  text-decoration: none; font-weight: 600;
}
.skip:focus { top: 12px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center;
  max-width: 580px; margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px 0;
}
.topbar-right { display: flex; gap: 8px; }
.icon-btn {
  display: grid; place-items: center;
  width: 40px; height: 40px; padding: 0;
  border: 1px solid var(--border); border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, transform .1s ease;
}
.icon-btn:hover { border-color: var(--border-strong); background: var(--surface); }
.icon-btn:active { transform: scale(.94); }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------- Layout ---------- */
.page {
  max-width: 580px; margin: 0 auto;
  padding: 8px 20px max(32px, env(safe-area-inset-bottom));
}

/* ---------- Profile ---------- */
.profile { text-align: center; padding: 16px 0 28px; }
.avatar {
  width: 96px; height: 96px; margin: 0 auto 16px;
  border-radius: 50%; object-fit: cover;
  box-shadow: 0 0 0 4px var(--surface), 0 0 0 5px var(--border);
  background: var(--tile);
}
.avatar.rounded { border-radius: 24%; }
.avatar.square { border-radius: 8px; }
.name {
  margin: 0; font-size: 24px; line-height: 1.2; font-weight: 700; letter-spacing: -.02em;
  display: inline-flex; align-items: center; gap: 6px;
}
.name .verified { width: 20px; height: 20px; color: var(--accent); }
.handle { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.bio { margin: 12px auto 0; max-width: 34ch; color: var(--text); opacity: .86; font-size: 15px; }
.location { margin: 8px 0 0; color: var(--muted); font-size: 13px;
  display: inline-flex; align-items: center; gap: 4px; }
.location svg { width: 14px; height: 14px; }

/* ---------- Links ---------- */
.links { display: flex; flex-direction: column; gap: 10px; }
.section-head { margin: 22px 4px 2px; }
.section-sub { margin: 2px 0 0; font-size: 13.5px; color: var(--muted); line-height: 1.4; }
.section-title {
  margin: 0; font-size: 12px; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}
.link {
  position: relative;
  display: flex; align-items: center; gap: 14px;
  min-height: 64px; padding: 10px 14px 10px 10px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow);
  color: inherit; text-decoration: none;
  transition: transform .16s cubic-bezier(.2,.7,.3,1), box-shadow .16s ease, border-color .16s ease, background .16s ease;
  -webkit-tap-highlight-color: transparent;
}
.link:hover { border-color: var(--border-strong); background: var(--surface-hover); box-shadow: var(--shadow-hover); transform: translateY(-1px); }
.link:active { transform: translateY(0) scale(.985); box-shadow: var(--shadow); }
.link:focus-visible { outline-offset: 2px; border-radius: var(--radius); }

.link-media {
  flex: none; display: grid; place-items: center;
  width: 44px; height: 44px; border-radius: calc(var(--radius) - 4px);
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  color: var(--accent); overflow: hidden;
}
.link-media svg { width: 20px; height: 20px; }
.link-media img { width: 100%; height: 100%; object-fit: cover; }
.link-media.emoji { font-size: 22px; }

.link-text { flex: 1; min-width: 0; }
.link-title { display: block; font-weight: 600; font-size: 15.5px; line-height: 1.3; overflow-wrap: anywhere; }
.link-title .badge { display: inline-block; margin-left: 8px; vertical-align: 2px; }

.link-sub { display: block; margin-top: 2px; font-size: 13px; color: var(--muted); line-height: 1.35; }
.badge {
  flex: none; padding: 2px 7px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: .02em;
  background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent);
}
[data-theme="dark"] .badge { color: color-mix(in srgb, var(--accent) 55%, white); }
[data-theme="dark"] .link-media { color: color-mix(in srgb, var(--accent) 55%, white);
  background: color-mix(in srgb, var(--accent) 18%, var(--surface)); }

.link-arrow { flex: none; width: 18px; height: 18px; color: var(--muted); transition: transform .16s ease, color .16s ease; }
.link:hover .link-arrow { transform: translate(2px,-2px); color: var(--text); }
.count {
  flex: none; font-size: 12px; font-variant-numeric: tabular-nums; color: var(--muted);
  padding: 2px 8px; border: 1px solid var(--border); border-radius: 999px;
}

/* Featured / highlighted link */
.link.featured {
  min-height: 76px; padding: 14px 16px 14px 14px;
  background: var(--accent); color: var(--accent-ink); border-color: transparent;
  box-shadow: 0 10px 30px -12px color-mix(in srgb, var(--accent) 70%, transparent);
}
.link.featured:hover { background: color-mix(in srgb, var(--accent) 92%, black); box-shadow: 0 14px 34px -12px color-mix(in srgb, var(--accent) 80%, transparent); }
.link.featured .link-media { background: color-mix(in srgb, var(--accent-ink) 18%, transparent); color: var(--accent-ink); }
.link.featured .link-sub, .link.featured .link-arrow, .link.featured .count { color: var(--accent-ink); opacity: .85; }
.link.featured .count { border-color: color-mix(in srgb, var(--accent-ink) 35%, transparent); }
.link.featured .link-title { font-size: 16.5px; }
.link.featured .badge { background: var(--accent-ink); color: var(--accent); }
.link.featured:focus-visible { outline-color: var(--text); }

/* ---------- Socials ---------- */
.socials { list-style: none; margin: 28px 0 0; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.socials a {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: 999px;
  color: var(--muted); transition: color .15s ease, background .15s ease, transform .1s ease;
}
.socials a:hover { color: var(--text); background: var(--surface); }
.socials a:active { transform: scale(.92); }
.socials svg { width: 20px; height: 20px; }

/* ---------- Footer ---------- */
.footer { margin-top: 28px; text-align: center; font-size: 12px; color: var(--muted); }

/* ---------- QR sheet ---------- */
.sheet {
  border: 1px solid var(--border); border-radius: 20px; padding: 0;
  background: var(--surface); color: var(--text);
  width: min(360px, calc(100vw - 32px));
  box-shadow: 0 30px 80px -20px rgba(0,0,0,.35);
}
.sheet::backdrop { background: rgba(10,10,14,.45); backdrop-filter: blur(4px); }
.sheet[open] { animation: pop .18s cubic-bezier(.2,.7,.3,1); }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.sheet-inner { padding: 22px; text-align: center; }
.sheet h2 { margin: 0 0 14px; font-size: 17px; font-weight: 650; }
.qr { width: 232px; height: 232px; margin: 0 auto; padding: 12px; background: #fff; border-radius: 14px; border: 1px solid #ececf0; }
.qr svg { width: 100%; height: 100%; display: block; }
.sheet-url { margin: 12px 0 18px; font-size: 13px; color: var(--muted); word-break: break-all; }
.sheet-actions { display: flex; gap: 8px; }
.btn {
  flex: 1; height: 44px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); font-weight: 600; font-size: 14px; cursor: pointer;
  transition: background .15s ease, transform .1s ease;
}
.btn:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 90%, black); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom));
  transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 500;
  background: var(--text); color: var(--bg);
  transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.noscript { text-align: center; color: var(--muted); }

/* ---------- Desktop ---------- */
@media (min-width: 768px) {
  .page { padding-top: 32px; }
  .profile { padding-bottom: 36px; }
  .avatar { width: 112px; height: 112px; }
  .name { font-size: 28px; }
}

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