/* Core Design Tokens */
:root {
    --gothic-gold: #d4af37;
    --gothic-gold-bright: #ffd700;
    --gothic-gold-glow: rgba(212, 175, 55, 0.3);
    --gothic-crimson: #a62b2b;
    --gothic-crimson-glow: rgba(166, 43, 43, 0.4);
    --gothic-dark-bg: #0b0b0d;
    --gothic-dark-card: rgba(16, 16, 20, 0.88);
    --gothic-grey: #4e4e5a;
    --gothic-text: #e8e2d5;
    --gothic-text-muted: #9f998c;
    --gothic-border: #4d4333;
    --gothic-border-glow: rgba(212, 175, 55, 0.15);
    
    --font-heading: 'Cinzel', serif;
    --font-body: 'Lora', serif;
}

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    font-family: var(--font-body);
    background-color: var(--gothic-dark-bg);
    color: var(--gothic-text);
    overflow-x: hidden;
}

/* Headings */
h1, h2, h3, h4, h5, h6, .fantasy-heading {
    font-family: var(--font-heading);
    letter-spacing: 0.1rem;
    color: var(--gothic-gold);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.9), 0 0 10px rgba(212, 175, 55, 0.2);
    font-weight: 600;
}

/* Custom Background Containers */
.game-bg-container {
    position: relative;
    min-height: 100vh;
    width: 100%;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
}

@media (max-width: 767.98px) {
    .game-bg-container {
        padding: 1rem 0.25rem;
    }
}

.game-bg-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle, rgba(0, 0, 0, 0.2) 0%, rgba(0, 0, 0, 0.85) 100%);
    z-index: 1;
}

.game-content-wrapper {
    position: relative;
    z-index: 2;
    width: 100%;
    max-width: 1200px;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Glassmorphism Fantasy Card */
.fantasy-card {
    background: var(--gothic-dark-card);
    border: 2px solid var(--gothic-border);
    border-radius: 8px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.9), 0 0 25px var(--gothic-border-glow);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--gothic-text);
    padding: 3rem;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    width: 100%;
}

.fantasy-card:hover {
    border-color: var(--gothic-gold);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.9), 0 0 35px var(--gothic-gold-glow);
}

/* Inputs & Forms */
.fantasy-input-group {
    margin-bottom: 1.5rem;
}

.fantasy-label {
    display: block;
    font-family: var(--font-heading);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05rem;
    color: var(--gothic-text-muted);
    margin-bottom: 0.5rem;
}

.fantasy-input {
    width: 100%;
    background: rgba(10, 10, 12, 0.8);
    border: 1px solid var(--gothic-border);
    border-radius: 4px;
    color: var(--gothic-text);
    padding: 0.75rem 1rem;
    font-family: var(--font-body);
    font-size: 1rem;
    outline: none;
    transition: all 0.25s ease-in-out;
}

.fantasy-input:focus {
    border-color: var(--gothic-gold);
    box-shadow: 0 0 10px var(--gothic-gold-glow);
    background: rgba(0, 0, 0, 0.95);
}

.fantasy-input::placeholder {
    color: #5a5448;
}

/* Buttons */
.fantasy-btn {
    font-family: var(--font-heading);
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.1rem;
    padding: 0.75rem 2rem;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
    outline: none;
    display: inline-block;
    text-align: center;
    border: 2px solid transparent;
}

