/* Windows has no flag emoji; this font only covers regional-indicator flags and loads only when needed. */
@font-face {
  font-family: "Twemoji Country Flags";
  unicode-range: U+1F1E6-1F1FF, U+1F3F4, U+E0062-E0063, U+E0065, U+E0067, U+E006C, U+E006E, U+E0073-E0074, U+E0077, U+E007F;
  src: url("https://cdn.jsdelivr.net/npm/country-flag-emoji-polyfill@0.1.8/dist/TwemojiCountryFlags.woff2") format("woff2");
  font-display: swap;
}

:root {
  --bg: #faf9f5;
  --bg-2: #f3f1ea;
  --surface: #ffffff;
  --text: #1f1e1c;
  --muted: #65635c;
  --faint: #8d8a80;
  --border: #e6e3d8;
  --border-strong: #d4d0c2;
  --accent: #c15f3c;
  --accent-ink: #a34c2d;
  --accent-soft: #f6e6dd;
  --star: #a8730b;
  --ok: #3f7d4e;
  --shadow: 0 1px 2px rgba(31, 30, 28, .05), 0 4px 16px rgba(31, 30, 28, .04);
  --radius: 12px;
  --sans: "Twemoji Country Flags", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Twemoji Country Flags", "Iowan Old Style", "Charter", "Source Serif Pro", Georgia, "Songti SC", "Noto Serif CJK SC", serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1a1917;
    --bg-2: #211f1d;
    --surface: #262422;
    --text: #ecebe6;
    --muted: #aaa79d;
    --faint: #85827a;
    --border: #36332f;
    --border-strong: #4a4641;
    --accent: #e3825f;
    --accent-ink: #f0a184;
    --accent-soft: #3a2a22;
    --star: #e2b44a;
    --ok: #7cc28d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .2);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #1a1917;
  --bg-2: #211f1d;
  --surface: #262422;
  --text: #ecebe6;
  --muted: #aaa79d;
  --faint: #85827a;
  --border: #36332f;
  --border-strong: #4a4641;
  --accent: #e3825f;
  --accent-ink: #f0a184;
  --accent-soft: #3a2a22;
  --star: #e2b44a;
  --ok: #7cc28d;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .2);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-padding-top: 72px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--sans);
  overflow-x: hidden;
}
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
code, kbd { font-family: var(--mono); font-size: .88em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 24px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 50; }
.skip:focus { left: 8px; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 58px; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 16px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand b { font-weight: 650; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.chip-btn, .icon-btn, .gh-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 34px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  border-radius: 9px; padding: 0 12px; font: inherit; font-size: 13.5px; cursor: pointer;
}
.icon-btn { width: 34px; padding: 0; justify-content: center; }
.chip-btn:hover, .icon-btn:hover, .gh-btn:hover { border-color: var(--accent); text-decoration: none; }
.gh-btn { background: var(--text); color: var(--bg); border-color: var(--text); }
.gh-btn:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.gh-count { margin-left: 2px; padding: 1px 7px; border-radius: 6px; background: rgba(255, 255, 255, .18); font-weight: 650; font-variant-numeric: tabular-nums; }
.i-moon { display: none; }
:root[data-theme="dark"] .i-sun { display: none; }
:root[data-theme="dark"] .i-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .i-sun { display: none; }
  :root:not([data-theme="light"]) .i-moon { display: block; }
}

/* Hero */
.hero { padding: 44px 0 26px; border-bottom: 1px solid var(--border); background:
  radial-gradient(900px 300px at 85% -10%, var(--accent-soft), transparent 70%), var(--bg); }
