:root {
  --bg: #16181d;
  --panel: #1e2128;
  --panel-2: #262a33;
  --line: #333845;
  --text: #e7e9ee;
  --dim: #98a0b0;
  --accent: #a77bff;      /* enchantment glow */
  --accent-soft: #2b2340;
  --xp: #7ec850;
  --warn: #e8a33d;
  --bad: #e8604c;
  --radius: 10px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f2f3f6; --panel: #ffffff; --panel-2: #f6f7fa; --line: #dcdfe6;
    --text: #1b1e25; --dim: #5f6775; --accent: #6b3fd4; --accent-soft: #efe9ff;
    --xp: #3f8f24; --warn: #a96a00; --bad: #c3392a;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 1.15rem; }
h2 { font-size: 0.95rem; }
a { color: var(--accent); }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 16px; border-bottom: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.anvil-mark { width: 30px; height: 30px; fill: var(--accent); flex: none; }
.tagline { margin: 1px 0 0; font-size: 0.78rem; color: var(--dim); }

main {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
  gap: 16px; padding: 16px; max-width: 1400px; margin: 0 auto; align-items: start;
}
@media (max-width: 900px) { main { grid-template-columns: 1fr; } }
.col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; display: flex; flex-direction: column; gap: 12px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.hint { margin: -4px 0 0; font-size: 0.8rem; color: var(--dim); }

.row { display: flex; align-items: center; flex-wrap: wrap; }
.row.gap { gap: 8px; }
.row.between { justify-content: space-between; }

.field { display: flex; flex-direction: column; gap: 4px; font-size: 0.78rem; color: var(--dim); min-width: 0; }
.field.inline { flex-direction: row; align-items: center; gap: 8px; }
.field em, .check em { font-style: normal; opacity: 0.75; }
select, input[type="number"], input[type="text"] {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 7px; padding: 6px 8px; font: inherit; font-size: 0.85rem; min-width: 0; max-width: 100%;
}
select:focus-visible, input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type="number"] { width: 78px; }

.check { display: flex; align-items: flex-start; gap: 8px; font-size: 0.85rem; line-height: 1.35; }
.check input { margin: 3px 0 0; accent-color: var(--accent); flex: none; }

.btn {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 7px; padding: 7px 12px; font: inherit; font-size: 0.85rem; font-weight: 550; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; color: var(--dim); }
.btn.icon { padding: 3px 8px; line-height: 1.2; color: var(--dim); }
.btn.icon:hover { color: var(--bad); border-color: var(--bad); }

.opt-grid { display: flex; flex-direction: column; gap: 10px; }
.opt-grid.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 520px) { .opt-grid.two { grid-template-columns: 1fr; } }

/* ---- items ---- */
.item-list { display: flex; flex-direction: column; gap: 10px; }
.item {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-2); padding: 10px;
  display: flex; flex-direction: column; gap: 8px;
}
.item.book { border-left: 3px solid var(--accent); }
.item.tool { border-left: 3px solid var(--xp); }
.item-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.item-title { font-size: 0.85rem; font-weight: 600; margin-right: auto; }
.item-title .kind { color: var(--dim); font-weight: 500; }
.pw-hint { font-size: 0.72rem; color: var(--dim); }
.ench-rows { display: flex; flex-direction: column; gap: 6px; }
.ench-row { display: flex; align-items: center; gap: 6px; }
.ench-row select:first-child { flex: 1; }
.ench-row .lvl { width: 72px; flex: none; }
.empty { font-size: 0.8rem; color: var(--dim); font-style: italic; }

.conflict-list { display: flex; flex-direction: column; gap: 10px; }
.conflict { display: flex; flex-direction: column; gap: 4px; font-size: 0.8rem; color: var(--dim); }

/* ---- tabs ---- */
.tabs { display: flex; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px; }
.tab {
  flex: 1; background: transparent; border: 0; border-radius: 7px; padding: 8px 10px;
  color: var(--dim); font: inherit; font-size: 0.85rem; font-weight: 550; cursor: pointer;
}
.tab.active { background: var(--accent-soft); color: var(--text); }

/* ---- results ---- */
.status { font-size: 0.8rem; color: var(--dim); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; }
.stat { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.stat .k { font-size: 0.7rem; color: var(--dim); text-transform: uppercase; letter-spacing: 0.04em; }
.stat .v { font-size: 1.25rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat.hl .v { color: var(--accent); }
.stat.bad .v { color: var(--bad); }

.steps { display: flex; flex-direction: column; gap: 8px; }
.step { border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); padding: 9px 10px; }
.step-head { display: flex; align-items: baseline; gap: 8px; font-size: 0.8rem; color: var(--dim); }
.step-n { font-weight: 650; color: var(--text); }
.step-cost { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 650; color: var(--xp); }
.step-cost.over { color: var(--bad); }
.step-body { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center; margin-top: 6px; }
@media (max-width: 620px) { .step-body { grid-template-columns: 1fr; } .arrow { transform: rotate(90deg); justify-self: start; } }
.slot { font-size: 0.8rem; min-width: 0; }
.slot .lbl { font-size: 0.68rem; color: var(--dim); text-transform: uppercase; letter-spacing: 0.04em; }
.arrow { color: var(--dim); font-size: 1.1rem; }
.ench-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.tag {
  background: var(--accent-soft); color: var(--text); border-radius: 5px;
  padding: 1px 6px; font-size: 0.74rem; white-space: nowrap;
}
.tag.pw { background: transparent; border: 1px dashed var(--line); color: var(--dim); }
.note { font-size: 0.76rem; color: var(--warn); margin-top: 5px; }
.msg { font-size: 0.85rem; padding: 10px; border-radius: 8px; background: var(--panel-2); border: 1px solid var(--line); }
.msg.bad { border-color: var(--bad); color: var(--bad); }
.msg.warn { border-color: var(--warn); color: var(--warn); }
.preview { font-size: 0.85rem; padding: 10px; border-radius: 8px; background: var(--panel-2); border: 1px solid var(--line); }
.final { border-top: 1px dashed var(--line); padding-top: 10px; }

footer { padding: 18px 16px 28px; max-width: 1400px; margin: 0 auto; font-size: 0.78rem; color: var(--dim); }
footer .sep { opacity: 0.5; }
