:root {
    /* Color Palette - Premium Dark Theme */
    --bg-color: #0f172a;
    --bg-surface: rgba(30, 41, 59, 0.7);
    --bg-surface-hover: rgba(51, 65, 85, 0.8);
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border-color: rgba(255, 255, 255, 0.1);
    --glass-border: rgba(255, 255, 255, 0.05);
    --danger: #ef4444;
    --danger-hover: #dc2626;
    
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-full: 9999px;
    
    --shadow-glass: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    
    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    
    --main-padding-x: 5%;

    /* Set precisely from JS (navbar height), used for full-height views */
    --navbar-h: 64px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-color);
    background-image: 
        radial-gradient(at 0% 0%, hsla(253,16%,7%,1) 0, transparent 50%), 
        radial-gradient(at 50% 0%, hsla(225,39%,30%,0.2) 0, transparent 50%), 
        radial-gradient(at 100% 0%, hsla(339,49%,30%,0.2) 0, transparent 50%);
    background-attachment: fixed;
    color: var(--text-main);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Typography */
h1, h2, h3, h4 {
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.02em;
}

/* Glassmorphism Classes */
.glass {
    background: var(--bg-surface);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-top: 1px solid rgba(255,255,255,0.1);
    border-left: 1px solid rgba(255,255,255,0.1);
    box-shadow: var(--shadow-glass);
}

/* Header */
.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.85rem 5%;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
    gap: 0.75rem;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, #818cf8 0%, #c084fc 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
    user-select: none;
}

.logo i {
    -webkit-text-fill-color: initial;
    color: #818cf8;
}

.logo-mark {
    width: 30px;
    height: 30px;
    display: block;
    border-radius: 7px;
    flex-shrink: 0;
}

.user-actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
    flex-shrink: 1;
    justify-content: flex-end;
}

.header-user-profile {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.4rem 0.85rem;
    background: rgba(30, 41, 59, 0.7);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    color: var(--text-main);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition-fast);
    min-width: 0;
    max-width: 200px;
}

.header-user-profile:hover {
    background: var(--bg-surface-hover);
    border-color: var(--primary);
    color: #ffffff;
}

.header-user-profile i {
    color: var(--primary);
    font-size: 1rem;
    flex-shrink: 0;
}

.header-user-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-full);
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all var(--transition-normal);
    border: none;
    outline: none;
}

.btn:active {
    transform: scale(0.96);
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
    transform: translateY(-2px);
}

.btn-secondary {
    background: var(--bg-surface);
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-surface-hover);
}

.btn-danger {
    background: #ef4444;
    color: white;
    font-weight: 600;
}

.btn-danger:hover {
    background: #dc2626;
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.4);
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border-radius: 50%;
    width: 38px;
    height: 38px;
}

.btn i, .btn-icon i {
    position: static !important;
    transform: none !important;
}

.btn-block {
    width: 100%;
}

/* Layout */
main {
    padding: 2rem var(--main-padding-x);
    max-width: 1200px;
    margin: 0 auto;
}

/* Cards */
.card {
    background: var(--bg-surface);
    backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-glass);
}

/* Login View */
.login-card {
    max-width: 400px;
    margin: 4rem auto;
    text-align: center;
}

.login-card h2 {
    margin-bottom: 0.5rem;
}

