@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;700&family=Spectral:wght@400;600&display=swap');

:root {
    --bg-main: #0b101e;
    --bg-panel: rgba(20, 24, 35, 0.95);
    
    --text-main: #d0d5dd;
    --text-header: #f0d096; /* HK Gold */
    --text-muted: #8890a0;
    --text-warning: #e74c3c;

    --border-main: #3a4050;
    --border-accent: #5c657a;

    --status-done-bg: rgba(45, 100, 160, 0.2);
    --status-done-border: #4a90e2;
    --status-done-text: #bce0ff;

    --status-missing-bg: rgba(20, 20, 25, 0.4);
    --status-missing-border: #444;
    --status-missing-text: #777;
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Spectral', serif;
    background-color: var(--bg-main);
    background-image: radial-gradient(circle at 50% 0%, #1a2235 0%, #0b101e 80%);
    color: var(--text-main);
    margin: 0;
    padding: 40px 20px;
    min-height: 100vh;
}

h1, h2, h3, button, summary {
    font-family: 'Cinzel', serif;
}

h1 {
    color: var(--text-header);
    text-shadow: 0 0 15px rgba(240, 208, 150, 0.3);
    font-size: 2.5rem;
    margin-bottom: 40px;
    border-bottom: 1px solid var(--border-main);
    padding-bottom: 20px;
    text-align: center;
}

/* Controls */
#controls {
    text-align: center;
    margin-bottom: 30px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.modifier-controls {
    margin: 0 auto 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0 10px;
    gap: 20px;
}

.game-switcher {
    margin: 20px 0 30px;
    text-align: center;
}

.game-switcher button, #controls button, .modifier-controls button {
    background: linear-gradient(to bottom, #2a3040, #1a202c);
    border: 1px solid var(--border-accent);
    color: #c8d6e5;
    padding: 10px 25px;
    margin: 0 5px;
    font-size: 1rem;
    border-radius: 4px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    text-transform: uppercase;
    letter-spacing: 1px;
    cursor: pointer;
}

.game-switcher button.active, #controls button:hover, .modifier-controls button:hover {
    background: linear-gradient(to bottom, #3a4050, #2a3040);
    border-color: var(--text-header);
    color: var(--text-header);
    box-shadow: 0 0 10px rgba(240, 208, 150, 0.2);
    outline: none;
}

/* Toggle Switch */
.toggle-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0,0,0,0.3);
    padding: 8px 15px;
    border: 1px solid var(--border-main);
    border-radius: 4px;
    cursor: pointer;
    user-select: none;
}

.toggle-wrapper:hover {
    border-color: var(--text-header);
}

.toggle-wrapper input[type="checkbox"] {
    cursor: pointer;
    width: 16px;
    height: 16px;
    accent-color: var(--text-header);
}

.toggle-label {
    color: var(--text-muted);
    font-family: 'Cinzel', serif;
    font-size: 0.9rem;
}

.toggle-wrapper:hover .toggle-label {
    color: var(--text-main);
}

/* File Input */
input[type="file"] {
    background: rgba(0,0,0,0.3);
    padding: 10px;
    border: 1px solid var(--border-main);
    border-radius: 4px;
    color: var(--text-muted);
    font-family: 'Spectral', serif;
    margin-right: 10px;
}

/* Panels (Details/Missing) */
details {
    background: var(--bg-panel);
    border: 1px solid var(--border-main);
    border-radius: 4px;
    margin-bottom: 20px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
    overflow: hidden; /* This might clip the expanding cards. Need to check. */
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
    overflow: visible; /* CHANGED: to allow cards to expand outside */
}

#missingList {
    /* Container only - no visual style */
    max-width: 1200px;
    margin: 0 auto 20px;
}

.missing-content {
    /* This is the new panel for missing items */
    background: var(--bg-panel);
    border: 1px solid var(--border-main);
    border-radius: 4px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
    
    padding: 20px;
    border-left: 3px solid #e74c3c; /* Red strip for missing items */
    margin-top: 10px;
}

/* Modifier Panel */
.modifier-panel {
    max-width: 1200px;
    margin: 20px auto;
    background: var(--bg-panel);
    border: 1px solid var(--border-main);
    border-radius: 4px;
    padding: 20px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
    border-left: 3px solid var(--text-header);
}

.modifier-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    padding-bottom: 10px;
}

