/* Custom Scrollbar */
::-webkit-scrollbar {
    height: 10px;
    width: 10px;
}
::-webkit-scrollbar-track {
    background: #1f2937;
}
::-webkit-scrollbar-thumb {
    background: #4b5563;
    border-radius: 5px;
}
::-webkit-scrollbar-thumb:hover {
    background: #6b7280;
}

/* Main Layout */
body {
    background-color: #111827;
    color: #e5e7eb;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    line-height: 1.6;
    background-image: radial-gradient(#374151 1px, transparent 1px);
    background-size: 20px 20px;
    background-attachment: fixed;
}

.tech-tree-wrapper {
    position: relative;
    overflow: auto;
    padding: 8rem 2rem 2rem 2rem; /* Top padding for fixed headers */
    background-image: radial-gradient(#374151 1px, transparent 1px);
    background-size: 20px 20px;
    display: grid;
    gap: 16px;
    width: 100%;
    height: 100%;
    /* Columns and Rows set via JS */
}

/* Headers */
.tier-headers {
    position: absolute;
    top: 0;
    left: 0;
    display: grid;
    padding-left: 2rem;
    padding-top: 0.5rem;
    gap: 16px;
    z-index: 10;
    pointer-events: none;
    grid-auto-flow: dense;
}

.tier-headers .era-header {
    grid-row: 1;
    pointer-events: auto;
}

.tier-headers .tier-header {
    grid-row: 2;
    pointer-events: auto;
}

.tier-header {
    width: 160px; /* Match cell width */
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(31, 41, 55, 0.95);
    border: 1px solid #4b5563;
    border-radius: 4px;
    color: #9ca3af;
    font-weight: bold;
    font-size: 1.2rem;
    outline: none;
}

/* Tree Cell */
.tree-cell {
    width: 160px;
    height: 140px;
    background: rgba(17, 24, 39, 0.4);
    border: 1px solid rgba(75, 85, 99, 0.3);
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    padding: 4px;
    gap: 2px;
    position: relative;
    transition: background 0.2s;
    pointer-events: auto;
    outline: none;
}

.tree-cell:hover {
    background: rgba(17, 24, 39, 0.7);
    border-color: #6b7280;
}

/* BR Slot (Button Row) */
.br-slot {
    flex: 1;
    display: flex;
    align-items: stretch;
    position: relative;
    pointer-events: auto;
    outline: none;
}

/* Tank Button Styling */
.tank-btn {
    flex: 1;
    display: flex;
    gap: 4px;
    cursor: pointer;
    transition: transform 0.1s;
    position: relative;
    overflow: visible; /* Allow dropdown */
    pointer-events: auto;
    border: none;
    padding: 0;
    background: none;
    outline: none;
    box-shadow: none;
}

.tank-btn:active {
    transform: scale(0.98);
}

.tank-btn:hover {
    transform: scale(1.02);
    z-index: 20;
}

.tank-btn:focus,
.tank-btn:focus-visible {
    outline: none;
    box-shadow: none;
}

.class-strip-side {
    width: 8px;
    height: 100%;
    border-radius: 2px;
    flex-shrink: 0;
}

.btn-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    border-radius: 2px;
    overflow: hidden;
    background: rgba(0,0,0,0.2);
    z-index: 5;
    pointer-events: none;
}

/* 3 Horizontal Strips */
.btn-strip {
    width: 100%;
    transition: all 0.2s;
    border: 1px solid #374151;
    box-sizing: border-box;
    pointer-events: none;
}

.btn-strip.top {
    height: 25%;
    background: #1f2937;
    border-bottom: none;
    border-radius: 2px 2px 0 0;
}

.btn-strip.mid {
    height: 50%;
    background: #1f2937;
    border-top: none;
    border-bottom: none;
    display: flex;
    align-items: center;
    padding-left: 6px;
    position: relative;
}

.btn-strip.bot {
    height: 25%;
    background: #1f2937;
    border-top: none;
    border-radius: 0 0 2px 2px;
}

/* Hover Effects */
.tank-btn:hover .btn-strip {
    background: #374151;
    border-color: #fbbf24;
}

.tank-btn.premium .btn-strip {
    border-color: #fbbf24;
}

.tank-btn.premium .tank-name {
    color: #fbbf24;
}

.tank-name {
    font-size: 0.7rem;
    font-weight: bold;
    color: #e5e7eb;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    line-height: 1;
    pointer-events: none;
}

.br-label {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.55rem;
    color: #6b7280;
    pointer-events: none;
}

/* Multi-Stack Dropdown */
.stack-badge {
    position: absolute;
    right: -6px;
    top: -6px;
    background: #4b5563;
    color: white;
    font-size: 0.6rem;
    padding: 1px 4px;
    border-radius: 4px;
    border: 1px solid #9ca3af;
    z-index: 25;
    pointer-events: none;
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    width: 160px;
    background: #1f2937;
    border: 1px solid #4b5563;
    border-radius: 4px;
    z-index: 50;
    padding: 4px;
    flex-direction: column;
    gap: 2px;
    box-shadow: 0 10px 15px rgba(0,0,0,0.5);
    pointer-events: auto;
}

.tank-btn.active .dropdown-menu {
    display: flex;
}

.dropdown-item {
    padding: 4px;
    display: flex;
    align-items: center;
    cursor: pointer;
    border-radius: 2px;
    pointer-events: auto;
    outline: none;
}

.dropdown-item:hover {
    background: #374151;
}

.dropdown-item:focus,
.dropdown-item:focus-visible {
    outline: none;
}

/* SVG Lines */
.connector-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.logo-circle {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #4b5563;
    transition: all 0.2s;
    margin-left: 10px;
}

.logo-circle:hover {
    border-color: #fbbf24;
    box-shadow: 0 0 12px rgba(251, 191, 36, 0.3);
}

/* Legend Panel */
.legend-panel {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: rgba(31, 41, 55, 0.95);
    border: 1px solid #4b5563;
    border-radius: 8px;
    padding: 16px;
    z-index: 45;
    max-width: 400px;
}


/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: #4b5563 #111827;
}