.login-card p {
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.landing-page {
    min-height: calc(100vh - 150px);
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(390px, 0.9fr);
    align-items: center;
    gap: clamp(2rem, 6vw, 5.5rem);
    padding-top: 2.5rem;
    padding-bottom: 4rem;
}

.landing-copy {
    max-width: 570px;
    animation: landingRise 0.65s ease both;
}

.landing-eyebrow {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    color: #c3d66b;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
}

.landing-eyebrow span {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #c3d66b;
    box-shadow: 0 0 16px rgba(195, 214, 107, 0.55);
}

.landing-copy h1 {
    margin-top: 1.25rem;
    font-size: 4rem;
    line-height: 1.04;
    letter-spacing: 0;
}

.landing-copy h1 em {
    color: #f2a47c;
    font-family: Georgia, 'Times New Roman', serif;
    font-weight: 400;
}

.landing-description {
    max-width: 450px;
    margin-top: 1.35rem;
    color: #b4bfcc;
    font-size: 1.05rem;
    line-height: 1.75;
}

.landing-cta {
    min-height: 52px;
    margin-top: 1.8rem;
    padding: 0.85rem 1.35rem;
    border-radius: 6px;
    background: #c3d66b;
    color: #17202b;
    font-size: 0.95rem;
}

.landing-cta:hover {
    background: #d2e77a;
    transform: translateY(-2px);
}

.landing-cta i {
    transition: transform var(--transition-fast);
}

.landing-cta:hover i {
    transform: translateX(3px);
}

.landing-login-button {
    border-radius: 6px;
    padding: 0.55rem 1rem;
}

.landing-categories {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    margin-top: 2.2rem;
}

.landing-categories span {
    padding: 0.3rem 0.65rem;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 4px;
    color: #b4bfcc;
    font-size: 0.75rem;
}

.landing-art {
    padding: 1.35rem;
    border: 1px solid rgba(255, 255, 255, 0.13);
    border-radius: 8px;
    background: linear-gradient(145deg, rgba(39, 52, 64, 0.94), rgba(24, 33, 43, 0.98));
    box-shadow: 0 28px 70px rgba(0, 0, 0, 0.28);
    transform: rotate(1.5deg);
    animation: landingRise 0.75s 0.12s ease both;
}

.landing-art-heading,
.landing-art-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    color: #dce2e8;
    font-size: 0.72rem;
    font-weight: 700;
}

.landing-art-heading i,
.landing-art-footer i {
    margin-right: 0.35rem;
    color: #c3d66b;
}

.landing-art-count,
.landing-art-footer > span:last-child {
    color: #8794a1;
    font-size: 0.65rem;
    font-weight: 500;
}

.landing-rank-list {
    display: grid;
    gap: 0.6rem;
    margin: 1.15rem 0;
}

.landing-rank {
    display: grid;
    grid-template-columns: 28px 48px minmax(0, 1fr) 18px;
    align-items: center;
    gap: 0.8rem;
    min-height: 66px;
    padding: 0.5rem 0.7rem;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 5px;
    background: rgba(8, 14, 19, 0.43);
}

.landing-rank > b {
    color: #9aa7b3;
    font-size: 0.75rem;
}

.rank-art {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    border-radius: 3px;
    color: rgba(18, 24, 28, 0.85);
    font-size: 1.2rem;
}

