/* ============================================================
   ENCHANT BUILD PLANNER  (/plugins/enchanting-planner.html)
   Interactive loadout calculator. Reads /data/enchanting.json (same
   live config as the codex). Layered on rank-pages.css + plugin-pages.css
   + enchanting.css (for the --ec violet identity and --ec-<category> colours).
   Prefix: ep-
   ============================================================ */
.ep-page .rk-tagline a { color: var(--ec-bright); }

/* category accent binding: every card marked is-<cat> picks up --c */
.ep-perk.is-gathering, .ep-tot.is-gathering, .ep-pick-perk.is-gathering { --c: var(--ec-gathering); }
.ep-perk.is-fishing,   .ep-tot.is-fishing,   .ep-pick-perk.is-fishing   { --c: var(--ec-fishing); }
.ep-perk.is-combat,    .ep-tot.is-combat,    .ep-pick-perk.is-combat    { --c: var(--ec-combat); }
.ep-perk.is-defense,   .ep-tot.is-defense,   .ep-pick-perk.is-defense   { --c: var(--ec-defense); }
.ep-perk.is-luck,      .ep-tot.is-luck,      .ep-pick-perk.is-luck      { --c: var(--ec-luck); }
.ep-perk.is-crafting,  .ep-tot.is-crafting,  .ep-pick-perk.is-crafting  { --c: var(--ec-crafting); }
.ep-perk.is-survival,  .ep-tot.is-survival,  .ep-pick-perk.is-survival  { --c: var(--ec-survival); }
.ep-perk.is-other,     .ep-tot.is-other,     .ep-pick-perk.is-other     { --c: var(--ec-other); }