.fantasy-btn-primary {
    background: linear-gradient(135deg, #8a1d1d 0%, #5c1111 100%);
    color: #ffffff;
    border-color: var(--gothic-border);
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

.fantasy-btn-primary:hover {
    background: linear-gradient(135deg, #a62b2b 0%, #7d1c1c 100%);
    border-color: var(--gothic-gold);
    box-shadow: 0 6px 15px rgba(0,0,0,0.6), 0 0 10px var(--gothic-crimson-glow);
    transform: translateY(-1px);
}

.fantasy-btn-primary:active {
    transform: translateY(1px);
}

.fantasy-btn-secondary {
    background: rgba(45, 40, 32, 0.6);
    color: var(--gothic-text);
    border-color: var(--gothic-border);
}

.fantasy-btn-secondary:hover {
    background: rgba(60, 55, 45, 0.85);
    border-color: var(--gothic-gold);
    color: #ffffff;
}

.fantasy-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed !important;
    pointer-events: none !important;
    background: rgba(45, 40, 32, 0.4) !important;
    border-color: rgba(77, 67, 51, 0.4) !important;
    color: var(--gothic-text-muted) !important;
    box-shadow: none !important;
    transform: none !important;
}

/* Custom interactive selectors for Races & Classes */
.card-selector-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.25rem;
    margin-bottom: 2rem;
}

.card-selector-item {
    background: rgba(10, 10, 12, 0.75);
    border: 2px solid var(--gothic-border);
    border-radius: 6px;
    padding: 1.5rem;
    cursor: pointer;
    text-align: center;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: relative;
    overflow: hidden;
}

.card-selector-item::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    box-shadow: inset 0 0 15px rgba(0,0,0,0.8);
    pointer-events: none;
}

.card-selector-item:hover {
    border-color: var(--gothic-gold-bright);
    box-shadow: 0 5px 15px rgba(0,0,0,0.5), 0 0 10px var(--gothic-gold-glow);
    transform: translateY(-2px);
}

.card-selector-item.active {
    background: rgba(166, 43, 43, 0.08);
    border-color: var(--gothic-gold-bright);
    box-shadow: inset 0 0 15px rgba(166, 43, 43, 0.15), 0 0 15px var(--gothic-gold-glow);
}

.card-selector-title {
    font-family: var(--font-heading);
    color: var(--gothic-gold);
    font-size: 1.2rem;
    margin-bottom: 0.5rem;
}

.card-selector-desc {
    font-size: 0.85rem;
    color: var(--gothic-text-muted);
    line-height: 1.3;
}

/* Attribute Allocation Panel */
.stat-allocation-container {
    background: rgba(10, 10, 12, 0.7);
    border: 1px solid var(--gothic-border);
    border-radius: 6px;
    padding: 1.5rem;
    margin-bottom: 2rem;
}

.stat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--gothic-border);
    padding-bottom: 0.75rem;
    margin-bottom: 1.25rem;
}

.stat-pool-badge {
    font-family: var(--font-heading);
    font-size: 1.1rem;
    color: #ffffff;
    background: var(--gothic-crimson);
    padding: 0.4rem 1rem;
    border-radius: 20px;
    border: 1px solid var(--gothic-gold);
    box-shadow: 0 0 10px var(--gothic-crimson-glow);
}

.stat-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 0;
    border-bottom: 1px dashed rgba(77, 67, 51, 0.4);
}

.stat-row:last-child {
    border-bottom: none;
}

.stat-name-block {
    flex: 1;
    min-width: 110px;
}

.stat-name {
    font-family: var(--font-heading);
    font-size: 1rem;
    color: var(--gothic-text);
    margin: 0;
}

.stat-desc {
    font-size: 0.75rem;
    color: var(--gothic-text-muted);
    margin: 0;
}

