@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;700&family=Noto+Sans+SC:wght@400;500;600;700&family=Noto+Serif+SC:wght@400;500;600;700&display=swap');

:root {
    /* Kingdom Come: Deliverance - Codex Theme (Dark - Default) */
    --bg-main: #05080f;
    --bg-panel: rgba(13, 20, 31, 0.85);
    --bg-card: #111824;
    --bg-slot: #0f1623;
    --bg-slot-hover: #151e2e;
    
    --gold-primary: #d4b46e;
    --gold-bright: #fbe6ad;
    --gold-dim: #7a632b;
    --gold-dark: #2f2718;
    
    --text-main: #e6e6e6;
    --text-muted: #94a3b8;
    --text-gold: #d4b46e;
    
    --border-slot: 2px solid #2d3748;
    --border-slot-active: 2px solid #d4b46e;
    --border-panel: 2px solid #3d3320;
    
    /* Shadow colors */
    --shadow-color: rgba(0, 0, 0, 0.7);
    --shadow-light: rgba(212, 180, 110, 0.15);
    
    /* Larger slot sizes for better image display */
    --slot-size: 160px;
    --slot-size-tablet: 140px;
    --slot-size-mobile: 110px;
    --slot-size-small: 90px;
}

/* Light Theme - Soft Cream & Deep Brown */
[data-theme="light"] {
    --bg-main: #e8e4dc;
    --bg-panel: rgba(245, 242, 235, 0.85);
    --bg-card: #ebe7de;
    --bg-slot: #ddd9d0;
    --bg-slot-hover: #d0ccc3;
    
    --gold-primary: #8b6914;
    --gold-bright: #a67c00;
    --gold-dim: #6b5a3d;
    --gold-dark: #4a3f2a;
    
    --text-main: #1a1a1a;
    --text-muted: #4a4a4a;
    --text-gold: #6b5308;
    
    --border-slot: 2px solid #b8b4ac;
    --border-slot-active: 2px solid #8b6914;
    --border-panel: 2px solid #a8a49c;
    
    --shadow-color: rgba(0, 0, 0, 0.15);
    --shadow-light: rgba(139, 105, 20, 0.2);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    touch-action: manipulation;
    -webkit-text-size-adjust: 100%;
}

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    font-family: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 15px;
    line-height: 1.7;
    background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.03'/%3E%3C/svg%3E");
    margin: 0;
    padding: 0;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Light theme body adjustments */
[data-theme="light"] body {
    background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.02'/%3E%3C/svg%3E");
}

/* Theme transition flash effect */
.theme-flash {
    position: fixed;
    inset: 0;
    background: var(--gold-primary);
    opacity: 0;
    pointer-events: none;
    z-index: 9999;
    transition: opacity 0.3s ease;
}

.theme-flash.active {
    animation: flashAnimation 0.6s ease-out;
}

@keyframes flashAnimation {
    0% { opacity: 0; }
    50% { opacity: 0.1; }
    100% { opacity: 0; }
}

/* ========== Typography ========== */
h1, h2, h3, .font-cinzel {
    font-family: 'Cinzel', serif;
    font-weight: 700;
    color: var(--gold-primary);
    text-transform: uppercase;
    letter-spacing: 2px;
    text-shadow: 2px 2px 4px var(--shadow-color);
}

[data-theme="light"] h1,
[data-theme="light"] h2,
[data-theme="light"] h3,
[data-theme="light"] .font-cinzel {
    text-shadow: 1px 1px 2px var(--shadow-color);
}

h1 {
    font-size: 1.6rem;
    border-bottom: 3px double var(--gold-dim);
    padding-bottom: 12px;
    margin: 0 0 20px 0;
}

h2 {
    font-size: 1.2rem;
    border-bottom: 1px solid var(--gold-dim);
    padding-bottom: 8px;
    margin: 0 0 16px 0;
}

/* ========== Main Layout ========== */
#app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ========== Header ========== */
.codex-header {
    background: linear-gradient(180deg, var(--bg-panel) 0%, rgba(6, 10, 18, 0.95) 100%);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 2px solid var(--gold-primary);
    padding: 16px 28px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 10px 40px var(--shadow-color), 0 1px 0 rgba(212, 180, 110, 0.2) inset;
    position: relative;
    flex-wrap: wrap;
    gap: 16px;
    z-index: 50;
}

[data-theme="light"] .codex-header {
    background: linear-gradient(to bottom, #f5f2eb, #e8e4dc);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
    border-bottom-color: #a68b4b;
}

.codex-header::before,
.codex-header::after {
    content: '';
    position: absolute;
    bottom: -3px;
    width: 30px;
    height: 30px;
    border: 2px solid var(--gold-dim);
}

.codex-header::before {
    left: 20px;
    border-right: none;
    border-bottom: none;
}

.codex-header::after {
    right: 20px;
    border-left: none;
    border-bottom: none;
}

.header-title {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-icon {
    width: 48px;
    height: 48px;
    background: var(--bg-panel);
    border: 2px solid var(--gold-dim);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.5);
    flex-shrink: 0;
}

.header-icon svg {
    width: 28px;
    height: 28px;
    color: var(--gold-primary);
}

.header-text h1 {
    border: none;
    padding: 0;
    margin: 0 0 4px 0;
    font-size: 1.4rem;
}

.header-text p {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.8rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
}

/* ========== Stats Bar ========== */
.stats-bar {
    display: flex;
    gap: 4px;
    background: var(--bg-panel);
    border: 1px solid var(--gold-dark);
    padding: 4px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 16px;
    background: linear-gradient(to bottom, #141c29, #0d141f);
    border: 1px solid var(--gold-dark);
    min-width: 70px;
}

.stat-value {
    font-family: 'Cinzel', serif;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--gold-bright);
    text-shadow: 0 0 10px rgba(212, 180, 110, 0.3);
}

.stat-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-top: 2px;
}

/* ========== Main Container ========== */
.main-container {
    flex: 1;
    display: flex;
    padding: 20px;
    gap: 20px;
    max-width: 1800px;
    margin: 0 auto;
    width: 100%;
}

