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

@layer reset {
  *, *::before, *::after { box-sizing: border-box; margin: 0; }
  img, picture, video { display: block; max-width: 100%; }
  input, button, textarea, select { font: inherit; }
  button { cursor: pointer; border: 0; background: transparent; color: inherit; }
  a { color: var(--pri); text-decoration: none; }
  a:hover { text-decoration: underline; }
  table { border-collapse: collapse; width: 100%; }
}

@layer tokens {
  :root {
    color-scheme: light;
    --bg:       light-dark(#fafbfc, #0b0d12);
    --surface:  light-dark(#ffffff, #141822);
    --surface-2: light-dark(#f1f3f5, #1a1f2b);
    --fg:       light-dark(#111418, #e6e8ee);
    --muted:    light-dark(#6b7280, #98a1b3);
    --line:     light-dark(#e4e7eb, #2a2f3a);
    --pri:      oklch(60% 0.16 250);
    --pri-soft: color-mix(in oklch, var(--pri), white 80%);
    --pri-hover: color-mix(in oklch, var(--pri), black 12%);
    --warn:     oklch(60% 0.18 30);
    --warn-soft: color-mix(in oklch, var(--warn), white 80%);
    --ok:       oklch(62% 0.15 150);
    --ok-soft:  color-mix(in oklch, var(--ok), white 80%);

    --radius: 0.625rem;
    --radius-sm: 0.375rem;
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.875rem;
    --space-4: 1.25rem;
    --space-5: 2rem;
    --space-6: 3rem;

    --font-sans: -apple-system, BlinkMacSystemFont, "Pretendard", "Apple SD Gothic Neo", "Segoe UI", sans-serif;
    --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
  }
  :root[data-theme="dark"] { color-scheme: dark; }
}

@layer base {
  html { scroll-behavior: smooth; }
  body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--fg);
    line-height: 1.65;
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
  }
  h1 { font-size: clamp(1.5rem, 1.2rem + 1.2vw, 2.25rem); letter-spacing: -0.02em; }
  h2 { font-size: clamp(1.2rem, 1.05rem + 0.6vw, 1.55rem); letter-spacing: -0.015em; margin-bottom: var(--space-4); }
  h3 { font-size: 1.05rem; margin: var(--space-4) 0 var(--space-2); letter-spacing: -0.01em; }
  h4 { font-size: 0.95rem; margin: var(--space-3) 0 var(--space-2); }
  code {
    font-family: var(--font-mono);
    font-size: 0.86em;
    background: var(--surface-2);
    padding: 0.1em 0.4em;
    border-radius: 4px;
  }
  pre code { background: transparent; padding: 0; }
  p { margin: 0.4rem 0; }
}

@layer components {

  .wrap {
    max-width: 1120px;
    margin: 0 auto;
    padding-inline: clamp(1rem, 3vw, 2rem);
  }

  .site-header {
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    padding: var(--space-5) 0 var(--space-3);
    position: sticky;
    top: 0;
    z-index: 10;
    backdrop-filter: saturate(180%) blur(8px);
  }
  .site-header .title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
  }
  .subtitle {
    color: var(--muted);
    font-size: 0.88rem;
    font-family: var(--font-mono);
    margin-top: var(--space-1);
  }

  .theme-toggle {
    font-size: 1.4rem;
    padding: 0.3rem 0.7rem;
    border-radius: 50%;
    background: var(--surface-2);
    transition: background 0.2s;
  }
  .theme-toggle:hover { background: var(--pri-soft); }

  .toc {
    display: flex;
    gap: var(--space-3);
    flex-wrap: wrap;
    margin-top: var(--space-3);
    font-size: 0.85rem;
  }
  .toc a {
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--muted);
  }
  .toc a:hover { background: var(--pri-soft); color: var(--pri); text-decoration: none; }

  .card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: var(--space-5);
    margin-block: var(--space-4);
    scroll-margin-top: 9rem;
  }

  .stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--space-3);
    margin-top: var(--space-3);
  }
  .stat-grid > div {
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    padding: var(--space-3);
    display: grid;
    gap: 0.2rem;
  }
  .stat-label { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; }
  .stat-value { font-family: var(--font-mono); font-weight: 600; font-size: 0.95rem; }
  .stat-value.none { color: var(--warn); }

  pre.ascii {
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: var(--space-3);
    overflow-x: auto;
    font-size: 0.78rem;
    line-height: 1.5;
  }

  .comp-list {
    display: grid;
    gap: var(--space-3);
  }
  @container (min-width: 720px) {
    .comp-list { grid-template-columns: repeat(2, 1fr); }
  }
  .comp {
    container-type: inline-size;
    background: var(--surface-2);
    border-radius: var(--radius);
    padding: var(--space-4);
    border: 1px solid var(--line);
  }
  .comp header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: var(--space-2);
    margin-bottom: var(--space-2);
  }
  .comp h3 { margin: 0; font-size: 1rem; }
  .tag {
    display: inline-block;
    font-size: 0.7rem;
    padding: 0.15rem 0.5rem;
    background: var(--pri-soft);
    color: var(--pri);
    border-radius: 999px;
    margin-left: 0.4rem;
    font-weight: 500;
    letter-spacing: 0;
  }
  .comp dl {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.3rem 1rem;
    font-size: 0.88rem;
  }
  .comp dt { color: var(--muted); }
  .comp dd { color: var(--fg); }

  .info-btn {
    font-size: 0.75rem;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--line);
    color: var(--muted);
    flex-shrink: 0;
  }
  .info-btn:hover { color: var(--pri); border-color: var(--pri); }

  .pop {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: var(--space-4);
    background: var(--surface);
    color: var(--fg);
    box-shadow: 0 10px 32px -8px oklch(0% 0 0 / 0.18);
    max-width: 420px;
    margin: auto;
  }
  .pop h4 { margin-top: 0; }
  .pop ul { padding-left: 1.1rem; line-height: 1.8; font-size: 0.88rem; }
  .pop button { margin-top: var(--space-3); padding: 0.4rem 0.9rem; background: var(--pri); color: white; border-radius: var(--radius-sm); }

  @scope (section.card) {
    table {
      font-size: 0.88rem;
      margin-top: var(--space-2);
    }
    th, td {
      text-align: left;
      padding: 0.55rem 0.7rem;
      border-bottom: 1px solid var(--line);
      vertical-align: top;
    }
    th {
      background: var(--surface-2);
      font-weight: 600;
      font-size: 0.78rem;
      letter-spacing: 0.02em;
      text-transform: uppercase;
      color: var(--muted);
    }
    tbody tr:hover { background: var(--pri-soft); }
    td.muted, .muted { color: var(--muted); }
    td.warn { color: var(--warn); font-weight: 600; }
    .ok { color: var(--ok); font-weight: 600; }
    .warn { color: var(--warn); font-weight: 600; }
  }

  table.mini { font-size: 0.8rem; margin-top: var(--space-2); }
  table.mini th, table.mini td { padding: 0.3rem 0.5rem; }

  details {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-2);
    background: var(--surface-2);
  }
  details summary {
    cursor: pointer;
    padding: 0.7rem 1rem;
    font-weight: 600;
    user-select: none;
  }
  details summary:hover { color: var(--pri); }
  details[open] summary { border-bottom: 1px solid var(--line); }
  details > *:not(summary) { padding: var(--space-3); }

  ol.risk {
    list-style: none;
    counter-reset: risk;
    padding: 0;
  }
  ol.risk > li {
    counter-increment: risk;
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--line);
    position: relative;
    padding-left: 2.4rem;
  }
  ol.risk > li::before {
    content: counter(risk);
    position: absolute;
    left: 0;
    top: var(--space-3);
    width: 1.8rem;
    height: 1.8rem;
    display: grid;
    place-items: center;
    background: var(--pri-soft);
    color: var(--pri);
    border-radius: 50%;
    font-weight: 700;
    font-size: 0.85rem;
  }
  ol.risk > li:last-child { border-bottom: 0; }

  dl.kv {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.4rem 1.2rem;
    font-size: 0.9rem;
    background: var(--surface-2);
    padding: var(--space-3);
    border-radius: var(--radius-sm);
  }
  dl.kv dt { color: var(--muted); }

  .caption {
    font-size: 0.8rem;
    color: var(--muted);
    margin-top: var(--space-3);
  }

  .site-footer {
    padding: var(--space-5) 0 var(--space-6);
    text-align: center;
    color: var(--muted);
    font-size: 0.82rem;
    border-top: 1px solid var(--line);
    margin-top: var(--space-5);
  }
  .cta {
    margin-top: var(--space-3);
    padding: 0.55rem 1.2rem;
    background: var(--pri);
    color: white;
    border-radius: var(--radius-sm);
    font-weight: 500;
    transition: background 0.18s;
  }
  .cta:hover { background: var(--pri-hover); }

  dialog {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0;
    max-width: 560px;
    width: 90vw;
    background: var(--surface);
    color: var(--fg);
  }
  dialog::backdrop { background: oklch(0% 0 0 / 0.55); backdrop-filter: blur(2px); }
  dialog article > header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--line);
  }
  dialog article > header button {
    padding: 0.25rem 0.55rem;
    border-radius: var(--radius-sm);
    color: var(--muted);
  }
  dialog article > header button:hover { background: var(--surface-2); color: var(--fg); }
  .dialog-body {
    padding: var(--space-4);
  }
  .dialog-body ul { padding-left: 1.2rem; line-height: 1.9; font-size: 0.88rem; }
}

@layer utilities {
  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation-duration: 0.3s;
  }
}
