/* Profile Page Styles */
.profile-header,
.library-header {
    margin-bottom: var(--spacing-xl);
    position: relative;
}

.profile-info {
    display: flex;
    flex-direction: column;
    gap: 0;
    text-align: left;
}

/* Profile name heading with edit button */
h1 {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.edit-name-btn {
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-sm);
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--color-text-muted);
    transition: all 0.2s ease;
    font-size: var(--font-size-md);
    flex-shrink: 0;
    text-decoration: none;
}

.edit-name-btn:hover {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
    transform: scale(1.05);
}

.profile-info h1 {
    margin-bottom: 0;
}

.profile-info h3 {
    font-family: var(--font-heading-normal);
    color: var(--color-text-lighter);
    font-size: var(--font-size-xl);
    margin-bottom: 0;
}

/* Profile stats after header */
.profile-stat {
    border-left: 2px solid var(--color-border);
    padding-left: var(--spacing-sm);
}

.profile-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--spacing-md);
    margin-top: var(--spacing-xl);
    margin-bottom: var(--spacing-2xl);
}

.stat-card {
    display: flex;
    align-items: center;
    flex-direction: row;
    gap: var(--spacing-md);
    padding: var(--spacing-sm);
    background: var(--color-background);
    border: none;
    border-radius: var(--border-radius-md);
    transition: transform var(--transition-base);
    text-align: left;
}

.stat-icon {
    width: 64px;
    height: 64px;
    border-radius: var(--border-radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

/* Stat icon monochromatic color schemes */
.stat-icon.stories {
    background-color: #E3F2FD;
    color: #1565C0;
}

.stat-icon.boon {
    background-color: #F3E5F5;
    color: #6A1B9A;
}

.stat-icon.streak {
    background-color: #FFF3E0;
    color: #E65100;
}

.stat-icon.reviews {
    background-color: #E8F5E9;
    color: #2E7D32;
}

.stat-content {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.stat-value {
    font-size: var(--font-size-2xl);
    font-weight: var(--font-weight-bold);
    color: var(--color-text);
    line-height: 1.1;
    margin-bottom: var(--spacing-xs);
}

.stat-label {
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-normal);
}

/* Stories section */
.workshop-card {
    padding-top: var(--spacing-lg);
}

.stories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    max-width: 100%;
    width: 100%;
    box-sizing: border-box;
    align-items: stretch;
    /* Ensure all cards have the same height */
}

.story-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    max-width: 100%;
    width: 100%;
    height: 100%;
    /* Fill grid cell height */
    box-sizing: border-box;
    justify-content: flex-start;
    /* Changed from space-between to allow margin-top: auto to work */
    gap: var(--spacing-md);
    padding: var(--spacing-md);
    border: 2px solid var(--color-border);
    border-radius: var(--border-radius-md);
    transition: transform var(--transition-base), border-color var(--transition-base);
    background: var(--color-background);
    text-decoration: none;
    color: inherit;
    position: relative;
    /* For absolute positioning of delete button */
}

.story-item:hover {
    transform: translateY(-2px);
    border-color: var(--color-primary);
}

.story-item.completed {
    border-color: var(--color-success);
}

.story-item.in_progress {
    border-color: var(--color-warning);
}

.story-item.draft {
    border-color: var(--color-border-dark);
}

.story-item.in-workshop {
    border-color: var(--color-info);
}

/* Publishing Package special styling */
.story-item.has-publishing-package.finished {
    border-color: var(--color-border-dark);
}

/* Finished story: use blue border */
.story-item.finished {
    border-color: var(--color-info);
}

.story-status-label.in_progress {
    color: var(--color-warning-dark);
}

.story-status-label.completed {
    color: var(--color-success-dark);
}

