/*!
 * Plain v1.0 — core.css
 * Tokens · Reset · Typografie · Basis-Elemente
 * Zero dependencies. MIT.
 */

@layer plain.tokens, plain.reset, plain.base, plain.components, plain.utilities;

/* =========================================================
   1. DESIGN TOKENS
   ========================================================= */
@layer plain.tokens {
  :root {
    color-scheme: light dark;

    /* --- Farbpalette (Light) --- */
    --color-primary:        hsl(232 70% 52%);
    --color-primary-hover:  hsl(232 70% 44%);
    --color-primary-soft:   hsl(232 80% 96%);
    --color-on-primary:     #fff;

    --color-bg:             hsl(220 20% 98%);
    --color-surface:        #fff;
    --color-surface-2:      hsl(220 18% 95%);
    --color-border:         hsl(220 14% 86%);
    --color-text:           hsl(222 24% 14%);
    --color-muted:          hsl(220 9% 44%);

    --color-success:        hsl(152 60% 34%);
    --color-success-soft:   hsl(152 60% 94%);
    --color-warning:        hsl(36 92% 40%);
    --color-warning-soft:   hsl(42 100% 93%);
    --color-danger:         hsl(356 70% 48%);
    --color-danger-soft:    hsl(356 90% 96%);

    --color-focus:          hsl(232 90% 60% / .45);

    /* --- Typografie --- */
    --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
                 "Noto Sans", "Liberation Sans", Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
                 "Liberation Mono", monospace;

    /* Modulare Skala (≈ 1.25), flüssig zwischen 360px und 1280px */
    --text-xs:  .75rem;
    --text-sm:  .875rem;
    --text-base: 1rem;
    --text-lg:  clamp(1.125rem, 1.08rem + .2vw, 1.25rem);
    --text-xl:  clamp(1.25rem, 1.17rem + .4vw, 1.5625rem);
    --text-2xl: clamp(1.5rem, 1.35rem + .7vw, 1.953rem);
    --text-3xl: clamp(1.75rem, 1.5rem + 1.2vw, 2.441rem);
    --text-4xl: clamp(2rem, 1.6rem + 2vw, 3.052rem);

    --leading-tight: 1.2;
    --leading-snug:  1.4;
    --leading-normal: 1.6;

    --weight-normal: 400;
    --weight-medium: 500;
    --weight-bold:   650;

    /* --- Spacing (rem) --- */
    --space-1: .25rem;
    --space-2: .5rem;
    --space-3: .75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;
    --space-7: 3rem;
    --space-8: 4rem;

    /* --- Radius --- */
    --radius-sm: .25rem;
    --radius:    .5rem;
    --radius-lg: .875rem;
    --radius-pill: 999px;

    /* --- Elevation --- */
    --shadow-1: 0 1px 2px hsl(220 30% 10% / .06), 0 1px 3px hsl(220 30% 10% / .08);
    --shadow-2: 0 4px 12px hsl(220 30% 10% / .08), 0 2px 4px hsl(220 30% 10% / .06);
    --shadow-3: 0 18px 40px hsl(220 30% 10% / .16), 0 6px 12px hsl(220 30% 10% / .08);

    /* --- Motion --- */
    --ease: cubic-bezier(.2, .7, .3, 1);
    --duration-fast: 120ms;
    --duration:      200ms;
    --duration-slow: 320ms;

    /* --- Layout --- */
    --container-max: 72rem;
    --container-pad: clamp(var(--space-4), 4vw, var(--space-6));
    --z-dropdown: 100;
    --z-nav: 200;
    --z-toast: 400;
  }

  /* --- Dark Mode: System-Präferenz --- */
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --color-primary:        hsl(232 90% 70%);
      --color-primary-hover:  hsl(232 90% 78%);
      --color-primary-soft:   hsl(232 40% 20%);
      --color-on-primary:     hsl(232 50% 10%);

      --color-bg:             hsl(222 22% 8%);
      --color-surface:        hsl(222 20% 12%);
      --color-surface-2:      hsl(222 18% 16%);
      --color-border:         hsl(222 14% 24%);
      --color-text:           hsl(220 20% 92%);
      --color-muted:          hsl(220 10% 64%);

      --color-success:        hsl(152 55% 56%);
      --color-success-soft:   hsl(152 40% 14%);
      --color-warning:        hsl(40 90% 60%);
      --color-warning-soft:   hsl(40 50% 14%);
      --color-danger:         hsl(356 85% 68%);
      --color-danger-soft:    hsl(356 40% 16%);

      --shadow-1: 0 1px 2px hsl(0 0% 0% / .4);
      --shadow-2: 0 4px 14px hsl(0 0% 0% / .45);
      --shadow-3: 0 18px 44px hsl(0 0% 0% / .6);
    }
  }

  /* --- Dark Mode: explizit erzwungen --- */
  :root[data-theme="dark"] {
    color-scheme: dark;
    --color-primary:        hsl(232 90% 70%);
    --color-primary-hover:  hsl(232 90% 78%);
    --color-primary-soft:   hsl(232 40% 20%);
    --color-on-primary:     hsl(232 50% 10%);
    --color-bg:             hsl(222 22% 8%);
    --color-surface:        hsl(222 20% 12%);
    --color-surface-2:      hsl(222 18% 16%);
    --color-border:         hsl(222 14% 24%);
    --color-text:           hsl(220 20% 92%);
    --color-muted:          hsl(220 10% 64%);
    --color-success:        hsl(152 55% 56%);
    --color-success-soft:   hsl(152 40% 14%);
    --color-warning:        hsl(40 90% 60%);
    --color-warning-soft:   hsl(40 50% 14%);
    --color-danger:         hsl(356 85% 68%);
    --color-danger-soft:    hsl(356 40% 16%);
    --shadow-1: 0 1px 2px hsl(0 0% 0% / .4);
    --shadow-2: 0 4px 14px hsl(0 0% 0% / .45);
    --shadow-3: 0 18px 44px hsl(0 0% 0% / .6);
  }
  :root[data-theme="light"] { color-scheme: light; }
}

