/* teblo — style.css
   Stage 4: OKLCH Tokens, clamp(), prefers-color-scheme */

@layer reset, layout, components;


/* ── Design Tokens ──────────────────────────────────────────── */

:root {
  /* Brand */
  --accent:          #00b1ed;

  /* Typografie */
  --font-sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    Segoe UI, Roboto, Helvetica Neue, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    Liberation Mono, Courier New, monospace;

  /* Fluid type scale */
  --text-xs:   clamp(0.75rem,  0.72rem + 0.13vw, 0.875rem);
  --text-sm:   clamp(0.875rem, 0.84rem + 0.18vw, 1rem);
  --text-base: clamp(1rem,     0.96rem + 0.22vw, 1.125rem);
  --text-lg:   clamp(1.125rem, 1.05rem + 0.38vw, 1.25rem);
  --text-xl:   clamp(1.25rem,  1.15rem + 0.5vw,  1.5rem);
  --text-2xl:  clamp(1.5rem,   1.35rem + 0.75vw, 1.875rem);
  --text-3xl:  clamp(1.875rem, 1.65rem + 1.13vw, 2.25rem);

  /* Light mode Farben */
  --color-bg:           oklch(99% 0 0);
  --color-text:         oklch(25% 0.03 255);   /* slate-800  rgb(30 41 59)   */
  --color-text-muted:   oklch(50% 0.03 255);   /* slate-500  rgb(100 116 139)*/
  --color-text-subtle:  oklch(65% 0.025 255);  /* slate-400  rgb(148 163 184)*/
  --color-text-faint:   oklch(82% 0.015 255);  /* slate-200  rgb(226 232 240)*/
  --color-surface:      oklch(20% 0.04 255);   /* slate-900  rgb(15 23 42)   */
  --color-hover:        oklch(95% 0.01 255);   /* slate-100  */
  --color-border:       oklch(88% 0.01 255);   /* slate-200  rgb(226 232 240)*/
  --color-border-dark:  oklch(75% 0.02 255);   /* slate-300  rgb(203 213 225)*/
  --color-heading:      oklch(13% 0.04 255);   /* slate-900  rgb(15 23 42)   */
  --color-pre-bg:       oklch(8%  0    0);     /* ~rgb(12 12 12)             */
  --color-pre-text:     oklch(88% 0.01 255);   /* slate-200  rgb(226 232 240)*/
  --color-code-pre-bg:  oklch(22% 0.03 255);   /* slate-800  rgb(30 41 59)   */

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg:           oklch(21% 0.040 265);   /* slate-900  rgb(15 23 42)   */
    --color-text:         oklch(91% 0.012 255); /* slate-200  rgb(226 232 240)*/
    --color-text-muted:   oklch(67% 0.020 255); /* slate-400  rgb(148 163 184)*/
    --color-text-subtle:  oklch(45% 0.025 255); /* slate-600  rgb(71 85 105)  */
    --color-text-faint:   oklch(67% 0.020 255); /* slate-400  rgb(148 163 184)*/
    --color-hover:        oklch(29% 0.03 255);  /* slate-700  */
    --color-border:       oklch(30% 0.03 255);  /* slate-700  rgb(51 65 85)   */
    --color-border-dark:  oklch(45% 0.025 255); /* slate-600  rgb(71 85 105)  */
    --color-heading:      oklch(100% 0 0);      /* white                      */
  }
}


/* ── Reset ──────────────────────────────────────────────────── */

@layer reset {
  *, *::before, *::after {
    box-sizing: border-box;
    border: 0 solid;
  }

  html {
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
    tab-size: 4;
    font-family: var(--font-sans);
  }

  body {
    margin: 0;
    line-height: inherit;
  }

  h1, h2, h3, h4, h5, h6 {
    font-size: inherit;
    font-weight: inherit;
  }

  a {
    color: inherit;
    text-decoration: inherit;
  }

  b, strong { font-weight: bolder; }

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

  small { font-size: 80%; }

  img, video, svg {
    display: block;
    max-inline-size: 100%;
    block-size: auto;
  }

  blockquote, dd, dl, figure, h1, h2, h3, h4, h5, h6, hr, p, pre {
    margin: 0;
  }

  ol, ul {
    list-style: none;
    margin: 0;
    padding: 0;
  }

  table {
    text-indent: 0;
    border-color: inherit;
    border-collapse: collapse;
  }

  hr {
    block-size: 0;
    color: inherit;
    border-block-start-width: 1px;
  }

  summary { display: list-item; }
  [hidden] { display: none; }
}


/* ── Layout ─────────────────────────────────────────────────── */