.modifier-header h3 {
    margin: 0;
    color: var(--text-header);
}

.modifier-warning {
    color: var(--text-warning);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 5px;
    background: rgba(231, 76, 60, 0.1);
    padding: 5px 10px;
    border-radius: 4px;
}

.modifier-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 15px;
}

.modifier-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    background: rgba(0,0,0,0.3);
    padding: 15px;
    border-radius: 4px;
    border: 1px solid transparent;
    transition: border-color 0.2s;
    position: relative; /* For tooltip positioning */
}

.modifier-item:hover {
    border-color: var(--border-accent);
}

.modifier-item label {
    margin-bottom: 12px;
    color: var(--text-main);
    font-weight: bold;
    font-size: 1rem;
    letter-spacing: 0.5px;
}

.modifier-item input, .modifier-item select {
    padding: 10px 15px;
    background-color: rgba(20, 24, 35, 0.8);
    color: var(--text-main);
    border: 1px solid var(--border-main);
    border-radius: 6px;
    font-family: 'Spectral', serif;
    font-size: 1rem;
    width: 100%;
    text-align: left;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
}

.modifier-item select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23f0d096' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 18px;
    padding-right: 35px; /* Space for the custom arrow */
}

.modifier-item input:hover, .modifier-item select:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
    border-color: var(--text-header);
    background-color: rgba(30, 36, 50, 0.9);
}

.modifier-item input:focus, .modifier-item select:focus {
    outline: none;
    border-color: var(--text-header);
    transform: scale(0.98);
    box-shadow: 0 0 0 3px rgba(240, 208, 150, 0.2);
    background-color: rgba(20, 24, 35, 1);
}

/* Fix for select options not inheriting styles on some browsers */
.modifier-item select option {
    background-color: var(--bg-main);
    color: var(--text-main);
    padding: 10px;
}

summary {
    background: linear-gradient(to right, rgba(255,255,255,0.03), transparent);
    padding: 15px 20px;
    font-size: 1.3rem;
    color: var(--text-header);
    cursor: pointer;
    list-style: none; /* Hide default triangle */
    position: relative;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

summary::after {
    content: "+";
    position: absolute;
    right: 20px;
    color: var(--text-muted);
    font-weight: bold;
}

details[open] summary::after {
    content: "-";
}

details[open] summary {
    border-bottom: 1px solid var(--border-main);
}

/* Grid Layout for Items */
.section-items {
    display: grid;
    /* Use smaller min-width to fit more items, creating a denser grid */
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 12px;
    padding: 15px;
}

/* Item styling */
.item {
    padding: 10px 5px;
    text-align: center;
    border: 1px solid transparent;
    border-radius: 4px;
    font-size: 0.9rem;
    transition: all 0.2s;
    background: rgba(0,0,0,0.25);
    display: flex;
    flex-direction: column; 
    align-items: center;
    justify-content: flex-start; /* Align to top */
    gap: 8px; /* Space between icon and text */
    /* Square-ish aspect ratio, slightly taller */
    aspect-ratio: 1 / 1.2; 
    min-height: 130px;
    text-decoration: none;
    position: relative;
    cursor: default;
    line-height: 1.3;
}

/* If it is a link, show pointer */
a.item {
    cursor: pointer;
}

.icon-wrapper {
    /* The consistent square container */
    width: 80px;
    height: 80px;
    min-width: 80px; /* Prevent shrinking */
    min-height: 80px;
    
    /* Box styling */
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 6px;
    
    /* Layout for image */
    display: flex;
    align-items: center;
    justify-content: center;
    
    margin-bottom: 8px;
    margin-top: 5px;
    
    /* Animation & Effects */
    filter: drop-shadow(0 4px 6px rgba(0,0,0,0.6));
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), background-color 0.2s, border-color 0.2s;
}

.item-icon {
    /* Image inside the wrapper */
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block; /* Remove inline gap */
}

.item:hover .icon-wrapper {
    background: rgba(255, 255, 255, 0.12);
    transform: scale(1.25);
    border-color: rgba(255, 255, 255, 0.2);
    z-index: 20;
    position: relative;
}

.item.done {
    background: var(--status-done-bg);
    border-color: var(--status-done-border);
    color: var(--status-done-text);
    box-shadow: inset 0 0 10px rgba(74, 144, 226, 0.1);
}