.nation-flag {
    width: 32px;
    height: 20px;
    border-radius: 2px;
    object-fit: cover;
    border: 1px solid #4b5563;
    flex-shrink: 0;
    pointer-events: none;
}

.nation-label {
    font-size: 0.65rem;
    font-weight: bold;
    color: #9ca3af;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    pointer-events: none;
}

.nation-label span {
    display: block;
    font-size: 0.6rem;
    color: #6b7280;
    margin-top: 1px;
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 100;
    justify-content: center;
    align-items: center;
    padding: 20px;
    overflow-y: auto;
    outline: none;
}

.modal.active {
    display: flex;
}

.modal > div {
    width: 100%;
    max-width: 900px;
}

/* Штамп FAKE */
.modal-fake-stamp {
    position: absolute;
    top: 0;
    right: -10px;
    width: 200px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 50;
}

.modal-fake-stamp img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Calculator Styles */
.calculator-card {
    background: rgba(17, 24, 39, 0.4);
    padding: 32px;
    border-radius: 6px;
    border: 1px solid rgba(75, 85, 99, 0.3);
    margin-top: 10px;
    transition: 0.2s;
}

.calculator-card:hover {
    background: rgba(17, 24, 39, 0.7);
    border-color: #fbbf24;
    box-shadow: 0 0 12px rgba(251, 191, 36, 0.2);
}

.calculator-card h1 {
    font-size: 24px;
    font-weight: bold;
    margin: 0 0 12px 0;
    color: #e5e7eb;
    border-bottom: 1px solid #374151;
    padding-bottom: 8px;
}

.calculator-card:hover h1 {
    color: #fbbf24;
    text-shadow: 0 0 8px rgba(251, 191, 36, 0.4);
}

