:root {
  --bg: #0c0d0f;
  --panel: #141619;
  --panel-2: #1b1e22;
  --line: #2a2e34;
  --line-strong: #3a3f47;
  --text: #e7e8ea;
  --muted: #8d939b;
  --faint: #5b6068;
  --accent: #f4d51c;
  --accent-ink: #141414;
  --danger: #e0564f;
  --p1: #9fd4ec;
  --r6: #ff7000;
  --r5: #e1ba03;
  --r4: #9451f8;
  --r3: #26bafb;
  --stat-attr: #c9ccd1;
  --stat-sec: #8fc3e6;
  --stat-skill: #e8c872;
  --announced: #5fd4b0;
  --display: 'Chakra Petch', 'Segoe UI', system-ui, sans-serif;
  --radius: 3px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

h1, h2, h3 { font-family: var(--display); font-weight: 700; letter-spacing: 0.04em; margin: 0; }
a { color: var(--p1); }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 14px 24px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #121417, var(--bg));
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 14px; height: 32px; background: var(--accent);
  clip-path: polygon(0 0, 100% 0, 100% 75%, 0 100%);
}
.brand h1 { font-size: 22px; text-transform: uppercase; }
.brand-sub { margin: 0; color: var(--muted); font-size: 12px; }
.tally { display: flex; gap: 14px; font-family: var(--display); font-size: 13px; color: var(--muted); }
.tally b { color: var(--text); font-size: 16px; margin-right: 4px; }
.tally .p2 b { color: var(--accent); }

/* Layout */
.layout {
  display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 24px;
  padding: 20px 24px; max-width: 1800px; margin: 0 auto;
}
.pane-head { margin-bottom: 14px; }
.pane-head h2 { font-size: 18px; text-transform: uppercase; margin-bottom: 4px; }
.hint { margin: 0 0 12px; color: var(--muted); font-size: 12.5px; }
.hint b { font-weight: 600; }
.p0 { color: var(--faint); }
.p1 { color: var(--p1); }
.p2 { color: var(--accent); }

.matches { position: sticky; top: 12px; align-self: start; max-height: calc(100vh - 24px); overflow-y: auto; scrollbar-width: thin; padding-right: 4px; }

.pane-tabs { display: none; }

