/* =============================================================
   AI Similarity — shared design foundation (site.css)
   Tokens, reset, layout, shell (header/footer), and primitives.
   Page-specific CSS lives next to each page and may only use the
   tokens and primitives defined here.
   Theme: <html data-theme="light|dark"> (set by assets/js/theme.js)
   ============================================================= */

:root {
  color-scheme: light;
  --brand-1: #2563eb;
  --brand-2: #4f46e5;
  --brand-3: #7c3aed;
  --brand-grad: linear-gradient(120deg, var(--brand-1), var(--brand-2) 55%, var(--brand-3));

  --bg: #f6f8ff;
  --bg-elev: #ffffff;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text-1: #0f172a;
  --text-2: #475569;
  --text-3: #64748b;
  --link: #1d4ed8;
  --focus: #2563eb;
  --ok: #15803d;
  --warn: #b45309;
  --danger: #b91c1c;
  --code-bg: #0f172a;
  --code-fg: #e2e8f0;
  --shadow-1: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .08);
  --shadow-2: 0 8px 24px rgba(15, 23, 42, .10);

  /* platform accents (text-safe on --surface in both themes) */
  --pf-android: #1b8a4f;
  --pf-compose: #2563eb;
  --pf-ios: #475569;
  --pf-swiftui: #d9480f;
  --pf-react_native: #0e7490;
  --pf-flutter: #0369a1;
  --pf-xamarin: #6d28d9;
  --pf-ionic: #1d4ed8;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --container: 1180px;
  --header-h: 60px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #07070d;
  --bg-elev: #0e0e18;
  --surface: #11111c;
  --surface-2: #181826;
  --border: rgba(255, 255, 255, .10);
  --border-strong: rgba(255, 255, 255, .20);
  --text-1: #f1f5f9;
  --text-2: #a8b3c7;
  --text-3: #8391a8;
  --link: #8ab4ff;
  --focus: #8ab4ff;
  --ok: #4ade80;
  --warn: #fbbf24;
  --danger: #f87171;
  --code-bg: #0b0b14;
  --code-fg: #e2e8f0;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-2: 0 8px 28px rgba(0, 0, 0, .5);
  --pf-android: #3ddc84;
  --pf-compose: #7aa7ff;
  --pf-ios: #c3cad8;
  --pf-swiftui: #ff8a5b;
  --pf-react_native: #61dafb;
  --pf-flutter: #54c5f8;
  --pf-xamarin: #b794f6;
  --pf-ionic: #6ea0ff;
}