.description {
    color: #9ca3af;
    font-size: 16px;
    margin-bottom: 24px;
    line-height: 1.5;
}

.formula-section {
    background: rgba(255, 255, 255, 0.02);
    border: 1px dashed #374151;
    border-radius: 4px;
    padding: 16px;
    margin-bottom: 24px;
    font-size: 14px;
    overflow-x: auto;
    color: #9ca3af;
    line-height: 1.8;
}

.formula-row {
    display: flex;
    gap: 24px;
    align-items: flex-start;
    justify-content: space-around;
}

.formula-item {
    flex: 1;
    min-width: 0;
}

.formula-section strong {
    color: #fbbf24;
    display: block;
    margin-bottom: 8px;
}

.formula-section .MathJax {
    color: #e5e7eb;
}

.formula-line {
    margin: 12px 0;
    display: flex;
    justify-content: center;
}

@media (max-width: 768px) {
    .formula-row {
        flex-direction: column;
        gap: 16px;
    }
}

.form-row {
    display: flex;
    gap: 16px;
    margin-bottom: 20px;
}

.form-row .form-group {
    flex: 1;
    margin-bottom: 0;
}

.form-group {
    margin-bottom: 20px;
}

@media (max-width: 768px) {
    .form-row {
        flex-direction: column;
        gap: 0;
    }

    .form-row .form-group {
        margin-bottom: 20px;
    }
}

.form-group label {
    display: block;
    font-weight: 500;
    font-size: 14px;
    margin-bottom: 8px;
    color: #e5e7eb;
}

.input-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
}

.input-wrapper input[type="text"] {
    flex: 1;
    padding: 10px 12px;
    font-size: 14px;
    background: rgba(31, 41, 55, 0.6);
    border: 1px solid #4b5563;
    color: #e5e7eb;
    border-radius: 4px;
    transition: 0.2s;
}

.input-wrapper input[type="text"]:focus {
    outline: none;
    background: rgba(31, 41, 55, 0.9);
    border-color: #fbbf24;
    box-shadow: 0 0 8px rgba(251, 191, 36, 0.4);
}

.input-wrapper input[type="text"]:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.unit {
    color: #9ca3af;
    font-size: 13px;
    min-width: 60px;
    text-align: right;
}

.btn {
    width: 100%;
    padding: 12px 32px;
    margin-top: 8px;
    font-size: 14px;
    font-weight: bold;
    background: #4b5563;
    color: #e5e7eb;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: 0.2s;
}

.btn:hover {
    background: #6b7280;
    border-color: #fbbf24;
    box-shadow: 0 0 8px rgba(251, 191, 36, 0.3);
}

.btn:disabled {
    background: #374151;
    cursor: not-allowed;
    opacity: 0.5;
}

.result-section {
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid rgba(75, 85, 99, 0.3);
}

.result-row {
    display: flex;
    gap: 16px;
    align-items: stretch;
}

.result-row .result-container {
    flex: 1;
    margin-bottom: 0;
}

.result-container {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(75, 85, 99, 0.3);
    border-radius: 4px;
    padding: 20px;
    text-align: center;
    margin-bottom: 15px;
    transition: 0.2s;
}

.result-container:hover {
    border-color: #fbbf24;
    background: rgba(251, 191, 36, 0.05);
}

@media (max-width: 768px) {
    .result-row {
        flex-direction: column;
        gap: 0;
    }

    .result-row .result-container {
        margin-bottom: 15px;
    }
}

