/* Pixel Chronicles wiki — dark-first, pixel-art friendly. */

:root {
  color-scheme: dark;
  --bg: #0f1116;
  --bg-raised: #171a22;
  --bg-inset: #1e222c;
  --line: #2b3040;
  --line-soft: #232734;
  --text: #e6e8ef;
  --text-dim: #9aa1b4;
  --text-faint: #6b7285;
  --accent: #f0b32d;
  --accent-dim: #7a5c14;
  --link: #7cc4ff;

  /* Rarity hues come from the game and are injected at runtime from meta.json;
     these are only the fallbacks used before the data loads. */
  --rarity: #9aa1b4;
  /* Text sits on a dark panel, so rarity hues get lifted toward white for
     contrast while the untouched hue stays as the accent bar and badge tint. */
  --rarity-mix: #ffffff;
  --rarity-mix-amount: 34%;

  --special: #fd54fd;
  --passive: #f0b877;

  --buff: #6fcf6f;
  --debuff: #e8685f;

  --neutral: #9aa1b4;
  --water: #4fa8e8;
  --fire: #ef7043;
  --grass: #6fbf5f;
  --dark: #9b6fd8;
  --light: #f0d264;

  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 8px 24px -12px rgb(0 0 0 / .5);
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", Menlo, Consolas, monospace;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f7f9;
  --bg-raised: #ffffff;
  --bg-inset: #eef0f4;
  --line: #d7dbe4;
  --line-soft: #e5e8ee;
  --text: #1a1d26;
  --text-dim: #5c6376;
  --text-faint: #868da0;
  --accent: #a9760a;
  --accent-dim: #e8d5a6;
  --link: #1667c4;

  /* On white, the same hues need darkening instead of lightening. */
  --rarity-mix: #14161c;
  --rarity-mix-amount: 55%;
  --special: #b810b8;
  --passive: #a2661a;
  --buff: #2f8b32;
  --debuff: #c0362c;
  --shadow: 0 1px 2px rgb(16 22 40 / .06), 0 8px 24px -14px rgb(16 22 40 / .18);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Pixel art must never be smoothed. */
img { image-rendering: pixelated; }

/* ------------------------------------------------------------------ topbar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: color-mix(in srgb, var(--bg-raised) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 650;
  letter-spacing: -.01em;
  color: var(--text);
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand em {
  display: block;
  font: 600 10px/1 var(--mono);
  font-style: normal;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--accent);
  margin-top: 2px;
}
.brand-mark {
  width: 20px; height: 20px;
  flex: none;
  background:
    linear-gradient(var(--accent) 0 0) 0 0 / 9px 9px no-repeat,
    linear-gradient(var(--grass) 0 0) 11px 11px / 9px 9px no-repeat;
  background-color: var(--bg-inset);
  border-radius: 3px;
}

.search { position: relative; flex: 1 1 260px; min-width: 200px; }

.search input {
  width: 100%;
  padding: 8px 12px;
  font: inherit;
  color: var(--text);
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.search input:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; }
.search input::placeholder { color: var(--text-faint); }

.suggestions {
  position: absolute;
  top: calc(100% + 6px);
  left: 0; right: 0;
  margin: 0; padding: 4px;
  list-style: none;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-height: min(60vh, 420px);
  overflow-y: auto;
  z-index: 30;
}
.suggestions li > a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 9px;
  border-radius: 6px;
  color: var(--text);
}
.suggestions li > a:hover,
.suggestions li[aria-selected="true"] > a {
  background: var(--bg-inset);
  text-decoration: none;
}
.suggestions a > img { width: 24px; height: 24px; object-fit: contain; flex: none; }
.suggestions a > .sprite { height: 24px; max-width: 24px; flex: none; }
.suggestions .kind {
  margin-left: auto;
  font: 600 10px/1 var(--mono);
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-faint);
}

.tabs { display: flex; gap: 2px; flex-wrap: wrap; }
.tabs a {
  padding: 7px 12px;
  border-radius: 7px;
  color: var(--text-dim);
  font-weight: 550;
  font-size: 14px;
}
.tabs a:hover { background: var(--bg-inset); color: var(--text); text-decoration: none; }
.tabs a[aria-current="page"] { background: var(--accent-dim); color: var(--text); }

.icon-btn {
  width: 34px; height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 15px;
}
.icon-btn:hover { color: var(--text); }
.icon-btn::before { content: "☾"; }
:root[data-theme="light"] .icon-btn::before { content: "☀"; }

/* Language picker: a real <select>, so it gets the platform's own list — long
   enough at 11 languages that a custom dropdown would only be worse. */
.lang { position: relative; flex: none; display: flex; align-items: center; }
.lang::before {
  content: "🌐";
  position: absolute;
  left: 8px;
  font-size: 12px;
  pointer-events: none;
}
.lang select {
  appearance: none;
  padding: 0 22px 0 26px;
  height: 34px;
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text-dim);
  font: 600 12px/1 inherit;
  cursor: pointer;
  max-width: 130px;
}
.lang select:hover { color: var(--text); }
.lang::after {
  content: "";
  position: absolute;
  right: 9px;
  width: 0;
  height: 0;
  border: 4px solid transparent;
  border-top-color: currentColor;
  color: var(--text-faint);
  pointer-events: none;
}