.stat-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.stat-btn {
    width: 32px;
    height: 32px;
    background: rgba(45, 40, 32, 0.8);
    border: 1px solid var(--gothic-border);
    border-radius: 4px;
    color: var(--gothic-text);
    font-weight: bold;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.stat-btn:hover:not(:disabled) {
    background: var(--gothic-gold);
    color: var(--gothic-dark-bg);
    border-color: var(--gothic-gold-bright);
}

.stat-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.stat-value-badge {
    font-family: var(--font-heading);
    font-size: 1.3rem;
    font-weight: bold;
    color: var(--gothic-gold-bright);
    width: 35px;
    text-align: center;
}

.stat-modifier {
    font-size: 0.85rem;
    color: var(--gothic-text-muted);
    width: 50px;
    text-align: right;
    font-weight: 500;
}

.stat-modifier.positive {
    color: #4cd137;
}

.stat-modifier.negative {
    color: #e84118;
}

/* Divider & Styling helpers */
.gothic-divider {
    height: 2px;
    background: linear-gradient(90deg, transparent 0%, var(--gothic-border) 50%, transparent 100%);
    margin: 2rem 0;
}

.gothic-ornament {
    text-align: center;
    font-size: 1.5rem;
    color: var(--gothic-border);
    margin: 1rem 0;
    line-height: 1;
}

.validation-error-alert {
    background: rgba(166, 43, 43, 0.15);
    border: 1px solid var(--gothic-crimson);
    border-radius: 4px;
    color: #ff8b8b;
    padding: 0.75rem 1.25rem;
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
    list-style: none;
}

.validation-error-alert ul {
    margin: 0;
    padding-left: 1.25rem;
}

/* Animations */
@keyframes pulseGlow {
    0% { box-shadow: 0 0 5px var(--gothic-border-glow); }
    50% { box-shadow: 0 0 15px var(--gothic-gold-glow); }
    100% { box-shadow: 0 0 5px var(--gothic-border-glow); }
}

.pulse-card {
    animation: pulseGlow 4s infinite ease-in-out;
}

/* Responsive Styling for Medium/Laptop Screens to prevent overflow */
@media (max-width: 1199.98px) {
    .fantasy-card {
        padding: 2rem;
    }
    
    .stat-allocation-container {
        padding: 1rem;
    }
    
    .stat-controls {
        gap: 0.5rem;
    }
    
    .stat-modifier {
        width: 45px;
    }
}

/* Responsive Styling for Mobile Devices */
@media (max-width: 767.98px) {
    .fantasy-card {
        padding: 1.5rem;
    }

    .card-selector-grid {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
        gap: 0.75rem;
    }

    .card-selector-item {
        padding: 1rem;
    }

    .card-selector-title {
        font-size: 1.05rem;
    }

    .card-selector-desc {
        font-size: 0.8rem;
    }

    .stat-row {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
        padding: 0.75rem 0;
        text-align: center;
    }

    .stat-name-block {
        min-width: 0;
    }

    .stat-controls {
        justify-content: center;
        gap: 0.75rem;
    }

    .stat-btn {
        width: 44px;
        height: 44px;
        font-size: 1.3rem;
    }

    .stat-modifier {
        width: auto;
        text-align: left;
    }

    h1, h2, h3, h4, h5, h6, .fantasy-heading {
        letter-spacing: 0.05rem;
        word-wrap: break-word;
        word-break: break-word;
        hyphens: auto;
    }

    h1, .fantasy-heading.h1 {
        font-size: 1.8rem;
    }

    h2, .fantasy-heading.h2 {
        font-size: 1.45rem;
    }

    h3, .fantasy-heading.h3 {
        font-size: 1.25rem;
    }
}

/* Knight Map Marker Styles */
.map-knight-marker-wrapper {
    position: relative;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid var(--gothic-gold);
    box-shadow: 0 0 12px rgba(0,0,0,0.8), 0 0 8px var(--gothic-gold-glow);
    background: #111114;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.map-knight-marker-wrapper:hover {
    border-color: var(--gothic-gold-bright);
    box-shadow: 0 0 18px rgba(0,0,0,0.9), 0 0 14px var(--gothic-gold-bright);
    transform: scale(1.15);
}

.map-knight-marker-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

/* Glowing ring pulse animation */
@keyframes knightMarkerPulse {
    0% {
        transform: scale(1);
        opacity: 1;
        border-color: var(--gothic-gold);
    }
    100% {
        transform: scale(1.6);
        opacity: 0;
        border-color: var(--gothic-crimson);
    }
}

.map-knight-marker-wrapper::after {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    border-radius: 50%;
    border: 2px solid var(--gothic-gold);
    animation: knightMarkerPulse 2.5s infinite ease-out;
    pointer-events: none;
    z-index: -1;
}

/* Medieval Map Theme overrides for Leaflet */
.leaflet-container {
    background-color: #3b3222 !important; /* warm dark parchment color for loading areas */
    position: relative;
}

/* 1. Apply old-world styling filters to map tiles */
.leaflet-tile {
    /* Convert tile imagery to sepia, shift hue to warm gold, boost contrast, and lower brightness slightly */
    filter: sepia(100%) hue-rotate(-15deg) contrast(1.2) saturate(0.8) brightness(0.92) !important;
    transition: filter 0.3s ease;
}

/* 2. Seamless parchment paper texture overlay */
.leaflet-container::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: url('images/parchment_texture.png');
    background-size: 512px 512px;
    background-repeat: repeat;
    opacity: 0.35; /* Blends beautiful crinkles and grain over the map */
    mix-blend-mode: multiply;
    pointer-events: none; /* Let clicks pass through to the map */
    z-index: 550; /* Sits above tile-pane (200) and overlay-pane (400), but below markers (600) and popups (700) */
}

