/* Craft window — uses body font (Press Start 2P) like market.
   Tokens mirror market_v2: bg #14141a, panels #18181f/#1f1f28,
   borders #2a2a35, text #ddd/#fff, accent #4a3aa8. */

/* Tall popup — covers from near the top down to the bottom menu (66px),
   so the menu stays tappable like in every other panel. */
#window-craft.game-window {
    top: 20px; bottom: 66px; left: 10px; right: 10px;
    height: auto; z-index: 200;
    border: 3px solid var(--win-border, #3a3520);
    border-radius: 14px;
    display: none;
    flex-direction: column;
    box-shadow: 0 0 40px rgba(0,0,0,0.85), inset 0 0 20px rgba(0,0,0,0.3);
}
#window-craft.game-window.visible { display: flex; }
#window-craft .win-body { flex: 1; overflow: hidden; padding: 0; display: flex; flex-direction: column; min-height: 0; }
#window-craft::before { display: none; }

#craft-root {
    display: flex;
    flex-direction: column;
    flex: 1;
    height: 100%;
    min-height: 0;
    color: #ddd;
    font-family: inherit;
    background: #14141a;
    overflow: hidden;
}

/* ── Top bar (only crystal counter + guide button) ── */
.cr-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    background: #18181f;
    border-bottom: 1px solid #2a2a35;
    flex-shrink: 0;
}
.cr-currencies { display: flex; gap: 8px; align-items: center; }
.cr-cur {
    display: inline-flex; align-items: center; gap: 6px;
    background: #1f1f28; border: 1px solid #2a2a35;
    padding: 5px 10px; border-radius: 6px;
    font-size: 9px; color: #ddd;
}
.cr-cur b { color: #fbbf24; font-weight: 700; font-size: 10px; }
.cr-cur-ico {
    width: 18px; height: 18px; display: inline-block;
    object-fit: contain;
    image-rendering: pixelated;
    vertical-align: middle;
}

.cr-guide-btn {
    background: linear-gradient(135deg, #4a3aa8, #6b4ad8);
    color: #fff; border: none; padding: 5px 10px;
    border-radius: 6px; cursor: pointer;
    font-size: 8px; font-weight: 700;
    font-family: inherit;
    letter-spacing: .3px;
}
.cr-guide-btn:hover { box-shadow: 0 4px 12px rgba(74,58,168,.4); }

/* ── Pane (forge / boosters area) ── */
.cr-pane { flex: 1; overflow: auto; padding: 8px; display: flex; flex-direction: column; min-height: 0; }

/* ── Forge stage (top half) ── */
.cr-stage {
    position: relative;
    background: linear-gradient(180deg, #1f1f28 0%, #14141a 100%);
    border: 1px solid #2a2a35;
    border-radius: 10px;
    padding: 10px 8px;
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
    overflow: hidden;
    flex-shrink: 0;
}
.cr-mat-wrap, .cr-extra-wrap { display: flex; flex-direction: column; gap: 6px; align-items: center; }
.cr-result-wrap { display: flex; flex-direction: column; gap: 4px; align-items: center; }

.cr-slot {
    width: 56px; height: 56px;
    background: rgba(255,255,255,0.04);
    border: 2px dashed #2a2a35;
    border-radius: 8px;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    cursor: pointer;
    transition: border-color .15s, background .15s;
    position: relative;
    color: #666;
    user-select: none;
    overflow: hidden;
}
.cr-slot:hover { border-color: #4a3aa8; }
.cr-slot.filled {
    border: 2px solid #4a3aa8;
    background: rgba(74,58,168,0.12);
    color: #fff;
    box-shadow: 0 0 6px rgba(74,58,168,0.3);
}
.cr-slot-hint { font-size: 18px; opacity: 0.5; }
.cr-slot-label {
    font-size: 6px; color: #888; margin-top: 2px;
    text-transform: uppercase; letter-spacing: .4px;
}

.cr-slot-result {
    width: 96px; height: 96px;
    border: 2px solid #2a2a35;
    background: radial-gradient(circle, rgba(74,58,168,0.18) 0%, rgba(20,20,26,0.4) 70%);
    cursor: default;
    padding: 4px;
}
.cr-slot-result.ready { border-color: #fbbf24; box-shadow: 0 0 12px rgba(251,191,36,0.4); }
.cr-result-label {
    text-align: center; line-height: 1.4;
    color: #ddd;
}
.cr-rl-small { font-size: 6px; color: #aaa; line-height: 1.4; letter-spacing: .3px; }
.cr-rl-big { font-size: 12px; font-weight: 700; margin: 3px 0; letter-spacing: .5px; }

/* Old position (under result tile) — kept hidden; cost moved to cost-row above the action btn. */
.cr-result-wrap .cr-cost-line { display: none; }
.cr-cost-row {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    margin-bottom: 8px;
    background: transparent;
    border: 0;
    padding: 0;
}
.cr-cost-row .cr-cost-line {
    font-size: 9px; color: #cfcfcf;
    display: inline-flex; align-items: center; gap: 5px;
    white-space: nowrap;
    letter-spacing: .3px;
    align-self: flex-end;
    background: transparent;
    border: 0;
    padding: 0 2px 4px 0;
    margin: 0;
}
.cr-cost-row .cr-cost-line:empty { display: none; }
.cr-cost-row .cr-cost-line .cr-cost { color: #fbbf24; font-weight: 700; font-size: 11px; }
.cr-cost-row .cr-cost-line .cr-cost-icon {
    width: 14px; height: 14px;
    image-rendering: pixelated;
    object-fit: contain;
    vertical-align: middle;
}
.cr-cost-row .cr-action-btn { margin-bottom: 0; }

.cr-success { font-size: 7px; color: #aaa; letter-spacing: .3px; }
.cr-success b { color: #5dd66b; font-weight: 700; font-size: 9px; }
.cr-success.warn b { color: #ff7766; }

/* item icon inside a slot — same tier color logic as bag tiles */
.cr-item-tile {
    width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
    border-radius: 6px;
    position: relative;
    background: rgba(255,255,255,0.04);
    overflow: hidden;
}
.cr-item-tile.tier-0  { background: linear-gradient(180deg, rgba(156,163,175,0.18), rgba(156,163,175,0.05)); }
.cr-item-tile.tier-1  { background: linear-gradient(180deg, rgba(176,176,176,0.22), rgba(176,176,176,0.06)); }
.cr-item-tile.tier-2  { background: linear-gradient(180deg, rgba(74,222,128,0.20), rgba(74,222,128,0.05)); }
.cr-item-tile.tier-3  { background: linear-gradient(180deg, rgba(110,231,160,0.22), rgba(110,231,160,0.06)); }
.cr-item-tile.tier-4  { background: linear-gradient(180deg, rgba(96,165,250,0.22), rgba(96,165,250,0.05)); }
.cr-item-tile.tier-5  { background: linear-gradient(180deg, rgba(125,184,252,0.24), rgba(125,184,252,0.06)); }
.cr-item-tile.tier-6  { background: linear-gradient(180deg, rgba(244,114,182,0.25), rgba(244,114,182,0.07)); }
.cr-item-tile.tier-7  { background: linear-gradient(180deg, rgba(249,168,212,0.27), rgba(249,168,212,0.08)); }
.cr-item-tile.tier-8  { background: linear-gradient(180deg, rgba(168,85,247,0.27), rgba(168,85,247,0.08)); }
.cr-item-tile.tier-9  { background: linear-gradient(180deg, rgba(192,132,252,0.30), rgba(192,132,252,0.10)); }
.cr-item-tile.tier-10 { background: linear-gradient(180deg, rgba(251,191,36,0.30), rgba(251,191,36,0.10)); }
.cr-item-tile.tier-11 { background: linear-gradient(180deg, rgba(254,240,138,0.32), rgba(254,240,138,0.10)); }
.cr-item-tile.tier-shiny {
    box-shadow: 0 0 6px var(--tier-glow, #f472b6);
    position: relative;
}
.cr-item-tile.tier-shiny::after {
    content: ''; position: absolute; inset: -1px;
    border-radius: inherit;
    padding: 2px;
    background: conic-gradient(from var(--cr-runner-angle, 0deg),
        transparent 0deg,
        var(--tier-glow, #fbbf24) 18deg,
        rgba(255,255,255,0.95) 28deg,
        var(--tier-glow, #fbbf24) 38deg,
        transparent 56deg,
        transparent 360deg);
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
            mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
            mask-composite: exclude;
    pointer-events: none;
    animation: cr-runner-spin 2.6s linear infinite;
}
.cr-item-tile.tier-6.tier-shiny  { --tier-glow: #f472b6; }
.cr-item-tile.tier-7.tier-shiny  { --tier-glow: #f9a8d4; }
.cr-item-tile.tier-8.tier-shiny  { --tier-glow: #a855f7; }
.cr-item-tile.tier-9.tier-shiny  { --tier-glow: #c084fc; }
.cr-item-tile.tier-10.tier-shiny { --tier-glow: #fbbf24; }
.cr-item-tile.tier-11.tier-shiny { --tier-glow: #fde047; }
.cr-item-tier-badge {
    position: absolute; top: 1px; right: 2px;
    font-size: 6px; font-weight: 700;
    padding: 1px 3px; border-radius: 3px;
    background: rgba(0,0,0,0.6);
    letter-spacing: .3px;
}
.cr-item-stack {
    position: absolute; bottom: 1px; right: 2px;
    font-size: 6px; font-weight: 700; color: #fff;
    padding: 1px 3px; border-radius: 3px;
    background: rgba(0,0,0,0.7);
    letter-spacing: .2px;
}

.cr-boost-tile {
    width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
    border-radius: 6px;
    color: #fff; font-size: 11px; font-weight: 700;
    letter-spacing: .3px;
}

.cr-action-btn {
    display: block; width: 100%;
    padding: 11px 10px; margin-bottom: 8px;
    background: linear-gradient(135deg, #4a3aa8, #6b4ad8);
    color: #fff; border: none;
    border-radius: 8px; cursor: pointer;
    font-size: 10px; font-weight: 700;
    font-family: inherit;
    letter-spacing: .8px;
    text-transform: uppercase;
    transition: transform .1s, box-shadow .15s;
    flex-shrink: 0;
}
.cr-action-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(74,58,168,0.5);
}
.cr-action-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Bag (bottom of forge) ── */
.cr-bag {
    background: #18181f;
    border: 1px solid #2a2a35;
    border-radius: 10px;
    padding: 8px;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}
.cr-bag-title {
    color: #aaa; font-size: 8px; font-weight: 700;
    text-transform: uppercase; letter-spacing: .6px;
    padding: 2px 4px 6px; border-bottom: 1px solid #2a2a35;
    margin-bottom: 6px;
    display: flex; justify-content: space-between; align-items: center;
}
.cr-bag-count { color: #fbbf24; font-size: 8px; }
.cr-bag-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
    grid-auto-rows: 56px;
    gap: 5px;
    overflow-y: auto;
    flex: 1;
    align-content: start;
    padding: 2px;
}
.cr-bag-item {
    height: 56px;
    background: rgba(255,255,255,0.03);
    border: 1px solid #2a2a35;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    transition: border-color .1s, transform .1s;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}
.cr-bag-item:not(.cr-bag-empty):hover { border-color: #4a3aa8; transform: translateY(-1px); }
.cr-bag-item.disabled { opacity: 0.3; cursor: not-allowed; }
.cr-bag-item.equipped::after {
    content: 'E'; position: absolute; top: 2px; left: 2px;
    font-size: 6px; font-weight: 700; color: #fff;
    padding: 1px 3px; border-radius: 3px;
    background: #2bbf3d;
    letter-spacing: .2px;
    z-index: 2;
}

/* ── TIER backgrounds + animated borders for crafted item tiles ── */
.cr-bag-item.tier-0  { background: linear-gradient(180deg, rgba(156,163,175,0.18), rgba(156,163,175,0.05)); border-color: #6b7280; }
.cr-bag-item.tier-1  { background: linear-gradient(180deg, rgba(176,176,176,0.22), rgba(176,176,176,0.06)); border-color: #8a8a8a; }
.cr-bag-item.tier-2  { background: linear-gradient(180deg, rgba(74,222,128,0.20), rgba(74,222,128,0.05));  border-color: #4ade80; }
.cr-bag-item.tier-3  { background: linear-gradient(180deg, rgba(110,231,160,0.22), rgba(110,231,160,0.06)); border-color: #6ee7a0; }
.cr-bag-item.tier-4  { background: linear-gradient(180deg, rgba(96,165,250,0.22), rgba(96,165,250,0.05));  border-color: #60a5fa; }
.cr-bag-item.tier-5  { background: linear-gradient(180deg, rgba(125,184,252,0.24), rgba(125,184,252,0.06)); border-color: #7db8fc; }
.cr-bag-item.tier-6  { background: linear-gradient(180deg, rgba(244,114,182,0.25), rgba(244,114,182,0.07)); border-color: #f472b6; }
.cr-bag-item.tier-7  { background: linear-gradient(180deg, rgba(249,168,212,0.27), rgba(249,168,212,0.08)); border-color: #f9a8d4; }
.cr-bag-item.tier-8  { background: linear-gradient(180deg, rgba(168,85,247,0.27), rgba(168,85,247,0.08));  border-color: #a855f7; }
.cr-bag-item.tier-9  { background: linear-gradient(180deg, rgba(192,132,252,0.30), rgba(192,132,252,0.10)); border-color: #c084fc; }
.cr-bag-item.tier-10 { background: linear-gradient(180deg, rgba(251,191,36,0.30), rgba(251,191,36,0.10));  border-color: #fbbf24; }
.cr-bag-item.tier-11 { background: linear-gradient(180deg, rgba(254,240,138,0.32), rgba(254,240,138,0.10)); border-color: #fde047; }

/* B (tier 6) and above: clockwise running spark on the cell border. */
.cr-bag-item.tier-shiny {
    box-shadow: 0 0 6px var(--tier-glow, #f472b6);
}
.cr-bag-item.tier-6.tier-shiny  { --tier-glow: #f472b6; }
.cr-bag-item.tier-7.tier-shiny  { --tier-glow: #f9a8d4; }
.cr-bag-item.tier-8.tier-shiny  { --tier-glow: #a855f7; }
.cr-bag-item.tier-9.tier-shiny  { --tier-glow: #c084fc; }
.cr-bag-item.tier-10.tier-shiny { --tier-glow: #fbbf24; }
.cr-bag-item.tier-11.tier-shiny { --tier-glow: #fde047; }
.cr-bag-item.tier-shiny::before {
    content: ''; position: absolute; inset: -1px;
    border-radius: inherit;
    padding: 2px;
    background: conic-gradient(from var(--cr-runner-angle, 0deg),
        transparent 0deg,
        var(--tier-glow, #fbbf24) 18deg,
        rgba(255,255,255,0.95) 28deg,
        var(--tier-glow, #fbbf24) 38deg,
        transparent 56deg,
        transparent 360deg);
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
            mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
            mask-composite: exclude;
    pointer-events: none;
    animation: cr-runner-spin 2.6s linear infinite;
    z-index: 1;
}
.cr-bag-item.tier-shiny > * { position: relative; z-index: 2; }
/* Animate the conic-gradient angle. Requires @property (Chrome 85+, Safari 16.4+, FF 128+). */
@property --cr-runner-angle {
    syntax: '<angle>';
    initial-value: 0deg;
    inherits: false;
}
@keyframes cr-runner-spin {
    to { --cr-runner-angle: 360deg; }
}
/* Fallback for browsers without @property: rotate the whole pseudo (visually similar). */
@supports not (background: conic-gradient(from var(--x, 0deg), red, transparent)) {
    .cr-bag-item.tier-shiny::after,
    .cr-item-tile.tier-shiny::after {
        animation: cr-runner-rotate 2.6s linear infinite;
    }
    @keyframes cr-runner-rotate { to { transform: rotate(360deg); } }
}
.cr-bag-item.selected { border-color: #fbbf24; box-shadow: 0 0 6px rgba(251,191,36,0.4); }
.cr-bag-item.cr-bag-empty {
    background: rgba(255,255,255,0.015);
    border-style: dashed;
    cursor: default;
    opacity: 0.4;
}
/* Icon fills the cell; tier badge is a small corner overlay (no full strip). */
.cr-bag-icon {
    flex: 1;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px;
    min-height: 0;
    overflow: hidden;
    width: 100%;
}
.cr-bag-boost-icon {
    color: #fff; font-size: 11px; font-weight: 700; letter-spacing: .3px;
    width: 100%; height: 100%;
}
/* Tier text in bottom-left corner of the cell (item tiles). */
.cr-bag-tier-corner {
    position: absolute;
    bottom: 2px; left: 3px;
    font-size: 7px; font-weight: 700;
    color: #fff;
    text-shadow: 0 1px 1px #000, 0 0 2px #000;
    letter-spacing: .2px;
    pointer-events: none;
    line-height: 1;
}
/* Currency stack count: bottom-right small text (no strip). */
.cr-bag-label {
    position: absolute;
    bottom: 2px; right: 3px;
    font-size: 7px; font-weight: 700;
    color: #fff;
    text-shadow: 0 1px 1px #000, 0 0 2px #000;
    letter-spacing: .2px;
    pointer-events: none;
    line-height: 1;
    background: transparent;
}

/* ── Sub-tabs as proper buttons (no overflow on small screens) ── */
.cr-tabs {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
    background: #14141a;
    border-top: 1px solid #2a2a35;
    padding: 6px;
    flex-shrink: 0;
}
.cr-tab {
    width: 100%;
    padding: 8px 2px;
    background: linear-gradient(180deg, #1f1f28, #14141a);
    color: #888; border: 1px solid #2a2a35;
    border-radius: 5px;
    cursor: pointer;
    font-size: 7px; font-weight: 700;
    font-family: inherit;
    transition: color .12s, border-color .12s, background .12s, transform .1s;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    letter-spacing: .3px;
    text-transform: uppercase;
    box-shadow: 0 1px 2px rgba(0,0,0,0.4);
    min-width: 0;     /* allow grid cell to shrink below content width */
}
.cr-tab > span { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis }
.cr-tab:hover:not(.disabled) { color: #fff; border-color: #4a3aa8; transform: translateY(-1px) }
.cr-tab.active {
    color: #fff;
    background: linear-gradient(135deg, #4a3aa8, #6b4ad8);
    border-color: #fbbf24;
    box-shadow: 0 0 8px rgba(74,58,168,0.5), 0 1px 2px rgba(0,0,0,0.4);
}
.cr-tab.disabled { opacity: 0.4; cursor: not-allowed; color: #555 }
@media (max-width: 380px) {
    .cr-tab { font-size: 6px; padding: 7px 1px; letter-spacing: .15px }
    .cr-tabs { gap: 3px; padding: 5px }
}

/* ── ПРЕДМЕТЫ TAB ── */
.cr-items-layout {
    display: grid;
    grid-template-columns: 36% 1fr;
    gap: 8px;
    flex: 1;
    min-height: 0;
}
.cr-items-list {
    background: #18181f;
    border: 1px solid #2a2a35;
    border-radius: 10px;
    padding: 6px;
    overflow-y: auto;
    display: flex; flex-direction: column;
    gap: 4px;
}
.cr-il-row {
    display: flex; align-items: center; gap: 6px;
    padding: 6px;
    background: #1f1f28;
    border: 1px solid #2a2a35;
    border-radius: 6px;
    cursor: pointer;
    transition: border-color .12s, background .12s;
}
.cr-il-row:hover { border-color: #4a3aa8; }
.cr-il-row.active { border-color: #fbbf24; background: rgba(251,191,36,0.08); }
.cr-il-icon {
    width: 32px; height: 32px;
    border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 8px; font-weight: 700;
    flex-shrink: 0;
    letter-spacing: .3px;
}
.cr-il-text { min-width: 0; flex: 1; }
.cr-il-name { font-size: 8px; font-weight: 700; color: #fff; letter-spacing: .3px; line-height: 1.3; }
.cr-il-have { font-size: 7px; color: #888; margin-top: 3px; letter-spacing: .2px; }
.cr-il-have b { color: #fbbf24; }

.cr-items-detail {
    background: #18181f;
    border: 1px solid #2a2a35;
    border-radius: 10px;
    padding: 12px;
    overflow-y: auto;
    display: flex; flex-direction: column;
}
.cr-items-detail-empty {
    color: #666; font-size: 9px; text-align: center; margin: auto;
    letter-spacing: .3px;
}
.cr-id-head { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; padding: 8px; background: linear-gradient(135deg, rgba(74,58,168,0.18), rgba(20,20,26,0.4)); border: 1px solid rgba(74,58,168,0.35); border-radius: 10px; }
.cr-id-icon {
    width: 60px; height: 60px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 13px; font-weight: 700;
    flex-shrink: 0;
    background: rgba(0,0,0,0.35);
    border: 1px solid rgba(74,58,168,0.45);
    box-shadow: 0 4px 12px rgba(0,0,0,0.4), inset 0 0 8px rgba(74,58,168,0.2);
    padding: 4px;
    letter-spacing: .4px;
}
.cr-id-title { min-width: 0; flex: 1; }
.cr-id-name { font-size: 11px; font-weight: 700; color: #fff; letter-spacing: .4px; line-height: 1.3; text-shadow: 0 1px 2px #000; }
.cr-id-short { font-size: 7px; color: #5dd66b; margin-top: 5px; letter-spacing: .3px; }
.cr-id-desc {
    font-size: 8px; color: #ccc;
    line-height: 1.6;
    padding: 10px;
    background: rgba(0,0,0,0.2);
    border: 1px solid #2a2a35;
    border-radius: 8px;
    margin-bottom: 10px;
    letter-spacing: .2px;
}
.cr-id-cost-block {
    background: linear-gradient(180deg, rgba(74,58,168,0.14), rgba(74,58,168,0.04));
    border: 1px solid rgba(74,58,168,0.45);
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 10px;
    box-shadow: inset 0 0 8px rgba(74,58,168,0.1);
}
.cr-id-cost-label {
    font-size: 7px;
    color: #b9a8e6;
    letter-spacing: .5px;
    text-transform: uppercase;
    margin-bottom: 6px;
    display: flex; align-items: center; gap: 4px;
}
.cr-id-cost-label::before {
    content: ''; flex: 0 0 8px; height: 1px;
    background: linear-gradient(90deg, rgba(74,58,168,0.6), transparent);
}
.cr-id-cost-label::after {
    content: ''; flex: 1; height: 1px;
    background: linear-gradient(90deg, rgba(74,58,168,0.4), transparent);
}
.cr-id-cost {
    font-size: 9px; color: #ddd;
    letter-spacing: .3px;
    display: flex; align-items: center; gap: 6px;
    padding: 6px 8px;
    background: rgba(0,0,0,0.25);
    border-radius: 6px;
    border: 1px solid rgba(74,58,168,0.25);
}
.cr-id-cost b {
    color: #fbbf24;
    font-size: 13px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}
.cr-id-cost-icon {
    width: 18px; height: 18px;
    object-fit: contain;
    image-rendering: pixelated;
    flex-shrink: 0;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.6));
}
.cr-id-have-line {
    font-size: 7px; color: #888;
    margin-top: 8px;
    letter-spacing: .3px;
    display: flex; gap: 10px;
    flex-wrap: wrap;
}
.cr-id-have-line .cr-id-have-pill {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 7px;
    background: rgba(255,255,255,0.04);
    border-radius: 10px;
    border: 1px solid #2a2a35;
}
.cr-id-have-line .cr-id-have-pill b { color: #5dd66b; font-size: 9px; }
.cr-id-have-line .cr-id-have-pill.warn b { color: #ff7766; }

.cr-id-buttons { display: flex; gap: 6px; margin-top: auto; }
.cr-id-btn {
    flex: 1; padding: 9px 6px;
    border: none; border-radius: 6px;
    cursor: pointer;
    font-size: 8px; font-weight: 700;
    font-family: inherit;
    letter-spacing: .4px;
    color: #fff;
    transition: transform .1s, box-shadow .15s;
}
.cr-id-btn-one { background: linear-gradient(135deg, #2bbf3d, #1a8c2a); }
.cr-id-btn-all { background: linear-gradient(135deg, #4a3aa8, #6b4ad8); }
.cr-id-btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,0.4); }
.cr-id-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Modals ── */
.cr-modal {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.72);
    z-index: 9100;
    align-items: center; justify-content: center;
    padding: 16px;
}
.cr-modal.visible { display: flex; }
.cr-modal-card {
    background: #14141a;
    border: 1px solid #2a2a35;
    border-radius: 12px;
    width: 100%; max-width: 380px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.6);
    display: flex; flex-direction: column;
    max-height: 85vh;
    overflow: hidden;
}
.cr-modal-wide { max-width: 480px; }
.cr-modal-head {
    padding: 10px 12px;
    border-bottom: 1px solid #2a2a35;
    display: flex; justify-content: space-between; align-items: center;
    font-weight: 700; color: #fff; font-size: 10px;
    background: #18181f;
    letter-spacing: .4px;
}
.cr-modal-x {
    background: transparent; border: none; color: #888;
    font-size: 14px; cursor: pointer; padding: 0 4px;
    font-family: inherit;
}
.cr-modal-x:hover { color: #ff7766; }
.cr-modal-body { padding: 12px; overflow: auto; flex: 1; }

.cr-result-success { color: #5dd66b; font-size: 11px; font-weight: 700; text-align: center; margin-bottom: 10px; letter-spacing: .4px; }
.cr-result-fail    { color: #ff7766; font-size: 11px; font-weight: 700; text-align: center; margin-bottom: 10px; letter-spacing: .4px; }
.cr-result-item    {
    width: 80px; height: 80px;
    margin: 10px auto;
    border: 2px solid #4a3aa8;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 32px;
    background: radial-gradient(circle, rgba(74,58,168,0.25) 0%, rgba(20,20,26,0.5) 70%);
    box-shadow: 0 0 24px rgba(74,58,168,0.4);
}
.cr-result-text { text-align: center; color: #ddd; font-size: 9px; line-height: 1.6; letter-spacing: .3px; }
.cr-result-text b { color: #fbbf24; }

/* Guide modal */
.cr-guide-section { margin-bottom: 12px; }
.cr-guide-section h4 { color: #fbbf24; font-size: 9px; margin: 0 0 6px; font-weight: 700; letter-spacing: .4px; }
.cr-guide-section p { color: #ddd; font-size: 8px; margin: 0 0 6px; line-height: 1.6; letter-spacing: .2px; }
.cr-guide-flow {
    display: flex; align-items: center; justify-content: center;
    gap: 6px; padding: 8px; background: #1f1f28;
    border: 1px solid #2a2a35; border-radius: 8px; margin-top: 6px;
    flex-wrap: wrap;
}
.cr-guide-tile {
    min-width: 36px; height: 36px;
    padding: 0 6px;
    background: rgba(255,255,255,0.04);
    border: 1px solid #4a3aa8;
    border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
    font-size: 9px; color: #fff;
    letter-spacing: .3px;
}
.cr-guide-arrow { color: #fbbf24; font-size: 14px; font-weight: 700; }

/* Animations */
@keyframes cr-shake {
    0%,100% { transform: translate(0,0); }
    10% { transform: translate(-2px, 1px); }
    20% { transform: translate(2px, -1px); }
    30% { transform: translate(-1px, 2px); }
    40% { transform: translate(1px, -2px); }
    50% { transform: translate(-2px, -1px); }
    60% { transform: translate(2px, 1px); }
    70% { transform: translate(-1px, -2px); }
    80% { transform: translate(1px, 2px); }
    90% { transform: translate(-2px, 0); }
}
.cr-shaking { animation: cr-shake 0.5s linear infinite; }

@keyframes cr-screen-shake {
    0%,100% { transform: translate(0,0); }
    20% { transform: translate(-3px, 2px); }
    40% { transform: translate(3px, -2px); }
    60% { transform: translate(-2px, -3px); }
    80% { transform: translate(2px, 3px); }
}
.cr-screen-shaking { animation: cr-screen-shake 0.5s linear infinite; }

@keyframes cr-converge {
    0%   { transform: translate(0,0); opacity: 1; }
    100% { transform: translate(var(--cr-tx,0), var(--cr-ty,0)) scale(0.4); opacity: 0; }
}
.cr-converging { animation: cr-converge 0.5s cubic-bezier(.5,.05,.95,.5) forwards; }

.cr-flash {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: radial-gradient(circle at 50% 50%, rgba(255,255,255,1) 0%, rgba(255,240,200,0.6) 30%, transparent 70%);
    opacity: 0;
    transition: opacity .15s ease-out;
}
.cr-flash.active { opacity: 1; transition: opacity .25s ease-in; }

/* ─── Item preview popover (anchored next to clicked bag tile) ────────
   Compact card showing slot/tier/stats + a single "Insert" button so the
   player can verify the item before pushing it into the forge slot. */
.cr-item-pop {
    position: fixed;
    z-index: 200;
    width: 180px;
    max-width: calc(100vw - 16px);
    background: linear-gradient(180deg, #1a1410 0%, #0a0608 100%);
    border: 1px solid #3a2e18;
    border-radius: 8px;
    box-shadow: 0 6px 20px rgba(0,0,0,.6), inset 0 1px 0 rgba(255,255,255,.04);
    padding: 0;
    color: #e7d9b8;
    font-family: 'Nunito', sans-serif;
    animation: cr-pop-in .12s ease-out;
}
@keyframes cr-pop-in {
    from { opacity: 0; transform: translateY(-4px) scale(.97); }
    to   { opacity: 1; transform: translateY(0)    scale(1); }
}
.cr-pop-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 6px 8px;
    border-bottom: 1px solid #3a2e18;
    gap: 6px;
}
.cr-pop-title {
    font-size: 10px; font-weight: 700; letter-spacing: .3px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    flex: 1;
}
.cr-pop-close {
    background: transparent; border: 0; color: #888;
    font-size: 12px; line-height: 1; padding: 2px 4px; cursor: pointer;
}
.cr-pop-close:hover { color: #fde68a; }
.cr-pop-stats {
    padding: 6px 8px;
    display: flex; flex-direction: column; gap: 2px;
    max-height: 160px; overflow-y: auto;
}
.cr-pop-insert {
    display: block; width: calc(100% - 12px); margin: 4px 6px 6px;
    padding: 6px 0;
    background: linear-gradient(180deg, #3a1f0c 0%, #1c0e04 100%);
    border: 1px solid #c8700a;
    border-radius: 6px;
    color: #fde68a;
    font-family: 'Nunito', sans-serif;
    font-size: 10px; font-weight: 800; letter-spacing: .4px;
    cursor: pointer;
}
.cr-pop-insert:hover  { background: linear-gradient(180deg, #4a2810 0%, #2a1308 100%); }
.cr-pop-insert:active { transform: scale(0.97); }