/* -------------------------------------------------------------------- main */

main {
  flex: 1;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 20px 56px;
}

.loading { color: var(--text-dim); }

h1 { font-size: 26px; letter-spacing: -.02em; margin: 0 0 4px; }
h2 { font-size: 17px; letter-spacing: -.01em; margin: 32px 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; color: var(--text-dim); }

.subtitle { color: var(--text-dim); margin: 0 0 22px; }

.crumbs { font-size: 13px; color: var(--text-faint); margin-bottom: 10px; }
.crumbs a { color: var(--text-dim); }

/* ------------------------------------------------------------------- cards */

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

.card {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px;
  background: var(--bg-raised);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  color: var(--text);
  border-left: 3px solid var(--rarity, var(--line));
}
.card:hover {
  text-decoration: none;
  border-color: var(--line);
  background: var(--bg-inset);
}
.card .thumb { width: 40px; height: 40px; flex: none; }
.card-body { min-width: 0; }
.card-title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-sub { font-size: 12px; color: var(--text-dim); }

.thumb {
  display: grid;
  place-items: center;
  background: var(--bg-inset);
  border-radius: 7px;
  overflow: hidden;
}
.thumb > img { width: 100%; height: 100%; object-fit: contain; padding: 3px; }
/* A height is required, not just max-*: the inner image is absolutely positioned,
   so the box has no content to size itself from and `aspect-ratio` has nothing to
   work with. Height drives it, max-width reins in wide cells. */
.thumb > .sprite { height: calc(100% - 6px); max-width: calc(100% - 6px); }

/* One cell of a sprite sheet: the box holds the cell's aspect ratio and clips,
   the oversized image inside is offset so only that cell shows. */
.sprite {
  position: relative;
  display: block;
  overflow: hidden;
  max-width: 100%;
  max-height: 100%;
}
.sprite > img { position: absolute; image-rendering: pixelated; }
.thumb.empty::after { content: "?"; color: var(--text-faint); font: 600 14px var(--mono); }

/* ------------------------------------------------------------------ badges */

.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 5px;
  font: 600 11px/1.5 var(--mono);
  letter-spacing: .02em;
  background: var(--bg-inset);
  color: var(--text-dim);
  white-space: nowrap;
}
/** Readable rarity text: the game hue nudged toward the page's extreme. */
.rarity-text { color: color-mix(in oklab, var(--rarity-mix) var(--rarity-mix-amount), var(--rarity)); }

.badge.rarity {
  color: color-mix(in oklab, var(--rarity-mix) var(--rarity-mix-amount), var(--rarity));
  background: color-mix(in srgb, var(--rarity) 15%, transparent);
}
.badge.element {
  color: var(--elem);
  background: color-mix(in srgb, var(--elem) 16%, transparent);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.badge.element > img { width: 13px; height: 13px; object-fit: contain; }

.e-neutral { --elem: var(--neutral); }
.e-water { --elem: var(--water); }
.e-fire { --elem: var(--fire); }
.e-grass { --elem: var(--grass); }
.e-dark { --elem: var(--dark); }
.e-light { --elem: var(--light); }

/* ----------------------------------------------------------------- filters */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
  padding: 12px 14px;
  margin-bottom: 18px;
  background: var(--bg-raised);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
}
.filter-group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.filter-group > span {
  font: 600 10px/1 var(--mono);
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-faint);
  margin-right: 2px;
}