/* ---------- toolbar ---------- */
.ep-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem;
  margin-bottom: 1.4rem;
}
.ep-toolbar .ep-updated {
  display: inline-flex; align-items: center; gap: 0.45rem;
  margin-right: auto; font-size: 0.82rem; color: var(--rk-muted, #9aa3b2);
}
.ep-updated i { width: 8px; height: 8px; border-radius: 50%; background: #7ee66b; box-shadow: 0 0 8px #7ee66b; }
.ep-btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.5rem 0.85rem; border-radius: 10px; cursor: pointer;
  font: inherit; font-weight: 600; font-size: 0.88rem;
  border: 1px solid var(--ec-line); background: var(--ec-dim); color: var(--ec-bright);
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.ep-btn svg { width: 16px; height: 16px; }
.ep-btn:hover { background: rgba(180, 140, 255, 0.22); border-color: var(--ec); transform: translateY(-1px); }
.ep-btn.is-go { background: linear-gradient(180deg, rgba(180, 140, 255, 0.4), rgba(180, 140, 255, 0.18)); border-color: var(--ec); color: #fff; box-shadow: 0 6px 20px rgba(180, 140, 255, 0.25); }
.ep-btn.is-go:hover { box-shadow: 0 10px 28px rgba(180, 140, 255, 0.4); }
.ep-btn.is-quiet { background: rgba(255, 255, 255, 0.04); border-color: rgba(255, 255, 255, 0.12); color: #cdd3df; }
.ep-btn.is-quiet:hover { border-color: rgba(255, 255, 255, 0.25); color: #fff; }
.ep-btn.is-copied { background: rgba(126, 230, 107, 0.18); border-color: #7ee66b; color: #cdeecd; }
.ep-btn[disabled] { opacity: 0.45; pointer-events: none; }

/* ---------- two-column layout ---------- */
.ep-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 1.6rem; align-items: start; }
.ep-summary-col { position: sticky; top: 84px; }
@media (max-width: 900px) {
  .ep-layout { grid-template-columns: 1fr; }
  .ep-summary-col { position: static; }
}

/* ---------- build column ---------- */
.ep-build { display: flex; flex-direction: column; gap: 1rem; }
.ep-loading { padding: 2.4rem; text-align: center; color: var(--ec-bright); letter-spacing: 0.02em; }

.ep-piece {
  border: 1px solid var(--ec-line); border-radius: 16px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(0, 0, 0, 0.12));
  padding: 0.9rem; position: relative; overflow: hidden;
}
.ep-piece::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: linear-gradient(180deg, var(--ec), transparent); }
.ep-piece-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.6rem; }
.ep-piece-n { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.14em; color: var(--ec-bright); font-weight: 700; }
.ep-piece-x { background: none; border: none; color: #8b93a3; cursor: pointer; padding: 4px; border-radius: 8px; line-height: 0; transition: color 0.15s, background 0.15s; }
.ep-piece-x svg { width: 17px; height: 17px; }
.ep-piece-x:hover { color: #ff6b5c; background: rgba(255, 107, 92, 0.12); }

/* item selector */
.ep-item {
  display: flex; align-items: center; gap: 0.7rem; width: 100%; text-align: left; cursor: pointer;
  padding: 0.7rem 0.8rem; border-radius: 12px; font: inherit;
  border: 1px dashed var(--ec-line); background: rgba(180, 140, 255, 0.06); color: #e8eaf0;
  transition: border-color 0.15s, background 0.15s;
}
.ep-item.is-set { border-style: solid; background: rgba(180, 140, 255, 0.1); }
.ep-item:hover { border-color: var(--ec); background: rgba(180, 140, 255, 0.16); }
.ep-item-ico { flex: 0 0 auto; width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; background: rgba(180, 140, 255, 0.14); color: var(--ec-bright); }
.ep-item-ico svg { width: 22px; height: 22px; }
.ep-item-ico.is-empty { color: #9aa3b2; background: rgba(255, 255, 255, 0.05); }
.ep-item-name { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1; }
.ep-item-name b { font-size: 1rem; color: #fff; }
.ep-item-name small { font-size: 0.76rem; color: #9aa3b2; }
.ep-item-edit { flex: 0 0 auto; font-size: 0.76rem; font-weight: 700; color: var(--ec-bright); padding: 0.25rem 0.55rem; border-radius: 999px; background: rgba(180, 140, 255, 0.14); }

/* equipped perks */
.ep-perks { display: flex; flex-direction: column; gap: 0.45rem; margin-top: 0.7rem; }
.ep-perk {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.5rem 0.55rem 0.5rem 0.6rem; border-radius: 11px;
  border: 1px solid rgba(255, 255, 255, 0.08); background: rgba(0, 0, 0, 0.18);
  border-left: 3px solid var(--c);
}
.ep-perk-ico { flex: 0 0 auto; width: 30px; height: 30px; display: grid; place-items: center; border-radius: 8px; color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); }
.ep-perk-ico svg { width: 18px; height: 18px; }
.ep-perk-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.ep-perk-main b { font-size: 0.92rem; color: #f2f3f7; }
.ep-perk-sub { font-size: 0.74rem; color: #9aa3b2; }
.ep-perk-tot { color: var(--ec-bright); }
.ep-stack { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 2px; background: rgba(255, 255, 255, 0.05); border-radius: 999px; padding: 2px; }
.ep-step { width: 24px; height: 24px; border-radius: 999px; border: none; cursor: pointer; font-size: 1rem; line-height: 1; color: #e8eaf0; background: rgba(255, 255, 255, 0.07); transition: background 0.13s, color 0.13s; }
.ep-step:hover { background: var(--ec); color: #1a1030; }
.ep-step[disabled] { opacity: 0.35; pointer-events: none; }
.ep-count { min-width: 30px; text-align: center; font-size: 0.82rem; font-weight: 700; color: #fff; }
.ep-perk-x { flex: 0 0 auto; width: 24px; height: 24px; border: none; background: none; color: #7d859a; cursor: pointer; border-radius: 7px; font-size: 1.05rem; line-height: 1; transition: color 0.13s, background 0.13s; }
.ep-perk-x:hover { color: #ff6b5c; background: rgba(255, 107, 92, 0.12); }

.ep-addperk {
  display: inline-flex; align-items: center; gap: 0.35rem; align-self: flex-start;
  padding: 0.45rem 0.75rem; margin-top: 0.15rem; cursor: pointer; font: inherit; font-weight: 600; font-size: 0.82rem;
  border: 1px dashed var(--ec-line); border-radius: 10px; background: transparent; color: var(--ec-bright);
  transition: background 0.15s, border-color 0.15s;
}
.ep-addperk svg { width: 15px; height: 15px; }
.ep-addperk small { color: #8b93a3; font-weight: 600; }
.ep-addperk:hover { background: rgba(180, 140, 255, 0.12); border-color: var(--ec); }
.ep-full { margin: 0.3rem 0 0; font-size: 0.76rem; color: #8b93a3; font-style: italic; }
.ep-piece-cost { display: flex; justify-content: flex-end; gap: 0.9rem; margin-top: 0.7rem; padding-top: 0.55rem; border-top: 1px solid rgba(255, 255, 255, 0.06); font-size: 0.8rem; color: #b9c0cd; }
.ep-piece-cost span:last-child { color: var(--ec-luck); font-weight: 700; }

/* empty state */
.ep-empty { text-align: center; padding: 2.4rem 1.4rem; border: 1px dashed var(--ec-line); border-radius: 18px; background: rgba(180, 140, 255, 0.04); }
.ep-empty-ico { display: inline-grid; place-items: center; width: 60px; height: 60px; border-radius: 16px; background: rgba(180, 140, 255, 0.12); color: var(--ec-bright); margin-bottom: 0.8rem; }
.ep-empty-ico svg { width: 32px; height: 32px; }
.ep-empty h3 { margin: 0 0 0.4rem; font-size: 1.15rem; color: #fff; }
.ep-empty p { margin: 0 auto 1.2rem; max-width: 46ch; color: #a7aebb; font-size: 0.9rem; line-height: 1.55; }
.ep-empty-actions { display: flex; gap: 0.6rem; justify-content: center; flex-wrap: wrap; }

/* ---------- summary column ---------- */
.ep-summary {
  border: 1px solid var(--ec-line); border-radius: 18px; overflow: hidden;
  background: linear-gradient(180deg, rgba(180, 140, 255, 0.08), rgba(10, 13, 20, 0.6));
}
.ep-cost { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; background: rgba(255, 255, 255, 0.07); }
.ep-cost-fig { background: #0b0e15; padding: 0.85rem 0.6rem; text-align: center; }
.ep-cost-fig b { display: block; font-size: 1.5rem; font-weight: 800; color: #fff; line-height: 1; font-family: "Cinzel", serif; }
.ep-cost-fig span { display: block; margin-top: 0.25rem; font-size: 0.72rem; color: #9aa3b2; text-transform: uppercase; letter-spacing: 0.06em; }
.ep-cost-fig.is-rp b { color: var(--ec-luck); }

.ep-sum-groups { padding: 0.9rem; display: flex; flex-direction: column; gap: 1rem; max-height: 62vh; overflow-y: auto; }
.ep-sum-group h4 { display: flex; align-items: center; gap: 0.4rem; margin: 0 0 0.5rem; font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--c); }
.ep-sum-group h4 span { display: inline-grid; place-items: center; }
.ep-sum-group h4 svg { width: 15px; height: 15px; }

.ep-tot { padding: 0.55rem 0.65rem; border-radius: 11px; background: rgba(0, 0, 0, 0.22); border: 1px solid rgba(255, 255, 255, 0.06); margin-bottom: 0.45rem; }
.ep-tot-head { display: flex; align-items: center; gap: 0.4rem; }
.ep-tot-ico { color: var(--c); display: inline-grid; place-items: center; }
.ep-tot-ico svg { width: 16px; height: 16px; }
.ep-tot-head b { font-size: 0.86rem; color: #eef0f4; margin-right: auto; }
.ep-tot-copies { font-size: 0.74rem; font-weight: 700; color: #cbd0da; background: rgba(255, 255, 255, 0.07); padding: 1px 6px; border-radius: 999px; }
.ep-tot-tag { font-size: 0.66rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; padding: 2px 6px; border-radius: 999px; }
.ep-tot-tag.is-cap { background: rgba(126, 230, 107, 0.16); color: #9fe38c; }
.ep-tot-tag.is-near { background: rgba(255, 208, 90, 0.14); color: var(--ec-luck); }
.ep-tot-tag.is-nocap { background: rgba(116, 168, 255, 0.14); color: var(--ec-defense); }
.ep-tot-val { display: flex; align-items: baseline; gap: 0.5rem; margin: 0.35rem 0 0.35rem; }
.ep-tot-val b { font-size: 1.05rem; color: #fff; }
.ep-tot-cap { font-size: 0.72rem; color: #8b93a3; }
.ep-gauge { position: relative; height: 7px; border-radius: 999px; background: rgba(255, 255, 255, 0.08); overflow: hidden; }
.ep-gauge-fill { position: absolute; top: 0; bottom: 0; border-radius: 999px; background: linear-gradient(90deg, color-mix(in srgb, var(--c) 55%, transparent), var(--c)); box-shadow: 0 0 10px color-mix(in srgb, var(--c) 60%, transparent); transition: left 0.3s ease, width 0.3s ease; }
.ep-gauge.is-max .ep-gauge-fill { background: linear-gradient(90deg, #6fce5f, #9fe38c); box-shadow: 0 0 10px rgba(126, 230, 107, 0.5); }
.ep-gauge-cap { position: absolute; top: -2px; bottom: -2px; right: 0; width: 2px; background: #fff; box-shadow: 0 0 6px rgba(255, 255, 255, 0.7); }
.ep-tot-note { margin: 0.4rem 0 0; font-size: 0.72rem; color: #8b93a3; }

.ep-sum-empty { padding: 2rem 1.2rem; text-align: center; color: #8b93a3; }
.ep-sum-empty span { display: inline-grid; place-items: center; width: 46px; height: 46px; border-radius: 12px; background: rgba(180, 140, 255, 0.1); color: var(--ec-bright); margin-bottom: 0.6rem; }
.ep-sum-empty svg { width: 24px; height: 24px; }
.ep-sum-empty p { margin: 0; font-size: 0.86rem; }
.ep-sum-fine { padding: 0.2rem 0.9rem 0.9rem; margin: 0; font-size: 0.72rem; color: #7d859a; line-height: 1.5; }
.ep-sum-fine a { color: var(--ec-bright); }

/* ---------- modal (item + perk picker) ---------- */
body.ep-modal-open { overflow: hidden; }
.ep-modal { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 4vh 1rem; }
.ep-modal-backdrop { position: absolute; inset: 0; background: rgba(4, 6, 11, 0.72); backdrop-filter: blur(3px); animation: ep-fade 0.16s ease; }
.ep-modal-panel {
  position: relative; width: min(620px, 100%); max-height: 92vh; display: flex; flex-direction: column;
  border: 1px solid var(--ec-line); border-radius: 18px; overflow: hidden;
  background: linear-gradient(180deg, #12141c, #0a0c12); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  animation: ep-pop 0.18s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
@keyframes ep-fade { from { opacity: 0; } }
@keyframes ep-pop { from { opacity: 0; transform: translateY(14px) scale(0.98); } }
.ep-modal-head { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.1rem; border-bottom: 1px solid rgba(255, 255, 255, 0.07); }
.ep-modal-head h2 { margin: 0; font-size: 1.1rem; color: #fff; }
.ep-modal-close { background: none; border: none; color: #9aa3b2; font-size: 1.6rem; line-height: 1; cursor: pointer; padding: 0 4px; border-radius: 8px; transition: color 0.13s, background 0.13s; }
.ep-modal-close:hover { color: #fff; background: rgba(255, 255, 255, 0.08); }
.ep-modal-body { padding: 1rem 1.1rem 1.2rem; overflow-y: auto; }
.ep-pick-for { margin: 0 0 0.7rem; font-size: 0.86rem; color: #a7aebb; }
.ep-pick-for b { color: var(--ec-bright); }

.ep-search { display: block; position: relative; margin-bottom: 0.9rem; }
.ep-search input { width: 100%; padding: 0.6rem 0.8rem; border-radius: 10px; border: 1px solid var(--ec-line); background: rgba(0, 0, 0, 0.3); color: #fff; font: inherit; }
.ep-search input:focus { outline: none; border-color: var(--ec); box-shadow: 0 0 0 3px rgba(180, 140, 255, 0.18); }

.ep-pick-list { display: flex; flex-direction: column; gap: 1rem; }
.ep-pick-group h5 { display: flex; align-items: center; gap: 0.4rem; margin: 0 0 0.5rem; font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--c, var(--ec-bright)); }
.ep-pick-group h5 span { color: #6b7385; font-weight: 600; }
.ep-pick-items { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.4rem; }
.ep-pick-item { text-align: left; cursor: pointer; font: inherit; padding: 0.5rem 0.6rem; border-radius: 10px; border: 1px solid rgba(255, 255, 255, 0.08); background: rgba(255, 255, 255, 0.03); color: #e8eaf0; display: flex; flex-direction: column; gap: 1px; transition: border-color 0.13s, background 0.13s, transform 0.1s; }
.ep-pick-item b { font-size: 0.85rem; }
.ep-pick-item small { font-size: 0.7rem; color: #8b93a3; }
.ep-pick-item:hover { border-color: var(--ec); background: rgba(180, 140, 255, 0.12); transform: translateY(-1px); }

.ep-pick-perk { display: flex; align-items: center; gap: 0.6rem; width: 100%; text-align: left; cursor: pointer; font: inherit; padding: 0.55rem 0.6rem; margin-bottom: 0.4rem; border-radius: 11px; border: 1px solid rgba(255, 255, 255, 0.08); border-left: 3px solid var(--c); background: rgba(0, 0, 0, 0.18); color: #e8eaf0; transition: background 0.13s, transform 0.1s; }
.ep-pick-perk:hover { background: rgba(180, 140, 255, 0.1); transform: translateY(-1px); }
.ep-pick-perk-ico { flex: 0 0 auto; width: 30px; height: 30px; display: grid; place-items: center; border-radius: 8px; color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); }
.ep-pick-perk-ico svg { width: 18px; height: 18px; }
.ep-pick-perk-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ep-pick-perk-main b { font-size: 0.9rem; color: #f2f3f7; }
.ep-pick-perk-main small { font-size: 0.74rem; color: #9aa3b2; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.ep-pick-perk-meta { flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.ep-pick-perk-range { font-size: 0.78rem; font-weight: 700; color: #fff; white-space: nowrap; }
.ep-pick-perk-cost { font-size: 0.7rem; color: var(--ec-luck); white-space: nowrap; }
.ep-pick-none { color: #8b93a3; text-align: center; padding: 1.4rem; }

@media (max-width: 520px) {
  .ep-perk-sub .ep-perk-tot { display: block; }
  .ep-pick-items { grid-template-columns: 1fr 1fr; }
}
