:root {
  --bg: #14161c;
  --bg-raised: #1b1e26;
  --bg-sunken: #101218;
  --line: #2a2f3a;
  --line-soft: #22262f;
  --fg: #dfe3ea;
  --fg-dim: #8d95a5;
  --fg-faint: #626a79;
  --accent: #d9a441;
  --accent-dim: #8a6a2b;
  --ok: #6fbf73;
  --buy: #5b9dd9;

  --grade-0: #e9edf3;
  --grade-1: #8fd200;
  --grade-2: #4aa8f0;
  --grade-3: #f0c040;
  --grade-4: #f07a35;
  --grade-5: #e05555;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.6 "Segoe UI", "Yu Gothic UI", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
}

a { color: var(--accent); }

/* ---- header ---- */
.topbar {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-raised);
}
.brand { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.topbar h1 { margin: 0; font-size: 17px; letter-spacing: .04em; }
/* タイトル＝トップへ戻るリンク。見た目は見出しのまま、押せることだけ伝える */
.topbar h1 .home { color: inherit; text-decoration: none; }
.topbar h1 .home:hover { color: var(--accent); }
.tagline { color: var(--fg-faint); font-size: 12px; }
.dbinfo { color: var(--fg-faint); font-size: 11px; text-align: right; }

main { max-width: 1400px; margin: 0 auto; padding: 18px 20px 40px; }

/* ---- search ---- */
.searchbar { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.searchwrap { position: relative; flex: 1 1 420px; }

input[type="search"], input[type="number"], select {
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  color: var(--fg);
  border-radius: 6px;
  padding: 10px 12px;
  font: inherit;
  width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--accent-dim); }

.qty { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--fg-dim); }
.qty input { width: 130px; font-size: 16px; font-variant-numeric: tabular-nums; }

.results {
  position: absolute; z-index: 20; top: calc(100% + 6px); left: 0; right: 0;
  max-height: 380px; overflow-y: auto;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 32px rgba(0,0,0,.55);
}
.results button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 12px; background: none; border: 0; border-bottom: 1px solid var(--line-soft);
  color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.results button:last-child { border-bottom: 0; }
