:root {
  color-scheme: dark;
  --bg: #090706;
  --surface: #14100c;
  --surface-raised: #1c1611;
  --line: rgb(199 179 119 / 0.12);
  --line-strong: rgb(199 179 119 / 0.28);
  --text: #e6dccb;
  --muted: #9a8b76;
  --gold: #d9c38a;
  --gold-deep: #a8874a;
  --blood: #b3261b;
  --legendary: #ff8a1f;
  --set: #45e24a;
  --gem: #ff8a1f;
  --radius: 14px;
  --display: 'Cinzel', Georgia, serif;
  --body: 'Inter', system-ui, sans-serif;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(70rem 40rem at 50% -10%, rgb(179 38 27 / 0.22), transparent 70%),
    radial-gradient(50rem 30rem at 50% 110%, rgb(255 138 31 / 0.06), transparent 70%),
    var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--body);
  -webkit-font-smoothing: antialiased;
}

/* Film grain over everything, very faint. */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 100;
  pointer-events: none;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.embers {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  pointer-events: none;
}

button, input { font: inherit; color: inherit; }
:focus-visible, .link-button:has(:focus-visible) { outline: 2px solid var(--gold); outline-offset: 3px; }

.glyph {
  width: 1.15em;
  height: 1.15em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

kbd {
  display: inline-grid;
  place-items: center;
  min-width: 1.4rem;
  height: 1.4rem;
  padding: 0 0.35rem;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 6px;
  font: 500 0.72rem/1 var(--body);
  color: var(--muted);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

/* Quality colours */

.quality-legendary { --quality: var(--legendary); }
.quality-set { --quality: var(--set); }
.quality-gem { --quality: var(--gem); }

/* Top bar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem max(1rem, calc((100% - 1100px) / 2));
  background: rgb(9 7 6 / 0.7);
  backdrop-filter: blur(14px) saturate(140%);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--gold);
  font: 700 1.05rem var(--display);
  letter-spacing: 0.06em;
  text-decoration: none;
}
.brand__mark {
  width: 1.6rem;
  height: 1.6rem;
  fill: rgb(179 38 27 / 0.35);
  stroke: var(--gold);
  stroke-width: 1.5;
  stroke-linejoin: round;
}

.search-trigger {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: min(320px, 50vw);
  padding: 0.5rem 0.6rem 0.5rem 0.9rem;
  background: rgb(255 255 255 / 0.03);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.search-trigger:hover { border-color: var(--gold-deep); background: rgb(255 255 255 / 0.05); }
.search-trigger__label { flex: 1; text-align: left; }

/* Page */

.page {
  flex: 1;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1rem 4rem;
}

.intro {
  padding: clamp(2.5rem, 8vw, 4.5rem) 0 1.75rem;
  text-align: center;
}
.intro h1 {
  margin: 0;
  font: 700 clamp(2.1rem, 7vw, 3.8rem)/1.1 var(--display);
  letter-spacing: 0.02em;
  background: linear-gradient(180deg, #f6e7bd 10%, var(--gold) 45%, var(--gold-deep) 90%);
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 24px rgb(179 38 27 / 0.35));
}
.summary {
  margin: 0.6rem 0 0;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.75rem;
}

/* Filters */

.filters {
  display: flex;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto 2rem;
  padding: 4px;
  gap: 2px;
  overflow-x: auto;
  background: rgb(255 255 255 / 0.03);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.filters[hidden] { display: none; }

.filter {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.6rem 0.45rem 0.95rem;
  background: none;
  border: 0;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: color 0.2s, background 0.2s;
}
.filter:hover { color: var(--text); }
.filter[aria-pressed="true"] {
  color: var(--quality, var(--gold));
  background: var(--surface-raised);
  box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--quality, var(--gold)) 35%, transparent), 0 2px 10px rgb(0 0 0 / 0.4);
}

.count {
  display: inline-grid;
  place-items: center;
  min-width: 1.45rem;
  height: 1.45rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  background: rgb(255 255 255 / 0.06);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.filter[aria-pressed="true"] .count {
  background: color-mix(in oklab, var(--quality, var(--gold)) 18%, transparent);
  color: var(--quality, var(--gold));
}

/* Grid of tiles */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.tile {
  position: relative;
  display: grid;
  grid-template-rows: 1fr auto;
  justify-items: center;
  align-items: center;
  gap: 0.75rem;
  min-height: 220px;
  padding: 1.25rem 0.75rem 1rem;
  overflow: hidden;
  isolation: isolate;
  background:
    radial-gradient(90% 60% at 50% 35%, color-mix(in oklab, var(--quality) 20%, transparent), transparent 70%),
    linear-gradient(180deg, var(--surface-raised), var(--surface));
  border: 1px solid color-mix(in oklab, var(--quality) 30%, #2a2018);
  border-radius: var(--radius);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.05), 0 12px 30px -16px rgb(0 0 0 / 0.9);
  text-align: center;
  view-transition-class: tile;
  transition: translate 0.3s var(--ease), box-shadow 0.3s var(--ease), border-color 0.3s;
}

/* Light sweep on hover. */
.tile::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(115deg, transparent 30%, rgb(255 255 255 / 0.07) 50%, transparent 70%);
  translate: -120% 0;
  transition: translate 0.8s var(--ease);
}

.tile:hover {
  translate: 0 -4px;
  border-color: color-mix(in oklab, var(--quality) 70%, transparent);
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.07),
    0 18px 40px -18px color-mix(in oklab, var(--quality) 70%, transparent),
    0 0 30px -10px color-mix(in oklab, var(--quality) 60%, transparent);
}
.tile:hover::before { translate: 120% 0; }

