/* =========================================================
   Design Systems Gallery — neutral host
   카드 안의 brand hero가 주인공. 호스트는 차분한 grayscale.
========================================================= */

:root {
  /* Palette — slate */
  --bg-base: #ffffff;
  --bg-subtle: #f8fafc;
  --bg-elevated: #ffffff;
  --bg-overlay: rgba(15, 23, 42, 0.45);

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-tertiary: #94a3b8;

  --border-default: #e2e8f0;
  --border-subtle: #f1f5f9;
  --border-strong: #cbd5e1;
  --border-focus: #0f172a;

  --accent: #0f172a;
  --accent-hover: #1e293b;
  --accent-bg: #f1f5f9;

  /* Spacing */
  --space-2: 4px;
  --space-3: 8px;
  --space-4: 12px;
  --space-5: 16px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 48px;

  /* Radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  /* Shadow */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 16px 48px rgba(15, 23, 42, 0.16);

  /* Z-index */
  --z-topbar: 50;
  --z-drawer: 100;
  --z-scrim: 90;

  /* Layout */
  --topbar-h: 56px;
  --sidebar-w: 280px;
  --content-max: 1600px;
  --detail-max: 960px;

  --transition: 0.18s ease;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }   /* author rules can override UA [hidden] */
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Pretendard', 'Apple SD Gothic Neo', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-base);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }

button { font: inherit; cursor: pointer; }

/* Skip link */
.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--accent); color: #fff;
  padding: 8px 12px; z-index: 999;
}
.skip-link:focus { left: 8px; top: 8px; }

/* ========= Topbar ========= */
.topbar {
  position: sticky; top: 0; z-index: var(--z-topbar);
  height: var(--topbar-h);
  display: flex; align-items: center;
  padding: 0 var(--space-6);
  background: rgba(255,255,255,0.92);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border-default);
}
.logo {
  display: inline-flex; align-items: center; gap: 10px;
  text-decoration: none; color: var(--text-primary);
  font-weight: 600;
}
.logo-mark {
  width: 18px; height: 18px; border-radius: 4px;
  background: linear-gradient(135deg, #0f172a 0%, #475569 100%);
}
.logo-text { letter-spacing: -0.01em; }
.topbar-meta { margin-left: auto; display: flex; align-items: center; gap: var(--space-5); }
.result-count { color: var(--text-secondary); font-variant-numeric: tabular-nums; }


/* ========= Layout ========= */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  gap: 0;
  max-width: var(--content-max);
  margin: 0 auto;
  min-height: calc(100vh - var(--topbar-h));
}

/* ========= Sidebar / Filters ========= */
.sidebar {
  border-right: 1px solid var(--border-default);
  background: var(--bg-base);
  position: sticky;
  top: var(--topbar-h);
  align-self: start;
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
}
.sidebar-inner { padding: var(--space-6) var(--space-5) var(--space-8); }

.filter-group { margin-bottom: var(--space-6); }
.filter-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  margin-bottom: var(--space-3);
}

.search, .select {
  width: 100%;
  height: 36px;
  padding: 0 var(--space-4);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  background: var(--bg-base);
  color: var(--text-primary);
  font: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.search:focus, .select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(15,23,42,0.10);
}

.filter-options {
  display: flex; flex-wrap: wrap; gap: 6px;
}
.facet-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-default);
  background: var(--bg-base);
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.facet-chip:hover { border-color: var(--border-strong); color: var(--text-primary); }
.facet-chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.facet-chip[aria-pressed="true"]:hover { background: var(--accent-hover); }
.facet-chip:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(15,23,42,0.18);
}

.range-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3);
}
.range {
  width: 100%;
  accent-color: var(--accent);
}
.range-readout {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.btn-secondary {
  width: 100%;
  height: 36px;
  border: 1px solid var(--border-default);
  background: var(--bg-base);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font: inherit;
}
.btn-secondary:hover { background: var(--bg-subtle); }
.btn-secondary:focus-visible {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(15,23,42,0.10);
}
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border-default);
  color: var(--text-primary);
  height: 32px; padding: 0 12px;
  border-radius: var(--radius-md);
}
.btn-ghost:hover { background: var(--bg-subtle); }

/* ========= Content ========= */
.content {
  padding: var(--space-6) var(--space-7);
  min-width: 0;
}