/* ---------- reset / base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  font: 15px/1.6 var(--font);
  color: var(--text-1);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
html[data-theme="dark"] body {
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse 70% 50% at 10% 0%, rgba(99, 102, 241, .22), transparent 60%),
    radial-gradient(ellipse 55% 45% at 90% 8%, rgba(37, 99, 235, .16), transparent 55%);
  background-attachment: fixed;
}
main { flex: 1 0 auto; }
[hidden] { display: none !important; } /* author display rules (.btn, .chips…) must not defeat the hidden attribute */
img, svg { max-width: 100%; }
a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: clamp(1.9rem, 4.5vw, 2.8rem); font-weight: 800; }
h2 { font-size: clamp(1.35rem, 2.6vw, 1.75rem); font-weight: 700; }
h3 { font-size: 1.1rem; font-weight: 650; }
p { margin: 0 0 1em; }
code, kbd, pre { font-family: var(--mono); font-size: .9em; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 8px; top: -48px; background: var(--brand-1); color: #fff; padding: 8px 14px; border-radius: var(--radius-sm); z-index: 100; }
.skip-link:focus { top: 8px; }
.gradient-text { background: var(--brand-grad); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ---------- layout ---------- */
.container { width: 100%; max-width: var(--container); margin-inline: auto; padding-inline: 16px; }
.page-head { padding: 40px 0 20px; }
.page-head p { color: var(--text-2); max-width: 70ch; font-size: 1.05rem; }
.section { padding: 28px 0; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.stack > * + * { margin-top: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.muted { color: var(--text-2); }
.small { font-size: .85rem; }

/* ---------- site header ---------- */
.site-header { position: sticky; top: 0; z-index: 50; height: var(--header-h); background: color-mix(in srgb, var(--bg-elev) 88%, transparent); backdrop-filter: saturate(160%) blur(12px); border-bottom: 1px solid var(--border); }
.site-header .container { height: 100%; display: flex; align-items: center; gap: 14px; }
.brand { font-weight: 800; font-size: 1.05rem; letter-spacing: -.02em; text-decoration: none; color: var(--text-1); white-space: nowrap; }
.brand span { background: var(--brand-grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.nav { display: flex; align-items: center; gap: 2px; margin-left: 8px; flex: 1; }
.nav a, .nav summary { color: var(--text-2); text-decoration: none; padding: 7px 12px; border-radius: var(--radius-md); font-weight: 550; font-size: .93rem; cursor: pointer; list-style: none; }
.nav summary::-webkit-details-marker { display: none; }
.nav a:hover, .nav summary:hover { background: var(--surface-2); color: var(--text-1); }
.nav a[aria-current="page"] { color: var(--text-1); background: var(--surface-2); }
.nav details { position: relative; }
.nav .menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 230px; background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-2); padding: 6px; display: grid; }
.nav .menu a { display: block; }
.header-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.icon-btn { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: var(--radius-md); border: 1px solid var(--border); background: var(--surface); color: var(--text-1); cursor: pointer; font-size: 1.05rem; }
.icon-btn:hover { background: var(--surface-2); }
.nav-toggle { display: none; }
@media (max-width: 820px) {
  .nav-toggle { display: inline-grid; }
  .nav { position: fixed; inset: var(--header-h) 0 auto 0; flex-direction: column; align-items: stretch; background: var(--bg-elev); border-bottom: 1px solid var(--border); padding: 10px 16px 16px; margin: 0; display: none; max-height: calc(100vh - var(--header-h)); overflow: auto; }
  .nav.open { display: flex; }
  .nav .menu { position: static; box-shadow: none; border: 0; padding: 0 0 0 10px; }
  .header-actions { margin-left: auto; }
}

/* ---------- site footer ---------- */
.site-footer { border-top: 1px solid var(--border); margin-top: 48px; padding: 28px 0 36px; color: var(--text-2); font-size: .9rem; }
.site-footer .cols { display: flex; flex-wrap: wrap; gap: 14px 28px; justify-content: space-between; }
.site-footer a { color: var(--text-2); }

/* ---------- primitives ---------- */
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 9px 16px; border-radius: var(--radius-md); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-1); font: 600 .92rem var(--font); cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--brand-grad); color: #fff; border-color: transparent; }
.btn-primary:hover { filter: brightness(1.08); background: var(--brand-grad); }

.search { position: relative; display: block; }
.search input { width: 100%; padding: 13px 16px 13px 44px; font: 500 1rem var(--font); color: var(--text-1); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-lg); box-shadow: var(--shadow-1); }
.search input::placeholder { color: var(--text-3); }
.search::before { content: ""; position: absolute; left: 16px; top: 50%; width: 15px; height: 15px; margin-top: -9px; border: 2px solid var(--text-3); border-radius: 50%; }
.search::after { content: ""; position: absolute; left: 29px; top: 50%; width: 7px; height: 2px; margin-top: 7px; background: var(--text-3); transform: rotate(45deg); }
.search input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
kbd { background: var(--surface-2); border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 5px; padding: 1px 6px; font-size: .8em; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); font: 600 .84rem var(--font); cursor: pointer; }
.chip:hover { color: var(--text-1); background: var(--surface-2); }
.chip[aria-pressed="true"], .chip.active { color: #fff; background: var(--brand-1); border-color: var(--brand-1); }
.chip .count { opacity: .75; font-weight: 500; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px; box-shadow: var(--shadow-1); }
a.card { display: block; text-decoration: none; color: inherit; }
a.card:hover, .card.hoverable:hover { border-color: var(--brand-1); box-shadow: var(--shadow-2); transform: translateY(-1px); }
.card h3 { margin-bottom: .25em; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .74rem; font-weight: 700; letter-spacing: .02em; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.badge.new { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); border-color: transparent; }
.badge.warn { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); border-color: transparent; }

