/* ===================== Upheaval (in-game item font) ===================== */
@font-face {
  font-family: "Upheaval";
  src: url("upheaval.ttf") format("truetype");
  font-display: block; /* preloaded in <head>; hold headings briefly rather than flashing a fallback (avoids FOUT) */
}

/* ===================== theme tokens ===================== */
:root {
  --bg:        #f5ede0;
  --bg-2:      #efe4d3;
  --panel:     #fffaf1;
  --ink:       #2c2420;
  --muted:     #90806f;
  --accent:    #c65d3b;
  --accent-2:  #e07a52;
  --line:      rgba(198, 93, 59, .30);
  --line-soft: rgba(120, 90, 70, .16);
  --shadow:    rgba(70, 45, 30, .16);
  --tile:      #fff7ec;
  --sheen:     #ffffff;
  --glass:     rgba(255, 250, 241, .70); /* translucent panel for backdrop-blur */
  --glass2:    rgba(245, 237, 224, .62); /* translucent bg for the search bar */

  /* quality scale (0 skip → 4 gold) */
  --q0: #9a8f83;
  --q1: #4a86c5;
  --q2: #3fa66a;
  --q3: #e08a2b;
  --q4: #e0b400;

  --maxw: 1180px;
  color-scheme: light;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg:        #141010;
  --bg-2:      #1b1512;
  --panel:     #211915;
  --ink:       #efe3d2;
  --muted:     #9d8b79;
  --accent:    #e0714a;
  --accent-2:  #f08d63;
  --line:      rgba(224, 113, 74, .32);
  --line-soft: rgba(210, 170, 140, .12);
  --shadow:    rgba(0, 0, 0, .5);
  --tile:      #2a201a;
  --sheen:     rgba(255,255,255,.04);
  --glass:     rgba(31, 24, 20, .64);
  --glass2:    rgba(20, 16, 16, .58);
  --q0: #8b8175;
  --q1: #5c9bda;
  --q2: #4fbb7d;
  --q3: #f0982f;
  --q4: #f2c218;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    color-scheme: dark;
    --bg:#141010; --bg-2:#1b1512; --panel:#211915; --ink:#efe3d2; --muted:#9d8b79;
    --accent:#e0714a; --accent-2:#f08d63; --line:rgba(224,113,74,.32);
    --line-soft:rgba(210,170,140,.12); --shadow:rgba(0,0,0,.5); --tile:#2a201a; --sheen:rgba(255,255,255,.04);
    --q0:#8b8175; --q1:#5c9bda; --q2:#4fbb7d; --q3:#f0982f; --q4:#f2c218;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  background-image:
    radial-gradient(rgba(120,90,70,.05) 1px, transparent 1px);
  background-size: 4px 4px;
  padding-bottom: 60px; /* fallback; JS sets this to the live tray height */
  line-height: 1.45;
  overflow-x: hidden;
}
.display { font-family: "Upheaval", ui-sans-serif, system-ui, sans-serif; letter-spacing: .5px; }
img { image-rendering: pixelated; image-rendering: crisp-edges; }
a { color: var(--accent); }

