/* ===== ПЕРЕМЕННЫЕ ===== */
:root {
    --primary: #6220b4;
    --primary-light: #8a3fd4;
    --primary-dark: #4a1887;
    --accent: #ff9800;
    --accent-gold: #d4af37;
    --elyos: #c9a227;
    --asmo: #8e44ad;
    --bg-dark: #121d3b;
    --bg-darker: #0a1128;
    --bg-card: rgba(255, 255, 255, 0.75);
    --text: #333;
    --text-muted: #777;
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.12);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.18);
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== БАЗА ===== */
html {
    background: #000;
}

body {
    background: #f2f4f7;
    color: var(--text);
    margin: 0;
    padding: 0;
    min-width: 1060px;
    font-family: 'Roboto', sans-serif;
    font-weight: 200;
    font-size: 16px;
}

h1, h2, h3, h4, h5, h6, p {
    margin: 0;
    padding: 0;
}

a.alt {
    color: var(--accent);
    text-decoration: underline;
    transition: color var(--transition);
}

a.alt:hover, a.alt:active {
    color: #ffb400;
}

*:focus {
    outline: none;
}

/* ===== ЕДИНЫЙ СКРОЛЛБАР ===== */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--primary) transparent;
}
*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
    background: linear-gradient(var(--primary), var(--primary-light));
    border-radius: 3px;
}

/* ===== КОНТЕЙНЕРЫ ===== */
.main-container {
    width: 1160px;
    margin: 0 auto;
    min-height: 600px;
    position: relative;
    top: -200px;
}

.home-container {
    box-shadow: var(--shadow-lg);
    overflow: auto;
    border-radius: var(--radius-lg);
}

/* ===== HEADER ===== */
.aioncms-header {
    background: 
        linear-gradient(135deg, rgba(15, 12, 41, 0.7), rgba(48, 43, 99, 0.5)),
        url('../img/background.jpg') no-repeat center;
    background-size: cover;
    width: 100%;
    height: 600px;
    border-bottom: 150px solid #ededed;
    position: relative;
}

.aioncms-header::after {
    content: '';
    position: absolute;
    bottom: -150px;
    left: 0;
    right: 0;
    height: 200px;
    background: linear-gradient(to top, #f2f4f7, transparent);
    pointer-events: none;
}

.aioncms-header .aioncms-header-logo {
    text-align: center;
    padding-top: 0;
}

/* ===== FOOTER ===== */
.aioncms-footer {
    background: linear-gradient(180deg, var(--bg-dark) 0%, var(--bg-darker) 100%);
    color: #aaa;
    min-height: 300px;
    margin-top: -150px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.aioncms-footer .aioncms-footer-social {
    background: var(--bg-dark);
    text-align: center;
    padding: 50px 0;
}

.aioncms-footer .aioncms-footer-social .social-icon-block {
    display: inline-block;
    margin: 0 20px;
}

.aioncms-footer .aioncms-footer-social .social-icon-block .social-icon {
    width: 50px;
    height: auto;
    transition: all var(--transition);
    filter: brightness(50%);
}

.aioncms-footer .aioncms-footer-social .social-icon-block .social-icon:hover {
    filter: brightness(100%);
    transform: translateY(-3px) scale(1.1);
}

.aioncms-footer .aioncms-footer-content {
    padding: 50px 0;
    font-size: 12px;
}

.aioncms-footer .aioncms-footer-content a {
    color: #cc4e4e;
    transition: color var(--transition);
}

.aioncms-footer .aioncms-footer-content a:hover {
    color: #ff6b6b;
}

.footer-time-title {
    font-family: 'Segoe UI', sans-serif;
    color: #fff;
    font-weight: bold;
    text-transform: uppercase;
}

.footer-time {
    font-family: 'Segoe UI', sans-serif;
    font-size: 48px;
    color: #ff3214;
    font-weight: bold;
    position: relative;
    top: -10px;
    text-shadow: 0 0 20px rgba(255, 50, 20, 0.5);
}

.footer-date {
    font-family: 'Segoe UI', sans-serif;
    position: relative;
    top: -15px;
    font-size: 12px;
}

/* ===== HOME BLOCKS ===== */
.home-block {
    width: 100%;
    background: #000;
    color: #fff;
    min-height: 280px;
}

.home-block-padding {
    padding: 30px;
}

.home-block-first {
    background: url('../img/home-block-first.jpg') no-repeat;
    background-size: cover;
    min-height: 280px;
    overflow: auto;
}

/* ===== КНОПКИ — GLASSMORPHISM ===== */
.home-block-first .home-block-button {
    display: block;
    width: 350px;
    height: 70px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    margin-bottom: 5px;
    transition: var(--transition);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    background: rgba(0, 0, 0, 0.4);
    font-size: 12px;
    padding-top: 12px;
    color: #fff;
    position: relative;
    overflow: hidden;
    border-radius: var(--radius);
}

.home-block-first .home-block-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.15), transparent);
    transition: left 0.6s;
}

.home-block-first .home-block-button:hover::before {
    left: 100%;
}

.home-block-first .home-block-button:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(98, 32, 180, 0.3);
    border-color: var(--primary-light);
    background: rgba(98, 32, 180, 0.3);
}

.home-block-first .home-block-button-1 {
    background: url('../img/home-button-block-1.jpg') no-repeat;
    background-size: cover;
}

.home-block-first .home-block-button-2 {
    background: url('../img/home-button-block-2.jpg') no-repeat;
    background-size: cover;
}

.home-block-first .home-block-button-3 {
    background: url('../img/home-button-block-3.jpg') no-repeat;
    background-size: cover;
}

.home-block-video {
    background: url('../img/home-block-download.jpg') no-repeat center center;
    background-size: cover;
    min-height: 280px;
}

.home-block-donate {
    background: url('../img/home-block-donate.jpg') no-repeat center center;
    background-size: cover;
    min-height: 280px;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.6);
}

.home-block-news {
    background: #eeeeee url('../img/home-block-news.jpg') no-repeat;
    background-size: cover;
    min-height: 280px;
    color: #000;
    overflow: auto;
    font-size: 14px;
}

/* ===== ТАБЛИЦА НОВОСТЕЙ ===== */
.home-block-news .home-news-table {
    width: 100%;
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    font-size: 14px;
    margin-top: 20px;
    border-spacing: 2px;
    border-collapse: separate;
    padding: 10px;
    border-radius: var(--radius);
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: var(--shadow-sm);
}

.home-block-news .home-news-table tr {
    transition: var(--transition);
}

.home-block-news .home-news-table tr:hover {
    background: rgba(255, 255, 255, 0.7);
    transform: translateX(3px);
}

.home-block-news .home-news-table tr td {
    padding: 3px 5px;
}

.home-block-news .home-news-table tr td:first-child {
    border-left: 3px solid rgba(255, 255, 255, 0.5);
    transition: all 0.2s ease;
}

.home-block-news .home-news-table tr td:first-child:hover {
    border-color: var(--primary);
}

.home-block-news .home-news-table tr td:last-child {
    text-align: left;
    font-size: 12px;
    color: #333;
}

.home-block-news .home-news-table tr td a {
    color: #344850;
    text-decoration: none;
    transition: color var(--transition);
}

.home-block-news .home-news-table tr td a:hover {
    color: var(--primary);
}

/* ===== ВКЛАДКИ ===== */
.home-block-news .nav-tabs {
    display: inline-block;
    border-bottom: 0;
    margin-bottom: 5px;
    margin-top: 13px;
}

.home-block-news .nav-tabs > li > a {
    margin-right: 2px;
    line-height: normal;
    border: 0;
    border-radius: 0 0 0 0;
}

.home-block-news .nav > li > a {
    position: static;
    display: inline-block;
    padding: 8px 5px;
    font-size: 12px;
    color: #777;
    background: rgba(255, 255, 255, 0.3);
    border-radius: var(--radius-sm);
    transition: var(--transition);
    margin: 0 3px;
}

.home-block-news .nav > li > a:hover,
.home-block-news .nav > li > a:focus {
    background: rgba(255, 255, 255, 0.8);
    color: #000;
}

.home-block-news .nav-tabs > li.active > a,
.home-block-news .nav-tabs > li.active > a:focus,
.home-block-news .nav-tabs > li.active > a:hover {
    color: #fff;
    cursor: default;
    background: linear-gradient(135deg, var(--primary), var(--primary-light)) !important;
    border: 0;
    border-bottom-color: transparent;
    box-shadow: 0 4px 15px rgba(98, 32, 180, 0.4);
}

.home-block-news .tab-content {
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 10px;
    border-radius: var(--radius);
    border: 1px solid rgba(255, 255, 255, 0.3);
    height: 320px;
    overflow-y: auto;
    overflow-x: hidden;
    box-shadow: var(--shadow-sm);
}

.home-block-news img {
    width: 15px;
    height: auto;
}

.home-block-news .abysstable,
.home-block-news .legionstable {
    width: 100%;
    margin: 0 auto;
}

.home-block-news .abysstable tr th,
.home-block-news .legionstable tr th {
    color: #000;
    padding: 3px 5px;
}

.home-block-news .legionstable tr td:nth-child(0),
.home-block-news .legionstable tr td:nth-child(1) {
    width: 50%;
}

.home-block-news .abysstable tr td:nth-child(0),
.home-block-news .abysstable tr td:nth-child(1) {
    width: 35%;
}

.home-block-news .abysstable tr td:nth-child(3),
.home-block-news .abysstable tr td:nth-child(4),
.home-block-news .abysstable tr td:nth-child(5) {
    width: 10%;
}

.home-block-news .abysstable tr td {
    padding: 3px 5px;
}

.home-block-news .abysstable tr td,
.home-block-news .legionstable tr td {
    transition: var(--transition);
}

.home-block-news .abysstable tr:hover td,
.home-block-news .legionstable tr:hover td {
    background: rgba(255, 255, 255, 0.7);
}

.home-block-news .legionstable tr th,
.home-block-news .legionstable tr td {
    padding: 3px 5px;
}

.node--forum.node--unread .node--newIndicator {
    display: inline-block;
}

.node--newIndicator {
    font-size: 11px;
    color: #fefefe;
    background: #b23838;
    border-radius: 3px;
    padding-right: 3px;
    padding-left: 3px;
    text-transform: uppercase;
}

.fixed-link {
    position: fixed;
    bottom: 20px;
    left: 20px;
    background: linear-gradient(135deg, #FF8C00, #ff6b00);
    padding: 10px 15px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    z-index: 1000;
    transition: var(--transition);
}

.fixed-link:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

/* ===== ИНФО-ПАНЕЛЬ — GLASSMORPHISM ===== */
.info-container {
    position: fixed;
    bottom: 50px;
    left: 20px;
    width: 300px;
    background: rgba(18, 29, 59, 0.85);
    backdrop-filter: blur(16px) saturate(180%);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius);
    text-align: center;
    font-size: 14px;
    box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255, 255, 255, 0.05);
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    box-sizing: border-box;
    transform: translateX(-100%);
    transition: transform var(--transition);
    overflow: visible !important;
    max-height: calc(100vh - 70px);
    overflow: hidden;
}

.info-container.show {
    transform: translateX(0);
}

.info-container > *:not(#event-list):not(.toggle-button) {
    flex-shrink: 0;
}

/* ===== СЕЗОН ===== */
.season-container {
    width: 100%;
    text-align: left;
}

.season-bar-container {
    display: flex;
    flex-direction: row;
    gap: 10px;
    align-items: center;
}

.season-bar {
    width: 100%;
    height: 14px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 7px;
    margin-top: 5px;
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3);
}