.chip {
  padding: 4px 10px;
  font: inherit;
  font-size: 13px;
  color: var(--text-dim);
  background: var(--bg-inset);
  border: 1px solid transparent;
  border-radius: 999px;
  cursor: pointer;
}
.chip:hover { color: var(--text); }
.chip[aria-pressed="true"] {
  color: var(--text);
  background: var(--accent-dim);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
}

select.chip { border-radius: 7px; padding: 5px 8px; }

.count { margin-left: auto; font-size: 13px; color: var(--text-faint); }

/* ------------------------------------------------------------------ tables */

.table-wrap { overflow-x: auto; border: 1px solid var(--line-soft); border-radius: var(--radius); }

table { width: 100%; border-collapse: collapse; font-size: 14px; background: var(--bg-raised); }

th, td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--line-soft); white-space: nowrap; }
th {
  position: sticky; top: 0;
  background: var(--bg-inset);
  font: 600 11px/1.6 var(--mono);
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-dim);
  z-index: 1;
}
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th[aria-sort]::after { content: " ▲"; font-size: 9px; }
th[aria-sort="descending"]::after { content: " ▼"; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--bg-inset); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td .with-icon { display: flex; align-items: center; gap: 8px; }
td .with-icon > img { width: 22px; height: 22px; object-fit: contain; flex: none; }
td .with-icon > .sprite { height: 22px; max-width: 22px; flex: none; }

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

.detail-head {
  display: flex;
  gap: 18px;
  align-items: center;
  flex-wrap: wrap;
  padding-bottom: 18px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--line-soft);
}
.detail-head .thumb { width: 84px; height: 84px; border-radius: var(--radius); }
.detail-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

.panels { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }

.panel {
  padding: 14px 16px;
  background: var(--bg-raised);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
}
.panel h3 {
  font: 600 10px/1 var(--mono);
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--text-faint);
  margin-bottom: 11px;
}

.stats { display: grid; gap: 7px; margin: 0; }
.stats > div:not(.bar) { display: flex; align-items: baseline; gap: 10px; justify-content: space-between; }
.stats dt { color: var(--text-dim); font-size: 13px; }
.stats dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 600; }

.stats .bar { margin-top: -4px; }
.bar {
  height: 5px;
  border-radius: 3px;
  background: var(--bg-inset);
  overflow: hidden;
}
.bar > i { display: block; height: 100%; background: var(--accent); }

.pill-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }

.skill { padding: 11px 0; border-top: 1px solid var(--line-soft); }
.skill:first-of-type { border-top: 0; padding-top: 0; }
.skill-head { display: flex; align-items: center; gap: 9px; }
.skill-icon {
  width: 34px; height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  background: var(--bg-inset);
  border-radius: 7px;
  overflow: hidden;
}
.skill-icon > img { width: 100%; height: 100%; object-fit: contain; padding: 2px; }
.skill-icon > .sprite { height: calc(100% - 4px); max-width: calc(100% - 4px); }
.skill-name { font-weight: 600; }
.skill-kind {
  font: 600 10px/1 var(--mono);
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-faint);
  margin-left: 6px;
  white-space: nowrap;
}
.skill-kind.special { color: var(--special); }
.skill-kind.passive { color: var(--passive); }
.skill p { margin: 6px 0 0; font-size: 13px; color: var(--text-dim); }

/* -------------------------------------------------------- status effects */

.status-group {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  margin: 26px 0 12px;
}
.status-group::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line-soft);
}
.status-group.buff { color: var(--buff); }
.status-group.debuff { color: var(--debuff); }

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

.status {
  display: flex;
  gap: 12px;
  padding: 12px;
  background: var(--bg-raised);
  border: 1px solid var(--line-soft);
  /* The group reads off the left edge, so the card itself stays neutral and the
     tint never fights the icon art. */
  border-left: 3px solid var(--group, var(--neutral));
  border-radius: var(--radius);
}
.status.s-buff { --group: var(--buff); }
.status.s-debuff { --group: var(--debuff); }

