:root {
  --bg: #f6f3ec;
  --bg-elev: #fffdf8;
  --bg-sunk: #ece7dc;
  --line: #ddd5c4;
  --line-strong: #c7bca5;
  --text: #2a2620;
  --text-dim: #6b6255;
  --text-faint: #6f6657;
  --accent: #8a5a2b;
  --accent-soft: #f0e2cf;
  --ok: #2f8a4f;
  --ok-soft: #e1f2e5;
  --bad: #b8432f;
  --bad-soft: #f8e1dc;
  --warn: #a8761b;
  --warn-soft: #f7ecd4;
  --cold: #3a78c2;
  --cold-soft: #e0ecf9;
  --hot: #c8492f;
  --hot-soft: #f9e2dc;
  --neutral: #6d7c62;
  --neutral-soft: #e7ecdf;
  --g1: #6e7269;
  --g2: #2e7d48;
  --g3: #3576c9;
  --g4: #8d53c7;
  --g5: #a65f12;
  --g6: #cf3c3c;
  --on-grade: #fff;
  --shadow: 0 1px 2px rgba(60, 45, 20, .08), 0 4px 16px rgba(60, 45, 20, .06);
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", "Noto Sans CJK KR", sans-serif;
  --font-han: "Noto Serif CJK SC", "Source Han Serif SC", "SimSun", "Songti SC", "Batang", serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17150f;
    --bg-elev: #211e17;
    --bg-sunk: #120f0b;
    --line: #36311f;
    --line-strong: #4a4330;
    --text: #ece5d6;
    --text-dim: #b3a993;
    --text-faint: #958b77;
    --accent: #d9a466;
    --accent-soft: #3a2c1b;
    --ok: #6cc98a;
    --ok-soft: #1c3324;
    --bad: #ec8a76;
    --bad-soft: #3d1f19;
    --warn: #e2b55a;
    --warn-soft: #3a2f17;
    --cold: #7fb2ef;
    --cold-soft: #1a2a3d;
    --hot: #f0866c;
    --hot-soft: #3d201a;
    --neutral: #a8b897;
    --neutral-soft: #263021;
    --g1: #a9ada3;
    --g2: #5fc27f;
    --g3: #66a3f0;
    --g4: #b98ae8;
    --g5: #f0a14b;
    --g6: #f06f6f;
    --on-grade: #17150f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17150f;
  --bg-elev: #211e17;
  --bg-sunk: #120f0b;
  --line: #36311f;
  --line-strong: #4a4330;
  --text: #ece5d6;
  --text-dim: #b3a993;
  --text-faint: #958b77;
  --accent: #d9a466;
  --accent-soft: #3a2c1b;
  --ok: #6cc98a;
  --ok-soft: #1c3324;
  --bad: #ec8a76;
  --bad-soft: #3d1f19;
  --warn: #e2b55a;
  --warn-soft: #3a2f17;
  --cold: #7fb2ef;
  --cold-soft: #1a2a3d;
  --hot: #f0866c;
  --hot-soft: #3d201a;
  --neutral: #a8b897;
  --neutral-soft: #263021;
  --g1: #a9ada3;
  --g2: #5fc27f;
  --g3: #66a3f0;
  --g4: #b98ae8;
  --g5: #f0a14b;
  --g6: #f06f6f;
  --on-grade: #17150f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--font);
  overflow-x: hidden;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
img { image-rendering: auto; }
code { font-size: .9em; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.han { font-family: var(--font-han); }
[hidden] { display: none !important; }

/* ---------- 상단 ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.top-row {
  display: flex; align-items: center; gap: 12px 16px; flex-wrap: wrap;
  max-width: 1400px; margin: 0 auto; padding: 10px 16px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { flex: none; }
.brand h1 { font-size: 18px; margin: 0; line-height: 1.2; letter-spacing: -.01em; }
.brand .sub { margin: 0; font-size: 12px; color: var(--text-faint); }
.view-switch { display: inline-flex; background: var(--bg-sunk); border-radius: 999px; padding: 3px; }
.view-switch button {
  border: 0; background: transparent; padding: 5px 16px; border-radius: 999px; font-weight: 600; color: var(--text-dim);
}
.view-switch button[aria-selected="true"] { background: var(--bg-elev); color: var(--text); box-shadow: var(--shadow); }
.top-actions { display: flex; align-items: center; gap: 8px; flex: 1 1 320px; justify-content: flex-end; min-width: 0; }
.search { flex: 1 1 auto; max-width: 460px; min-width: 0; }
.search input {
  width: 100%; padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line-strong);
  background: var(--bg-elev);
}
.icon-btn {
  border: 1px solid var(--line-strong); background: var(--bg-elev); border-radius: 999px;
  min-width: 36px; height: 36px; padding: 0 10px; flex: none;
}
.icon-btn:hover { border-color: var(--accent); }
.only-mobile { display: none; }

.filters {
  max-width: 1400px; margin: 0 auto; padding: 10px 16px;
  display: grid; gap: 6px; border-bottom: 1px solid var(--line);
}
.frow { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.frow > .flabel { font-size: 12px; color: var(--text-faint); width: 44px; flex: none; }
.chip {
  border: 1px solid var(--line); background: var(--bg-elev); border-radius: 999px;
  padding: 3px 11px; font-size: 13px; line-height: 1.5; color: var(--text-dim); white-space: nowrap;
}
.chip:hover { border-color: var(--line-strong); color: var(--text); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--bg-elev); }
.chip.g[aria-pressed="true"] { background: var(--gc); border-color: var(--gc); color: var(--on-grade); }
.chip .n { opacity: .7; margin-left: 3px; font-size: 11px; }
.toggle { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; color: var(--text-dim); margin-right: 8px; white-space: nowrap; }
.toggle input { accent-color: var(--accent); }
.fsel {
  border: 1px solid var(--line); background: var(--bg-elev); border-radius: 8px; padding: 3px 8px; font-size: 13px; max-width: 100%;
}
.count { margin-left: auto; font-size: 12px; color: var(--text-faint); }
.herb-filter { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; min-width: 0; }

/* ---------- 본문 그리드 ---------- */
main { max-width: 1400px; margin: 0 auto; padding: 8px 16px 40px; }
.grade-section { margin-top: 18px; }
.grade-head {
  display: flex; align-items: baseline; gap: 10px; margin: 0 0 10px; padding-bottom: 6px;
  border-bottom: 2px solid var(--gc);
}
.grade-head h2 { margin: 0; font-size: 17px; color: var(--gc); }
.grade-head .han { color: var(--text-faint); font-size: 14px; }
.grade-head .n { color: var(--text-faint); font-size: 13px; margin-left: auto; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.card {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 6px 8px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--bg-elev); text-align: center; min-width: 0;
  transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
}
.card:hover { transform: translateY(-2px); border-color: var(--gc); box-shadow: var(--shadow); }
.card .ic {
  width: 64px; height: 64px; border-radius: 12px; display: grid; place-items: center;
  background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--gc) 22%, transparent), transparent 70%);
  border: 1.5px solid color-mix(in srgb, var(--gc) 55%, transparent);
}
.card .ic img { width: 58px; height: 58px; object-fit: contain; }
.card .nm { font-size: 13.5px; font-weight: 600; line-height: 1.3; word-break: keep-all; overflow-wrap: anywhere; }
.card .zh { font-size: 11.5px; color: var(--text-faint); line-height: 1.2; }
.card .flag {
  position: absolute; top: 5px; right: 5px; font-size: 10px; line-height: 1; padding: 2px 4px; border-radius: 4px;
  background: var(--bg-sunk); color: var(--text-faint);
}
.card .flag.perm { background: var(--accent-soft); color: var(--accent); }
.empty { text-align: center; color: var(--text-faint); padding: 60px 0; }