.season-progress {
    height: 100%;
    background: linear-gradient(90deg, #ff9800, #ffb74d);
    border-radius: 7px;
    width: 0%;
    transition: width 0.5s ease-in-out;
    box-shadow: 0 0 10px rgba(255, 152, 0, 0.5);
}

.season-progress-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 18px;
    font-weight: bold;
    color: #333;
}

#days-left {
    font-size: 14px;
    color: white;
    margin-top: 5px;
}

#event-list {
    background: rgba(0, 0, 0, 0.3);
    padding: 10px;
    border-radius: var(--radius-sm);
    width: 100%;
    text-align: left;
    box-sizing: border-box;
    color: white;
    flex: 1 1 auto;
    min-height: 60px;
    max-height: 60vh;
    overflow-y: auto;
    overflow-x: hidden;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.current-event {
    background: linear-gradient(135deg, #ff9800, #ffb74d);
    color: #333;
    font-weight: bold;
    padding: 5px;
    border-radius: var(--radius-sm);
    box-shadow: 0 2px 8px rgba(255, 152, 0, 0.3);
}

/* ===== КНОПКА TOGGLE ===== */
.toggle-button {
    position: absolute;
    top: -12px;
    right: -20px;
    width: 36px;
    height: 36px;
    background: rgba(18, 29, 59, 0.9);
    backdrop-filter: blur(10px);
    border: 2px solid var(--primary);
    border-radius: 50%;
    color: var(--accent);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    animation: spin 5s linear infinite;
    transition: all var(--transition);
    box-shadow: 0 0 15px rgba(98, 32, 180, 0.4);
}

.info-container.show .toggle-button {
    transform: rotate(180deg);
}

.toggle-button:hover {
    background: rgba(98, 32, 180, 0.9);
    box-shadow: 0 0 20px rgba(98, 32, 180, 0.6);
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ===== ВКЛАДКИ ПАНЕЛИ ===== */
.tabs {
    display: flex;
    flex-wrap: nowrap;
    justify-content: space-between;
    margin-bottom: 5px;
    gap: 5px;
    background: rgba(0, 0, 0, 0.3);
    padding: 5px;
    box-sizing: border-box;
    border-radius: var(--radius-sm);
    z-index: 1000;
}

.tab-button {
    padding: 6px 8px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.08);
    border: none;
    border-radius: var(--radius-sm);
    font-weight: bold;
    color: white;
    transition: var(--transition);
    width: 13%;
    text-align: center;
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.tab-button:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-1px);
}

.tab-button.active {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: white;
    box-shadow: 0 4px 15px rgba(98, 32, 180, 0.4);
}

.tab-button.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 3px;
    background: var(--accent);
    border-radius: 2px;
}

.tab-button.active:hover {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
}