/* ===================== header ===================== */
.topbar {
  max-width: var(--maxw); margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) 16px 8px;
  border-bottom: 3px solid var(--accent);
  display: flex; flex-direction: column; gap: 8px;
}
.brandrow { display: flex; align-items: center; gap: 10px; }
.title-box {
  border: 2.5px solid var(--accent); border-radius: 8px;
  padding: 1px 12px 3px; background: var(--panel);
  box-shadow: 2px 2px 0 var(--line); flex: 0 0 auto;
}
.title-box h1 {
  font-family: "Upheaval", sans-serif; margin: 0; font-size: 24px; font-weight: 400;
  color: var(--accent); letter-spacing: 1px; line-height: 1.25;
}
.tagline {
  color: var(--muted); font-size: 13px;
  flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dlc-group { display: flex; gap: 6px; flex-wrap: wrap; }
.linkbtn {
  font: inherit; font-size: 14px; text-decoration: none;
  color: var(--muted); background: none; border: none; cursor: pointer;
  padding: 6px 8px; border-radius: 6px;
}
.linkbtn:hover { color: var(--accent); background: var(--line-soft); }
.themebtn { font-size: 17px; line-height: 1; width: 34px; text-align: center; }

/* dlc chips */
.chip {
  font: inherit; font-size: 12.5px; cursor: pointer;
  border: 1.5px solid var(--line); background: var(--panel); color: var(--muted);
  padding: 5px 10px; border-radius: 999px; display: inline-flex; align-items: center; gap: 6px;
  transition: all .12s ease; white-space: nowrap;
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; opacity: .5; }
.chip[aria-pressed="true"] { color: var(--ink); border-color: var(--accent); background: var(--tile); }
.chip[aria-pressed="true"] .dot { background: var(--accent); opacity: 1; }
.chip.locked { position: relative; }

/* ===================== search ===================== */
.searchwrap {
  position: sticky; top: env(safe-area-inset-top); z-index: 30;
  background: var(--bg);
  padding: 10px 16px 8px;
}
@supports ((backdrop-filter: blur(2px)) or (-webkit-backdrop-filter: blur(2px))) {
  .searchwrap {
    background: var(--glass2);
    -webkit-backdrop-filter: blur(12px) saturate(1.3);
    backdrop-filter: blur(12px) saturate(1.3);
  }
}
/* glass over the iOS top safe-area so content blurs as it scrolls up into the notch / status-bar gutter */
.top-gutter { position: fixed; top: 0; left: 0; right: 0; height: env(safe-area-inset-top); z-index: 31; pointer-events: none; }
@supports ((backdrop-filter: blur(2px)) or (-webkit-backdrop-filter: blur(2px))) {
  .top-gutter { background: var(--glass2); -webkit-backdrop-filter: blur(12px) saturate(1.3); backdrop-filter: blur(12px) saturate(1.3); }
}
.searchbar {
  max-width: var(--maxw); margin: 0 auto;
  display: flex; align-items: center; gap: 10px;
  border: 3px solid var(--accent); border-radius: 12px;
  background: var(--panel); padding: 10px 16px;
  box-shadow: 3px 3px 0 var(--line);
}
.search-ico { opacity: .7; font-size: 16px; }
#search {
  flex: 1; font: inherit; font-size: 17px; border: none; outline: none;
  background: transparent; color: var(--ink); min-width: 0;
}
#search::placeholder { color: var(--muted); }
.controls {
  max-width: var(--maxw); margin: 8px auto 0;
  display: flex; align-items: center; gap: 6px 10px; flex-wrap: wrap;
}
/* type + sort + group on one line; scroll horizontally when they don't fit */
.controls-scroll {
  display: flex; align-items: center; gap: 10px;
  flex: 1 1 auto; min-width: 0; overflow-x: auto;
  padding-bottom: 2px; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.controls-scroll::-webkit-scrollbar { display: none; }
.controls-scroll > * { flex: 0 0 auto; } /* keep natural widths and scroll, don't shrink */
.segmented { display: inline-flex; border: 1.5px solid var(--line); border-radius: 8px; overflow: hidden; }
.segmented button {
  font: inherit; font-size: 12.5px; border: none; background: var(--panel); color: var(--muted);
  padding: 5px 11px; cursor: pointer; border-right: 1px solid var(--line-soft);
}
.segmented button:last-child { border-right: none; }
.segmented button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.ctl { display: inline-flex; align-items: center; gap: 6px; }
.ctl-lbl { color: var(--muted); font-size: 12px; }
.groupchk { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12.5px; cursor: pointer; }
.groupchk input { accent-color: var(--accent); cursor: pointer; }
.count { color: var(--muted); font-size: 12.5px; margin-left: auto; flex: 0 0 auto; white-space: nowrap; }

/* ===================== catalog ===================== */
#catalog { max-width: var(--maxw); margin: 4px auto 0; padding: 0 18px; }
.section { margin-top: 10px; }
.section-head {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-2);
  border-radius: 8px; padding: 6px 12px; margin-bottom: 10px;
  border-left: 5px solid var(--accent);
  box-shadow: 0 1px 0 var(--line-soft);
}
.section-head h2 {
  font-family: "Upheaval", sans-serif; font-weight: 400; margin: 0;
  font-size: 19px; color: var(--ink); letter-spacing: .5px; line-height: 1.4;
}
.section-head .sec-count { color: var(--muted); font-size: 12.5px; }
.section-head .qbar { width: 26px; height: 8px; border-radius: 3px; }

.grid {
  display: grid; gap: 8px;
  grid-template-columns: repeat(auto-fill, 72px);
  justify-content: start;
  margin-bottom: 18px;
}
.tile {
  position: relative; width: 72px; height: 72px; border: 0; cursor: pointer; padding: 4px;
  background: var(--tile); border-radius: 9px;
  box-shadow: inset 0 0 0 1px var(--line-soft);
  display: flex; align-items: center; justify-content: center;
  transition: transform .08s ease, box-shadow .08s ease;
}
.tile:hover, .tile:focus-visible {
  transform: translateY(-2px);
  box-shadow: inset 0 0 0 1px var(--line-soft), 0 4px 10px var(--shadow), 0 0 0 2px var(--accent);
  outline: none;
  z-index: 5; /* above sibling tiles, but below the search bar (30) and tray (40) */
}
.tile img { width: 64px; height: 64px; object-fit: contain; pointer-events: none; }
.tile.pinned { box-shadow: inset 0 0 0 2px var(--accent); }
.tile.trinket { border-radius: 999px 999px 12px 12px; } /* subtle shape cue for trinkets */

/* hover name bubble */
.tile::after {
  content: attr(data-name); position: absolute; bottom: calc(100% + 4px); left: 50%;
  transform: translateX(-50%) scale(.96); transform-origin: bottom center;
  background: var(--ink); color: var(--bg); font-size: 11px; white-space: nowrap;
  padding: 3px 7px; border-radius: 5px; opacity: 0; pointer-events: none;
  transition: opacity .1s ease; z-index: 20; max-width: 180px; overflow: hidden; text-overflow: ellipsis;
}
.tile:hover::after, .tile:focus-visible::after { opacity: .96; }

