/* cssShowcase.com — performance-first stylesheet */

@layer reset, base, layout, components, hero, filter, utilities;

/* ─── Reset ──────────────────────────────────────────────── */
@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  * { margin: 0; padding: 0; }
  img, picture, video, canvas, svg { display: block; max-width: 100%; }
  input, button, textarea, select { font: inherit; }
  p, h1, h2, h3, h4, h5, h6 { overflow-wrap: break-word; }
}

/* ─── Base tokens ─────────────────────────────────────────── */
@layer base {
  :root {
    --bg:            oklch(0.97 0.006 260);
    --text:          oklch(0.18 0.025 260);
    --muted:         oklch(0.48 0.025 260);
    --subtle:        oklch(0.88 0.01 260);
    --accent:        oklch(0.52 0.22 265);
    --accent-hover:  oklch(0.43 0.24 265);
    --accent-soft:   oklch(0.92 0.06 265);
    --accent-bg:     oklch(0.52 0.22 265);
    --accent-bg-hover: oklch(0.43 0.24 265);
    --card:          oklch(1 0 0);
    --card-border:   oklch(0 0 0 / 0.07);
    --radius:        0.5rem;
    --radius-lg:     1rem;
    --font-sans:     "DM Sans", system-ui, sans-serif;
    --font-display:  "Syne", "DM Sans", system-ui, sans-serif;
    --font-mono:     "JetBrains Mono", "Fira Code", ui-monospace, monospace;
    --shadow-sm:     0 1px 3px oklch(0 0 0 / 0.08);
    --shadow-md:     0 4px 16px oklch(0 0 0 / 0.1);
    --shadow-lg:     0 12px 40px oklch(0 0 0 / 0.14);
  }

  @media (prefers-color-scheme: dark) {
    :root {
      --bg:           oklch(0.13 0.02 260);
      --text:         oklch(0.93 0.01 260);
      --muted:        oklch(0.63 0.02 260);
      --subtle:       oklch(0.22 0.02 260);
      --accent:       oklch(0.72 0.19 265);
      --accent-hover: oklch(0.78 0.16 265);
      --accent-soft:  oklch(0.25 0.06 265);
      --accent-bg:    oklch(0.52 0.22 265);
      --accent-bg-hover: oklch(0.48 0.22 265);
      --card:         oklch(0.19 0.02 260);
      --card-border:  oklch(1 0 0 / 0.07);
    }
  }

  html { font-size: clamp(1rem, 0.95rem + 0.25vw, 1.125rem); scroll-behavior: smooth; }
  body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
    line-height: 1.65;
    min-height: 100vh;
  }
  a { color: var(--accent); text-decoration: none; }
  a:hover { text-decoration: underline; }
  code, pre { font-family: var(--font-mono); }
  ::selection { background: var(--accent-soft); }
}

/* ─── Layout ──────────────────────────────────────────────── */
@layer layout {
  .wrap { width: min(80rem, 100% - 2rem); margin-inline: auto; }
  .wrap--wide { width: min(90rem, 100% - 2rem); margin-inline: auto; }

  .page-header {
    position: sticky; top: 0; z-index: 100;
    padding-block: 1rem;
    background: oklch(from var(--bg) l c h / 0.85);
    backdrop-filter: blur(0.75rem);
    -webkit-backdrop-filter: blur(0.75rem);
    border-bottom: 1px solid var(--card-border);
  }
  .page-header .wrap {
    display: flex; flex-wrap: wrap;
    align-items: center; justify-content: space-between; gap: 1rem;
  }
  .page-footer {
    padding-block: 2rem; margin-top: 4rem;
    border-top: 1px solid var(--card-border);
    color: var(--muted); font-size: 0.875rem;
  }
  .page-footer .wrap { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 1rem; }
}

