/* =========================================================================
   BarGen UI — design system
   Light is default; dark via [data-theme="dark"] on <html>.
   ========================================================================= */

:root {
  /* Neutral ramp (zinc/slate family) */
  --n-0:   #ffffff;
  --n-25:  #fafafa;
  --n-50:  #f5f5f6;
  --n-100: #ececee;
  --n-150: #e2e2e6;
  --n-200: #d6d6db;
  --n-300: #c0c0c7;
  --n-400: #9b9ba6;
  --n-500: #71717f;
  --n-600: #565664;
  --n-700: #3f3f4a;
  --n-800: #2a2a33;
  --n-900: #1a1a20;
  --n-950: #0e0e13;

  /* Accent — violet → indigo */
  --accent-50:  #f1eefe;
  --accent-100: #e3ddfd;
  --accent-200: #c8bdfb;
  --accent-400: #8b76f0;
  --accent-500: #7559e8;
  --accent-600: #6446d6;
  --accent-700: #5638bc;

  /* Semantic — light theme */
  --bg:            var(--n-25);
  --surface:       var(--n-0);
  --surface-2:     var(--n-50);
  --surface-sunken: var(--n-100);

  --text:          var(--n-900);
  --text-secondary: var(--n-600);
  --text-muted:    var(--n-500);

  --border:        var(--n-150);
  --border-strong: var(--n-300);

  --accent:        var(--accent-600);
  --accent-hover:  var(--accent-700);
  --accent-soft:   var(--accent-50);
  --accent-text:   var(--accent-700);
  --on-accent:     #ffffff;

  /* Preview stage — fixed neutral light backdrop in BOTH themes */
  --stage-bg:      #f4f4f6;
  --stage-grid:    rgba(20, 20, 30, 0.045);
  --stage-border:  rgba(20, 20, 30, 0.08);

  /* Code block */
  --code-bg:       var(--n-950);
  --code-text:     #e6e6ec;
  --code-border:   rgba(255, 255, 255, 0.08);

  /* Effects */
  --ring: 0 0 0 3px var(--accent-100), 0 0 0 1.5px var(--accent);
  --shadow-sm:  0 1px 2px rgba(16, 16, 24, 0.06), 0 1px 1px rgba(16, 16, 24, 0.04);
  --shadow-md:  0 4px 14px -4px rgba(16, 16, 24, 0.10), 0 2px 6px -2px rgba(16, 16, 24, 0.06);
  --shadow-lg:  0 24px 60px -16px rgba(16, 16, 24, 0.30), 0 8px 24px -8px rgba(16, 16, 24, 0.18);

  --radius-sm: 10px;
  --radius:    14px;
  --radius-lg: 18px;
  --radius-pill: 999px;

  --maxw: 1180px;
  --dur: 180ms;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);

  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", "Fira Code", Menlo, Consolas, monospace;

  color-scheme: light;
}

[data-theme="dark"] {
  --bg:            var(--n-950);
  --surface:       #16161c;
  --surface-2:     #1c1c23;
  --surface-sunken: #101015;

  --text:          #f3f3f6;
  --text-secondary: #adadbb;
  --text-muted:    #82828f;

  --border:        rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);

  --accent:        var(--accent-400);
  --accent-hover:  #9d8bf4;
  --accent-soft:   rgba(123, 89, 232, 0.16);
  --accent-text:   var(--accent-200);
  --on-accent:     #14101f;

  --code-bg:       #08080c;
  --code-text:     #e6e6ec;
  --code-border:   rgba(255, 255, 255, 0.07);

  --ring: 0 0 0 3px rgba(139, 118, 240, 0.28), 0 0 0 1.5px var(--accent);
  --shadow-sm:  0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md:  0 4px 16px -4px rgba(0, 0, 0, 0.5);
  --shadow-lg:  0 28px 70px -16px rgba(0, 0, 0, 0.72), 0 8px 24px -8px rgba(0, 0, 0, 0.5);

  color-scheme: dark;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}

body.modal-open { overflow: hidden; }

h1, h2, h3, p { margin: 0; }

