:root {
  --bg: #0c1014;
  --panel: #121820;
  --panel-2: #171f28;
  --panel-3: #1d2732;
  --text: #f4f0e7;
  --muted: #9da8b5;
  --faint: #687482;
  --border: #293543;
  --border-strong: #3a4857;
  --gold: #e7b45a;
  --gold-bright: #ffd985;
  --gold-soft: rgba(231, 180, 90, .14);
  --danger: #ff786f;
  --danger-soft: rgba(255, 120, 111, .1);
  --warrior: #e16f5b;
  --ranger: #72c38b;
  --mage: #7f9ce8;
  --core: #d1b879;
  --shadow: 0 24px 70px rgba(0, 0, 0, .36);
  --radius: 14px;
  --font-display: Georgia, "Times New Roman", serif;
  --font-ui: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  color: var(--text);
  background:
    radial-gradient(circle at 72% 2%, rgba(91, 118, 147, .11), transparent 32%),
    radial-gradient(circle at 8% 100%, rgba(199, 142, 58, .08), transparent 28%),
    var(--bg);
  font: 500 15px/1.5 var(--font-ui);
}

button, input, textarea { font: inherit; }
button { color: inherit; }
button, .node { cursor: pointer; }

button:focus-visible, input:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--gold-bright);
  outline-offset: 2px;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 12px;
  left: 12px;
  transform: translateY(-150%);
  padding: 10px 14px;
  color: #17130d;
  background: var(--gold-bright);
  border-radius: 8px;
}
.skip-link:focus { transform: translateY(0); }

.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;
}

.hidden { display: none !important; }

.app-shell {
  display: grid;
  grid-template-rows: 76px 58px minmax(0, 1fr);
  height: 100%;
}

.topbar, .controlbar {
  display: flex;
  align-items: center;
  gap: 18px;
  border-bottom: 1px solid var(--border);
  padding: 0 22px;
  background: rgba(14, 19, 24, .94);
  backdrop-filter: blur(14px);
  z-index: 5;
}

.topbar { justify-content: space-between; }