@layer layout {
  .page-body {
    display: flex;
    flex-direction: column;
    min-block-size: 100svh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    color: var(--color-text);
    background-color: var(--color-bg);
  }

  .page-wrapper {
    flex-grow: 1;
    inline-size: 100%;
    padding-inline: 1rem;
    padding-block-start: 4rem;
    margin-inline: auto;

    @media (min-width: 768px) {
      max-inline-size: 42rem;
    }
  }
}


/* ── Components ─────────────────────────────────────────────── */

@layer components {

  /* ── Site header ──────────────────────────────── */

  .site-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .site-title {
    font-size: var(--text-3xl);
    text-decoration: underline;
    text-decoration-color: var(--accent);
    text-decoration-thickness: 4px;
    text-underline-offset: 10px;
    margin-top: -20px;
    transform: rotate(-1deg);
  }

  .site-tagline {
    margin-block-start: 1.5rem;
    font-size: var(--text-lg);
    color: var(--color-text-muted);
  }


  /* ── Post list ────────────────────────────────── */

  .post-list {
    margin-block-start: 3rem;

    & > * + * {
      margin-block-start: 1.5rem;
    }
  }

  .post-date {
    font-size: var(--text-xs);
    font-weight: 500;
    color: var(--color-text-subtle);
  }

  .post-title {
    font-size: var(--text-lg);
    font-weight: 600;

    &:hover {
      text-decoration: underline;
    }
  }

  .post-subtitle {
    font-weight: 400;
    color: var(--color-text-faint);
  }


  /* ── Back header ──────────────────────────────── */

  .back-header {
    position: fixed;
    inset-block-start: 0;
    inset-inline-start: 0;
    padding: 1rem;
    z-index: 50;
    min-inline-size: 100%;
    background-color: var(--color-bg);

    @media (min-width: 768px) {
      background-color: transparent;
    }
  }

  .back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    font-size: var(--text-sm);
    border-radius: 0.5rem;
    border: 1px solid var(--color-border);
    white-space: nowrap;
    transition: background-color 150ms ease, border-color 150ms ease;

    &:hover {
      background-color: var(--color-hover);
      border-color: var(--color-border-dark);
    }
  }

  .back-icon {
    inline-size: 0.875rem;
    block-size: 0.875rem;
    flex-shrink: 0;
  }


  /* ── Article ──────────────────────────────────── */

  .article-meta {
    display: flex;
    gap: 0.5rem;
    max-inline-size: max-content;
    margin-inline: auto;
    font-size: var(--text-xs);
    font-weight: 500;
    color: var(--color-text-muted);

    @media (min-width: 768px) {
      font-size: var(--text-base);
    }
  }

  .article-title {
    margin-block-start: 0.5rem;
    margin-block-end: 3rem;
    font-size: var(--text-3xl);
    font-weight: 800;

    @media (min-width: 768px) {
      text-align: center;
    }
  }


  /* ── Site footer ──────────────────────────────── */

  .site-footer {
    margin-inline: auto;
    margin-block: 4rem;
    padding-block-end: 2rem;
    text-align: center;
    font-size: var(--text-sm);
    color: var(--color-text-subtle);

    & > * + * {
      margin-block-start: 1.5rem;
    }
  }

  .footer-nav {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
  }

  .footer-nav-item {
    list-style: none;
    font-size: var(--text-sm);
    color: var(--color-text-subtle);

    a {
      color: oklch(from var(--color-text-muted) calc(l + 0.1) c h);
    }

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

  .footer-sep {
    padding-inline: 0.25rem;
  }


  /* ── Badge draft ──────────────────────────────── */

  .badge-draft {
    --_h: 75;

    display: inline-flex;
    align-items: center;
    padding-inline: 0.45em;
    padding-block: 0.1em;
    border-radius: 0.3em;
    font-size: 0.6em;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    vertical-align: middle;
    line-height: 1.6;
    background: oklch(82% 0.17 var(--_h));
    color: oklch(32% 0.08 var(--_h));

    @media (prefers-color-scheme: dark) {
      background: oklch(34% 0.1 var(--_h));
      color: oklch(84% 0.16 var(--_h));
    }
  }


  /* ── Dev indicators (hadley build preview) ───── */

  body { counter-reset: hadley-indicator; }

  [data-hadley] {
    counter-increment: hadley-indicator;

    position: fixed;
    top: calc((counter(hadley-indicator) - 1) * 2.6rem);
    right: 0;
    z-index: 9999;

    font-family: monospace;
    font-size: 13px;
    line-height: 1;
    padding-inline: 1em 1.4em;
    padding-block: 0.7em;

    background: oklch(16% 0.03 55 / 0.92);
    border: 1px solid oklch(38% 0.05 55 / 0.6);
    border-radius: 6px;
    backdrop-filter: blur(8px);
    box-shadow: -2px 2px 10px oklch(0% 0 0 / 0.35);

    &::before {
      content: 'ℹ ' attr(data-hadley) ':';
      color: oklch(68% 0.16 50);
      margin-inline-end: 0.5em;
    }

    &::after {
      content: attr(data-hadley-val);
      color: oklch(86% 0.06 55);
    }
  }


  /* ── Markdown / Prose ─────────────────────────── */

  .markdown {
    color: var(--color-text);
    font-size: var(--text-base);
    line-height: 1.7777778;
    max-inline-size: 42rem;
    margin-inline: auto;
    display: block;

    p {
      margin-block: 1.3333333em;
      color: var(--color-text-muted);
    }

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

      &:hover { text-decoration: underline; }
      & > strong { color: var(--accent); }
    }

    strong {
      font-weight: 600;
      color: var(--color-heading);
    }

    h1, h2, h3, h4 {
      color: var(--color-heading);
      font-weight: 700;
      line-height: 1.3;
    }

    h1 {
      font-size: var(--text-3xl);
      line-height: 1.1;
      margin-block-start: 0;
      margin-block-end: 0.8333333em;
      font-weight: 800;
    }

    h2 {
      font-size: var(--text-2xl);
      margin-block-start: 1.8666667em;
      margin-block-end: 1.0666667em;
    }

    h3 {
      font-size: var(--text-xl);
      margin-block-start: 1.6666667em;
      margin-block-end: 0.6666667em;
    }

    h4 {
      font-size: var(--text-lg);
      margin-block-start: 1.7777778em;
      margin-block-end: 0.4444444em;
    }

    h2 + *, h3 + *, h4 + *, hr + * {
      margin-block-start: 0;
    }

    ul {
      list-style-type: disc;
      padding-inline-start: 1.5555556em;
      margin-block: 1.3333333em;
    }

    ol {
      list-style-type: decimal;
      padding-inline-start: 1.5555556em;
      margin-block: 1.3333333em;
    }

    li {
      margin-block: 0.6666667em;
      padding-inline-start: 0.4444444em;
    }

    ul ul, ul ol, ol ul, ol ol {
      margin-block: 0.8888889em;
    }

    ol > li::marker {
      font-weight: 400;
      color: var(--color-text-muted);
    }

    ul > li::marker {
      color: var(--color-border-dark);
    }

    blockquote {
      font-style: italic;
      color: var(--color-heading);
      border-inline-start: 0.25rem solid var(--accent);
      padding-inline-start: 1em;
      margin-block: 1.6666667em;
      margin-inline: 0;
    }

    hr {
      border-color: var(--color-border);
      border-block-start-width: 1px;
      margin-block: 3.1111111em;
    }

    code {
      font-size: 0.8888889em;
      font-weight: 600;
      color: var(--color-heading);
    }

    :not(pre) > code {
      &::before, &::after { content: '`'; }
    }

    pre {
      color: var(--color-pre-text);
      background-color: var(--color-pre-bg);
      overflow-x: auto;
      font-size: 0.8888889em;
      line-height: 1.75;
      margin-block: 2em;
      border-radius: 0.375rem;
      padding: 1em 1.5em;

      code {
        background-color: transparent;
        padding: 0;
        font-weight: 400;
        color: inherit;
        font-size: inherit;
        font-family: inherit;
        line-height: inherit;

        &::before, &::after { content: none; }
      }
    }

    table {
      inline-size: 100%;
      table-layout: auto;
      text-align: start;
      margin-block: 2em;
      font-size: 0.8888889em;
      line-height: 1.5;
    }

    thead {
      border-block-end: 1px solid var(--color-border-dark);
    }

    thead th {
      color: var(--color-heading);
      font-weight: 600;
      vertical-align: bottom;
      padding: 0.75em;
    }

    tbody tr {
      border-block-end: 1px solid var(--color-border);

      &:last-child { border-block-end-width: 0; }
    }

    tbody td {
      vertical-align: baseline;
      padding: 0.75em;
    }

    figure {
      float: inline-start;
      max-inline-size: 33%;
      margin-block: 0.5em;
      margin-inline: 0 1.5em;

      & > * { margin-block: 0; }
    }

    figcaption {
      color: var(--color-text-muted);
      font-size: 0.8888889em;
      line-height: 1.5;
      margin-block-start: 1em;
      text-align: center;
    }

    img {
      margin-block: 1.7777778em;
    }

    footer.footnotes {
      clear: inline-start;
    }

    & > :first-child { margin-block-start: 0; }
    & > :last-child  { margin-block-end: 0; }
  }
}
