/* Reset and Variables */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --primary-gradient: linear-gradient(135deg, #2c3e50, #1a252f);
    --accent-color: #f1c40f;
    --accent-glow: rgba(241, 196, 15, 0.4);
    --completed-color: #2ecc71;
    --completed-bg: rgba(46, 204, 113, 0.15);
    --text-color: #ecf0f1;
    --bg-dark: #0f171e;
    --card-bg: rgba(255, 255, 255, 0.04);
    --card-border: rgba(255, 255, 255, 0.08);
}

body {
    font-family: 'Rubik', 'Inter', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-color);
    min-height: 100vh;
    overflow: hidden;
    /* Avoid page bouncing on mobile */
    position: relative;
}

/* Mobile Wrapper */
.mobile-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    /* Fallback for older browsers */
    height: 100dvh;
    /* Dynamic viewport height */
    max-width: 600px;
    margin: 0 auto;
    background: var(--primary-gradient);
    box-shadow: 0 0 25px rgba(0, 0, 0, 0.5);
    position: relative;
}

/* Header */
.mobile-header {
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--card-border);
    padding: 15px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 10;
}

.header-main {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-main h1 {
    font-size: 1.6rem;
    font-weight: 800;
    color: #fff;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    font-family: 'Outfit', sans-serif;
    white-space: nowrap;
}

.header-main.has-four-buttons h1 {
    font-size: 1.35rem;
}

.header-actions {
    display: flex;
    gap: 10px;
}

.action-icon-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--card-border);
    color: #fff;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
}

.action-icon-btn:active {
    transform: scale(0.9);
    background: rgba(255, 255, 255, 0.2);
}

.action-icon-btn.reset {
    color: #e74c3c;
}

/* Progress Tracker */
.mobile-progress-wrapper {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.progress-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    font-weight: 500;
    color: #a0a8b0;
}

.progress-bar {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 6px;
    height: 8px;
    width: 100%;
    overflow: hidden;
}

.progress-fill {
    background: linear-gradient(90deg, #9b59b6, var(--accent-color));
    height: 100%;
    width: 0%;
    transition: width 0.5s ease-out;
    box-shadow: 0 0 8px var(--accent-glow);
}

/* Main Gameplay Area */
.mobile-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* Important for grid inner scroll */
    padding: 10px 15px;
}

/* Feedback banner */
.result-feedback {
    background: rgba(241, 196, 15, 0.12);
    border: 1px dashed rgba(241, 196, 15, 0.3);
    color: var(--accent-color);
    padding: 0 15px;
    border-radius: 10px;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 500;
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    margin-bottom: 0;
    transition: max-height 0.3s ease, opacity 0.3s ease, margin-bottom 0.3s ease, padding 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.result-feedback.show {
    padding: 10px 15px;
    max-height: 80px;
    opacity: 1;
    margin-bottom: 12px;
}

/* Grid container */
.inventory-scroll-area {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 20px;
}

.inventory-scroll-area::-webkit-scrollbar {
    width: 5px;
}

.inventory-scroll-area::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

/* Grid of Items */
.item-grid-mobile {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    padding: 2px;
}

/* Item Card */
.item {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 8px 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    position: relative;
    transition: transform 0.15s, background 0.15s, border-color 0.15s;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

.item img {
    width: 80px;
    height: 80px;
    object-fit: contain;
    margin-bottom: 4px;
    pointer-events: none;
}

.item i {
    font-size: 2.6rem;
    color: var(--accent-color);
    margin-bottom: 6px;
}

.item span {
    font-size: 0.75rem;
    font-weight: bold;
    color: #e0e6ed;
    display: block;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-top: 4px;
}

/* Item states */
.item.selected {
    border-color: #3498db !important;
    background: rgba(52, 152, 219, 0.15) !important;
    box-shadow: 0 0 12px rgba(52, 152, 219, 0.5) !important;
    transform: scale(1.03);
}

.item.drag-over-target {
    border-color: var(--accent-color) !important;
    background: rgba(241, 196, 15, 0.15) !important;
    box-shadow: 0 0 12px var(--accent-glow) !important;
}

.item.terminal {
    border-color: #f1c40f !important;
    background: rgba(241, 196, 15, 0.08) !important;
    box-shadow: 0 0 10px rgba(241, 196, 15, 0.2);
}

.item.completed {
    opacity: 0.6;
    filter: grayscale(85%);
    border-color: #7f8c8d !important;
    background: rgba(52, 73, 94, 0.45) !important;
}

.item.completed:hover, .item.completed:active {
    opacity: 0.85;
    filter: grayscale(40%);
}

.crown-badge {
    position: absolute;
    top: 6px;
    right: 6px;
    background-color: #f1c40f;
    color: #18232c !important;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem !important;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    border: 1.5px solid #18232c;
    z-index: 5;
}

/* Touch dragging representation */
.touch-dragging {
    transition: none !important;
    transform: scale(1.1) !important;
    opacity: 0.85 !important;
    border-color: #3498db !important;
    background: rgba(44, 62, 80, 0.95) !important;
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.5) !important;
}

.item.dragging {
    opacity: 0.3;
}

/* Bottom Sheet Drawer */
.bottom-sheet {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    z-index: 1000;
    visibility: hidden;
    transition: visibility 0.3s;
}

.bottom-sheet.show {
    visibility: visible;
}

.bottom-sheet-backdrop {
    position: absolute;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    opacity: 0;
    transition: opacity 0.3s;
}

.bottom-sheet.show .bottom-sheet-backdrop {
    opacity: 1;
}

.bottom-sheet-content {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: #18232c;
    border-radius: 20px 20px 0 0;
    padding: 20px;
    box-shadow: 0 -10px 25px rgba(0, 0, 0, 0.3);
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.1, 0.8, 0.25, 1);
    display: flex;
    flex-direction: column;
    max-height: 85%;
    max-height: 85dvh;
}