.status-icon { width: 40px; height: 40px; flex: none; }
.status-body { min-width: 0; }
.status-name { display: block; font-weight: 600; font-size: 14px; }
.status-effects {
  margin: 6px 0 0;
  padding: 0;
  list-style: none;
  font-size: 13px;
  color: var(--text-dim);
}
.status-effects li { padding-left: 11px; position: relative; }
.status-effects li::before {
  content: "";
  position: absolute;
  left: 0;
  top: .55em;
  width: 4px;
  height: 4px;
  border-radius: 1px;
  background: var(--group, var(--text-faint));
}
.status-none { margin: 6px 0 0; font-size: 13px; color: var(--text-faint); }

/* ---------------------------------------------------------------- bastion */

.bastion-rules { margin: 14px 0 26px; }
.bastion-rules .badge { font-size: 12px; padding: 5px 10px; }

/* An upgrade card is a status card whose left edge carries its rarity instead of
   a buff/debuff group. */
.status.s-up { --group: var(--rarity); }
.status.s-up .status-name { display: flex; align-items: baseline; }
.status.s-up > .status-body > .badge { margin: 6px 0 0; }

.upgrade-levels {
  margin: 8px 0 0;
  padding: 0 0 0 20px;
  font-size: 13px;
  color: var(--text-dim);
}
.upgrade-levels li { margin-top: 4px; }
.upgrade-levels li::marker { color: var(--rarity); font: 700 11px var(--mono); }
/* One effect per line: a rank often grants two or three at once. */
.upgrade-levels span { display: block; }

/* Talent ranks: roman numerals read as a column of labels, not as figures. */
td.rank {
  font: 700 12px/1 var(--mono);
  color: var(--accent);
  width: 3.5em;
  letter-spacing: .06em;
}

.ingredients { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.ingredients li { display: flex; align-items: center; gap: 9px; }
.ingredients li > img { width: 26px; height: 26px; object-fit: contain; flex: none; }
.ingredients li > .sprite { height: 26px; max-width: 26px; flex: none; }
.ingredients .amount { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--text-dim); }

.arrow { color: var(--text-faint); }

.chance {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-variant-numeric: tabular-nums;
}
.chance i {
  width: 34px; height: 5px;
  border-radius: 3px;
  background: var(--bg-inset);
  overflow: hidden;
  flex: none;
}
.chance i > b { display: block; height: 100%; background: var(--rare); }

.empty-note { color: var(--text-faint); font-size: 13px; margin: 0; }

.biome-list { display: flex; flex-wrap: wrap; gap: 4px; }

.warn {
  padding: 11px 14px;
  border: 1px solid color-mix(in srgb, var(--legendary) 40%, transparent);
  background: color-mix(in srgb, var(--legendary) 10%, transparent);
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 18px;
}
.warn ul { margin: 6px 0 0; padding-left: 18px; }

/* -------------------------------------------------------------------- home */

.hero { margin-bottom: 26px; }
.hero h1 { font-size: 30px; }

.stat-row {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  margin-bottom: 30px;
}
.stat-tile {
  padding: 14px 16px;
  background: var(--bg-raised);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  color: var(--text);
}
.stat-tile:hover { text-decoration: none; border-color: var(--line); background: var(--bg-inset); }
.stat-tile b { display: block; font-size: 25px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat-tile span {
  font: 600 10px/1 var(--mono);
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--text-faint);
}

/* ------------------------------------------------------------------ footer */

.footer {
  padding: 16px 20px;
  border-top: 1px solid var(--line-soft);
  color: var(--text-faint);
  font-size: 12px;
  text-align: center;
}
.footer code { font-family: var(--mono); }
.sep { margin: 0 6px; }

@media (max-width: 760px) {
  /* Brand + theme share the first row, then search, then the tab strip. */
  .topbar { gap: 10px; padding: 10px 14px; }
  .brand { order: 1; }
  .lang { order: 2; margin-left: auto; }
  .icon-btn { order: 3; }
  .search { order: 4; flex-basis: 100%; }
  .tabs { order: 5; flex-basis: 100%; justify-content: space-between; }
  .tabs a { padding: 7px 9px; }
  main { padding: 18px 14px 44px; }
  th, td { padding: 7px 10px; }
  .detail-head .thumb { width: 64px; height: 64px; }
  h1 { font-size: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

/* Link back out to the marketing site. Not a router tab, so it must not be
   highlighted by the aria-current logic and reads as leaving the app. */
.tabs a.offsite { color: var(--text-faint); font-size: 13px; }
.tabs a.offsite:hover { color: var(--text); background: var(--bg-inset); text-decoration: none; }
