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

:root {
  --bg: #0e0e14;
  --bg-elev: #181822;
  --bg-elev2: #20202e;
  --line: #2c2c3a;
  --text: #e9e9f0;
  --text-dim: #9a9ab0;
  --accent: #e23b4e;
  --accent-dim: #7a1f29;
  --radius: 12px;

  /* affinity tag colors */
  --aff-Wk: #e23b4e;  /* Weak */
  --aff-Vn: #e8862f;  /* Vulnerable */
  --aff-Rs: #2bb39a;  /* Resist */
  --aff-Nu: #3d8bf2;  /* Null */
  --aff-Rp: #9b6cf0;  /* Repel */
  --aff-Ab: #38b24a;  /* Absorb */
  --aff-St: #6b7280;  /* Strong */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---------- header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(14, 14, 20, 0.95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding: max(env(safe-area-inset-top), 8px) 12px 8px;
}

.header-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-title {
  margin: 0;
  white-space: nowrap;
}
.app-title button {
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: var(--accent);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}
.app-title span { color: var(--text-dim); font-weight: 600; }

.search-wrap { flex: 1; }

#search {
  width: 100%;
  font-size: 16px; /* avoid iOS zoom */
  padding: 11px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text);
  outline: none;
}
#search:focus { border-color: var(--accent); }
#search::placeholder { color: var(--text-dim); }

/* ---------- recents ---------- */
.recents {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 0 2px;
  scrollbar-width: none;
}
.recents::-webkit-scrollbar { display: none; }
.recents:empty { display: none; }

.recent-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  padding: 5px 10px 5px 6px;
  border-radius: 999px;
  background: var(--bg-elev2);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 0.8rem;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
.recent-chip img { width: 22px; height: 22px; object-fit: contain; image-rendering: pixelated; }
.recent-chip .ph { width: 22px; height: 22px; display: grid; place-items: center; font-size: 0.7rem; color: var(--text-dim); }

/* ---------- views ---------- */
.view { padding: 10px 12px 28px; }
[hidden] { display: none !important; }

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

.row {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 10px;
  align-items: center;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  cursor: pointer;
  /* Block text-selection drag so a mouse-hold long-press isn't aborted
     by the browser starting a selection (Firefox fires pointercancel
     as soon as the selection drag kicks in). */
  user-select: none;
  -webkit-user-select: none;
}
.row:active { background: var(--bg-elev2); }

.sprite {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  background: var(--bg-elev2);
  border-radius: 8px;
  overflow: hidden;
}
.sprite img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
}
.sprite .ph { font-size: 1.4rem; color: var(--text-dim); }

.row-body { min-width: 0; }
.row-top {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.row-name { font-weight: 700; font-size: 0.98rem; }
.row-lv { color: var(--text-dim); font-size: 0.78rem; white-space: nowrap; }
.row-meta {
  margin-top: 4px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 6px;
  align-items: center;
  font-size: 0.74rem;
  color: var(--text-dim);
}
.row-contact { color: var(--text); }
.row-contact b { color: var(--accent); font-weight: 700; }

/* ---------- affinity chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 6px;
  border: 1px solid currentColor;
  white-space: nowrap;
}
.chip .tag { font-weight: 800; }
.chip.chip-aggregate {
  border-style: double;
  border-width: 3px;
  padding: 0 5px;
}
.chip.chip-aggregate[role="button"] {
  cursor: pointer;
  touch-action: manipulation;
}
/* An individual chip rendered because its parent group is currently
   expanded. Dashed border invites a tap back into the group chip.
   Border width matches the regular .chip baseline (1px) so the dash
   pattern reads at the same fineness as the compare view's
   .grid-cell.expanded cells. */
.chip.chip-constituent {
  border-style: dashed;
  cursor: pointer;
  touch-action: manipulation;
}

/* Dire affinities (200% repel/drain) override any dimming from the
   .expanded grid styling and get a bolder text weight so they stand
   out in long affinity strips. Inverted fill (solid background, dark
   text) so they read as alarm chips at a glance. */
.chip.pct-extreme,
.grid-cell.pct-extreme {
  opacity: 1;
  font-weight: 800;
}
.chip.pct-extreme,
.grid-cell.pct-extreme {
  background: var(--chip-clr);
  color: var(--bg);
  border-color: var(--chip-clr);
}
.chip-Wk { --chip-clr: var(--aff-Wk); color: var(--chip-clr); }
.chip-Vn { --chip-clr: var(--aff-Vn); color: var(--chip-clr); }
.chip-Rs { --chip-clr: var(--aff-Rs); color: var(--chip-clr); }
.chip-Nu { --chip-clr: var(--aff-Nu); color: var(--chip-clr); }
.chip-Rp { --chip-clr: var(--aff-Rp); color: var(--chip-clr); }
.chip-Ab { --chip-clr: var(--aff-Ab); color: var(--chip-clr); }
.chip-St { --chip-clr: var(--aff-St); color: var(--chip-clr); }

/* ---------- detail ---------- */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 4px 0;
  margin-bottom: 8px;
  cursor: pointer;
}

