@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 { font: inherit; }
}

@layer tokens {
  :root {
    color-scheme: light;
    --bg: #ffffff;
    --bg-soft: #f8fafc;
    --bg-strong: #f1f5f9;
    --fg: #0f172a;
    --muted: #64748b;
    --pri: oklch(58% 0.18 250);
    --pri-soft: oklch(95% 0.04 250);
    --pri-hover: color-mix(in oklch, var(--pri), white 15%);
    --accent: oklch(70% 0.18 145);
    --warn: oklch(72% 0.18 60);
    --danger: oklch(62% 0.22 25);
    --gold: oklch(80% 0.16 85);
    --silver: oklch(80% 0 0);
    --bronze: oklch(72% 0.12 45);
    --line: #e2e8f0;
    --line-strong: #cbd5e1;
    --radius: 0.625rem;
    --radius-sm: 0.375rem;
    --space-1: 0.25rem; --space-2: 0.5rem;
    --space-3: 1rem;    --space-4: 1.5rem;
    --space-5: 2rem;    --space-6: 3rem;
    --font-sans: -apple-system, BlinkMacSystemFont, "Pretendard", "Apple SD Gothic Neo", sans-serif;
    --font-mono: "SF Mono", "JetBrains Mono", ui-monospace, monospace;
    --shadow-sm: 0 1px 2px oklch(0% 0 0 / 0.06);
    --shadow: 0 4px 12px oklch(0% 0 0 / 0.06), 0 1px 3px oklch(0% 0 0 / 0.04);
  }
}

@layer base {
  body {
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.65;
    background: var(--bg-soft);
    color: var(--fg);
    -webkit-font-smoothing: antialiased;
  }
  main {
    max-width: 72rem;
    margin-inline: auto;
    padding: var(--space-5) var(--space-4) var(--space-6);
  }
  h1, h2, h3, h4 { line-height: 1.25; letter-spacing: -0.01em; }
  h1 { font-size: clamp(1.75rem, 4vw, 2.5rem); font-weight: 700; }
  h2 { font-size: clamp(1.3rem, 2.5vw, 1.6rem); font-weight: 650; margin-top: var(--space-6); margin-bottom: var(--space-3); padding-bottom: var(--space-2); border-bottom: 2px solid var(--line); }
  h3 { font-size: 1.125rem; font-weight: 600; margin-top: var(--space-4); margin-bottom: var(--space-2); }
  h4 { font-size: 1rem; font-weight: 600; margin-bottom: var(--space-2); }
  p { margin-block: var(--space-2); color: var(--fg); }
  a { color: var(--pri); text-decoration: none; }
  a:hover { text-decoration: underline; }
  code { font-family: var(--font-mono); font-size: 0.9em; background: var(--bg-strong); padding: 0.1em 0.35em; border-radius: var(--radius-sm); }
  ul, ol { padding-left: 1.25rem; }
  li { margin-block: 0.2rem; }
}