.item.missing {
    background: var(--status-missing-bg);
    border-color: var(--status-missing-border);
    color: var(--status-missing-text);
    opacity: 0.7;
    filter: grayscale(0.6); /* Slightly gray out missing items */
}

.item.partial {
    background: var(--status-partial-bg);
    border-color: var(--status-partial-border);
    color: var(--status-partial-text);
}

.status-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    font-size: 0.7rem;
    padding: 1px 5px;
    border-radius: 3px;
    font-weight: 600;
    pointer-events: none;
    z-index: 5;
}

.item.partial .status-badge {
    background: rgba(230, 126, 34, 0.3);
    border: 1px solid var(--status-partial-border);
    color: var(--status-partial-text);
}

.item.done .status-badge {
    background: rgba(74, 144, 226, 0.3);
    border: 1px solid var(--status-done-border);
    color: var(--status-done-text);
}

.item:hover {
    transform: translateY(-3px);
    z-index: 10;
    border-color: var(--text-header);
    box-shadow: 0 5px 15px rgba(0,0,0,0.5);
}

a.item:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Missing List Content */
.completion-stat {
    text-align: center;
    margin: 0 0 15px 0;
    color: var(--text-header);
    font-size: 2.5rem;
    font-weight: 700;
    text-shadow: 0 0 15px rgba(240, 208, 150, 0.2);
}

.missing-sub {
    color: var(--text-muted);
    font-size: 1.1rem;
    opacity: 0.8;
    margin-bottom: 10px;
    font-weight: bold;
}

#missingList ul {
    list-style-type: none;
    padding: 0;
    margin: 0;
}

#missingList li {
    padding: 8px 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    color: var(--text-muted);
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}
::-webkit-scrollbar-track {
    background: #0b101e;
}
::-webkit-scrollbar-thumb {
    background: #3a4050;
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: #5c657a;
}

/* === Stacked Card Groups === */
.item-group {
    position: relative;
    aspect-ratio: 1 / 1.2;
    min-height: 130px;
    width: 100%;
    z-index: 1;
    perspective: 1000px;
}

.item-group:hover {
    z-index: 100;
}

.group-item {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.3s, box-shadow 0.3s;
    background: var(--bg-panel);
    box-shadow: 0 2px 8px rgba(0,0,0,0.5);
    
    /* Initial stack: slightly rotated based on index */
    transform: rotate(calc((var(--i) - (var(--n) - 1) / 2) * 4deg));
    transform-origin: center 80%;
}

.group-item.done {
    background: var(--bg-panel);
    background-color: rgba(20, 35, 50, 0.95);
}

/* Hover Effect: Fan out */
.item-group:hover .group-item {
    /* Fan spread calculation */
    --angle: calc((var(--i) - (var(--n) - 1) / 2) * 15deg);
    --x-off: calc((var(--i) - (var(--n) - 1) / 2) * 50%);
    
    transform: translateX(var(--x-off)) rotate(var(--angle)) scale(1.1) translateY(-10px);
    box-shadow: 0 15px 30px rgba(0,0,0,0.7);
    z-index: calc(10 + var(--i));
    
    background-color: var(--bg-panel);
}

/* Highlight individual card on hover */
.item-group:hover .group-item:hover {
    z-index: 100;
    transform: translateX(var(--x-off)) rotate(var(--angle)) scale(1.25) translateY(-25px);
    box-shadow: 0 20px 40px rgba(0,0,0,0.9);
    border-color: var(--text-header);
}

.group-item.done {
    border-color: var(--status-done-border);
}

.group-item .icon-wrapper {
}

/* === Path Hint === */
.path-hint-container {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-main);
    border-radius: 8px;
    padding: 10px 15px;
    margin: 20px auto;
    max-width: 800px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.path-hint-container code {
    background: rgba(0, 0, 0, 0.5);
    padding: 4px 8px;
    border-radius: 4px;
    color: var(--text-header);
    font-family: monospace;
    flex: 1;
    overflow-x: auto;
    white-space: nowrap;
}

#copyPathBtn {
    background: transparent;
    border: 1px solid var(--border-accent);
    color: var(--text-main);
    cursor: pointer;
    padding: 6px;
    border-radius: 4px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
}

#copyPathBtn svg {
    fill: currentColor;
    width: 18px;
    height: 18px;
}

