/* SPDX-License-Identifier: GPL-3.0-or-later */

:root {
  --bg: #0f0e12;
  --bg-elev: #1a1822;
  --bg-elev2: #232031;
  --line: #322e40;
  --text: #ece9f2;
  --text-dim: #9b96ac;
  --accent: #e6b34a;       /* tarot gold */
  --accent-dim: #6a5324;
  --radius: 12px;

  /* Affinity outcome colors */
  --aff-Wk: #e8544e;       /* Weak    — exploitable */
  --aff-St: #6b7280;       /* Strong  — resisted */
  --aff-Nu: #3d8bf2;       /* Null    — no effect */
  --aff-Dr: #38b24a;       /* Drain   — heals the enemy */
  --aff-Rp: #9b6cf0;       /* Repel   — reflected back */

  --mood-eager: #e6b34a;
  --mood-happy: #38b24a;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--accent); }

/* --- header --------------------------------------------------------------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding: 8px max(10px, env(safe-area-inset-left)) 6px;
}

.header-row {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 1100px;
  margin: 0 auto;
}

.app-title { margin: 0; font-size: 15px; white-space: nowrap; }
.app-title button {
  background: none;
  border: 0;
  padding: 4px 2px;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: var(--accent);
}
.app-title span { color: var(--text-dim); font-weight: 600; }

.search-wrap { flex: 1; min-width: 0; }
#search {
  width: 100%;
  font-size: 16px;              /* avoids iOS zoom-on-focus */
  padding: 9px 12px;
  color: var(--text);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 999px;
  outline: none;
}
#search:focus { border-color: var(--accent); }

.about-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--text-dim);
}
.about-btn:hover { color: var(--accent); border-color: var(--accent-dim); }

/* --- recents -------------------------------------------------------------- */

.recents {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  max-width: 1100px;
  margin: 6px auto 0;
  padding-bottom: 2px;
}
.recents::-webkit-scrollbar { display: none; }
.recent-chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px 3px 3px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}
.recent-sprite { width: 22px; height: 22px; border-radius: 50%; object-fit: cover; }

/* --- layout --------------------------------------------------------------- */

#main { max-width: 1100px; margin: 0 auto; padding: 10px; }
.view[hidden] { display: none; }

/* --- results -------------------------------------------------------------- */

