/* Base Styles */

body {
    font-family: 'Arial', sans-serif;
    margin: 0;
    padding: 0;
    background: #f0f0f0;
}

/* Grid System */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 2px;
    padding: 0;
    width: 100%;
    align-items: start;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

@media (min-width: 768px) {
    .grid {
        max-width: 70%;
        margin: 0 auto;
    }
}

@media (max-width: 480px) {
    .grid {
        grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    }
}

/* Checkered Pattern */
.character-cell:nth-child(even) {
    background: #f8f8f8;
}

.character-cell {
    touch-action: pan-y; /* Allow vertical scrolling */
    position: relative;
    padding-top: 100%;
    background: transparent;
    margin: 0;
    overflow: hidden;
    border: 2px solid #ddd;
    border-radius: 8px;
    transition: transform 0.3s ease, opacity 0.2s ease;
    will-change: transform;
    /* dragging smth */
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

.dragging {
    opacity: 0.5;
    transform: scale(0.95);
    z-index: 1000;
    transition: none !important;
}

.character-cell:hover {
    /* transform: translateY(-2px); */
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

@media (max-width: 768px) {
    .character-cell {
        user-select: none;  /* Disable text selection */
    }
    
    .character-cell.dragging {
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    }
}

/* Character Image */
.character-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
    /* Prevent images from blocking drag events */
    -webkit-touch-callout: none;
    user-select: none;
}

/* Prevent ghosting on mobile only */
@media (pointer: coarse) {
    .character-cell {
        -webkit-user-drag: none;
    }
    
    .character-image {
        -webkit-user-drag: none !important;
        pointer-events: none;
    }
}

/* Overlay Elements */
.check-mark {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url('/images/check.png');
    background-size: contain;
    background-repeat: no-repeat;
    opacity: 1;
    z-index: 2;
}

.circles {
    display: block;
    z-index: 3;
}

.circle {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    /* Stretch circle to fill the container */
    height: 100%;
    /* Stretch circle to fill the container */
    background-size: contain;
    /* Scale the circle image to fit the container */
    background-repeat: no-repeat;
    opacity: 0;
    transition: opacity 0.3s;
    /* Optional smooth transition */
}

.circle.show {
    opacity: 1;
    /* Make the circle visible when the class 'show' is added */
}

/* Specific background images for each circle (M3.png, M6.png, M9.png) */
.circle:nth-child(1) {
    background-image: url('/images/M3.png');
}

.circle:nth-child(2) {
    background-image: url('/images/M6.png');
}

.circle:nth-child(3) {
    background-image: url('/images/M9.png');
}

/* Controls */
.controls {
    margin: 1rem;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

button,
.btn {
    font: inherit;
    /* Inherit from parent */
    padding: 6px 12px;
    background: #4CAF50;
    line-height: 1.5;
    -webkit-appearance: none;
    /* Disable default mobile styles */
    -moz-appearance: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;

    border: none;
    border-radius: 4px;
    color: white;
    cursor: pointer;
    transition: opacity 0.2s;
}

/* Import Button */
.import-btn {
    position: relative;
    overflow: hidden;
}

.import-btn input[type="file"] {
    position: absolute;
    opacity: 0;
    width: 0.1px;
    height: 0.1px;
}

/* Hover states */
button:hover,
.btn:hover {
    opacity: 0.9;
}

.import-icon {
    width: 20px;
    height: 20px;
    fill: currentColor;
    margin-right: 8px;
}

/* Loading State */
.import-btn.loading .btn-content {
    visibility: hidden;
}

.import-btn.loading::after {
    content: "";
    position: absolute;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s linear infinite;
}

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

/* Context Menu */
.context-menu {
    position: fixed;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 1000;
}

.context-item {
    padding: 8px 16px;
    cursor: pointer;
    transition: background 0.2s;
}

.context-item.disabled {
    color: #999 !important;
    cursor: not-allowed;
    pointer-events: none;
}

.context-item:hover {
    background: #f5f5f5;
}

@media (max-width: 768px) {
    .context-menu {
        position: fixed !important;
        min-width: 120px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        border-radius: 8px;
        z-index: 1000;
        touch-action: pan-y !important;
    }

    .context-item {
        padding: 12px 16px;
        font-size: 16px;
        border-bottom: 1px solid #eee;
        user-select: none;  /* Disable text selection */
        
        -webkit-touch-callout: none;
        touch-action: manipulation;
    }

    .context-item:last-child {
        border-bottom: none;
    }

    .context-item:active {
        background: #f0f0f0;
    }
}

/* Delete mode indicators */
.destruction-off {
    background: #4CAF50 !important;
}

.destruction-on {
    background: #ff4444 !important;
    /* border: 2px solid #cc0000 !important; */
}

.delete-mode .character-cell {
    border-color: #ff4444;
}

/* Profile loading indicator */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.8);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

/* Share Dialog */
.share-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
    z-index: 1000;
}