/* platform label: <span class="pf pf-android">Android</span> */
.pf { font-weight: 700; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; }
/* Platform logos: every .pf-<key> label and every chip[data-pf=<key>] shows its logo (assets/<icon>.svg).
   Single place to change; page scripts only need to emit the existing class/attribute. */
.pf::before, .chip[data-pf]::before {
  content: ""; display: none; flex: none; /* shown only when a platform key rule below matches */
  width: 1.3em; height: 1.3em; margin-right: .45em; vertical-align: -.3em;
  background: center / contain no-repeat;
}
.chip[data-pf]::before { margin-right: 0; vertical-align: baseline; width: 1.25em; height: 1.25em; }
.pf-android::before, .chip[data-pf="android"]::before { display: inline-block; background-image: url(../android.svg); }
.pf-compose::before, .chip[data-pf="compose"]::before { display: inline-block; background-image: url(../jetpack-compose.svg); }
.pf-ios::before, .chip[data-pf="ios"]::before { display: inline-block; background-image: url(../ios.svg); }
.pf-swiftui::before, .chip[data-pf="swiftui"]::before { display: inline-block; background-image: url(../swiftui.svg); }
.pf-react_native::before, .chip[data-pf="react_native"]::before { display: inline-block; background-image: url(../react.svg); }
.pf-flutter::before, .chip[data-pf="flutter"]::before { display: inline-block; background-image: url(../flutter.svg); }
.pf-xamarin::before, .chip[data-pf="xamarin"]::before { display: inline-block; background-image: url(../x.svg); width: 3.1em; }
.pf-ionic::before, .chip[data-pf="ionic"]::before { display: inline-block; background-image: url(../ionic.svg); width: 3.1em; }
/* the Apple logo is a single black path: invert it on dark surfaces (selected chips undo this below) */
html[data-theme="dark"] .pf-ios::before, html[data-theme="dark"] .chip[data-pf="ios"]::before { filter: invert(1); }
/* selected chips are brand-blue: put the logo on a white tile so blue logos (React, Ionic, Compose) stay visible, and keep the Apple logo black on it */
.chip[data-pf][aria-pressed="true"]::before { background-color: #fff; border-radius: 5px; box-sizing: border-box; padding: .17em; background-origin: content-box; }
html .chip[data-pf][aria-pressed="true"]::before { filter: none; }
.pf-android { color: var(--pf-android); } .pf-compose { color: var(--pf-compose); }
.pf-ios { color: var(--pf-ios); } .pf-swiftui { color: var(--pf-swiftui); }
.pf-react_native { color: var(--pf-react_native); } .pf-flutter { color: var(--pf-flutter); }
.pf-xamarin { color: var(--pf-xamarin); } .pf-ionic { color: var(--pf-ionic); }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.data th, table.data td { padding: 10px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
table.data thead th { position: sticky; top: 0; background: var(--surface-2); font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-2); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }

.empty-state { text-align: center; color: var(--text-2); padding: 48px 16px; border: 1px dashed var(--border-strong); border-radius: var(--radius-lg); }
.result-count { color: var(--text-2); font-size: .9rem; }
mark { background: color-mix(in srgb, #facc15 45%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
@media (prefers-reduced-motion: no-preference) {
  .card, .btn, .chip { transition: border-color .15s, box-shadow .15s, transform .15s, background .15s; }
}