/* Controls */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
#search {
  flex: 1 1 220px; min-width: 0; padding: 7px 10px;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
}
#search:focus { border-color: var(--accent); outline: none; }
.chip-group, .bulk { display: flex; gap: 4px; flex-wrap: wrap; }
.btn, .chip-toggle {
  background: var(--panel-2); border: 1px solid var(--line-strong); border-radius: var(--radius);
  padding: 5px 10px; font-size: 12px; cursor: pointer; color: var(--muted);
  font-family: var(--display); font-weight: 600; letter-spacing: 0.03em; text-transform: uppercase;
}
.btn:hover, .chip-toggle:hover { color: var(--text); border-color: var(--faint); }
.btn-primary { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.btn-primary:hover { color: var(--accent-ink); filter: brightness(1.1); border-color: var(--accent); }
.btn-danger:hover { color: #fff; background: var(--danger); border-color: var(--danger); }
.chip-toggle[aria-pressed="true"] { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.chip-toggle.r6[aria-pressed="true"] { background: var(--r6); border-color: var(--r6); }
.chip-toggle.r5[aria-pressed="true"] { background: var(--r5); border-color: var(--r5); }
.chip-toggle.r4[aria-pressed="true"] { background: var(--r4); border-color: var(--r4); color: #fff; }
.chip-toggle.r3[aria-pressed="true"] { background: var(--r3); border-color: var(--r3); }

/* Weapon groups */
.group-head {
  display: flex; align-items: center; gap: 10px; margin: 22px 0 10px;
  padding-bottom: 6px; border-bottom: 1px solid var(--line);
  font-family: var(--display); font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; font-size: 13px;
}
.group-head img { width: 20px; height: 20px; opacity: 0.85; }
.group-head .count { margin-left: auto; color: var(--muted); letter-spacing: 0.04em; font-weight: 500; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 8px; }

.card {
  position: relative; display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 4px 10px; align-items: center;
  width: 100%; padding: 10px 10px 10px 12px; text-align: left; cursor: pointer; user-select: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  transition: border-color 0.12s, opacity 0.12s, background 0.12s;
}
.card::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--rarity); }
.card:hover { border-color: var(--line-strong); background: var(--panel-2); }
.card[data-p="0"] { opacity: 0.38; }
.card[data-p="0"] .wicon img { filter: grayscale(1); }
.card[data-p="0"]:hover { opacity: 0.7; }
.card[data-p="2"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.card-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--p1); padding-right: 18px; }
.card[data-p="2"] .card-name { color: var(--text); }
.card[data-p="0"] .card-name { color: var(--muted); }
.card .star { position: absolute; top: 6px; right: 8px; color: var(--accent); font-size: 15px; line-height: 1; visibility: hidden; }
.card[data-p="2"] .star { visibility: visible; }
.card .wicon { grid-row: span 2; }
.card .stats { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.card-meta { font-size: 11.5px; color: var(--rarity); font-family: var(--display); font-weight: 600; letter-spacing: 0.04em; }

/* Announced weapons: striped rarity edge, dashed outline and a tag. */
.card.announced { border-style: dashed; }
.card.announced::before {
  width: 4px;
  background: repeating-linear-gradient(-45deg, var(--rarity) 0 4px, transparent 4px 8px);
}
.tag-announced {
  display: inline-block; margin-left: 6px; padding: 0 5px; vertical-align: 1px;
  font-family: var(--display); font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; line-height: 15px;
  color: var(--announced); border: 1px solid currentColor; border-radius: var(--radius);
}
.chip-toggle.announced[aria-pressed="true"] { background: var(--announced); border-color: var(--announced); }

/* Weapon tooltip */
@media (hover: hover) { .touch-hint { display: none; } }
[data-tip] { -webkit-touch-callout: none; }
#tip {
  position: fixed; inset: auto; margin: 0; pointer-events: none;
  width: max-content; max-width: min(360px, calc(100vw - 16px)); padding: 10px 12px;
  color: var(--text); font-size: 12.5px; line-height: 1.45;
  background: var(--panel-2); border: 1px solid var(--line-strong); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.5);
}
.tip-head { display: flex; align-items: center; gap: 6px; font-family: var(--display); font-size: 14px; }
.tip-head .tag-announced { margin-left: 0; }
.tip-meta { color: var(--rarity); font-family: var(--display); font-weight: 600; font-size: 11.5px; letter-spacing: 0.04em; }
.tip-op { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-weight: 600; }
.tip-op small { display: block; color: var(--faint); font-size: 10.5px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.06em; }
.tip-avatars { display: flex; flex: none; }
.tip-avatars img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; background: var(--panel); border: 1px solid var(--line-strong); }
.tip-avatars img + img { margin-left: -12px; }
.tip-skill { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.tip-skill b { color: var(--stat-skill); }
.tip-effect { margin: 4px 0 0; white-space: pre-line; }
.tip-effect.missing { color: var(--muted); }
.tip-note { margin: 8px 0 0; padding-top: 6px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11.5px; }
.chip-toggle .count { opacity: 0.7; margin-left: 2px; }

.r6 { --rarity: var(--r6); }
.r5 { --rarity: var(--r5); }
.r4 { --rarity: var(--r4); }
.r3 { --rarity: var(--r3); }

.wicon {
  position: relative; width: 52px; height: 52px; border-radius: var(--radius); overflow: hidden;
  background: linear-gradient(135deg, color-mix(in srgb, var(--rarity) 28%, transparent), color-mix(in srgb, var(--rarity) 6%, transparent));
  border: 1px solid color-mix(in srgb, var(--rarity) 35%, transparent);
}
.wicon::after {
  content: attr(data-initial); position: absolute; inset: 0; display: grid; place-items: center;
  font-family: var(--display); font-weight: 700; color: var(--muted); z-index: 0;
}
.wicon img { position: relative; z-index: 1; width: 100%; height: 100%; object-fit: contain; display: block; }
.wicon img.broken { visibility: hidden; }
.wicon.sm { width: 26px; height: 26px; }
.wicon.md { width: 40px; height: 40px; }

/* Stat chips */
.stat {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 6px; font-size: 11px; line-height: 18px; white-space: nowrap;
  border: 1px solid var(--line-strong); border-radius: var(--radius); background: #0f1113;
}
.stat.attr { color: var(--stat-attr); }
.stat.secondary { color: var(--stat-sec); }
.stat.skill { color: var(--stat-skill); }
.stat.any { color: var(--faint); border-style: dashed; }
.stat.fixed { border-color: currentColor; background: color-mix(in srgb, currentColor 12%, transparent); font-weight: 600; }
.or { color: var(--faint); font-size: 11px; }

/* Location filter */
.locations summary {
  cursor: pointer; color: var(--muted); font-family: var(--display); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em; font-size: 12px;
}
.locations summary:hover { color: var(--text); }
.region { margin-top: 10px; }
.region-head { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 6px; }
.region-head button { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 11px; text-decoration: underline; padding: 0; }
.region .chip-group .chip-toggle { text-transform: none; letter-spacing: 0; }

/* Results */
.results { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.result {
  display: block; width: 100%; text-align: left; cursor: pointer;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px;
}
.result:hover { border-color: var(--line-strong); background: var(--panel-2); }
.result-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.rank { font-family: var(--display); color: var(--faint); font-weight: 600; min-width: 1.8em; }
.loc { font-family: var(--display); font-weight: 700; font-size: 16px; letter-spacing: 0.02em; }
.loc-region { color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }
.score { margin-left: auto; font-family: var(--display); font-weight: 700; display: flex; gap: 10px; }
.score .p2::before { content: '\2605 '; }
.engraving { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: 8px 0 10px; }
.engraving .sep { width: 1px; height: 16px; background: var(--line-strong); margin: 0 4px; }
.hits { display: flex; flex-wrap: wrap; gap: 5px; }
.hit {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px 2px 2px;
  background: #0f1113; border: 1px solid var(--line); border-radius: var(--radius); font-size: 12.5px;
}
.hit .wicon.sm { border: 0; }
.hit[data-p="2"] { border-color: var(--accent); }
.hit[data-p="2"] .hit-name::before { content: '\2605 '; color: var(--accent); }
.hit[data-p="1"] .hit-name { color: var(--p1); }
.hit.announced { border-style: dashed; }
.hit.announced .hit-name::after { content: ' \25C7'; color: var(--announced); }
.empty { color: var(--muted); padding: 24px; border: 1px dashed var(--line-strong); border-radius: var(--radius); text-align: center; }
.more { width: 100%; margin-top: 8px; padding: 8px; }

/* Dialogs */
dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--line-strong); border-radius: 4px;
  padding: 0; width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.72); }
