:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efede7;
  --text: #17161a;
  --muted: #6b6a70;
  --faint: #a3a1a8;
  --border: #e4e2dc;
  --border-strong: #d2cfc7;
  --accent: #ff5a1f;
  --accent-ink: #ffffff;
  --accent-soft: rgba(255, 90, 31, 0.1);
  --shadow: 0 1px 2px rgba(23, 22, 26, 0.04), 0 8px 24px -12px rgba(23, 22, 26, 0.12);
  --shadow-hover: 0 1px 2px rgba(23, 22, 26, 0.06), 0 20px 40px -16px rgba(23, 22, 26, 0.22);
  --toolbar-bg: rgba(246, 245, 241, 0.82);
  --logo-l: 92%;
  --logo-c: 0.05;
  --icon-sun: block;
  --icon-moon: none;

  --font: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont, system-ui, 'Apple SD Gothic Neo', 'Noto Sans KR', sans-serif;
  --mono: ui-monospace, 'SF Mono', 'JetBrains Mono', Menlo, Consolas, monospace;
  --radius: 18px;
  --gutter: clamp(16px, 4vw, 40px);
  --max: 1240px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0d0d10;
    --surface: #16161b;
    --surface-2: #1d1d23;
    --text: #f2f1ee;
    --muted: #9a99a2;
    --faint: #5f5e66;
    --border: #25252c;
    --border-strong: #34343c;
    --accent: #ff7a45;
    --accent-ink: #160a05;
    --accent-soft: rgba(255, 122, 69, 0.14);
    --shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset;
    --shadow-hover: 0 1px 0 rgba(255, 255, 255, 0.05) inset, 0 24px 48px -20px rgba(0, 0, 0, 0.7);
    --toolbar-bg: rgba(13, 13, 16, 0.78);
    --logo-l: 30%;
    --logo-c: 0.06;
    --icon-sun: none;
    --icon-moon: block;
    color-scheme: dark;
  }
}

:root[data-theme='dark'] {
  --bg: #0d0d10;
  --surface: #16161b;
  --surface-2: #1d1d23;
  --text: #f2f1ee;
  --muted: #9a99a2;
  --faint: #5f5e66;
  --border: #25252c;
  --border-strong: #34343c;
  --accent: #ff7a45;
  --accent-ink: #160a05;
  --accent-soft: rgba(255, 122, 69, 0.14);
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset;
  --shadow-hover: 0 1px 0 rgba(255, 255, 255, 0.05) inset, 0 24px 48px -20px rgba(0, 0, 0, 0.7);
  --toolbar-bg: rgba(13, 13, 16, 0.78);
  --logo-l: 30%;
  --logo-c: 0.06;
  --icon-sun: none;
  --icon-moon: block;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-padding-top: 100px; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  letter-spacing: -0.011em;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a { color: inherit; }

svg { display: block; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

.visually-hidden {
  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: 16px; top: -48px; z-index: 50;
  padding: 10px 14px; border-radius: 10px;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; text-decoration: none;
}
.skip-link:focus { top: 12px; }

/* ── Top bar ─────────────────────────────────────────── */

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  max-width: var(--max); margin: 0 auto; padding: 20px var(--gutter);
}

.brand { font-weight: 700; font-size: 17px; letter-spacing: -0.02em; text-decoration: none; }

.topbar-actions { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; padding: 0;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
  color: var(--text); text-decoration: none; cursor: pointer; transition: border-color 0.2s;
}
.icon-btn:hover { border-color: var(--border-strong); }
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
#random svg circle, a.icon-btn svg { fill: currentColor; stroke: none; }
.icon-sun { display: var(--icon-sun); }
.icon-moon { display: var(--icon-moon); }

/* ── Toolbar ─────────────────────────────────────────── */

.toolbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--toolbar-bg);
  backdrop-filter: saturate(1.6) blur(16px); -webkit-backdrop-filter: saturate(1.6) blur(16px);
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s;
}
.toolbar.is-stuck { border-bottom-color: var(--border); }

.toolbar-inner {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  max-width: var(--max); margin: 0 auto; padding: 14px var(--gutter);
}

.search {
  position: relative; flex: 1 1 320px; display: flex; align-items: center;
}
.search > svg {
  position: absolute; left: 16px; width: 18px; height: 18px;
  fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; pointer-events: none;
}
.search input {
  width: 100%; height: 48px; padding: 0 48px 0 46px;
  border: 1px solid var(--border); border-radius: 14px; background: var(--surface);
  color: var(--text); font: 500 16px var(--font); letter-spacing: -0.01em;
  box-shadow: var(--shadow); transition: border-color 0.2s, box-shadow 0.2s;
}
.search input::placeholder { color: var(--faint); }
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.search input::-webkit-search-cancel-button { display: none; }
.search kbd {
  position: absolute; right: 12px; display: grid; place-items: center; min-width: 24px; height: 24px;
  border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2);
  color: var(--muted); font: 600 12px var(--mono);
}
.search input:focus + kbd, .search input:not(:placeholder-shown) + kbd { display: none; }