.share-dialog input {
    width: 300px;
    padding: 8px;
    margin: 5px;
    border: 1px solid #ddd;
}

.share-dialog button {
    padding: 8px 12px;
    background: #4CAF50;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

/* Add share dialog styles */
.notice {
    font-size: 0.9em;
    color: #666;
    margin-top: 10px;
}

.share-type {
    padding: 10px;
    border-radius: 4px;
    margin: 10px 0;
}

.share-type.persistent {
    background: #e3f2fd;
    color: #1976d2;
}

.share-type.snapshot {
    background: #fff3e0;
    color: #ef6c00;
}

.notice {
    font-size: 0.9em;
    color: #666;
    margin-top: 10px;
}

/* Import Button */
#importProfile {
    position: relative;
    overflow: hidden;
    display: inline-block;
}

#importProfile input[type="file"] {
    position: absolute;
    left: 0;
    top: 0;
    opacity: 0;
    cursor: pointer;
    height: 100%;
    width: 100%;
}

/* Sidebar Styles */
.sidebar-container {
    position: fixed;
    top: 0;
    right: -40vw;
    width: 40vw;
    height: 100vh;
    background: white;
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.1);
    transition: right 0.3s ease;
    z-index: 1000;
    display: flex;
    flex-direction: column;
}

.sidebar-container.active {
    right: 0;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid #eee;
}

.close-sidebar {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
}

.search-container {
    padding: 15px;
    border-bottom: 1px solid #eee;
}

.search-field {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.sidebar-grid {
    flex: 1;
    overflow-y: auto;
    padding: 1px;
    display: grid;
    gap: 1px;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    grid-auto-rows: min-content;
}

/* Mobile Styles */
@media (max-width: 768px),
(orientation: portrait) {
    .sidebar-container {
        width: 100%;
        height: 70vh;
        right: 0;
        bottom: -70vh;
        top: auto;
        transition: bottom 0.3s ease;
    }

    .sidebar-container.active {
        bottom: 0;
        right: 0;
    }
}

/* Overlay */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 999;
    display: none;
}

.sidebar-overlay.active {
    display: block;
}

/* Character item container */
.sidebar-character {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px;
    border: 1px solid #eee;
    border-radius: 8px;
    transition: transform 0.2s;
    cursor: pointer;
}

.sidebar-character:hover {
    transform: translateY(-2px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

/* Image container */
.sidebar-character img {
    width: 100%;
    height: 100px;
    object-fit: contain;
    border-radius: 4px;
    margin-bottom: 8px;
}

/* Loading animation */
.sidebar-character img::after {
    content: "Loading...";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #999;
    font-size: 0.8em;
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.8);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.cell-placeholder {
    background: #f0f0f0;
    border: 2px dashed #ddd;
    border-radius: 8px;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% {
        opacity: 0.6;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.6;
    }
}

/* Text container */
.char-info {
    width: 100%;
    text-align: center;
}

.char-name {
    font-weight: 500;
    font-size: 0.9em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.char-id {
    font-size: 0.8em;
    color: #666;
    margin-top: 4px;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .sidebar-grid {
        grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    }

    .sidebar-character img {
        height: 80px;
    }
}

/* Reuse admin filter styles with minor adjustments */
.filter-panel {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(5px);
}

.class-filter-item {
    background: rgba(0, 0, 0, 0.1);
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .filter-panel {
        top: 56px;
        /* Below header */
    }
}

/* Skin Popup */
.skin-popup {
    position: fixed;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 8px;
    padding: 1rem;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.skin-options {
    display: grid;
    grid-template-columns: repeat(3, 80px);
    gap: 0.5rem;
}

.skin-option {
    width: 80px;
    height: 80px;
    object-fit: contain;
    cursor: pointer;
    border: 2px solid transparent;
    border-radius: 4px;
    transition: transform 0.2s;
}

.skin-option:hover {
    transform: scale(1.1);
    z-index: 2;
}

.skin-option.selected {
    border-color: #4CAF50;
    box-shadow: 0 0 8px rgba(76, 175, 80, 0.5);
}