/* ---------- 상세 서랍 ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(20, 14, 6, .38); z-index: 30; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 40; width: min(640px, 100vw);
  background: var(--bg-elev); border-left: 1px solid var(--line); box-shadow: -8px 0 32px rgba(0, 0, 0, .18);
  display: flex; flex-direction: column;
}
.drawer-head { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.drawer-title { flex: 1; font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-body { overflow-y: auto; padding: 16px 18px 40px; flex: 1; overscroll-behavior: contain; }

.hero { display: flex; gap: 14px; align-items: flex-start; }
.hero .ic {
  width: 88px; height: 88px; border-radius: 16px; flex: none; display: grid; place-items: center;
  background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--gc) 26%, transparent), transparent 72%);
  border: 2px solid color-mix(in srgb, var(--gc) 60%, transparent);
}
.hero .ic img { width: 80px; height: 80px; object-fit: contain; }
.hero h2 { margin: 0; font-size: 22px; line-height: 1.25; }
.hero .han-line { color: var(--text-dim); font-size: 14px; margin-top: 2px; }
.badges { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.badge {
  font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--bg-sunk); color: var(--text-dim); white-space: nowrap;
}
.badge.grade { background: var(--gc); color: var(--on-grade); font-weight: 600; }
.badge.perm { background: var(--accent-soft); color: var(--accent); }
.badge.rare { background: var(--warn-soft); color: var(--warn); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin: 14px 0; }
.stat { background: var(--bg-sunk); border-radius: 8px; padding: 7px 10px; }
.stat .k { font-size: 11.5px; color: var(--text-faint); }
.stat .v { font-weight: 650; font-size: 15px; }

.effect {
  border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 8px 8px 0;
  padding: 8px 12px; margin: 10px 0;
}
.effect .ko { font-weight: 600; }
.orig { color: var(--text-faint); font-size: 12.5px; margin-top: 2px; }
.flavor { color: var(--text-dim); font-size: 14px; margin: 8px 0 0; }
.note { font-size: 12.5px; color: var(--text-faint); margin: 6px 0; }
.note.warn { color: var(--warn); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: 18px 0 14px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tabs button {
  border: 0; background: transparent; padding: 8px 12px; color: var(--text-dim); font-weight: 600;
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }

h3 { font-size: 14.5px; margin: 16px 0 8px; }
h3 .sub { font-weight: 400; color: var(--text-faint); font-size: 12.5px; margin-left: 6px; }

/* 슬롯 */
.slots { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; }
.slot { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; background: var(--bg); min-width: 0; }
.slot .role { font-size: 11.5px; color: var(--text-faint); display: flex; justify-content: space-between; gap: 6px; }
.slot.yin { border-style: dashed; }
.herb-btn {
  display: flex; align-items: center; gap: 8px; border: 0; background: transparent; padding: 4px 0; text-align: left; width: 100%; min-width: 0;
}
.herb-btn img { width: 36px; height: 36px; object-fit: contain; flex: none; border-radius: 8px; background: var(--bg-sunk); }
.herb-btn .t { min-width: 0; }
.herb-btn .t b { display: block; font-size: 14px; line-height: 1.25; }
.herb-btn .t small { color: var(--text-faint); font-size: 11.5px; }
.herb-btn:hover b { color: var(--accent); text-decoration: underline; }
.qty { font-weight: 700; font-size: 15px; margin-left: auto; padding-left: 6px; white-space: nowrap; }
.prop-line { font-size: 12.5px; margin-top: 2px; color: var(--text-dim); }