/* ─── Components ──────────────────────────────────────────── */
@layer components {
  /* Nav */
  .logo {
    font-family: var(--font-display);
    font-weight: 700; font-size: 1.2rem;
    color: var(--text); letter-spacing: -0.02em;
  }
  .nav { display: flex; gap: 1.5rem; align-items: center; }
  .nav a { color: var(--muted); font-size: 0.9rem; font-weight: 500; }
  .nav a:hover { color: var(--text); text-decoration: none; }

  /* Badges */
  .badge {
    display: inline-flex; align-items: center; gap: 0.35rem;
    padding: 0.2rem 0.55rem; border-radius: 999px;
    font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  }
  .badge--supported    { background: oklch(0.88 0.1 145);  color: oklch(0.28 0.1 145); }
  .badge--experimental { background: oklch(0.93 0.1 75);   color: oklch(0.38 0.12 75); }
  .badge--new          { background: oklch(0.88 0.12 265);  color: oklch(0.28 0.14 265); }

  /* Tags (for filter) */
  .tag {
    display: inline-flex; align-items: center;
    padding: 0.15rem 0.5rem; border-radius: 999px;
    font-size: 0.7rem; font-weight: 600;
    background: var(--subtle); color: var(--muted);
    border: 1px solid var(--card-border);
  }

  /* Buttons */
  .btn {
    display: inline-flex; align-items: center; gap: 0.4rem;
    padding: 0.55rem 1.1rem; border-radius: var(--radius); border: none;
    font-size: 0.9rem; font-weight: 600; cursor: pointer;
    transition: background 0.15s, color 0.15s, box-shadow 0.15s;
    text-decoration: none;
  }
  .btn--primary {
    background: var(--accent-bg); color: white;
    box-shadow: 0 2px 8px oklch(from var(--accent) l c h / 0.35);
  }
  .btn--primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 4px 16px oklch(from var(--accent) l c h / 0.4);
    text-decoration: none;
  }
  .btn--secondary { background: var(--subtle); color: var(--text); }
  .btn--secondary:hover { background: oklch(0 0 0 / 0.1); text-decoration: none; }
  .btn--ghost {
    background: transparent; color: var(--muted);
    border: 1px solid var(--card-border); padding: 0.4rem 0.8rem;
  }
  .btn--ghost:hover { color: var(--text); border-color: var(--muted); text-decoration: none; }

  /* Code blocks */
  .code-block {
    position: relative;
    display: grid;      /* makes <pre> a grid item so min-width: 0 works */
    background: oklch(0.12 0.02 260);
    color: oklch(0.88 0.01 260);
    border-radius: var(--radius);
    overflow: hidden;   /* clips border-radius corners */
    border: 1px solid oklch(1 0 0 / 0.07);
  }
  /* min-width: 0 lets the pre shrink below its content size;
     overflow-x: auto then creates the horizontal scroll within those bounds */
  .code-block pre { min-width: 0; padding: 1.1rem 1.25rem; overflow-x: auto; font-size: 0.85rem; line-height: 1.6; }
  .code-block code { color: oklch(0.85 0.08 265); }
  .code-block .copy-wrap { position: absolute; top: 0.5rem; right: 0.5rem; }
  .code-block .copy-wrap .btn { font-size: 0.75rem; padding: 0.3rem 0.6rem; }

  /* Callout */
  .callout {
    padding: 1rem 1.25rem;
    border-radius: var(--radius);
    border-left: 3px solid var(--accent);
    background: var(--accent-soft);
    font-size: 0.9rem;
  }
  .callout--warn {
    border-left-color: oklch(0.7 0.15 75);
    background: oklch(0.96 0.05 75);
  }
  @media (prefers-color-scheme: dark) {
    .callout--warn { background: oklch(0.22 0.05 75); }
  }

  /* Cards */
  .card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr));
    gap: 1.1rem;
  }
  .card {
    position: relative;
    background: var(--card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--card-border);
    padding: 1.25rem;
    display: flex; flex-direction: column; gap: 0.5rem;
    transition: box-shadow 0.15s, border-color 0.15s;
    cursor: pointer;
  }
  .card:hover { box-shadow: var(--shadow-md); border-color: oklch(from var(--accent) l c h / 0.25); }
  .card h2 { font-size: 0.975rem; margin: 0; }
  .card h2 a { color: var(--text); }
  .card h2 a:hover { color: var(--accent); text-decoration: none; }
  /* Stretched link — expands the title anchor to cover the entire card */
  .card h2 a::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
  }
  .card p { font-size: 0.855rem; color: var(--muted); margin: 0; }
  .card .card-tags { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: auto; padding-top: 0.5rem; }

  /* Snippet page layout */
  .snippet-preview {
    min-height: 14rem;
    display: grid; place-items: center;
    border-radius: var(--radius-lg);
    border: 1px solid var(--card-border);
    padding: 2rem;
    background: var(--card);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
  }

  .article-section { margin-top: 2.25rem; }
  .article-section h2 {
    font-size: 1.15rem; font-weight: 700;
    margin-bottom: 0.75rem; letter-spacing: -0.01em;
  }
  .article-section p + p { margin-top: 0.8rem; }
  .article-section .code-block { margin-top: 1rem; }
  .article-section ul, .article-section ol { padding-left: 1.25rem; }
  .article-section li { margin-bottom: 0.4rem; }

  .sidebar { margin-top: 2rem; }
  .sidebar--sticky { position: sticky; top: 5rem; }
  .sidebar h3 {
    font-size: 0.78rem; text-transform: uppercase;
    letter-spacing: 0.07em; color: var(--muted); margin-bottom: 0.75rem;
  }
  .sidebar ul { list-style: none; }
  .sidebar li { margin-bottom: 0.5rem; font-size: 0.9rem; }

  /* Same min-width: 0 fix for snippet two-column grids */
  .snippet-hero > *,
  .snippet-body > * { min-width: 0; }

  @media (max-width: 52rem) {
    .snippet-hero   { grid-template-columns: 1fr !important; }
    .snippet-actions { flex-direction: row; flex-wrap: wrap; align-items: center; }
    .snippet-body   { grid-template-columns: 1fr !important; }
  }
}