/* ========== Sidebar ========== */
.sidebar {
    width: 220px;
    background: var(--bg-panel);
    border: 2px solid var(--gold-dark);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    flex-shrink: 0;
    max-height: calc(100vh - 140px);
    overflow-y: auto;
}

.sidebar-title {
    font-family: 'Cinzel', serif;
    font-size: 0.9rem;
    color: var(--gold-primary);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--gold-dark);
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-title::before {
    content: '';
    display: inline-block;
    width: 4px;
    height: 16px;
    background: var(--gold-primary);
    border-radius: 2px;
}

.category-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.category-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: linear-gradient(90deg, var(--bg-slot) 0%, transparent 100%);
    border: 1px solid transparent;
    border-left: 2px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: 'Noto Sans SC', sans-serif;
    user-select: none;
    -webkit-user-select: none;
    position: relative;
    overflow: hidden;
}

.category-item::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, rgba(212, 180, 110, 0) 0%, rgba(212, 180, 110, 0.05) 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.category-item:hover::before {
    opacity: 1;
}

.category-item:hover {
    background: var(--bg-slot-hover);
    border-color: var(--gold-dim);
    transform: translateX(4px);
}

.category-item.active {
    background: linear-gradient(90deg, rgba(212, 180, 110, 0.2) 0%, transparent 100%);
    border-color: transparent;
    border-left: 3px solid var(--gold-primary);
    box-shadow: 0 4px 15px rgba(212, 180, 110, 0.15), inset 20px 0 30px -20px var(--gold-primary);
    transform: translateX(6px);
}

.category-name {
    color: var(--text-main);
    font-size: 0.9rem;
}

.category-item.active .category-name {
    color: var(--gold-bright);
}

.category-count {
    font-family: 'Cinzel', serif;
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--bg-main);
    padding: 2px 8px;
    border: 1px solid var(--gold-dark);
}

.category-item.active .category-count {
    color: var(--gold-primary);
    border-color: var(--gold-dim);
}

/* ========== Inventory Panel ========== */
.inventory-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-panel);
    border: 2px solid var(--gold-dark);
    position: relative;
    min-height: 0;
}

.inventory-panel::before,
.inventory-panel::after,
.inventory-panel > .corner-bl,
.inventory-panel > .corner-br {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border: 2px solid var(--gold-dim);
    pointer-events: none;
}

.inventory-panel::before {
    top: -2px;
    left: -2px;
    border-right: none;
    border-bottom: none;
}

.inventory-panel::after {
    top: -2px;
    right: -2px;
    border-left: none;
    border-bottom: none;
}

.inventory-panel > .corner-bl {
    bottom: -2px;
    left: -2px;
    border-right: none;
    border-top: none;
}

.inventory-panel > .corner-br {
    bottom: -2px;
    right: -2px;
    border-left: none;
    border-top: none;
}

/* ========== Toolbar ========== */
.inventory-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    background: linear-gradient(to bottom, #141c29, #0d141f);
    border-bottom: 1px solid var(--gold-dark);
    gap: 20px;
    flex-wrap: wrap;
}

.toolbar-search {
    position: relative;
    flex: 0 1 320px;
    min-width: 200px;
}

.toolbar-search input {
    width: 100%;
    padding: 10px 12px 10px 36px;
    background: var(--bg-main);
    border: 1px solid var(--gold-dark);
    color: var(--text-main);
    font-family: 'Noto Sans SC', sans-serif;
    font-size: 0.9rem;
    outline: none;
    transition: all 0.3s;
}

.toolbar-search input:focus {
    border-color: var(--gold-primary);
    box-shadow: 0 0 8px rgba(212, 180, 110, 0.2);
}

.toolbar-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

/* 工具栏按钮分组 */
.toolbar-group {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 0 12px;
    border-left: 1px solid var(--gold-dark);
}

.toolbar-group:first-child {
    border-left: none;
    padding-left: 0;
}

/* ========== Inventory Grid ========== */
.inventory-grid {
    flex: 1;
    padding: 24px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(var(--slot-size), 1fr));
    gap: 16px;
    overflow-y: auto;
    align-content: start;
}

/* Item Slot */
.item-slot {
    background: linear-gradient(135deg, var(--bg-card) 0%, var(--bg-slot) 100%);
    border: 1px solid var(--gold-dark);
    position: relative;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    aspect-ratio: 1;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.item-slot::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, var(--shadow-light) 0%, transparent 50%);
    pointer-events: none;
}

.item-slot:hover {
    border-color: var(--gold-bright);
    background: linear-gradient(135deg, var(--bg-slot-hover) 0%, var(--bg-slot) 100%);
    transform: translateY(-6px) scale(1.03);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.6), 0 0 20px rgba(212, 180, 110, 0.25), inset 0 0 20px rgba(212, 180, 110, 0.1);
    z-index: 2;
}

.item-slot.selected {
    border: var(--border-slot-active);
    background: var(--shadow-light);
    box-shadow: 0 0 15px var(--shadow-light);
}

.item-slot.selected::after {
    content: '';
    position: absolute;
    inset: 0;
    border: 1px solid var(--gold-bright);
    pointer-events: none;
}

/* Batch Indicator */
.batch-indicator {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 24px;
    height: 24px;
    background: var(--gold-primary);
    color: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

/* Item Image */
.item-image {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    overflow: hidden;
    min-height: 0;
}

.item-image img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    filter: brightness(0.95);
    transition: filter 0.2s, transform 0.2s;
    will-change: transform;
}

.item-slot:hover .item-image img {
    filter: brightness(1);
    transform: scale(1.02);
}

/* Item Info */
.item-info {
    background: linear-gradient(to top, rgba(0, 0, 0, 0.95) 0%, rgba(0, 0, 0, 0.5) 100%);
    backdrop-filter: blur(4px);
    padding: 10px;
    border-top: 1px solid rgba(212, 180, 110, 0.2);
    text-align: center;
    min-height: 52px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 6px;
    transform: translateY(2px);
    transition: transform 0.3s ease;
}