.empty-poop { display: flex; justify-content: center; padding: 40px 0 20px; }
.empty-poop img {
  width: 176px; height: 176px; image-rendering: pixelated; opacity: .92;
  filter: drop-shadow(0 8px 14px var(--shadow));
  animation: poop-bob 3.2s ease-in-out infinite;
}
@keyframes poop-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@media (prefers-reduced-motion: reduce) { .empty-poop img { animation: none; } }
.empty-poop.clickable { cursor: pointer; }
.empty-poop.clickable img { transition: filter .12s ease, transform .12s ease; }
.empty-poop.clickable:hover img { filter: drop-shadow(0 8px 16px var(--shadow)) brightness(1.08); }

/* ===================== results tray ===================== */
.tray {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  max-height: 48vh; /* hug content, but never eat more than half the screen */
  background: var(--panel);
  border-top: 3px solid var(--accent);
  box-shadow: 0 -6px 20px var(--shadow);
  padding-bottom: env(safe-area-inset-bottom);
}
@supports ((backdrop-filter: blur(2px)) or (-webkit-backdrop-filter: blur(2px))) {
  .tray {
    background: var(--glass);
    -webkit-backdrop-filter: blur(16px) saturate(1.4);
    backdrop-filter: blur(16px) saturate(1.4);
  }
}
.tray[hidden] { display: none; } /* no results / no pins -> no tray */
.tray-head {
  display: flex; align-items: center; gap: 10px; padding: 9px 18px 3px;
  max-width: var(--maxw); margin: 0 auto;
}
.tray-title {
  font-family: "Upheaval", sans-serif; font-size: 16px; color: var(--accent);
  line-height: 1.6; padding-top: 1px; /* the display font's tall glyphs need vertical room */
}
.tray-clear {
  margin-left: auto; font: inherit; font-size: 12.5px; color: var(--muted);
  background: none; border: 1.5px solid var(--line); border-radius: 6px; padding: 3px 10px; cursor: pointer;
}
.tray-clear:hover { color: var(--accent); border-color: var(--accent); }
.tray-scroll {
  display: flex; align-items: flex-start; gap: 12px; overflow-x: auto; overflow-y: hidden;
  padding: 4px 18px 16px; scroll-snap-type: x proximity;
  max-width: var(--maxw); margin: 0 auto;
}
.tray-scroll::-webkit-scrollbar { height: 8px; }
.tray-scroll::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

/* big item card */
.card {
  flex: 0 0 auto; width: 320px; max-width: 82vw;
  display: grid; grid-template-columns: 68px 1fr; gap: 12px;
  background: var(--tile); border: 2px solid var(--line);
  border-radius: 12px; padding: 12px; scroll-snap-align: start;
  position: relative;
  max-height: calc(48vh - 56px); overflow-y: auto; /* long descriptions scroll inside the card */
}
.card .art {
  width: 64px; height: 64px; display: flex; align-items: center; justify-content: center;
  background: var(--bg-2); border-radius: 8px;
}
.card .art img { width: 56px; height: 56px; object-fit: contain; }
.card .cname { font-family: "Upheaval", sans-serif; font-size: 18px; color: var(--ink); line-height: 1.3; margin-right: 18px; }
.card .badges { display: flex; flex-wrap: wrap; gap: 5px; margin: 6px 0; }
.badge { font-size: 10.5px; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--line);
  color: var(--muted); text-transform: capitalize; }
.badge.q { color: #fff; border: none; font-weight: 700; background: var(--qc); }
.badge.type { border-color: var(--accent); color: var(--accent); }
.badge.dlc { background: var(--bg-2); }
.card .desc { font-size: 13px; color: var(--ink); }
.card .stats { font-size: 11.5px; color: var(--muted); margin-top: 5px; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.card .stats b { color: var(--accent); font-weight: 600; }
.card .xf { font-size: 11px; color: var(--muted); margin-top: 4px; }
.card .pools { font-size: 11px; color: var(--muted); margin-top: 5px; }
.card .pools b { color: var(--ink); font-weight: 600; }
.card .pools .pool { display: inline-block; background: var(--bg-2); border-radius: 5px; padding: 0 6px; margin: 2px 3px 0 0; }
.card .close {
  position: absolute; top: 6px; right: 8px; border: none; background: none; cursor: pointer;
  color: var(--muted); font-size: 18px; line-height: 1; padding: 2px 4px; border-radius: 4px;
}
.card .close:hover { color: var(--accent); background: var(--line-soft); }

/* ===================== responsive ===================== */
@media (max-width: 640px) {
  .tray { max-height: 56vh; }
  .card { max-height: calc(56vh - 56px); }
  .searchwrap { padding: 8px 12px 6px; }
  #catalog { padding: 0 12px; }
  .grid { gap: 6px; justify-content: center; }
  .card { width: 78vw; }
  /* touch: no hover bubbles */
  .tile::after { display: none; }
}
@media (hover: none) {
  .tile:hover { transform: none; }
}
