:root {
  --bg: #f4f2ec;
  --card: #ffffff;
  --ink: #1d2126;
  --muted: #5d6670;
  --line: #d9d5cb;
  --a: #2f6fb2;
  --a-soft: #e3eefa;
  --b: #b8423a;
  --b-soft: #fbe6e3;
  --accent: #3d6b3a;
  --bad: #b23a2f;
  --sel: #3d6b3a;
  --sel-soft: #e2efdf;
  --lock: #c9c4b8;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15181c; --card: #1f2329; --ink: #e8e6e1; --muted: #9aa3ad; --line: #353b43;
    --a: #6ea6e4; --a-soft: #1c2b3c; --b: #e47c73; --b-soft: #3a2220; --accent: #8cc286;
    --bad: #f08a80; --sel: #8cc286; --sel-soft: #22331f; --lock: #4a4f57;
  }
}
:root[data-theme="dark"] {
  --bg: #15181c; --card: #1f2329; --ink: #e8e6e1; --muted: #9aa3ad; --line: #353b43;
  --a: #6ea6e4; --a-soft: #1c2b3c; --b: #e47c73; --b-soft: #3a2220; --accent: #8cc286;
  --bad: #f08a80; --sel: #8cc286; --sel-soft: #22331f; --lock: #4a4f57;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 "Pretendard", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
}
.top { padding: 20px 16px 4px; max-width: 1280px; margin: 0 auto; }
h1 { margin: 0; font-size: 1.5rem; }
.top-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; }
.lang { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 0.88rem; }
h2 { margin: 0 0 10px; font-size: 1.1rem; }
h3 { margin: 14px 0 6px; font-size: 0.98rem; }
.tag { white-space: nowrap; font-size: 0.75rem; padding: 2px 8px; border: 1px solid var(--line); border-radius: 99px; color: var(--muted); vertical-align: middle; }
.sub, .hint { color: var(--muted); font-size: 0.88rem; margin: 4px 0; }
main { max-width: 1280px; margin: 0 auto; padding: 8px 16px 24px; display: grid; gap: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; min-width: 0; }
.row { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: flex-end; }
.row label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }
.row label.chk { flex-direction: row; align-items: center; color: var(--ink); }
.opts { margin-top: 10px; }
.value { color: var(--ink); font-weight: 600; }
.pick { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
select, input[type="text"], input[type="number"], button {
  font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line);
  border-radius: 6px; padding: 5px 8px;
}
button { cursor: pointer; }
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; padding: 7px 18px; }
.sides { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 900px) { .sides { grid-template-columns: 1fr; } }
.side[data-side="0"] { border-top: 4px solid var(--a); }
.side[data-side="1"] { border-top: 4px solid var(--b); }
.side h2 .badge { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.side[data-side="0"] .badge { background: var(--a); }
.side[data-side="1"] .badge { background: var(--b); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px 12px; }
.grid2 label { display: flex; flex-direction: column; gap: 3px; font-size: 0.82rem; color: var(--muted); }
.slots { display: grid; grid-template-columns: max-content 1fr; gap: 5px 10px; align-items: center; font-size: 0.86rem; }
.slots .slot-name { color: var(--muted); }
.slots select { width: 100%; min-width: 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 6px; margin-top: 10px; }
.stat { border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; }
.stat .k { color: var(--muted); font-size: 0.75rem; }
.stat .v { font-weight: 700; font-variant-numeric: tabular-nums; }
.errors { color: var(--bad); font-size: 0.85rem; margin: 6px 0 0; padding-left: 18px; }
.country { position: relative; }
.country-list { position: absolute; z-index: 5; left: 0; right: 0; top: 100%; max-height: 240px; overflow: auto;
  background: var(--card); border: 1px solid var(--line); border-radius: 6px; margin: 2px 0 0; padding: 0; list-style: none; }
.country-list li { padding: 5px 10px; cursor: pointer; font-size: 0.88rem; }
.country-list li:hover, .country-list li.on { background: var(--sel-soft); }
.tree-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; margin-top: 8px; max-height: 520px; }
.tree { position: relative; }
.tree svg { position: absolute; inset: 0; pointer-events: none; }
.trait { position: absolute; width: 104px; min-height: 46px; padding: 4px 5px; border: 1px solid var(--line); border-radius: 6px;
  font-size: 0.72rem; line-height: 1.25; background: var(--card); cursor: pointer; overflow: hidden; }
.trait .tb { color: var(--muted); font-size: 0.66rem; }
.trait.sel { border-color: var(--sel); background: var(--sel-soft); font-weight: 600; }
.trait.locked { opacity: 0.45; cursor: not-allowed; }
.trait.init { border-style: dashed; }
.trait.cond::after { content: "●"; position: absolute; right: 4px; top: 2px; font-size: 0.6rem; color: var(--muted); }
.result-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.res-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; margin-top: 8px; }
.res-table th, .res-table td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: right; }
.res-table th:first-child, .res-table td:first-child { text-align: left; color: var(--muted); font-weight: 400; }
.res-table .ca { color: var(--a); font-weight: 700; }
.res-table .cb { color: var(--b); font-weight: 700; }
.verdict { font-size: 1.05rem; font-weight: 700; margin: 6px 0 2px; }
#chart { width: 100%; height: auto; margin-top: 12px; }
.notes ul { margin: 0; padding-left: 20px; color: var(--muted); font-size: 0.88rem; }
.foot { max-width: 1280px; margin: 0 auto; padding: 8px 16px 28px; color: var(--muted); font-size: 0.8rem; }
.foot p { margin: 2px 0; }
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 20; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-box { background: var(--card); border-radius: 10px; width: min(1200px, 100%); max-height: 100%; display: flex; flex-direction: column; padding: 10px; gap: 6px; }
.modal-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }
.map-wrap { position: relative; width: 100%; height: min(70vh, 640px); overflow: hidden; border-radius: 6px; background: #34506f; touch-action: none; }
#mapCanvas { width: 100%; height: 100%; display: block; cursor: crosshair; }
.tooltip { position: fixed; z-index: 30; max-width: 320px; background: var(--card); color: var(--ink); border: 1px solid var(--line);
  border-radius: 6px; padding: 8px 10px; font-size: 0.8rem; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2); pointer-events: none; white-space: pre-line; }
code { font-size: 0.85em; }