.item-slot:hover .item-info {
    transform: translateY(0);
    background: linear-gradient(to top, rgba(0, 0, 0, 0.98) 0%, rgba(0, 0, 0, 0.7) 100%);
    border-top-color: var(--gold-dim);
}

[data-theme="light"] .item-info {
    background: rgba(240, 236, 228, 0.95);
    border-top-color: #b8b4ac;
}

[data-theme="light"] .item-category {
    color: #4a3f2a;
    font-weight: 600;
}

.item-category {
    color: var(--gold-primary);
    font-family: 'Noto Sans SC', sans-serif;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.item-meta-row {
    display: flex;
    justify-content: center;
    margin-top: 6px;
}

.scope-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.68rem;
    letter-spacing: 0.04em;
    border: 1px solid rgba(212, 180, 110, 0.35);
    color: var(--gold-bright);
    background: rgba(212, 180, 110, 0.1);
}

.scope-pill.local {
    border-color: rgba(239, 68, 68, 0.4);
    color: #fecaca;
    background: rgba(239, 68, 68, 0.14);
}

.scope-pill.public {
    border-color: rgba(34, 197, 94, 0.35);
    color: #bbf7d0;
    background: rgba(34, 197, 94, 0.12);
}

.form-hint {
    margin-top: 8px;
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* ========== Pagination ========== */
.pagination-bar {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: linear-gradient(to bottom, #0d141f, #141c29);
    border-top: 1px solid var(--gold-dark);
    flex-wrap: wrap;
}

.page-info {
    font-family: 'Cinzel', serif;
    color: var(--gold-primary);
    font-size: 0.9rem;
    min-width: 100px;
    text-align: center;
}

/* ========== Buttons ========== */
.codex-btn {
    background: linear-gradient(180deg, #1d2633 0%, #0d121c 100%);
    border: 1px solid var(--gold-dim);
    color: var(--gold-primary);
    padding: 10px 20px;
    font-family: 'Cinzel', serif;
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.05);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    position: relative;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    white-space: nowrap;
    min-height: 42px;
    border-radius: 4px;
}

.codex-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 50%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(212, 180, 110, 0.2), transparent);
    transform: skewX(-20deg);
    transition: left 0.5s ease;
}

.codex-btn:hover::before {
    left: 150%;
}