.eyebrow { margin: 0 0 10px; color: var(--accent-ink); font-size: 13px; font-weight: 600; letter-spacing: .02em; }
.hero h1 { font-family: var(--serif); font-weight: 500; font-size: clamp(30px, 4.4vw, 48px); line-height: 1.12; margin: 0 0 12px; letter-spacing: -.01em; max-width: 20ch; }
.lede { font-size: 17px; color: var(--muted); max-width: 62ch; margin: 0 0 22px; }
.search {
  position: relative; display: flex; align-items: center; max-width: 680px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 12px;
  box-shadow: var(--shadow); padding: 0 12px; gap: 10px; color: var(--faint);
}
.search:focus-within { border-color: var(--accent); }
.search input { flex: 1; min-width: 0; height: 50px; border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; font-size: 16px; }
.search input::-webkit-search-cancel-button { cursor: pointer; }
.search kbd { border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 5px; padding: 1px 7px; color: var(--muted); background: var(--bg-2); }
.stats { display: flex; flex-wrap: wrap; gap: 8px 28px; margin: 22px 0 0; }
.stats div { display: flex; flex-direction: column; }
.stats dt { order: 2; font-size: 12.5px; color: var(--muted); }
.stats dd { order: 1; margin: 0; font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }

/* Spotlight + board */
.spot { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 28px; padding-top: 30px; padding-bottom: 8px; }
.spot h2, .board h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 0 0 4px; font-weight: 650; }
.spot-main > p { margin: 0 0 14px; font-size: 14px; }
.spot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.spot-card {
  display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; min-height: 104px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text);
  transition: border-color .15s, transform .15s;
}
.spot-card:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-1px); }
.spot-card .top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.spot-card strong { font-weight: 650; font-size: 14.5px; }
.spot-card p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.spot-card .cat { margin-top: auto; font-size: 12px; color: var(--accent-ink); }
.board { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; align-self: start; }
.board ol { list-style: none; margin: 10px 0 0; padding: 0; counter-reset: b; }
.board li { counter-increment: b; display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; gap: 6px; align-items: baseline; padding: 5px 0; border-top: 1px dashed var(--border); font-size: 13.5px; }
.board li:first-child { border-top: 0; }
.board li::before { content: counter(b); color: var(--faint); font-variant-numeric: tabular-nums; font-size: 12px; }
.board li a { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board li a:hover { color: var(--accent-ink); }

/* Layout */
.layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 32px; padding-top: 26px; padding-bottom: 60px; }
.sidebar { position: sticky; top: 74px; align-self: start; max-height: calc(100vh - 90px); overflow: auto; padding-right: 4px; }
.sidebar summary { list-style: none; font-size: 13px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 650; margin-bottom: 8px; cursor: default; }
.sidebar summary::-webkit-details-marker { display: none; }
#cats { display: flex; flex-direction: column; gap: 1px; }
.cat-btn {
  display: flex; justify-content: space-between; align-items: center; gap: 8px; width: 100%;
  border: 0; background: transparent; color: var(--text); font: inherit; font-size: 13.5px;
  text-align: left; padding: 5px 10px; border-radius: 7px; cursor: pointer;
}
.cat-btn:hover { background: var(--bg-2); }
.cat-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.cat-btn .n { color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; }
.cat-btn.sec { font-weight: 650; margin-top: 10px; }
.cat-btn.sec:first-child { margin-top: 0; }
.cat-btn.sub { padding-left: 24px; color: var(--muted); }
.cat-btn.sub[aria-pressed="true"] { color: var(--accent-ink); }
.cat-btn[disabled] { opacity: .4; cursor: default; }

