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

:root {
  --bg: #1e2326;
  --surface: #272e33;
  --surface2: #2e383c;
  --border: #374145;
  --text: #d3c6aa;
  --muted: #7a8478;
  --accent: #7fbbb3;
  --gold: #dbbc7f;
  --gold-dim: #9da86c;
  --green: #a7c080;
  --red: #e67e80;
  --radius: 8px;

  /* Rarity colors */
  --rarity-common: #d3c6aa;
  --rarity-uncommon: #a7c080;
  --rarity-rare: #7fbbb3;
  --rarity-exceptional: #e67e80;
  --rarity-epic: #d699b6;
  --rarity-legendary: #dbbc7f;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  padding: 2rem 1rem;
}

header {
  text-align: center;
  margin-bottom: 2rem;
}

header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.02em;
}


/* Drop zone */
#drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 3rem 2rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  max-width: 560px;
  margin: 0 auto 2rem;
  background: var(--surface);
}

#drop-zone:hover, #drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--surface2);
}

#drop-zone svg {
  display: block;
  margin: 0 auto 1rem;
  color: var(--muted);
}

#drop-zone.drag-over svg { color: var(--accent); }

#drop-zone p {
  color: var(--muted);
  font-size: 0.95rem;
}

#drop-zone p strong { color: var(--text); }

#file-input { display: none; }

.btn {
  display: inline-block;
  margin-top: 1rem;
  padding: 0.5rem 1.25rem;
  background: var(--accent);
  color: #1e2326;
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn:hover { opacity: 0.85; }

/* Output */
#output { display: none; max-width: 960px; margin: 0 auto; }

/* ── Hero Character Header ──────────────────────────────────────────── */
.char-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1.5rem;
}

.char-identity {
  flex: 1;
  min-width: 200px;
}

.char-identity h2 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text);
}

.char-identity-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.35rem;
}

.identity-pill {
  display: inline-block;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 600;
}

.char-top-skills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.6rem;
}

.top-skill-chip {
  display: inline-block;
  background: color-mix(in srgb, var(--gold) 10%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--gold) 25%, transparent);
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  font-size: 0.7rem;
  color: var(--gold);
  font-weight: 600;
}

/* Combat stats */
.char-combat-stats {
  display: flex;
  gap: 1.25rem;
}

.combat-stat {
  text-align: center;
}

.combat-stat-value {
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1.1;
}

.combat-stat-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-top: 0.15rem;
}

/* Total level badge */
.total-level {
  background: linear-gradient(135deg, #2e3538, #272e33);
  border: 2px solid var(--gold-dim);
  border-radius: var(--radius);
  padding: 1rem 1.75rem;
  text-align: center;
  min-width: 160px;
}

.total-level .label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--gold-dim);
}

.total-level .number {
  font-size: 2.75rem;
  font-weight: 800;
  color: var(--gold);
  line-height: 1;
  margin: 0.15rem 0;
}

.total-level .sub {
  font-size: 0.75rem;
  color: var(--muted);
}

/* Stat chips (reused in multiple places) */
.stat-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 1rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.stat-chip strong { color: var(--text); }

/* Controls */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1rem;
}

.controls input[type="text"] {
  flex: 1;
  min-width: 180px;
  padding: 0.45rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.875rem;
}

.controls input[type="text"]::placeholder { color: var(--muted); }
.controls input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}

.controls select {
  padding: 0.45rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.875rem;
  cursor: pointer;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.toggle-label input { cursor: pointer; accent-color: var(--accent); }

/* Skill grid */
#skill-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.5rem;
}

.skill-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  transition: border-color 0.15s;
}

.skill-card:hover { border-color: var(--accent); }

.skill-level {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--gold);
  min-width: 2.5rem;
  text-align: right;
  flex-shrink: 0;
  padding-top: 0.1rem;
}

.skill-info { flex: 1; min-width: 0; }

.skill-name {
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

.skill-bonus {
  font-size: 0.7rem;
  color: var(--green);
}

.skill-xp-bar {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 4px;
  overflow: hidden;
}

.skill-xp-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s ease;
}

/* Skill abilities */
.skill-abilities-toggle {
  font-size: 0.65rem;
  color: var(--muted);
  cursor: pointer;
  margin-top: 0.3rem;
  user-select: none;
  transition: color 0.15s;
}