.codex-btn:hover {
    border-color: var(--gold-bright);
    color: var(--gold-bright);
    background: linear-gradient(180deg, #243040 0%, #111825 100%);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6), 0 0 15px rgba(212, 180, 110, 0.3);
    transform: translateY(-2px);
}

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

.codex-btn.primary {
    background: linear-gradient(180deg, var(--gold-primary) 0%, var(--gold-dark) 100%);
    color: #05080f;
    border-color: var(--gold-bright);
    text-shadow: 0 1px 1px rgba(255,255,255,0.3);
    font-weight: 800;
}

.codex-btn.primary::before {
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
}

.codex-btn.primary:hover {
    background: linear-gradient(180deg, var(--gold-bright) 0%, var(--gold-dim) 100%);
    box-shadow: 0 8px 25px rgba(212, 180, 110, 0.4), inset 0 0 10px rgba(255,255,255,0.5);
    color: #000;
}

.codex-btn:disabled,
.codex-btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.codex-btn.danger {
    color: #ef4444;
    border-color: rgba(239, 68, 68, 0.3);
}

.codex-btn.danger:hover {
    border-color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

.icon-btn {
    width: 40px;
    height: 40px;
    padding: 0;
}

/* ========== Modals ========== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(4, 7, 10, 0.7);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 1000;
    overflow-y: auto;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-panel {
    background: linear-gradient(145deg, rgba(20, 28, 41, 0.95), rgba(10, 15, 24, 0.98));
    border: 1px solid var(--gold-primary);
    max-width: 900px;
    width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    position: relative;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(212, 180, 110, 0.1) inset;
    border-radius: 8px;
    animation: scaleUp 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes scaleUp {
    from { opacity: 0; transform: scale(0.95) translateY(20px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-panel::before,
.modal-panel::after {
    display: none !important;
}

.modal-panel::before {
    top: -2px;
    left: -2px;
    border-right: none;
    border-bottom: none;
}

.modal-panel::after {
    top: -2px;
    right: -2px;
    border-left: none;
    border-bottom: none;
}

/* Corner decorations for modal panels (as real elements, not pseudo) */
.modal-panel-corner-bl,
.modal-panel-corner-br {
    position: absolute;
    width: 24px;
    height: 24px;
    border: 2px solid var(--gold-dim);
    pointer-events: none;
}

.modal-panel-corner-bl {
    bottom: -2px;
    left: -2px;
    border-right: none;
    border-top: none;
}

.modal-panel-corner-br {
    bottom: -2px;
    right: -2px;
    border-left: none;
    border-top: none;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 28px;
    background: linear-gradient(to bottom, rgba(20, 28, 41, 0.4), rgba(10, 15, 24, 0.6));
    border-bottom: 1px solid rgba(212, 180, 110, 0.2);
    border-radius: 8px 8px 0 0;
    flex-shrink: 0;
}

.modal-header h2 {
    border: none;
    padding: 0;
    margin: 0;
    font-size: 1.1rem;
}

.modal-close {
    width: 36px;
    height: 36px;
    background: transparent;
    border: 1px solid var(--gold-dark);
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    padding: 0;
}

.modal-close:hover {
    border-color: var(--gold-primary);
    color: var(--gold-primary);
    transform: rotate(90deg);
}

.modal-content {
    flex: 1;
    overflow-y: auto;
    display: flex;
}

/* Item Detail */
.item-detail {
    display: flex;
    width: 100%;
    min-height: 500px;
}

.item-preview {
    flex: 1;
    background: linear-gradient(135deg, #0a0f16 0%, #000 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    position: relative;
    min-height: 500px;
}

.item-preview img {
    max-width: 100%;
    max-height: 480px;
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
}

.nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 48px;
    height: 48px;
    background: rgba(13, 20, 31, 0.9);
    border: 1px solid var(--gold-dim);
    color: var(--gold-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    padding: 0;
}

.nav-btn:hover {
    background: var(--gold-primary);
    color: #000;
}

.nav-btn.left {
    left: 16px;
}

.nav-btn.right {
    right: 16px;
}

.item-stats {
    width: 360px;
    background: var(--bg-main);
    border-left: 1px solid var(--gold-dark);
    padding: 28px;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    gap: 4px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 0;
    border-bottom: 1px solid rgba(61, 51, 32, 0.5);
}

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

.stat-name {
    color: var(--text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 500;
}

.stat-value {
    color: var(--gold-primary);
    font-family: 'Noto Sans SC', sans-serif;
    font-weight: 600;
    font-size: 0.95rem;
}

.item-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.tag {
    background: rgba(212, 180, 110, 0.08);
    border: 1px solid var(--gold-dark);
    padding: 6px 14px;
    font-size: 0.85rem;
    color: var(--gold-dim);
    border-radius: 4px;
    transition: all 0.2s ease;
}

.tag:hover {
    background: rgba(212, 180, 110, 0.15);
    border-color: var(--gold-dim);
    color: var(--gold-primary);
}


.analysis-result {
    background: linear-gradient(145deg, rgba(212, 180, 110, 0.12), rgba(212, 180, 110, 0.03));
    border: 1px solid rgba(212, 180, 110, 0.35);
    border-radius: 8px;
    padding: 12px;
}

.analysis-result-head {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.analysis-result-title {
    color: var(--gold-primary);
    font-size: 0.8rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.analysis-result-subtitle {
    color: var(--text-muted);
    font-size: 0.78rem;
}

.scene-tag {
    color: var(--gold-primary);
    border-color: rgba(212, 180, 110, 0.45);
}

.scene-tag-btn {
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.scene-tag-btn:hover {
    transform: translateY(-1px);
    border-color: rgba(212, 180, 110, 0.65);
}

.scene-tag-btn.active {
    background: rgba(212, 180, 110, 0.24);
    color: #f8e3ae;
    border-color: rgba(212, 180, 110, 0.85);
    box-shadow: 0 0 0 1px rgba(212, 180, 110, 0.2) inset;
}

.modal-actions {
    display: flex;
    gap: 12px;
    padding: 20px;
    background: var(--bg-panel);
    border-top: 1px solid var(--gold-dark);
    flex-wrap: wrap;
}

.modal-actions .codex-btn {
    flex: 1;
    min-width: 80px;
}

/* ========== Login Page ========== */
.login-overlay {
    position: fixed;
    inset: 0;
    background: 
        radial-gradient(ellipse at top, rgba(212, 180, 110, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at bottom, rgba(139, 105, 20, 0.05) 0%, transparent 50%),
        var(--bg-main);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 100;
    overflow: hidden;
}

/* Background Decorations */
.login-bg-decoration {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
}

.floating-icon {
    position: absolute;
    width: 120px;
    height: 120px;
    color: var(--gold-dim);
    opacity: 0.15;
    animation: float 20s ease-in-out infinite;
}

.floating-icon svg {
    width: 100%;
    height: 100%;
}

.floating-icon.icon-1 {
    top: 10%;
    left: 10%;
    animation-delay: 0s;
}

.floating-icon.icon-2 {
    top: 20%;
    right: 15%;
    animation-delay: -5s;
    width: 80px;
    height: 80px;
}

.floating-icon.icon-3 {
    bottom: 20%;
    left: 15%;
    animation-delay: -10s;
    width: 100px;
    height: 100px;
}

.floating-icon.icon-4 {
    bottom: 15%;
    right: 10%;
    animation-delay: -15s;
}

@keyframes float {
    0%, 100% {
        transform: translateY(0) rotate(0deg);
    }
    25% {
        transform: translateY(-20px) rotate(5deg);
    }
    50% {
        transform: translateY(0) rotate(0deg);
    }
    75% {
        transform: translateY(20px) rotate(-5deg);
    }
}

/* Login Panel */
.login-panel {
    background: linear-gradient(145deg, rgba(20, 28, 41, 0.8), rgba(10, 15, 24, 0.9));
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--gold-primary);
    border-radius: 12px;
    max-width: 440px;
    width: 100%;
    position: relative;
    box-shadow: 
        0 30px 90px rgba(0, 0, 0, 0.8),
        0 0 0 1px rgba(212, 180, 110, 0.1) inset;
    animation: loginPanelAppear 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes loginPanelAppear {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.login-panel-corner {
    position: absolute;
    width: 24px;
    height: 24px;
    border: 2px solid transparent; /* Hide corners since we round it */
    pointer-events: none;
}

.login-panel-corner-tl {
    top: -2px;
    left: -2px;
    border-right: none;
    border-bottom: none;
}

.login-panel-corner-tr {
    top: -2px;
    right: -2px;
    border-left: none;
    border-bottom: none;
}

.login-panel-corner-bl {
    bottom: -2px;
    left: -2px;
    border-right: none;
    border-top: none;
}

.login-panel-corner-br {
    bottom: -2px;
    right: -2px;
    border-left: none;
    border-top: none;
}

/* Login Logo Section */
.login-logo {
    text-align: center;
    padding: 40px 30px 30px;
    background: linear-gradient(to bottom, rgba(212, 180, 110, 0.05), transparent);
    border-bottom: 1px solid var(--gold-dark);
}

.login-logo-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 20px;
    background: linear-gradient(145deg, var(--bg-card), var(--bg-slot));
    border: 2px solid var(--gold-dim);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 
        0 8px 30px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    animation: logoPulse 3s ease-in-out infinite;
}

@keyframes logoPulse {
    0%, 100% {
        box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3), 0 0 0 0 rgba(212, 180, 110, 0.2);
    }
    50% {
        box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3), 0 0 30px 5px rgba(212, 180, 110, 0.1);
    }
}

.login-logo-icon svg {
    width: 40px;
    height: 40px;
    color: var(--gold-primary);
}

.login-title {
    font-family: 'Cinzel', serif;
    font-size: 1.8rem;
    color: var(--gold-primary);
    margin: 0 0 8px;
    text-transform: uppercase;
    letter-spacing: 3px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.login-subtitle {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin: 0;
    letter-spacing: 2px;
    text-transform: uppercase;
}

/* Login Loading State */
.login-loading {
    padding: 60px 30px;
    text-align: center;
}

.login-spinner {
    position: relative;
    width: 80px;
    height: 80px;
    margin: 0 auto 24px;
}

.login-spinner-ring {
    position: absolute;
    inset: 0;
    border: 3px solid transparent;
    border-top-color: var(--gold-primary);
    border-radius: 50%;
    animation: spinnerRing 1.5s linear infinite;
}

.login-spinner-ring:nth-child(2) {
    inset: 10px;
    border-top-color: var(--gold-dim);
    animation-duration: 1.2s;
    animation-direction: reverse;
}

.login-spinner-ring:nth-child(3) {
    inset: 20px;
    border-top-color: var(--gold-bright);
    animation-duration: 0.9s;
}

@keyframes spinnerRing {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.login-loading-text {
    font-family: 'Cinzel', serif;
    color: var(--gold-primary);
    font-size: 1rem;
    letter-spacing: 2px;
    animation: loadingPulse 1.5s ease-in-out infinite;
}

@keyframes loadingPulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* Login Success State */
.login-success {
    padding: 60px 30px;
    text-align: center;
}

.login-success-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 20px;
    background: linear-gradient(145deg, rgba(16, 185, 129, 0.2), rgba(16, 185, 129, 0.1));
    border: 2px solid #10b981;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: successPop 0.5s ease-out;
}

@keyframes successPop {
    0% { transform: scale(0); opacity: 0; }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

.login-success-icon svg {
    width: 40px;
    height: 40px;
    color: #10b981;
}

.login-success-text {
    font-family: 'Cinzel', serif;
    font-size: 1.4rem;
    color: #10b981;
    margin: 0 0 8px;
}

.login-success-subtext {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin: 0;
}

/* Login Form */
.login-form {
    padding: 30px;
}

.login-form-header {
    text-align: center;
    margin-bottom: 24px;
}

.login-lock-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 16px;
    background: linear-gradient(145deg, var(--bg-card), var(--bg-slot));
    border: 2px solid var(--gold-dark);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-lock-icon svg {
    width: 28px;
    height: 28px;
    color: var(--gold-primary);
}

.login-form-title {
    font-size: 1rem;
    color: var(--text-muted);
    margin: 0;
    letter-spacing: 1px;
}

/* Login Input Group */
.login-input-group {
    margin-bottom: 20px;
}

.login-input-wrapper {
    position: relative;
    display: flex;
    gap: 8px;
}

.login-input {
    flex: 1;
    background: rgba(6, 10, 18, 0.4);
    border: 2px solid var(--gold-dark);
    color: var(--text-main);
    padding: 14px 18px;
    font-family: 'Noto Sans SC', sans-serif;
    font-size: 1rem;
    outline: none;
    transition: all 0.3s;
    border-radius: 6px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.5);
}

.login-input:focus {
    border-color: var(--gold-primary);
    box-shadow: 0 0 0 3px rgba(212, 180, 110, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.login-input::placeholder {
    color: var(--text-muted);
    opacity: 0.6;
}

.login-input-toggle {
    width: 48px;
    height: 48px;
    background: linear-gradient(to bottom, var(--bg-card), var(--bg-slot));
    border: 2px solid var(--gold-dark);
    color: var(--gold-dim);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.login-input-toggle:hover {
    border-color: var(--gold-primary);
    color: var(--gold-primary);
}

.login-input-toggle svg {
    width: 20px;
    height: 20px;
}

.login-session-info {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin: 12px 0 0;
    display: flex;
    align-items: center;
}

/* Login Error */
.login-error {
    display: flex;
    align-items: center;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #ef4444;
    padding: 12px 16px;
    margin-bottom: 20px;
    font-size: 0.9rem;
    animation: shake 0.5s ease-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* Login Submit Button */
.login-submit-btn {
    width: 100%;
    background: linear-gradient(to bottom, var(--gold-primary), var(--gold-dark));
    border: 2px solid var(--gold-bright);
    color: #000;
    padding: 16px 24px;
    font-family: 'Cinzel', serif;
    font-size: 1rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    transition: all 0.3s;
    position: relative;
    overflow: hidden;
}

.login-submit-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0.2), transparent);
    opacity: 0;
    transition: opacity 0.3s;
}

.login-submit-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(212, 180, 110, 0.3);
    border-color: var(--gold-bright);
}

.login-submit-btn:hover::before {
    opacity: 1;
}

.login-submit-btn:active {
    transform: translateY(0);
}

.login-submit-btn svg {
    width: 20px;
    height: 20px;
    transition: transform 0.3s;
}

.login-submit-btn:hover svg {
    transform: translateX(4px);
}

/* Light Theme Login Adjustments */
[data-theme="light"] .login-overlay {
    background: 
        radial-gradient(ellipse at top, rgba(139, 105, 20, 0.05) 0%, transparent 50%),
        radial-gradient(ellipse at bottom, rgba(201, 162, 39, 0.03) 0%, transparent 50%),
        var(--bg-main);
}

[data-theme="light"] .floating-icon {
    color: var(--gold-dim);
    opacity: 0.1;
}

[data-theme="light"] .login-panel {
    box-shadow: 
        0 25px 80px rgba(0, 0, 0, 0.15),
        0 0 0 1px rgba(139, 105, 20, 0.1);
}

[data-theme="light"] .login-logo {
    background: linear-gradient(to bottom, rgba(139, 105, 20, 0.03), transparent);
}

[data-theme="light"] .login-logo-icon {
    background: linear-gradient(145deg, #ffffff, #f0eeeb);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .login-input {
    background: #ffffff;
    border-color: #d1d5db;
}

[data-theme="light"] .login-input:focus {
    border-color: #8b6914;
    box-shadow: 0 0 0 3px rgba(139, 105, 20, 0.1);
}

[data-theme="light"] .login-input-toggle {
    background: linear-gradient(to bottom, #ffffff, #f0eeeb);
    border-color: #d1d5db;
}

[data-theme="light"] .login-submit-btn {
    background: linear-gradient(to bottom, #a67c00, #8b6914);
    border-color: #c9a227;
    color: #ffffff;
}

[data-theme="light"] .login-submit-btn:hover {
    box-shadow: 0 8px 25px rgba(139, 105, 20, 0.25);
}

/* Responsive */
@media (max-width: 480px) {
    .login-panel {
        max-width: 100%;
    }
    
    .login-title {
        font-size: 1.4rem;
    }
    
    .floating-icon {
        display: none;
    }
}

/* ========== Form Elements ========== */
.codex-input {
    background: rgba(13, 20, 31, 0.6);
    border: 1px solid var(--gold-dark);
    color: var(--text-main);
    padding: 12px 16px;
    font-family: 'Noto Sans SC', sans-serif;
    font-size: 0.95rem;
    width: 100%;
    outline: none;
    transition: all 0.3s;
    -webkit-appearance: none;
    border-radius: 6px;
}

.codex-input:focus {
    border-color: var(--gold-primary);
    box-shadow: 0 0 8px rgba(212, 180, 110, 0.2);
}

textarea.codex-input {
    resize: vertical;
    min-height: 80px;
}

select.codex-input {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23d4b46e%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat;
    background-position: right 12px top 50%;
    background-size: 12px auto;
    padding-right: 36px;
}

/* ========== Upload ========== */
.upload-area {
    border: 2px dashed var(--gold-dark);
    padding: 40px;
    text-align: center;
    background: var(--bg-main);
    transition: all 0.3s;
    cursor: pointer;
}

.upload-area:hover {
    border-color: var(--gold-dim);
    background: rgba(212, 180, 110, 0.05);
}

.upload-preview {
    max-width: 200px;
    max-height: 200px;
    border: 2px solid var(--gold-dim);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

/* ========== Batch Bar ========== */
.batch-bar {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(6, 10, 18, 0.98);
    border: 2px solid var(--gold-primary);
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.8);
    z-index: 90;
    flex-wrap: wrap;
    justify-content: center;
}

/* ========== Loading & Empty ========== */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px;
    gap: 20px;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 3px solid rgba(212, 180, 110, 0.2);
    border-top-color: var(--gold-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px;
    color: var(--text-muted);
    text-align: center;
}

/* ========== Scrollbar ========== */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: var(--bg-main);
    border: 1px solid var(--gold-dark);
}

::-webkit-scrollbar-thumb {
    background: var(--gold-dark);
    border: 1px solid var(--bg-main);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--gold-dim);
}

/* ========== Tablet Responsive ========== */
@media (max-width: 1200px) {
    :root {
        --slot-size: var(--slot-size-tablet);
    }
    
    .inventory-grid {
        grid-template-columns: repeat(auto-fill, minmax(var(--slot-size-tablet), 1fr));
    }
}

/* ========== Mobile Responsive ========== */
@media (max-width: 1024px) {
    .main-container {
        flex-direction: column;
        padding: 12px;
        gap: 12px;
    }
    
    .sidebar {
        width: 100%;
        flex-direction: row;
        overflow-x: auto;
        padding: 12px;
        max-height: none;
        gap: 8px;
    }
    
    .sidebar-title {
        display: none;
    }
    
    .category-list {
        flex-direction: row;
        gap: 8px;
    }
    
    .category-item {
        white-space: nowrap;
        min-width: auto;
    }
    
    .item-stats {
        width: 100%;
        border-left: none;
        border-top: 1px solid var(--gold-dark);
    }
    
    .item-detail {
        flex-direction: column;
    }
    
    .item-preview {
        min-height: 300px;
        padding: 20px;
    }
    
    .item-preview img {
        max-height: 350px;
    }
}

@media (max-width: 768px) {
    :root {
        --slot-size: var(--slot-size-mobile);
    }
    
    .codex-header {
        flex-direction: column;
        gap: 12px;
        padding: 12px 16px;
    }
    
    .header-title h1 {
        font-size: 1.1rem;
    }
    
    .header-icon {
        width: 40px;
        height: 40px;
    }
    
    .header-icon svg {
        width: 24px;
        height: 24px;
    }
    
    .stats-bar {
        width: 100%;
        justify-content: space-around;
    }
    
    .stat-item {
        padding: 8px 12px;
        min-width: auto;
        flex: 1;
    }
    
    .stat-value {
        font-size: 1.2rem;
    }
    
    .inventory-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }
    
    .toolbar-search {
        max-width: none;
        min-width: auto;
    }
    
    .toolbar-actions {
        justify-content: center;
    }
    
    .inventory-grid {
        grid-template-columns: repeat(auto-fill, minmax(var(--slot-size-mobile), 1fr));
        gap: 8px;
        padding: 12px;
    }
    
    .item-info {
        padding: 4px 6px;
    }
    
    .item-category {
        font-size: 0.65rem;
    }
    
    .modal-overlay {
        padding: 8px;
    }
    
    .modal-panel {
        max-height: 95vh;
    }
    
    .modal-header h2 {
        font-size: 1rem;
    }
    
    .item-preview {
        min-height: 250px;
        padding: 16px;
    }
    
    .item-preview img {
        max-height: 280px;
    }
    
    .nav-btn {
        width: 40px;
        height: 40px;
    }
    
    .nav-btn.left {
        left: 8px;
    }
    
    .nav-btn.right {
        right: 8px;
    }
    
    .modal-actions {
        padding: 12px;
    }
    
    .modal-actions .codex-btn {
        min-width: 60px;
        padding: 10px 12px;
        font-size: 0.75rem;
    }
    
    .batch-bar {
        left: 12px;
        right: 12px;
        transform: none;
        bottom: 12px;
        padding: 10px 16px;
    }
    
    .pagination-bar {
        gap: 12px;
        padding: 12px;
    }
    
    .page-info {
        min-width: 80px;
        font-size: 0.85rem;
    }
}

/* Small mobile devices */
@media (max-width: 380px) {
    :root {
        --slot-size: var(--slot-size-small);
    }
    
    .inventory-grid {
        grid-template-columns: repeat(auto-fill, minmax(var(--slot-size-small), 1fr));
        gap: 6px;
    }
    
    .item-image {
        padding: 8px;
    }
}

/* Touch device optimizations */
@media (hover: none) {
    .item-slot:hover {
        transform: none;
    }
    
    .item-slot:active {
        transform: scale(0.98);
    }
    
    .codex-btn:hover {
        transform: none;
    }
    
    .category-item:hover {
        background: var(--bg-slot);
        border-color: transparent;
    }
    
    .category-item.active:hover {
        background: linear-gradient(to right, rgba(212, 180, 110, 0.15), transparent);
        border-color: var(--gold-primary);
    }
}

/* Android Chrome specific fixes */
@supports (-webkit-touch-callout: none) {
    .inventory-grid {
        /* Prevent scroll issues on iOS/Android */
        -webkit-overflow-scrolling: touch;
    }
    
    .modal-content {
        -webkit-overflow-scrolling: touch;
    }
}

/* Prevent text selection on UI elements */
.codex-btn,
.category-item,
.item-slot,
.nav-btn {
    -webkit-user-select: none;
    user-select: none;
}

/* Utility Classes */
.text-gold { color: var(--gold-primary) !important; }
.text-bright { color: var(--gold-bright) !important; }
.text-muted { color: var(--text-muted) !important; }
.font-cinzel { font-family: 'Cinzel', serif; }

/* ========== Theme Toggle ========== */
.theme-toggle {
    margin-left: 12px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(145deg, #1a2332, #0f1419);
    border: 2px solid var(--gold-dim);
    position: relative;
    overflow: hidden;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 
        0 4px 15px rgba(0, 0, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.1),
        0 0 0 1px rgba(212, 180, 110, 0.1);
}

.theme-toggle::before {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: 50%;
    background: conic-gradient(from 0deg, transparent, var(--gold-primary), transparent);
    opacity: 0;
    transition: opacity 0.3s ease;
    animation: rotate 3s linear infinite;
}

@keyframes rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.theme-toggle:hover::before {
    opacity: 0.3;
}

.theme-toggle:hover {
    border-color: var(--gold-primary);
    box-shadow: 
        0 8px 25px rgba(212, 180, 110, 0.25),
        0 0 40px rgba(212, 180, 110, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.15);
    transform: scale(1.08);
}

.theme-toggle:active {
    transform: scale(0.95);
}

.theme-icon-wrapper {
    position: relative;
    z-index: 2;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle svg {
    width: 22px;
    height: 22px;
    color: var(--gold-primary);
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Sun icon styles */
.theme-toggle .sun-icon {
    animation: sunRotate 10s linear infinite;
}

@keyframes sunRotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.theme-toggle:hover .sun-icon {
    animation-duration: 3s;
}

/* Moon icon styles */
.theme-toggle .moon-icon {
    animation: moonBob 4s ease-in-out infinite;
}

@keyframes moonBob {
    0%, 100% { transform: translateY(0) rotate(-5deg); }
    50% { transform: translateY(-3px) rotate(5deg); }
}

.theme-glow {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: radial-gradient(circle at center, var(--gold-primary) 0%, transparent 70%);
    opacity: 0;
    transform: scale(0.5);
    transition: all 0.5s ease;
    pointer-events: none;
}

.theme-toggle:hover .theme-glow {
    opacity: 0.15;
    transform: scale(1.2);
}

/* Light theme styles */
[data-theme="light"] .theme-toggle {
    background: linear-gradient(145deg, #ffffff, #e8e5e0);
    border-color: #d1c4a8;
    box-shadow: 
        0 4px 15px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.9),
        0 0 0 1px rgba(184, 149, 78, 0.1);
}

[data-theme="light"] .theme-toggle::before {
    background: conic-gradient(from 0deg, transparent, #b8954e, transparent);
}

[data-theme="light"] .theme-toggle:hover {
    border-color: #b8954e;
    box-shadow: 
        0 8px 25px rgba(184, 149, 78, 0.2),
        0 0 40px rgba(184, 149, 78, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

[data-theme="light"] .theme-toggle svg {
    color: #6b5630;
}

[data-theme="light"] .theme-toggle:hover .theme-glow {
    opacity: 0.1;
}

/* Additional Light Theme Optimizations */
[data-theme="light"] .sidebar {
    background: #f5f2eb;
    border-color: #a8a49c;
}

[data-theme="light"] .sidebar-title {
    color: #6b5308;
    border-bottom-color: #c9a227;
}

[data-theme="light"] .category-item {
    background: #ebe7de;
    border-color: transparent;
}

[data-theme="light"] .category-item:hover {
    background: #ddd9d0;
    border-color: #b8b4ac;
}

[data-theme="light"] .category-item.active {
    background: linear-gradient(to right, rgba(139, 105, 20, 0.1), transparent);
    border-color: #8b6914;
}

[data-theme="light"] .category-name {
    color: #1a1a1a;
}

[data-theme="light"] .category-count {
    background: #f5f2eb;
    border-color: #b8b4ac;
    color: #4a4a4a;
}

[data-theme="light"] .inventory-panel {
    background: #f5f2eb;
    border-color: #a8a49c;
}

[data-theme="light"] .inventory-toolbar {
    background: linear-gradient(to bottom, #ebe7de, #ddd9d0);
    border-bottom-color: #b8b4ac;
}

[data-theme="light"] .toolbar-search input {
    background: #f5f2eb;
    border-color: #b8b4ac;
    color: #1a1a1a;
}

[data-theme="light"] .toolbar-search input::placeholder {
    color: #6b6560;
}

[data-theme="light"] .codex-input {
    background: #f5f2eb;
    border-color: #b8b4ac;
    color: #1a1a1a;
}

[data-theme="light"] .codex-input:focus {
    border-color: #8b6914;
    box-shadow: 0 0 8px rgba(139, 105, 20, 0.2);
}

[data-theme="light"] .codex-btn {
    background: linear-gradient(to bottom, #ebe7de, #ddd9d0);
    border-color: #a68b4b;
    color: #6b5308;
}

[data-theme="light"] .codex-btn:hover {
    border-color: #8b6914;
    color: #4a3f2a;
}

[data-theme="light"] .codex-btn.primary {
    background: linear-gradient(to bottom, #a68b4b, #8b6914);
    color: #ffffff;
    border-color: #6b5308;
}

[data-theme="light"] .stat-item {
    background: linear-gradient(to bottom, #f5f2eb, #ebe7de);
    border-color: #b8b4ac;
}

[data-theme="light"] .stat-value {
    color: #8b6914;
    text-shadow: 0 0 10px rgba(139, 105, 20, 0.2);
}

[data-theme="light"] .stat-label {
    color: #4a4a4a;
}

[data-theme="light"] .modal-panel {
    background: #f5f2eb;
    border-color: #a68b4b;
}

[data-theme="light"] .modal-header {
    background: linear-gradient(to bottom, #ebe7de, #ddd9d0);
    border-bottom-color: #b8b4ac;
}

[data-theme="light"] .modal-overlay {
    background: rgba(0, 0, 0, 0.6);
}

[data-theme="light"] .item-slot {
    background: linear-gradient(145deg, #ebe7de, #ddd9d0);
    border-color: #b8b4ac;
}

[data-theme="light"] .item-slot:hover {
    background: #d0ccc3;
    border-color: #a68b4b;
}

[data-theme="light"] .item-slot.selected {
    border-color: #8b6914;
    background: rgba(139, 105, 20, 0.08);
}

[data-theme="light"] .pagination-bar {
    background: linear-gradient(to bottom, #ddd9d0, #ebe7de);
    border-top-color: #b8b4ac;
}

[data-theme="light"] .page-info {
    color: #8b6914;
}

[data-theme="light"] .upload-area {
    background: #f5f2eb;
    border-color: #b8b4ac;
}

[data-theme="light"] .upload-area:hover {
    background: #ebe7de;
    border-color: #a68b4b;
}

[data-theme="light"] .empty-state {
    color: #6b6560;
}

[data-theme="light"] .loading-state p {
    color: #8b6914;
}

[data-theme="light"] ::-webkit-scrollbar-track {
    background: #ebe7de;
    border-color: #b8b4ac;
}

[data-theme="light"] ::-webkit-scrollbar-thumb {
    background: #a68b4b;
}

[data-theme="light"] ::-webkit-scrollbar-thumb:hover {
    background: #8b6914;
}

/* Smooth transitions for theme changes */
*,
*::before,
*::after {
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease, box-shadow 0.3s ease;
}

/* Exclude certain elements from transition for better performance */
.spinner,
.item-image img {
    transition: none;
}

/* ========== Animations ========== */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slideIn {
    from { opacity: 0; transform: translateX(-20px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* ========== Batch Upload Modal Styles ========== */
.batch-file-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 8px;
    margin-top: 12px;
    max-height: 200px;
    overflow-y: auto;
}

.batch-file-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.batch-file-thumb {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border: 1px solid var(--gold-dark);
    border-radius: 4px;
}

.batch-file-name {
    font-size: 0.7rem;
    color: var(--text-muted);
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
}

.batch-file-more {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
    padding: 8px;
}

.codex-checkbox {
    width: 18px;
    height: 18px;
    accent-color: var(--gold-primary);
    cursor: pointer;
}

/* Light theme adjustments */
[data-theme="light"] .batch-file-thumb {
    border-color: var(--gold-dark);
}

[data-theme="light"] .progress-bar {
    background: #ddd9d0;
}

.batch-spinner {
    display: flex;
    justify-content: center;
    align-items: center;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--bg-main);
    border: 1px solid var(--gold-dark);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--gold-dim), var(--gold-primary));
    transition: width 0.3s ease;
}

/* Apply animations to elements */
.inventory-grid .item-slot {
    animation: fadeIn 0.3s ease-out;
}

.category-item {
    animation: slideIn 0.2s ease-out;
}

.stat-value {
    animation: pulse 2s ease-in-out infinite;
}

/* Improved focus states for accessibility */
.codex-input:focus,
.codex-btn:focus,
.category-item:focus {
    outline: 2px solid var(--gold-primary);
    outline-offset: 2px;
}

/* Custom scrollbar for webkit browsers */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-panel);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--gold-dim);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--gold-primary);
}

/* Loading skeleton animation */
@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

.skeleton {
    background: linear-gradient(90deg, var(--bg-slot) 25%, var(--bg-slot-hover) 50%, var(--bg-slot) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

/* Toast notification styles */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: var(--bg-panel);
    border: 1px solid var(--gold-dim);
    padding: 12px 20px;
    border-radius: 4px;
    box-shadow: 0 4px 12px var(--shadow-color);
    animation: slideIn 0.3s ease-out;
    max-width: 300px;
}

.toast.success {
    border-color: #10b981;
    background: rgba(16, 185, 129, 0.1);
}

.toast.error {
    border-color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

/* Responsive improvements */
@media (max-width: 768px) {
    .theme-toggle {
        margin-left: 8px;
    }
    
    .codex-header {
        padding: 12px 16px;
    }
}

[data-theme="light"] .analysis-result {
    background: linear-gradient(145deg, rgba(212, 180, 110, 0.18), rgba(255, 255, 255, 0.75));
    border-color: rgba(139, 105, 20, 0.35);
}

[data-theme="light"] .scene-tag-btn.active {
    color: #6a4c00;
}
