:root {
  --bg: #0c0e14;
  --bg-elevated: #141824;
  --bg-card: #1a1f2e;
  --border: #2a3145;
  --text: #e8ecf4;
  --muted: #8b95a8;
  --gold: #c9a227;
  --gold-dim: #8a7020;
  --p4: #4a9eff;
  --p5: #b06cff;
  --source: #9aa8c2;
  --danger: #ff6b6b;
  --ok: #3ecf8e;
  --radius: 12px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  --sidebar-w: 300px;
  --q1: #ffffff;
  --q2: #1eff00;
  --q3: #0070dd;
  --q4: #a335ee;
  --q5: #ff8000;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: Inter, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  background-image: radial-gradient(ellipse 80% 50% at 50% -20%, rgba(201, 162, 39, 0.12), transparent);
}

a { color: #7eb8ff; text-decoration: none; }
a:hover { text-decoration: underline; }

.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
}

.brand { padding: 1rem; border-bottom: 1px solid var(--border); }
.brand-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.5rem; }
.brand-identity { display: flex; align-items: center; gap: 0.65rem; min-width: 0; }
.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 1px solid rgba(201, 162, 39, 0.35);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  flex-shrink: 0;
  object-fit: cover;
}
.brand h1 {
  font-family: Cinzel, serif;
  font-size: 0.95rem;
  color: var(--gold);
  line-height: 1.15;
}
.brand p { font-size: 0.68rem; color: var(--muted); margin-top: 0.2rem; }

.lang-btn, .tool-btn, .filter-btn, .view-tab {
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 600;
}