.detail-head {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 16px;
}
.detail-sprite {
  width: 96px;
  height: 96px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.detail-sprite img { max-width: 100%; max-height: 100%; image-rendering: pixelated; }
.detail-sprite .ph { font-size: 2.4rem; color: var(--text-dim); }

.detail-title h2 { margin: 0 0 2px; font-size: 1.4rem; }
.detail-jp { color: var(--text-dim); font-size: 0.95rem; }
.detail-kind {
  margin-top: 2px;
  font-size: 0.78rem;
  color: var(--text-dim);
  letter-spacing: 0.4px;
}
.detail-stats {
  margin-top: 6px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 0.85rem;
  color: var(--text-dim);
}
.detail-stats b { color: var(--text); }

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

.aff-group { margin-bottom: 12px; }
.aff-group-label {
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-bottom: 5px;
  /* color set by chip-Wk / chip-Rs / chip-Nu / ... */
}
.aff-group:last-child { margin-bottom: 0; }

.contact-list { display: grid; gap: 6px; }
.contact {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 0.95rem;
}
.contact .who { font-weight: 700; color: var(--accent); min-width: 64px; }
.contact .act { color: var(--text); }

.item-line { font-size: 1rem; }
.item-line .jp { color: var(--text-dim); margin-left: 8px; font-size: 0.9rem; }

.skill-list { display: grid; gap: 6px; }
.skill {
  display: grid;
  grid-template-columns: minmax(96px, auto) 1fr;
  gap: 10px;
  align-items: baseline;
  font-size: 0.92rem;
}
.skill-name { font-weight: 700; color: var(--text); }
.skill-effect { color: var(--text-dim); }
/* Inheritable skills carry a small leading glyph (a fusion-arrow) on the
   name. Subtle accent so it scans without shouting. */
.skill.skill-inh .skill-name::before {
  content: "↗ ";
  color: var(--accent);
  font-weight: 800;
}

.traits { display: flex; flex-wrap: wrap; gap: 6px; }
.trait {
  font-size: 0.82rem;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--bg-elev2);
  border: 1px solid var(--line);
}

.muted { color: var(--text-dim); font-size: 0.9rem; }

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

/* ---------- selected indicator (in group) ---------- */
/* Recent-chips use a muted (not red) marker so they're clearly distinct
   from the actionable red × chips in the group row that sits right next
   to them: tapping a recent-chip opens the demon; tapping a group-chip
   removes it. Search-result .row.selected stays red — it's far from the
   group row so the affordance collision doesn't apply. */
.row.selected { box-shadow: inset 0 0 0 2px var(--accent); }
.recent-chip.selected { border-color: var(--text-dim); box-shadow: inset 0 0 0 1px var(--text-dim); }
.row.selected .row-name::before {
  content: "★";
  color: var(--accent);
  margin-right: 4px;
  font-size: 0.85em;
}
.recent-chip.selected::before {
  content: "★";
  color: var(--text-dim);
  margin-right: 4px;
  font-size: 0.85em;
}

/* ---------- group row ---------- */
.group {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  align-items: center;
  margin-top: 4px;
  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(226, 59, 78, 0.25); }
}

.group-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  padding: 4px 8px 4px 5px;
  border-radius: 999px;
  background: rgba(226, 59, 78, 0.12);
  border: 1px solid var(--accent);
  color: var(--text);
  font-size: 0.8rem;
  cursor: pointer;
}
.group-chip img { width: 22px; height: 22px; object-fit: contain; image-rendering: pixelated; }
.group-chip .ph { width: 22px; height: 22px; display: grid; place-items: center; font-size: 0.7rem; color: var(--text-dim); }
.group-chip .x { color: var(--accent); font-weight: 800; margin-left: 2px; font-size: 1rem; line-height: 1; }