.tile .icon {
  width: 80px;
  height: 128px;
  filter: drop-shadow(0 8px 12px rgb(0 0 0 / 0.75));
  transition: scale 0.35s var(--ease);
}
.tile:hover .icon { scale: 1.07; }

.tile__caption { display: grid; gap: 0.15rem; }
.tile .item-name {
  color: var(--quality);
  font-weight: 600;
  font-size: 0.92rem;
  line-height: 1.25;
  text-wrap: balance;
}
.item-kind { color: var(--muted); font-size: 0.75rem; }

.tile__remove {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  display: grid;
  place-items: center;
  width: 1.8rem;
  height: 1.8rem;
  background: rgb(0 0 0 / 0.45);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  scale: 0.85;
  transition: opacity 0.2s, scale 0.2s, color 0.2s, border-color 0.2s;
}
.tile:hover .tile__remove, .tile__remove:focus-visible { opacity: 1; scale: 1; }
.tile__remove:hover { color: #ff6b5e; border-color: var(--blood); }
@media (hover: none) { .tile__remove { opacity: 1; scale: 1; } }

.icon { display: block; object-fit: contain; }
.icon--missing {
  display: grid;
  place-items: center;
  color: var(--muted);
  font: 700 1.5rem var(--display);
}

/* Empty state */

.empty {
  display: grid;
  justify-items: center;
  gap: 0.5rem;
  max-width: 460px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: rgb(255 255 255 / 0.015);
  text-align: center;
}
.empty[hidden] { display: none; }
.empty__mark {
  width: 3rem;
  height: 3rem;
  fill: rgb(179 38 27 / 0.2);
  stroke: var(--gold-deep);
  stroke-width: 1.2;
}
.empty__title { margin: 0; color: var(--gold); font: 600 1.25rem var(--display); }
.empty__hint { margin: 0 0 0.75rem; color: var(--muted); }
@media (hover: none) { .tip { display: none; } }

.button {
  padding: 0.65rem 1.4rem;
  border: 1px solid #c9473a;
  border-radius: 999px;
  background: linear-gradient(180deg, #a52a1f, #6e150f);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.18), 0 8px 24px -8px rgb(179 38 27 / 0.7);
  color: #fbeee0;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.2s, translate 0.2s;
}
.button:hover { filter: brightness(1.15); translate: 0 -1px; }

/* Footer */

.footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem 1.25rem;
  padding: 1.5rem 1rem 2rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.85rem;
}
.link-button {
  padding: 0;
  background: none;
  border: 0;
  color: var(--gold);
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: var(--line-strong);
  text-underline-offset: 3px;
}
.link-button:hover { text-decoration-color: var(--gold); }

/* Floating add button (touch screens) */

.fab {
  position: fixed;
  right: 1.25rem;
  bottom: calc(1.25rem + env(safe-area-inset-bottom));
  z-index: 20;
  display: none;
  place-items: center;
  width: 3.5rem;
  height: 3.5rem;
  border: 1px solid #c9473a;
  border-radius: 999px;
  background: linear-gradient(180deg, #b02d21, #6e150f);
  box-shadow: 0 10px 30px -6px rgb(179 38 27 / 0.8), inset 0 1px 0 rgb(255 255 255 / 0.2);
  color: #fbeee0;
  font-size: 1.4rem;
  cursor: pointer;
}

@media (max-width: 640px) {
  .search-trigger { width: auto; padding: 0.55rem; }
  .search-trigger__label, .search-trigger kbd { display: none; }
  .fab { display: grid; }
  .filters { width: 100%; }
  .filter { flex: 1; justify-content: center; gap: 0.35rem; padding: 0.45rem 0.4rem; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 0.75rem; }
  .tile { min-height: 200px; }
  .footer { padding-bottom: 6rem; }
}

/* Search palette */

.palette {
  width: min(640px, calc(100% - 2rem));
  max-height: min(72dvh, 680px);
  margin: 12dvh auto auto;
  padding: 0;
  overflow: hidden;
  background: rgb(22 17 13 / 0.94);
  backdrop-filter: blur(20px);
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  box-shadow: 0 40px 100px -20px #000, 0 0 60px -20px rgb(179 38 27 / 0.45);
  color: var(--text);
}
.palette[open] {
  display: flex;
  flex-direction: column;
  animation: palette-in 0.22s var(--ease);
}
.palette::backdrop {
  background: rgb(5 3 2 / 0.6);
  backdrop-filter: blur(3px);
}
@keyframes palette-in {
  from { opacity: 0; translate: 0 -8px; scale: 0.98; }
}

.palette__field {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--line);
  color: var(--gold-deep);
}
.palette__field input {
  flex: 1;
  min-width: 0;
  padding: 0;
  background: none;
  border: 0;
  outline: none;
  color: var(--text);
  font-size: 1.1rem;
}
.palette__field input::placeholder { color: var(--muted); }
.palette__close {
  padding: 0.2rem 0.5rem;
  background: none;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.72rem;
  cursor: pointer;
}

.palette__results {
  flex: 1;
  margin: 0;
  padding: 0.4rem;
  overflow-y: auto;
  list-style: none;
  overscroll-behavior: contain;
}
.palette__results:empty { display: none; }

.result {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 0.85rem;
  padding: 0.45rem 0.7rem;
  border-radius: 10px;
  cursor: pointer;
}
.result:hover { background: rgb(255 255 255 / 0.035); }
.result[aria-selected="true"] {
  background: linear-gradient(90deg, color-mix(in oklab, var(--quality) 14%, transparent), rgb(255 255 255 / 0.03));
  box-shadow: inset 2px 0 0 var(--quality);
}
.result .icon { width: 44px; height: 56px; filter: drop-shadow(0 3px 5px rgb(0 0 0 / 0.7)); }
.result__label { display: grid; min-width: 0; }
.result .item-name { color: var(--quality); font-weight: 600; }
.item-details {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.marker {
  padding: 0.25rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}
.result[aria-selected="true"] .marker:not(.marker--on-list) { color: var(--text); border-color: var(--line-strong); }
.marker--on-list {
  border-color: color-mix(in oklab, var(--gold) 40%, transparent);
  background: rgb(217 195 138 / 0.1);
  color: var(--gold);
}

.palette__hint {
  margin: 0;
  padding: 2rem 1rem;
  color: var(--muted);
  text-align: center;
}
.palette__hint[hidden] { display: none; }

.palette__keys {
  display: flex;
  gap: 1.25rem;
  padding: 0.6rem 1.1rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.75rem;
}
.palette__keys span { display: flex; align-items: center; gap: 0.3rem; }

@media (max-width: 640px) {
  .palette {
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border: 0;
    border-radius: 0;
    background: var(--surface);
  }
  .palette__keys { display: none; }
}

/* Status toast */

.status {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  z-index: 30;
  translate: -50% 0;
  max-width: calc(100% - 2rem);
  margin: 0;
  padding: 0.7rem 1.1rem;
  background: var(--surface-raised);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  box-shadow: 0 16px 40px -10px #000;
  animation: palette-in 0.22s var(--ease);
}
.status[hidden] { display: none; }
@media (max-width: 640px) {
  .status { bottom: calc(6rem + env(safe-area-inset-bottom)); }
}

/* View transitions: tiles glide to new spots, new ones rise in. */

::view-transition-group(*.tile) { animation-duration: 0.35s; animation-timing-function: var(--ease); }
::view-transition-new(*.tile):only-child { animation: tile-in 0.35s var(--ease); }
::view-transition-old(*.tile):only-child { animation: tile-out 0.25s ease-in forwards; }
@keyframes tile-in { from { opacity: 0; scale: 0.9; translate: 0 10px; } }
@keyframes tile-out { to { opacity: 0; scale: 0.9; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