.results {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr;
}
@media (min-width: 680px) { .results { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1024px) { .results { grid-template-columns: 1fr 1fr 1fr; } }

.result {
  display: flex;
  gap: 10px;
  padding: 10px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: border-color 0.12s;
}
.result:hover, .result:focus-visible { border-color: var(--accent-dim); outline: none; }

.sprite {
  width: 52px;
  height: 52px;
  flex: none;
  border-radius: 8px;
  object-fit: cover;
  background: var(--bg-elev2);
  image-rendering: pixelated;
}
.sprite-fallback {
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 22px;
  color: var(--text-dim);
}

.row-body { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 5px; }
.row-head { display: flex; align-items: baseline; gap: 8px; justify-content: space-between; }
.row-name { font-weight: 700; }
.row-meta { font-size: 12px; color: var(--text-dim); white-space: nowrap; }

.row-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.row-noaff { color: var(--text-dim); font-size: 11px; font-style: italic; }
.row-contact { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 12px; }

.mini-contact { display: inline-flex; align-items: center; gap: 4px; }
.mini-label { color: var(--text-dim); }
.mini-codes { font-weight: 700; }
.mini-contact.is-eager .mini-codes { color: var(--mood-eager); }
.mini-contact.is-happy .mini-codes { color: var(--mood-happy); }
.row-item { color: var(--text-dim); }

/* --- affinity chips ------------------------------------------------------- */

.chip {
  display: inline-block;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.5;
  border-radius: 999px;
  border: 1px solid currentColor;
}
.chip-Wk { color: var(--aff-Wk); }
.chip-St { color: var(--aff-St); }
.chip-Nu { color: var(--aff-Nu); }
.chip-Dr { color: var(--aff-Dr); }
.chip-Rp { color: var(--aff-Rp); }
/* An aggregate chip (Elemental / Force / Physical / Ailment) covers a whole
   group of types at one outcome — a heavier double border sets it apart from a
   single-type chip. */
.chip-tag { font-weight: 800; }
.chip-aggregate {
  border-width: 2px;
  border-style: double;
  font-weight: 700;
}
/* Aggregate + constituent chips are tappable to expand/collapse the group. */
.chip[role="button"] {
  cursor: pointer;
  touch-action: manipulation;
}
/* An individual chip shown because its parent aggregate is expanded — dashed
   border distinguishes it from a standalone single-type chip. */
.chip-constituent {
  border-style: dashed;
}

/* --- detail --------------------------------------------------------------- */

.detail { display: flex; flex-direction: column; gap: 10px; max-width: 640px; margin: 0 auto; }

.back-btn {
  align-self: flex-start;
  background: none;
  border: 0;
  padding: 4px 2px;
  color: var(--text-dim);
  font-weight: 600;
}
.back-btn:hover { color: var(--accent); }

.detail-head { display: flex; gap: 14px; align-items: center; }
.detail-sprite {
  width: 84px;
  height: 84px;
  flex: none;
  border-radius: 10px;
  object-fit: cover;
  background: var(--bg-elev2);
  image-rendering: pixelated;
}
.detail-sprite.sprite-fallback { font-size: 34px; }
.detail-name { margin: 0 0 4px; font-size: 22px; }
.detail-sub { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; color: var(--text-dim); font-size: 13px; }

.cat-link {
  background: var(--bg-elev2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 10px;
  color: var(--text);
  font-size: 12px;
}
.cat-link:hover { border-color: var(--accent); color: var(--accent); }

.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.card-title {
  margin: 0 0 10px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.muted { color: var(--text-dim); margin: 0; }

/* --- negotiation ---------------------------------------------------------- */

.card-negotiation { border-color: var(--accent-dim); }
.nego { display: flex; flex-direction: column; gap: 12px; }
.nego-row { display: flex; flex-direction: column; gap: 6px; }
.nego-head { display: flex; align-items: center; gap: 8px; }
.nego-mood {
  font-weight: 800;
  font-size: 13px;
  padding: 1px 9px;
  border-radius: 999px;
}
.mood-eager { color: #1a1408; background: var(--mood-eager); }
.mood-happy { color: #08150c; background: var(--mood-happy); }
.nego-reward { font-size: 12px; color: var(--text-dim); }

.contact-opts { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.contact-or { color: var(--text-dim); font-size: 12px; font-style: italic; }
.contact-opt {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-elev2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 9px;
}
.code {
  font-weight: 800;
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-dim);
  border-radius: 5px;
  padding: 1px 5px;
  min-width: 22px;
  text-align: center;
}
.code-group { color: #dcd6ea; background: #43395c; }
.contact-who { font-weight: 600; }
.contact-sep { color: var(--text-dim); }
.contact-act { color: var(--text-dim); }

.nego-facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 14px;
  margin: 0;
}
.nego-facts dt { color: var(--text-dim); font-size: 12px; padding-top: 2px; }
.nego-facts dd { margin: 0; }
.card-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.tarot-chip {
  font-size: 12px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--bg-elev2);
  border: 1px solid var(--accent-dim);
  color: var(--accent);
}
.nego-note { margin: 2px 0 0; font-size: 11px; color: var(--text-dim); }

/* --- affinities card ------------------------------------------------------ */

.aff-groups { display: flex; flex-direction: column; gap: 12px; }
/* The outcome name is a plain caps heading (color from chip-<tag>), NOT a
   pill — so the element chips below are the only chip-shaped things and stay
   easy to scan. */
.aff-group-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-bottom: 5px;
}
.aff-chips { display: flex; flex-wrap: wrap; gap: 5px; }

/* --- stats ---------------------------------------------------------------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-bottom: 8px;
}
.stat-grid:last-child { margin-bottom: 0; grid-template-columns: repeat(4, 1fr); }
.stat-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 2px;
  background: var(--bg-elev2);
  border-radius: 8px;
}
.stat-key { font-size: 10px; color: var(--text-dim); letter-spacing: 0.05em; }
.stat-val { font-size: 17px; font-weight: 700; }

/* --- skills / drops ------------------------------------------------------- */

.skill-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.skill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  background: var(--bg-elev2);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px;
}
.rumor-tag {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  border: 1px solid var(--accent-dim);
  border-radius: 4px;
  padding: 0 3px;
}

.drops, .loc-chips { margin: 0; }
.drops { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; }
.drops dt { color: var(--text-dim); font-size: 12px; }
.drops dd { margin: 0; }
.loc-chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* --- about ---------------------------------------------------------------- */

.about h2 { margin: 4px 0 0; }
.about h3 { margin: 14px 0 4px; font-size: 15px; }
.about ul { margin: 4px 0; padding-left: 20px; }
.about li { margin: 3px 0; }
.about code {
  background: var(--bg-elev2);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 12px;
}
.update-row {
  margin-top: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.build-line { margin: 0; font-size: 12px; }
.update-btn {
  flex: none;
  padding: 7px 16px;
  font-weight: 700;
  color: #1a1408;
  background: var(--accent);
  border: 0;
  border-radius: 999px;
}
.update-btn:hover { filter: brightness(1.08); }
.update-btn:disabled { opacity: 0.6; }
.update-note { margin: 8px 0 0; font-size: 11px; }

.empty { text-align: center; color: var(--text-dim); padding: 40px 0; }

/* --- compare group -------------------------------------------------------- */

/* Long-pressing a demon card toggles its group membership, so block the
   native long-press behaviors that would otherwise fight it: images raising
   the "Save image" callout (Firefox/Safari mobile), and a text-selection drag
   aborting the press (Firefox fires pointercancel the moment selection kicks
   in). Sprites are <img>/placeholder elements carrying these classes. */
.sprite, .recent-sprite, .detail-sprite, .member-sprite, .group-sprite {
  pointer-events: none;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}
.result, .recent-chip {
  user-select: none;
  -webkit-user-select: none;
}

/* Selected (in-group) demons get a gold ring wherever they appear. */
.result.selected { border-color: var(--accent); }
.recent-chip.selected { border-color: var(--accent); color: var(--text); }

/* The persistent group row under recents. */
.group {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  max-width: 1100px;
  margin: 8px auto 0;
  padding: 8px 0 2px;
  border-top: 1px dashed var(--line);
}
.group::-webkit-scrollbar { display: none; }
.group:empty { display: none; }
.group.flash { animation: flash-warn 600ms ease; }
@keyframes flash-warn {
  0%, 100% { background: transparent; }
  30%      { background: rgba(232, 84, 78, 0.22); }
}

.group-chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px 3px 3px;
  border-radius: 999px;
  background: rgba(230, 179, 74, 0.12);
  border: 1px solid var(--accent);
  color: var(--text);
  font-size: 12px;
  white-space: nowrap;
}
.group-sprite { width: 22px; height: 22px; border-radius: 50%; object-fit: cover; }
.group-chip .x { color: var(--accent); font-weight: 800; margin-left: 1px; font-size: 15px; line-height: 1; }

.compare-btn {
  flex: none;
  margin-left: auto;
  position: sticky;
  right: 0;
  padding: 5px 14px;
  border-radius: 999px;
  background: var(--accent);
  color: #1a1408;
  border: 0;
  font-weight: 700;
  font-size: 12px;
}
.compare-btn:hover { filter: brightness(1.08); }

/* --- compare view --------------------------------------------------------- */

.compare-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.compare-title-row { display: flex; align-items: baseline; gap: 10px; margin: 4px 0 0; }
.compare-title { margin: 0; }
.compare-count { font-size: 13px; }

.compare-members {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
  margin: 4px 0 2px;
}
.member-card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.member-head {
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: 0;
  padding: 0;
  text-align: left;
  color: var(--text);
}
.member-sprite { width: 44px; height: 44px; border-radius: 8px; object-fit: contain; background: var(--bg-elev2); image-rendering: pixelated; flex: none; }
.member-id { display: flex; flex-direction: column; }
.member-name { font-weight: 700; }
.member-lv { font-size: 12px; color: var(--text-dim); }
.member-head:hover .member-name { color: var(--accent); }

.member-rewards { display: flex; flex-direction: column; gap: 5px; }
.reward-line { display: flex; gap: 8px; align-items: baseline; font-size: 13px; }
.reward-key {
  flex: none;
  width: 44px;
  color: var(--text-dim);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.reward-val { min-width: 0; }
.member-rewards .muted { margin: 0; font-size: 13px; }

.linkish { background: none; border: 0; color: var(--accent); font-weight: 600; font-size: 13px; padding: 4px 0; }

.compare-buckets { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; }
.compare-section { margin: 0; }
.bucket-label {
  margin: 0 0 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.bucket-USE   .bucket-label { color: var(--aff-Dr); }
.bucket-OK    .bucket-label { color: var(--accent); }
.bucket-MEH   .bucket-label { color: var(--text-dim); }
.bucket-AVOID .bucket-label { color: var(--aff-Wk); }

.compare-grid {
  display: grid;
  gap: 4px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px;
  overflow-x: auto;
  align-items: center;
  width: max-content;
  max-width: 100%;
}
.grid-col-head {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
  text-align: center;
  padding: 2px 4px;
  text-transform: uppercase;
  white-space: nowrap;
}
.grid-type { font-size: 13px; font-weight: 600; padding: 4px 8px 4px 0; white-space: nowrap; }
.grid-cell {
  display: grid;
  place-items: center;
  padding: 3px 6px;
  font-size: 11px;
  font-weight: 700;
  border-radius: 4px;
  border: 1px solid currentColor;
  min-width: 34px;
  min-height: 22px;
}
.grid-cell.empty { color: var(--text-dim); border-color: transparent; font-weight: 400; }
.grid-cell.chip-aggregate { border-style: double; border-width: 3px; }
/* Expanded constituent cells: dashed border, matching the detail page's
   expanded constituent chips (needs .grid-cell specificity to beat the solid
   border shorthand declared later in this section). */
.grid-cell.chip-constituent { border-style: dashed; }
.grid-toggle { cursor: pointer; touch-action: manipulation; }
