@font-face {
  font-family: "Silk";
  src: url("/assets/fonts/slkscr.ttf") format("truetype");
  font-display: swap;
}

@font-face {
  font-family: "Alagard";
  src: url("/assets/fonts/alagard.ttf") format("truetype");
  font-display: swap;
}

:root {
  --bg: #1a120e;
  --bg-2: #241811;
  --panel: #2c1e16;
  --panel-2: #38261c;
  --line: #6a4e38;
  --line-soft: #4a3528;
  --cream: #f4efe6;
  --muted: #b5a394;
  --gold: #f0d7a0;
  --amber: #e99507;
  --common: #e1dee7;
  --uncommon: #baf3ea;
  --rare: #ea8cf5;
  --legendary: #e99507;
  --heirloom: #e99507;
  --weapon: #8eb4e8;
  --skill: #8fd18a;
  --pet: #e8a0c8;
  --danger: #ffb4a8;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--cream);
  font-family: "Segoe UI", ui-sans-serif, sans-serif;
  font-size: 14px;
}

button, select, input, textarea {
  font: inherit;
  color: inherit;
}

button, select, input[type="search"], input[type="password"], input[type="text"] {
  background: var(--bg-2);
  border: 2px solid var(--line-soft);
  border-radius: 0;
  padding: 6px 8px;
}

button {
  font-family: Silk, sans-serif;
  font-size: 14px;
  cursor: pointer;
  background: var(--amber);
  color: #2a1c14;
  border-color: #a86800;
}

button:hover { filter: brightness(1.08); }
button:disabled { opacity: 0.55; cursor: wait; }

button.ghost {
  background: var(--panel);
  color: var(--gold);
  border-color: var(--line);
}

button:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

#app {
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 14px 18px 16px;
  gap: 10px;
}

header, .actions, .filters, .filter-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

header { justify-content: space-between; align-items: flex-end; }

h1, h2, h3 {
  font-family: Silk, sans-serif;
  font-weight: normal;
  margin: 0;
  color: var(--gold);
}

h1 {
  font-family: Alagard, Silk, sans-serif;
  font-size: 32px;
  line-height: 1;
  letter-spacing: 0.5px;
  -webkit-font-smoothing: none;
  font-smooth: never;
}
h2 { font-size: 20px; }
h3 { font-size: 16px; color: var(--cream); }

.title-block p, .lead, .filters p, .card p {
  margin: 4px 0 0;
  color: var(--muted);
}

#subtitle { font-size: 13px; }

.filters {
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px 12px;
}

.filters label, .stack {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: Silk, sans-serif;
  font-size: 13px;
  color: var(--gold);
}

.filters select, .filters input { min-width: 120px; }

#summary {
  margin: 0 0 2px auto;
  font-variant-numeric: tabular-nums;
}

#more { margin-top: 8px; }

#layout {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: var(--panel);
  border: 2px solid var(--line-soft);
  padding: 8px;
}

.player { border-bottom: 2px solid var(--line-soft); }
.player:last-child { border-bottom: 0; }

.player-head, .run {
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--cream);
  border: 0;
  font-family: "Segoe UI", ui-sans-serif, sans-serif;
  padding: 8px;
}

.player-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  position: sticky;
  top: -8px;
  background: var(--panel);
  z-index: 1;
}

.player-head strong { color: var(--gold); font-family: Silk, sans-serif; font-weight: normal; font-size: 16px; }
.player-head span, .muted { color: var(--muted); }

.player-runs { display: none; padding: 0 0 6px; }
.player.open .player-runs { display: block; }

.run {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 2px 8px;
  border: 2px solid transparent;
  margin-bottom: 4px;
}

.run:hover { background: var(--panel-2); }
.run.selected { border-color: var(--amber); background: #3a281c; }

.run-main, .run-sub {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 8px;
  align-items: center;
}

.run-num {
  grid-row: span 2;
  align-self: center;
  font-family: Silk, sans-serif;
  color: var(--gold);
}

.score { font-variant-numeric: tabular-nums; font-weight: 700; }

.class-pill, .chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--cream);
}

.class-pill img, .skill img, .bless img, .stat-cell img {
  width: 22px;
  height: 22px;
  image-rendering: pixelated;
  object-fit: contain;
}

.mini {
  display: flex;
  height: 8px;
  width: 92px;
  background: #140e0b;
  border: 1px solid var(--line-soft);
}

.mini i { display: block; height: 100%; }

#detail { padding: 14px 16px 28px; }
#detail .empty-detail { color: var(--muted); padding: 24px 8px; }