.heat { display: inline-block; font-size: 11px; font-weight: 700; padding: 0 6px; border-radius: 999px; line-height: 1.6; white-space: nowrap; }
.heat.h1 { background: var(--cold-soft); color: var(--cold); }
.heat.h2 { background: var(--hot-soft); color: var(--hot); }
.heat.h3 { background: var(--neutral-soft); color: var(--neutral); }

.req { display: flex; flex-wrap: wrap; gap: 6px; }
.req .r { background: var(--bg-sunk); border-radius: 8px; padding: 4px 10px; font-size: 13px; }
.req .r b { color: var(--accent); }

/* 표 */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: 11.5px; color: var(--text-faint); font-weight: 600; background: var(--bg-sunk); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.std td { background: color-mix(in srgb, var(--accent-soft) 70%, transparent); }
td .herb-btn { padding: 0; }
td .herb-btn img { width: 28px; height: 28px; }
td .herb-btn .t b { font-size: 13px; }
.src { display: flex; flex-wrap: wrap; gap: 3px; }
.src .badge { font-size: 11px; padding: 0 6px; }
.src .badge.shop { background: var(--ok-soft); color: var(--ok); }
.src .badge.sect { background: var(--cold-soft); color: var(--cold); }

/* 추천 */
.opt-bar { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; margin-bottom: 10px; }
.reco { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px; background: var(--bg); }
.reco-head { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: baseline; margin-bottom: 6px; }
.reco-head .cost { font-weight: 700; }
.reco-head .meta { font-size: 12px; color: var(--text-faint); }
.reco-slots { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 4px 10px; }
.reco-slot { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 13px; }
.reco-slot .lab { font-size: 11px; color: var(--text-faint); width: 34px; flex: none; }
.reco-slot .herb-btn img { width: 26px; height: 26px; }
.reco-slot .herb-btn .t b { font-size: 13px; }
.link-btn { border: 0; background: none; color: var(--accent); padding: 0; font-size: 12.5px; text-decoration: underline; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.sw-g { background: #57c27c; } .sw-b { background: #4fb6d9; } .sw-r { background: #e46a7c; } .sw-5 { background: #d8c83a; } .sw-6 { background: #e8954a; }

/* 계산기 */
.calc-grid { display: grid; gap: 8px; }
.calc-row { display: grid; grid-template-columns: 64px minmax(0, 1fr) 76px; gap: 8px; align-items: center; }
.calc-row .lab { font-size: 12.5px; color: var(--text-dim); font-weight: 600; }
.calc-row.locked { opacity: .45; }
.combo { position: relative; min-width: 0; }
.combo input { width: 100%; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--bg-elev); }
.combo .list {
  position: absolute; left: 0; right: 0; top: calc(100% + 2px); z-index: 5; max-height: 260px; overflow-y: auto;
  background: var(--bg-elev); border: 1px solid var(--line-strong); border-radius: 8px; box-shadow: var(--shadow);
}
.combo .opt { display: flex; gap: 8px; align-items: center; padding: 5px 8px; cursor: pointer; font-size: 13px; }
.combo .opt img { width: 24px; height: 24px; object-fit: contain; }
.combo .opt small { color: var(--text-faint); margin-left: auto; white-space: nowrap; }
.combo .opt[aria-selected="true"], .combo .opt:hover { background: var(--accent-soft); }
.qty-in { width: 100%; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--bg-elev); text-align: right; }
.qty-in:disabled { opacity: .45; cursor: not-allowed; background: var(--bg-sunk); }
.result {
  border-radius: var(--radius); padding: 12px 14px; margin: 12px 0; border: 1px solid var(--line);
}
.result.ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.result.bad { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.result.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.result .big { font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.result .big img { width: 32px; height: 32px; object-fit: contain; }
.result ul { margin: 6px 0 0; padding-left: 18px; font-size: 13px; }
.check-ok { color: var(--ok); font-weight: 700; }
.check-bad { color: var(--bad); font-weight: 700; }
.btn {
  border: 1px solid var(--line-strong); background: var(--bg-elev); border-radius: 8px; padding: 5px 12px; font-size: 13px;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--bg-elev); border-color: var(--accent); }
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.uses { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.use-btn { display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 4px 8px; text-align: left; font-size: 13px; min-width: 0; }
.use-btn img { width: 28px; height: 28px; object-fit: contain; flex: none; }
.use-btn span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.use-btn:hover { border-color: var(--accent); }

.foot { max-width: 1400px; margin: 0 auto; padding: 16px; color: var(--text-faint); font-size: 12px; border-top: 1px solid var(--line); }

@media (max-width: 760px) {
  .only-mobile { display: inline-block; }
  .filters { display: none; }
  .filters.open { display: grid; max-height: 60vh; overflow-y: auto; }
  .brand .sub { display: none; }
  .top-actions { flex-basis: 100%; }
  .search { max-width: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
  .card .ic { width: 56px; height: 56px; }
  .card .ic img { width: 50px; height: 50px; }
  .drawer { width: 100vw; border-left: 0; }
  .drawer-body { padding: 14px 16px 40px; }
  .calc-row { grid-template-columns: 52px minmax(0, 1fr) 62px; }
  .frow > .flabel { width: 100%; }
}