a {
  color: var(--accent-text);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

button { font: inherit; cursor: pointer; }

img, svg { display: block; }

/* The hidden attribute must always win. Without !important, component display
   rules (.card{display:flex}, .state{display:flex}, .grid{display:grid}, …)
   override the UA [hidden]{display:none}, so filtering and empty/loading-state
   toggling set the attribute but nothing visually hides. */
[hidden] { display: none !important; }

:focus-visible {
  outline: none;
  box-shadow: var(--ring);
  border-radius: var(--radius-sm);
}

.wrap {
  width: 100%;
  max-width: var(--maxw);
  margin-inline: auto;
  padding-inline: clamp(1rem, 4vw, 2rem);
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: -3rem;
  z-index: 100;
  padding: 0.6rem 1rem;
  background: var(--accent);
  color: var(--on-accent);
  border-radius: var(--radius-sm);
  transition: top var(--dur) var(--ease);
}
.skip-link:focus { top: 1rem; text-decoration: none; }

/* ---------------------------------------------------------------- header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  height: 64px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--text);
  font-weight: 650;
  letter-spacing: -0.02em;
  font-size: 1.0625rem;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
}
.brand-accent { color: var(--accent); margin-left: 0.18em; }

.site-nav {
  display: none;
  align-items: center;
  gap: 1.5rem;
  margin-left: auto;
  font-size: 0.9375rem;
}
.site-nav a {
  color: var(--text-secondary);
  font-weight: 500;
}
.site-nav a:hover { color: var(--text); text-decoration: none; }

.theme-toggle {
  margin-left: auto;
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  color: var(--text-secondary);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.site-nav + .theme-toggle { margin-left: 0; }
.theme-toggle:hover { color: var(--text); border-color: var(--border-strong); }
.theme-toggle svg { transition: transform var(--dur) var(--ease), opacity var(--dur) var(--ease); }
.theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

/* ---------------------------------------------------------------- hero */
.hero {
  padding-top: clamp(2.5rem, 7vw, 5rem);
  padding-bottom: clamp(1.5rem, 4vw, 2.5rem);
  text-align: center;
}
.hero-eyebrow {
  display: inline-block;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent-text);
  background: var(--accent-soft);
  padding: 0.35rem 0.8rem;
  border-radius: var(--radius-pill);
  margin-bottom: 1.25rem;
}
.hero-title {
  font-size: clamp(2rem, 6vw, 3.4rem);
  line-height: 1.08;
  font-weight: 720;
  letter-spacing: -0.035em;
}
.hero-subtitle {
  max-width: 38rem;
  margin: 1.1rem auto 0;
  color: var(--text-secondary);
  font-size: clamp(1rem, 2.2vw, 1.1875rem);
}

/* ---------------------------------------------------------------- controls */
.controls {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding-top: clamp(1.5rem, 4vw, 2.5rem);
  padding-bottom: 1.25rem;
}
.search-field {
  position: relative;
  max-width: 420px;
  width: 100%;
}
.search-icon {
  position: absolute;
  left: 0.95rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}
#search {
  width: 100%;
  height: 46px;
  padding: 0 1rem 0 2.75rem;
  font-size: 0.9375rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
#search::placeholder { color: var(--text-muted); }
#search:focus-visible { box-shadow: var(--ring); border-color: var(--accent); }
#search::-webkit-search-cancel-button { -webkit-appearance: none; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.chip {
  padding: 0.45rem 0.95rem;
  font-size: 0.875rem;
  font-weight: 550;
  color: var(--text-secondary);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  transition: all var(--dur) var(--ease);
}
.chip:hover { color: var(--text); border-color: var(--border-strong); }
.chip[aria-pressed="true"] {
  color: var(--on-accent);
  background: var(--accent);
  border-color: var(--accent);
}

/* ---------------------------------------------------------------- gallery / grid */
#gallery {
  padding-bottom: clamp(3rem, 8vw, 6rem);
  min-height: 40vh;
}
.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
}
@media (min-width: 640px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 980px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}
.card:focus-within { border-color: var(--accent); }

