/* CSS Reset & Base Styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    /* Color Palette - Inspired by Animal Crossing */
    --primary: #7dc4a5;
    --primary-dark: #5ba883;
    --primary-light: #a8dcc4;
    --secondary: #f8e9d2;
    --accent: #f4a261;
    --accent-dark: #e76f51;

    --bg-main: #faf9f6;
    --bg-card: #ffffff;
    --bg-sidebar: #f5f3ef;
    --bg-header: #7dc4a5;

    --text-primary: #3d3d3d;
    --text-secondary: #6b6b6b;
    --text-light: #ffffff;
    --text-muted: #9a9a9a;

    --border-color: #e8e5e0;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.15);

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;

    --transition: 0.2s ease;
}

html {
    font-size: 16px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.5;
    overflow-x: hidden;
}

/* App Container */
.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    background: var(--bg-header);
    padding: 0.75rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-md);
}

.header-content {
    max-width: 1600px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-light);
    white-space: nowrap;
}

.search-container {
    flex: 1;
    max-width: 500px;
    position: relative;
}

.search-input {
    width: 100%;
    padding: 0.65rem 1rem 0.65rem 2.5rem;
    border: none;
    border-radius: var(--radius-lg);
    font-size: 0.95rem;
    background: rgba(255, 255, 255, 0.95);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition);
}

.search-input:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.5);
}

.search-input::placeholder {
    color: var(--text-muted);
}

.search-icon {
    position: absolute;
    left: 0.85rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1rem;
    color: var(--text-muted);
}

.cart-toggle {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: var(--radius-md);
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    transition: background var(--transition);
}

.cart-toggle:hover {
    background: rgba(255, 255, 255, 0.3);
}

.cart-icon {
    font-size: 1.3rem;
}

.cart-count {
    background: var(--accent);
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.15rem 0.45rem;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}

/* Main Layout */
.main-layout {
    display: flex;
    flex: 1;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
}

/* Sidebar */
.sidebar {
    width: 220px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    padding: 1rem 0;
    position: sticky;
    top: 60px;
    height: calc(100vh - 60px);
    overflow-y: auto;
    flex-shrink: 0;
}

.category-nav h3 {
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.category-list {
    list-style: none;
}

.category-item {
    padding: 0.6rem 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all var(--transition);
    font-size: 0.9rem;
    color: var(--text-secondary);
    border-left: 3px solid transparent;
}

.category-item:hover {
    background: rgba(125, 196, 165, 0.1);
    color: var(--text-primary);
}

.category-item.active {
    background: rgba(125, 196, 165, 0.15);
    color: var(--primary-dark);
    border-left-color: var(--primary);
    font-weight: 500;
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 1.5rem;
    min-width: 0;
}

.content-header {
    display: flex;
    align-items: baseline;
    gap: 1rem;
    margin-bottom: 1rem;
}

.content-header h2 {
    font-size: 1.5rem;
    color: var(--text-primary);
}

.item-count {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Subcategory Tabs */
.subcategory-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.subcategory-tab {
    padding: 0.4rem 0.9rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-secondary);
    transition: all var(--transition);
}

.subcategory-tab:hover {
    border-color: var(--primary);
    color: var(--primary-dark);
}

.subcategory-tab.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* Items Grid */
.items-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 1rem;
}

/* Item Card */
.item-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 0.75rem;
    cursor: pointer;
    transition: all var(--transition);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.item-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary-light);
}

