:root {
  --bg: #0f1115;
  --bg-soft: #151922;
  --panel: #181d27;
  --panel-2: #1e2430;
  --line: #262d3b;
  --text: #e7ecf3;
  --muted: #8b95a7;
  --accent: #d9a441;
  --accent-soft: rgba(217, 164, 65, 0.14);
  --good: #5fcf80;
  --bad: #ff6b6b;
  --radius: 14px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);

  /* rarity colours (match the in-game rank palette) */
  --r-default: #9d9d9d;
  --r-newbie: #6ec26e;
  --r-stalker: #3fa9f5;
  --r-veteran: #b768f2;
  --r-master: #ff9d2e;
  --r-legend: #ffd23f;
  --r-quest: #d9d9d9;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  background-image: radial-gradient(1200px 500px at 50% -10%, rgba(217, 164, 65, 0.08), transparent 70%);
}

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.app {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 12px calc(24px + env(safe-area-inset-bottom));
}

/* ------------------------------------------------------------------ header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 0 8px;
  position: sticky;
  top: 0;
  z-index: 20;
  background: linear-gradient(var(--bg) 75%, rgba(15, 17, 21, 0));
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 34px; height: 34px; flex: 0 0 34px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: var(--accent-soft);
  border: 1px solid rgba(217, 164, 65, 0.35);
  color: var(--accent);
  font-size: 18px;
}
.brand-text { display: flex; flex-direction: column; font-weight: 650; letter-spacing: 0.2px; }
.brand-text small { font-weight: 500; color: var(--muted); font-size: 11px; letter-spacing: 1.2px; }

.region select {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  font-weight: 600;
  min-height: 40px;
}

/* ------------------------------------------------------------------ search */
.searchbar { position: sticky; top: calc(52px + env(safe-area-inset-top)); z-index: 19; padding-bottom: 8px;
  background: linear-gradient(var(--bg) 70%, rgba(15, 17, 21, 0)); }
.search-field { position: relative; display: flex; align-items: center; }
.search-icon { position: absolute; left: 12px; color: var(--muted); font-size: 18px; pointer-events: none; }
#search-input {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  padding: 12px 40px 12px 38px;
  font-size: 16px; /* >=16px prevents iOS zoom on focus */
  outline: none;
}
#search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
#search-input::-webkit-search-cancel-button { display: none; }
.clear-btn {
  position: absolute; right: 6px;
  background: transparent; border: 0; color: var(--muted);
  width: 32px; height: 32px; border-radius: 8px;
}
.clear-btn:active { background: var(--panel-2); }

/* ------------------------------------------------------------------ banners */
.banner {
  border-radius: 12px;
  padding: 10px 12px;
  margin: 4px 0 12px;
  font-size: 13px;
  border: 1px solid var(--line);
  background: var(--panel);
}
.banner code { background: var(--panel-2); padding: 1px 5px; border-radius: 5px; font-size: 12px; }
.banner-error { border-color: rgba(255, 107, 107, 0.45); background: rgba(255, 107, 107, 0.1); color: #ffc9c9; }

/* ------------------------------------------------------------------ generic */
.view { padding-top: 4px; }
.section-title {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  font-size: 12px; letter-spacing: 1px; text-transform: uppercase;
  color: var(--muted); margin: 14px 2px 8px;
}
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; line-height: 1.6; }
.empty b { color: var(--text); display: block; margin-bottom: 6px; font-size: 16px; }

.skeleton { background: linear-gradient(90deg, var(--panel) 25%, var(--panel-2) 37%, var(--panel) 63%);
  background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: 10px; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* ------------------------------------------------------------------ item list */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 13px;
  min-height: 36px;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.chip .count { color: var(--muted); font-size: 11px; }
.chip.on .count { color: inherit; }

.item-list { display: flex; flex-direction: column; gap: 8px; }
.item-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--r-default);
  border-radius: var(--radius);
  padding: 10px 12px;
  min-height: 62px;
  transition: transform 0.08s ease;
}
.item-row:active { transform: scale(0.99); background: var(--panel-2); }
.item-row[data-color="RANK_NEWBIE"] { border-left-color: var(--r-newbie); }
.item-row[data-color="RANK_STALKER"] { border-left-color: var(--r-stalker); }
.item-row[data-color="RANK_VETERAN"] { border-left-color: var(--r-veteran); }
.item-row[data-color="RANK_MASTER"] { border-left-color: var(--r-master); }
.item-row[data-color="RANK_LEGEND"] { border-left-color: var(--r-legend); }
.item-row[data-color="QUEST_ITEM"] { border-left-color: var(--r-quest); }