.bottom-sheet.show .bottom-sheet-content {
    transform: translateY(0);
}

.bottom-sheet-handle {
    width: 40px;
    height: 5px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 5px;
    margin: -10px auto 15px auto;
    cursor: pointer;
}

.bottom-sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.bottom-sheet-header h3 {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--accent-color);
}

.close-sheet-btn {
    background: none;
    border: none;
    color: #a0a8b0;
    font-size: 1.2rem;
    cursor: pointer;
}

.bottom-sheet-body {
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    padding-bottom: 30px;
}

.sheet-image-container {
    width: 180px;
    height: 180px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--card-border);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    pointer-events: none;
    /* Prevents context menu and save image options */
    -webkit-touch-callout: none;
    user-select: none;
}

.sheet-image-container img {
    width: 150px;
    height: 150px;
    object-fit: contain;
}

.sheet-image-container i {
    font-size: 6rem;
    color: var(--accent-color);
}

.sheet-lore-text {
    font-size: 0.95rem;
    line-height: 1.6;
    color: #e0f2f1;
    text-align: right;
    width: 100%;
}

/* Bottom sheet links styling */
.sheet-links {
    display: flex;
    gap: 12px;
    margin-top: 15px;
    justify-content: center;
    width: 100%;
}

.sheet-link-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--card-border);
    color: #a0d9e2;
    padding: 8px 16px;
    border-radius: 8px;
    text-decoration: none;
    font-size: 0.8rem;
    font-weight: bold;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background 0.2s, transform 0.2s;
}

.sheet-link-btn:active {
    background: rgba(255, 255, 255, 0.15);
    transform: scale(0.95);
}

/* Footer */
.mobile-footer {
    padding: 10px 8px;
    background: rgba(0, 0, 0, 0.2);
    border-top: 1px solid var(--card-border);
    display: flex;
    justify-content: center;
}

.visualizer-link-btn {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--card-border);
    color: #a0d9e2;
    padding: 10px 20px;
    border-radius: 10px;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: bold;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: background 0.2s;
}

.visualizer-link-btn:active {
    background: rgba(255, 255, 255, 0.15);
}

/* Overlays (Victory, Dead-end) */
.game-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(8, 5, 20, 0.9);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.overlay-card {
    background: #18232c;
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    padding: 30px 20px;
    text-align: center;
    width: 85%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.victory-card {
    border-color: var(--accent-color);
}

.dead-end-card {
    border-color: #e74c3c;
}

.trophy-icon {
    font-size: 3.5rem;
    color: var(--accent-color);
}

.dead-end-icon {
    font-size: 3.5rem;
    color: #e74c3c;
}

.overlay-card h2 {
    font-size: 1.6rem;
}

.overlay-card p {
    font-size: 0.95rem;
    color: #b2bec3;
    line-height: 1.5;
}

.stats-summary {
    background: rgba(255, 255, 255, 0.05);
    padding: 8px 15px;
    border-radius: 10px;
    font-size: 0.95rem;
}

.overlay-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    width: 100%;
    margin-top: 10px;
}

.overlay-button {
    flex: 1 1 calc(50% - 10px);
    min-width: 120px;
    background: linear-gradient(45deg, #8a2be2, var(--accent-color));
    border: none;
    color: #fff;
    font-size: 0.95rem;
    font-weight: bold;
    padding: 12px;
    border-radius: 10px;
    cursor: pointer;
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.overlay-button.secondary {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--card-border);
}

/* Toast Messages */
.toast-message {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: bold;
    z-index: 1500;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s, visibility 0.25s;
    text-align: center;
}

.toast-message.show {
    opacity: 1;
    visibility: visible;
}

/* Animations */
.new-item-effect {
    animation: popAndGlowMobile 0.6s;
    border: 2px solid #00e6e6 !important;
}

@keyframes popAndGlowMobile {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.15);
    }

    100% {
        transform: scale(1);
    }
}