@layer components {
  .hero {
    background: linear-gradient(135deg, var(--pri-soft), var(--bg));
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: var(--space-5);
    margin-bottom: var(--space-4);
  }
  .hero p.lead {
    font-size: 1.05rem;
    color: var(--muted);
    margin-top: var(--space-2);
  }
  .meta-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-top: var(--space-3);
    font-size: 0.875rem;
  }
  .pill {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.7rem;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--muted);
    font-size: 0.85rem;
  }
  .pill strong { color: var(--fg); margin-right: 0.35rem; }

  .winner-card {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: var(--space-4);
    align-items: center;
    background: linear-gradient(135deg, oklch(96% 0.05 145), var(--bg));
    border: 2px solid var(--accent);
    border-radius: var(--radius);
    padding: var(--space-4);
    margin-block: var(--space-3);
  }
  .winner-card .badge {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 4rem; height: 4rem;
    background: var(--accent);
    color: white;
    border-radius: 50%;
    font-weight: 700;
    font-size: 0.85rem;
  }
  .winner-card .score {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
  }

  table.ranking {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    font-size: 0.92rem;
  }
  table.ranking th,
  table.ranking td {
    padding: 0.7rem 0.85rem;
    text-align: left;
    border-bottom: 1px solid var(--line);
  }
  table.ranking th {
    background: var(--bg-strong);
    font-weight: 600;
    color: var(--muted);
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }
  table.ranking td.num,
  table.ranking th.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
  }
  table.ranking tbody tr:hover { background: var(--bg-soft); }
  table.ranking .rank {
    display: inline-flex;
    width: 1.75rem; height: 1.75rem;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--bg-strong);
    font-weight: 700;
    font-size: 0.85rem;
  }
  table.ranking tr:nth-child(1) .rank { background: var(--gold); color: white; }
  table.ranking tr:nth-child(2) .rank { background: var(--silver); color: white; }
  table.ranking tr:nth-child(3) .rank { background: var(--bronze); color: white; }
  table.ranking td:last-child { font-weight: 600; }

  table.matrix {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    font-size: 0.85rem;
  }
  table.matrix th,
  table.matrix td {
    padding: 0.5rem 0.6rem;
    border-bottom: 1px solid var(--line);
    border-right: 1px solid var(--line);
    text-align: center;
    font-variant-numeric: tabular-nums;
  }
  table.matrix th:first-child,
  table.matrix td:first-child {
    text-align: left;
    font-weight: 500;
    background: var(--bg-strong);
    position: sticky;
    left: 0;
  }
  table.matrix thead th {
    background: var(--bg-strong);
    font-weight: 600;
    color: var(--fg);
    font-size: 0.78rem;
  }
  table.matrix .total {
    background: var(--pri-soft);
    font-weight: 700;
    color: var(--pri);
  }
  .matrix-wrap {
    overflow-x: auto;
    border-radius: var(--radius);
  }

  .score-bar {
    display: inline-block;
    width: 2.5rem;
    height: 0.35rem;
    background: var(--bg-strong);
    border-radius: 999px;
    overflow: hidden;
    vertical-align: middle;
    margin-left: 0.35rem;
  }
  .score-bar > i {
    display: block;
    height: 100%;
    background: var(--pri);
    border-radius: 999px;
  }

  .criteria-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
    gap: var(--space-3);
    margin-top: var(--space-3);
  }
  .criteria-card {
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: var(--space-3);
  }
  .criteria-card .weight {
    display: inline-block;
    background: var(--pri-soft);
    color: var(--pri);
    font-weight: 700;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
  }

  @container (min-width: 40rem) {
    .option-grid { grid-template-columns: 1fr 1fr; }
  }
  .options-container { container-type: inline-size; }
  .option-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-3);
    margin-top: var(--space-3);
  }
  .option-card {
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: var(--space-4);
    box-shadow: var(--shadow-sm);
  }
  .option-card header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-2);
    margin-bottom: var(--space-2);
    padding-bottom: var(--space-2);
    border-bottom: 1px solid var(--line);
  }
  .option-card h3 { margin: 0; }
  .option-card .total-score {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--pri);
    font-variant-numeric: tabular-nums;
  }
  .option-card .summary {
    color: var(--muted);
    font-size: 0.92rem;
    margin-bottom: var(--space-3);
  }
  .pros-cons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-2);
    margin-top: var(--space-2);
    font-size: 0.88rem;
  }
  .pros-cons h4 { font-size: 0.85rem; margin-bottom: 0.35rem; }
  .pros-cons .pros h4 { color: var(--accent); }
  .pros-cons .cons h4 { color: var(--danger); }
  .pros-cons ul { padding-left: 1rem; }
  .pros-cons li { line-height: 1.45; }

  details.choose {
    background: var(--bg-soft);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.85rem;
    margin-top: var(--space-2);
    font-size: 0.88rem;
  }
  details.choose summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--pri);
  }
  details.choose[open] summary { margin-bottom: 0.35rem; }
  details.choose .reasons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-2);
    margin-top: 0.35rem;
  }
  details.choose .reasons h5 { font-size: 0.82rem; margin-bottom: 0.3rem; font-weight: 600; }
  details.choose .yes h5 { color: var(--accent); }
  details.choose .no h5 { color: var(--danger); }

  .scenario-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
    gap: var(--space-3);
    margin-top: var(--space-3);
  }
  .scenario {
    background: var(--bg);
    border-left: 4px solid var(--pri);
    border-radius: var(--radius-sm);
    padding: var(--space-3);
    box-shadow: var(--shadow-sm);
  }
  .scenario h4 { color: var(--pri); margin-bottom: var(--space-2); }
  .scenario .pick {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--fg);
    margin-bottom: 0.35rem;
  }
  .scenario small { color: var(--muted); }

  .sources {
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: var(--space-4);
    margin-top: var(--space-4);
    font-size: 0.88rem;
  }
  .sources ul { padding-left: 1.1rem; }
  .sources a { word-break: break-all; }

  footer.foot {
    margin-top: var(--space-5);
    padding-top: var(--space-3);
    border-top: 1px solid var(--line);
    text-align: center;
    color: var(--muted);
    font-size: 0.85rem;
  }
}

@layer utilities {
  .mt-1 { margin-top: var(--space-1); }
  .mt-2 { margin-top: var(--space-2); }
  .mt-3 { margin-top: var(--space-3); }
  .text-muted { color: var(--muted); }
  .text-sm { font-size: 0.875rem; }
}