.current-day-tab {
    background: linear-gradient(135deg, var(--accent), #ffb74d);
    color: white;
    font-weight: bold;
    border-radius: var(--radius-sm);
    padding: 10px;
    box-shadow: 0 2px 10px rgba(255, 152, 0, 0.3);
}

.active-event {
    background: linear-gradient(135deg, var(--accent), #ffb74d);
    color: black;
    font-weight: bold;
    padding: 5px;
    border-radius: var(--radius-sm);
}

/* ===== ИКОНКИ ===== */
.season-gun-icon {
    width: 20px;
    height: 20px;
    vertical-align: middle;
    margin-right: 4px;
    display: inline-block;
}

.weekend-boost {
    font-size: 1.05em;
    font-weight: bold;
    color: #FFD700;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
    animation: rich-glow 8s ease-in-out infinite alternate;
    text-shadow: 
        0 0 6px rgba(255, 215, 0, 0.6),
        0 0 12px rgba(255, 215, 0, 0.4),
        0 0 20px rgba(255, 215, 0, 0.2);
}

@keyframes rich-glow {
    0%, 100% {
        text-shadow: 
            0 0 8px rgba(255, 215, 0, 0.5),
            0 0 16px rgba(255, 215, 0, 0.3),
            0 0 24px rgba(255, 215, 0, 0.1);
    }
    50% {
        text-shadow: 
            0 0 12px rgba(255, 215, 0, 0.8),
            0 0 24px rgba(255, 215, 0, 0.6),
            0 0 36px rgba(255, 215, 0, 0.4),
            0 0 48px rgba(255, 215, 0, 0.2);
    }
}

.weekend-icon {
    width: 20px;
    height: 20px;
    object-fit: contain;
    vertical-align: middle;
    filter: drop-shadow(0 0 4px rgba(255, 215, 0, 0.5));
}

.season-skillbook-icon {
    height: 20px;
    vertical-align: middle;
    margin-left: 4px;
}

/* ===== ХРОНИКА ===== */
.chronicle-content {
    font-size: 12px;
    line-height: 1.4;
    color: #333;
}

.chronicle-content .header {
    text-align: center;
    font-size: 1.1em;
    font-weight: bold;
    color: #000;
    border-bottom: 1px solid #ddd;
    padding-bottom: 5px;
    margin-bottom: 10px;
}

.chronicle-content .intro {
    text-align: center;
    font-style: italic;
    color: #666;
    margin-bottom: 15px;
    font-size: 11px;
}

.chronicle-content .section {
    margin-top: 10px;
}

.chronicle-content .section-title {
    font-size: 1em;
    font-weight: bold;
    color: #000;
    margin: 10px 0 5px 0;
    padding: 3px 0;
    border-bottom: 1px solid #eee;
}

.chronicle-content .event {
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(5px);
    padding: 5px;
    margin: 3px 0;
    border-radius: var(--radius-sm);
    border-left: 2px solid #ccc;
    font-size: 11px;
    transition: var(--transition);
}

.chronicle-content .event:hover {
    transform: translateX(3px);
    box-shadow: var(--shadow-sm);
}

.chronicle-content .event.legend { border-left-color: #d9534f; }
.chronicle-content .event.fail { border-left-color: #f0ad4e; }
.chronicle-content .event.healer { border-left-color: #5bc0de; }
.chronicle-content .event.new { border-left-color: #5cb85c; }
.chronicle-content .event.enchant { border-left-color: #ffd700; }

.chronicle-content .quote {
    text-align: center;
    font-style: italic;
    color: #666;
    margin-top: 10px;
    padding-top: 5px;
    border-top: 1px solid #ddd;
    font-size: 10px;
}

.chronicle-content .footer {
    text-align: center;
    margin-top: 10px;
    font-weight: bold;
    color: #000;
    font-size: 11px;
}

.chronicle-content .divider {
    text-align: center;
    color: #999;
    margin: 5px 0;
    font-size: 10px;
}

/* ===== ТЕРРИТОРИАЛЬНАЯ ВОЙНА — GLASSMORPHISM ===== */
.tw-daily-content,
.tw-alltime-content {
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: var(--radius);
    padding: 15px 18px;
    font-size: 13px;
    line-height: 1.5;
    color: #333;
    box-shadow: var(--shadow-sm);
}

.tw-daily-content .tw-header,
.tw-alltime-content .tw-header {
    font-size: 18px;
    font-weight: 700;
    text-align: center;
    color: #1a1a1a;
    padding-bottom: 10px;
    margin-bottom: 8px;
    border-bottom: 2px solid var(--accent-gold);
    letter-spacing: 0.5px;
}

.tw-daily-content .tw-date,
.tw-alltime-content .tw-date {
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
    font-style: italic;
    margin-bottom: 12px;
}

.tw-daily-content .tw-winner {
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    color: #222;
    padding: 10px 12px;
    margin: 10px 0;
    background: linear-gradient(135deg, rgba(212, 175, 55, 0.15), rgba(212, 175, 55, 0.05));
    border-left: 3px solid var(--accent-gold);
    border-radius: var(--radius-sm);
    line-height: 1.4;
    backdrop-filter: blur(5px);
}

.tw-daily-content .tw-score {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    font-size: 15px;
    font-weight: 700;
    padding: 10px;
    margin: 8px 0 14px 0;
    background: rgba(0, 0, 0, 0.05);
    border-radius: var(--radius-sm);
}

.tw-daily-content .tw-score .elyos {
    color: var(--elyos);
    text-shadow: 0 1px 2px rgba(201, 162, 39, 0.3);
}

.tw-daily-content .tw-score .asmo {
    color: var(--asmo);
    text-shadow: 0 1px 2px rgba(142, 68, 173, 0.3);
}

.tw-daily-content .tw-section-title,
.tw-alltime-content .tw-section-title {
    font-size: 13px;
    font-weight: 700;
    color: #1a1a1a;
    margin: 14px 0 8px 0;
    padding: 5px 0 4px 0;
    border-bottom: 1px dashed #bbb;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ===== КАРТОЧКИ ГЕРОЕВ ===== */
.tw-daily-content .tw-hero {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(5px);
    padding: 8px 12px;
    margin: 5px 0;
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--accent-gold);
    font-size: 12px;
    color: #333;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.tw-daily-content .tw-hero::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--accent-gold);
    transform: scaleY(0);
    transition: transform var(--transition);
}

.tw-daily-content .tw-hero:hover {
    transform: translateX(6px) scale(1.01);
    box-shadow: var(--shadow-md);
}

.tw-daily-content .tw-hero:hover::after {
    transform: scaleY(1);
}

.tw-daily-content .tw-hero:nth-child(1 of .tw-hero) { 
    border-left-color: #ffd700; 
    background: rgba(255, 215, 0, 0.15); 
}
.tw-daily-content .tw-hero:nth-child(2 of .tw-hero) { 
    border-left-color: #c0c0c0; 
    background: rgba(192, 192, 192, 0.18); 
}
.tw-daily-content .tw-hero:nth-child(3 of .tw-hero) { 
    border-left-color: #cd7f32; 
    background: rgba(205, 127, 50, 0.15); 
}

.tw-daily-content .tw-hero:first-of-type { 
    border-left-color: #ffd700; 
    background: rgba(255, 215, 0, 0.15); 
}

.tw-alltime-content .tw-stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    margin: 4px 0;
    background: rgba(255, 255, 255, 0.7);
    border-radius: var(--radius-sm);
    font-size: 12px;
    border-left: 3px solid #888;
    transition: var(--transition);
}

.tw-alltime-content .tw-stat:hover {
    background: rgba(255, 255, 255, 0.9);
    transform: translateX(3px);
}

.tw-alltime-content .tw-stat b {
    font-size: 14px;
    font-weight: 700;
}

.tw-alltime-content .tw-stat b.elyos { color: var(--elyos); }
.tw-alltime-content .tw-stat b.asmo { color: var(--asmo); }

.tw-alltime-content .tw-stat:nth-child(2 of .tw-stat) { border-left-color: var(--elyos); }
.tw-alltime-content .tw-stat:nth-child(3 of .tw-stat) { border-left-color: var(--elyos); }
.tw-alltime-content .tw-stat:nth-child(4 of .tw-stat) { border-left-color: var(--asmo); }
.tw-alltime-content .tw-stat:nth-child(5 of .tw-stat) { border-left-color: var(--asmo); }
.tw-alltime-content .tw-stat:nth-child(6 of .tw-stat) { border-left-color: #95a5a6; }

.tw-alltime-content .tw-legend {
    padding: 7px 12px;
    margin: 4px 0;
    background: rgba(255, 255, 255, 0.75);
    border-radius: var(--radius-sm);
    font-size: 12px;
    color: #333;
    border-left: 3px solid var(--accent-gold);
    transition: var(--transition);
}

.tw-alltime-content .tw-legend:hover {
    background: rgba(255, 255, 255, 0.95);
    transform: translateX(3px);
    box-shadow: var(--shadow-sm);
}

.tw-alltime-content .tw-legend:first-of-type {
    border-left-color: #ffd700;
    background: linear-gradient(90deg, rgba(255, 215, 0, 0.18), rgba(255, 255, 255, 0.75));
    font-weight: 600;
}

.tw-alltime-content .tw-legend:nth-of-type(2) {
    border-left-color: #c0c0c0;
    background: linear-gradient(90deg, rgba(192, 192, 192, 0.2), rgba(255, 255, 255, 0.75));
}

.tw-alltime-content .tw-legend:nth-of-type(3) {
    border-left-color: #cd7f32;
    background: linear-gradient(90deg, rgba(205, 127, 50, 0.18), rgba(255, 255, 255, 0.75));
}

.tw-daily-content .tw-footer {
    text-align: center;
    font-size: 11px;
    color: #666;
    margin-top: 12px;
    padding-top: 8px;
    border-top: 1px dashed #ccc;
    font-style: italic;
}

.tw-daily-content .tw-quote,
.tw-alltime-content .tw-quote {
    text-align: center;
    font-style: italic;
    color: #555;
    font-size: 11px;
    margin-top: 12px;
    padding: 8px 10px;
    background: rgba(212, 175, 55, 0.08);
    border-radius: var(--radius-sm);
    border-top: 1px solid #e5d68f;
    border-bottom: 1px solid #e5d68f;
    line-height: 1.4;
}

.home-block-news .tab-content #tw_daily,
.home-block-news .tab-content #tw_alltime {
    overflow-y: auto;
    max-height: 100%;
}

/* ===== КАЛЬДОР ===== */
.kaldor-daily-content,
.kaldor-alltime-content {
    background: rgba(255, 250, 245, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(231, 76, 60, 0.2);
    border-radius: var(--radius);
    padding: 15px 18px;
    font-size: 13px;
    line-height: 1.5;
    color: #333;
    box-shadow: var(--shadow-sm);
}

.kaldor-daily-content .kaldor-header,
.kaldor-alltime-content .kaldor-header {
    font-size: 18px;
    font-weight: 700;
    text-align: center;
    color: #1a1a1a;
    padding-bottom: 10px;
    margin-bottom: 8px;
    border-bottom: 2px solid #e74c3c;
    letter-spacing: 0.5px;
}

.kaldor-daily-content .kaldor-date,
.kaldor-alltime-content .kaldor-date {
    text-align: center;
    font-size: 11px;
    color: #777;
    font-style: italic;
    margin-bottom: 12px;
}

.kaldor-daily-content .kaldor-winner {
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    color: #222;
    padding: 10px 12px;
    margin: 10px 0;
    background: linear-gradient(135deg, rgba(231, 76, 60, 0.15), rgba(255, 107, 53, 0.05));
    border-left: 3px solid #e74c3c;
    border-radius: var(--radius-sm);
    line-height: 1.4;
}

.kaldor-daily-content .kaldor-score {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    font-size: 15px;
    font-weight: 700;
    padding: 10px;
    margin: 8px 0 14px 0;
    background: rgba(0, 0, 0, 0.05);
    border-radius: var(--radius-sm);
}

.kaldor-daily-content .kaldor-score .elyos {
    color: var(--elyos);
    text-shadow: 0 1px 2px rgba(201, 162, 39, 0.3);
}

.kaldor-daily-content .kaldor-score .asmo {
    color: var(--asmo);
    text-shadow: 0 1px 2px rgba(142, 68, 173, 0.3);
}

.kaldor-daily-content .kaldor-section-title,
.kaldor-alltime-content .kaldor-section-title {
    font-size: 13px;
    font-weight: 700;
    color: #1a1a1a;
    margin: 14px 0 8px 0;
    padding: 5px 0 4px 0;
    border-bottom: 1px dashed #d98880;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.kaldor-daily-content .kaldor-hero {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(5px);
    padding: 8px 12px;
    margin: 5px 0;
    border-radius: var(--radius-sm);
    border-left: 3px solid #e74c3c;
    font-size: 12px;
    color: #333;
    transition: var(--transition);
}

.kaldor-daily-content .kaldor-hero:hover {
    transform: translateX(3px);
    box-shadow: 0 2px 6px rgba(231, 76, 60, 0.2);
}

.kaldor-daily-content .kaldor-hero:first-of-type { 
    border-left-color: #ffd700; 
    background: rgba(255, 215, 0, 0.15); 
}
.kaldor-daily-content .kaldor-hero:nth-of-type(2) { 
    border-left-color: #c0c0c0; 
    background: rgba(192, 192, 192, 0.18); 
}
.kaldor-daily-content .kaldor-hero:nth-of-type(3) { 
    border-left-color: #cd7f32; 
    background: rgba(205, 127, 50, 0.15); 
}

.kaldor-alltime-content .kaldor-stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    margin: 4px 0;
    background: rgba(255, 255, 255, 0.7);
    border-radius: var(--radius-sm);
    font-size: 12px;
    border-left: 3px solid #888;
    transition: var(--transition);
}

.kaldor-alltime-content .kaldor-stat:hover {
    background: rgba(255, 255, 255, 0.9);
    transform: translateX(3px);
}

.kaldor-alltime-content .kaldor-stat b {
    font-size: 14px;
    font-weight: 700;
}

.kaldor-alltime-content .kaldor-stat b.elyos { color: var(--elyos); }
.kaldor-alltime-content .kaldor-stat b.asmo { color: var(--asmo); }

.kaldor-alltime-content .kaldor-stat:nth-of-type(2) { border-left-color: var(--elyos); }
.kaldor-alltime-content .kaldor-stat:nth-of-type(3) { border-left-color: var(--elyos); }
.kaldor-alltime-content .kaldor-stat:nth-of-type(4) { border-left-color: var(--asmo); }
.kaldor-alltime-content .kaldor-stat:nth-of-type(5) { border-left-color: var(--asmo); }
.kaldor-alltime-content .kaldor-stat:nth-of-type(6) { border-left-color: #e74c3c; }

.kaldor-alltime-content .kaldor-legend {
    padding: 7px 12px;
    margin: 4px 0;
    background: rgba(255, 255, 255, 0.75);
    border-radius: var(--radius-sm);
    font-size: 12px;
    color: #333;
    border-left: 3px solid #e74c3c;
    transition: var(--transition);
}

.kaldor-alltime-content .kaldor-legend:hover {
    background: rgba(255, 255, 255, 0.95);
    transform: translateX(3px);
    box-shadow: var(--shadow-sm);
}

.kaldor-alltime-content .kaldor-legend:first-of-type {
    border-left-color: #ffd700;
    background: linear-gradient(90deg, rgba(255, 215, 0, 0.18), rgba(255, 255, 255, 0.75));
    font-weight: 600;
}

.kaldor-alltime-content .kaldor-legend:nth-of-type(2) {
    border-left-color: #c0c0c0;
    background: linear-gradient(90deg, rgba(192, 192, 192, 0.2), rgba(255, 255, 255, 0.75));
}

.kaldor-alltime-content .kaldor-legend:nth-of-type(3) {
    border-left-color: #cd7f32;
    background: linear-gradient(90deg, rgba(205, 127, 50, 0.18), rgba(255, 255, 255, 0.75));
}

.kaldor-daily-content .kaldor-footer {
    text-align: center;
    font-size: 11px;
    color: #666;
    margin-top: 12px;
    padding-top: 8px;
    border-top: 1px dashed #d98880;
    font-style: italic;
}

.home-block-news .tab-content #kaldor_daily,
.home-block-news .tab-content #kaldor_alltime {
    overflow-y: auto;
    max-height: 100%;
}

/* ===== АНИМАЦИИ ПОЯВЛЕНИЯ ===== */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.tw-hero,
.kaldor-hero,
.chronicle-content .event,
.tw-alltime-content .tw-legend,
.kaldor-alltime-content .kaldor-legend {
    animation: fadeInUp 0.4s ease backwards;
}

.tw-hero:nth-child(1),
.kaldor-hero:nth-child(1),
.tw-alltime-content .tw-legend:nth-of-type(1),
.kaldor-alltime-content .kaldor-legend:nth-of-type(1) { animation-delay: 0.05s; }

.tw-hero:nth-child(2),
.kaldor-hero:nth-child(2),
.tw-alltime-content .tw-legend:nth-of-type(2),
.kaldor-alltime-content .kaldor-legend:nth-of-type(2) { animation-delay: 0.1s; }

.tw-hero:nth-child(3),
.kaldor-hero:nth-child(3),
.tw-alltime-content .tw-legend:nth-of-type(3),
.kaldor-alltime-content .kaldor-legend:nth-of-type(3) { animation-delay: 0.15s; }

.tw-hero:nth-child(4),
.kaldor-hero:nth-child(4) { animation-delay: 0.2s; }

.tw-hero:nth-child(5),
.kaldor-hero:nth-child(5) { animation-delay: 0.25s; }


/* =========================================
   ЗАГОЛОВКИ СЕКЦИЙ НА ГЛАВНОЙ
   ========================================= */

.home-block-news h1,
.home-block-padding h1 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    margin: 0 0 16px 0;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--primary);
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative;
}

.home-block-news h1::before,
.home-block-padding h1::before {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 40px;
    height: 2px;
    background: linear-gradient(90deg, var(--accent), transparent);
}

/* =========================================
   УЛУЧШЕННАЯ ГАЛЕРЕЯ ИЗОБРАЖЕНИЙ
   ========================================= */

.custom-col {
    width: 100%;
    margin: 0 auto;
    padding: 20px 30px;
}

.image-grid {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: 16px;
    flex-wrap: wrap;
    margin-top: 16px;
}

.image-wrapper {
    position: relative;
    margin: 0;
    text-align: center;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: var(--radius);
    padding: 10px;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    width: 180px;
}

.image-wrapper::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary), var(--accent), var(--primary));
    background-size: 200% 100%;
    animation: shop-shimmer 3s linear infinite;
    opacity: 0;
    transition: var(--transition);
}

.image-wrapper:hover {
    transform: translateY(-6px) scale(1.02);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-light);
}

.image-wrapper:hover::before {
    opacity: 1;
}

.image-wrapper a {
    display: block;
    position: relative;
    overflow: hidden;
    border-radius: var(--radius-sm);
}

.image-wrapper a::after {
    content: '🔍';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    font-size: 28px;
    opacity: 0;
    transition: var(--transition);
    background: rgba(0, 0, 0, 0.6);
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.image-wrapper:hover a::after {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.image-wrapper img {
    max-width: 100%;
    height: 120px;
    width: 100%;
    object-fit: cover;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    display: block;
}

.image-wrapper:hover img {
    transform: scale(1.08);
    filter: brightness(0.85);
}

.image-info {
    margin-top: 8px;
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
}

.image-date {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
}

/* Бейдж NEW на картинках */
.image-wrapper .node--newIndicator {
    position: absolute;
    top: 16px;
    right: 16px;
    background: linear-gradient(135deg, #e74c3c, #c0392b);
    color: #fff;
    font-size: 9px;
    font-weight: 800;
    padding: 3px 8px;
    border-radius: 10px;
    letter-spacing: 1px;
    box-shadow: 0 2px 8px rgba(231, 76, 60, 0.4);
    animation: badge-pulse 2s ease-in-out infinite;
    z-index: 2;
}

@keyframes badge-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* =========================================
   БЛОК ЦИТАТ
   ========================================= */

.block-quotes {
    width: 100%;
    max-width: 800px;
    margin: 20px auto;
    padding: 20px 24px;
    background: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(12px) saturate(180%);
    -webkit-backdrop-filter: blur(12px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    position: relative;
    overflow: hidden;
}

.block-quotes::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary), var(--accent), var(--primary));
    background-size: 200% 100%;
    animation: shop-shimmer 3s linear infinite;
}

h111 {
    font-size: 16px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 16px;
    color: var(--text);
    display: block;
    letter-spacing: 0.5px;
}

.quote-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
}