.item-icon {
  width: 42px; height: 42px; flex: 0 0 42px;
  border-radius: 10px; background: var(--panel-2);
  object-fit: contain; image-rendering: auto;
}
.item-main { min-width: 0; flex: 1 1 auto; }
.item-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-sub { color: var(--muted); font-size: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.item-id { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; color: var(--muted); }
.chevron { color: var(--muted); font-size: 18px; }

/* ------------------------------------------------------------------ item page */
.back-btn {
  background: transparent; border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 12px; min-height: 38px; margin-bottom: 10px;
}
.hero {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px;
}
.hero .item-icon { width: 68px; height: 68px; flex: 0 0 68px; }
.hero-title { font-size: 18px; font-weight: 700; margin: 0 0 4px; }
.hero-sub { color: var(--muted); font-size: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  border-radius: 999px; padding: 2px 8px; font-size: 11px;
  border: 1px solid currentColor;
}
.hero-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.btn {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 8px 12px; min-height: 38px; font-size: 13px;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:active { background: #232a38; }
.btn.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.stat-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 12px 0; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.stat .label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; }
.stat .value { font-size: 15px; font-weight: 650; margin-top: 2px; word-break: break-word; }

.tabs { display: flex; gap: 6px; margin: 6px 0 10px; }
.tab {
  flex: 1 1 0; text-align: center;
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
  border-radius: 10px; padding: 10px 6px; min-height: 42px; font-weight: 600; font-size: 14px;
}
.tab.on { color: var(--text); border-color: var(--accent); background: var(--accent-soft); }

.controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.controls select {
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 8px; min-height: 38px; font-size: 13px;
}
.spacer { flex: 1 1 auto; }

.lot {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; display: grid; grid-template-columns: auto 1fr auto; gap: 4px 10px; align-items: center;
}
.lot + .lot { margin-top: 8px; }
.lot .amount {
  background: var(--panel-2); border-radius: 8px; padding: 6px 8px;
  font-size: 12px; color: var(--muted); text-align: center; min-width: 44px;
}
.lot .amount b { display: block; color: var(--text); font-size: 14px; }
.lot .price { font-weight: 700; font-size: 16px; }
.lot .unit { color: var(--muted); font-size: 12px; }
.lot .time { text-align: right; color: var(--muted); font-size: 12px; }
.lot .tags { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; }
.time.soon { color: var(--accent); }
.time.ended { color: var(--bad); }

.chart-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 12px; }
.chart-card svg { width: 100%; height: 120px; display: block; }
.chart-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; margin-top: 4px; }

.sale { display: flex; justify-content: space-between; gap: 10px; padding: 9px 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.sale + .sale { margin-top: 6px; }
.sale .when { color: var(--muted); font-size: 12px; text-align: right; }
.sale .p { font-weight: 650; }
.delta.up { color: var(--bad); }
.delta.down { color: var(--good); }
.delta.flat { color: var(--muted); }

.more-btn { width: 100%; margin-top: 10px; justify-content: center; }

/* ------------------------------------------------------------------ misc */
.footer { color: #5d6675; font-size: 11px; text-align: center; margin-top: 24px; line-height: 1.6; }
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #232a38; color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 14px; font-size: 13px; box-shadow: var(--shadow);
  z-index: 50; max-width: calc(100% - 32px);
}
.toast[hidden] { display: none; }

@media (min-width: 560px) {
  .item-list { display: grid; grid-template-columns: 1fr 1fr; }
  .stat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