.skill-abilities-toggle::before {
  content: '\25B6 ';
  font-size: 0.5rem;
  display: inline-block;
  transition: transform 0.15s;
}

.skill-abilities-toggle.open::before {
  transform: rotate(90deg);
}

.skill-abilities-toggle:hover {
  color: var(--accent);
}

.skill-abilities {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem;
  margin-top: 0.3rem;
}

.ability-chip {
  display: inline-block;
  font-size: 0.6rem;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
}

/* Share button (in character header) */
.char-identity-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

#share-btn {
  display: none;
  background: none;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 0.25rem 0.75rem;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

#share-btn:hover {
  background: var(--accent);
  color: var(--bg);
}

/* Reset button */
#reset-btn {
  display: block;
  text-align: center;
  margin-top: 1.5rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  padding: 0.45rem 1rem;
  font-size: 0.8rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

#reset-btn:hover { border-color: var(--red); color: var(--red); }

/* Share banner */
#share-banner {
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.875rem;
  color: var(--text);
}

#share-banner strong { color: var(--accent); }

.share-banner-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  transition: opacity 0.15s;
}

.share-banner-link:hover { opacity: 0.75; }

/* Toast */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(0.5rem);
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 0.5rem 1.25rem;
  font-size: 0.825rem;
  font-weight: 600;
  color: var(--accent);
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 1000;
  pointer-events: none;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.error-msg {
  background: #3a2e2e;
  border: 1px solid var(--red);
  border-radius: var(--radius);
  color: var(--red);
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  max-width: 560px;
  margin: 0 auto 1rem;
  display: none;
}

/* Section titles */
.section-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 0.85rem;
}

/* ── Tabs ──────────────────────────────────────────────────────────────── */
.tabs-container {
  margin-bottom: 1.5rem;
}

.tabs-nav {
  display: flex;
  gap: 0.25rem;
  border-bottom: 2px solid var(--border);
  margin-bottom: 1.5rem;
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs-nav::-webkit-scrollbar { display: none; }

.tab-button {
  background: none;
  border: none;
  color: var(--muted);
  padding: 0.75rem 1rem;
  font-size: 0.825rem;
  font-weight: 600;
  cursor: pointer;
  position: relative;
  transition: color 0.2s;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
}

.tab-button:hover {
  color: var(--text);
}

.tab-button.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* ── Tab Upload Prompts ───────────────────────────────────────────────── */
.tab-upload-prompt {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  margin-bottom: 1rem;
  background: var(--surface);
}

.tab-upload-prompt:hover,
.tab-upload-prompt.drag-over {
  border-color: var(--accent);
  background: var(--surface2);
}

.tab-upload-prompt p {
  color: var(--muted);
  font-size: 0.875rem;
}

.tab-upload-prompt p strong {
  color: var(--text);
}

/* ── NPC Favor ─────────────────────────────────────────────────────────── */
.favor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.5rem;
}

.favor-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  transition: border-color 0.15s;
}

.favor-card:hover { border-color: var(--accent); }

.favor-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.favor-info { flex: 1; min-width: 0; }

.favor-npc-name {
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

.favor-level-text {
  font-size: 0.7rem;
  color: var(--muted);
}

/* NPC Favor Summary Chips */
#favor-summary-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.favor-summary-chip {
  display: inline-block;
  border: 1px solid;
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--surface);
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.favor-summary-chip:hover {
  background: var(--surface2);
}

.favor-summary-chip.active {
  background: color-mix(in srgb, currentColor 15%, var(--surface));
}

/* ── Active Favors ─────────────────────────────────────────────────────── */
.favors-header {
  margin-bottom: 0.75rem;
}

.favors-count-chip {
  display: inline-block;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 600;
}

.favors-search {
  width: 100%;
  max-width: 320px;
  padding: 0.45rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.875rem;
  margin-bottom: 0.75rem;
}

.favors-search::placeholder { color: var(--muted); }
.favors-search:focus {
  outline: none;
  border-color: var(--accent);
}

.favors-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.4rem;
}

.favor-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  color: var(--text);
  transition: border-color 0.15s;
}

.favor-item:hover { border-color: var(--accent); }