/* ─── Hero ────────────────────────────────────────────────── */
@layer hero {
  .site-hero {
    position: relative;
    overflow: hidden;
    padding-block: clamp(4rem, 10vw, 7rem);
    background:
      radial-gradient(ellipse 80% 60% at 20% 40%, oklch(0.65 0.22 265 / 0.18) 0%, transparent 60%),
      radial-gradient(ellipse 60% 50% at 80% 70%, oklch(0.55 0.2 300 / 0.15) 0%, transparent 55%),
      var(--bg);
  }

  @media (prefers-color-scheme: dark) {
    .site-hero {
      background:
        radial-gradient(ellipse 80% 60% at 20% 40%, oklch(0.45 0.22 265 / 0.3) 0%, transparent 60%),
        radial-gradient(ellipse 60% 50% at 80% 70%, oklch(0.38 0.2 300 / 0.25) 0%, transparent 55%),
        var(--bg);
    }
  }

  .site-hero::before {
    content: "";
    position: absolute; inset: 0;
    background-image:
      radial-gradient(circle at 1px 1px, oklch(0 0 0 / 0.04) 1px, transparent 0);
    background-size: 24px 24px;
    pointer-events: none;
  }

  .hero-inner {
    position: relative; z-index: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3rem;
    align-items: center;
  }

  @media (max-width: 52rem) {
    .hero-inner { grid-template-columns: 1fr; }
    .hero-demos { display: none; }
  }

  .hero-eyebrow {
    display: inline-flex; align-items: center; gap: 0.5rem;
    font-size: 0.78rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.08em; color: var(--accent);
    margin-bottom: 1rem;
  }
  .hero-eyebrow::before {
    content: "";
    display: block; width: 1.5rem; height: 2px;
    background: var(--accent); border-radius: 2px;
  }

  .hero-title {
    font-family: var(--font-display);
    font-size: clamp(2.25rem, 5vw, 3.5rem);
    line-height: 1.1;
    letter-spacing: -0.03em;
    font-weight: 700;
  }
  .hero-title em {
    font-style: normal;
    background: linear-gradient(135deg, var(--accent), oklch(0.55 0.2 300));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
  }

  .hero-sub {
    margin-top: 1.25rem;
    font-size: clamp(1rem, 2vw, 1.125rem);
    color: var(--muted); max-width: 40ch; line-height: 1.7;
  }

  .hero-actions {
    display: flex; flex-wrap: wrap; gap: 0.75rem;
    margin-top: 2rem;
  }

  /* Live mini-demo panel */
  .hero-demos {
    display: grid; gap: 0.75rem;
  }

  .mini-demo {
    background: var(--card);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-lg);
    padding: 1rem 1.25rem;
    display: flex; align-items: center; gap: 1rem;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s;
  }
  .mini-demo:hover { box-shadow: var(--shadow-md); }

  .mini-demo__label {
    flex: 1; font-size: 0.85rem; color: var(--muted);
  }
  .mini-demo__label strong { display: block; color: var(--text); font-size: 0.9rem; margin-bottom: 0.1rem; }

  /* ── inline demo: glassmorphism swatch ── */
  .demo-glass {
    width: 3.5rem; height: 3.5rem; flex-shrink: 0; border-radius: var(--radius);
    background: linear-gradient(135deg, oklch(0.65 0.22 265), oklch(0.5 0.22 300));
    position: relative; overflow: hidden;
  }
  .demo-glass::after {
    content: "";
    position: absolute; inset: 25% 15%;
    background: oklch(1 0 0 / 0.25);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border: 1px solid oklch(1 0 0 / 0.4);
    border-radius: 0.25rem;
  }

  /* ── inline demo: scroll bar ── */
  .demo-scroll-wrap {
    width: 3.5rem; height: 3.5rem; flex-shrink: 0;
    background: var(--subtle); border-radius: var(--radius);
    overflow: hidden; position: relative;
  }
  .demo-scroll-bar {
    height: 3px; width: 60%;
    background: var(--accent); border-radius: 2px;
    position: absolute; top: 0.5rem; left: 0.5rem;
    animation: demo-fill 2.5s ease-in-out infinite alternate;
  }
  @keyframes demo-fill { from { width: 15%; } to { width: 85%; } }
  .demo-scroll-lines { padding: 1.25rem 0.5rem 0.5rem; display: flex; flex-direction: column; gap: 0.35rem; }
  .demo-scroll-lines span {
    display: block; height: 2px; border-radius: 2px; background: var(--muted); opacity: 0.3;
  }
  .demo-scroll-lines span:nth-child(1) { width: 90%; }
  .demo-scroll-lines span:nth-child(2) { width: 70%; }
  .demo-scroll-lines span:nth-child(3) { width: 80%; }

  /* ── inline demo: toggle ── */
  .demo-toggle-wrap {
    width: 3.5rem; height: 3.5rem; flex-shrink: 0;
    background: var(--subtle); border-radius: var(--radius);
    display: grid; place-items: center;
  }
  .demo-toggle {
    width: 2.2rem; height: 1.1rem;
    background: var(--accent); border-radius: 999px;
    position: relative;
    animation: demo-toggle-slide 2s ease-in-out infinite alternate;
  }
  .demo-toggle::after {
    content: "";
    position: absolute; top: 2px; right: 2px;
    width: 0.7rem; height: 0.7rem;
    background: white; border-radius: 50%;
    box-shadow: 0 1px 3px oklch(0 0 0 / 0.2);
  }
  @keyframes demo-toggle-slide {
    0%, 40%  { background: oklch(0.7 0.05 260); }
    60%, 100%{ background: var(--accent); }
  }

  /* ── inline demo: :has() pill ── */
  .demo-has-wrap {
    width: 3.5rem; height: 3.5rem; flex-shrink: 0;
    background: var(--subtle); border-radius: var(--radius);
    display: grid; place-items: center;
  }
  .demo-has-pill {
    padding: 0.2rem 0.55rem;
    background: var(--accent-soft);
    border: 1px solid oklch(from var(--accent) l c h / 0.4);
    border-radius: 999px;
    font-size: 0.65rem; font-family: var(--font-mono);
    color: var(--accent); font-weight: 600;
    animation: demo-has-pulse 2s ease-in-out infinite;
  }
  @keyframes demo-has-pulse {
    0%, 100% { opacity: 0.5; transform: scale(0.95); }
    50%       { opacity: 1;   transform: scale(1); }
  }

  /* ── inline demo: grid ── */
  .demo-grid-wrap {
    width: 3.5rem; height: 3.5rem; flex-shrink: 0;
    background: var(--subtle); border-radius: var(--radius);
    display: grid; place-items: center; padding: 0.4rem;
  }
  .demo-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 0.2rem; width: 100%;
    animation: demo-grid-expand 2.5s ease-in-out infinite alternate;
  }
  @keyframes demo-grid-expand {
    0%, 30%  { grid-template-columns: 1fr; }
    70%, 100%{ grid-template-columns: 1fr 1fr; }
  }
  .demo-grid span {
    display: block; height: 0.65rem; border-radius: 2px; background: var(--accent); opacity: 0.6;
  }
  .demo-grid span:nth-child(even) { opacity: 0.35; }
}