.first-time-frame {
    border: 2px solid gold !important;
    box-shadow: 0 0 10px gold;
}

/* Filter Toggle Button Style */
.action-icon-btn.active {
    color: var(--accent-color);
    border-color: var(--accent-color);
    background: rgba(241, 196, 15, 0.15);
}

@keyframes pulseGlow {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(241, 196, 15, 0.6);
    }

    70% {
        transform: scale(1.15);
        box-shadow: 0 0 0 8px rgba(241, 196, 15, 0);
    }

    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(241, 196, 15, 0);
    }
}

.action-icon-btn.glow {
    color: var(--accent-color) !important;
    border-color: var(--accent-color) !important;
    background: rgba(241, 196, 15, 0.2) !important;
    animation: pulseGlow 1.5s infinite;
}

/* Ad Banner Styles */
.ad-banner-container {
    margin-top: 12px;
    padding: 0;
    background: rgba(0, 0, 0, 0.25);
    border: 1px dashed rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 50px;
    position: relative;
    overflow: hidden;
    width: 320px;
    max-width: 100%;
    transition: all 0.3s ease;
}

.ad-banner-container ins.adsbygoogle {
    width: 100%;
}

.ad-placeholder {
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.25);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 4px;
    font-family: 'Rubik', sans-serif;
}

/* Hide placeholder and borders when the ad is successfully filled */
.ad-banner-container:has(ins.adsbygoogle[data-ad-status="filled"]) {
    background: transparent;
    border-color: transparent;
}

.ad-banner-container:has(ins.adsbygoogle[data-ad-status="filled"]) .ad-placeholder {
    display: none;
}

/* Auto-Retire & Archive Animation */
.item.retiring {
    animation: retireSparkle 0.55s cubic-bezier(0.4, 0, 0.2, 1) forwards;
    pointer-events: none;
}

@keyframes retireSparkle {
    0% {
        transform: scale(1);
        opacity: 1;
        box-shadow: 0 0 10px gold;
    }
    40% {
        transform: scale(1.15) rotate(3deg);
        opacity: 0.9;
        box-shadow: 0 0 25px #f1c40f, 0 0 35px #e67e22;
        filter: brightness(1.3);
    }
    100% {
        transform: scale(0.1) rotate(15deg);
        opacity: 0;
    }
}

/* Collection & Archive Modal View */
.collection-nav {
    display: flex;
    width: 100%;
    gap: 8px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--card-border);
    padding-bottom: 10px;
}

.collection-tab-btn {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--card-border);
    color: #a0a8b0;
    padding: 9px 12px;
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.2s;
    font-family: inherit;
}

.collection-tab-btn.active {
    background: rgba(241, 196, 15, 0.2);
    border-color: var(--accent-color);
    color: var(--accent-color);
}

.collection-filter-pills {
    display: flex;
    width: 100%;
    gap: 6px;
    margin-bottom: 12px;
    overflow-x: auto;
    padding-bottom: 4px;
}

.pill-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--card-border);
    color: #cfd8dc;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.78rem;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.pill-btn.active {
    background: var(--accent-color);
    color: #0f171e;
    font-weight: 700;
    border-color: var(--accent-color);
}

.collection-items-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}

.collection-item-row {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 8px 12px;
    gap: 10px;
    justify-content: space-between;
    transition: background 0.2s;
}

.collection-item-row.completed-item {
    border-right: 4px solid var(--completed-color);
}

.collection-item-row.active-item {
    border-right: 4px solid var(--accent-color);
}

.collection-item-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    cursor: pointer;
    text-align: right;
}

.collection-item-thumb {
    width: 44px;
    height: 44px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.collection-item-thumb img {
    width: 38px;
    height: 38px;
    object-fit: contain;
}

.collection-item-thumb i {
    font-size: 1.5rem;
    color: var(--accent-color);
}

.collection-item-details {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.collection-item-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: #fff;
}

.collection-item-status {
    font-size: 0.72rem;
    color: #a0a8b0;
}

.collection-item-status.status-gold {
    color: #f1c40f;
    font-weight: 500;
}

.collection-item-status.status-green {
    color: #2ecc71;
}

.collection-restore-btn {
    background: rgba(46, 204, 113, 0.15);
    border: 1px solid rgba(46, 204, 113, 0.4);
    color: #2ecc71;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
    transition: all 0.2s;
    font-family: inherit;
}

.collection-restore-btn:active {
    transform: scale(0.95);
    background: rgba(46, 204, 113, 0.3);
}

.collection-on-board-tag {
    font-size: 0.72rem;
    color: #81c784;
    background: rgba(129, 199, 132, 0.1);
    padding: 4px 8px;
    border-radius: 6px;
    white-space: nowrap;
    border: 1px solid rgba(129, 199, 132, 0.2);
}