/* ── Currencies ────────────────────────────────────────────────────────── */
.currency-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.5rem;
}

.currency-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  text-align: center;
  transition: border-color 0.15s;
}

.currency-card:hover { border-color: var(--accent); }

.currency-card.currency-gold {
  border-color: var(--gold-dim);
  background: color-mix(in srgb, var(--gold) 5%, var(--surface));
}

.currency-card.currency-gold .currency-value {
  color: var(--gold);
  font-size: 1.5rem;
}

.currency-value {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
}

.currency-label {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

/* ── Crafting ──────────────────────────────────────────────────────────── */
.craft-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.craft-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(172px, 1fr));
  gap: 0.5rem;
}

.craft-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
}

.craft-card-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.3rem;
}

.craft-card-stats {
  font-size: 0.72rem;
  color: var(--muted);
  display: flex;
  gap: 0.75rem;
}

.craft-card-stats strong {
  color: var(--text);
}

.craft-bar {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 0.45rem;
  overflow: hidden;
}

.craft-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
}

/* Empty message styling */
.empty-message {
  color: var(--muted);
  font-size: 0.875rem;
}

/* ── Storage / Items ──────────────────────────────────────────────────── */
.storage-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.storage-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1rem;
}

.storage-controls input[type="text"] {
  flex: 1;
  min-width: 180px;
  padding: 0.45rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.875rem;
}

.storage-controls input[type="text"]::placeholder { color: var(--muted); }
.storage-controls input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}

.storage-controls select {
  padding: 0.45rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.875rem;
  cursor: pointer;
}

/* Vault sections */
.vault-section {
  margin-bottom: 1.25rem;
}

.vault-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  user-select: none;
  transition: border-color 0.15s;
  margin-bottom: 0.5rem;
}

.vault-header:hover { border-color: var(--accent); }

.vault-chevron {
  font-size: 0.7rem;
  color: var(--muted);
  transition: transform 0.2s;
  flex-shrink: 0;
}

.vault-header.collapsed .vault-chevron {
  transform: rotate(-90deg);
}

.vault-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  flex: 1;
}

.vault-count {
  font-size: 0.72rem;
  color: var(--muted);
}

.vault-items {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.5rem;
}

.vault-items.hidden {
  display: none;
}

/* Item cards */
.item-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
  transition: border-color 0.15s;
}

.item-card:hover { border-color: var(--accent); }

.item-card-header {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.rarity-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 0.25rem;
}

.item-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  min-width: 0;
  word-break: break-word;
}

.item-stack {
  font-size: 0.72rem;
  color: var(--muted);
  flex-shrink: 0;
  font-weight: 600;
}

.item-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.35rem;
}

.item-badge {
  display: inline-block;
  font-size: 0.65rem;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
}

.item-badge.slot-badge {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
}

.item-badge.level-badge {
  color: var(--gold);
  border-color: var(--gold-dim);
}

.item-badge.value-badge {
  color: var(--gold);
}

.item-badge.attuned-badge {
  color: var(--green);
  border-color: color-mix(in srgb, var(--green) 30%, transparent);
}

.item-badge.transmute-badge {
  color: var(--accent);
}

/* TSysPowers chips */
.item-powers {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.35rem;
}

.power-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.62rem;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 20%, transparent);
  color: var(--text);
}

.power-tier {
  color: var(--accent);
  font-weight: 700;
}

/* Durability bar */
.durability-bar {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 0.4rem;
  overflow: hidden;
}

.durability-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s ease;
}

.durability-fill.high { background: var(--green); }
.durability-fill.medium { background: var(--gold); }
.durability-fill.low { background: var(--red); }

.durability-label {
  font-size: 0.62rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .char-header {
    flex-direction: column;
    align-items: stretch;
  }
  .char-combat-stats {
    justify-content: center;
  }
  .total-level {
    align-self: center;
  }
  .vault-items { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
}

@media (max-width: 480px) {
  #skill-grid { grid-template-columns: 1fr 1fr; }
  .vault-items { grid-template-columns: 1fr; }
  .currency-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  .favors-list { grid-template-columns: 1fr; }
  .tabs-nav { gap: 0; }
  .tab-button { padding: 0.6rem 0.6rem; font-size: 0.75rem; }
}