.quote-item {
    width: 100%;
    padding: 16px 24px;
    background: linear-gradient(135deg, rgba(98, 32, 180, 0.06), rgba(255, 152, 0, 0.04));
    border: 1px solid rgba(98, 32, 180, 0.15);
    border-radius: var(--radius);
    text-align: center;
    position: relative;
}

.quote-item::before {
    content: '"';
    position: absolute;
    top: -10px;
    left: 20px;
    font-size: 60px;
    color: var(--primary);
    opacity: 0.15;
    font-family: Georgia, serif;
    line-height: 1;
}

#quote-text {
    font-size: 14px;
    font-weight: 400;
    color: var(--text);
    margin: 0 0 10px 0;
    line-height: 1.5;
    font-style: italic;
    min-height: 40px;
}

#quote-author {
    font-size: 12px;
    font-weight: 600;
    color: var(--primary);
    margin: 0;
}

/* =========================================
   YOUTUBE БЛОК
   ========================================= */

.home-block-video iframe {
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    transition: var(--transition);
}

.home-block-video:hover iframe {
    box-shadow: var(--shadow-lg);
    transform: scale(1.02);
}

/* =========================================
   ТАБЛИЦА НОВОСТЕЙ И ИВЕНТОВ
   ========================================= */

.home-block-news .home-news-table {
    width: 100%;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    font-size: 13px;
    margin-top: 12px;
    border-spacing: 0 6px;
    border-collapse: separate;
    padding: 8px;
    border-radius: var(--radius);
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: var(--shadow-sm);
}

.home-block-news .home-news-table tr {
    transition: var(--transition);
}

.home-block-news .home-news-table tr td {
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.6);
    border-top: 1px solid rgba(255, 255, 255, 0.4);
    border-bottom: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: var(--radius-sm);
}

.home-block-news .home-news-table tr td:first-child {
    border-left: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: var(--radius-sm) 0 0 var(--radius-sm);
    border-left: 3px solid var(--primary);
}

.home-block-news .home-news-table tr td:last-child {
    border-right: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    text-align: right;
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}

.home-block-news .home-news-table tr:hover td {
    background: rgba(255, 255, 255, 0.95);
    transform: translateX(4px);
    box-shadow: var(--shadow-sm);
}

.home-block-news .home-news-table tr td a {
    color: var(--text);
    text-decoration: none;
    transition: var(--transition);
    font-weight: 500;
}

.home-block-news .home-news-table tr td a:hover {
    color: var(--primary);
}


/* =========================================
   КОМПАКТНЫЕ ТАБЫ ДЛЯ РЕЙТИНГОВ
   ========================================= */

/* Контейнер табов — компактный */
.home-block-news .nav-tabs {
    display: flex;
    flex-wrap: nowrap;
    gap: 3px;
    border-bottom: none;
    margin-bottom: 10px;
    padding: 4px;
    background: rgba(0, 0, 0, 0.06);
    border-radius: var(--radius-sm);
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.home-block-news .nav-tabs::-webkit-scrollbar {
    display: none;
}

.home-block-news .nav-tabs > li {
    margin: 0;
    flex: 1 1 auto;
    min-width: 0;
}

/* Сами табы — очень компактные */
.home-block-news .nav-tabs > li > a {
    margin: 0;
    padding: 5px 6px;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.6);
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-radius: 6px;
    transition: var(--transition);
    text-decoration: none;
    display: block;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
}

.home-block-news .nav-tabs > li > a:hover,
.home-block-news .nav-tabs > li > a:focus {
    background: rgba(255, 255, 255, 0.95);
    color: var(--primary);
    text-decoration: none;
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.home-block-news .nav-tabs > li.active > a,
.home-block-news .nav-tabs > li.active > a:focus,
.home-block-news .nav-tabs > li.active > a:hover {
    color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border-color: transparent;
    box-shadow: 0 3px 10px rgba(98, 32, 180, 0.3);
}

/* =========================================
   ОКНО КОНТЕНТА — ФИКСИРОВАННАЯ ВЫСОТА
   ========================================= */

.home-block-news .tab-content {
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 10px 12px;
    border-radius: var(--radius);
    border: 1px solid rgba(255, 255, 255, 0.3);
    height: 360px;
    overflow-y: auto;
    overflow-x: hidden;
    box-shadow: var(--shadow-sm);
}

/* Убираем скролл для вкладок рейтингов */
.home-block-news .tab-content#veteran,
.home-block-news .tab-content#newbie,
.home-block-news .tab-content#abyss,
.home-block-news .tab-content#gp,
.home-block-news .tab-content#kills,
.home-block-news .tab-content#legions,
.home-block-news .tab-content#duel,
.home-block-news .tab-content#mobkills,
.home-block-news .tab-content#healerpoint,
.home-block-news .tab-content#posol,
.home-block-news .tab-content#anoha,
.home-block-news .tab-content#shitha,
.home-block-news .tab-content#grendal,
.home-block-news .tab-content#sunya,
.home-block-news .tab-content#giper,
.home-block-news .tab-content#bases,
.home-block-news .tab-content#mounts,
.home-block-news .tab-content#deletes,
.home-block-news .tab-content#duel_lost,
.home-block-news .tab-content#stupid_notes {
    overflow-y: hidden;
}

/* =========================================
   ТАБЛИЦЫ РЕЙТИНГОВ — КОМПАКТНЫЕ
   ========================================= */

.home-block-news .abysstable,
.home-block-news .legionstable {
    width: 100%;
    margin: 0;
    border-collapse: separate;
    border-spacing: 0 3px;
}

/* Заголовки — компактные */
.home-block-news .abysstable tr th,
.home-block-news .legionstable tr th {
    color: #fff;
    padding: 6px 8px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    text-align: left;
    border: none;
    line-height: 1.2;
}

.home-block-news .abysstable tr th:first-child,
.home-block-news .legionstable tr th:first-child {
    border-radius: 6px 0 0 6px;
}

.home-block-news .abysstable tr th:last-child,
.home-block-news .legionstable tr th:last-child {
    border-radius: 0 6px 6px 0;
}

/* Строки — фиксированная высота для 10 строк */
.home-block-news .abysstable tr td,
.home-block-news .legionstable tr td {
    padding: 5px 8px;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(6px);
    border-top: 1px solid rgba(255, 255, 255, 0.4);
    border-bottom: 1px solid rgba(255, 255, 255, 0.4);
    font-size: 12px;
    color: var(--text);
    transition: var(--transition);
    vertical-align: middle;
    height: 26px;
    line-height: 1.3;
}

/* Закругление краёв */
.home-block-news .abysstable tr td:first-child,
.home-block-news .legionstable tr td:first-child {
    border-left: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 6px 0 0 6px;
}

.home-block-news .abysstable tr td:last-child,
.home-block-news .legionstable tr td:last-child {
    border-right: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 0 6px 6px 0;
}

/* Hover */
.home-block-news .abysstable tr:hover td,
.home-block-news .legionstable tr:hover td {
    background: rgba(255, 255, 255, 0.95);
    transform: translateX(3px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

/* ===== МЕДАЛИ ДЛЯ ТОП-3 ===== */
/* ===== МЕДАЛИ ДЛЯ ТОП-3 (исправленные) ===== */

/* 1-е место — золото (строка №2, т.к. №1 = заголовок) */
.home-block-news .abysstable tbody tr:nth-child(2) td:first-child,
.home-block-news .legionstable tbody tr:nth-child(2) td:first-child {
    position: relative;
    padding-left: 26px;
}

.home-block-news .abysstable tbody tr:nth-child(2) td:first-child::before,
.home-block-news .legionstable tbody tr:nth-child(2) td:first-child::before {
    content: '🥇';
    position: absolute;
    left: 6px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
    filter: drop-shadow(0 1px 2px rgba(255, 215, 0, 0.5));
    animation: medal-bounce 2s ease-in-out infinite;
}

/* 2-е место — серебро (строка №3) */
.home-block-news .abysstable tbody tr:nth-child(3) td:first-child,
.home-block-news .legionstable tbody tr:nth-child(3) td:first-child {
    position: relative;
    padding-left: 26px;
}

.home-block-news .abysstable tbody tr:nth-child(3) td:first-child::before,
.home-block-news .legionstable tbody tr:nth-child(3) td:first-child::before {
    content: '🥈';
    position: absolute;
    left: 6px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
    filter: drop-shadow(0 1px 2px rgba(192, 192, 192, 0.5));
}

/* 3-е место — бронза (строка №4) */
.home-block-news .abysstable tbody tr:nth-child(4) td:first-child,
.home-block-news .legionstable tbody tr:nth-child(4) td:first-child {
    position: relative;
    padding-left: 26px;
}

.home-block-news .abysstable tbody tr:nth-child(4) td:first-child::before,
.home-block-news .legionstable tbody tr:nth-child(4) td:first-child::before {
    content: '🥉';
    position: absolute;
    left: 6px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
    filter: drop-shadow(0 1px 2px rgba(205, 127, 50, 0.5));
}

/* ===== ПОДСВЕТКА СТРОК ТОП-3 (тоже сдвинута) ===== */

/* 1-е место — золото */
.home-block-news .abysstable tbody tr:nth-child(2) td,
.home-block-news .legionstable tbody tr:nth-child(2) td {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.18), rgba(255, 183, 77, 0.12));
    border-color: rgba(255, 215, 0, 0.35);
    font-weight: 600;
}

/* 2-е место — серебро */
.home-block-news .abysstable tbody tr:nth-child(3) td,
.home-block-news .legionstable tbody tr:nth-child(3) td {
    background: linear-gradient(135deg, rgba(192, 192, 192, 0.18), rgba(189, 189, 189, 0.12));
    border-color: rgba(192, 192, 192, 0.35);
    font-weight: 600;
}

/* 3-е место — бронза */
.home-block-news .abysstable tbody tr:nth-child(4) td,
.home-block-news .legionstable tbody tr:nth-child(4) td {
    background: linear-gradient(135deg, rgba(205, 127, 50, 0.15), rgba(205, 127, 50, 0.1));
    border-color: rgba(205, 127, 50, 0.35);
    font-weight: 600;
}

@keyframes medal-bounce {
    0%, 100% { transform: translateY(-50%) scale(1); }
    50% { transform: translateY(-50%) scale(1.15); }
}

/* =========================================
   АДАПТИВ
   ========================================= */

@media (max-width: 1100px) {
    .home-block-news .nav-tabs > li > a {
        padding: 4px 5px;
        font-size: 9px;
    }
    
    .home-block-news .abysstable tr td,
    .home-block-news .legionstable tr td {
        padding: 4px 6px;
        font-size: 11px;
    }
}

/* ===== ФИКС ДЛИННЫХ НИКОВ (ОДНА СТРОКА + ...) ===== */
.home-block-news .abysstable tbody tr td:first-child,
.home-block-news .legionstable tbody tr td:first-child {
    white-space: nowrap !important;      /* Запрещаем перенос текста на новую строку */
    overflow: hidden !important;         /* Скрываем всё, что вылезает за границы */
    text-overflow: ellipsis !important;  /* Добавляем троеточие (...) в конце длинного ника */
    max-width: 180px;                    /* Максимальная ширина колонки с ником (можешь поменять на 200px, если нужно шире) */
    
    /* Сохраняем отступ слева для медали */
    position: relative;
    padding-left: 26px !important;
}

/* Дополнительно: разрешаем остальным колонкам сжиматься, чтобы дать место нику */
.home-block-news .abysstable tr td:not(:first-child),
.home-block-news .legionstable tr td:not(:first-child) {
    white-space: nowrap;
    width: 1%; /* Трюк CSS: заставляет колонку занимать минимум места по содержимому */
}