.result-label {
    color: #9ca3af;
    font-size: 12px;
    font-weight: bold;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.result-value {
    font-size: 32px;
    font-weight: bold;
    color: #fbbf24;
    font-family: 'Courier New', monospace;
    margin-bottom: 4px;
}

.result-unit {
    color: #9ca3af;
    font-size: 14px;
}

.error-message {
    color: #ff5459;
    font-size: 13px;
    margin-top: 6px;
    display: none;
}

.info-box {
    background: rgba(255, 255, 255, 0.02);
    border-left: 3px solid #fbbf24;
    padding: 12px 16px;
    border-radius: 4px;
    font-size: 13px;
    color: #9ca3af;
    margin-bottom: 10px;
    border: 1px solid rgba(75, 85, 99, 0.3);
}

.info-box strong {
    color: #fbbf24;
}


/* Gun Catalogue Styles */
.status {
    text-align: center;
    color: #9ca3af;
    margin-top: 30px;
    margin-bottom: 20px;
    font-size: 0.95rem;
}

.status.ready {
    color: #55ff55;
}

.search-box {
    display: flex;
    gap: 10px;
    margin-bottom: 40px;
    justify-content: center;
}

.search-box input {
    flex: 1;
    max-width: 500px;
    padding: 12px 16px;
    background: rgba(31, 41, 55, 0.6);
    border: 1px solid #4b5563;
    color: #e5e7eb;
    border-radius: 4px;
    font-size: 16px;
    transition: 0.2s;
}

.search-box input:focus {
    outline: none;
    background: rgba(31, 41, 55, 0.9);
    border-color: #fbbf24;
    box-shadow: 0 0 8px rgba(251, 191, 36, 0.4);
}

.search-box input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.search-box button {
    padding: 12px 32px;
    background: #4b5563;
    color: #e5e7eb;
    border: none;
    font-weight: bold;
    cursor: pointer;
    border-radius: 4px;
    font-size: 14px;
    transition: 0.2s;
}

.search-box button:hover {
    background: #6b7280;
    box-shadow: 0 0 8px rgba(251, 191, 36, 0.3);
}

.search-box button:disabled {
    background: #374151;
    cursor: not-allowed;
    opacity: 0.5;
}

#results {
    max-width: 900px;
    margin: 0 auto;
}

.weapon-card {
    background: rgba(17, 24, 39, 0.4);
    padding: 20px;
    border-radius: 6px;
    margin-bottom: 15px;
    border: 1px solid rgba(75, 85, 99, 0.3);
    transition: 0.2s;
}

.weapon-card:hover {
    background: rgba(17, 24, 39, 0.7);
    border-color: #fbbf24;
    box-shadow: 0 0 12px rgba(251, 191, 36, 0.2);
}

.weapon-title {
    font-size: 1.3em;
    color: #e5e7eb;
    font-weight: bold;
    margin-bottom: 10px;
    border-bottom: 1px solid #374151;
    padding-bottom: 5px;
    transition: all 0.2s ease;
}

.weapon-card:hover .weapon-title {
    color: #fbbf24;
    text-shadow: 0 0 8px rgba(251, 191, 36, 0.4);
}

.variant {
    margin-top: 10px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    transition: all 0.2s ease;
}

.ammo-group {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed #374151;
}

.ammo-group:first-of-type {
    border-top: none;
    margin-top: 0;
    padding-top: 0;
}

.country-badge {
    display: inline-flex;
    align-items: center;
    background: #1f2937;
    color: #e5e7eb;
    padding: 4px 8px 4px 4px;
    border-radius: 4px;
    font-weight: bold;
    align-self: flex-start;
    border: 1px solid #374151;
    margin-bottom: 5px;
    font-size: 0.85rem;
    transition: all 0.2s ease;
}

.flag-icon {
    width: 24px;
    height: 16px;
    object-fit: cover;
    margin-right: 8px;
    border-radius: 2px;
    display: block;
}

.flag-icon[src=""], 
.flag-icon:not([src]) {
    display: none;
}

.ammo-type {
    color: #9ca3af;
    font-weight: bold;
    font-size: 0.95em;
}

.stats-list {
    margin-top: 2px;
    font-family: 'Courier New', monospace;
    color: #9ca3af;
    font-size: 0.85em;
    padding-left: 10px;
}