.active-chips {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-bottom: var(--space-5);
  min-height: 0;
}
.active-chips:empty { display: none; }
.active-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--accent-bg);
  font-size: 12px;
  color: var(--text-primary);
  border: 1px solid var(--border-default);
}
.active-chip button {
  background: transparent; border: 0; color: var(--text-tertiary);
  cursor: pointer; line-height: 1; padding: 0; font-size: 14px;
}
.active-chip button:hover { color: var(--text-primary); }

/* ========= Grid ========= */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-6);
}

/* ========= Card ========= */
.card {
  display: flex; flex-direction: column;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
  padding: 0;
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}
.card:focus-visible {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(15,23,42,0.18);
}

.card-hero {
  position: relative;
  aspect-ratio: 4 / 3;     /* ~ 60% of card height for 280×360 */
  background: var(--bg-subtle);
  overflow: hidden;
  border-bottom: 1px solid var(--border-default);
  pointer-events: none;    /* never intercept clicks meant for the card link */
}
.card-hero iframe {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  border: 0;
  pointer-events: none;
}
.card-meta { pointer-events: none; }   /* a-tag receives all clicks */

.card-meta {
  padding: var(--space-4) var(--space-5) var(--space-5);
  display: flex; flex-direction: column; gap: 8px;
}
.card-title-row {
  display: flex; align-items: center; gap: 8px;
}
.card-swatch {
  width: 14px; height: 14px; border-radius: 4px; flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.06);
}
.card-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  margin: 0;
}
.card-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-badges {
  display: flex; flex-wrap: wrap; gap: 4px;
  margin-top: 2px;
}
.badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
}
.badge-region { background: #f8fafc; }

/* ========= Empty ========= */
.empty {
  text-align: center;
  padding: var(--space-8) var(--space-6);
  color: var(--text-secondary);
}
.empty-mark {
  font-size: 32px; color: var(--text-tertiary); margin-bottom: var(--space-4);
}
.empty button { display: inline-block; width: auto; padding: 0 16px; margin-top: var(--space-4); }

/* ========= Detail ========= */
.detail { background: var(--bg-base); }
.detail-inner {
  max-width: var(--detail-max);
  margin: 0 auto;
  padding: var(--space-7) var(--space-6) var(--space-8);
}
.back {
  display: inline-block;
  color: var(--text-secondary);
  text-decoration: none;
  margin-bottom: var(--space-6);
  font-size: 13px;
}
.back:hover { color: var(--text-primary); }

.detail-header {
  margin-bottom: var(--space-7);
}
.detail-title {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 var(--space-3);
  display: flex; align-items: center; gap: 12px;
}
.detail-swatch {
  width: 28px; height: 28px; border-radius: 6px;
  border: 1px solid rgba(0,0,0,0.06);
  flex-shrink: 0;
}
.detail-tagline {
  color: var(--text-secondary);
  font-size: 16px;
  margin: 0 0 var(--space-5);
}
.detail-meta-row {
  display: flex; flex-wrap: wrap; gap: 6px;
}
.detail-meta-row .badge { font-size: 11px; padding: 4px 8px; }

/* Raw md panel */
.raw-md-panel {
  margin: var(--space-5) 0 var(--space-7);
  padding: var(--space-5);
  background: var(--bg-subtle);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
}
.raw-md-actions {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
}
.btn-copy {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: var(--radius-md);
  padding: 8px 14px;
  font: 600 13px/1 inherit;
}
.btn-copy:hover { background: var(--accent-hover); }
.btn-copy:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(15,23,42,0.18); }
.btn-toggle-raw { width: auto; padding: 0 14px; height: 36px; }
.copy-status { font-size: 12px; color: var(--text-secondary); margin-left: 4px; }
.raw-md {
  margin: var(--space-4) 0 0;
  background: #0f172a; color: #e2e8f0;
  border-radius: var(--radius-md);
  padding: 16px 20px;
  max-height: 480px;
  overflow: auto;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 12px; line-height: 1.5;
  white-space: pre;
}
.raw-md.hidden { display: none; }

.detail-section {
  margin-bottom: var(--space-7);
  padding-top: var(--space-6);
  border-top: 1px solid var(--border-subtle);
}
.detail-section:first-of-type { border-top: 0; padding-top: 0; }
.detail-section h2 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  margin: 0 0 var(--space-3);
}
.detail-section h3 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 var(--space-5);
}