.segmented {
  display: inline-flex; padding: 4px; gap: 2px; height: 48px;
  border: 1px solid var(--border); border-radius: 14px; background: var(--surface);
}
.segmented button {
  display: inline-flex; align-items: center; gap: 6px; padding: 0 14px;
  border: 0; border-radius: 10px; background: transparent; color: var(--muted);
  font: 600 14px var(--font); white-space: nowrap; cursor: pointer; transition: background 0.2s, color 0.2s;
}
.segmented button span { color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; }
.segmented button:hover { color: var(--text); }
.segmented button[aria-checked='true'] { background: var(--text); color: var(--bg); }
.segmented button[aria-checked='true'] span { color: inherit; opacity: 0.6; }

.sort select {
  height: 48px; padding: 0 36px 0 14px;
  border: 1px solid var(--border); border-radius: 14px; background: var(--surface);
  color: var(--text); font: 600 14px var(--font); cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 16px;
}

#random { width: 48px; height: 48px; border-radius: 14px; }

/* ── Results ─────────────────────────────────────────── */

.results { max-width: var(--max); margin: 0 auto; padding: 20px var(--gutter) 80px; }

.result-meta { margin: 8px 0 18px; color: var(--muted); font-size: 14px; }

.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); gap: 14px;
  margin: 0; padding: 0; list-style: none;
}

.card {
  --hue: 20;
  position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 176px; padding: 20px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
  box-shadow: var(--shadow);
  transition: box-shadow 0.25s, border-color 0.25s;
  animation: rise 0.45s cubic-bezier(0.2, 0.8, 0.2, 1) both;
  animation-delay: calc(min(var(--i, 0), 24) * 18ms);
}
.card:hover { border-color: var(--border-strong); }
.card:has(.card-link:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.card.is-picked { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow-hover); }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.card-top { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 18px; }

.logo {
  position: relative; display: grid; place-items: center; width: 48px; height: 48px; border-radius: 14px;
  background: oklch(var(--logo-l) var(--logo-c) var(--hue));
  overflow: hidden;
}
.logo img { position: relative; z-index: 1; width: 28px; height: 28px; border-radius: 6px; }
.logo img.is-broken { display: none; }
.monogram {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: oklch(55% 0.16 var(--hue)); font-size: 20px; font-weight: 800;
}
.logo:has(img:not(.is-broken)) .monogram { visibility: hidden; }

.tag {
  padding: 4px 10px; border-radius: 999px; background: var(--surface-2);
  color: var(--muted); font-size: 12px; font-weight: 600;
}

.card-title { margin: 0; font-size: 18px; font-weight: 700; line-height: 1.3; letter-spacing: -0.025em; word-break: keep-all; }
.card-link { text-decoration: none; }
.card-link::after { content: ''; position: absolute; inset: 0; border-radius: inherit; }
.card-link:focus-visible { outline: none; }

.card-host {
  margin: 6px 0 0; padding-right: 28px;
  color: var(--muted); font: 500 13px var(--mono); letter-spacing: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.card-extra { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; padding-top: 14px; }
.card-extra:empty { display: none; }
.card-extra a {
  position: relative; z-index: 2; padding: 4px 10px; border: 1px solid var(--border); border-radius: 999px;
  color: var(--muted); font: 500 12px var(--mono); text-decoration: none; transition: color 0.2s, border-color 0.2s;
}
.card-extra a:hover { color: var(--accent); border-color: var(--accent); }

.card-arrow {
  position: absolute; right: 18px; bottom: 18px; width: 20px; height: 20px;
  fill: none; stroke: var(--faint); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  transition: stroke 0.2s;
}
.card:hover .card-arrow { stroke: var(--text); }

mark { background: var(--accent-soft); color: var(--accent); border-radius: 3px; padding: 0 1px; }

.empty { margin: 0; padding: 64px 0; color: var(--muted); text-align: center; }

/* ── Responsive ──────────────────────────────────────── */

@media (max-width: 720px) {
  html { scroll-padding-top: 150px; }
  .toolbar-inner { gap: 8px; padding-top: 10px; padding-bottom: 10px; }
  .search { flex-basis: 100%; }
  .segmented button { flex: 1; justify-content: center; padding: 0 8px; }
  .segmented { flex: 1; min-width: 0; }
  .segmented button span { display: none; }
  .grid { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .card { min-height: 0; }
}

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