.results button:hover, .results button.cursor { background: #232734; }
.results .cats { margin-left: auto; color: var(--fg-faint); font-size: 11px; white-space: nowrap; }
.results .none { padding: 12px; color: var(--fg-faint); }

/* ---- empty state ---- */
.empty { margin-top: 40px; color: var(--fg-dim); max-width: 760px; }
.empty p { font-size: 15px; }
.hints { padding-left: 20px; font-size: 13px; color: var(--fg-faint); }
.samples { margin-top: 22px; display: flex; gap: 8px; flex-wrap: wrap; }
.samples button {
  background: var(--bg-raised); border: 1px solid var(--line); color: var(--fg-dim);
  border-radius: 999px; padding: 6px 14px; font: inherit; font-size: 12px; cursor: pointer;
}
.samples button:hover { border-color: var(--accent-dim); color: var(--fg); }

/* ---- layout ---- */
.view { display: grid; grid-template-columns: minmax(0,1fr) 340px; gap: 16px; margin-top: 20px; }
@media (max-width: 1000px) { .view { grid-template-columns: minmax(0,1fr); } }

.panel { background: var(--bg-raised); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.panelhead {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; margin-bottom: 10px;
}
.panelhead h2 { margin: 0; font-size: 13px; letter-spacing: .08em; color: var(--fg-dim); text-transform: uppercase; }
.sidepanel .panelhead:not(:first-child) { margin-top: 22px; }

.controls { display: flex; gap: 8px; align-items: center; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button {
  background: none; border: 0; color: var(--fg-faint);
  padding: 5px 12px; font: inherit; font-size: 12px; cursor: pointer;
}
.seg button.on { background: var(--accent-dim); color: #fff; }
.ghost {
  background: none; border: 1px solid var(--line); color: var(--fg-dim);
  border-radius: 6px; padding: 5px 12px; font: inherit; font-size: 12px; cursor: pointer;
}
.ghost:hover { border-color: var(--accent-dim); color: var(--fg); }

/* ---- root recipe picker ---- */
.rootpick { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.rootpick .title { display: flex; align-items: center; gap: 8px; font-size: 17px; font-weight: 600; }
.rootpick select { width: auto; min-width: 220px; padding: 6px 10px; font-size: 12px; }
.rootpick .meta { color: var(--fg-faint); font-size: 12px; }

/* ---- tree ---- */
.tree { font-variant-numeric: tabular-nums; overflow-x: auto; }
.node { border-left: 1px solid var(--line-soft); margin-left: 9px; padding-left: 12px; }
.node.root { border-left: 0; margin-left: 0; padding-left: 0; }

.row {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 6px; border-radius: 6px; min-height: 32px;
  width: max-content; min-width: 100%;
}
.row:hover { background: #1f232c; }
.row.leafbuy { opacity: .78; }

.twist {
  width: 18px; height: 18px; flex: none; padding: 0;
  background: none; border: 0; color: var(--fg-faint);
  cursor: pointer; font-size: 10px; line-height: 1;
}
.twist:hover { color: var(--fg); }
.twist.spacer { cursor: default; }

.ico { width: 26px; height: 26px; flex: none; border-radius: 4px; background: #0c0e13; }
.nm { color: var(--grade-0); }
.g0 { color: var(--grade-0); } .g1 { color: var(--grade-1); } .g2 { color: var(--grade-2); }
.g3 { color: var(--grade-3); } .g4 { color: var(--grade-4); } .g5 { color: var(--grade-5); }

.need { font-weight: 600; color: var(--accent); white-space: nowrap; }
.crafts { color: var(--fg-faint); font-size: 11px; white-space: nowrap; }
.badge {
  font-size: 10px; padding: 1px 6px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--fg-faint); white-space: nowrap;
  /* <button> で使う版がブラウザ既定の明るい背景を拾わないように、必ず自分で塗る */
  background: transparent;
}
.badge.fixed { border-color: #6b5a2e; color: #c8a552; }
.badge.cyc { border-color: #6b3a3a; color: #d08a8a; }
.row .spacerflex { flex: 1; }

/* 代用可能枠は、名前そのものがプルダウンになる */
.gsel {
  background: none; border: 1px dashed var(--line); border-radius: 5px;
  padding: 2px 4px; font: inherit; width: auto; max-width: 240px;
  color: var(--grade-0);
}
.gsel:hover { border-color: var(--accent-dim); }
.gsel option { background: var(--bg-raised); color: var(--fg); }

.rsel { background: var(--bg-sunken); border: 1px solid var(--line); color: var(--fg-dim);
        border-radius: 5px; padding: 2px 6px; font: inherit; font-size: 11px; width: auto; max-width: 340px; }

/* ツリー内の「作る / 買う」トグル。選ばれている側に背景が付く */
.seg.mini { flex: none; }
.seg.mini button { padding: 2px 10px; font-size: 11px; line-height: 1.5; }
.seg.mini button:hover:not(.on) { color: var(--fg); }
.seg.mini button:first-child.on { background: var(--accent-dim); color: #fff; }
.seg.mini button:last-child.on { background: #35597a; color: #fff; }

/* ---- totals / steps ---- */
.totals, .steps { font-variant-numeric: tabular-nums; }
.trow {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 0; border-bottom: 1px solid var(--line-soft); font-size: 13px;
}
.trow:last-child { border-bottom: 0; }
.trow .ico { width: 22px; height: 22px; }
.trow .amt { margin-left: auto; font-weight: 600; color: var(--accent); }
.steps .trow .amt { color: var(--ok); }
.steps .cat { color: var(--fg-faint); font-size: 11px; }
.note { color: var(--fg-faint); font-size: 11px; margin: 8px 0 0; }

footer {
  border-top: 1px solid var(--line);
  padding: 16px 20px 30px;
  color: var(--fg-faint); font-size: 12px;
}
footer p { margin: 4px 0; }
.disclaimer { color: #565d6b; }

/* 入手手段のバッジ。押すと内訳が開く。
   ふだんは塗りつぶし、マウスを乗せたときに枠線だけにする（以前と逆）。
   塗ってあるほうが地の色に負けずに読めるので、常時のほうを塗りにしてある。 */
.badge.npc  { background: #223347; border-color: #35597a; color: #a9d2f5; }
.badge.node { background: #223a2a; border-color: #3c6b4a; color: #a5e0b8; }

.badge.clickable {
  font: inherit; font-size: 10px; line-height: 1.6;
  padding: 1px 7px; cursor: pointer;
}
.badge.npc.clickable:hover  { background: transparent; color: #7db6e8; }
.badge.node.clickable:hover { background: transparent; color: #79c48f; }

/* 販売元のポップアップ */
.popover {
  position: absolute; z-index: 40; width: 320px; max-width: calc(100vw - 24px);
  background: var(--bg-raised); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px 14px;
  box-shadow: 0 14px 40px rgba(0,0,0,.6);
  overflow-y: auto;                 /* 職業が多いと縦に伸びるので中でスクロールさせる */
  overscroll-behavior: contain;
}
.pop-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.pop-head .nm { font-weight: 600; }
.pop-close {
  margin-left: auto; background: none; border: 0; color: var(--fg-faint);
  font-size: 18px; line-height: 1; cursor: pointer; padding: 0 2px;
}
.pop-close:hover { color: var(--fg); }
.pop-price {
  color: var(--accent); font-weight: 600; font-variant-numeric: tabular-nums;
  padding-bottom: 8px; border-bottom: 1px solid var(--line-soft); margin-bottom: 8px;
}
.pop-note { color: var(--fg-faint); font-size: 11px; margin: 0 0 8px; }
.pop-job { margin-bottom: 8px; }
.pop-job:last-child { margin-bottom: 0; }
.pop-jobname { color: var(--buy); font-size: 12px; font-weight: 600; }
.pop-names { color: var(--fg-dim); font-size: 12px; line-height: 1.7; }