.rank-coral .rank-art { background: #f2a47c; }
.rank-blue .rank-art { background: #77b7bd; }
.rank-yellow .rank-art { background: #e7c96f; }
.rank-green .rank-art { background: #91b996; }
.rank-violet .rank-art { background: #b29bc3; }

.rank-title {
    overflow: hidden;
    color: #e8edf1;
    font-size: 0.88rem;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.landing-rank > i {
    color: #71808d;
    font-size: 0.8rem;
}

.landing-art-footer {
    padding-top: 0.9rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.login-modal .login-card {
    margin: 0;
    padding: 1.75rem;
    text-align: left;
}

.login-modal .modal-header {
    margin-bottom: 1.25rem;
}

.login-modal-mark {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
}

.login-modal-mark img {
    width: 44px;
    height: 44px;
    display: block;
}

.login-modal .login-card h2 {
    font-size: 1.5rem;
}

.login-modal .login-card p {
    margin-bottom: 1.5rem;
}

/* Google Sign-In Styles */
.google-login-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    margin-bottom: 0.75rem;
}

.google-button-render {
    display: flex;
    justify-content: center;
    width: 100%;
}

.google-button-render > div {
    margin: 0 auto !important;
}

.btn-google {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    padding: 0.8rem 1.25rem;
    background-color: #ffffff;
    color: #1f2937;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    font-weight: 500;
    letter-spacing: 0.01em;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2), 0 1px 2px rgba(0, 0, 0, 0.1);
    transition: background-color var(--transition-fast), box-shadow var(--transition-fast), transform var(--transition-fast);
}

.btn-google:hover {
    background-color: #f8fafc;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
    transform: translateY(-1px);
}

.btn-google:active {
    background-color: #f1f5f9;
    transform: translateY(0);
}

.btn-google .google-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.google-login-caption {
    margin-top: 0.65rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
}

@keyframes landingRise {
    from { opacity: 0; transform: translateY(14px); }
    to { opacity: 1; transform: translateY(0); }
}

.divider {
    display: flex;
    align-items: center;
    text-align: center;
    margin: 1.5rem 0;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.divider::before, .divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid var(--border-color);
}

.divider span {
    padding: 0 1rem;
}

.auth-switch {
    margin-top: 1rem;
    text-align: center;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.auth-switch a {
    color: var(--primary);
    font-weight: 600;
}

.auth-switch-secondary {
    margin-top: 0.35rem;
    font-size: 0.82rem;
}

/* Remember me */
.remember-row {
    display: flex;
    align-items: center;
    margin-bottom: 1.1rem;
}

.remember-label {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    font-size: 0.875rem;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}

.remember-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: var(--primary);
    cursor: pointer;
}

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

/* Local captcha (account creation) */
.captcha-row {
    display: flex;
    align-items: stretch;
    gap: 0.6rem;
    margin-bottom: 0.4rem;
}

.captcha-row input {
    flex: 1;
    min-width: 0;
    padding: 0.85rem 1rem;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-main);
    font-family: inherit;
    font-size: 1rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    transition: var(--transition-fast);
}

.captcha-row input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.captcha-row img {
    width: 150px;
    min-height: 46px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: #f1f5f9;
    cursor: pointer;
}

.captcha-hint {
    display: block;
    color: var(--text-muted);
    font-size: 0.78rem;
    margin-bottom: 1.1rem;
}

@media (max-width: 420px) {
    .captcha-row {
        flex-direction: column;
    }

    .captcha-row img {
        width: 100%;
    }
}

/* Inputs */
.input-group {
    position: relative;
    margin-bottom: 1rem;
    text-align: left;
}

.input-group > i {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.input-group input, .input-group select {
    width: 100%;
    padding: 1rem 1rem 1rem 2.8rem;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-main);
    font-family: inherit;
    font-size: 1rem;
    transition: var(--transition-fast);
}

.input-group input:focus, .input-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.input-group select {
    padding-left: 1rem;
}

/* Dashboard Grids List */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    gap: 1rem;
}

.dashboard-header h2 {
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--text-main);
}

.grids-list {
    display: flex;
    flex-direction: column;
    gap: 3rem;
}

/* Grid Row (No box, seamless with body background, no border) */
.grid-row-card {
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 0;
    cursor: pointer;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    transition: opacity var(--transition-fast);
}

.grid-row-card:hover {
    background: transparent;
    border: none;
    transform: none;
    box-shadow: none;
}

/* Grid Row Header: Title & Arrow */
.grid-row-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    gap: 1rem;
}

.grid-row-title-wrap {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.grid-row-drag-handle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    border-radius: var(--radius-md);
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    cursor: grab;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    transition: var(--transition-fast);
}

.grid-row-drag-handle:hover {
    color: var(--text-main);
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.15);
}

.grid-row-drag-handle:active {
    cursor: grabbing;
}

.grid-row-card.dragging {
    opacity: 0.55;
    border-style: dashed;
}

.grid-row-title {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.01em;
}

.grid-category-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    font-size: 1.15rem;
    opacity: 0.85;
    transition: opacity var(--transition-fast), color var(--transition-fast), transform var(--transition-fast);
    flex-shrink: 0;
    margin-right: 0.15rem;
}

.grid-row-card:hover .grid-category-icon {
    opacity: 1;
    color: #a5b4fc;
    transform: scale(1.1);
}

/* Backward compatibility if referenced */
.grid-row-badge {
    display: none;
}

.grid-row-arrow-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 1.25rem;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    padding: 0.25rem 0.5rem;
    margin-left: auto;
    flex-shrink: 0;
}

.grid-row-card:hover .grid-row-arrow-btn {
    color: var(--primary);
    transform: translateX(5px);
}

/* First Item Thumbnails Row */
.grid-thumbnails-row {
    display: flex;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 1.15rem;
    width: 100%;
    scrollbar-width: none;
    -ms-overflow-style: none;
    padding-bottom: 0.35rem;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

.grid-thumbnails-row::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}