.item-image {
    width: 80px;
    height: 80px;
    object-fit: contain;
    margin-bottom: 0.5rem;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

.item-name {
    font-size: 0.8rem;
    color: var(--text-primary);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.item-variation-count {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* Loading State */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    color: var(--text-muted);
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* No Results */
.no-results {
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition);
    padding: 1rem;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Modal */
.modal {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    transform: scale(0.95);
    transition: transform var(--transition);
    box-shadow: var(--shadow-lg);
}

.modal-overlay.active .modal {
    transform: scale(1);
}

.modal-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: none;
    border: none;
    font-size: 1.75rem;
    cursor: pointer;
    color: var(--text-muted);
    z-index: 10;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all var(--transition);
}

.modal-close:hover {
    background: var(--bg-sidebar);
    color: var(--text-primary);
}

.modal-content {
    display: flex;
    flex-direction: column;
}

/* Modal Image Section */
.modal-image-section {
    background: var(--secondary);
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

.modal-image-container {
    width: 160px;
    height: 160px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#modalImage {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* Carousel Buttons */
.carousel-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: var(--bg-card);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1rem;
    color: var(--text-secondary);
    box-shadow: var(--shadow-sm);
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.carousel-btn:hover {
    background: var(--primary);
    color: white;
}

.carousel-btn.prev {
    left: 1rem;
}

.carousel-btn.next {
    right: 1rem;
}

.carousel-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.carousel-btn:disabled:hover {
    background: var(--bg-card);
    color: var(--text-secondary);
}

/* Variation Indicator */
.variation-indicator {
    display: flex;
    gap: 0.4rem;
    margin-top: 1rem;
}

.variation-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.2);
    cursor: pointer;
    transition: all var(--transition);
}

.variation-dot.active {
    background: var(--primary);
    transform: scale(1.2);
}

.variation-name {
    margin-top: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Modal Info Section */
.modal-info-section {
    padding: 1.5rem;
}

.modal-title {
    font-size: 1.4rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

/* Tags */
.modal-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

.tag {
    padding: 0.3rem 0.7rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 500;
}

.tag-variation {
    background: #e3f2fd;
    color: #1976d2;
}

.tag-cyrus {
    background: #fff3e0;
    color: #e65100;
}

.tag-size {
    background: #f3e5f5;
    color: #7b1fa2;
}

.tag-concept {
    background: #e8f5e9;
    color: #388e3c;
}

.tag-series {
    background: #fce4ec;
    color: #c2185b;
}

.tag-set {
    background: #e0f7fa;
    color: #00838f;
}

.tag-style {
    background: #fff8e1;
    color: #f57f17;
}

/* Modal Details */
.modal-details {
    background: var(--bg-sidebar);
    border-radius: var(--radius-sm);
    padding: 1rem;
    margin-bottom: 1.25rem;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 0.4rem 0;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border-color);
}

.detail-row:last-child {
    border-bottom: none;
}

.detail-label {
    color: var(--text-secondary);
}

.detail-value {
    font-weight: 500;
    color: var(--text-primary);
    font-family: 'Courier New', monospace;
}

/* Modal Actions */
.modal-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

/* Buttons */
.btn {
    padding: 0.6rem 1.25rem;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    border: none;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.btn-copy {
    background: var(--bg-sidebar);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-copy:hover {
    background: var(--border-color);
}

.btn-add-cart {
    background: var(--primary);
    color: white;
    flex: 1;
}

.btn-add-cart:hover {
    background: var(--primary-dark);
}

.btn-add-cart:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
}

/* Cart Panel */
.cart-panel {
    position: fixed;
    top: 0;
    right: -400px;
    width: 380px;
    max-width: 100%;
    height: 100vh;
    background: var(--bg-card);
    box-shadow: var(--shadow-lg);
    z-index: 300;
    display: flex;
    flex-direction: column;
    transition: right 0.3s ease;
}

.cart-panel.active {
    right: 0;
}

.cart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--primary);
    color: white;
}

.cart-header h3 {
    font-size: 1.1rem;
}

.cart-close {
    background: none;
    border: none;
    font-size: 1.75rem;
    cursor: pointer;
    color: white;
    opacity: 0.8;
}

.cart-close:hover {
    opacity: 1;
}

.cart-items {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.cart-empty {
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
}

/* Cart Item */
.cart-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--bg-sidebar);
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
}

.cart-item-image {
    width: 45px;
    height: 45px;
    object-fit: contain;
}

.cart-item-info {
    flex: 1;
    min-width: 0;
}

.cart-item-name {
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cart-item-hex {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: 'Courier New', monospace;
}

.cart-item-actions {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.cart-item-btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.7rem;
    border-radius: 4px;
    cursor: pointer;
    border: none;
    transition: all var(--transition);
}

.cart-item-customize {
    background: var(--accent);
    color: white;
}

.cart-item-customize.active {
    background: var(--accent-dark);
}

.cart-item-remove {
    background: transparent;
    color: var(--accent-dark);
    border: 1px solid var(--accent-dark);
}

.cart-item-remove:hover {
    background: var(--accent-dark);
    color: white;
}

/* Cart Footer */
.cart-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 0.75rem;
}

.btn-clear {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    flex: 1;
}

.btn-clear:hover {
    background: var(--bg-sidebar);
}

.btn-checkout {
    background: var(--primary);
    color: white;
    flex: 1;
}

.btn-checkout:hover {
    background: var(--primary-dark);
}

/* Cart Overlay */
.cart-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 250;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition);
}

.cart-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Checkout Modal */
.checkout-modal {
    max-width: 500px;
    padding: 1.5rem;
}

.checkout-modal h2 {
    margin-bottom: 0.5rem;
}

.checkout-instructions {
    color: var(--text-secondary);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.checkout-textarea {
    width: 100%;
    height: 200px;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    resize: none;
    background: var(--bg-sidebar);
    margin-bottom: 1rem;
}

.checkout-actions {
    display: flex;
    justify-content: flex-end;
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text-primary);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    z-index: 400;
    opacity: 0;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-md);
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Responsive */
@media (max-width: 900px) {
    .sidebar {
        display: none;
    }

    .main-layout {
        flex-direction: column;
    }

    .items-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }
}

@media (max-width: 600px) {
    .header-content {
        gap: 0.75rem;
    }

    .logo {
        font-size: 1.1rem;
    }

    .search-input {
        padding: 0.5rem 0.75rem 0.5rem 2rem;
        font-size: 0.9rem;
    }

    .items-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 0.75rem;
    }

    .item-image {
        width: 60px;
        height: 60px;
    }

    .modal {
        max-height: 95vh;
    }

    .modal-actions {
        flex-direction: column;
    }

    .modal-actions .btn {
        width: 100%;
        justify-content: center;
    }

    .cart-panel {
        width: 100%;
        right: -100%;
    }
}
