:root {
  --bg: #0d0b09;
  --bg-2: #17130f;
  --panel: #1e1913;
  --panel-2: #262017;
  --border: #4a3c26;
  --gold: #f8d26b;
  --gold-dim: #b8954a;
  --text: #ece3cf;
  --muted: #9c8f78;
  --horde: #b1271c;
  --alliance: #1f4fa0;
  --xp: #8e3fd6;
  --xp-2: #c27cff;
  --prof: #3f9b3a;
  --danger: #d9534f;
  --ok: #5cb85c;
  --radius: 14px;
  --font-display: 'Cinzel', 'Georgia', serif;
  --font-body: 'Inter', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { color-scheme: dark; }

[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(ellipse at top, rgba(120, 220, 80, 0.10), transparent 55%),
    radial-gradient(ellipse at bottom right, rgba(140, 40, 200, 0.12), transparent 50%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.45;
}

a { color: var(--gold); }

img { display: block; }

.muted { color: var(--muted); }
.small-text { font-size: 0.85rem; margin: 0.25rem 0 0; }

/* ---------- Hero ---------- */

.hero {
  text-align: center;
  padding: 3.5rem 1rem 2rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(40, 90, 30, 0.25), transparent);
}

.eyebrow {
  margin: 0;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  font-size: 0.75rem;
  color: #9bdc62;
}

.hero h1 {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2.2rem, 6vw, 4rem);
  margin: 0.4rem 0 0.2rem;
  color: var(--gold);
  text-shadow: 0 0 24px rgba(248, 210, 107, 0.35), 0 3px 0 #5a3d0e;
}

.tagline { margin: 0 0 1.75rem; color: var(--muted); font-style: italic; }

.stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
  max-width: 1000px;
  margin: 0 auto;
}

.stat {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.9rem 0.55rem 0.55rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.stat img { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--gold-dim); }
.stat strong { display: block; font-family: var(--font-display); color: var(--gold); font-size: 1.15rem; line-height: 1.1; }
.stat span { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }

/* ---------- Layout ---------- */

.container { width: 100%; max-width: 1280px; margin: 0 auto; padding: 1.5rem 1rem 3rem; flex: 1; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.chip {
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  transition: border-color 0.15s, background 0.15s;
}
.chip:hover { border-color: var(--gold-dim); }
.chip.active { background: var(--gold); border-color: var(--gold); color: #2a1c05; font-weight: 600; }

.sort { display: flex; align-items: center; gap: 0.5rem; color: var(--muted); font-size: 0.9rem; margin-left: auto; }

select, input, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.65rem;
}
select:focus, input:focus, textarea:focus { outline: 2px solid var(--gold-dim); outline-offset: 1px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
  gap: 1.25rem;
}

.empty { text-align: center; color: var(--muted); padding: 3rem 1rem; }
.empty img { margin: 0 auto 1rem; width: 64px; height: 64px; border-radius: 10px; border: 1px solid var(--border); }

/* ---------- Character card ---------- */

.card {
  --faction: var(--border);
  position: relative;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--border);
  border-top: 3px solid var(--faction);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.card:hover { transform: translateY(-3px); box-shadow: 0 16px 36px rgba(0, 0, 0, 0.5), 0 0 0 1px var(--class-color); }
.card.faction-horde { --faction: var(--horde); }
.card.faction-alliance { --faction: var(--alliance); }

.card-banner {
  height: 86px;
  background:
    linear-gradient(180deg, transparent 30%, var(--panel-2)),
    radial-gradient(circle at 20% 0%, color-mix(in srgb, var(--class-color) 40%, transparent), transparent 70%),
    var(--bg-2);
  background-size: cover;
  background-position: center 25%;
  position: relative;
}
.card-banner[style*='background-image'] { filter: saturate(1.1); }
.card-banner::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 20%, var(--panel-2));
}

.faction-crest {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  z-index: 1;
}

.card-head { display: flex; gap: 0.9rem; align-items: flex-end; padding: 0 1rem; margin-top: -44px; position: relative; z-index: 1; }

.portrait { position: relative; flex: none; }
.portrait img {
  width: 84px;
  height: 84px;
  object-fit: cover;
  border-radius: 50%;
  border: 3px solid var(--class-color);
  background: var(--bg);
  box-shadow: 0 0 0 3px #000, 0 0 18px color-mix(in srgb, var(--class-color) 45%, transparent);
}