/* 3. Outer vignette border effect to frame the map like an ancient scroll */
.leaflet-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    box-shadow: inset 0 0 35px rgba(0, 0, 0, 0.75); /* Soft, dark vignetted edges */
    z-index: 1000; /* Stays on top of everything inside the map container */
    pointer-events: none;
}

/* 4. Gothic/Medieval Map Controls Styling */
.leaflet-bar {
    border: 2px solid var(--gothic-border) !important;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.6) !important;
    background-color: var(--gothic-dark-card) !important;
    border-radius: 4px !important;
    overflow: hidden;
}

.leaflet-bar a {
    background-color: var(--gothic-dark-card) !important;
    color: var(--gothic-gold) !important;
    border-bottom: 1px solid var(--gothic-border) !important;
    transition: all 0.2s ease !important;
}

.leaflet-bar a:last-child {
    border-bottom: none !important;
}

.leaflet-bar a:hover {
    background-color: rgba(60, 55, 45, 0.85) !important;
    color: var(--gothic-gold-bright) !important;
}

/* 5. Medieval styling for attribution control */
.leaflet-control-attribution {
    background: rgba(16, 16, 20, 0.85) !important;
    color: var(--gothic-text-muted) !important;
    border: 1px solid var(--gothic-border) !important;
    border-radius: 4px !important;
    font-family: var(--font-body) !important;
    font-size: 0.7rem !important;
}

.leaflet-control-attribution a {
    color: var(--gothic-gold) !important;
}

/* 6. Gothic styled map popups */
.leaflet-popup-content-wrapper {
    background: var(--gothic-dark-card) !important;
    color: var(--gothic-text) !important;
    border: 2px solid var(--gothic-border) !important;
    border-radius: 8px !important;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.95) !important;
    padding: 2px !important;
}

.leaflet-popup-tip {
    background: var(--gothic-border) !important;
}

.leaflet-popup-close-button {
    color: var(--gothic-text-muted) !important;
    font-size: 1.2rem !important;
    padding: 6px !important;
    background: transparent !important;
    border: none !important;
}

.leaflet-popup-close-button:hover {
    color: var(--gothic-gold-bright) !important;
    background: transparent !important;
}

/* Generic Progress Bar (Oriented on Inventory Capacity Bar) */
.gothic-progress-outer {
    background: rgba(0,0,0,0.5);
    border: 1px solid var(--gothic-border);
    height: 6px;
    border-radius: 3px;
    overflow: hidden;
    width: 100%;
}

.gothic-progress-inner {
    height: 100%;
    width: 0%;
    border-radius: 3px;
    transition: width 0.3s ease, background 0.3s ease;
}