/* ─── Filter bar ──────────────────────────────────────────── */
@layer filter {
  .filter-bar {
    display: flex; flex-wrap: wrap; gap: 0.5rem;
    margin-bottom: 1.75rem;
  }

  .filter-bar label {
    display: inline-flex; align-items: center;
    padding: 0.3rem 0.75rem; border-radius: 999px;
    font-size: 0.8rem; font-weight: 600; cursor: pointer;
    border: 1.5px solid var(--card-border);
    color: var(--text); background: var(--card);
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    user-select: none;
  }
  .filter-bar label:hover { color: var(--text); border-color: var(--accent); }

  /* Active-pill highlight — inputs live outside .filter-bar as siblings of .card-grid */
  #filter-all:checked         ~ .filter-bar label[for="filter-all"]         ,
  #filter-layout:checked      ~ .filter-bar label[for="filter-layout"]      ,
  #filter-color:checked       ~ .filter-bar label[for="filter-color"]       ,
  #filter-animation:checked   ~ .filter-bar label[for="filter-animation"]   ,
  #filter-no-js:checked       ~ .filter-bar label[for="filter-no-js"]       ,
  #filter-experimental:checked ~ .filter-bar label[for="filter-experimental"],
  #filter-typography:checked  ~ .filter-bar label[for="filter-typography"]  ,
  #filter-ui:checked          ~ .filter-bar label[for="filter-ui"]          ,
  #filter-performance:checked ~ .filter-bar label[for="filter-performance"] ,
  #filter-new-feature:checked ~ .filter-bar label[for="filter-new-feature"] {
    background: var(--accent-bg); color: white; border-color: var(--accent-bg);
  }

  /* Hide cards that don't match the selected filter */
  #filter-all:checked         ~ .card-grid .card { display: flex; }

  #filter-layout:checked      ~ .card-grid .card:not([data-tags~="layout"])      { display: none; }
  #filter-color:checked       ~ .card-grid .card:not([data-tags~="color"])       { display: none; }
  #filter-animation:checked   ~ .card-grid .card:not([data-tags~="animation"])   { display: none; }
  #filter-no-js:checked       ~ .card-grid .card:not([data-tags~="no-js"])       { display: none; }
  #filter-experimental:checked ~ .card-grid .card:not([data-tags~="experimental"]) { display: none; }
  #filter-typography:checked  ~ .card-grid .card:not([data-tags~="typography"])  { display: none; }
  #filter-ui:checked          ~ .card-grid .card:not([data-tags~="ui"])          { display: none; }
  #filter-performance:checked ~ .card-grid .card:not([data-tags~="performance"]) { display: none; }
  #filter-new-feature:checked ~ .card-grid .card:not([data-tags~="new-feature"]) { display: none; }
}