.story-status-label.draft {
    color: var(--color-text-muted, #6c757d);
    /* Secondary/muted color */
}

.story-status-label.finished {
    color: var(--color-info);
    /* Blue */
}

/* Finished stories without publishing package: use info color even if status-success class */
.story-item.finished:not(.has-publishing-package) .story-status-label.status-success {
    color: var(--color-info);
}

.story-status-label.status-success {
    color: var(--color-success-dark);
}

.story-status-label.status-warning {
    color: var(--color-warning-dark);
}

.story-status-label.status-info {
    color: var(--color-primary-dark);
}

.story-status-label.status-danger {
    color: var(--color-error, var(--color-danger));
}

.story-status-label.status-secondary {
    color: var(--color-text-muted, #6c757d);
}

.story-icon {
    width: 64px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--color-background-muted);
    font-size: var(--font-size-xl);
    margin-top: var(--spacing-lg);
}

.story-item.completed .story-icon {
    background: var(--color-success-light);
    color: var(--color-success);
}

.story-item.in_progress .story-icon {
    background: var(--color-warning);
    color: var(--color-warning-dark);
}

.story-item.draft .story-icon {
    background: var(--color-background-muted);
    color: var(--color-text-muted);
}

.story-item.in-workshop .story-icon {
    background: var(--color-error-light, rgba(220, 53, 69, 0.1));
    color: var(--color-error, var(--color-danger));
}

.story-item.finished .story-icon {
    background: var(--color-info-light);
    color: var(--color-info);
}

/* Publishing Package icon enhancement */
.story-item.has-publishing-package.finished .story-icon {
    background: var(--color-success);
    color: white;
}

.story-item.add-new-story {
    border: 2px solid var(--color-border);
    background: var(--color-surface-gradient-soft);
}


.story-item.add-new-story .story-icon {
    background: var(--color-primary-light);
    color: var(--color-primary);
}

.story-info {
    width: 100%;
}

.story-status {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
}

.story-info h4 {
    margin: 0 0 var(--spacing-sm) 0;
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-bold);
    color: var(--color-text);
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    min-height: calc(var(--font-size-xl) * 1.3 * 2);
    /* Ensure consistent height for 2 lines */
}

.story-preview {
    margin: 0 0 var(--spacing-sm) 0;
    font-size: var(--font-size-md);
    color: var(--color-text-light);
    line-height: 1.5;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    text-wrap: balance;
}

.story-date {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-normal);
    color: var(--color-text-muted);
    line-height: 1.4;
    margin-top: auto;
}

/* Delete button in top-right corner of story card */
.story-delete-btn {
    position: absolute;
    top: var(--spacing-sm);
    right: var(--spacing-sm);
    background: var(--color-background-light);
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: var(--spacing-xs);
    border-radius: var(--border-radius-sm);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    opacity: 0;
    /* Hidden by default */
    pointer-events: none;
    /* Disable clicks when hidden */
    z-index: 10;
    /* Ensure it's above other content */
}

.story-item:hover .story-delete-btn {
    opacity: 1;
    /* Show on card hover */
    pointer-events: auto;
    /* Enable clicks when visible */
}

.story-delete-btn:hover {
    background: var(--color-error-light);
    color: var(--color-error);
    transform: scale(1.1);
}

.story-delete-btn:active {
    transform: scale(0.95);
}

.story-delete-btn i {
    font-size: 0.875rem;
}

.story-actions {
    display: flex;
    gap: var(--spacing-sm);
    width: 100%;
    margin-top: auto;
    /* Push actions to bottom of card */
    align-items: flex-end;
    /* Align buttons/icons to bottom */
}

/* Make forms inside story-actions full width */
.story-actions form {
    display: block;
    width: 100%;
}

.story-actions .button {
    flex: 1 1 100%;
    width: 100%;
    box-sizing: border-box;
    justify-content: center;
    gap: var(--spacing-xs);
    align-self: flex-end;
}

/* Add new story item */
.story-item.add-new-story {
    border: 2px solid var(--color-border);
    background: var(--color-background-muted);
    transition: all var(--transition-base);
}

.story-item.add-new-story .story-icon {
    background: var(--color-primary-light);
    color: var(--color-primary);
}

/* Empty state */
.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px 20px;
    color: var(--color-text-muted);
}

.empty-icon {
    font-size: 48px;
    margin-bottom: var(--spacing-md);
    opacity: 0.5;
}

.empty-state h4 {
    margin: 0 0 8px 0;
    font-size: 18px;
    color: var(--color-text);
}

.empty-state p {
    margin: 0;
    font-size: 14px;
}

/* Writer Level Badge in Avatar/Protector Container */
#profile .profile-header .avatar,
#profile .library-header .avatar,
#library .library-header .avatar {
    margin-left: 40px;
}

#profile .profile-header .avatar-container,
#profile .profile-header .protector-container,
#profile .library-header .protector-container,
#library .library-header .protector-container {
    display: flex;
    align-items: flex-end;
    justify-content: flex-start;
    padding: 0;
    min-height: 208px;
    background: var(--color-surface-gradient-soft);
    border: 2px solid var(--color-border);
    position: relative;
}

#profile h1 {
    font-size: var(--font-size-3xl);
    margin-top: var(--spacing-xs);
    margin-bottom: var(--spacing-sm);
}

/* Bio Speech Bubble */
.bio-speech-bubble {
    position: relative;
    background: var(--color-background);
    padding: var(--spacing-lg) var(--spacing-xl);
    border-radius: var(--border-radius-lg);
    margin-top: var(--spacing-sm);
    margin-bottom: var(--spacing-sm);
    z-index: 10;
    border: 2px solid var(--color-border-dark);
}