/* Global Tab and Item Card styles */
.filter-tab {
    flex: 0 0 auto;
    background: transparent;
    border: none;
    color: var(--gothic-text-muted);
    font-family: var(--font-heading);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05rem;
    padding: 0.5rem 1.25rem;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.25s ease-in-out;
}

.filter-tab:hover {
    color: #ffffff;
}

.filter-tab.active {
    background: var(--gothic-gold);
    color: var(--gothic-dark-bg);
    font-weight: bold;
    box-shadow: 0 0 10px var(--gothic-gold-glow);
}

.item-card {
    display: flex;
    align-items: center;
    background: rgba(18, 18, 22, 0.85);
    border: 1px solid var(--gothic-border);
    border-radius: 4px;
    padding: 0.75rem;
    cursor: grab;
    position: relative;
    transition: all 0.2s ease-in-out;
    touch-action: pan-y;
}

.item-card:hover {
    transform: scale(1.01);
    border-color: var(--gothic-gold);
    box-shadow: 0 4px 10px rgba(0,0,0,0.6);
}

.item-card.gewöhnlich {
    border-left: 4px solid var(--gothic-grey);
}
.item-card.selten {
    border-left: 4px solid #00a8ff;
    box-shadow: inset 5px 0 10px rgba(0, 168, 255, 0.05);
}
.item-card.selten:hover {
    box-shadow: 0 4px 15px rgba(0, 168, 255, 0.15), inset 5px 0 10px rgba(0, 168, 255, 0.08);
    border-color: #00a8ff;
}
.item-card.episch {
    border-left: 4px solid #9c88ff;
    box-shadow: inset 5px 0 10px rgba(156, 136, 255, 0.05);
}
.item-card.episch:hover {
    box-shadow: 0 4px 15px rgba(156, 136, 255, 0.2), inset 5px 0 10px rgba(156, 136, 255, 0.1);
    border-color: #9c88ff;
}
.item-card.legendär {
    border-left: 4px solid var(--gothic-gold);
    box-shadow: inset 5px 0 10px rgba(212, 175, 55, 0.05);
}
.item-card.legendär:hover {
    box-shadow: 0 4px 15px rgba(212, 175, 55, 0.25), inset 5px 0 10px rgba(212, 175, 55, 0.12);
    border-color: var(--gothic-gold-bright);
}

.item-icon-container {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.4);
    border: 1px solid rgba(77, 67, 51, 0.3);
    border-radius: 4px;
    flex-shrink: 0;
}

.item-emoji {
    font-size: 1.5rem;
}

.item-name {
    font-family: var(--font-heading);
    font-size: 0.95rem;
    color: #ffffff;
}

.rarity-badge {
    font-size: 0.65rem;
    text-transform: uppercase;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    margin-left: 0.5rem;
    background: rgba(255,255,255,0.08);
    color: var(--gothic-text-muted);
}

.gewöhnlich .rarity-badge { border: 1px solid var(--gothic-grey); color: var(--gothic-text-muted); }
.selten .rarity-badge { border: 1px solid #00a8ff; color: #00a8ff; }
.episch .rarity-badge { border: 1px solid #9c88ff; color: #9c88ff; }
.legendär .rarity-badge { border: 1px solid var(--gothic-gold); color: var(--gothic-gold-bright); }

.weight-badge {
    font-size: 0.65rem;
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    margin-left: 0.5rem;
    background: rgba(255,255,255,0.05);
    color: #a4b0be;
    border: 1px solid rgba(255,255,255,0.1);
    display: inline-block;
}

.stat-bonus-badge {
    font-size: 0.75rem;
    color: var(--gothic-gold);
    background: rgba(212, 175, 55, 0.05);
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    border: 1px solid rgba(212, 175, 55, 0.15);
    font-family: var(--font-heading);
}

.item-description {
    line-height: 1.3;
}