.grid-thumb-item {
    position: relative;
    border-radius: var(--radius-md);
    overflow: hidden;
    aspect-ratio: 2/3;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
    transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.2s ease, border-color 0.2s ease;
    flex: 0 0 calc((100% - 4.6rem) / 5);
    min-width: 130px;
    user-select: none;
}

.grid-thumb-item[draggable="true"] {
    cursor: grab;
}

.grid-thumb-item[draggable="true"]:active {
    cursor: grabbing;
}

.grid-thumb-item.dragging {
    opacity: 0.35 !important;
    transform: scale(0.92) !important;
    border-color: var(--primary) !important;
    box-shadow: 0 0 0 2px var(--primary) !important;
}

.grid-thumb-item.drag-over-before {
    border-left: 4px solid var(--primary) !important;
    box-shadow: -6px 0 16px rgba(99, 102, 241, 0.6) !important;
    transform: translateX(6px) scale(1.02);
}

.grid-thumb-item.drag-over-after {
    border-right: 4px solid var(--primary) !important;
    box-shadow: 6px 0 16px rgba(99, 102, 241, 0.6) !important;
    transform: translateX(-6px) scale(1.02);
}

.grid-thumb-drag-handle {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 24px;
    height: 24px;
    border-radius: var(--radius-full);
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(4px);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    opacity: 0;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 4;
    pointer-events: none;
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.grid-thumb-item:hover .grid-thumb-drag-handle {
    opacity: 1;
    transform: scale(1.05);
}

.grid-thumb-item:hover {
    transform: translateY(-4px) scale(1.03);
    border-color: rgba(255, 255, 255, 0.3);
    box-shadow: 0 10px 22px rgba(0, 0, 0, 0.55);
    z-index: 2;
}

.grid-thumb-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.grid-thumb-rank {
    position: absolute;
    top: 6px;
    left: 6px;
    min-width: 24px;
    height: 24px;
    padding: 0 0.4rem;
    border-radius: var(--radius-full);
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #ffffff;
    font-size: 0.75rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3;
}

.grid-thumb-item:nth-child(1) .grid-thumb-rank {
    background: linear-gradient(135deg, #fbbf24 0%, #d97706 100%);
    color: #000000;
    border-color: rgba(255, 255, 255, 0.4);
}

.grid-thumb-info {
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.9) 0%, rgba(0, 0, 0, 0.2) 45%, transparent 100%);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 0.65rem;
    pointer-events: none;
}

.grid-thumb-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: #ffffff;
    line-height: 1.25;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* Empty or unpopulated grid message */
.grid-row-empty {
    padding: 2.25rem 1.5rem;
    text-align: center;
    color: var(--text-muted);
    background: transparent;
    border-radius: var(--radius-md);
    border: 1px dashed rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    font-size: 0.9rem;
}

.grid-row-empty i {
    color: var(--primary);
    font-size: 1.1rem;
}

/* Grid View */
.grid-header-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2rem;
}

.search-section {
    position: relative;
    margin-bottom: 2rem;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-surface);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-top: 0.5rem;
    z-index: 50;
    max-height: 300px;
    overflow-y: auto;
    box-shadow: var(--shadow-glass);
}

.search-result-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--glass-border);
    transition: var(--transition-fast);
}

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

.search-result-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.search-result-img {
    width: 40px;
    height: 60px;
    object-fit: cover;
    border-radius: 4px;
}

/* Sortable List (Now a Grid of Cards) */
.grid-items-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1.5rem;
    max-width: 100%;
}

/* Grid Header Actions */
.grid-header-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2rem;
    gap: 1rem;
}

.grid-title-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.65rem;
    min-width: 0;
}

.current-grid-title {
    font-size: 1.6rem;
    font-weight: 700;
    margin: 0;
    text-align: center;
    letter-spacing: -0.01em;
}

.current-grid-title.editable {
    cursor: pointer;
    transition: color var(--transition-fast);
    border-radius: var(--radius-md);
    padding: 0.2rem 0.6rem;
}

.current-grid-title.editable:hover {
    color: #a5b4fc;
    background: rgba(99, 102, 241, 0.1);
}