/* =========================================================
   2. MODERN RESET
   ========================================================= */
@layer plain.reset {
  *, *::before, *::after { box-sizing: border-box; }

  * { margin: 0; }

  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    hanging-punctuation: first last;
  }

  @media (prefers-reduced-motion: no-preference) {
    html { scroll-behavior: smooth; interpolate-size: allow-keywords; }
  }

  body { min-height: 100dvh; }

  img, picture, video, canvas, svg { display: block; max-width: 100%; height: auto; }

  input, button, textarea, select { font: inherit; color: inherit; }

  p, h1, h2, h3, h4, h5, h6, li, dd, figcaption { overflow-wrap: break-word; }
  h1, h2, h3, h4, h5, h6 { text-wrap: balance; }
  p { text-wrap: pretty; }

  [hidden] { display: none !important; }

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

/* =========================================================
   3. BASIS-TYPOGRAFIE & ELEMENTE
   ========================================================= */
@layer plain.base {
  body {
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: var(--leading-normal);
    color: var(--color-text);
    background: var(--color-bg);
    -webkit-font-smoothing: antialiased;
  }

  h1, h2, h3, h4, h5, h6 {
    line-height: var(--leading-tight);
    font-weight: var(--weight-bold);
    letter-spacing: -.015em;
    margin-block: 0 var(--space-3);
  }
  h1 { font-size: var(--text-4xl); letter-spacing: -.025em; }
  h2 { font-size: var(--text-3xl); }
  h3 { font-size: var(--text-2xl); }
  h4 { font-size: var(--text-xl); }
  h5 { font-size: var(--text-lg); }
  h6 { font-size: var(--text-base); text-transform: uppercase; letter-spacing: .06em; }

  p, ul, ol, dl, blockquote, pre, table, figure { margin-block: 0 var(--space-4); }

  * + h2, * + h3 { margin-block-start: var(--space-6); }

  .lead { font-size: var(--text-lg); color: var(--color-muted); }
  small, .small { font-size: var(--text-sm); }

  a {
    color: var(--color-primary);
    text-decoration-thickness: 1px;
    text-underline-offset: .2em;
    transition: color var(--duration-fast) var(--ease);
  }
  a:hover { color: var(--color-primary-hover); text-decoration-thickness: 2px; }

  :focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
  }

  strong, b { font-weight: var(--weight-bold); }
  mark { background: var(--color-warning-soft); color: inherit; padding-inline: .15em; border-radius: var(--radius-sm); }

  hr {
    border: 0;
    border-top: 1px solid var(--color-border);
    margin-block: var(--space-6);
  }

  blockquote {
    padding: var(--space-3) var(--space-5);
    border-inline-start: 4px solid var(--color-primary);
    background: var(--color-surface-2);
    border-radius: 0 var(--radius) var(--radius) 0;
    font-size: var(--text-lg);
  }
  blockquote > :last-child { margin-bottom: 0; }
  blockquote footer, blockquote cite { display: block; margin-top: var(--space-2); font-size: var(--text-sm); color: var(--color-muted); font-style: normal; }

  code, kbd, samp, pre { font-family: var(--font-mono); font-size: .9em; }

  :not(pre) > code {
    padding: .1em .35em;
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
  }

  pre {
    padding: var(--space-4);
    overflow-x: auto;
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    line-height: var(--leading-snug);
    tab-size: 2;
  }

  kbd {
    display: inline-block;
    padding: .1em .45em;
    font-size: .8em;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-bottom-width: 2px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-1);
  }

  ul, ol { padding-inline-start: var(--space-5); }
  li + li { margin-top: var(--space-1); }
  li::marker { color: var(--color-muted); }

  dt { font-weight: var(--weight-bold); }
  dd { margin-inline-start: 0; margin-bottom: var(--space-3); color: var(--color-muted); }

  abbr[title] { text-decoration: underline dotted; cursor: help; }

  ::selection { background: var(--color-primary); color: var(--color-on-primary); }
}