#copyPathBtn:hover {
    background: var(--border-accent);
    color: white;
}

/* Tooltip Styles */
.modifier-item, .item:not(.group-item) {
    position: relative; /* Ensure positioning context for tooltip. Group items are already absolute. */
}

.modifier-item:hover, .item:hover {
    /* background: rgba(255, 255, 255, 0.05);  -- Conflict with existing item hover? Item has its own hover. */
}

.tooltip-text {
    visibility: hidden;
    width: 220px;
    background-color: var(--bg-main);
    color: var(--text-main);
    text-align: left;
    border-radius: 6px;
    padding: 10px;
    position: absolute;
    z-index: 1000;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(10px) scale(0.9);
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    border: 1px solid var(--text-header);
    box-shadow: 0 4px 15px rgba(0,0,0,0.8);
    pointer-events: none;
    font-size: 0.85rem;
    line-height: 1.4;
    white-space: normal;
    margin-bottom: 8px;
}

.modifier-item:hover .tooltip-text, .item:hover .tooltip-text {
    visibility: visible;
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(1);
    transition-delay: 0.2s; /* Small delay to prevent flickering */
}

/* === Location Image Button === */
.item-location-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 24px;
    height: 24px;
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid var(--border-accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    z-index: 20;
    transition: all 0.2s;
    opacity: 0.7;
}

.item-location-btn:hover {
    background: var(--bg-panel);
    border-color: var(--text-header);
    opacity: 1;
    transform: scale(1.1);
}

/* Hover Preview */
.location-preview {
    position: absolute;
    bottom: 100%; /* Above the button */
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    width: 200px;
    background: var(--bg-main);
    border: 1px solid var(--text-header);
    border-radius: 4px;
    padding: 4px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.8);
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    pointer-events: none; /* Let clicks pass through if needed, but usually it's hover */
    z-index: 1001;
}

.item-location-btn:hover .location-preview {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(-5px);
}

.location-preview img {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 2px;
}

/* === Lightbox === */
.lightbox-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.9);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    overflow: hidden; /* Prevent scrollbars from panning */
}

.lightbox-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.lightbox-content-wrapper {
    position: absolute; /* Changed from relative to allow free movement */
    /* Center initially */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column; /* Stack image and title */
    align-items: center;
    justify-content: center;
    transform-origin: 0 0; /* Important for custom matrix transform logic */
    cursor: grab;
    /* transition: transform 0.1s;  -- Removed for immediate drag response */
}

.lightbox-content {
    display: block;
    max-width: 90vw;
    max-height: 85vh; /* Reduce slightly to make room for title */
    /* Removed border and strong shadow for cleaner look */
    /* border: 2px solid var(--text-header); */
    border-radius: 4px;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
    user-select: none;
    pointer-events: none; /* Let clicks pass to wrapper for drag */
}

.lightbox-close {
    position: fixed; /* Fixed relative to screen, not image */
    top: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    background: rgba(0, 0, 0, 0.6);
    border: 2px solid var(--text-header);
    border-radius: 50%;
    color: var(--text-header);
    font-size: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0,0,0,0.8);
    transition: all 0.2s;
    z-index: 10001;
}

.lightbox-close:hover {
    background: var(--text-header);
    color: var(--bg-main);
    transform: rotate(90deg);
}

.lightbox-title {
    /* Position below image, moving with it */
    position: static; 
    margin-top: 10px;
    width: auto;
    max-width: 90vw;
    text-align: center;
    color: var(--text-main);
    font-family: 'Cinzel', serif;
    font-size: 1.5rem;
    text-shadow: 0 2px 4px black, 0 0 10px black;
    pointer-events: none;
    z-index: 10000;
    padding: 5px 10px;
    background: rgba(0,0,0,0.6); /* Add background for readability */
    border-radius: 4px;
}

.footer {
    text-align: center;
    margin-top: 60px;
    padding-top: 20px;
    border-top: 1px solid var(--border-main);
    color: var(--text-muted);
    font-size: 0.9rem;
}

.footer span {
    margin: 0 8px;
}

.footer .divider {
    color: var(--border-accent);
}

/* === Social Links === */
.social-links {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 20px;
    margin-bottom: 20px;
}

.social-link {
    color: var(--text-muted);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid transparent;
}

.social-link:hover {
    color: var(--text-header);
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--text-header);
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

.social-link svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}