/* Border triangle (outer) */
.bio-speech-bubble::before {
    content: '';
    position: absolute;
    bottom: -40px;
    left: 140px;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 40px 12px 0 12px;
    border-color: var(--color-border-dark) transparent transparent transparent;
}

/* Fill triangle (inner) */
.bio-speech-bubble::after {
    content: '';
    position: absolute;
    bottom: -34px;
    left: 140px;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 38px 11px 0 11px;
    border-color: var(--color-background) transparent transparent transparent;
    z-index: 1;
}

.bio-speech-bubble p {
    margin: 0;
    line-height: 1.6;
    font-size: var(--font-size-lg);
    color: var(--color-text);
}

.bio-speech-bubble.empty {
    background: var(--color-background-muted);
    border: 2px solid var(--color-border);
}

.bio-speech-bubble.empty::before {
    border-color: var(--color-border) transparent transparent transparent;
}

.bio-speech-bubble.empty::after {
    border-color: var(--color-background-muted) transparent transparent transparent;
}

.bio-speech-bubble .add-bio-prompt {
    color: var(--color-text-muted);
    font-size: 1rem;
    font-style: italic;
    margin: 0;
}

.bio-edit-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    background: var(--color-background);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-sm);
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--color-text-muted);
    transition: all 0.2s ease;
    opacity: 1;
}

.bio-edit-btn:hover {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

/* Bio character counter */
.character-counter {
    text-align: right;
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    margin-top: var(--spacing-xs);
}

.character-counter #bio-char-count {
    font-weight: 500;
    color: var(--color-text);
}

/* Username with Badge Container */
.username-with-badge {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    justify-content: flex-start;
}

.writer-level-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: var(--border-radius-pill);
    font-weight: var(--font-weight-medium);
    text-transform: uppercase;
    font-size: 11px;
}

.writer-level-badge i {
    font-size: 10px;
}

