:root {
    --primary: #4facfe;
    --primary-dark: #00f2fe;
    --bg-gradient: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    --card-bg: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border-soft: #e2e8f0;
    --profile-accent-1: #4facfe;
    --profile-accent-2: #00f2fe;
    --profile-accent-gradient: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: #f8fafc;
    min-height: 100vh;
    color: var(--text-main);
    line-height: 1.5;
}

.profile-page.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 48px 24px 80px;
}

/* --- Header --------------------------------------------------------------- */

.profile-header-v2 {
    display: flex;
    gap: 28px;
    align-items: flex-start;
    margin-bottom: 36px;
}

.profile-avatar-wrap {
    position: relative;
    flex: 0 0 auto;
}

.profile-avatar-v2 {
    width: 120px;
    height: 120px;
    border-radius: 24px;
    object-fit: cover;
    display: block;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
}

.profile-avatar-badge {
    position: absolute;
    right: -4px;
    bottom: -4px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--profile-accent-1);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 3px solid var(--card-bg);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.profile-header-info {
    flex: 1 1 auto;
    min-width: 0;
    padding-top: 4px;
}

.profile-name {
    font-size: 40px;
    font-weight: 800;
    line-height: 1.1;
    color: var(--text-main);
    margin-bottom: 12px;
}

.profile-bio {
    font-size: 16px;
    color: var(--text-muted);
    margin-bottom: 20px;
    max-width: 640px;
    line-height: 1.55;
}

.profile-bio-empty {
    color: var(--text-muted);
    font-style: italic;
    opacity: 0.7;
}

.profile-stats {
    display: flex;
    gap: 32px;
    align-items: flex-start;
    flex-wrap: wrap;
}

.profile-stat-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1;
}

.profile-stat-label {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* --- Filter bar ----------------------------------------------------------- */

.profile-filter-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    background: #f1f5f9;
    border: 1px solid var(--border-soft);
    border-radius: 14px;
    margin-bottom: 28px;
    flex-wrap: wrap;
}

.profile-search-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1 1 260px;
    min-width: 200px;
    padding: 8px 14px;
    background: rgba(255, 255, 255, 0.75);
    border-radius: 999px;
    color: var(--text-muted);
}

.profile-search-wrap input {
    flex: 1;
    min-width: 0;
    border: none;
    background: transparent;
    outline: none;
    font-size: 14px;
    color: var(--text-main);
    font-family: inherit;
}

.profile-search-wrap input::placeholder {
    color: var(--text-muted);
}