/* ===== КНОПКИ — GLASSMORPHISM (ВЫРАВНЕННЫЕ) ===== */
.home-block-first .home-block-button {
    display: flex;
    align-items: center;
    width: 100%;
    max-width: 380px;
    min-height: 70px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    margin: 0 0 8px 0;
    transition: var(--transition);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    background: rgba(0, 0, 0, 0.4);
    font-size: 12px;
    padding: 12px 16px;
    color: #fff;
    position: relative;
    overflow: hidden;
    border-radius: var(--radius);
    box-sizing: border-box;
    text-decoration: none;
}

.home-block-first .home-block-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.15), transparent);
    transition: left 0.6s;
}

.home-block-first .home-block-button:hover::before {
    left: 100%;
}

.home-block-first .home-block-button:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(98, 32, 180, 0.3);
    border-color: var(--primary-light);
    background: rgba(98, 32, 180, 0.3);
    color: #fff;
    text-decoration: none;
}

.home-block-first .home-block-button-1 {
    background: url('../img/home-button-block-1.jpg') no-repeat;
    background-size: cover;
}

.home-block-first .home-block-button-2 {
    background: url('../img/home-button-block-2.jpg') no-repeat;
    background-size: cover;
}

.home-block-first .home-block-button-3 {
    background: url('../img/home-button-block-3.jpg') no-repeat;
    background-size: cover;
}

/* Внутренние колонки кнопок */
.home-block-first .home-block-button .col-xs-10 {
    width: 85%;
    padding: 0;
    float: none;
}

.home-block-first .home-block-button .col-xs-2 {
    width: 15%;
    padding: 0;
    float: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.home-block-first .home-block-button h4 {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 2px;
    color: #fff !important;
}

.home-block-first .home-block-button p {
    font-size: 11px;
    opacity: 0.85;
    margin: 0;
    line-height: 1.3;
}

/* =========================================
   ЦИТАТЫ ВЕТЕРАНОВ — GLASSMORPHISM (КОМПАКТ)
   ========================================= */

.veteran-quotes-block {
    position: relative;
    width: 100%;
    background: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(12px) saturate(180%);
    -webkit-backdrop-filter: blur(12px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    box-shadow: var(--shadow-md);
    overflow: hidden;
    transition: var(--transition);
    margin-bottom: 10px;
    /* ← УБРАНО: min-height, display:flex, justify-content */
}

/* Анимированная полоска сверху */
.veteran-quotes-block::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary), var(--accent), var(--primary));
    background-size: 200% 100%;
    animation: shop-shimmer 3s linear infinite;
}

/* Лёгкий градиент-фон */
.veteran-quotes-block::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(
        135deg,
        rgba(98, 32, 180, 0.04) 0%,
        rgba(138, 63, 212, 0.02) 50%,
        rgba(255, 152, 0, 0.03) 100%
    );
    pointer-events: none;
    z-index: 0;
}

.veteran-quotes-block:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg), 0 0 30px rgba(98, 32, 180, 0.12);
    border-color: var(--primary-light);
}

/* ===== ЗАГОЛОВОК ===== */
.vq-header {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: 0.5px;
    margin-bottom: 12px;
    text-transform: uppercase;
}

.vq-header i {
    font-size: 12px;
    color: var(--primary);
    opacity: 0.7;
    transition: var(--transition);
}

.veteran-quotes-block:hover .vq-header i {
    opacity: 1;
    color: var(--accent);
    transform: scale(1.15);
}

/* ===== ТЕЛО ЦИТАТЫ ===== */
.vq-body {
    position: relative;
    z-index: 1;
    background: linear-gradient(
        135deg,
        rgba(98, 32, 180, 0.06),
        rgba(255, 152, 0, 0.04)
    );
    border: 1px solid rgba(98, 32, 180, 0.15);
    border-radius: var(--radius);
    padding: 16px 18px;
    text-align: center;
    transition: var(--transition);
    /* ← УБРАНО: min-height, display:flex, justify-content */
}

.vq-body:hover {
    background: linear-gradient(
        135deg,
        rgba(98, 32, 180, 0.09),
        rgba(255, 152, 0, 0.06)
    );
    border-color: rgba(98, 32, 180, 0.25);
}

/* Большая декоративная кавычка */
.vq-quote-mark {
    position: absolute;
    top: -8px;
    left: 14px;
    font-size: 50px;
    color: var(--primary);
    opacity: 0.15;
    font-family: Georgia, serif;
    line-height: 1;
    transition: var(--transition);
}

.veteran-quotes-block:hover .vq-quote-mark {
    opacity: 0.25;
    transform: scale(1.1);
}

/* Текст цитаты */
.vq-text {
    font-size: 13px;
    font-weight: 400;
    color: var(--text);
    line-height: 1.55;
    font-style: italic;
    margin: 0 0 12px 0;
    position: relative;
    z-index: 1;
    /* ← УБРАНО: min-height */
}

/* Анимация смены цитаты */
.vq-text.typing {
    animation: fadeInUp 0.6s ease;
}

/* ===== АВТОР ===== */
.vq-author {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    /* ← УБРАНО: margin-top: auto */
}

.vq-author-line {
    flex: 1;
    max-width: 50px;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--primary), transparent);
    opacity: 0.5;
}

.vq-author-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--primary);
    letter-spacing: 0.5px;
    white-space: nowrap;
    transition: var(--transition);
}

.veteran-quotes-block:hover .vq-author-name {
    color: var(--primary-dark);
    text-shadow: 0 0 8px rgba(98, 32, 180, 0.2);
}

/* ===== ТОЧКИ-ИНДИКАТОРЫ ===== */
.vq-dots {
    position: relative;
    z-index: 1;
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-top: 12px;
}

.vq-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: rgba(98, 32, 180, 0.2);
    border: 1px solid rgba(98, 32, 180, 0.3);
    cursor: pointer;
    transition: var(--transition);
}

.vq-dot.active {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border-color: var(--primary);
    box-shadow: 0 0 8px rgba(98, 32, 180, 0.5);
    transform: scale(1.3);
}

.vq-dot:hover {
    background: rgba(98, 32, 180, 0.5);
    transform: scale(1.2);
}

/* Адаптив */
@media (max-width: 1100px) {
    .veteran-quotes-block {
        padding: 14px 16px;
    }
    .vq-header { font-size: 12px; }
    .vq-text { font-size: 12px; }
}

/* === ФИКС ВЫРАВНИВАНИЯ === */
.home-block-first {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start; /* ← Выравниваем по верху, отключаем растягивание */
    min-height: 280px;
}

/* Сбрасываем float, чтобы flex работал корректно */
.home-block-first .col-xs-6 {
    float: none;
    width: 50%;
    box-sizing: border-box;
}

/* === КОМПАКТНЫЙ БЛОК ЦИТАТ === */
.veteran-quotes-block {
    position: relative;
    width: 100%;
    max-height: 260px; /* ← Жёсткий лимит под высоту 3 кнопок */
    background: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(12px) saturate(180%);
    -webkit-backdrop-filter: blur(12px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    box-shadow: var(--shadow-md);
    overflow: hidden;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    margin: 0;
}

/* ===== КОМПАКТНЫЙ БЛОК АУКЦИОНА ===== */
.auction-home-wrapper {
    width: 100%;
    background: linear-gradient(135deg, rgba(98,32,180,0.08), rgba(255,152,0,0.06)) !important;
    border: 2px solid rgba(98,32,180,0.2);
    border-radius: 10px;
    padding: 12px 15px !important;
    margin: 10px 0 !important;
    box-shadow: 0 2px 10px rgba(98,32,180,0.1);
    color: #333 !important;
    min-height: auto !important;
    overflow: visible !important;
}

.auction-home-wrapper h1 {
    font-size: 20px !important;
    font-weight: 800 !important;
    text-align: center;
    margin: 0 0 10px 0 !important;
    background: linear-gradient(135deg, #6220b4, #ff9800) !important;
    -webkit-background-clip: text !important;
    -webkit-text-fill-color: transparent !important;
    background-clip: text !important;
    border-bottom: none !important;
    padding-bottom: 0 !important;
}

.auction-home-wrapper h1::before {
    display: none !important;
}

.auction-subtitle-home {
    font-size: 11px !important;
    color: #666 !important;
    font-weight: 600 !important;
    -webkit-text-fill-color: #666 !important;
}

/* ===== СЕТКА КАРТОЧЕК (ГОРИЗОНТАЛЬНАЯ) ===== */
.auction-grid-home {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 10px;
}

/* ===== КАРТОЧКА (ГОРИЗОНТАЛЬНАЯ) ===== */
.auction-card-home {
    display: flex;
    align-items: center;
    gap: 10px;
    background: linear-gradient(135deg, #ffffff 0%, #f8f9ff 100%);
    border: 1.5px solid rgba(98,32,180,0.2);
    border-radius: 8px;
    overflow: hidden;
    text-decoration: none;
    transition: all 0.2s ease;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    position: relative;
    color: #333;
    padding: 8px;
}

.auction-card-home::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, #6220b4, #ff9800, #6220b4);
    opacity: 0.6;
}

.auction-card-home:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(98,32,180,0.2);
    border-color: #6220b4;
    text-decoration: none;
    color: #333;
}

.auction-card-home:hover::before { opacity: 1; }

/* ===== ИКОНКА СЛЕВА ===== */
.card-icon-wrapper {
    flex-shrink: 0;
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, rgba(98,32,180,0.04), rgba(255,152,0,0.02));
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
}

.card-icon {
    max-width: 42px;
    max-height: 42px;
    object-fit: contain;
    filter: drop-shadow(0 1px 3px rgba(0,0,0,0.15));
    transition: transform 0.2s ease;
}

.auction-card-home:hover .card-icon { transform: scale(1.08); }

/* ===== КОНТЕНТ ПО ЦЕНТРУ ===== */
.card-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.card-name {
    font-size: 11px;
    font-weight: 700;
    color: #2c3e50;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-badges {
    display: flex;
    gap: 2px;
    flex-wrap: wrap;
}

.badge-main {
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 8px;
    font-weight: 800;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.badge-main.enchant {
    background: rgba(231,76,60,0.15);
    color: #e74c3c;
    border: 1px solid rgba(231,76,60,0.3);
}

.badge-main.authorize {
    background: rgba(255,152,0,0.15);
    color: #e67e22;
    border: 1px solid rgba(255,152,0,0.3);
}

.badge-main.eb {
    background: rgba(156,39,176,0.15);
    color: #9c27b0;
    border: 1px solid rgba(156,39,176,0.3);
}

.badge-stones {
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 8px;
    font-weight: 800;
    background: rgba(52,152,219,0.15);
    color: #3498db;
    border: 1px solid rgba(52,152,219,0.3);
}

.badge-qty {
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 8px;
    font-weight: 800;
    background: rgba(108,117,125,0.15);
    color: #6c757d;
    border: 1px solid rgba(108,117,125,0.3);
}

/* ===== ПРОДАВЕЦ + РАСА ===== */
.card-seller {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 9px;
    color: #666;
}

.race-icon {
    font-size: 10px;
    line-height: 1;
}

.race-icon.elyos {
    filter: drop-shadow(0 0 2px rgba(255,215,0,0.5));
}

.race-icon.asmodian {
    filter: drop-shadow(0 0 2px rgba(142,68,173,0.5));
}

.seller-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 80px;
}

/* ===== ФЛАГИ AMP/PACK ===== */
.card-flags {
    display: flex;
    gap: 2px;
    margin-left: auto;
}

.flag-badge {
    padding: 1px 3px;
    border-radius: 2px;
    font-size: 7px;
    font-weight: 800;
    letter-spacing: 0.3px;
}