.level-badge {
  position: absolute;
  bottom: -4px;
  left: -4px;
  min-width: 30px;
  height: 30px;
  padding: 0 6px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #1a1208;
  border: 2px solid var(--gold-dim);
  color: var(--gold);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.9rem;
}
.level-badge.max { background: var(--gold); color: #2a1c05; border-color: #fff3c4; box-shadow: 0 0 12px rgba(248, 210, 107, 0.7); }

.identity { min-width: 0; padding-bottom: 0.2rem; }
.name {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.45rem;
  color: var(--class-color);
  text-shadow: 0 2px 0 #000;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.subtitle { margin: 0.1rem 0 0; display: flex; align-items: center; gap: 0.4rem; font-size: 0.92rem; }
.subtitle img { width: 18px; height: 18px; border-radius: 4px; }
.guild { margin: 0.1rem 0 0; color: #7fd36b; font-size: 0.85rem; }

.xp { padding: 0.9rem 1rem 0.2rem; }
.xp-label { display: block; margin-top: 0.3rem; font-size: 0.78rem; color: var(--muted); text-align: right; }

.bar { height: 10px; border-radius: 999px; background: #0a0806; border: 1px solid #3a2f1d; overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: inherit; }
.xp-bar > span {
  background: linear-gradient(90deg, var(--xp), var(--xp-2));
}
.xp-bar.maxed > span { background: linear-gradient(90deg, #d39b2a, var(--gold), #fff1b8); }
.bar.small { height: 6px; }
.bar.small > span { background: linear-gradient(90deg, #2c7a2a, #6ad15a); }

.meta { display: grid; gap: 0.5rem; padding: 0.75rem 1rem 0.25rem; }
.meta-row { display: flex; gap: 0.6rem; align-items: center; font-size: 0.9rem; }
.meta-row img { width: 26px; height: 26px; border-radius: 5px; border: 1px solid var(--border); flex: none; }
.meta-label { display: block; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 0.9rem 1rem 0.4rem;
  font-family: var(--font-display);
  font-size: 0.8rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--gold-dim);
}
.card > .small-text { padding: 0 1rem; margin-bottom: 1rem; }

.link-btn {
  font: inherit;
  font-family: var(--font-body);
  font-size: 0.78rem;
  letter-spacing: normal;
  text-transform: none;
  color: var(--gold);
  background: none;
  border: 0;
  padding: 0.1rem 0.2rem;
  cursor: pointer;
  opacity: 0.75;
}
.link-btn:hover, .link-btn:focus-visible { opacity: 1; text-decoration: underline; }

.meta-row > div:not(.death-controls) { flex: 1; min-width: 0; }
.death-controls { display: flex; gap: 0.3rem; flex: none; }
.death-controls .btn { padding: 0.2rem 0.5rem; min-width: 2.1rem; }

.death-count { display: inline-block; }
.death-count.bump { animation: bump 0.5s ease; color: #ff9c99; }
@media (prefers-reduced-motion: reduce) {
  .death-count.bump { animation: none; }
}
@keyframes bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.35) rotate(-6deg); }
  100% { transform: scale(1); }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  max-width: calc(100vw - 2rem);
  padding: 0.7rem 1.1rem;
  border-radius: 10px;
  background: #3a1513;
  border: 1px solid var(--danger);
  color: #ffd2cf;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  z-index: 10;
}

.professions { list-style: none; margin: 0 0 1rem; padding: 0 1rem; display: grid; gap: 0.5rem; }
.profession { display: flex; gap: 0.6rem; align-items: center; }
.profession img { width: 28px; height: 28px; border-radius: 5px; border: 1px solid var(--border); flex: none; }
.profession-body { flex: 1; min-width: 0; }
.profession-head { display: flex; justify-content: space-between; font-size: 0.88rem; margin-bottom: 0.2rem; }

.card-foot {
  margin: auto 0 0;
  padding: 0.85rem 1rem;
  border-top: 1px solid rgba(74, 60, 38, 0.6);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.card-foot strong { color: var(--text); }
.note { font-style: italic; }

/* ---------- Footer ---------- */

.footer {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}

/* ---------- Admin ---------- */

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
}
.admin-header h1 { margin: 0; font-family: var(--font-display); color: var(--gold); font-size: 1.4rem; }
.admin-header nav { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

.btn {
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  border-radius: 8px;
  padding: 0.5rem 0.95rem;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}
.btn:hover { border-color: var(--gold-dim); }
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn.primary { background: linear-gradient(180deg, #a3171a, #6e0b0d); border-color: #d7a536; color: #ffe9a8; font-weight: 600; }
.btn.danger { color: #ff9c99; }
.btn.small { padding: 0.3rem 0.6rem; font-size: 0.82rem; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; }

.login { max-width: 380px; margin: 4rem auto; text-align: center; }
.login img { margin: 0 auto 0.75rem; width: 56px; height: 56px; border-radius: 10px; border: 1px solid var(--gold-dim); }
.login h2 { font-family: var(--font-display); color: var(--gold); margin: 0 0 1rem; }
.login form { display: grid; gap: 0.75rem; }

.notice { padding: 0.75rem 1rem; border-radius: 10px; border: 1px solid; margin-bottom: 1rem; font-size: 0.9rem; }
.notice.warn { border-color: #8a6d1f; background: rgba(138, 109, 31, 0.15); }
.notice.error { border-color: var(--danger); background: rgba(217, 83, 79, 0.12); color: #ffb3b0; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.65rem 0.6rem; border-bottom: 1px solid rgba(74, 60, 38, 0.6); vertical-align: middle; }
th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; }
td .actions { display: flex; gap: 0.4rem; justify-content: flex-end; flex-wrap: wrap; }
.char-cell { display: flex; align-items: center; gap: 0.6rem; }
.char-cell img { width: 32px; height: 32px; border-radius: 6px; border: 1px solid var(--border); }
.status { font-size: 0.8rem; }
.deaths { display: flex; align-items: center; gap: 0.5rem; }
.deaths span { min-width: 2ch; text-align: center; font-weight: 600; }
.status.ok { color: var(--ok); }
.status.bad { color: #ff9c99; }

dialog {
  width: min(560px, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  padding: 0;
  border: 1px solid var(--gold-dim);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.7); }
dialog form { padding: 1.25rem; display: grid; gap: 0.9rem; }
dialog h2 { margin: 0; font-family: var(--font-display); color: var(--gold); }

.field { display: grid; gap: 0.3rem; font-size: 0.88rem; }
.field > span { color: var(--muted); }
.field small { color: var(--muted); font-size: 0.78rem; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }

.prof-row { display: grid; grid-template-columns: 1fr 80px 80px auto; gap: 0.4rem; align-items: center; margin-bottom: 0.4rem; }
.prof-row input { min-width: 0; }

.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; }

@media (max-width: 560px) {
  .row { grid-template-columns: 1fr; }
  .prof-row { grid-template-columns: 1fr 64px 64px auto; }
  .sort { margin-left: 0; }
}

/* ---------- Character sheet (Arsenal) ---------- */

:root {
  --q-poor: #9d9d9d;
  --q-common: #ffffff;
  --q-uncommon: #1eff00;
  --q-rare: #0070dd;
  --q-epic: #a335ee;
  --q-legendary: #ff8000;
  --q-artifact: #e6cc80;
  --q-heirloom: #00ccff;
}

.card { cursor: pointer; }

.name-btn {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-shadow: inherit;
}
.name-btn:hover, .name-btn:focus-visible { text-decoration: underline; text-underline-offset: 4px; }

dialog.armory {
  width: min(980px, calc(100vw - 1.5rem));
  max-height: calc(100vh - 1.5rem);
  overflow: auto;
  background:
    radial-gradient(ellipse at top, rgba(120, 220, 80, 0.08), transparent 60%),
    var(--panel);
}

.armory-head {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 2;
}
.armory-portrait { width: 64px; height: 64px; border-radius: 50%; border: 2px solid var(--gold-dim); object-fit: cover; flex: none; }
.armory-title { flex: 1; min-width: 0; }
.armory-title h2 { margin: 0; font-family: var(--font-display); color: var(--gold); font-size: 1.6rem; }
.armory-title p { margin: 0.1rem 0 0; }
.armory-close { flex: none; }

.armory-loading, .armory-empty { padding: 3rem 1.25rem; text-align: center; color: var(--muted); }
.armory-empty img { margin: 0 auto 1rem; width: 56px; height: 56px; border-radius: 10px; border: 1px solid var(--border); }
.armory-empty p { margin: 0.3rem 0; }
.armory-hint { text-align: center; font-size: 0.8rem; margin: 0 0 1rem; }

.paperdoll {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(200px, 260px) minmax(0, 1fr);
  grid-template-areas:
    "left doll right"
    "bottom bottom bottom";
  gap: 0.75rem 1rem;
  padding: 1.25rem;
}
.slots { display: grid; gap: 0.45rem; align-content: start; }
.slots-left { grid-area: left; }
.slots-right { grid-area: right; }
.slots-bottom { grid-area: bottom; grid-template-columns: repeat(3, minmax(0, 1fr)); max-width: 760px; width: 100%; justify-self: center; }

.slot {
  --q: var(--q-common);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  min-width: 0;
  padding: 0.3rem;
  font: inherit;
  text-align: left;
  color: var(--text);
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
button.slot:hover, button.slot:focus-visible, button.slot.active {
  background: rgba(255, 255, 255, 0.05);
  border-color: color-mix(in srgb, var(--q) 50%, transparent);
  outline: none;
}
.slot img {
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 6px;
  border: 2px solid var(--q);
  box-shadow: 0 0 8px color-mix(in srgb, var(--q) 35%, transparent);
  background: #000;
}
.slot-text { display: grid; min-width: 0; }
.slot-name { color: var(--q); font-weight: 600; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot-meta { color: var(--muted); font-size: 0.75rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot.right { flex-direction: row-reverse; text-align: right; }
.slot.slot-empty { cursor: default; opacity: 0.55; }
.slot.slot-empty img { border-color: #3a2f1d; box-shadow: none; }
.slot.slot-empty .slot-name { color: var(--muted); font-weight: 500; }

.q-poor { --q: var(--q-poor); }
.q-common { --q: var(--q-common); }
.q-uncommon { --q: var(--q-uncommon); }
.q-rare { --q: var(--q-rare); }
.q-epic { --q: var(--q-epic); }
.q-legendary { --q: var(--q-legendary); }
.q-artifact { --q: var(--q-artifact); }
.q-heirloom { --q: var(--q-heirloom); }

.doll {
  grid-area: doll;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 0.75rem;
  border-radius: 12px;
  background:
    radial-gradient(ellipse at 50% 35%, color-mix(in srgb, var(--class-color) 22%, transparent), transparent 70%),
    rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  min-height: 100%;
}
.doll-render {
  width: 100%;
  height: 440px;
  object-fit: contain;
  object-position: center bottom;
  flex: 1;
  min-height: 0;
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.6));
  transition: opacity 0.25s ease;
}
.doll-render.is-cropping { opacity: 0; }
.doll-fallback { width: 120px; height: 120px; border-radius: 50%; border: 3px solid var(--class-color); margin: auto 0; }
.doll-facts { margin: 0; width: 100%; display: grid; gap: 0.35rem; }
.doll-facts div { display: flex; justify-content: space-between; gap: 0.5rem; font-size: 0.85rem; }
.doll-facts dt { color: var(--muted); }
.doll-facts dd { margin: 0; color: var(--gold); font-weight: 600; }

/* WoW-style item tooltip */
.item-tooltip {
  position: fixed;
  z-index: 20;
  width: max-content;
  max-width: min(320px, calc(100vw - 16px));
  padding: 0.6rem 0.75rem;
  background: rgba(6, 10, 26, 0.96);
  border: 1px solid #5d6a8c;
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  font-size: 0.84rem;
  line-height: 1.4;
  color: #fff;
  pointer-events: none;
}
.item-tooltip.pinned { pointer-events: auto; }
.tt-name { font-size: 1rem; font-weight: 600; color: var(--q); margin-bottom: 0.1rem; }
.tt-split { display: flex; justify-content: space-between; gap: 1.5rem; }
.tt-gold { color: #ffd100; }
.tt-green { color: #1eff00; }
.tt-grey { color: #808080; }
.tt-set-on { color: #ffff98; }
.tt-indent { padding-left: 0.75rem; }
.tt-gap { margin-top: 0.6rem; }
.tt-gap-small { margin-top: 0.25rem; }
.tt-quote { font-style: italic; }
.tt-link { display: none; margin-top: 0.6rem; font-size: 0.8rem; }
.item-tooltip.pinned .tt-link { display: inline-block; }

@media (max-width: 760px) {
  .paperdoll {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "doll" "left" "right" "bottom";
    padding: 1rem;
  }
  .doll { min-height: 0; }
  .doll-render { height: 300px; }
  .slot.right { flex-direction: row; text-align: left; }
  .slots-bottom { grid-template-columns: minmax(0, 1fr); }
  .armory-head { padding: 0.75rem 1rem; }
  .armory-title h2 { font-size: 1.3rem; }
}
