/* Modern CSS showcase - demonstrating various CSS features */
:root {
  --primary: #6366f1;
  --secondary: #ec4899;
  --surface: oklch(98% 0.01 240);
  --text: color-mix(in oklch, black 85%, var(--primary));
  --radius: 0.5rem;
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
}

/* Container queries */
@container sidebar (min-width: 400px) {
  .widget { grid-template-columns: 1fr 1fr; }
}

/* Nesting and logical properties */
.card {
  padding-block: 1.5rem;
  padding-inline: 2rem;
  border-radius: var(--radius);
  background: var(--surface);

  & > h2 {
    font-size: clamp(1.25rem, 4vw, 2rem);
    text-wrap: balance;
  }

  &:has(img) { container-type: inline-size; }
  &:not(:last-child) { margin-block-end: 1rem; }
}

/* Grid with named areas */
.layout {
  display: grid;
  grid-template:
    "header header" auto
    "nav    main"   1fr
    "footer footer" auto
    / 250px 1fr;
  min-height: 100dvh;
}

/* Animation with @property */
@property --gradient-angle {
  syntax: "<angle>";
  initial-value: 0deg;
  inherits: false;
}

@keyframes rotate-gradient {
  to { --gradient-angle: 360deg; }
}

.animated-border {
  background: conic-gradient(
    from var(--gradient-angle),
    var(--primary),
    var(--secondary),
    var(--primary)
  );
  animation: rotate-gradient 3s linear infinite;
}

/* Complex selectors */
input:is([type="email"], [type="url"]):valid {
  border-color: oklch(0.7 0.15 145);
}

dialog::backdrop {
  background: oklch(0 0 0 / 0.5);
  backdrop-filter: blur(4px);
}

/* Scroll-driven animations */
@supports (animation-timeline: scroll()) {
  .progress-bar {
    animation: grow-progress auto linear;
    animation-timeline: scroll(root);
  }

  @keyframes grow-progress {
    from { transform: scaleX(0); }
    to { transform: scaleX(1); }
  }
}

/* Responsive with custom media */
@media (prefers-color-scheme: dark) {
  :root {
    --surface: oklch(15% 0.02 260);
    --text: oklch(95% 0.01 240);
  }
}

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

/* Subgrid for alignment */
.form-row {
  display: grid;
  grid-template-columns: subgrid;
  grid-column: span 2;

  & label { justify-self: end; }
  & input { justify-self: start; }
}

/* Layers for cascade control */
@layer reset, base, components, utilities;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  body { margin: 0; font-family: system-ui, sans-serif; }
}

@layer utilities {
  .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    clip: rect(0, 0, 0, 0);
    overflow: hidden;
  }
}
