/* Stolen Realm Companion — Dark Fantasy Theme */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #0e1420;
  --panel:       #141e2e;
  --panel2:      #192338;
  --gold:        #c8a84b;
  --gold-dim:    #8a7030;
  --teal:        #5bc8c0;
  --teal-dim:    #3a8a84;
  --text:        #e0d8c8;
  --text-dim:    #9a9080;
  --danger:      #cc4444;
  --border:      #2a3548;
  --border-gold: #5a4820;
  --row-alt:     #1a2840;
  --selected:    rgba(200, 168, 75, 0.15);
  --shadow:      0 4px 24px rgba(0,0,0,0.7);
}

html { scroll-behavior: smooth; }

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--teal); text-decoration: none; }
a:hover { color: var(--gold); text-decoration: underline; }

/* ─── NAV ─── */
nav {
  background: var(--panel);
  border-bottom: 2px solid var(--border-gold);
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}

nav .nav-logo {
  display: flex;
  align-items: center;
  padding: 0.5rem 0;
}

nav .nav-logo img {
  height: 44px;
  width: auto;
}

nav .nav-links {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
  padding: 0.5rem 0;
}

nav .nav-links a {
  color: var(--text-dim);
  padding: 0.4rem 0.85rem;
  border-radius: 4px;
  font-size: 0.9rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  transition: background 0.15s, color 0.15s;
  border: 1px solid transparent;
}

nav .nav-links a:hover {
  color: var(--gold);
  background: rgba(200,168,75,0.08);
  border-color: var(--border-gold);
  text-decoration: none;
}

nav .nav-links a.active {
  color: var(--gold);
  background: rgba(200,168,75,0.12);
  border-color: var(--gold-dim);
}

/* ─── PAGE LAYOUT ─── */
.page-container {
  max-width: 1300px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

/* ─── HEADINGS ─── */
h1 {
  font-size: 2.2rem;
  color: var(--gold);
  text-shadow: 0 0 20px rgba(200,168,75,0.3);
  margin-bottom: 0.4rem;
  letter-spacing: 0.04em;
}

h2 {
  font-size: 1.5rem;
  color: var(--gold);
  margin: 2rem 0 1rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border-gold);
}

h3 {
  font-size: 1.15rem;
  color: var(--teal);
  margin: 1.2rem 0 0.6rem;
}

h4 { color: var(--text); margin: 0.8rem 0 0.4rem; font-size: 1rem; }

/* ─── PAGE HEADER ─── */
.page-header {
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.page-header p {
  color: var(--text-dim);
  font-size: 1.05rem;
}

/* ─── TABLES ─── */
.table-wrap {
  overflow-x: auto;
  border-radius: 6px;
  border: 1px solid var(--border);
  margin-bottom: 1.5rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

thead th {
  background: var(--panel2);
  color: var(--gold);
  padding: 0.7rem 0.9rem;
  text-align: left;
  font-weight: 600;
  letter-spacing: 0.04em;
  border-bottom: 2px solid var(--border-gold);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}

tbody tr:nth-child(even) { background: var(--row-alt); }
tbody tr:hover { background: rgba(91,200,192,0.06); }
tbody tr.hidden { display: none; }

tbody td {
  padding: 0.55rem 0.9rem;
  vertical-align: middle;
}

/* ─── ICON CELLS ─── */
.icon-cell { width: 44px; text-align: center; }
.icon-cell img, .item-icon {
  width: 36px;
  height: 36px;
  object-fit: contain;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--panel2);
}

/* ─── BADGES ─── */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  font-size: 0.73rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1.4;
}

