  /* =========================================================================
     RARITY TIERS — slot-style визуальные тиры для inv/market карточек.
     Класс .rarity-<tier> добавляется в JS (invTypeRarity → rarities.js).
     Каждый тир задаёт CSS custom props (--rarity-*), которые подхватывают
     общие стили .inv-card / .market-card. Legendary + ultimate получают
     holographic ::after оверлей (только на hover для не-ultimate, чтобы
     не тратить GPU на статичных гридах).
     ========================================================================= */
  .inv-card.rarity-common, .market-card.rarity-common {
    --rarity-color: #a8b0b8;
    --rarity-color-soft: rgba(168,176,184,0.45);
    --rarity-color-hover: rgba(168,176,184,0.85);
    --rarity-glow: rgba(168,176,184,0.18);
    --rarity-glow-hover: rgba(168,176,184,0.28);
    --rarity-tint: rgba(168,176,184,0.04);
  }
  .inv-card.rarity-rare, .market-card.rarity-rare {
    --rarity-color: #5fa8d3;
    --rarity-color-soft: rgba(95,168,211,0.55);
    --rarity-color-hover: rgba(95,168,211,0.95);
    --rarity-glow: rgba(95,168,211,0.30);
    --rarity-glow-hover: rgba(95,168,211,0.50);
    --rarity-tint: rgba(95,168,211,0.08);
  }
  .inv-card.rarity-epic, .market-card.rarity-epic {
    --rarity-color: #a37fd3;
    --rarity-color-soft: rgba(163,127,211,0.55);
    --rarity-color-hover: rgba(163,127,211,0.95);
    --rarity-glow: rgba(163,127,211,0.35);
    --rarity-glow-hover: rgba(163,127,211,0.55);
    --rarity-tint: rgba(163,127,211,0.10);
  }
  .inv-card.rarity-legendary, .market-card.rarity-legendary {
    --rarity-color: #d9a062;
    --rarity-color-soft: rgba(217,160,98,0.60);
    --rarity-color-hover: rgba(217,160,98,1);
    --rarity-glow: rgba(217,160,98,0.45);
    --rarity-glow-hover: rgba(217,160,98,0.65);
    --rarity-tint: rgba(217,160,98,0.12);
  }
  .inv-card.rarity-ultimate, .market-card.rarity-ultimate {
    --rarity-color: #7af5ff;
    --rarity-color-alt: #ff5fa8;
    --rarity-color-soft: rgba(180,160,220,0.70);
    --rarity-color-hover: rgba(220,200,255,1);
    --rarity-glow: rgba(122,245,255,0.45);
    --rarity-glow-alt: rgba(255,95,168,0.40);
    --rarity-glow-hover: rgba(180,180,255,0.65);
    --rarity-tint: rgba(180,140,220,0.14);
  }

  /* Apply rarity-color to base inv/market card — gradient-tinted bg, coloured
     border, soft outer glow. Existing per-type overrides (.ad_package etc.)
     still control the icon hue; rarity controls the frame. */
  .inv-card[class*="rarity-"], .market-card[class*="rarity-"] {
    border-color: var(--rarity-color-soft);
    background:
      radial-gradient(120% 70% at 50% 100%, var(--rarity-tint), transparent 70%),
      var(--surface);
    box-shadow:
      var(--shadow-card),
      0 0 0 1px transparent,
      0 4px 14px var(--rarity-glow);
  }
  .inv-card[class*="rarity-"]:hover, .market-card[class*="rarity-"]:hover {
    border-color: var(--rarity-color-hover);
    box-shadow:
      var(--shadow-card),
      0 0 0 1px var(--rarity-color-soft),
      0 6px 22px var(--rarity-glow-hover);
  }

  /* Holographic sheen for legendary — appears on hover. Uses conic-gradient
     under mix-blend-mode:screen — GPU-cheap, single composite layer. */
  .inv-card.rarity-legendary, .market-card.rarity-legendary { position: relative; overflow: hidden; }
  .inv-card.rarity-legendary::after, .market-card.rarity-legendary::after {
    content: '';
    position: absolute; inset: 0;
    border-radius: inherit;
    pointer-events: none;
    background: conic-gradient(from 200deg at 30% 20%,
      transparent 0deg,
      rgba(255,225,160,0.18) 70deg,
      transparent 140deg,
      transparent 220deg,
      rgba(217,160,98,0.14) 300deg,
      transparent 360deg);
    mix-blend-mode: screen;
    opacity: 0;
    transition: opacity 0.28s ease;
    z-index: 1;
  }
  .inv-card.rarity-legendary:hover::after,
  .market-card.rarity-legendary:hover::after { opacity: 1; }

  /* Ultimate — двухцветная плазма + лёгкий вечный pulse (только этот тир,
     ради «слотовой» вершины). conic-gradient крутится опционально на hover,
     но базовый glow всегда живой. */
  .inv-card.rarity-ultimate, .market-card.rarity-ultimate {
    position: relative; overflow: hidden;
    animation: rarity-ultimate-pulse 3.2s ease-in-out infinite;
  }
  .inv-card.rarity-ultimate::after, .market-card.rarity-ultimate::after {
    content: '';
    position: absolute; inset: -25%;
    border-radius: inherit;
    pointer-events: none;
    background: conic-gradient(from 0deg,
      rgba(122,245,255,0.22) 0deg,
      transparent 80deg,
      rgba(201,126,216,0.20) 160deg,
      transparent 240deg,
      rgba(255,95,168,0.22) 320deg,
      rgba(122,245,255,0.22) 360deg);
    mix-blend-mode: screen;
    opacity: 0.55;
    transition: opacity 0.25s ease;
    z-index: 1;
    animation: rarity-ultimate-spin 14s linear infinite;
  }
  .inv-card.rarity-ultimate:hover::after,
  .market-card.rarity-ultimate:hover::after { opacity: 0.85; }

  @keyframes rarity-ultimate-pulse {
    0%, 100% {
      box-shadow:
        var(--shadow-card),
        0 0 0 1px rgba(122,245,255,0.30),
        0 4px 14px rgba(122,245,255,0.35);
    }
    50% {
      box-shadow:
        var(--shadow-card),
        0 0 0 1px rgba(255,95,168,0.40),
        0 6px 22px rgba(255,95,168,0.45);
    }
  }
  @keyframes rarity-ultimate-spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
  }

  /* Keep inner card content (icon, badges, info-btn) above the sheen layer. */
  .inv-card[class*="rarity-"] > *, .market-card[class*="rarity-"] > * { position: relative; z-index: 2; }

  /* Inventory (Minecraft-style stackable cards) */
  .inv-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 12px;
  }
  .inv-card {
    aspect-ratio: 1 / 1;
    position: relative;
    display: grid; place-items: center;
    border-radius: var(--r-md);
    border: 1px solid var(--border-2);
    background:
      linear-gradient(180deg, rgba(255,220,180,0.025), transparent 40%),
      var(--surface);
    box-shadow: var(--shadow-card);
    cursor: pointer;
    color: var(--text);
    transition: border-color 0.15s ease, transform 0.12s ease;
  }
  .inv-card:hover { border-color: rgba(110,150,135,0.45); transform: translateY(-2px); }
  .inv-card .inv-icon { color: #9ec2b3; }
  .inv-card .inv-icon svg { width: 42px; height: 42px; display: block; }
  .inv-card .inv-count {
    position: absolute;
    right: 8px; bottom: 6px;
    font-size: 18px; font-weight: 700;
    color: var(--text);
    text-shadow: 0 1px 2px rgba(0,0,0,0.6);
    pointer-events: none;
  }
  /* Icon hue: все ad_package_* тиры используют золотистый рупор. Тир
     различается рамкой/glow'ом, см. .rarity-* выше. */
  .inv-card.ad_package_common    .inv-icon,
  .inv-card.ad_package_rare      .inv-icon,
  .inv-card.ad_package_epic      .inv-icon,
  .inv-card.ad_package_legendary .inv-icon,
  .inv-card.ad_package_ultimate  .inv-icon { color: #d6c89a; }
  .inv-card.game_link .inv-icon { color: #b6d8c8; }

  /* Top-center "running" chip — single number showing the most relevant
     remaining resource for any active applied records of this item type.
     No prose labels — just the digit, colour-coded by resource kind. */
  .inv-card .inv-running {
    position: absolute;
    left: 50%; top: 6px;
    transform: translateX(-50%);
    min-width: 28px;
    text-align: center;
    font-size: 13px; font-weight: 800; font-variant-numeric: tabular-nums;
    letter-spacing: 0.3px;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(20, 50, 42, 0.85);
    border: 1px solid rgba(110,180,160,0.5);
    color: #c6efde;
    pointer-events: none;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 5;
    box-shadow: 0 2px 6px rgba(0,0,0,0.45);
  }
  /* Per-kind colour. Budget = gold (ad-budget = плюсики), usages = magenta
     (one-shot), time-d = teal (days), time-h = sky (hours), time-m = amber
     (minutes ≈ running out). */
  .inv-card .inv-running.kind-budget {
    color: #ffe9a8; background: rgba(60, 45, 14, 0.9); border-color: rgba(220,180,80,0.6);
  }
  .inv-card .inv-running.kind-usages {
    color: #f0c6ec; background: rgba(60, 22, 60, 0.85); border-color: rgba(200,120,200,0.5);
  }
  .inv-card .inv-running.kind-time-d {
    color: #b6efe0; background: rgba(20, 50, 48, 0.85); border-color: rgba(110,200,180,0.5);
  }
  .inv-card .inv-running.kind-time-h {
    color: #b6dbef; background: rgba(20, 36, 56, 0.85); border-color: rgba(110,160,210,0.5);
  }
  .inv-card .inv-running.kind-time-m {
    color: #ffd49a; background: rgba(60, 36, 14, 0.9); border-color: rgba(220,150,80,0.6);
  }
  .inv-card.is-running { border-color: rgba(110,180,160,0.55); }
  .inv-card.is-running .inv-icon {
    filter: drop-shadow(0 0 4px rgba(140,210,180,0.45));
  }

  /* Info button — center-bottom, visible on card hover. Opens detail popover.
     Applies to both inventory (.inv-card) and marketplace (.market-card) cards. */
  .inv-card .inv-info-btn,
  .market-card .inv-info-btn {
    position: absolute;
    left: 50%; bottom: 6px;
    transform: translate(-50%, 4px);
    width: 24px; height: 24px;
    display: grid; place-items: center;
    border-radius: 50%;
    border: 1px solid rgba(150,170,200,0.4);
    background: rgba(20, 30, 40, 0.72);
    color: #cdd9e6;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease, transform 0.18s ease, background 0.12s ease, color 0.12s ease;
    z-index: 6;
    padding: 0;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
  }
  .inv-card:hover .inv-info-btn,
  .market-card:hover .inv-info-btn {
    opacity: 0.9;
    pointer-events: auto;
    transform: translate(-50%, 0);
  }
  .inv-card .inv-info-btn:hover,
  .market-card .inv-info-btn:hover {
    opacity: 1;
    background: rgba(40, 55, 75, 0.95);
    color: #fff;
  }
  .inv-card .inv-info-btn:active,
  .market-card .inv-info-btn:active { transform: translate(-50%, 1px); }
  .inv-card .inv-info-btn svg,
  .market-card .inv-info-btn svg { width: 13px; height: 13px; display: block; }

  /* Touch devices: info button is unreachable when hover:none (opacity:0).
     Reveal it and expand to a 44px tap target via padding (the visual 24px circle
     stays; extra padding is invisible but hittable). Transform is frozen at the
     visible position (no translateY translate needed). */
  @media (hover: none) {
    .inv-card .inv-info-btn,
    .market-card .inv-info-btn {
      opacity: 0.9;
      pointer-events: auto;
      transform: translate(-50%, 0);
      min-width: 44px; min-height: 44px;
    }
  }

  /* Detail popover styling. */
  .info-pop {
    color: var(--text);
    display: flex; flex-direction: column; gap: 8px;
    font-size: 12.5px; line-height: 1.4;
  }
  .info-pop .info-head { display: flex; align-items: center; gap: 10px; }
  .info-pop .info-icon { width: 28px; height: 28px; display: inline-grid; place-items: center; color: #d6c89a; }
  .info-pop .info-icon svg { width: 26px; height: 26px; display: block; }
  .info-pop .info-icon.ad_package_common,
  .info-pop .info-icon.ad_package_rare,
  .info-pop .info-icon.ad_package_epic,
  .info-pop .info-icon.ad_package_legendary,
  .info-pop .info-icon.ad_package_ultimate { color: #d6c89a; }
  .info-pop .info-icon.game_link           { color: #b6d8c8; }
  .info-pop .info-title { font-size: 14px; font-weight: 700; color: #f3ead0; }
  /* Rarity flourish — gem + gradient-text tier label. Colours come inline from
     the tier scheme (rarities.js); here we only style structure/typography. */
  .info-pop .info-rarity {
    display: inline-flex; align-items: center; gap: 6px;
    align-self: flex-start; margin-top: -2px;
  }
  .info-pop .info-rarity-gem {
    width: 9px; height: 9px; border-radius: 2px;
    transform: rotate(45deg); flex: none;
  }
  .info-pop .info-rarity-cap {
    font-size: 10px; font-weight: 700; letter-spacing: 0.09em;
    text-transform: uppercase; color: var(--muted);
  }
  .info-pop .info-rarity-label {
    font-size: 12px; font-weight: 800; letter-spacing: 0.03em;
    -webkit-background-clip: text; background-clip: text;
    -webkit-text-fill-color: transparent; color: transparent;
  }
  .info-pop .info-summary { color: var(--muted); font-size: 12px; }
  .info-pop .info-bullets {
    margin: 0; padding-left: 18px;
    color: var(--text);
  }
  .info-pop .info-bullets li { margin-bottom: 3px; }
  .info-pop .info-status {
    border-top: 1px solid var(--border-2);
    padding-top: 8px;
    display: flex; flex-direction: column; gap: 4px;
    font-size: 12px;
  }
  .info-pop .info-row { color: var(--text); }
  .info-pop .info-row.dim { color: var(--muted); font-size: 11px; }
  .info-pop .info-row b { color: #f3ead0; }
  .info-pop .info-link {
    color: #b6e0d0;
    text-decoration: none;
    border-bottom: 1px dashed rgba(180,220,200,0.4);
    cursor: pointer;
    transition: color 0.12s ease, border-color 0.12s ease;
  }
  .info-pop .info-link:hover {
    color: #d8efe5;
    border-bottom-color: rgba(180,220,200,0.9);
  }
  .info-pop .dim { color: var(--muted); }

  /* Variety types — subtle hue shifts off the same warm-green palette so they
     stay visually distinct without introducing new CSS variables. */

  /* Sell-button on inventory cards (top-left, gold-tinted) */
  .inv-card .sell-btn {
    position: absolute;
    left: 8px; top: 8px;
    width: 26px; height: 26px;
    display: grid; place-items: center;
    border-radius: 50%;
    border: 1px solid rgba(160,140,40,0.45);
    background: rgba(40, 30, 8, 0.75);
    color: #e6d59b;
    cursor: pointer;
    opacity: 0.75;
    transition: opacity 0.15s ease, background 0.12s ease, color 0.12s ease, transform 0.06s ease;
    z-index: 5;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    padding: 0;
  }
  .inv-card:hover .sell-btn { opacity: 1; }
  .inv-card .sell-btn:hover { background: rgba(80, 60, 18, 0.95); color: #ffe9a8; }
  .inv-card .sell-btn svg { width: 14px; height: 14px; display: block; }

  /* Touch: sell-btn already revealed (opacity:1) by responsive.css @media(hover:none).
     Expand to 44px tap target — the visual 26px circle stays, extra area is padding. */
  @media (hover: none) {
    .inv-card .sell-btn { min-width: 44px; min-height: 44px; }
  }
  /* Highlighted state: at least one active listing exists for this item type */
  .inv-card .sell-btn.is-listed {
    background: linear-gradient(180deg, #c79a3a 0%, #6d4f12 100%);
    color: #fff7d6;
    border-color: rgba(220,180,80,0.7);
    opacity: 1;
    box-shadow:
      0 0 0 1px rgba(220,180,80,0.35),
      0 2px 6px rgba(0,0,0,0.5);
  }
  .inv-card .sell-btn.is-listed:hover {
    background: linear-gradient(180deg, #dcad48 0%, #815b18 100%);
  }

  /* Trash button on inventory cards (bottom-left, danger-tinted).
     Mirrors .my-tile .frame .trash to keep the destructive control consistent.
     Opacity + pointer-events are owned by .danger-reveal (modules/ux/ctrl-reveal.css);
     setting opacity here would out-specificity .danger-reveal { opacity: 0 } and
     leave the button visible-but-unclickable when Ctrl is not held. */
  .inv-card .trash {
    position: absolute;
    left: 8px; bottom: 8px;
    width: 26px; height: 26px;
    display: grid; place-items: center;
    border-radius: 50%;
    border: 1px solid rgba(140,60,50,0.45);
    background: rgba(20, 8, 6, 0.72);
    color: #f0bdac;
    cursor: pointer;
    transition: opacity 0.15s ease, background 0.12s ease, color 0.12s ease, transform 0.06s ease;
    z-index: 5;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    padding: 0;
  }
  body.ctrl-on .inv-card:hover .trash { opacity: 1; }
  .inv-card .trash:hover {
    background: rgba(70, 25, 18, 0.95);
    color: #ffd4c4;
  }
  .inv-card .trash:active { transform: translateY(1px); }
  .inv-card .trash svg { width: 14px; height: 14px; display: block; }

  /* Touch (pointer: coarse): .trash is gated by body.ctrl-on which doesn't work
     on mobile. Override the ctrl-reveal.css (hover:none) fallback that would make
     danger-reveal always visible — on inv-cards we want the long-press gesture
     instead (safer: accidental taps won't trigger delete).
     • Default state: hidden (overrides .danger-reveal opacity:1 from ctrl-reveal.css;
       specificity .inv-card .trash [0-2-0] > .danger-reveal [0-1-0]).
     • .touch-trash-reveal on the card: reveal with a 44×44 tap target.
     • body.ctrl-on (e.g. external keyboard): still works as before. */
  @media (hover: none) {
    .inv-card .trash {
      opacity: 0;
      pointer-events: none;
    }
    .inv-card.touch-trash-reveal .trash {
      opacity: 1;
      pointer-events: auto;
      min-width: 44px;
      min-height: 44px;
    }
    body.ctrl-on .inv-card .trash {
      opacity: 1;
      pointer-events: auto;
      min-width: 44px;
      min-height: 44px;
    }
  }

  /* Hover-morph: trash icon rotates out, X (cross) rotates in. Pure CSS, GPU-friendly.
     Shared across .my-tile .frame .trash, .inv-card .trash, and .inv-listing-cancel.
     The wrapper button already has `display:grid; place-items:center;` so the absolute
     glyphs overlay in the centre and inherit `currentColor`. `max-width:60%` keeps the
     SVGs from bleeding past the existing per-context svg sizing (16px / 14px).
     `.inv-listing-cancel` is a tighter button — it overrides the max-width clamp below. */
  .inv-listing-cancel { position: relative; width: 16px; height: 12px; }
  .trash .trash-glyph, .inv-listing-cancel .trash-glyph {
    position: absolute; inset: 0;
    display: grid; place-items: center;
    pointer-events: none;
    transition: opacity 0.18s ease, transform 0.22s cubic-bezier(0.2, 0.7, 0.2, 1);
    will-change: transform, opacity;
  }
  .trash .trash-glyph svg, .inv-listing-cancel .trash-glyph svg {
    width: 100%; height: 100%; display: block;
    max-width: 60%; max-height: 60%;
  }
  .inv-listing-cancel .trash-glyph svg { max-width: 100%; max-height: 100%; }
  .trash .trash-glyph-default, .inv-listing-cancel .trash-glyph-default {
    opacity: 1;
    transform: rotate(0deg) scale(1);
  }
  .trash .trash-glyph-hover, .inv-listing-cancel .trash-glyph-hover {
    opacity: 0;
    transform: rotate(-90deg) scale(0.6);
  }
  .trash:hover .trash-glyph-default, .inv-listing-cancel:hover .trash-glyph-default {
    opacity: 0;
    transform: rotate(90deg) scale(0.6);
  }
  .trash:hover .trash-glyph-hover, .inv-listing-cancel:hover .trash-glyph-hover {
    opacity: 1;
    transform: rotate(0deg) scale(1);
  }

  /* Inventory ad-target picker tiles (compact, text-free) */
  .inv-picker {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
    gap: 8px;
    max-height: 60vh; overflow: auto;
  }
  /* Compact variant for cursor-anchored popover — narrow & scrollable */
  .inv-picker.compact {
    grid-template-columns: repeat(4, 56px);
    gap: 6px;
    width: min(244px, calc(100vw - 24px));
    max-height: 220px;
    overflow: auto;
  }
  .inv-tile {
    width: 100%; aspect-ratio: 1 / 1;
    border-radius: var(--r-sm);
    border: 1px solid var(--border-2);
    overflow: hidden;
    cursor: pointer;
    background: var(--surface-2);
    box-shadow: var(--shadow-card);
    transition: border-color 0.12s ease, transform 0.12s ease;
    position: relative;
  }
  .inv-tile:hover { border-color: rgba(110,150,135,0.45); transform: translateY(-1px); }
  .inv-tile .poster { aspect-ratio: 1 / 1; }
  .inv-tile .poster .ph { font-size: 22px; }

  /* Touch: legendary sheen is hover-only (opacity:0 → 1 on :hover).
     On touch devices show it at a reduced, always-on opacity so the rarity
     effect is visible without hover. */
  @media (hover: none) {
    .inv-card.rarity-legendary::after,
    .market-card.rarity-legendary::after { opacity: 0.6; }
  }