.lang-btn { padding: 0.35rem 0.55rem; color: var(--gold); }
.view-tabs { display: flex; gap: 0.35rem; padding: 0.6rem 1rem 0; }
.view-tab {
  flex: 1;
  padding: 0.45rem;
  background: transparent;
  color: var(--muted);
  border-radius: 8px 8px 0 0;
}
.view-tab.active { background: var(--bg-card); color: var(--gold); border-bottom-color: transparent; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.55rem 1rem;
  border-bottom: 1px solid var(--border);
}
.tool-btn { padding: 0.35rem 0.55rem; }
.tool-btn.active { background: var(--gold); color: #111; border-color: var(--gold); }
.tool-btn.danger:hover { border-color: var(--danger); color: var(--danger); }

.search-wrap { padding: 0.65rem 1rem; border-bottom: 1px solid var(--border); }
.search-wrap input, .modal-body input[type="search"] {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
}

.filters { display: flex; gap: 0.35rem; padding: 0.55rem 1rem; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.filter-btn { padding: 0.3rem 0.55rem; border-radius: 999px; background: transparent; color: var(--muted); }
.filter-btn.active { background: var(--gold); color: #111; border-color: var(--gold); }

.nav-scroll { overflow-y: auto; flex: 1; padding: 0.5rem 0 1rem; }
.nav-class-title {
  padding: 0.45rem 1rem 0.25rem;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.nav-spec {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.45rem 1rem 0.45rem 1.25rem;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 0.82rem;
  cursor: pointer;
  border-left: 3px solid transparent;
}
.nav-spec.active { background: rgba(201, 162, 39, 0.1); border-left-color: var(--gold); color: var(--gold); }
.nav-spec .role-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 0.45rem; }

.server-hint {
  padding: 0.65rem 1rem;
  font-size: 0.7rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  line-height: 1.4;
}
.server-hint.ok { color: var(--ok); }
.server-hint.warn { color: #ffb366; }

.main { flex: 1; min-width: 0; padding: 1.5rem 2rem 3rem; overflow-y: auto; }

.meta-banner, .contested-intro {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem;
  margin-bottom: 1rem;
  font-size: 0.84rem;
  color: var(--muted);
  line-height: 1.5;
}
.meta-banner-editable {
  padding: 0.75rem 1rem;
  border-color: rgba(201, 162, 39, 0.3);
  background: rgba(201, 162, 39, 0.05);
}
.editable-note-label {
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--gold);
  margin-bottom: 0.4rem;
}
.editable-note-input {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  padding: 0.65rem 0.75rem;
  font-size: 0.84rem;
  line-height: 1.45;
  resize: vertical;
  min-height: 4.5rem;
  font-family: inherit;
}
.editable-note-input:focus {
  outline: none;
  border-color: rgba(201, 162, 39, 0.55);
  box-shadow: 0 0 0 2px rgba(201, 162, 39, 0.15);
}
.editable-note-hint {
  font-size: 0.65rem;
  color: var(--muted);
  margin-top: 0.35rem;
}
.spec-note {
  background: rgba(201, 162, 39, 0.08);
  border: 1px solid rgba(201, 162, 39, 0.25);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.84rem;
  color: #d4c48a;
  line-height: 1.45;
}
.spec-note-editable {
  background: rgba(201, 162, 39, 0.06);
  border-color: rgba(201, 162, 39, 0.35);
}
.spec-note-editable .editable-note-input {
  background: rgba(0, 0, 0, 0.2);
  color: #e8d8b0;
  border-color: rgba(201, 162, 39, 0.25);
}
.contested-intro { background: rgba(201, 162, 39, 0.08); border-color: rgba(201, 162, 39, 0.25); color: #d4c48a; }

.spec-header { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.spec-title-wrap h2 { font-family: Cinzel, serif; font-size: 1.5rem; }
.spec-title-wrap .class-tag { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; }
.badges { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.badge { padding: 0.25rem 0.6rem; border-radius: 6px; font-size: 0.72rem; font-weight: 700; }
.badge-phase { background: rgba(255, 255, 255, 0.06); border: 1px solid var(--border); color: var(--muted); }

.gear-table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  box-shadow: var(--shadow);
}

table { width: 100%; border-collapse: collapse; font-size: 0.86rem; min-width: 720px; }
thead { background: rgba(0, 0, 0, 0.25); }
th {
  text-align: left;
  padding: 0.75rem 1rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
td { padding: 0.65rem 1rem; border-top: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: rgba(255, 255, 255, 0.025); }

.slot-col { color: var(--muted); font-size: 0.8rem; white-space: nowrap; }
.item-col { font-weight: 500; }
.source-col { color: var(--source); font-size: 0.8rem; }
tr.weapon-option { background: rgba(201, 162, 39, 0.04); }
tr.weapon-option .slot-col { color: var(--gold); }

.tag-p4, .tag-p5 { padding: 0.15rem 0.45rem; border-radius: 4px; font-size: 0.68rem; font-weight: 700; }
.tag-p4 { background: rgba(74, 158, 255, 0.15); color: var(--p4); }
.tag-p5 { background: rgba(176, 108, 255, 0.15); color: var(--p5); }

.slot-actions { display: flex; gap: 0.35rem; flex-wrap: wrap; margin-top: 0.35rem; }
.slot-btn {
  padding: 0.2rem 0.45rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 0.68rem;
  cursor: pointer;
}
.slot-btn:hover { border-color: var(--gold-dim); color: var(--gold); }
.slot-btn.danger:hover { border-color: var(--danger); color: var(--danger); }

.alt-block {
  margin-top: 0.35rem;
  padding: 0.45rem 0.55rem;
  border-left: 2px solid var(--border);
  background: rgba(0, 0, 0, 0.15);
  border-radius: 0 6px 6px 0;
}
.alt-block summary {
  cursor: pointer;
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 600;
  list-style: none;
}
.alt-block summary::-webkit-details-marker { display: none; }
.alt-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.35rem 0;
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  font-size: 0.8rem;
}
.alt-row:first-of-type { border-top: none; }

.q1 { color: var(--q1); }
.q2 { color: var(--q2); }
.q3 { color: var(--q3); }
.q4 { color: var(--q4); }
.q5 { color: var(--q5); }

.empty-slot {
  color: var(--muted);
  font-style: italic;
  font-size: 0.8rem;
}

body.view-contested #spec-panels,
body.view-contested #talent-panels { display: none; }
body.view-contested #contested-panel { display: block; }
body.view-contested #meta-note { display: none; }
body.view-contested .contested-intro { display: block; }

body.view-talents #spec-panels,
body.view-talents #contested-panel { display: none; }
body.view-talents #talent-panels { display: block; }
body.view-talents #meta-note { display: none; }
body.view-talents .contested-intro { display: none !important; }

.talent-panel { display: none; }
.talent-panel.active { display: block; }

.talent-calc {
  --wh-gold: #ffd100;
  --wh-green: rgba(64, 191, 64, 0.8);
  --wh-frame: #181818;
  background: var(--wh-frame);
  border: 1px solid #202020;
  border-radius: 6px;
  padding: 6px;
}
.talent-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 6px;
  padding: 4px 10px;
  background: hsl(0, 0%, 4%);
  border-radius: 6px;
  flex-wrap: wrap;
}
.talent-summary-left { display: flex; align-items: baseline; gap: 0.65rem; }
.talent-summary-right { display: flex; align-items: center; gap: 0.5rem; }
.talent-build-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #818181;
}
.talent-build {
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.04em;
}
.talent-remaining {
  font-size: 0.75rem;
  color: #818181;
  font-weight: 600;
}
.talent-reset-btn {
  border: 2px solid #444;
  background: transparent;
  color: #fff;
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 0.68rem;
  font-weight: 700;
  cursor: pointer;
}
.talent-reset-btn:hover { background: #0c0c0c; border-color: #666; }

.talent-trees-wrap {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 0;
  padding: 3px;
  background: #181818;
  overflow-x: auto;
}
.talent-tree-col {
  flex: 0 0 auto;
  width: 240px;
  margin: 0 3px;
  background: #101010;
  border-radius: 6px;
  overflow: hidden;
}
.talent-tree-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 5px 10px;
  color: #bbb;
  background: transparent;
  border-bottom: none;
}
.talent-tree-col[data-with-points] .talent-tree-header {
  color: #fff;
}
.talent-tree-name {
  font-size: 0.95rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.talent-tree-meta {
  font-size: 0.95rem;
  color: inherit;
  font-weight: 700;
  flex-shrink: 0;
}
.talent-tree-body {
  position: relative;
  width: 240px;
  min-height: 540px;
  margin: 0 auto;
}
.talent-tree-bg {
  position: absolute;
  inset: 0;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  filter: brightness(0.45);
  box-shadow: inset 0 0 30px 10px #000;
  pointer-events: none;
  z-index: 0;
}
.talent-tree-body::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--talent-accent, #c9a227) 18%, transparent),
    transparent 35%
  );
  pointer-events: none;
  z-index: 1;
}

.talent-grid {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  padding: 8px 8px 12px;
}
.talent-row {
  display: grid;
  grid-template-columns: repeat(4, 36px);
  column-gap: 24px;
  align-items: start;
  min-height: 60px;
  padding: 0;
  border-bottom: none;
}
.talent-tier { display: none; }

.talent-cell {
  position: relative;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: 5px;
  background: transparent;
  cursor: pointer;
  overflow: visible;
  filter: grayscale(100%);
  box-shadow: none;
}
.talent-cell.empty {
  visibility: hidden;
  pointer-events: none;
}
.talent-icon-wrap {
  display: block;
  width: 36px;
  height: 36px;
  border-radius: 5px;
  overflow: hidden;
  border: 1px solid #333;
}
.talent-cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.talent-cell .talent-rank {
  position: absolute;
  right: -5px;
  bottom: -5px;
  min-width: 1rem;
  padding: 0 3px;
  font-size: 0.68rem;
  font-weight: 700;
  color: #777;
  background: #000;
  border: 1px solid #333;
  border-radius: 3px;
  line-height: 1.2;
  z-index: 1;
}
.talent-cell.available:not(.disabled):hover .talent-icon-wrap {
  border-color: #666;
}
.talent-cell.active {
  filter: none;
}
.talent-cell.active .talent-icon-wrap {
  border: 1px solid var(--wh-green);
}
.talent-cell .talent-rank:empty { display: none; }
.talent-cell.active:not(.maxed) .talent-rank {
  color: #d8ffd8;
  background: #061206;
  border-color: var(--wh-green);
  display: inline-block;
  box-shadow: 0 0 4px rgba(64, 191, 64, 0.35);
}
.talent-cell.maxed .talent-icon-wrap {
  border: 2px solid var(--wh-gold);
  box-shadow: 0 0 10px rgba(255, 209, 0, 0.45);
}
.talent-cell.maxed .talent-rank {
  color: #1a1000;
  background: linear-gradient(180deg, #fff0a0 0%, #ffd100 55%, #e6a800 100%);
  border-color: #ffd100;
  font-weight: 800;
  box-shadow: 0 0 8px rgba(255, 209, 0, 0.65);
  display: inline-block;
}
.talent-cell.disabled:not(.active) { cursor: not-allowed; }
.talent-cell.readonly { cursor: default; }

.talent-tooltip {
  position: fixed;
  z-index: 200;
  max-width: 280px;
  padding: 8px 10px;
  background: linear-gradient(180deg, #0f0c08, #080604);
  border: 1px solid #5a4528;
  border-radius: 4px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.75);
  pointer-events: none;
}
.talent-tooltip-name { color: var(--wh-gold); font-weight: 700; font-size: 0.82rem; margin-bottom: 2px; }
.talent-tooltip-rank { color: #9a8868; font-size: 0.68rem; margin-bottom: 4px; }
.talent-tooltip-desc { color: #e8dcc8; font-size: 0.72rem; line-height: 1.35; }

.talent-hint {
  font-size: 0.68rem;
  color: var(--muted);
  margin-top: 0.5rem;
}
.talent-note-label {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  margin: 0.65rem 0 0.25rem;
}

.talent-note-label,
.talent-url-label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}
.talent-note,
.talent-url {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  padding: 0.65rem 0.75rem;
  font-size: 0.84rem;
  margin-bottom: 0.85rem;
}
.talent-note { min-height: 5rem; resize: vertical; }
.talent-url { margin-bottom: 0; }
.talent-readonly .talent-note,
.talent-readonly .talent-url { pointer-events: none; opacity: 0.92; }
.talent-readonly .talent-tree-controls button { display: none; }

.talent-remaining.ok { color: var(--wh-gold); font-weight: 800; }
.talent-remaining.warn { color: #ffb347; }
.talent-remaining.bad { color: var(--danger); }

.talent-build-complete .talent-summary {
  border: 1px solid rgba(255, 209, 0, 0.35);
  box-shadow: inset 0 0 12px rgba(255, 209, 0, 0.08);
}
.talent-build-complete .talent-build,
.talent-build-complete .talent-build-label,
.talent-build-complete .tree-pts {
  color: var(--wh-gold) !important;
}
.talent-build-complete .talent-tree-col[data-with-points] .talent-tree-header {
  color: var(--wh-gold);
}
.talent-build-complete .talent-remaining.ok {
  text-shadow: 0 0 10px rgba(255, 209, 0, 0.45);
}
.talent-build-over .talent-remaining.bad {
  animation: talent-over-pulse 1.2s ease-in-out infinite;
}
@keyframes talent-over-pulse {
  50% { opacity: 0.65; }
}

.alt-row {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  gap: 0.5rem;
  align-items: start;
  padding: 0.35rem 0;
  border-top: 1px dashed rgba(255, 255, 255, 0.06);
}
.alt-source { font-size: 0.78rem; color: var(--source); }
.alt-row .slot-actions { grid-column: 1 / -1; }

.heat-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
  background: rgba(201, 162, 39, 0.15);
  color: var(--gold);
  border: 1px solid rgba(201, 162, 39, 0.35);
}

.spec-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.spec-chip {
  padding: 0.18rem 0.45rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
}
.spec-chip .role-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin-right: 0.35rem; }

.empty-state { text-align: center; padding: 4rem 2rem; color: var(--muted); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: min(520px, 100%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1rem; color: var(--gold); }
.modal-close {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
}
.modal-body { padding: 1rem 1.1rem 1.1rem; }
.picker-hint { font-size: 0.72rem; color: var(--muted); margin: 0.5rem 0; }
.picker-results { list-style: none; max-height: 320px; overflow-y: auto; margin-top: 0.5rem; }
.picker-results li {
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
}
.picker-results li:hover { background: rgba(201, 162, 39, 0.1); border-color: rgba(201, 162, 39, 0.25); }
.picker-results .sub { font-size: 0.72rem; color: var(--muted); margin-top: 0.15rem; }

.officer-only { display: none !important; }
body.officer-mode .officer-only { display: flex !important; }
body.officer-mode .toolbar.officer-only { display: flex !important; flex-wrap: wrap; }
body.officer-mode #auth-guest { display: none !important; }
body.officer-mode .modal-backdrop.officer-only { display: block; }
body.officer-mode .modal-backdrop.officer-only[hidden] { display: none !important; }

.auth-box {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
}
.auth-label { font-size: 0.68rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.auth-input {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.84rem;
}
.auth-btn { width: 100%; margin-top: 0.15rem; }
.auth-error { font-size: 0.72rem; color: var(--danger); }
#auth-officer {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}
.officer-badge {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

body.edit-mode .slot-btn { display: inline-block; }
body:not(.edit-mode) .slot-actions { display: none; }

.tool-btn.primary {
  background: rgba(62, 207, 142, 0.12);
  border-color: rgba(62, 207, 142, 0.45);
  color: var(--ok);
}
.tool-btn.primary:hover { background: rgba(62, 207, 142, 0.22); }
.tool-btn:disabled { opacity: 0.55; cursor: wait; }

body:not(.officer-mode) .slot-actions,
body:not(.officer-mode) .alt-block summary + .slot-btn { display: none !important; }

@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: relative; max-height: 50vh; }
  .main { padding: 1rem; }
  .talent-trees-wrap { justify-content: flex-start; }
  .alt-row { grid-template-columns: 1fr; }
}