/* Preview stage — fixed neutral light backdrop in both themes */
.stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  padding: 1.5rem;
  background-color: var(--stage-bg);
  background-image:
    linear-gradient(var(--stage-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--stage-grid) 1px, transparent 1px);
  background-size: 18px 18px;
  border-bottom: 1px solid var(--stage-border);
  color: #1a1a20;
  overflow: hidden;
}
/* Real flex box (NOT display:contents) so the shadow-DOM preview reliably
   renders and stays centred in every browser. */
.stage-host {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}
.stage-skeleton {
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 30%, rgba(255,255,255,0.55) 50%, transparent 70%);
  background-size: 200% 100%;
  animation: shimmer 1.3s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

.card-body {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 1.15rem 1.25rem 1.35rem;
  flex: 1;
}
.card-name {
  font-size: 1.0625rem;
  font-weight: 640;
  letter-spacing: -0.015em;
}
.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}
.badge {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--accent-text);
  background: var(--accent-soft);
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-pill);
}
.tag {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-pill);
}
.card-desc {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.55;
  flex: 1;
}
.card-action { margin-top: 0.35rem; }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  height: 42px;
  padding: 0 1.1rem;
  font-size: 0.9375rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
  white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn-icon { display: inline-flex; }

.btn-primary {
  color: var(--on-accent);
  background: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  color: var(--text);
  background: var(--surface);
  border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--surface-2); }

.card-action .btn { width: 100%; }

.btn.is-success {
  color: var(--on-accent);
  background: var(--accent);
  border-color: var(--accent);
}

/* ---------------------------------------------------------------- states */
.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  text-align: center;
  padding: clamp(3rem, 10vw, 6rem) 1rem;
  color: var(--text-secondary);
}
.state h2 {
  font-size: 1.25rem;
  font-weight: 640;
  color: var(--text);
  letter-spacing: -0.02em;
}
.state p { max-width: 26rem; }
.state .btn { margin-top: 0.5rem; }
.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- footer */
.site-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.footer-inner {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding-top: 2rem;
  padding-bottom: 2rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}
.footer-credit { color: var(--text-secondary); }
.footer-credit a { font-weight: 600; }

/* ---------------------------------------------------------------- modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: clamp(1rem, 4vw, 2rem);
}
.modal[hidden] { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 16, 0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity var(--dur) var(--ease);
}
.modal.is-open .modal-backdrop { opacity: 1; }

.modal-dialog {
  position: relative;
  width: min(680px, 100%);
  max-height: min(82vh, 760px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(12px) scale(0.985);
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.modal.is-open .modal-dialog { opacity: 1; transform: none; }

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.35rem 1.5rem 1rem;
  border-bottom: 1px solid var(--border);
}
.modal-eyebrow {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--accent-text);
}
.modal-title {
  font-size: 1.35rem;
  font-weight: 680;
  letter-spacing: -0.02em;
  margin-top: 0.2rem;
}
.modal-close {
  flex-shrink: 0;
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  color: var(--text-secondary);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.modal-close:hover { color: var(--text); background: var(--surface-sunken); }

.modal-body {
  padding: 1.25rem 1.5rem;
  overflow: auto;
}
.code-block {
  margin: 0;
  padding: 1.1rem 1.25rem;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: var(--radius);
  overflow: auto;
  max-height: 46vh;
}
.code-block code {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.7;
  color: var(--code-text);
  white-space: pre-wrap;
  word-break: break-word;
  tab-size: 2;
}

.modal-foot {
  display: flex;
  gap: 0.75rem;
  padding: 1.1rem 1.5rem 1.35rem;
  border-top: 1px solid var(--border);
}
.modal-foot .btn { flex: 1; }

/* ---------------------------------------------------------------- scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-pill);
  border: 3px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); background-clip: padding-box; }
.code-block::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); background-clip: padding-box; }

/* ---------------------------------------------------------------- responsive */
@media (min-width: 720px) {
  .site-nav { display: flex; }
  .site-nav + .theme-toggle { margin-left: 0; }
  .controls { flex-direction: row; align-items: center; justify-content: space-between; }
  .controls .chips { justify-content: flex-end; }
}

/* ---------------------------------------------------------------- motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .card:hover { transform: none; }
}