.flag-badge.amp {
    background: linear-gradient(135deg, #f39c12, #e67e22);
    color: #fff;
    box-shadow: 0 1px 2px rgba(243,156,18,0.3);
}

.flag-badge.pack {
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: #fff;
    box-shadow: 0 1px 2px rgba(52,152,219,0.3);
}

/* ===== ЦЕНА СПРАВА ===== */
.card-price-wrapper {
    flex-shrink: 0;
    text-align: right;
    padding-left: 8px;
    border-left: 1px solid rgba(98,32,180,0.1);
}

.card-price {
    font-size: 14px;
    font-weight: 800;
    background: linear-gradient(135deg, #6220b4, #ff9800);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1.1;
    white-space: nowrap;
}

.price-label {
    font-size: 8px;
    font-weight: 700;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ===== ПУСТОЕ СОСТОЯНИЕ ===== */
.auction-empty-home {
    text-align: center;
    padding: 20px;
    background: rgba(255,255,255,0.5);
    border-radius: 8px;
    border: 1px dashed rgba(98,32,180,0.2);
}

.auction-empty-home i {
    font-size: 32px;
    color: rgba(98,32,180,0.3);
    margin-bottom: 8px;
    display: block;
}

.auction-empty-home p {
    font-size: 12px;
    color: #666;
    margin: 0 0 10px 0;
}

.btn-auction-home {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 16px;
    background: linear-gradient(135deg, #6220b4, #8e44ad);
    color: #fff !important;
    border-radius: 6px;
    text-decoration: none !important;
    font-weight: 700;
    font-size: 11px;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(98,32,180,0.3);
}

.btn-auction-home:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(98,32,180,0.4);
    color: #fff !important;
    text-decoration: none !important;
}

/* ===== ФУТЕР ===== */
.auction-footer-home {
    text-align: center;
    margin-top: 8px;
}

.btn-all-lots {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 16px;
    background: linear-gradient(135deg, #28a745, #20c997);
    color: #fff !important;
    border-radius: 6px;
    text-decoration: none !important;
    font-weight: 700;
    font-size: 11px;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(40,167,69,0.3);
}

.btn-all-lots:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(40,167,69,0.4);
    color: #fff !important;
    text-decoration: none !important;
}

/* ===== АДАПТИВ ===== */
@media (max-width: 992px) {
    .auction-grid-home { grid-template-columns: 1fr; }
}

@media (max-width: 576px) {
    .auction-home-wrapper h1 { font-size: 18px !important; }
    .card-name { font-size: 10px; }
    .card-price { font-size: 12px; }
}

/* Заголовок, тело, точки — оставляем как в прошлом ответе */

<?php
class AuctionManager {
    private $dbSiel;
    private $dbLs;
    
    // ✅ НАСТРОЙКИ
    private $depositAmount = 5;
    private $minStartPrice = 25;
    private $minTotalPrice = 25; 
    private $bidStepPercent = 5;
    private $minBidStep = 1;
    private $commissionPercent = 10;
    private $listingDuration = 1209600; // 14 дней общий срок
    private $auctionPhaseDuration = 86400; // 24 часа фаза ставок
    
    public function __construct($dbSiel, $dbLs) {
        $this->dbSiel = $dbSiel;
        $this->dbLs = $dbLs;
    }
    
    private function beginTransaction($db) { if (method_exists($db, 'beginTransaction')) $db->beginTransaction(); }
    private function commit($db) { if (method_exists($db, 'commit')) $db->commit(); }
    private function rollBack($db) { 
        if (method_exists($db, 'rollBack')) $db->rollBack(); 
        elseif (method_exists($db, 'rollback')) $db->rollback(); 
    }
    
    /**
     * ✅ ЕДИНАЯ ТОЧКА РАСЧЁТА МИНИМАЛЬНОГО ШАГА СТАВКИ.
     * Шаг всегда СТРОГО НЕ МЕНЬШЕ $bidStepPercent (5%) от текущей ОБЩЕЙ стоимости лота
     * (лот может быть стаком из N предметов — price уже хранит стоимость ВСЕГО стака,
     * поэтому шаг считается от общей суммы и количество предметов в стаке роли не играет).
     * ceil() гарантирует, что округление никогда не занизит шаг ниже 5%.
     */
    private function calcMinBidStep($currentTotalValue) {
        $currentTotalValue = (int)$currentTotalValue;
        $step = (int)ceil($currentTotalValue * ($this->bidStepPercent / 100));
        return max($this->minBidStep, $step);
    }
    
    private function generateUniqueId() {
        try { @$this->dbSiel->query("LOCK TABLES `inventory` WRITE"); } catch (Exception $e) {}
        $maxInv = $this->dbSiel->queryFetchSingle("SELECT MAX(item_unique_id) as max_id FROM `inventory`");
        $newId = (int)($maxInv['max_id'] ?? 0) + 1;
        try { @$this->dbSiel->query("UNLOCK TABLES"); } catch (Exception $e) {}
        return $newId;
    }
    
    private function getItemStones($itemUniqueId) {
        try {
            $stones = $this->dbSiel->queryFetch(
                "SELECT `slot`, `category`, `item_id`, `polishNumber`, `polishCharge` 
                 FROM `item_stones` 
                 WHERE `item_unique_id` = ?",
                [$itemUniqueId]
            );
            return $stones ?: [];
        } catch (\Throwable $e) {
            return [];
        }
    }
    
    private function saveAuctionStones($auctionId, $stones) {
        if (empty($stones)) return;
        foreach ($stones as $stone) {
            $this->dbSiel->query("INSERT INTO `auction_stones` (`auction_id`, `slot`, `category`, `item_id`, `polishNumber`, `polishCharge`) VALUES (?, ?, ?, ?, ?, ?)",
                [$auctionId, $stone['slot'], $stone['category'], (int)$stone['item_id'], (int)$stone['polishNumber'], (int)$stone['polishCharge']]);
        }
    }
    
    private function restoreStonesToInventory($newUniqueId, $auctionId) {
        try {
            $stmt = $this->dbSiel->query("SELECT `slot`, `category`, `item_id`, `polishNumber`, `polishCharge` FROM `auction_stones` WHERE `auction_id` = ?", [$auctionId]);
            if (!$stmt || !is_object($stmt)) return;
            while ($stone = $stmt->fetch(PDO::FETCH_ASSOC)) {
                try {
                    $this->dbSiel->query("INSERT INTO `item_stones` (`item_unique_id`, `item_id`, `slot`, `category`, `polishNumber`, `polishCharge`) VALUES (?, ?, ?, ?, ?, ?)",
                        [$newUniqueId, (int)$stone['item_id'], $stone['slot'], $stone['category'], (int)$stone['polishNumber'], (int)$stone['polishCharge']]);
                } catch (\Throwable $e) {}
            }
        } catch (\Throwable $e) {}
    }

    private function clearAuctionStones($auctionId) {
        try { $this->dbSiel->query("DELETE FROM `auction_stones` WHERE `auction_id` = ?", [$auctionId]); } catch (\Throwable $e) {}
    }
    
    public function canList($item, $player) {
        if ($player['online'] != 0) return ['ok' => false, 'error' => 'Персонаж должен быть оффлайн!'];
        if ($item['is_equiped'] == 1) return ['ok' => false, 'error' => 'Нельзя продать экипированный предмет!'];
        if ($item['is_soul_bound'] == 1) return ['ok' => false, 'error' => 'Привязанные предметы нельзя продавать!'];
        if ($item['item_location'] != 0) return ['ok' => false, 'error' => 'Предмет должен быть в инвентаре!'];
        return ['ok' => true];
    }
    
    public function listAuction($playerId, $playerName, $itemUniqueId, $quantity, $price, $playerToll) {
        $stones = []; 
        try {
            $this->beginTransaction($this->dbSiel);
            
            $item = $this->dbSiel->queryFetchSingle("SELECT * FROM `inventory` WHERE `item_unique_id` = ? AND `item_owner` = ?", [$itemUniqueId, $playerId]);
            if (!$item) throw new Exception('Предмет не найден');
            
            $player = $this->dbSiel->queryFetchSingle("SELECT * FROM `players` WHERE `id` = ?", [$playerId]);
            if (!$player) throw new Exception('Игрок не найден');
            
            $can = $this->canList($item, $player);
            if (!$can['ok']) throw new Exception($can['error']);
            
            $quantity = (int)$quantity;
            if ($quantity <= 0 || $quantity > $item['item_count']) throw new Exception('Неверное количество');
            
            $startPrice = (int)$price; // Цена за единицу от пользователя
            $totalLotValue = $startPrice * $quantity;
            
            if ($totalLotValue < $this->minTotalPrice) {
                throw new Exception('Минимальная общая стоимость лота: ' . $this->minTotalPrice . ' PTS.');
            }
            
            if ($playerToll < $this->depositAmount) throw new Exception('Недостаточно PTS для депозита.');
            
            $now = time();
            $expires = $now + $this->listingDuration;
            
            // ✅ ВАЖНО: В поле price мы сразу кладем ОБЩУЮ СТОИМОСТЬ ЛОТА
            $params = [
                $item['item_id'], $quantity, $playerId, $playerName, $totalLotValue, 
                $now, $expires,
                (int)$item['item_color'], (int)$item['color_expires'], $item['item_creator'],
                (int)$item['expire_time'], (int)$item['activation_count'], (int)$item['is_soul_bound'],
                $item['enchant'] ?? '0', (int)($item['enchant_bonus'] ?? 0),
                (int)$item['item_skin'], (int)$item['fusioned_item'],
                (int)$item['optional_socket'], (int)$item['optional_fusion_socket'],
                (int)$item['charge'], $item['rnd_bonus'], (int)$item['rnd_count'],
                (int)$item['pack_count'], (int)$item['pack_aftr_20_ench'],
                (int)$item['authorize'], (int)$item['is_packed'],
                (int)$item['is_amplified'], (int)$item['buff_skill']
            ];
            
            $sql = "INSERT INTO `auction_items` 
                (item_id, item_count, seller_id, seller_name, price, deposit_paid, listed_at, expires_at, status, 
                 item_color, color_expires, item_creator, expire_time, activation_count, is_soul_bound, 
                 enchant, enchant_bonus, item_skin, fusioned_item, optional_socket, optional_fusion_socket, 
                 charge, rnd_bonus, rnd_count, pack_count, pack_aftr_20_ench, authorize, is_packed, 
                 is_amplified, buff_skill) 
                VALUES (?, ?, ?, ?, ?, 1, ?, ?, 'active', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
            
            $stones = $this->getItemStones($item['item_unique_id']);
            
            if ($quantity < $item['item_count']) {
                $this->dbSiel->query("UPDATE `inventory` SET `item_count` = `item_count` - ? WHERE `item_unique_id` = ?", [$quantity, $item['item_unique_id']]);
                $this->dbSiel->query($sql, $params);
            } else {
                $this->dbSiel->query($sql, $params);
                $auctionId = $this->dbSiel->lastInsertId();
                
                if (!empty($stones)) {
                    $this->saveAuctionStones($auctionId, $stones);
                }
                
                $this->dbSiel->query("DELETE FROM `inventory` WHERE `item_unique_id` = ?", [$item['item_unique_id']]);
            }
            
            $this->dbLs->query("UPDATE `account_data` SET `toll` = `toll` - ? WHERE `id` = ?", [$this->depositAmount, $player['account_id']]);
            
            $this->commit($this->dbSiel);
            return ['ok' => true, 'auction_id' => $this->dbSiel->lastInsertId()];
            
        } catch (Exception $e) {
            $this->rollBack($this->dbSiel);
            return ['ok' => false, 'error' => $e->getMessage()];
        }
    }
    
    public function placeBid($buyerId, $buyerName, $auctionId, $bidAmount, $buyerToll) {
        try {
            $this->beginTransaction($this->dbSiel);
            $lot = $this->dbSiel->queryFetchSingle("SELECT * FROM `auction_items` WHERE `auction_id` = ? AND `status` = 'active'", [$auctionId]);
            if (!$lot) throw new Exception('Лот не найден');
            
            $timePassed = time() - $lot['listed_at'];
            if ($timePassed > $this->auctionPhaseDuration) throw new Exception('Фаза ставок завершена.');
            if ($lot['seller_id'] == $buyerId) throw new Exception('Нельзя ставить на свой предмет');
            
            $buyer = $this->dbSiel->queryFetchSingle("SELECT * FROM `players` WHERE `id` = ?", [$buyerId]);
            if (!$buyer || $buyer['online'] != 0) throw new Exception('Покупатель должен быть оффлайн');
            
            // ✅ В PRICE ЛЕЖИТ ОБЩАЯ СТОИМОСТЬ ЛОТА (за весь стак сразу)
            $currentTotalValue = (int)$lot['price'];
            
            // ✅ Шаг ставки: ВСЕГДА минимум 5% от текущей ОБЩЕЙ стоимости лота.
            // Используем единый метод calcMinBidStep(), который через ceil() гарантирует,
            // что шаг никогда не окажется меньше 5% — независимо от размера стака и суммы лота.
            $step = $this->calcMinBidStep($currentTotalValue);
            $minNextBidTotal = $currentTotalValue + $step;
            
            if ($bidAmount < $minNextBidTotal) {
                throw new Exception('Минимальная ставка: ' . $minNextBidTotal . ' PTS (шаг +' . $step . ' PTS, не менее ' . $this->bidStepPercent . '%)');
            }
            
            if ($buyerToll < $bidAmount) throw new Exception('Недостаточно PTS для ставки.');
            
            $this->dbLs->query("UPDATE `account_data` SET `toll` = `toll` - ? WHERE `id` = ?", [$bidAmount, $buyer['account_id']]);
            
            $lastBid = $this->dbSiel->queryFetchSingle("SELECT * FROM `auction_bids` WHERE `auction_id` = ? ORDER BY `id` DESC LIMIT 1", [$auctionId]);
            if ($lastBid) {
                $prevBuyer = $this->dbSiel->queryFetchSingle("SELECT `account_id` FROM `players` WHERE `id` = ?", [$lastBid['player_id']]);
                if ($prevBuyer) {
                    $this->dbLs->query("UPDATE `account_data` SET `toll` = `toll` + ? WHERE `id` = ?", [$lastBid['bid_amount'], $prevBuyer['account_id']]);
                }
            }
            
            // Обновляем ОБЩУЮ цену в лоте
            $this->dbSiel->query("UPDATE `auction_items` SET `price` = ? WHERE `auction_id` = ?", [$bidAmount, $auctionId]);
            
            $this->dbSiel->query("INSERT INTO `auction_bids` (`auction_id`, `player_id`, `player_name`, `bid_amount`, `created_at`) VALUES (?, ?, ?, ?, ?)", [$auctionId, $buyerId, $buyerName, $bidAmount, time()]);
            
            $this->commit($this->dbSiel);
            return ['ok' => true, 'new_price' => $bidAmount];
        } catch (Exception $e) {
            $this->rollBack($this->dbSiel);
            return ['ok' => false, 'error' => $e->getMessage()];
        }
    }

    public function buyAuction($buyerId, $buyerName, $auctionId, $buyerToll) {
        try {
            $this->beginTransaction($this->dbSiel);
            $lot = $this->dbSiel->queryFetchSingle("SELECT * FROM `auction_items` WHERE `auction_id` = ? AND `status` = 'active'", [$auctionId]);
            if (!$lot) throw new Exception('Лот не найден');
            
            $timePassed = time() - $lot['listed_at'];
            if ($timePassed <= $this->auctionPhaseDuration) throw new Exception('Сейчас идет фаза ставок.');
            
            $bidCount = $this->dbSiel->queryFetchSingle("SELECT COUNT(*) as cnt FROM `auction_bids` WHERE `auction_id` = ?", [$auctionId]);
            if (($bidCount['cnt'] ?? 0) > 0) throw new Exception('На этот лот были ставки.');
            
            if ($lot['seller_id'] == $buyerId) throw new Exception('Нельзя купить свой предмет');
            
            $buyer = $this->dbSiel->queryFetchSingle("SELECT * FROM `players` WHERE `id` = ?", [$buyerId]);
            if (!$buyer || $buyer['online'] != 0) throw new Exception('Покупатель должен быть оффлайн');
            
            // ✅ В PRICE ТЕПЕРЬ ОБЩАЯ СТОИМОСТЬ
            $totalCost = (int)$lot['price'];
            
            if ($buyerToll < $totalCost) throw new Exception('Недостаточно PTS. Нужно: ' . $totalCost);
            
            $freeSlot = $this->findFreeInventorySlot($buyerId);
            if (!$freeSlot) throw new Exception('Инвентарь покупателя переполнен');
            
            $now = time();
            $newUniqueId = $this->generateUniqueId();
            $this->insertInventoryItem($newUniqueId, $lot, $buyerId, $freeSlot);
            $this->restoreStonesToInventory($newUniqueId, $auctionId);
            $this->clearAuctionStones($auctionId);
            
            $this->dbLs->query("UPDATE `account_data` SET `toll` = `toll` - ? WHERE `id` = ?", [$totalCost, $buyer['account_id']]);
            
            $sellerReceive = (int)floor($totalCost * (100 - $this->commissionPercent) / 100);
            $seller = $this->dbSiel->queryFetchSingle("SELECT `account_id` FROM `players` WHERE `id` = ?", [$lot['seller_id']]);
            if ($seller) $this->dbLs->query("UPDATE `account_data` SET `toll` = `toll` + ? WHERE `id` = ?", [$sellerReceive, $seller['account_id']]);
            
            $this->dbSiel->query("UPDATE `auction_items` SET `status` = 'sold', `buyer_id` = ?, `buyer_name` = ?, `sold_at` = ? WHERE `auction_id` = ?", [$buyerId, $buyerName, $now, $auctionId]);
            
            $this->commit($this->dbSiel);
            return ['ok' => true];
        } catch (Exception $e) {
            $this->rollBack($this->dbSiel);
            return ['ok' => false, 'error' => $e->getMessage()];
        }
    }

    private function insertInventoryItem($newUniqueId, $lot, $ownerId, $freeSlot) {
        $sql = "INSERT INTO `inventory` (item_unique_id, item_id, item_count, item_color, color_expires, item_creator, expire_time, activation_count, item_owner, is_equiped, is_soul_bound, slot, item_location, enchant, enchant_bonus, item_skin, fusioned_item, optional_socket, optional_fusion_socket, charge, rnd_bonus, rnd_count, pack_count, pack_aftr_20_ench, authorize, is_packed, is_amplified, buff_skill) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, 0, 0, ?, 0, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
        
        $params = [$newUniqueId, $lot['item_id'], $lot['item_count'], (int)$lot['item_color'], (int)$lot['color_expires'], $lot['item_creator'], (int)$lot['expire_time'], (int)$lot['activation_count'], $ownerId, $freeSlot, $lot['enchant'] ?? '0', (int)($lot['enchant_bonus'] ?? 0), (int)$lot['item_skin'], (int)$lot['fusioned_item'], (int)$lot['optional_socket'], (int)$lot['optional_fusion_socket'], (int)$lot['charge'], $lot['rnd_bonus'], (int)$lot['rnd_count'], (int)$lot['pack_count'], (int)$lot['pack_aftr_20_ench'], (int)$lot['authorize'], (int)$lot['is_packed'], (int)$lot['is_amplified'], (int)$lot['buff_skill']];
        $this->dbSiel->query($sql, $params);
    }
    
    private function findFreeInventorySlot($playerId) {
        $occupied = $this->dbSiel->queryFetch("SELECT DISTINCT `slot` FROM `inventory` WHERE `item_owner` = ? AND `item_location` = 0 AND `is_equiped` = 0 AND `slot` >= 0 AND `slot` < 108", [$playerId]);
        $occupiedSlots = [];
        if (is_array($occupied)) foreach ($occupied as $row) $occupiedSlots[] = (int)$row['slot'];
        for ($i = 0; $i < 108; $i++) if (!in_array($i, $occupiedSlots)) return $i;
        return false;
    }

    public function finalizeAuction($auctionId) {
        try {
            $this->beginTransaction($this->dbSiel);
            $lot = $this->dbSiel->queryFetchSingle("SELECT * FROM `auction_items` WHERE `auction_id` = ? AND `status` = 'active'", [$auctionId]);
            if (!$lot || $lot['expires_at'] > time()) { $this->rollBack($this->dbSiel); return false; }
            
            $winner = $this->dbSiel->queryFetchSingle("SELECT * FROM `auction_bids` WHERE `auction_id` = ? ORDER BY `bid_amount` DESC LIMIT 1", [$auctionId]);
            
            if ($winner) {
                $buyer = $this->dbSiel->queryFetchSingle("SELECT * FROM `players` WHERE `id` = ?", [$winner['player_id']]);
                $finalPrice = (int)$winner['bid_amount']; 
                
                if ($buyer && $buyer['online'] == 0) {
                    $freeSlot = $this->findFreeInventorySlot($buyer['id']);
                    if ($freeSlot) {
                        $newUniqueId = $this->generateUniqueId();
                        $this->insertInventoryItem($newUniqueId, $lot, $buyer['id'], $freeSlot);
                        $this->restoreStonesToInventory($newUniqueId, $auctionId);
                        $this->clearAuctionStones($auctionId);
                        
                        $sellerReceive = (int)floor($finalPrice * (100 - $this->commissionPercent) / 100);
                        $seller = $this->dbSiel->queryFetchSingle("SELECT `account_id` FROM `players` WHERE `id` = ?", [$lot['seller_id']]);
                        if ($seller) $this->dbLs->query("UPDATE `account_data` SET `toll` = `toll` + ? WHERE `id` = ?", [$sellerReceive, $seller['account_id']]);
                        
                        $this->dbSiel->query("UPDATE `auction_items` SET `status` = 'sold', `buyer_id` = ?, `buyer_name` = ?, `sold_at` = ? WHERE `auction_id` = ?", [$buyer['id'], $buyer['name'], time(), $auctionId]);
                    } else {
                         $this->returnLotToSellerInternal($lot);
                         $this->dbLs->query("UPDATE `account_data` SET `toll` = `toll` + ? WHERE `id` = ?", [$finalPrice, $buyer['account_id']]);
                    }
                } else {
                     $this->returnLotToSellerInternal($lot);
                     if ($buyer) $this->dbLs->query("UPDATE `account_data` SET `toll` = `toll` + ? WHERE `id` = ?", [$finalPrice, $buyer['account_id']]);
                }
            } else {
                 $this->returnLotToSellerInternal($lot);
            }
            
            $this->commit($this->dbSiel);
            return true;
        } catch (Exception $e) {
            $this->rollBack($this->dbSiel);
            return false;
        }
    }
    
    private function returnLotToSellerInternal($lot) {
        $seller = $this->dbSiel->queryFetchSingle("SELECT * FROM `players` WHERE `id` = ?", [$lot['seller_id']]);
        if ($seller && $seller['online'] == 0) {
            $freeSlot = $this->findFreeInventorySlot($lot['seller_id']);
            if ($freeSlot) {
                $newUniqueId = $this->generateUniqueId();
                $this->insertInventoryItem($newUniqueId, $lot, $lot['seller_id'], $freeSlot);
                $this->restoreStonesToInventory($newUniqueId, $lot['auction_id']);
                $this->clearAuctionStones($lot['auction_id']);
                $this->dbSiel->query("UPDATE `auction_items` SET `status` = 'returned' WHERE `auction_id` = ?", [$lot['auction_id']]);
            }
        }
    }

    public function cancelLot($playerId, $auctionId) {
        try {
            $this->beginTransaction($this->dbSiel);
            
            $lot = $this->dbSiel->queryFetchSingle(
                "SELECT * FROM `auction_items` WHERE `auction_id` = ? AND `seller_id` = ?", 
                [$auctionId, $playerId]
            );
            
            if (!$lot) throw new Exception('Лот не найден.');

            if ($lot['status'] !== 'active') {
                throw new Exception('Этот лот уже не активен (статус: ' . $lot['status'] . ').');
            }
            
            $timePassed = time() - $lot['listed_at'];
            if ($timePassed < $this->auctionPhaseDuration) {
                $secondsLeft = $this->auctionPhaseDuration - $timePassed;
                $hours = floor($secondsLeft / 3600);
                $minutes = floor(($secondsLeft % 3600) / 60);
                throw new Exception('Отмена недоступна во время фазы ставок. Осталось: ' . $hours . ' ч. ' . $minutes . ' мин.');
            }
            
            $bidCount = $this->dbSiel->queryFetchSingle("SELECT COUNT(*) as cnt FROM `auction_bids` WHERE `auction_id` = ?", [$auctionId]);
            if (($bidCount['cnt'] ?? 0) > 0) {
                throw new Exception('Нельзя отменить лот, на который уже сделаны ставки!');
            }
            
            $player = $this->dbSiel->queryFetchSingle("SELECT * FROM `players` WHERE `id` = ?", [$playerId]);
            if (!$player || $player['online'] != 0) {
                throw new Exception('Для управления аукционом персонаж должен быть оффлайн.');
            }
            
            $freeSlot = $this->findFreeInventorySlot($playerId);
            if (!$freeSlot) {
                throw new Exception('Недостаточно места в инвентаре для возврата предмета.');
            }
            
            $newUniqueId = $this->generateUniqueId();
            $this->insertInventoryItem($newUniqueId, $lot, $playerId, $freeSlot);
            $this->restoreStonesToInventory($newUniqueId, $auctionId);
            $this->clearAuctionStones($auctionId);
            
            $this->dbSiel->query("DELETE FROM `auction_bids` WHERE `auction_id` = ?", [$auctionId]); 
            $this->dbSiel->query("UPDATE `auction_items` SET `status` = 'cancelled' WHERE `auction_id` = ?", [$auctionId]);
            
            $this->commit($this->dbSiel);
            return ['ok' => true];
            
        } catch (Exception $e) {
            $this->rollBack($this->dbSiel);
            return ['ok' => false, 'error' => $e->getMessage()];
        }
    }

    public function getActiveLots($filters = [], $page = 1, $perPage = 24) {
        $where = ["a.`status` = 'active'"];
        $params = [];
        if (!empty($filters['min_price'])) { $where[] = "a.`price` >= ?"; $params[] = $filters['min_price']; }
        if (!empty($filters['max_price'])) { $where[] = "a.`price` <= ?"; $params[] = $filters['max_price']; }
        
        $whereStr = implode(' AND ', $where);
        $offset = ($page - 1) * $perPage;
        $total = $this->dbSiel->queryFetchSingle("SELECT COUNT(*) as cnt FROM `auction_items` a WHERE $whereStr", $params);
        $lots = $this->dbSiel->queryFetch("SELECT a.*, p.online as seller_online, p.race as seller_race, (SELECT COUNT(*) FROM `auction_stones` s WHERE s.auction_id = a.auction_id) as stones_count, (SELECT player_name FROM `auction_bids` b WHERE b.auction_id = a.auction_id ORDER BY b.id DESC LIMIT 1) as last_bidder, (SELECT COUNT(*) FROM `auction_bids` b WHERE b.auction_id = a.auction_id) as bids_count FROM `auction_items` a LEFT JOIN `players` p ON p.id = a.seller_id WHERE $whereStr ORDER BY a.`expires_at` ASC LIMIT $offset, $perPage", $params);
        return ['lots' => $lots ?: [], 'total' => $total['cnt'] ?? 0, 'page' => $page, 'per_page' => $perPage];
    }
    
    public function getLotById($auctionId) {
        return $this->dbSiel->queryFetchSingle("SELECT a.*, p.online as seller_online, p.race as seller_race, (SELECT COUNT(*) FROM `auction_stones` s WHERE s.auction_id = a.auction_id) as stones_count, (SELECT player_name FROM `auction_bids` b WHERE b.auction_id = a.auction_id ORDER BY b.id DESC LIMIT 1) as last_bidder, (SELECT COUNT(*) FROM `auction_bids` b WHERE b.auction_id = a.auction_id) as bids_count FROM `auction_items` a LEFT JOIN `players` p ON p.id = a.seller_id WHERE a.`auction_id` = ?", [$auctionId]);
    }

    public function getMyLots($playerId, $status = 'active', $page = 1, $perPage = 50) {
        $offset = ($page - 1) * $perPage;
        $total = $this->dbSiel->queryFetchSingle("SELECT COUNT(*) as cnt FROM `auction_items` WHERE `seller_id` = ? AND `status` = ?", [$playerId, $status]);
        $lots = $this->dbSiel->queryFetch("SELECT a.* FROM `auction_items` a WHERE `seller_id` = ? AND `status` = ? ORDER BY `listed_at` DESC LIMIT $offset, $perPage", [$playerId, $status]);
        return ['lots' => $lots ?: [], 'total' => $total['cnt'] ?? 0, 'page' => $page, 'per_page' => $perPage];
    }
    
    public function getLotStones($auctionId) {
        $stones = $this->dbSiel->queryFetch("SELECT * FROM `auction_stones` WHERE `auction_id` = ? ORDER BY `category`, `slot`", [$auctionId]) ?: [];
        foreach ($stones as &$stone) {
            $stone['name'] = $this->safeItemName($stone['item_id']);
        }
        return $stones;
    }
    
    private function safeItemName($itemId) {
        if (!$itemId || $itemId == 0) return null;
        $name = getItemName($itemId);
        if (!check($name)) { dreamaionBuildAionItemList($itemId); $name = getItemName($itemId); if (!check($name)) return null; }
        return html_entity_decode($name, ENT_QUOTES | ENT_HTML5, 'UTF-8');
    }
    
    public function getLatestLotsForHome($limit = 4) {
        $limit = (int)$limit;
        if ($limit < 1) $limit = 4;
        if ($limit > 20) $limit = 20;
        
        $lots = $this->dbSiel->queryFetch(
            "SELECT a.auction_id, a.item_id, a.item_count, a.price, 
                    a.enchant, a.authorize, a.enchant_bonus, a.is_amplified, a.is_packed,
                    p.online as seller_online, p.name as seller_name, p.race as seller_race
             FROM `auction_items` a 
             LEFT JOIN `players` p ON p.id = a.seller_id 
             WHERE a.`status` = 'active' 
             ORDER BY a.`listed_at` DESC 
             LIMIT $limit"
        ) ?: [];
        
        $countResult = $this->dbSiel->queryFetchSingle(
            "SELECT COUNT(*) as cnt FROM `auction_items` WHERE `status` = 'active'"
        );
        $total = (int)($countResult['cnt'] ?? 0);
        
        $docRoot = '';
        if (!empty($_SERVER['DOCUMENT_ROOT'])) {
            $docRoot = rtrim($_SERVER['DOCUMENT_ROOT'], '/');
        } else {
            $docRoot = realpath(dirname(__FILE__) . '/../');
        }
        
        $iconsMap = [];
        $iconsMapPaths = [
            $docRoot . '/database/cache/icons_map.json',
            $docRoot . '/includes/cache/icons_map.json',
            dirname(__FILE__) . '/../database/cache/icons_map.json',
            dirname(__FILE__) . '/../includes/cache/icons_map.json',
        ];
        
        foreach ($iconsMapPaths as $iconsPath) {
            $realPath = realpath($iconsPath);
            if ($realPath && file_exists($realPath)) {
                $iconsMap = json_decode(file_get_contents($realPath), true) ?: [];
                break;
            }
        }
        
        $iconBaseUrl = '/database/images/icons/';
        $iconBaseDir = $docRoot . '/database/images/icons/';
        
        if (!is_dir($iconBaseDir)) {
            $altDir = $docRoot . '/images/icons/';
            if (is_dir($altDir)) {
                $iconBaseUrl = '/images/icons/';
                $iconBaseDir = $altDir;
            }
        }
        
        $fallbackIcon = $iconBaseUrl . 'unknown.png';
        if (!file_exists($iconBaseDir . 'unknown.png')) {
            $fallbackIcon = 'data:image/svg+xml,' . urlencode(
                '<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 50 50">' .
                '<rect width="50" height="50" rx="6" fill="#e8e8e8" stroke="#ccc" stroke-width="1"/>' .
                '<text x="50%" y="50%" font-size="20" fill="#999" text-anchor="middle" dy=".35em">?</text>' .
                '</svg>'
            );
        }
        
        $resultLots = [];
        foreach ($lots as $lot) {
            $itemName = 'Unknown';
            if (function_exists('getItemName') && function_exists('check')) {
                $name = getItemName($lot['item_id']);
                if (check($name)) {
                    $itemName = html_entity_decode($name, ENT_QUOTES | ENT_HTML5, 'UTF-8');
                } else {
                    if (function_exists('dreamaionBuildAionItemList')) {
                        dreamaionBuildAionItemList($lot['item_id']);
                    }
                    $name = getItemName($lot['item_id']);
                    if (check($name)) {
                        $itemName = html_entity_decode($name, ENT_QUOTES | ENT_HTML5, 'UTF-8');
                    }
                }
            }
            
            $iconPath = $fallbackIcon;
            $itemIdStr = (string)$lot['item_id'];
            $itemIdInt = (int)$lot['item_id'];
            
            $fileName = null;
            if (isset($iconsMap[$itemIdStr])) {
                $fileName = $iconsMap[$itemIdStr];
            } elseif (isset($iconsMap[$itemIdInt])) {
                $fileName = $iconsMap[$itemIdInt];
            }
            
            if ($fileName) {
                $fullPath = $iconBaseDir . $fileName;
                if (file_exists($fullPath)) {
                    $iconPath = $iconBaseUrl . $fileName;
                }
            }
            
            $stonesCount = 0;
            try {
                $stonesResult = $this->dbSiel->queryFetchSingle(
                    "SELECT COUNT(*) as cnt FROM `auction_stones` WHERE `auction_id` = ?",
                    [$lot['auction_id']]
                );
                $stonesCount = (int)($stonesResult['cnt'] ?? 0);
            } catch (Exception $e) {}
            
            $resultLots[] = [
                'auction_id' => $lot['auction_id'],
                'item_id' => $lot['item_id'],
                'item_name' => $itemName,
                'icon_path' => $iconPath,
                'item_count' => (int)$lot['item_count'],
                'price' => (int)$lot['price'],
                'enchant' => (int)$lot['enchant'],
                'authorize' => (int)($lot['authorize'] ?? 0),
                'enchant_bonus' => (int)($lot['enchant_bonus'] ?? 0),
                'stones_count' => $stonesCount,
                'is_amplified' => (int)$lot['is_amplified'],
                'is_packed' => (int)$lot['is_packed'],
                'seller_name' => $lot['seller_name'] ?? '',
                'seller_race' => (int)($lot['seller_race'] ?? 0)
            ];
        }
        
        return [
            'total' => $total,
            'lots' => $resultLots,
            'updated_at' => time()
        ];
    }
}