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

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  body, h1, h2, h3, h4, p, ul, ol, figure { margin: 0; }
  ul, ol { padding-left: 1.2em; }
  table { border-collapse: collapse; }
}

@layer tokens {
  :root {
    color-scheme: light;
    --bg: #fafaf9;
    --surface: #ffffff;
    --surface-2: #f4f4f3;
    --border: #e5e5e3;
    --text: #1a1a1a;
    --text-muted: #6b6b6b;
    --accent: #1f6feb;
    --accent-soft: #e7f0fe;
    --good: #1a7f37;
    --warn: #b45309;
    --bad: #c0392b;
    --gold: #b8860b;
    --code-bg: #f0eee9;
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --space-7: 48px;
    --radius: 8px;
    --radius-lg: 12px;
    --font: ui-sans-serif, system-ui, -apple-system, "Apple SD Gothic Neo", "Pretendard", sans-serif;
    --font-mono: ui-monospace, "SF Mono", Menlo, monospace;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.04);
    --shadow: 0 4px 16px rgba(0,0,0,.06);
  }
}

@layer base {
  html { font-family: var(--font); }
  body {
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    font-size: 16px;
    padding: var(--space-6) var(--space-4);
  }
  main { max-width: 960px; margin: 0 auto; }
  h1 { font-size: 1.875rem; font-weight: 700; letter-spacing: -0.01em; }
  h2 { font-size: 1.5rem; font-weight: 600; margin-top: var(--space-7); margin-bottom: var(--space-4); letter-spacing: -0.01em; }
  h3 { font-size: 1.125rem; font-weight: 600; margin-top: var(--space-5); margin-bottom: var(--space-3); }
  p { margin-bottom: var(--space-3); }
  a { color: var(--accent); text-decoration: none; }
  a:hover { text-decoration: underline; }
  code { font-family: var(--font-mono); background: var(--code-bg); padding: 1px 6px; border-radius: 4px; font-size: 0.9em; }
  pre { background: var(--code-bg); padding: var(--space-3) var(--space-4); border-radius: var(--radius); overflow-x: auto; }
  pre code { background: none; padding: 0; font-size: 0.875rem; }
}

@layer components {
  .hero {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    box-shadow: var(--shadow);
    margin-bottom: var(--space-6);
  }
  .hero__meta {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-4);
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: var(--space-3);
  }
  .hero__meta span::before {
    content: "•";
    margin-right: var(--space-2);
    color: var(--border);
  }
  .hero__meta span:first-child::before { content: none; margin-right: 0; }

  .question {
    background: var(--accent-soft);
    border-left: 4px solid var(--accent);
    padding: var(--space-4) var(--space-5);
    border-radius: var(--radius);
    margin-top: var(--space-4);
  }

  .options-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: var(--space-4);
    margin-top: var(--space-4);
  }
  .option-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-4);
  }
  .option-card h3 { margin-top: 0; }
  .option-card .num {
    display: inline-block;
    width: 1.5em;
    height: 1.5em;
    line-height: 1.5em;
    text-align: center;
    background: var(--surface-2);
    border-radius: 50%;
    font-weight: 600;
    margin-right: var(--space-2);
    font-size: 0.85em;
  }
  .option-card p { font-size: 0.95rem; color: var(--text-muted); margin-bottom: 0; }

  .criteria-table, .matrix-table {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    font-variant-numeric: tabular-nums;
  }
  .criteria-table th, .matrix-table th,
  .criteria-table td, .matrix-table td {
    padding: var(--space-3) var(--space-4);
    text-align: left;
    border-bottom: 1px solid var(--border);
  }
  .criteria-table th, .matrix-table th {
    background: var(--surface-2);
    font-weight: 600;
    font-size: 0.875rem;
  }
  .matrix-table td.num, .matrix-table th.num,
  .criteria-table td.num, .criteria-table th.num { text-align: right; }
  .matrix-table tbody tr:last-child td,
  .criteria-table tbody tr:last-child td { border-bottom: none; }
  .matrix-table tr.winner {
    background: #fffbe6;
  }
  .matrix-table tr.winner td { font-weight: 600; }
  .rank-1 { color: var(--gold); font-weight: 700; }

  .pros-cons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-4);
    margin-top: var(--space-3);
  }
  .pros, .cons {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius);
    font-size: 0.95rem;
  }
  .pros { background: #f0f9f3; border-left: 3px solid var(--good); }
  .cons { background: #fdf3ef; border-left: 3px solid var(--bad); }
  .pros h4, .cons h4 { font-size: 0.85rem; margin-bottom: var(--space-2); text-transform: uppercase; letter-spacing: 0.04em; }
  .pros h4 { color: var(--good); }
  .cons h4 { color: var(--bad); }
  .pros ul, .cons ul { margin: 0; padding-left: 1em; }
  .pros li, .cons li { margin-bottom: var(--space-1); }

  details.option-detail {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: var(--space-3);
    overflow: hidden;
  }
  details.option-detail > summary {
    padding: var(--space-3) var(--space-4);
    cursor: pointer;
    font-weight: 600;
    background: var(--surface-2);
    display: flex;
    justify-content: space-between;
    gap: var(--space-3);
    align-items: center;
  }
  details.option-detail > summary::-webkit-details-marker { display: none; }
  details.option-detail > summary::after {
    content: "▸";
    color: var(--text-muted);
    transition: transform 0.15s ease;
  }
  details.option-detail[open] > summary::after { transform: rotate(90deg); }
  details.option-detail > div { padding: var(--space-4); }
  details.option-detail .score-chip {
    background: var(--accent-soft);
    color: var(--accent);
    padding: 2px var(--space-3);
    border-radius: 999px;
    font-size: 0.85em;
    font-family: var(--font-mono);
  }

  .recommend {
    background: linear-gradient(135deg, #fffbe6 0%, #fff7d6 100%);
    border: 1px solid var(--gold);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    box-shadow: var(--shadow);
    margin-top: var(--space-5);
  }
  .recommend h2 {
    margin-top: 0;
    color: var(--gold);
  }
  .recommend h2::before {
    content: "★ ";
  }
  .recommend .code-block {
    background: rgba(255,255,255,0.7);
    border: 1px solid #e3d9a3;
    border-radius: var(--radius);
    padding: var(--space-3) var(--space-4);
    margin-top: var(--space-3);
  }

  .impl-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-5);
    margin-top: var(--space-4);
  }
  .impl-section table td:first-child {
    font-family: var(--font-mono);
    font-size: 0.875rem;
    color: var(--accent);
    white-space: nowrap;
  }

  footer {
    margin-top: var(--space-7);
    padding-top: var(--space-4);
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.875rem;
    text-align: center;
  }
}

@layer utilities {
  .muted { color: var(--text-muted); }
  .nowrap { white-space: nowrap; }
  .center { text-align: center; }
  .small { font-size: 0.875rem; }
}

@container (max-width: 700px) {
  .pros-cons { grid-template-columns: 1fr; }
  .options-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  body { padding: var(--space-4) var(--space-3); font-size: 15px; }
  .hero, .recommend { padding: var(--space-4); }
  .pros-cons { grid-template-columns: 1fr; }
  .matrix-table { font-size: 0.85rem; }
  .matrix-table th, .matrix-table td { padding: var(--space-2) var(--space-3); }
}