.detail-section h4, .detail-section h5, .detail-section h6 {
  margin: var(--space-5) 0 var(--space-3);
  font-weight: 600;
}
.detail-section h4 { font-size: 18px; }
.detail-section h5 { font-size: 15px; }

.detail-section p, .detail-section ul, .detail-section ol {
  margin: 0 0 var(--space-4);
}
.detail-section ul, .detail-section ol { padding-left: 22px; }
.detail-section li { margin-bottom: 4px; }
.detail-section li ul { margin-top: 4px; }

.detail-section .code {
  background: #0f172a;
  color: #e2e8f0;
  padding: 16px 20px;
  border-radius: var(--radius-md);
  overflow-x: auto;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.55;
  margin: 0 0 var(--space-4);
}
.detail-section code { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: 0.92em; background: var(--bg-subtle); padding: 1px 5px; border-radius: 3px; }
/* Reset inline-code styles when nested inside a code block (pre) */
.detail-section pre code,
.raw-md code {
  background: transparent;
  padding: 0;
  border-radius: 0;
  color: inherit;
  font-size: inherit;
}

/* Color swatch grid */
.swatch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
  margin: 0 0 var(--space-5);
}
.swatch {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.swatch-color { aspect-ratio: 3/2; }
.swatch-meta {
  padding: 6px 8px;
  font-size: 10.5px;
  font-family: ui-monospace, monospace;
  color: var(--text-secondary);
  background: var(--bg-base);
  border-top: 1px solid var(--border-subtle);
  display: flex; flex-direction: column; gap: 2px;
}
.swatch-meta .swatch-name { color: var(--text-primary); }

/* Token visualizers */
.token-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px,1fr));
  gap: 12px;
  margin: 0 0 var(--space-5);
}
.token-cell {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 16px 8px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-base);
}
.token-cell .token-vis {
  width: 64px; height: 64px;
  background: #fff;
  border: 1px solid var(--border-default);
}
.token-cell .token-name {
  font-family: ui-monospace, monospace;
  font-size: 11px;
  color: var(--text-secondary);
  text-align: center;
}
.token-cell .token-value {
  font-family: ui-monospace, monospace;
  font-size: 10.5px;
  color: var(--text-tertiary);
}

/* Type preview */
.type-preview {
  padding: var(--space-6);
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
  margin: 0 0 var(--space-5);
}
.type-preview-display {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
  margin: 0 0 var(--space-3);
}
.type-preview-body {
  color: var(--text-secondary);
  font-size: 14px;
  margin: 0;
}

/* Signature demo iframe */
.sig-demo-wrap {
  position: relative;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin: 0 0 var(--space-4);
}
.sig-demo {
  display: block;
  width: 100%;
  height: 480px;
  border: 0;
  background: #fff;
}
.sig-demo-actions {
  position: absolute; top: 12px; right: 12px;
  display: flex; gap: 6px;
}
.sig-demo-actions button {
  background: rgba(15,23,42,0.85);
  color: #fff;
  border: 0;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 11px;
}
.sig-demo-actions button:hover { background: var(--accent); }

.sources-list {
  margin: 0; padding-left: 20px;
}
.sources-list li { margin-bottom: 4px; }
.sources-list a { color: var(--accent); text-decoration: none; }
.sources-list a:hover { text-decoration: underline; }

/* ========= Responsive ========= */
.mobile-only { display: none; }

@media (max-width: 880px) {
  .mobile-only { display: inline-flex; align-items: center; gap: 6px; }
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    height: 100vh;
    width: 320px;
    max-width: 90vw;
    z-index: var(--z-drawer);
    background: var(--bg-base);
    border-right: 1px solid var(--border-default);
    transform: translateX(-100%);
    transition: transform 0.22s ease;
  }
  .sidebar[data-open="true"] { transform: translateX(0); }
  .sidebar-inner { padding-top: calc(var(--topbar-h) + var(--space-4)); }
  .scrim {
    position: fixed; inset: 0; background: var(--bg-overlay);
    z-index: var(--z-scrim);
  }
  .content { padding: var(--space-5) var(--space-5); }
  .detail-inner { padding: var(--space-5) var(--space-5) var(--space-7); }
  .detail-title { font-size: 28px; }
}

@media (max-width: 480px) {
  .grid { grid-template-columns: 1fr; }
}