#confirm { width: min(440px, calc(100vw - 32px)); }
#confirm form { padding: 20px; }
#confirm p { color: var(--muted); }
#confirm .confirm-count { color: var(--text); margin-bottom: 6px; }
.confirm-list {
  list-style: none; margin: 0; padding: 8px 10px; max-height: 220px; overflow-y: auto; scrollbar-width: thin;
  background: #0f1113; border: 1px solid var(--line); border-radius: var(--radius); font-size: 13px;
}
.confirm-list li { padding: 2px 0; }
#confirm-ok.btn-danger { color: #fff; background: var(--danger); border-color: var(--danger); }
#confirm-ok.btn-danger:hover { filter: brightness(1.1); }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

.detail-head { position: sticky; top: 0; z-index: 2; background: var(--panel); padding: 18px 20px 14px; border-bottom: 1px solid var(--line); }
.detail-head h3 { font-size: 22px; padding-right: 36px; }
.detail-close {
  position: absolute; top: 14px; right: 14px; width: 32px; height: 32px;
  background: none; border: 1px solid var(--line-strong); border-radius: var(--radius); color: var(--muted); cursor: pointer; font-size: 18px; line-height: 1;
}
.detail-close:hover { color: var(--text); border-color: var(--faint); }
.detail-body { padding: 16px 20px 22px; }
.steps { margin: 10px 0 0; padding-left: 20px; color: var(--muted); font-size: 13px; }
.steps li { margin: 4px 0; }
.steps li .stat { vertical-align: 1px; }
.detail-body h4 {
  font-family: var(--display); font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted);
  margin: 18px 0 8px;
}
.drop-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.drop-table th { text-align: left; font-weight: 500; color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; padding: 0 8px 6px 0; }
.drop-table td { padding: 6px 8px 6px 0; border-top: 1px solid var(--line); vertical-align: middle; }
.drop-table .roll { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: 2px 0; }
.drop-table .who { display: flex; align-items: center; gap: 10px; }
.drop-table .who small { display: block; color: var(--muted); font-size: 11.5px; }
.drop-table tr[data-p="2"] .name::before { content: '\2605 '; color: var(--accent); }
.drop-table tr[data-p="1"] .name { color: var(--p1); }
.untracked { margin-top: 16px; color: var(--muted); font-size: 12.5px; }
.untracked summary { cursor: pointer; }
.untracked ul { margin: 8px 0 0; padding-left: 18px; columns: 2; }

.foot { color: var(--faint); font-size: 12px; text-align: center; padding: 20px 24px 32px; }

/* Narrow screens: one pane at a time */
@media (max-width: 900px) {
  .topbar { padding: 12px 16px; }
  .layout { grid-template-columns: 1fr; padding: 12px 16px; }
  .pane-tabs {
    display: grid; grid-template-columns: 1fr 1fr; position: sticky; top: 0; z-index: 5;
    background: var(--bg); border-bottom: 1px solid var(--line);
  }
  .pane-tabs button {
    background: none; border: 0; border-bottom: 2px solid transparent; padding: 12px; cursor: pointer;
    font-family: var(--display); font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
  }
  .pane-tabs button[aria-pressed="true"] { color: var(--text); border-bottom-color: var(--accent); }
  .layout[data-pane="targets"] .matches, .layout[data-pane="matches"] .targets { display: none; }
  .matches { position: static; max-height: none; overflow: visible; padding-right: 0; }
  .grid { grid-template-columns: 1fr; }
  .untracked ul { columns: 1; }
}
