:root {
  color-scheme: light dark;
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #efefeb;
  --text: #1c1c1a;
  --muted: #66665f;
  --border: #dcdcd6;
  --accent: #2f6fdb;
  --accent-contrast: #ffffff;
  --danger: #c0392b;
  --warn: #9a5b00;
  --radius: 10px;
  --gutter: 16px;
  font-family: "Pretendard Variable", Pretendard, system-ui, -apple-system, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413;
    --surface: #1d1d1b;
    --surface-2: #2a2a27;
    --text: #ecece8;
    --muted: #a3a39c;
    --border: #36362f;
    --accent: #6ea2ff;
    --accent-contrast: #0b1020;
    --danger: #ff7b6b;
    --warn: #f0b35a;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}
main { flex: 1; width: 100%; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 var(--gutter); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

button {
  font: inherit; cursor: pointer; border-radius: var(--radius);
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-contrast);
  padding: 8px 14px;
}
button:disabled { opacity: .5; cursor: default; }
button.ghost { background: transparent; color: var(--text); border-color: var(--border); }
button { white-space: normal; overflow-wrap: anywhere; }
input { font: inherit; color: var(--text); }

.site-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.site-header .wrap { display: flex; justify-content: center; padding-block: 12px; }
.site-title { margin: 0; font-weight: 700; font-size: 1.15rem; text-align: center; }
.site-title a { color: var(--text); text-decoration: none; }

.search { position: relative; margin: 20px 0 8px; }
.search-box { display: flex; gap: 8px; }
.search-box input {
  flex: 1; min-width: 0; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.suggest {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 10;
  margin: 4px 0 0; padding: 4px; list-style: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  max-height: 320px; overflow-y: auto; box-shadow: 0 8px 24px rgb(0 0 0 / .15);
}
.suggest-item {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  padding: 8px 10px; border-radius: 6px; cursor: pointer; overflow-wrap: anywhere;
}
.suggest-item[aria-selected="true"], .suggest-item:hover { background: var(--surface-2); }
.suggest-name { min-width: 0; overflow-wrap: anywhere; }
.suggest-category { flex: none; color: var(--muted); font-size: .8rem; }

.status { min-height: 1.5em; margin: 8px 0; color: var(--muted); }
.status[data-kind="error"] { color: var(--danger); }
.status[data-kind="warn"] { color: var(--warn); }
.candidates { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 16px; }
.candidates-label { color: var(--muted); font-size: .9rem; width: 100%; }

.result-title { font-size: 1.3rem; margin: 8px 0 0; overflow-wrap: anywhere; }
.fetched-at { margin: 0 0 12px; color: var(--muted); font-size: .85rem; }
.summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; min-width: 0; }
.card-label { color: var(--muted); font-size: .8rem; }
.card-value {
  font-weight: 700; font-size: .95rem; white-space: normal;
  overflow-wrap: anywhere; font-variant-numeric: tabular-nums;
}

/*
 * Narrow screens: single column, filters above results (DOM order is
 * results-col then filters, so `order: -1` puts filters back on top).
 * >=900px: two columns, results on the left (wider) and filters on the
 * right — `order` resets to the natural (DOM) order for that placement.
 */
.layout { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
.layout > .filters { order: -1; }
@media (min-width: 900px) {
  /*
   * 440px fits the site's widest real checkbox values (e.g. a 세공 옵션 line
   * like "타운트 유인한 적 1명 당 자신의 방어/마법방어 증가(19레벨:19 증가)")
   * close to one line at the site's font — labels themselves still truncate
   * with an ellipsis (+ title tooltip) for anything longer. The results
   * column keeps a workable width down to 900px (~410px net of this panel).
   */
  .layout { grid-template-columns: minmax(0, 1fr) 440px; align-items: start; }
  .layout > .filters { order: 0; }
}
.layout > * { min-width: 0; }

.filters-details { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 12px 12px; }
.filters-details > summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.filter-group { border: 0; border-top: 1px solid var(--border); margin: 8px 0 0; padding: 8px 0 0; min-width: 0; }
.filter-group legend { font-weight: 600; font-size: .9rem; padding: 0; display: flex; gap: 6px; width: 100%; }
.range { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.range input, .group-search {
  width: 100%; min-width: 0; padding: 6px 8px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
}
.range input[aria-invalid="true"] { border-color: var(--danger); }
.group-search { margin-top: 6px; }
/* Fixed 28px row height so "exactly 5 rows visible" is an exact max-height
   (5 rows + 4 gaps), not a guess; extra values scroll within the list. */
.checklist { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 4px; max-height: 156px; overflow-y: auto; }
.checklist li { height: 28px; }
.checklist label { display: flex; align-items: center; gap: 6px; height: 100%; font-size: .9rem; cursor: pointer; }
.value-text { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.value-count { flex: none; margin-left: auto; color: var(--muted); font-size: .8rem; font-weight: 400; font-variant-numeric: tabular-nums; }
.selected-badge {
  flex: none; color: var(--accent-contrast); background: var(--accent);
  border-radius: 999px; padding: 1px 7px; font-size: .72rem; font-weight: 600;
}
.swatches { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.swatch-btn { width: 28px; height: 28px; padding: 0; border-radius: 50%; border: 2px solid var(--border); }
.swatch-btn[aria-pressed="true"] { border-color: var(--text); box-shadow: 0 0 0 2px var(--accent); }
.checklist li.is-disabled label, .swatch-btn.is-disabled { opacity: .4; cursor: default; }
.checklist li.is-disabled { cursor: default; }
.no-facet-values { margin: 6px 0 0; color: var(--muted); font-size: .85rem; font-style: italic; }
.rgb-inputs { display: flex; gap: 8px; margin-top: 8px; }
.rgb-channel { display: flex; align-items: center; gap: 4px; flex: 1; min-width: 0; font-size: .8rem; color: var(--muted); }
.rgb-channel-input {
  width: 100%; min-width: 0; padding: 5px 6px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
}
.rgb-channel-input[aria-invalid="true"] { border-color: var(--danger); }
.rgb-hint { margin: 4px 0 0; }
.more-note { margin: 4px 0 0; color: var(--muted); font-size: .8rem; }
.clear-btn { width: 100%; margin-top: 12px; }

.results-toolbar {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center;
  gap: 8px; margin-bottom: 8px; color: var(--muted); font-size: .9rem;
}
.results-toolbar > * { min-width: 0; max-width: 100%; }
.results { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.row { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; min-width: 0; }
.row-main { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 4px 12px; }
.row-name { font-weight: 600; overflow-wrap: anywhere; min-width: 0; }
.row-price { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.row-meta { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 2px; color: var(--muted); font-size: .85rem; }
.option-sections { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.option-section-label { margin: 0; color: var(--muted); font-size: .72rem; font-weight: 600; letter-spacing: .02em; }
.chips { list-style: none; margin: 2px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; max-width: 100%;
  background: var(--surface-2); border-radius: 999px; padding: 2px 8px;
  font-size: .78rem; overflow-wrap: anywhere;
}
.enchant-list { list-style: none; margin: 2px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.enchant-entry { min-width: 0; }
.enchant-effects { list-style: none; margin: 3px 0 0; padding: 0 0 0 4px; display: flex; flex-direction: column; gap: 1px; }
.enchant-effects li { color: var(--muted); font-size: .75rem; overflow-wrap: anywhere; }
.numbered-list { list-style: none; margin: 2px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.numbered-line { display: flex; align-items: center; gap: 6px; min-width: 0; }
.numbered-line .chip { min-width: 0; }
.swatch { width: 12px; height: 12px; border-radius: 50%; border: 1px solid var(--border); flex: none; }
.color-dots { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.color-dot {
  display: inline-block; width: 14px; height: 14px; border-radius: 50%;
  border: 1px solid var(--border); flex: none;
}
.empty { color: var(--muted); padding: 16px 0; text-align: center; }
.more { width: 100%; margin-top: 12px; }

.site-footer { margin-top: 32px; border-top: 1px solid var(--border); color: var(--muted); font-size: .85rem; }
.site-footer .wrap { padding-block: 16px; }