.brand-block { display: flex; align-items: center; gap: 12px; min-width: 250px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(231, 180, 90, .42);
  border-radius: 11px;
  color: var(--gold-bright);
  background: linear-gradient(145deg, rgba(231, 180, 90, .18), rgba(231, 180, 90, .03));
  box-shadow: inset 0 0 18px rgba(231, 180, 90, .09);
}
.brand-mark svg { width: 25px; fill: currentColor; }
.eyebrow { margin: 0; color: var(--gold); font-size: 11px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
h1, h2 { font-family: var(--font-display); }
h1 { margin: -1px 0 0; font-size: 26px; line-height: 1.05; font-weight: 600; letter-spacing: .01em; }

.point-summary {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 6px 18px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: rgba(255, 255, 255, .018);
}
.point-summary div { display: flex; align-items: baseline; gap: 7px; }
.point-summary span { color: var(--gold-bright); font: 600 22px/1 var(--font-display); }
.point-summary small { color: var(--muted); font-size: 12px; }
.summary-divider { width: 1px; height: 22px; background: var(--border-strong); }

.top-actions, .dialog-actions { display: flex; gap: 9px; align-items: center; }
.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  font-weight: 750;
  font-size: 13px;
  background: var(--panel-2);
  transition: border-color .18s ease, background .18s ease, color .18s ease, transform .18s ease;
}
.button:hover { border-color: #5a6979; background: var(--panel-3); }
.button:active { transform: translateY(1px); }
.button svg, .search-field svg, .source-note svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.button-primary { color: #1d1609; border-color: var(--gold); background: linear-gradient(180deg, var(--gold-bright), var(--gold)); }
.button-primary:hover { border-color: #ffe1a0; background: #f7c66f; }
.button-secondary { color: var(--text); background: #202a34; }
.button-ghost { background: transparent; }
.button-danger-soft { color: #ffaaa4; border-color: rgba(255, 120, 111, .26); background: var(--danger-soft); }
.button-danger-soft:hover { border-color: rgba(255, 120, 111, .55); background: rgba(255, 120, 111, .16); }
.button:disabled { cursor: not-allowed; opacity: .42; transform: none; }

.controlbar { gap: 14px; background: #10161c; }
.search-field {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 210px;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--muted);
  background: #0c1116;
}
.search-field:focus-within { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
.search-field input { width: 100%; color: var(--text); border: 0; outline: 0; background: transparent; }
.search-field input::placeholder { color: var(--faint); }

.segmented { display: flex; align-items: center; gap: 3px; overflow-x: auto; }
.segment {
  min-height: 38px;
  white-space: nowrap;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 11px;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  font-weight: 700;
}
.segment:hover { color: var(--text); background: rgba(255, 255, 255, .035); }
.segment.active { color: var(--gold-bright); border-color: rgba(231, 180, 90, .35); background: var(--gold-soft); }
.segment span { margin-left: 4px; color: var(--faint); }
.segment.active span { color: var(--gold); }

.budget-control { display: flex; align-items: center; gap: 9px; margin-left: auto; color: var(--muted); font-size: 12px; font-weight: 750; white-space: nowrap; }
.budget-control input {
  width: 66px;
  height: 38px;
  padding: 0 8px;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0c1116;
  text-align: center;
}

.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 340px; min-height: 0; }
.tree-panel { position: relative; min-width: 0; min-height: 0; border-right: 1px solid var(--border); }
.tree-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background:
    linear-gradient(rgba(255,255,255,.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.022) 1px, transparent 1px),
    radial-gradient(circle at 50% 48%, rgba(231, 180, 90, .055), transparent 32%),
    #0b1015;
  background-size: 40px 40px, 40px 40px, auto, auto;
  touch-action: none;
}
.tree-stage.dragging { cursor: grabbing; }
#tree-svg { display: block; width: 100%; height: 100%; user-select: none; }

.edge { stroke: #34414d; stroke-width: 4; fill: none; opacity: .54; vector-effect: non-scaling-stroke; transition: stroke .18s ease, opacity .18s ease; }
.edge.active { stroke: var(--gold); opacity: .76; }
.edge.base-edge { stroke: #927849; opacity: .6; }
.edge.filtered { opacity: .09; }
.base-ring { fill: rgba(231, 180, 90, .025); stroke: rgba(231, 180, 90, .42); stroke-width: 5; stroke-dasharray: 10 9; vector-effect: non-scaling-stroke; }
.base-anchor { cursor: default; pointer-events: none; }
.base-anchor-ring { fill: #171b1e; stroke: rgba(231, 180, 90, .72); stroke-width: 4; vector-effect: non-scaling-stroke; }
.base-anchor-dot { fill: var(--gold-bright); filter: drop-shadow(0 0 9px rgba(231, 180, 90, .7)); }

.node { color: var(--muted); transition: opacity .18s ease; }
.node .node-hit { fill: transparent; }
.node .node-ring { fill: #10171e; stroke: #46525e; stroke-width: 7; vector-effect: non-scaling-stroke; transition: fill .18s ease, stroke .18s ease, filter .18s ease; }
.node .node-core { fill: #222d37; stroke: rgba(255,255,255,.07); stroke-width: 2; vector-effect: non-scaling-stroke; }
.node .node-glyph { fill: none; stroke: currentColor; stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.node .node-label { fill: #c8d0d7; font: 700 25px/1 var(--font-ui); paint-order: stroke; stroke: #0b1015; stroke-width: 7; stroke-linejoin: round; pointer-events: none; }
.node .node-cost-bg { fill: #111820; stroke: #48545f; stroke-width: 3; vector-effect: non-scaling-stroke; }
.node .node-cost { fill: #d6dee4; font: 800 22px/1 var(--font-ui); text-anchor: middle; dominant-baseline: central; }
.node .node-rank { fill: #10161c; stroke: #5a6875; stroke-width: 3; vector-effect: non-scaling-stroke; }
.node .node-rank-text { fill: #e9edf0; font: 800 18px/1 var(--font-ui); text-anchor: middle; dominant-baseline: central; }
.node.available { color: #e5c786; }
.node.available .node-ring { stroke: #a78850; filter: drop-shadow(0 0 7px rgba(231, 180, 90, .18)); }
.node.selected { color: #241a0a; }
.node.selected .node-ring { fill: var(--gold); stroke: var(--gold-bright); filter: drop-shadow(0 0 12px rgba(231, 180, 90, .45)); }
.node.selected .node-core { fill: var(--gold-bright); }
.node.selected .node-label { fill: #ffe3a1; }
.node.selected .node-cost-bg, .node.selected .node-rank { fill: var(--gold-bright); stroke: #fff0bc; }
.node.selected .node-cost, .node.selected .node-rank-text { fill: #2b1d08; }
.node.locked { opacity: .43; }
.node.filtered { opacity: .08; pointer-events: none; }
.node.search-match .node-ring { stroke: #fff; filter: drop-shadow(0 0 14px rgba(255,255,255,.58)); }
.node.focused .node-ring { stroke: #fff3c7; stroke-width: 10; }

.tree-tools {
  position: absolute;
  left: 16px;
  bottom: 16px;
  display: grid;
  gap: 5px;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(16, 22, 28, .9);
  box-shadow: var(--shadow);
}
.tree-tools button, .icon-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  color: var(--muted);
  border: 0;
  border-radius: 7px;
  background: transparent;
  font-size: 22px;
}
.tree-tools button:hover, .icon-button:hover { color: var(--text); background: rgba(255,255,255,.055); }
.tree-tools svg { width: 19px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.legend {
  position: absolute;
  right: 16px;
  bottom: 16px;
  display: flex;
  gap: 14px;
  padding: 9px 12px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 9px;
  background: rgba(16, 22, 28, .9);
  font-size: 11px;
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend-dot { width: 10px; height: 10px; border: 2px solid #65717c; border-radius: 50%; background: #202a33; }
.legend-dot.base { border-color: var(--gold); background: var(--gold-bright); box-shadow: 0 0 6px rgba(231, 180, 90, .5); }
.legend-dot.available { border-color: #a78850; }
.legend-dot.selected { border-color: var(--gold-bright); background: var(--gold); }
.legend-dot.locked { opacity: .45; }

.detail-panel { display: flex; flex-direction: column; gap: 22px; min-width: 0; padding: 26px 24px 20px; overflow: auto; background: linear-gradient(180deg, #131a22, #10161c); }
.empty-detail { margin: auto 0; text-align: center; color: var(--muted); }
.empty-icon { display: grid; place-items: center; width: 66px; height: 66px; margin: 0 auto 18px; color: var(--gold); border: 1px solid var(--border-strong); border-radius: 50%; background: var(--gold-soft); }
.empty-icon svg { width: 31px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; }
.empty-detail h2, .skill-detail h2, dialog h2 { margin: 7px 0 8px; font-size: 25px; font-weight: 500; }
.empty-detail p:last-child { max-width: 270px; margin: 0 auto; font-size: 13px; }

.detail-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.class-badge, .data-badge { display: inline-flex; align-items: center; min-height: 26px; padding: 0 9px; border-radius: 999px; font-size: 10px; font-weight: 850; letter-spacing: .08em; text-transform: uppercase; }
.class-badge { color: #17130e; background: var(--core); }
.class-badge.warrior { background: var(--warrior); }
.class-badge.ranger { background: var(--ranger); }
.class-badge.mage { background: var(--mage); }
.data-badge { color: #a9e8bd; background: rgba(114, 195, 139, .11); border: 1px solid rgba(114, 195, 139, .25); }
.data-badge.unverified { color: #ffd38d; background: rgba(231, 180, 90, .1); border-color: rgba(231, 180, 90, .25); }
.skill-detail h2 { margin-top: 14px; font-size: 29px; line-height: 1.12; }
.english-name { margin: -3px 0 18px; color: var(--faint); font-size: 12px; }
.detail-description { white-space: pre-line; color: #c5cdd4; font-size: 13px; }
.detail-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin: 22px 0; }
.detail-stats div { padding: 10px 9px; border: 1px solid var(--border); border-radius: 9px; background: rgba(255,255,255,.018); }
.detail-stats dt { color: var(--faint); font-size: 9px; font-weight: 850; letter-spacing: .06em; text-transform: uppercase; }
.detail-stats dd { margin: 4px 0 0; color: var(--gold-bright); font-size: 14px; font-weight: 800; }
.requirements { padding: 14px; border: 1px solid var(--border); border-radius: 10px; background: #0e141a; }
.requirements h3 { margin: 0 0 7px; color: var(--muted); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.requirements p { margin: 0; color: #cbd2d8; font-size: 12px; }
.rank-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 18px; }

.source-note { display: flex; gap: 10px; margin-top: auto; padding-top: 18px; color: var(--faint); border-top: 1px solid var(--border); font-size: 10px; }
.source-note svg { flex: 0 0 auto; margin-top: 1px; }
.source-note p { margin: 0; }
.source-note strong { color: var(--muted); }
.source-note code { color: var(--gold); }

dialog { width: min(94vw, 520px); padding: 0; color: var(--text); border: 1px solid var(--border-strong); border-radius: 15px; background: transparent; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(4, 7, 9, .78); backdrop-filter: blur(4px); }
.dialog-card { padding: 22px; background: var(--panel); }
.dialog-wide { width: min(94vw, 670px); }
#builds-dialog { width: min(94vw, 670px); }
.dialog-header { display: flex; align-items: start; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.dialog-header h2 { margin-bottom: 0; }
.icon-button { flex: 0 0 auto; font-size: 27px; }
.form-field { display: grid; gap: 7px; }
.form-field span { color: var(--muted); font-size: 12px; font-weight: 750; }
.form-field input, .form-field textarea {
  width: 100%;
  padding: 11px 12px;
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  outline: none;
  background: #0c1116;
}
.form-field textarea { resize: vertical; min-height: 105px; font: 500 12px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; }
.dialog-actions { justify-content: flex-end; margin-top: 18px; }
.split-actions { justify-content: space-between; }
.dialog-copy { margin: -4px 0 18px; color: var(--muted); font-size: 13px; }
.saved-build-list { display: grid; gap: 8px; max-height: 430px; overflow: auto; }
.saved-build-empty { padding: 32px; color: var(--muted); border: 1px dashed var(--border-strong); border-radius: 10px; text-align: center; }
.saved-build-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; padding: 13px; border: 1px solid var(--border); border-radius: 10px; background: #0e141a; }
.saved-build-item h3 { margin: 0 0 3px; font-size: 14px; }
.saved-build-item p { margin: 0; color: var(--muted); font-size: 11px; }
.saved-build-actions { display: flex; gap: 5px; }
.saved-build-actions button { min-width: 42px; min-height: 42px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel-2); }
.saved-build-actions button:hover { border-color: var(--gold); }

.toast {
  position: fixed;
  z-index: 110;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 30px);
  padding: 10px 15px;
  color: #1b160d;
  border-radius: 9px;
  background: var(--gold-bright);
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { color: #fff; background: #b94d47; }

@media (max-width: 1120px) {
  .brand-block { min-width: 0; }
  .top-actions .button { padding: 0 11px; }
  .top-actions .button { font-size: 0; }
  .top-actions .button svg { width: 19px; height: 19px; }
  .workspace { grid-template-columns: minmax(0, 1fr) 300px; }
  .segment { padding: 0 8px; }
  .segment span { display: none; }
}

@media (max-width: 820px) {
  body { overflow: auto; }
  .app-shell { grid-template-rows: auto auto minmax(680px, 1fr); min-height: 100%; }
  .topbar { flex-wrap: wrap; padding: 12px 14px; }
  .point-summary { order: 3; width: 100%; justify-content: center; }
  .controlbar { flex-wrap: wrap; padding: 10px 12px; }
  .search-field { flex: 1 1 200px; }
  .segmented { order: 3; width: 100%; }
  .budget-control { margin-left: 0; }
  .workspace { grid-template-columns: 1fr; grid-template-rows: minmax(610px, 72vh) auto; }
  .tree-panel { border-right: 0; border-bottom: 1px solid var(--border); }
  .detail-panel { min-height: 320px; }
  .legend { display: none; }
}

@media (max-width: 520px) {
  .brand-block { width: calc(100% - 150px); }
  .top-actions { margin-left: auto; }
  .top-actions .button { min-width: 42px; padding: 0 10px; }
  .controlbar .button-danger-soft { flex: 1; }
  .segmented { padding-bottom: 2px; }
  .segment { flex: 0 0 auto; }
  .detail-panel { padding: 22px 16px; }
  .dialog-actions { flex-wrap: wrap; }
  .dialog-actions .button { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