.stats-list div {
    line-height: 1.4;
}

/* Responsive */
@media (max-width: 768px) {
    .search-box {
        flex-direction: column;
    }

    .search-box input {
        max-width: 100%;
    }

    .search-box button {
        width: 100%;
    }

    .weapon-title {
        font-size: 1.1em;
    }

    .weapon-card {
        padding: 15px;
        margin-bottom: 12px;
    }
}

/* Page Title */
.page-title {
    text-align: center;
    font-size: 36px;
    font-weight: 700;
    color: #fbbf24;
    margin-bottom: 60px;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

/* Sections Grid */
.sections-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 40px;
    max-width: 1000px;
    margin: 0 auto;
}

/* Section Card */
.section-card {
    background: rgba(17, 24, 39, 0.85);
    border: 2px solid #4b5563;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    height: auto;
    opacity: 1;
    position: relative;
    margin-top: 150px;    
}

.section-card:hover {
    border-color: #fbbf24;
    transform: translateY(-6px);
    box-shadow: 0 12px 32px rgba(251, 191, 36, 0.25);
}

.section-image {
    width: 100%;
    height: 240px;
    object-fit: cover;
    background-color: #1f2937;
    flex-shrink: 0;
}

.section-title {
    font-size: 22px;
    font-weight: 600;
    color: #ffffff;
    margin: 16px 0 8px 0;
    text-align: center;
    line-height: 1.3;
    padding: 0 16px;
}

.section-status {
    font-size: 12px;
    color: #d1d5db;
    font-style: italic;
    text-align: center;
    line-height: 1.5;
    padding: 0 16px 16px 16px;
}

.section-card:hover .section-title {
    color: #f59e0b;
}

/* Bureau Card (Full Width) */
.bureau-card {
    background: rgba(17, 24, 39, 0.6);
    border: 2px solid #4b5563;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    color: inherit;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 24px;
    padding: 24px;
    opacity: 0.85;
    grid-column: 1 / -1;
}

.bureau-card:hover {
    opacity: 1;
    border-color: #fbbf24;
    background: rgba(17, 24, 39, 0.8);
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(251, 191, 36, 0.2);
}

.bureau-logo {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #4b5563;
    flex-shrink: 0;
    transition: all 0.2s;
    order: -1;
}

.bureau-card:hover .bureau-logo {
    border-color: #fbbf24;
    box-shadow: 0 0 12px rgba(251, 191, 36, 0.3);
}

.bureau-info {
    text-align: center;
    margin-right: 120px;
}

.bureau-title {
    font-size: 24px;
    font-weight: 700;
    color: #ffffff;
    margin-bottom: 6px;
    line-height: 1.3;
}

.bureau-subtitle {
    font-size: 14px;
    color: #d1d5db;
    margin-bottom: 6px;
    font-style: italic;
}

.bureau-card:hover .bureau-title {
    color: #f59e0b;
}

/* Responsive */
@media (max-width: 768px) {
    main {
        padding-top: 100px !important;
    }

    .page-title {
        font-size: 28px;
        margin-bottom: 50px;
    }

    .sections-grid {
        gap: 30px;
    }

    .section-title {
        font-size: 20px;
    }

    .bureau-info {
        margin-right: 0;
    }
}

@media (max-width: 480px) {
    main {
        padding-top: 80px !important;
        padding: 80px 16px 20px 16px;
    }

    .page-title {
        font-size: 24px;
        margin-bottom: 40px;
    }

    .sections-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .section-card {
        padding: 30px 20px;
        min-height: 220px;
    }

    .section-title {
        font-size: 18px;
    }

    .section-status {
        font-size: 12px;
    }

    .bureau-card {
        flex-direction: column;
        gap: 16px;
        padding: 20px;
    }

    .bureau-logo {
        order: 0;
    }

    .bureau-title {
        font-size: 18px;
    }
}