.compare-btn {
  position: sticky;
  right: 0;
  flex: 0 0 auto;
  margin-left: auto;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  border: 0;
  font-weight: 700;
  font-size: 0.8rem;
  cursor: pointer;
}

/* ---------- compare view ---------- */
.compare-head {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 4px 0 12px;
}
.compare-head::-webkit-scrollbar { display: none; }

.compare-member {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  cursor: pointer;
  color: var(--text);
  font-size: 0.78rem;
}
.compare-sprite {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  background: var(--bg-elev2);
  border-radius: 8px;
  overflow: hidden;
}
.compare-sprite img { max-width: 100%; max-height: 100%; image-rendering: pixelated; }
.compare-sprite .ph { font-size: 1.5rem; color: var(--text-dim); }
.compare-name { max-width: 84px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.compare-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.linkish {
  background: none;
  border: 0;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0;
  font-size: 0.85rem;
}

.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: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
}
.bucket-USE     .bucket-label { color: var(--aff-Ab); }
.bucket-OK      .bucket-label { color: var(--aff-Vn); }
.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: 0.7rem;
  font-weight: 700;
  color: var(--text-dim);
  text-align: center;
  padding: 2px 4px;
  text-transform: uppercase;
  white-space: nowrap;
}
.grid-type {
  font-size: 0.9rem;
  font-weight: 600;
  padding: 4px 6px 4px 0;
  white-space: nowrap;
}
.grid-cell {
  display: grid;
  place-items: center;
  padding: 4px 6px;
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: 4px;
  border: 1px solid currentColor;
  text-align: center;
  min-width: 36px;
  min-height: 22px;
}
.grid-cell.empty {
  color: var(--text-dim);
  border-color: transparent;
  background: transparent;
  font-weight: 400;
}
/* Cells derived from an aggregate (e.g. Element/Force) are faded so direct
   entries pop. The `title` attribute names the source aggregate on hover;
   tap-to-reveal popover (below) provides the same info on touch.
   touch-action: manipulation disables the double-tap-zoom heuristic so the
   click event fires immediately on iOS. */
.grid-cell.expanded {
  opacity: 0.85;
  border-style: dashed;
  cursor: pointer;
  touch-action: manipulation;
}
/* Collapsed-group cells get the double border treatment (matching
   .chip-aggregate) so they read as "tap to expand". */
.grid-cell.chip-aggregate {
  border-style: double;
  border-width: 3px;
}
/* Anything tap-to-toggle (group row label/cells, expanded constituent
   row label/cells) shows a pointer affordance. */
.grid-toggle {
  cursor: pointer;
  touch-action: manipulation;
}

/* Provenance popover anchored to a tapped expanded cell. Fixed-position so
   it isn't clipped by .compare-grid's overflow-x. */
.compare-popover {
  position: fixed;
  z-index: 100;
  background: var(--bg-elev2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 9px;
  font-size: 0.78rem;
  pointer-events: none;
  opacity: 0;
  white-space: nowrap;
  max-width: calc(100vw - 16px);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
  transition: opacity 80ms;
}
.compare-popover.open { opacity: 1; }
.compare-popover::before {
  content: "";
  position: absolute;
  top: -5px;
  left: var(--arrow-left, 50%);
  transform: translateX(-50%);
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 5px solid var(--line);
}

/* color for grid cells comes from existing chip-Wk/-Rs/... rules */

/* ---------- About: header button + page ---------- */
.about-btn {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: none;
  border: 0;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0;
}
.about-btn:hover,
.about-btn:focus-visible { color: var(--text); outline: none; }

.about-title {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 4px 0 16px;
}
.about-title img {
  width: 64px;
  height: 64px;
  border-radius: 12px;
  image-rendering: pixelated;
}
.about-title h2 { margin: 0; font-size: 1.4rem; }
.about-title .sub { color: var(--text-dim); font-size: 0.85rem; }

.about-card p { margin: 0 0 8px; line-height: 1.45; }
.about-card p:last-child { margin-bottom: 0; }
.about-card a { color: var(--accent); text-decoration: none; }
.about-card a:hover { text-decoration: underline; }
.about-card ul { margin: 0; padding-left: 18px; line-height: 1.6; }
.about-card li { margin-bottom: 4px; }

.build-line {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  color: var(--text-dim);
  word-break: break-all;
}