.btn-icon.btn-sm {
    width: 34px;
    height: 34px;
    padding: 0;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.btn-grid-card-edit {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.btn-grid-card-edit:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: #ffffff;
    transform: scale(1.1);
}

.btn-grid-card-share {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.btn-grid-card-share:hover {
    background: #0284c7;
    border-color: #0284c7;
    color: #ffffff;
    transform: scale(1.1);
}

.btn-grid-card-delete {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.btn-grid-card-delete:hover {
    background: #ef4444;
    border-color: #ef4444;
    color: #ffffff;
    transform: scale(1.1);
}

.share-url-box {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.share-input {
    flex: 1;
    background: rgba(15, 23, 42, 0.7);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.65rem 0.85rem;
    color: var(--text-main);
    font-size: 0.875rem;
    font-family: monospace;
    outline: none;
    cursor: pointer;
    min-width: 0;
}

.share-input:focus {
    border-color: var(--primary);
}

.grid-item {
    position: relative;
    border-radius: 14px;
    overflow: hidden;
    aspect-ratio: 2/3;
    cursor: pointer;
    transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.25s ease, border-color 0.25s ease;
    background: var(--bg-surface);
    padding: 0;
    border: 2px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}

.grid-item:hover {
    transform: translateY(-4px);
    box-shadow: 0 14px 28px rgba(0, 0, 0, 0.5);
    border-color: rgba(255, 255, 255, 0.25);
}

.grid-item.selected {
    border-color: #ef4444;
    transform: scale(0.96);
}

.grid-item.selected::after {
    content: '\f058';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    position: absolute;
    top: 10px;
    right: 10px;
    color: #ef4444;
    font-size: 1.5rem;
    z-index: 10;
    background: white;
    border-radius: 50%;
    line-height: 1;
}

.grid-item[draggable="true"] {
    cursor: grab;
    user-select: none;
}

.grid-item[draggable="true"]:active {
    cursor: grabbing;
}

.grid-item.dragging {
    opacity: 0.35 !important;
    transform: scale(0.95) !important;
    border-color: var(--primary) !important;
    box-shadow: 0 0 0 2px var(--primary), 0 12px 28px rgba(0, 0, 0, 0.6) !important;
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.grid-item.drag-over-before {
    border-left: 4px solid var(--primary) !important;
    box-shadow: -6px 0 20px rgba(99, 102, 241, 0.6) !important;
    transform: translateX(6px);
}

.grid-item.drag-over-after {
    border-right: 4px solid var(--primary) !important;
    box-shadow: 6px 0 20px rgba(99, 102, 241, 0.6) !important;
    transform: translateX(-6px);
}

.item-drag-handle {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(4px);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    opacity: 0;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 5;
    pointer-events: none;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.grid-item:hover .item-drag-handle {
    opacity: 1;
    transform: scale(1.05);
}

.touch-drag-clone {
    position: fixed !important;
    pointer-events: none !important;
    z-index: 99999 !important;
    opacity: 0.9 !important;
    transform: scale(1.05) rotate(2deg) !important;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.7), 0 0 0 2px var(--primary) !important;
    transition: none !important;
    border-radius: 12px !important;
    overflow: hidden !important;
}

.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #ffffff;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-md);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.9rem;
    font-weight: 600;
    opacity: 0;
    pointer-events: none;
    transform: translateY(12px);
    transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
    z-index: 9999;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.item-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.item-rank {
    position: absolute;
    top: 8px;
    left: 8px;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(4px);
    color: #ffffff;
    min-width: 26px;
    height: 26px;
    padding: 0 0.45rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    font-size: 0.8rem;
    font-weight: 800;
    z-index: 5;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
}

.item-rank.rank-1,
.grid-item:nth-child(1) .item-rank {
    background: linear-gradient(135deg, #fbbf24 0%, #d97706 100%);
    color: #000000;
    border-color: rgba(255, 255, 255, 0.4);
}

.item-info {
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.92) 0%, rgba(0,0,0,0.3) 45%, transparent 100%);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 1.15rem;
    pointer-events: none;
}

.item-rank-sub {
    font-size: 0.725rem;
    font-weight: 700;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.2rem;
}

.item-title {
    font-size: 1.05rem;
    font-weight: 700;
    line-height: 1.3;
}

.playbook-empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 3rem 1.5rem;
    background: rgba(30, 41, 59, 0.3);
    border: 1px dashed rgba(255, 255, 255, 0.12);
    border-radius: 16px;
}

.playbook-empty-icon {
    font-size: 2.5rem;
    color: var(--text-muted);
    opacity: 0.45;
    margin-bottom: 0.75rem;
}

.playbook-empty-state h3 {
    font-size: 1.25rem;
    margin-bottom: 0.4rem;
}

.playbook-empty-state p {
    color: var(--text-muted);
    font-size: 0.9rem;
    max-width: 420px;
    margin: 0 auto;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    width: 100%;
    max-width: 450px;
    animation: modalIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.btn-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    transition: var(--transition-fast);
}

.btn-close:hover {
    color: var(--text-main);
}

/* Clean Profile Popup */
.profile-popup-box {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.profile-username-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.profile-username-display {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.01em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.profile-actions-inline {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    flex-shrink: 0;
}

.profile-url-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.45rem 0.65rem 0.45rem 0.85rem;
}

.profile-url-text {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.btn.btn-sm {
    padding: 0.45rem 0.9rem;
    font-size: 0.82rem;
    gap: 0.35rem;
}

/* Profile picture */
.header-user-avatar {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.profile-avatar-row {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding-bottom: 0.85rem;
    border-bottom: 1px solid var(--border-color);
}

.profile-avatar-wrap {
    position: relative;
    width: 64px;
    height: 64px;
    flex-shrink: 0;
    border-radius: 50%;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    color: var(--text-muted);
    font-size: 1.6rem;
}

.profile-avatar-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.profile-avatar-btn {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    padding: 0.3rem 0;
    border: none;
    background: rgba(2, 6, 23, 0.7);
    color: #fff;
    font-size: 0.75rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.profile-avatar-wrap:hover .profile-avatar-btn,
.profile-avatar-btn:focus {
    opacity: 1;
}

.profile-avatar-meta {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    min-width: 0;
}

.profile-avatar-label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.profile-avatar-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.public-profile-avatar {
    width: 100px;
    height: 100px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    margin: 0 auto 1rem auto;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    color: var(--text-muted);
    overflow: hidden;
}

.public-profile-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.public-profile-cta {
    margin-top: auto;
    align-self: center;
    width: 100%;
    max-width: 560px;
    padding: 1.75rem 1.5rem;
    text-align: center;
    background: var(--bg-surface);
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-lg);
}

.public-profile-cta p {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-bottom: 1rem;
}

#view-public-profile {
    flex-direction: column;
    gap: 1.5rem;
    min-height: calc(100vh - var(--navbar-h) - 4rem);
}

/* Modal Share Profile Card & Elements */
.modal-share-profile-card {
    background: rgba(15, 23, 42, 0.55);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.15rem;
    margin-bottom: 0.5rem;
}

.modal-share-profile-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.modal-share-profile-header h4 {
    margin: 0;
    font-size: 0.95rem;
    color: var(--text-main);
    display: flex;
    align-items: center;
    font-weight: 600;
}

.share-badge {
    font-size: 0.72rem;
    font-weight: 600;
    background: rgba(99, 102, 241, 0.18);
    border: 1px solid rgba(99, 102, 241, 0.35);
    color: #a5b4fc;
    padding: 0.15rem 0.55rem;
    border-radius: var(--radius-full);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.modal-divider {
    display: flex;
    align-items: center;
    text-align: center;
    margin: 1.25rem 0 1rem 0;
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
}

.modal-divider::before,
.modal-divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid var(--border-color);
}

.modal-divider span {
    padding: 0 0.75rem;
}

/* Loader */
.loader-container {
    position: fixed;
    inset: 0;
    background: var(--bg-color);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loader {
    width: 48px;
    height: 48px;
    border: 5px solid rgba(255,255,255,0.1);
    border-bottom-color: var(--primary);
    border-radius: 50%;
    display: inline-block;
    box-sizing: border-box;
    animation: rotation 1s linear infinite;
}

@keyframes rotation {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Utilities */
.message {
    margin-top: 1rem;
    font-size: 0.9rem;
}
.message.error { color: #ef4444; }
.message.success { color: #10b981; }

/* Responsive */
@media (max-width: 768px) {
    .navbar {
        padding: 0.75rem 1rem;
        gap: 0.5rem;
    }

    .logo {
        font-size: 1.25rem;
        gap: 0.4rem;
    }

    .logo i {
        font-size: 1.15rem;
    }

    .user-actions {
        gap: 0.4rem;
    }

    .header-user-profile {
        padding: 0.35rem 0.65rem;
        font-size: 0.8rem;
        max-width: 130px;
    }

    .header-user-profile i {
        font-size: 0.9rem;
    }

    .btn-icon {
        width: 36px;
        height: 36px;
        padding: 0.45rem;
        font-size: 0.85rem;
    }

    .dashboard-header {
        margin-bottom: 1.25rem;
    }

    .dashboard-header h2 {
        font-size: 1.35rem;
    }

    .dashboard-header .btn {
        padding: 0.5rem 1rem;
        font-size: 0.875rem;
    }

    .landing-page {
        min-height: auto;
        grid-template-columns: minmax(0, 1fr);
        gap: 2.5rem;
        padding-top: 3rem;
    }

    .landing-copy h1 {
        font-size: 3.3rem;
    }

    .landing-art {
        width: 100%;
        max-width: 560px;
        margin: 0 auto;
        transform: none;
    }

    .grid-header-actions {
        gap: 0.5rem;
        margin-bottom: 1.25rem;
    }

    .grid-row-card {
        padding: 0;
        width: 100%;
    }

    .grid-row-title {
        font-size: 1.15rem;
    }

    .grid-thumbnails-row {
        display: flex;
        overflow-x: auto;
        overflow-y: hidden;
        gap: 0.85rem;
        /* Remove scrollbar under items */
        scrollbar-width: none;
        -ms-overflow-style: none;
        /* Spans 100% width across parent padding to prevent cutoff during scroll */
        margin-left: calc(-1 * var(--main-padding-x));
        margin-right: calc(-1 * var(--main-padding-x));
        padding-left: var(--main-padding-x);
        padding-right: var(--main-padding-x);
        padding-bottom: 0.5rem;
        padding-top: 0.25rem;
        width: calc(100% + (2 * var(--main-padding-x)));
        box-sizing: border-box;
        scroll-behavior: smooth;
        -webkit-overflow-scrolling: touch;
    }

    .grid-thumbnails-row::-webkit-scrollbar {
        display: none;
        width: 0;
        height: 0;
    }

    .grid-thumb-item {
        width: 115px;
        min-width: 115px;
        flex-shrink: 0;
    }

    .grid-items-container {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 1rem;
    }

    #current-grid-title {
        font-size: 1.15rem;
        padding: 0 0.25rem;
        line-height: 1.3;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .item-actions {
        opacity: 1;
    }
}

@media (max-width: 480px) {
    .navbar {
        padding: 0.65rem 0.75rem;
    }

    .logo {
        font-size: 1.1rem;
    }

    .header-user-profile {
        max-width: 95px;
        padding: 0.3rem 0.5rem;
    }

    .header-user-label {
        font-size: 0.75rem;
    }

    .landing-page {
        gap: 2rem;
        padding-top: 2.25rem;
        padding-bottom: 2rem;
    }

    .landing-copy h1 {
        font-size: 2.6rem;
    }

    .landing-description {
        font-size: 0.95rem;
    }

    .landing-art {
        padding: 0.85rem;
    }

    .landing-rank {
        grid-template-columns: 22px 42px minmax(0, 1fr) 14px;
        gap: 0.55rem;
        min-height: 58px;
        padding: 0.4rem 0.5rem;
    }

    .rank-art {
        width: 42px;
        height: 42px;
    }

    .rank-title {
        font-size: 0.78rem;
    }

    .landing-art-footer > span:last-child {
        text-align: right;
    }

    .btn-icon {
        width: 34px;
        height: 34px;
        padding: 0.4rem;
    }

    .grid-thumb-item {
        width: 95px;
        min-width: 95px;
    }

    .grid-items-container {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }
}