.writer-level-badge.novice {
    background: linear-gradient(135deg, #94a3b8, #64748b);
    color: white;
}

.writer-level-badge.apprentice {
    background: linear-gradient(135deg, #CD7F32, #8B4513);
    color: white;
}

.writer-level-badge.storyteller {
    background: linear-gradient(135deg, #C0C0C0, #808080);
    color: white;
}

.writer-level-badge.wordsmith {
    background: linear-gradient(135deg, var(--color-tertiary-300), var(--color-tertiary));
    color: white;
}

.writer-level-badge.master {
    background: linear-gradient(135deg, #9333ea, #7c3aed);
    color: white;
}

.boon-status {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.boon-label {
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
}

.boon-value {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-bold);
    color: var(--color-tertiary);
}

/* Story conflict modal */
.story-comparison {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin: 20px 0;
}

.story-comparison-item {
    padding: 16px;
    border: 2px solid var(--color-border);
    border-radius: var(--border-radius-md);
    background: var(--color-background);
}

.story-comparison-item h4 {
    margin: 0 0 12px 0;
    font-size: 16px;
    color: var(--color-text);
}

.story-preview .story-title {
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: var(--spacing-sm);
}

.story-preview .story-progress {
    margin-bottom: var(--spacing-sm);
}

.story-preview .story-date {
    font-size: 12px;
}

.conflict-actions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-top: 20px;
}

.conflict-actions .button {
    padding: 12px 16px;
    font-size: 14px;
}

/* Responsive design */
/* Tablet breakpoint */
@media (max-width: 1024px) {
    .stories-grid {
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
        gap: 18px;
    }
}

/* Mobile breakpoint */
@media (max-width: 768px) {
    .profile-stats {
        gap: var(--spacing-sm);
    }

    .stories-grid {
        grid-template-columns: 1fr;
        gap: 16px;
        padding: 0 var(--spacing-sm);
    }

    .story-item {
        padding: 16px 12px;
    }

    .story-info h4 {
        font-size: var(--font-size-2xl);
    }

    .story-date {
        font-size: 12px;
    }

    .story-comparison {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .conflict-actions {
        grid-template-columns: 1fr;
        gap: 8px;
    }
}

/* Profile Empty State */
.profile-empty-state {
    position: relative;
    min-height: 600px;
}

.profile-ghost-grid {
    opacity: 0.5;
    filter: blur(2px);
    pointer-events: none;
}

.ghost-story-item {
    background: var(--color-background-muted);
    border: 2px solid var(--color-border);
}

.ghost-story-icon {
    width: 64px;
    height: 64px;
    background: var(--color-neutral-300);
    border-radius: 50%;
}

.ghost-story-title {
    height: 16px;
    background: var(--color-neutral-300);
    border-radius: var(--border-radius-sm);
    width: 70%;
    margin-bottom: var(--spacing-sm);
}

.ghost-story-date {
    height: 12px;
    background: var(--color-neutral-300);
    border-radius: var(--border-radius-sm);
    width: 50%;
}

/* Character Selection Interface */
.character-selection-interface {
    position: absolute;
    right: var(--spacing-lg);
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    border-radius: var(--border-radius-pill);
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 16px;
    width: 0;
    max-width: calc(100vw - 108px);
    overflow: hidden;
    transition: width 0.4s ease-out;
}

.large-character-display {
    flex-shrink: 0;
    margin-right: 16px;
}

.large-character-display .avatar {
    width: 120px;
    height: 120px;
    border-radius: var(--border-radius-lg);
    border: 2px solid #e5e7eb;
}

.character-selection-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.character-select-label {
    color: var(--color-text-muted);
    font-size: 12px;
    font-weight: 500;
    position: absolute;
    top: 8px;
    left: 16px;
}

.close-character-btn {
    background: #ef4444;
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s;
    flex-shrink: 0;
}

.close-character-btn:hover {
    background: var(--color-danger);
}

.character-scroll-container {
    flex: 1;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
    border-radius: var(--border-radius-pill);
}

.character-scroll-container::-webkit-scrollbar {
    display: none;
}

.character-grid {
    display: flex;
    gap: 8px;
    padding: 4px 0;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
}

.character-grid.grabbing {
    cursor: grabbing;
}

.character-selection-interface.open {
    width: 40vw;
}

.character-option {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px;
    border-radius: 50%;
    background: transparent;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    justify-content: center;
}

.character-option:hover {
    transform: scale(1.05);
}

.character-option.selected {
    border-color: #f472b6;
    background: rgba(244, 114, 182, 0.1);
}

.character-standing {
    width: 88px;
    height: 88px;
    object-fit: contain;
    transition: transform 0.2s;
    pointer-events: none;
    border-radius: 50%;
    background-color: var(--color-info-light);
}

.character-option:hover .character-standing {
    transform: scale(1.1);
}

.character-name-tooltip {
    visibility: visible;
    opacity: 1;
    position: fixed;
    z-index: 10000;
    width: max-content;
    max-width: 150px;
    padding: var(--spacing-xs) var(--spacing-sm);
    background: var(--color-neutral-900);
    color: var(--color-text-inverse);
    text-align: center;
    border-radius: var(--border-radius-sm);
    font-size: var(--font-size-sm);
    line-height: 1.4;
    transition: var(--transition-base);
    box-shadow: var(--shadow-md);
    pointer-events: none;
    text-transform: none;
    white-space: nowrap;
}

.character-name-tooltip::after {
    content: "";
    position: absolute;
    left: 50%;
    margin-left: -5px;
    border: 5px solid transparent;
    border-top-color: var(--color-neutral-900);
    bottom: -10px;
}

/* Tooltip hover rule removed - now handled by JavaScript */

/* Mobile responsive character selection */
@media (max-width: 768px) {
    .character-selection-interface {
        left: 12px;
        right: 12px;
        width: 84vw !important;
        height: auto;
        max-width: none;
        gap: 8px;
    }

    .character-option {
        padding: 4px;
    }

    .character-standing {
        width: 60px;
        height: 60px;
    }
}

/* Contextual Hints for New Users */
.contextual-hint {
    position: absolute;
    top: -60px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    animation: slideUpFadeIn 0.3s ease-out;
}

.hint-content {
    background: var(--color-primary);
    color: white;
    padding: var(--spacing-md);
    border-radius: var(--border-radius-lg);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    min-width: 250px;
    max-width: 300px;
    position: relative;
}

.hint-content::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid var(--color-primary);
}

.hint-content i {
    display: inline-block;
    margin-right: var(--spacing-sm);
    font-size: var(--font-size-lg);
}

.hint-content p {
    margin: 0;
    font-size: var(--font-size-sm);
    line-height: 1.4;
}

.hint-dismiss {
    margin-top: var(--spacing-sm);
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: var(--spacing-xs) var(--spacing-md);
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    font-size: var(--font-size-sm);
    transition: background 0.2s ease;
}

.hint-dismiss:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Highlight pulse animation */
.highlight-pulse {
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(74, 110, 224, 0.4);
    }

    50% {
        box-shadow: 0 0 0 10px rgba(74, 110, 224, 0);
    }
}

@keyframes slideUpFadeIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* Animated counter */
.stat-value.animating {
    animation: countUp 1.5s ease-out;
}

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

    50% {
        transform: scale(1.3);
        color: var(--color-success);
    }

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