/* Toolbar */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.seg { display: inline-flex; flex-wrap: wrap; background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 13px; padding: 5px 10px; border-radius: 7px; cursor: pointer; white-space: nowrap; }
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }
.sort { margin-left: auto; display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.sort select { font: inherit; font-size: 13px; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; padding: 6px 8px; }
.result-meta { display: flex; align-items: center; gap: 12px; margin: 14px 0 6px; min-height: 24px; }
.result-meta p { margin: 0; color: var(--muted); font-size: 13.5px; }
.link-btn { border: 0; background: none; color: var(--accent-ink); font: inherit; font-size: 13.5px; cursor: pointer; padding: 0; }
.link-btn:hover { text-decoration: underline; }

/* Results */
#results:focus { outline: none; }
.sec-block { margin-top: 26px; }
.sec-block > h2 { font-family: var(--serif); font-weight: 500; font-size: 26px; margin: 0 0 4px; letter-spacing: -.005em; }
.sec-block > p { margin: 0 0 6px; color: var(--muted); font-size: 14px; max-width: 75ch; }
.cat-block { margin-top: 18px; }
.cat-block > h3 { display: flex; align-items: baseline; gap: 8px; font-size: 16px; margin: 0 0 2px; font-weight: 650; }
.cat-block > h3 .n { font-size: 12px; color: var(--faint); font-weight: 500; }
.cat-block > p { margin: 0 0 8px; color: var(--muted); font-size: 13.5px; }
.group-h { font-size: 12.5px; font-weight: 650; color: var(--muted); margin: 12px 0 4px; text-transform: uppercase; letter-spacing: .05em; }
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 16px; padding: 11px 16px; border-top: 1px solid var(--border); }
.row:first-child { border-top: 0; }
.row:hover { background: color-mix(in srgb, var(--accent-soft) 35%, var(--surface)); }
.row-main { min-width: 0; }
.row-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
.row-title a.name { font-weight: 650; font-size: 15px; color: var(--text); }
.row-title a.name:hover { color: var(--accent-ink); }
.row-title .slug { font-family: var(--mono); font-size: 12px; color: var(--faint); overflow-wrap: anywhere; }
.badge { display: inline-flex; align-items: center; gap: 3px; font-size: 11.5px; line-height: 1; padding: 3px 7px; border-radius: 999px; border: 1px solid var(--border-strong); color: var(--muted); white-space: nowrap; }
.badge.top { border-color: transparent; background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.badge.arch { border-style: dashed; }
.badge.cat { border-color: transparent; background: var(--bg-2); }
.row-desc { margin: 3px 0 0; color: var(--muted); font-size: 14px; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.tag { font-size: 11.5px; color: var(--faint); background: var(--bg-2); border-radius: 5px; padding: 1px 6px; cursor: pointer; border: 0; font-family: inherit; }
.tag:hover { color: var(--accent-ink); }
.row-side { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; text-align: right; white-space: nowrap; }
.stars { font-variant-numeric: tabular-nums; font-weight: 650; font-size: 14px; color: var(--star); }
.stars::before { content: "★ "; }
.upd { font-size: 12px; color: var(--faint); }
.upd.fresh { color: var(--ok); }
.empty { padding: 48px 16px; text-align: center; color: var(--muted); border: 1px dashed var(--border-strong); border-radius: var(--radius); margin-top: 16px; }
mark { background: color-mix(in srgb, var(--star) 28%, transparent); color: inherit; border-radius: 2px; padding: 0 1px; }

.footer { border-top: 1px solid var(--border); padding: 28px 0 40px; background: var(--bg-2); font-size: 14px; }
.footer p { margin: 0 0 6px; }

@media (max-width: 1000px) {
  .spot { grid-template-columns: minmax(0, 1fr); }
  .board ol { columns: 2; column-gap: 20px; }
  .board li { break-inside: avoid; }
}

@media (max-width: 820px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .sidebar { position: static; max-height: none; overflow: visible; padding: 0; }
  .sidebar details { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; }
  .sidebar summary { cursor: pointer; margin: 0; }
  .sidebar details[open] summary { margin-bottom: 8px; }
  #cats { max-height: 55vh; overflow: auto; }
  .sort { margin-left: 0; }
}

@media (max-width: 600px) {
  .wrap { padding: 0 16px; }
  body { font-size: 14.5px; }
  .hero { padding: 30px 0 20px; }
  .lede { font-size: 15.5px; }
  .brand span { display: none; }
  .gh-btn span { display: none; }
  .gh-btn { width: 34px; padding: 0; justify-content: center; }
  .stats { gap: 6px 20px; }
  .stats dd { font-size: 19px; }
  .spot-grid {
    grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: 80%;
    overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: 6px; overscroll-behavior-x: contain;
  }
  .spot-card { scroll-snap-align: start; }
  .board ol { columns: 1; }
  .row { grid-template-columns: minmax(0, 1fr); padding: 11px 13px; }
  .row-side { flex-direction: row; align-items: center; gap: 10px; justify-content: flex-start; }
  .seg { width: 100%; }
  .seg button { flex: 1 1 auto; }
}

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