.identity {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.identity img.class-icon {
  width: 48px;
  height: 48px;
  image-rendering: pixelated;
}

.identity .who { font-family: Silk, sans-serif; font-size: 22px; color: var(--gold); }
.identity .score-lg { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 14px; }

.chip {
  background: var(--bg-2);
  border: 2px solid var(--line-soft);
  padding: 4px 7px;
  font-size: 12px;
}

.section { margin: 16px 0; }
.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.help {
  width: 22px;
  height: 22px;
  padding: 0;
  background: var(--bg-2);
  color: var(--gold);
  border-color: var(--line);
}

.toggles { display: flex; gap: 4px; margin-left: auto; }
.toggles button[aria-pressed="true"] {
  background: var(--amber);
  color: #2a1c14;
  border-color: #a86800;
}

.stackbar {
  display: flex;
  height: 16px;
  width: 100%;
  background: #140e0b;
  border: 2px solid var(--line-soft);
  margin-bottom: 10px;
}

.stackbar i { display: block; height: 100%; }

.bar-row {
  display: grid;
  grid-template-columns: 28px minmax(90px, 150px) 1fr auto;
  gap: 8px;
  align-items: center;
  margin: 4px 0;
}

.bar-row img, .heir img, .item img {
  width: 28px;
  height: 28px;
  image-rendering: pixelated;
  object-fit: contain;
  background: #140e0b;
}

.bar-track {
  display: block;
  width: 100%;
  height: 12px;
  background: #140e0b;
  border: 1px solid var(--line-soft);
}

.bar-fill {
  display: block;
  height: 100%;
  min-width: 2px;
}
.bar-val { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; white-space: nowrap; }

.cat-label {
  margin: 10px 0 4px;
  color: var(--gold);
  font-family: Silk, sans-serif;
  font-size: 14px;
}

.rarity-line { display: flex; height: 14px; width: 100%; border: 2px solid var(--line-soft); margin: 6px 0 10px; }
.rarity-line i { display: block; height: 100%; }
.rarity-counts { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.rarity-counts b { font-weight: 650; }

.common { color: var(--common); }
.uncommon { color: var(--uncommon); }
.rare { color: var(--rare); }
.legendary { color: var(--legendary); }

.hist {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 88px;
  margin: 8px 0 12px;
}

.hist-col {
  flex: 1;
  min-width: 28px;
  max-width: 56px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--muted);
}

.hist-col i {
  display: block;
  width: 100%;
  background: var(--amber);
  min-height: 2px;
}

.heir-grid, .skill-row, .bless-row, .gear-grid, .stat-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.heir, .skill, .bless, .item, .stat-cell {
  background: var(--bg-2);
  border: 2px solid var(--line-soft);
  padding: 4px;
  position: relative;
}

.heir { width: 78px; text-align: center; }
.heir .count {
  position: absolute;
  right: 2px;
  bottom: 2.5em;
  background: #140e0b;
  color: var(--gold);
  font-family: Silk, sans-serif;
  font-size: 13px;
  padding: 0 3px;
  border: 1px solid var(--line);
}
.heir .label, .skill .label, .bless .label {
  display: block;
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.heir .label {
  white-space: normal;
  line-height: 1.15;
  height: 2.3em;
}

.heir.common { border-color: var(--common); }
.heir.uncommon, .skill.uncommon, .item.uncommon { border-color: var(--uncommon); }
.heir.rare, .skill.rare, .item.rare { border-color: var(--rare); }
.heir.legendary, .skill.legendary, .item.legendary, .gear-frame.legendary, .mini-heir.legendary, .mini-skill.legendary { border-color: var(--legendary); }

.gear-frame {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  background: #140e0b;
  border: 2px solid var(--line-soft);
  flex: none;
}
.gear-frame.common, .mini-heir.common { border-color: var(--common); }
.gear-frame.uncommon, .mini-heir.uncommon, .mini-skill.uncommon { border-color: var(--uncommon); }
.gear-frame.rare, .mini-heir.rare, .mini-skill.rare { border-color: var(--rare); }

.sprite { display: block; image-rendering: pixelated; }

.run-row {
  display: grid;
  grid-template-columns: 230px minmax(150px, 1.1fr) minmax(190px, 1.4fr) minmax(130px, 0.9fr) minmax(110px, 0.75fr);
  gap: 8px 14px;
  align-items: start;
  padding: 8px 10px;
  margin-bottom: 4px;
  border: 2px solid transparent;
  cursor: pointer;
}
.run-row:hover { background: var(--panel-2); }
.run-row.open { border-color: var(--amber); background: #3a281c; cursor: default; }
.run-more { grid-column: 1 / -1; padding-top: 4px; }

.who-name { display: flex; align-items: center; gap: 6px; min-width: 0; }
.rank {
  flex: none;
  min-width: 2.4em;
  font-family: Silk, sans-serif;
  font-size: 16px;
  color: var(--amber);
  font-variant-numeric: tabular-nums;
}
.who-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.who-name img { width: 20px; height: 20px; image-rendering: pixelated; object-fit: contain; }
.score-row { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.15; }
.who-meta { display: flex; flex-wrap: wrap; gap: 2px 8px; color: var(--muted); font-size: 12px; }
.who-meta span::before { content: "· "; }
.who-meta span:first-child::before { content: ""; }

.kicker { font-family: Silk, sans-serif; font-size: 12px; color: var(--gold); margin: 0 0 4px; }
.icon-row { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }

.mini-heir, .mini-bless, .mini-skill {
  position: relative;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  background: #140e0b;
  border: 2px solid var(--line-soft);
}
.mini-bless, .mini-skill { width: 52px; height: 52px; }
.mini-heir img { width: 28px; height: 28px; image-rendering: pixelated; object-fit: contain; }
.mini-bless img, .mini-skill img {
  width: 44px;
  height: 44px;
  image-rendering: pixelated;
  object-fit: contain;
}
.mini-heir .n {
  position: absolute;
  right: 1px;
  bottom: 0;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  color: var(--cream);
  text-shadow: 1px 1px 0 #140e0b, -1px 0 0 #140e0b;
}
.mini-heir.more {
  color: var(--gold);
  font-family: Silk, sans-serif;
  font-size: 13px;
}

.thin-bars .bar-row > span:nth-child(2) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.run-row .stackbar { height: 10px; border-width: 1px; margin-bottom: 4px; }
.run-row > div > .muted { display: block; font-size: 12px; margin: 0 0 4px; }
.thin-bars .bar-row {
  grid-template-columns: 16px minmax(52px, 88px) 1fr auto;
  gap: 4px;
  margin: 1px 0;
  font-size: 12px;
}
.thin-bars .bar-row img, .thin-bars .ph { width: 16px; height: 16px; }
.thin-bars .bar-track { height: 8px; }

@media (max-width: 1100px) {
  .run-row { grid-template-columns: 1fr 1fr; }
  .who-col { grid-column: 1 / -1; }
}

@media (max-width: 900px) {
  #app { height: auto; min-height: 100vh; }
  h1 { font-size: 24px; }
}

.skill, .bless { width: 112px; text-align: center; padding: 6px; }
.skill img, .bless img { width: 48px; height: 48px; }

.item { width: 210px; padding: 6px 8px; }
.item-head { display: flex; gap: 8px; align-items: center; margin-bottom: 4px; }
.item .name { font-weight: 650; }
.item .statline { display: block; font-size: 12px; color: var(--muted); }
.item .statline.Low { color: #b7b3ae; }
.item .statline.Average { color: #d9d4cc; }
.item .statline.High { color: var(--amber); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.stat-cell { display: flex; gap: 6px; align-items: center; padding: 6px 8px; }
.stat-cell b { display: block; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat-cell span { color: var(--muted); font-size: 12px; }

.mob-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.mob-table th { text-align: left; color: var(--gold); font-family: Silk, sans-serif; font-weight: normal; font-size: 13px; }
.mob-table td { padding: 3px 8px 3px 0; border-bottom: 1px solid var(--line-soft); }

.endless {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 72px;
}
.endless i {
  display: block;
  width: 10px;
  background: #c4543a;
  min-height: 2px;
}

.ph {
  display: inline-flex;
  width: 28px;
  height: 28px;
  align-items: center;
  justify-content: center;
  background: #140e0b;
  color: var(--muted);
  font-size: 11px;
}

#tip {
  position: fixed;
  z-index: 40;
  max-width: 280px;
  background: #140e0b;
  color: var(--cream);
  border: 2px solid var(--gold);
  padding: 8px 10px;
  pointer-events: none;
  font-size: 13px;
  line-height: 1.35;
}

#tip div + div { margin-top: 3px; }
#tip div:first-child { color: var(--gold); }

#gate {
  position: fixed;
  inset: 0;
  background: rgba(12, 8, 6, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 18px;
}

#gate[hidden], [hidden] { display: none !important; }

.card {
  width: min(640px, 100%);
  background: var(--panel);
  border: 2px solid var(--line);
  padding: 16px 18px 18px;
  max-height: calc(100vh - 36px);
  overflow: auto;
}

.card textarea, pre {
  width: 100%;
  background: #140e0b;
  color: var(--cream);
  border: 2px solid var(--line-soft);
  padding: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}

.card details { margin-top: 14px; }
.card summary { cursor: pointer; color: var(--gold); font-family: Silk, sans-serif; }

.check, .file { display: flex; gap: 8px; align-items: center; margin: 8px 0; color: var(--muted); }

.warn { color: var(--danger); }

.note {
  background: #3a281c;
  border: 2px solid var(--line);
  padding: 8px 10px;
  color: var(--gold);
}

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