.profile-filter-pills {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.profile-filter-pill {
    padding: 8px 16px;
    border-radius: 999px;
    border: 1px solid var(--border-soft);
    background: transparent;
    color: var(--text-main);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    font-family: inherit;
}

.profile-filter-pill:hover {
    background: rgba(255, 255, 255, 0.6);
}

.profile-filter-pill.is-active {
    background: rgba(79, 172, 254, 0.15);
    border-color: var(--profile-accent-1);
    color: var(--profile-accent-1);
}

/* --- Pages bar ------------------------------------------------------------ */

.profile-pages-bar {
    display: flex;
    align-items: center;
    gap: 14px;
    margin: -12px 0 24px;
    padding: 4px 4px 4px 4px;
    flex-wrap: wrap;
}

.profile-pages-label {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    flex-shrink: 0;
}

.profile-pages-list {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.profile-page-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid var(--border-soft);
    border-radius: 999px;
    color: var(--text-main);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.profile-page-link:hover {
    background: #fff;
    border-color: var(--profile-accent-1);
    color: var(--profile-accent-1);
    transform: translateY(-1px);
}

.profile-page-link.is-playlist {
    background: rgba(15, 23, 42, 0.9);
    color: #fff;
    border-color: rgba(15, 23, 42, 0.9);
}

.profile-page-link.is-playlist:hover {
    background: #0f172a;
    color: #fff;
    border-color: #0f172a;
}

.profile-page-icon {
    font-size: 14px;
    line-height: 1;
}

.profile-page-link.is-draft {
    border-style: dashed;
    opacity: 0.85;
}

/* Owner-only pill wrapper — holds the Collection link + the rename button
   so the anchor stays a valid <a> without nested interactive content. */
.profile-collection-group {
    display: inline-flex;
    align-items: stretch;
    gap: 0;
}
.profile-collection-group .profile-page-link {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    border-right-width: 0;
}
.profile-collection-edit {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 10px;
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-left: 1px solid rgba(0, 0, 0, 0.08);
    border-top-right-radius: 999px;
    border-bottom-right-radius: 999px;
    background: rgba(255, 255, 255, 0.75);
    color: #334155;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}
.profile-collection-edit:hover {
    background: #fff;
    color: var(--profile-accent-1);
}
.profile-collection-group:has(.is-playlist) .profile-collection-edit {
    background: rgba(15, 23, 42, 0.9);
    border-color: rgba(15, 23, 42, 0.9);
    color: #fff;
}
.profile-collection-group:has(.is-playlist) .profile-collection-edit:hover {
    background: #0f172a;
}

.profile-page-draft-tag {
    margin-left: 4px;
    padding: 1px 8px;
    border-radius: 999px;
    background: #fef3c7;
    color: #92400e;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
}

/* --- Tag cloud ------------------------------------------------------------ */

.profile-tag-cloud {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    margin: 0 0 28px;
    flex-wrap: wrap;
}

.profile-tag-cloud-list {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.profile-tag-cloud-item {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    padding: 5px 12px;
    background: #ffffff;
    border: 1px solid var(--border-soft);
    border-radius: 999px;
    color: var(--text-main);
    cursor: pointer;
    font-family: inherit;
    font-weight: 500;
    line-height: 1.3;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.profile-tag-cloud-item:hover {
    transform: translateY(-1px);
    background: #fff;
    border-color: var(--profile-accent-1);
    color: var(--profile-accent-1);
}

.profile-tag-cloud-item.is-active {
    background: var(--profile-accent-1);
    border-color: var(--profile-accent-1);
    color: #fff;
}

.profile-tag-cloud-item.is-active .profile-tag-cloud-count {
    color: rgba(255, 255, 255, 0.85);
}

.profile-tag-cloud-item.tier-1 { font-size: 11px; }
.profile-tag-cloud-item.tier-2 { font-size: 12px; }
.profile-tag-cloud-item.tier-3 { font-size: 14px; }
.profile-tag-cloud-item.tier-4 { font-size: 16px; }
.profile-tag-cloud-item.tier-5 { font-size: 18px; font-weight: 700; }

.profile-tag-cloud-count {
    font-size: 0.75em;
    font-weight: 600;
    color: var(--text-muted);
}

/* --- Card grid ------------------------------------------------------------ */

.profile-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 24px;
}

.profile-card-v2 {
    position: relative;
    display: flex;
    flex-direction: column;
    background: var(--card-bg);
    border-radius: 18px;
    overflow: hidden;
    border: 1px solid var(--border-soft);
    text-decoration: none;
    color: inherit;
    transition: transform 0.15s, box-shadow 0.15s;
}

.profile-card-v2:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
    border-color: #cbd5e1;
}

.profile-card-image {
    position: relative;
    aspect-ratio: 16 / 10;
    background: #f1f5f9;
    overflow: hidden;
}

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

.profile-card-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 800;
    font-size: 28px;
    letter-spacing: 1px;
}

.profile-card-group-badge {
    position: absolute;
    top: 12px;
    left: 12px;
    padding: 4px 10px;
    background: rgba(255, 255, 255, 0.92);
    color: var(--text-main);
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    text-transform: none;
    letter-spacing: 0.2px;
    backdrop-filter: blur(6px);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
    max-width: calc(100% - 24px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.profile-card-body {
    padding: 16px 18px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
}

.profile-card-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.profile-card-description {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.45;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.profile-card-tags {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 2px;
}

.profile-card-tag {
    padding: 3px 10px;
    background: rgba(79, 172, 254, 0.12);
    color: var(--profile-accent-1);
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
}

.profile-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: auto;
    padding-top: 8px;
    border-top: 1px solid var(--border-soft);
}

.profile-card-domain {
    font-size: 12px;
    color: var(--profile-accent-1);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 80%;
}

.profile-card-bookmark-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 6px;
    background: #f1f5f9;
    color: var(--text-muted);
    flex-shrink: 0;
}

/* --- Empty states / footer ----------------------------------------------- */

.profile-empty-state,
.profile-empty-results {
    padding: 48px 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 15px;
}

.profile-back-link {
    display: inline-block;
    margin-top: 36px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
}

.profile-back-link:hover {
    color: var(--profile-accent-1);
}

/* --- Owner-only hover controls -------------------------------------------- */

.owner-actions {
    display: flex;
    gap: 6px;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 2;
}

.profile-card-v2 .owner-actions {
    position: absolute;
    top: 10px;
    right: 10px;
}

.profile-card-v2:hover .owner-actions,
.profile-card-v2:focus-within .owner-actions {
    opacity: 1;
}

.owner-actions button,
.owner-actions a {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.1);
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    color: #334155;
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s;
}

.owner-actions button svg,
.owner-actions a svg { width: 14px; height: 14px; }

.owner-actions .goto-action { color: #059669; }
.owner-actions .goto-action:hover { background: #ecfdf5; border-color: #059669; }
.owner-actions .edit-action { color: #2563eb; }
.owner-actions .edit-action:hover { background: #eff6ff; border-color: #2563eb; }
.owner-actions .remove-action { color: #dc2626; }
.owner-actions .remove-action:hover { background: #fef2f2; border-color: #dc2626; }

/* --- Edit override modal -------------------------------------------------- */

.owner-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 16px;
}

.owner-modal-backdrop.active { display: flex; }

.owner-modal {
    background: #fff;
    border-radius: 12px;
    max-width: 480px;
    width: 100%;
    padding: 24px;
    color: #0f172a;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

.owner-modal h3 { margin: 0 0 8px; font-size: 18px; }
.owner-modal p.hint { margin: 0 0 16px; color: #64748b; font-size: 13px; }

.owner-modal label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: #475569;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.owner-modal input,
.owner-modal textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    margin-bottom: 12px;
    box-sizing: border-box;
}

.owner-modal textarea { min-height: 80px; resize: vertical; }
.owner-modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.owner-modal button { padding: 8px 16px; border-radius: 6px; border: none; cursor: pointer; font-size: 14px; font-weight: 600; }
.owner-modal .btn-cancel { background: #f1f5f9; color: #334155; }
.owner-modal .btn-save { background: #2563eb; color: #fff; }
.owner-modal .btn-save.owner-remove-btn { background: #dc2626; }
.owner-modal .btn-save.owner-remove-btn:hover { background: #b91c1c; }

/* --- Customize panel (owner-only) ---------------------------------------- */

.customize-launcher {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 900;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border: none;
    border-radius: 999px;
    background: #0f172a;
    color: #fff;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    font-family: inherit;
}

.customize-launcher:hover { background: #1e293b; }

.customize-panel {
    position: fixed;
    right: 20px;
    bottom: 74px;
    z-index: 901;
    width: 340px;
    max-width: calc(100vw - 40px);
    background: #fff;
    color: #0f172a;
    border-radius: 14px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.25);
    padding: 18px;
    display: none;
}

.customize-panel.active { display: block; }
.customize-panel h3 { margin: 0 0 12px; font-size: 16px; font-weight: 700; }

.customize-panel .customize-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.customize-panel .customize-row-bio {
    align-items: flex-start;
}

.customize-panel label {
    flex: 0 0 95px;
    font-size: 12px;
    font-weight: 600;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    padding-top: 6px;
}

.customize-panel input[type="color"] {
    width: 36px;
    height: 32px;
    padding: 0;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: transparent;
    cursor: pointer;
}

.customize-panel input[type="text"] {
    flex: 1;
    min-width: 0;
    padding: 6px 8px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 13px;
    font-family: monospace;
}

.customize-panel textarea {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
    resize: vertical;
    min-width: 0;
}

.customize-panel select {
    flex: 1;
    padding: 6px 8px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 13px;
}

.customize-panel .customize-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid #e2e8f0;
}

.customize-save-status {
    flex: 1;
    font-size: 12px;
    color: #64748b;
    font-weight: 500;
    min-height: 18px;
}

.customize-panel button.customize-btn {
    padding: 8px 14px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
}

.customize-panel .customize-close {
    margin-left: auto;
    margin-right: 0;
    background: transparent;
    border: none;
    color: #64748b;
    font-size: 18px;
    cursor: pointer;
    position: absolute;
    top: 10px;
    right: 10px;
}

.customize-btn-save { background: #2563eb; color: #fff; }
.customize-btn-cancel { background: #f1f5f9; color: #334155; }

/* --- Mobile --------------------------------------------------------------- */

@media (max-width: 640px) {
    .profile-header-v2 { flex-direction: column; align-items: flex-start; }
    .profile-avatar-v2 { width: 96px; height: 96px; }
    .profile-name { font-size: 32px; }
    .profile-filter-bar { flex-direction: column; align-items: stretch; }
    .profile-search-wrap { flex: initial; }
}