/* ─── Utilities ───────────────────────────────────────────── */
@layer utilities {
  .flow > * + * { margin-top: 1rem; }
  .flow-lg > * + * { margin-top: 1.5rem; }
  .text-muted { color: var(--muted); }
  .text-small { font-size: 0.875rem; }
  .mt-2 { margin-top: 2rem; }
  .mt-3 { margin-top: 3rem; }
}

/* ─── Responsive ──────────────────────────────────────────── */
@layer responsive {

  /* Article pages: two-column (article + sidebar) */
  .article-layout {
    display: grid;
    grid-template-columns: 1fr 15rem;
    gap: 3rem;
    align-items: start;
  }
  /* Prevent grid children from expanding beyond their column.
     Without min-width: 0, a <pre> with a long line forces the article
     wider than the viewport even in a 1fr column. */
  .article-layout > * { min-width: 0; }

  /* ── Breakpoint: tablet and below (≤ 52rem / ~830px) ── */
  @media (max-width: 52rem) {

    /* Article layout: stack article above sidebar */
    .article-layout {
      grid-template-columns: 1fr;
      gap: 2rem;
    }

    /* Snippet pages */
    .snippet-hero { grid-template-columns: 1fr !important; }
    .snippet-actions { flex-direction: row !important; flex-wrap: wrap; align-items: center; }
    .snippet-body  { grid-template-columns: 1fr !important; }

    /* Sidebar: un-stick so it flows naturally below article content */
    .sidebar--sticky { position: static; top: auto; }
    .sidebar { border-top: 1px solid var(--card-border); padding-top: 1.5rem; margin-top: 1rem; }

    /* Card grid: allow single column on narrow screens */
    .card-grid {
      grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
    }

    /* Snippet preview: less padding on mobile */
    .snippet-preview { padding: 1.25rem; }

    /* Article sections: tighten spacing */
    .article-section { margin-top: 1.75rem; }
  }

  /* ── Breakpoint: phone (≤ 32rem / ~512px) ── */
  @media (max-width: 32rem) {

    /* Single-column card grid at phone widths */
    .card-grid { grid-template-columns: 1fr; }

    /* Nav: tighten gap so logo + links fit on one row */
    .nav { gap: 1rem; }
    .nav a { font-size: 0.82rem; }

    /* Buttons: full-width stacked in hero areas */
    .hero-actions,
    .hero-btns { flex-direction: column; }
    .hero-actions .btn,
    .hero-btns .btn { width: 100%; justify-content: center; }

    /* Reduce hero padding */
    .site-hero { padding-block: clamp(2.5rem, 8vw, 4rem); }

    /* Code blocks: ensure horizontal scroll works on phones */
    .code-block { border-radius: var(--radius); }
    .code-block pre { font-size: 0.78rem; padding: 1rem; }

    /* Callout: reduce padding */
    .callout { padding: 0.75rem 1rem; }
  }
}