.badge-common    { background: #2e3a28; color: #8dc870; border: 1px solid #4a6040; }
.badge-uncommon  { background: #1a3050; color: #60a0e0; border: 1px solid #2a5080; }
.badge-rare      { background: #1a2060; color: #8888ff; border: 1px solid #3040a0; }
.badge-epic      { background: #302040; color: #cc88ff; border: 1px solid #6040a0; }
.badge-legendary { background: #3a2010; color: var(--gold); border: 1px solid var(--border-gold); }
.badge-unused    { background: #3a1010; color: var(--danger); border: 1px solid #6a2020; }
.badge-passive   { background: #1a2830; color: var(--teal-dim); border: 1px solid #2a4858; }
.badge-active    { background: #201830; color: #9966cc; border: 1px solid #4a3060; }
.badge-tag       { background: var(--panel2); color: var(--text-dim); border: 1px solid var(--border); font-size: 0.7rem; }
.badge-fortune   { background: rgba(200,168,75,0.15); color: var(--gold); border: 1px solid var(--border-gold); }

/* ─── FILTERS ─── */
.filters {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 1.25rem;
  padding: 1rem 1.25rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.filters label {
  font-size: 0.82rem;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.filters input[type="text"],
.filters select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.4rem 0.7rem;
  font-size: 0.88rem;
  font-family: inherit;
  min-width: 160px;
  outline: none;
  transition: border-color 0.15s;
}

.filters input[type="text"]:focus,
.filters select:focus {
  border-color: var(--teal);
}

.filters select option { background: var(--panel); }

/* ─── CARDS (homepage) ─── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1.25rem;
  margin: 2rem 0;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border-gold);
  border-radius: 8px;
  padding: 1.5rem 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.6rem;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
  cursor: pointer;
}

.card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 32px rgba(200,168,75,0.15);
  border-color: var(--gold);
  text-decoration: none;
}

.card-icon { font-size: 2.4rem; }
.card-title { font-size: 1.1rem; color: var(--gold); font-weight: 700; }
.card-count { font-size: 0.85rem; color: var(--text-dim); }
.card-desc  { font-size: 0.83rem; color: var(--text-dim); }

/* ─── HERO (homepage) ─── */
.hero {
  display: flex;
  align-items: center;
  gap: 2rem;
  padding: 2.5rem 0 1rem;
  margin-bottom: 2rem;
}

.hero-logo img { max-width: 320px; filter: drop-shadow(0 4px 20px rgba(200,168,75,0.3)); }
.hero-text h1 { font-size: 2.5rem; }
.hero-text p  { color: var(--text-dim); max-width: 560px; margin-top: 0.75rem; font-size: 1.05rem; }

/* ─── QUICK STATS ─── */
.quick-stats {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-bottom: 2rem;
  padding: 1rem 1.5rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
}

.stat-num  { font-size: 1.8rem; font-weight: 700; color: var(--gold); line-height: 1; }
.stat-label{ font-size: 0.8rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.08em; }

/* ─── LEGEND ─── */
.legend {
  margin-top: 2rem;
  padding: 1.25rem 1.5rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.86rem;
}

.legend h3 { margin-top: 0; }
.legend dl { display: grid; grid-template-columns: max-content 1fr; gap: 0.35rem 1.25rem; margin-top: 0.75rem; }
.legend dt { color: var(--gold); font-weight: 600; }
.legend dd { color: var(--text-dim); }

/* ─── FACTION TAGS ─── */
.pill-list { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.pill {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 0.8rem;
  color: var(--text-dim);
}

/* ─── FACTION SECTION ─── */
.faction-section { margin-bottom: 0.75rem; padding: 0.75rem 1rem; background: var(--panel); border-radius: 6px; border: 1px solid var(--border); }
.faction-name { font-size: 0.95rem; font-weight: 700; color: var(--teal); margin-bottom: 0.4rem; }

/* ─── FORMULAS ─── */
.formula-content { max-width: 900px; }
.formula-content pre {
  background: #0a1020;
  border: 1px solid var(--border);
  border-left: 3px solid var(--teal);
  border-radius: 4px;
  padding: 0.9rem 1.2rem;
  overflow-x: auto;
  font-family: 'Courier New', monospace;
  font-size: 0.85rem;
  color: #c0e8d0;
  margin: 0.75rem 0;
}

.formula-content code {
  background: #0a1020;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.1rem 0.35rem;
  font-family: 'Courier New', monospace;
  font-size: 0.85rem;
  color: var(--teal);
}

.formula-content p { margin-bottom: 0.8rem; }
.formula-content ul, .formula-content ol { margin: 0.5rem 0 0.8rem 1.5rem; }
.formula-content li { margin-bottom: 0.3rem; }
.formula-content strong { color: var(--gold); }
.formula-content em { color: var(--text-dim); font-style: italic; }

.formula-table-wrap {
  overflow-x: auto;
  margin: 0.75rem 0 1.25rem;
  border-radius: 6px;
  border: 1px solid var(--border);
}

/* ─── FORTUNE QUOTE ─── */
.fortune-effect { margin-bottom: 0.3rem; }
.fortune-quote {
  font-size: 0.8rem;
  color: var(--text-dim);
  font-style: italic;
  border-left: 2px solid var(--border-gold);
  padding-left: 0.6rem;
  margin-top: 0.3rem;
}

/* ─── ENEMIES TOC ─── */
.page-toc {
  margin-top: 0.75rem;
  font-size: 0.9rem;
  color: var(--text-dim);
}
.page-toc a { color: var(--teal); }

/* ─── BUILDER ─── */
.builder-layout {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.builder-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: var(--panel);
  border: 1px solid var(--border-gold);
  border-radius: 6px;
}

.points-display {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.04em;
}

.points-display span { color: var(--text-dim); font-size: 1rem; }

.builder-controls {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
}

.btn {
  padding: 0.45rem 1rem;
  border-radius: 5px;
  border: 1px solid var(--border-gold);
  background: var(--panel2);
  color: var(--gold);
  font-size: 0.88rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  font-weight: 600;
}

.btn:hover { background: rgba(200,168,75,0.12); border-color: var(--gold); }
.btn-teal  { border-color: var(--teal-dim); color: var(--teal); }
.btn-teal:hover { background: rgba(91,200,192,0.1); border-color: var(--teal); }
.btn-danger { border-color: #6a2020; color: var(--danger); }
.btn-danger:hover { background: rgba(204,68,68,0.1); border-color: var(--danger); }

.builder-search-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
  padding: 0.75rem 1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.builder-search-row input[type="text"] {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.4rem 0.7rem;
  font-size: 0.88rem;
  font-family: inherit;
  width: 220px;
  outline: none;
}

.builder-search-row input[type="text"]:focus { border-color: var(--teal); }

.tag-filters { display: flex; gap: 0.35rem; flex-wrap: wrap; }

.tag-btn {
  padding: 0.2rem 0.6rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--text-dim);
  font-size: 0.75rem;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}

.tag-btn:hover { border-color: var(--teal-dim); color: var(--teal); }
.tag-btn.active { background: rgba(91,200,192,0.15); border-color: var(--teal); color: var(--teal); }

/* tree tabs */
.tree-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.75rem 1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.tree-tab {
  padding: 0.35rem 0.85rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--text-dim);
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  transition: all 0.15s;
}

.tree-tab:hover { border-color: var(--gold-dim); color: var(--gold); }
.tree-tab.active { background: rgba(200,168,75,0.12); border-color: var(--gold); color: var(--gold); }
.tree-tab .tree-count { font-size: 0.7rem; color: var(--text-dim); margin-left: 0.35rem; }

/* ─── POINTS BAR ─── */
.points-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 0.4rem;
  width: 160px;
  overflow: hidden;
}
.points-bar-fill {
  height: 100%;
  background: var(--gold);
  border-radius: 2px;
  transition: width 0.2s;
}

/* tree panel */
.tree-panel { display: none; }
.tree-panel.active { display: block; }

/* ─── TREE PANEL GRID (tier-row layout) ─── */
.tree-panel-grid {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.tree-col-header-row {
  display: grid;
  grid-template-columns: 72px 1fr 1fr;
  background: var(--panel2);
  border-bottom: 2px solid var(--border-gold);
}

.tree-col-label-cell {
  padding: 0.5rem 0.75rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold-dim);
  text-align: center;
  border-right: 1px solid var(--border);
}
.tree-col-label-cell:last-child { border-right: none; }

.tier-row {
  display: grid;
  grid-template-columns: 72px 1fr 1fr;
  border-bottom: 1px solid var(--border);
  min-height: 80px;
  transition: opacity 0.2s;
}
.tier-row:last-child { border-bottom: none; }

.tier-row.tier-locked {
  opacity: 0.45;
  pointer-events: none;
}

.tier-row-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 0.4rem;
  background: var(--panel2);
  border-right: 1px solid var(--border);
  gap: 0.2rem;
}
.tier-row-num {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--gold-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.tier-req {
  font-size: 0.62rem;
  color: var(--text-dim);
  text-align: center;
}

.tier-skill-col {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
  border-right: 1px solid var(--border);
  align-content: flex-start;
}
.tier-skill-col:last-child { border-right: none; }

/* skill card */
.skill-card {
  background: var(--panel2);
  border: 2px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.7rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
  position: relative;
  user-select: none;
}

.skill-card:hover { border-color: var(--teal-dim); background: rgba(91,200,192,0.05); }
.skill-card.selected { border-color: var(--gold); background: var(--selected); box-shadow: 0 0 12px rgba(200,168,75,0.2); }
.skill-card.disabled-skill { opacity: 0.45; cursor: not-allowed; }
.skill-card.dep-missing { border-color: var(--danger); }
.skill-card.search-highlight { box-shadow: 0 0 0 2px var(--teal); }
.skill-card.search-dim { opacity: 0.3; }

.skill-card-inner { display: flex; align-items: center; gap: 0.6rem; }

.skill-icon {
  width: 40px; height: 40px;
  object-fit: contain;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

.skill-info { min-width: 0; flex: 1; }
.skill-name { font-size: 0.82rem; font-weight: 700; color: var(--text); line-height: 1.2; }
.skill-badges { display: flex; gap: 0.25rem; flex-wrap: wrap; margin-top: 0.25rem; }

.dep-arrow {
  position: absolute;
  top: -2px; left: -2px;
  width: 10px; height: 10px;
  border-left: 2px solid var(--danger);
  border-top: 2px solid var(--danger);
  border-radius: 2px 0 0 0;
}

/* tooltip */
.skill-tooltip {
  position: fixed;
  background: var(--panel);
  border: 2px solid var(--gold);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  max-width: 340px;
  z-index: 9999;
  box-shadow: 0 8px 32px rgba(0,0,0,0.8);
  pointer-events: none;
  display: none;
}

.skill-tooltip.visible { display: block; }

.tooltip-name { font-size: 1.05rem; font-weight: 700; color: var(--gold); margin-bottom: 0.3rem; }
.tooltip-meta { font-size: 0.78rem; color: var(--text-dim); margin-bottom: 0.6rem; display: flex; flex-wrap: wrap; gap: 0.35rem; }
.tooltip-desc { font-size: 0.85rem; color: var(--text); line-height: 1.55; }

/* skill detail panel */
.skill-detail-panel {
  background: var(--panel);
  border: 1px solid var(--border-gold);
  border-radius: 6px;
  padding: 1.25rem;
  min-height: 120px;
}

.sdp-name  { font-size: 1.15rem; font-weight: 700; color: var(--gold); }
.sdp-meta  { font-size: 0.82rem; color: var(--text-dim); margin: 0.35rem 0 0.5rem; display: flex; flex-wrap: wrap; gap: 0.5rem; }
.sdp-dep   { font-size: 0.8rem; margin-bottom: 0.5rem; }
.sdp-dep.dep-warn { color: var(--danger); }
.sdp-dep.dep-ok   { color: var(--teal); }
.sdp-desc  { font-size: 0.9rem; color: var(--text); }
.sdp-empty { color: var(--text-dim); font-style: italic; }

/* ─── BOSS SKILL TABLE ─── */
.boss-section { margin-bottom: 2rem; }
.boss-section h3 { color: var(--gold); }

/* ─── RESPONSIVE ─── */
@media (max-width: 768px) {
  .hero { flex-direction: column; }
  .hero-logo img { max-width: 220px; }
  .tree-col-header-row,
  .tier-row { grid-template-columns: 52px 1fr 1fr; }
  .tier-row-label { padding: 0.3rem 0.2rem; }
  .skill-card { padding: 0.4rem; }
  h1 { font-size: 1.6rem; }
}

/* ─── COPY CONFIRM ─── */
.copy-confirm {
  font-size: 0.8rem;
  color: var(--teal);
  display: none;
}

.copy-confirm.visible { display: inline; }

/* ─── SEARCH COUNT ─── */
.search-count {
  font-size: 0.82rem;
  color: var(--text-dim);
  margin-left: auto;
}

/* ─── SECTION DIVIDER ─── */
.section-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

/* ─── TRUNCATED TEXT ─── */
.trunc {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
}

/* ─── GENERIC SKILL LIST ─── */
.generic-skill-list {
  columns: 3;
  column-gap: 1rem;
  font-size: 0.86rem;
  color: var(--text-dim);
  list-style: disc inside;
  margin: 0.5rem 0;
}

.generic-skill-list li { margin-bottom: 0.25rem; }

@media (max-width: 900px) { .generic-skill-list { columns: 2; } }
@media (max-width: 540px) { .generic-skill-list { columns: 1; } }
