/* CSS Custom Properties for Library Theme */
:root {
    --primary-color: #8B4513;
    --secondary-color: #D2691E;
    --accent-color: #CD853F;
    --text-primary: #2C1810;
    --text-secondary: #5D4E37;
    --text-muted: #8B7355;
    --background-primary: #FFF8DC;
    --background-secondary: #F5DEB3;
    --background-paper: #FFFEF7;
    --border-color: #DEB887;
    --success-color: #228B22;
    --error-color: #B22222;
    --warning-color: #DAA520;
    
    --shadow-light: 0 2px 4px rgba(139, 69, 19, 0.1);
    --shadow-medium: 0 4px 12px rgba(139, 69, 19, 0.15);
    --shadow-heavy: 0 8px 24px rgba(139, 69, 19, 0.2);
    
    --border-radius: 8px;
    --border-radius-large: 12px;
    
    --font-serif: 'Playfair Display', serif;
    --font-body: 'Crimson Text', serif;

    /* Animation variables */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;
    --transition-slow: 0.5s ease;
}

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

body {
    font-family: var(--font-body);
    background: linear-gradient(135deg, var(--background-primary), var(--background-secondary));
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

.library-container {
    max-width: 1400px;
    margin: 0 auto;
    min-height: 100vh;
    background: var(--background-paper);
    box-shadow: var(--shadow-heavy);
}

/* Header Styles */
.library-header {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    padding: 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.header-content {
    flex: 1;
    min-width: 300px;
}

.library-title {
    font-family: var(--font-serif);
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    animation: titleGlow 3s ease-in-out infinite alternate;
}

@keyframes titleGlow {
    from { text-shadow: 0 0 5px rgba(255, 255, 255, 0.5); }
    to { text-shadow: 0 0 20px rgba(255, 255, 255, 0.8), 0 0 30px rgba(205, 133, 63, 0.5); }
}

.library-title i {
    color: var(--accent-color);
    animation: bookFloat 2s ease-in-out infinite alternate;
}

@keyframes bookFloat {
    from { transform: translateY(0px) rotate(0deg); }
    to { transform: translateY(-3px) rotate(2deg); }
}

.library-subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
    margin-bottom: 1rem;
}

.network-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.network-selector label {
    font-weight: 600;
}

.network-selector select {
    padding: 0.5rem;
    border: none;
    border-radius: var(--border-radius);
    background: white;
    color: var(--text-primary);
    font-family: var(--font-body);
    transition: var(--transition-normal);
}

.network-selector select:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-light);
}

/* Wallet Section */
.wallet-section {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 1rem;
    min-width: 200px;
}

.wallet-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    font-weight: 600;
    transition: var(--transition-normal);
}

.wallet-status.connected {
    background: rgba(34, 139, 34, 0.2);
    border: 2px solid rgba(34, 139, 34, 0.3);
    animation: pulseGreen 2s ease-in-out infinite;
}

.wallet-status.disconnected {
    background: rgba(178, 34, 34, 0.2);
    border: 2px solid rgba(178, 34, 34, 0.3);
    animation: pulseRed 2s ease-in-out infinite;
}

@keyframes pulseGreen {
    0%, 100% { box-shadow: 0 0 5px rgba(34, 139, 34, 0.3); }
    50% { box-shadow: 0 0 20px rgba(34, 139, 34, 0.6); }
}

@keyframes pulseRed {
    0%, 100% { box-shadow: 0 0 5px rgba(178, 34, 34, 0.3); }
    50% { box-shadow: 0 0 20px rgba(178, 34, 34, 0.6); }
}

.wallet-status::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    animation: statusBlink 1.5s ease-in-out infinite;
}

@keyframes statusBlink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0.3; }
}

.wallet-info {
    text-align: right;
    font-size: 0.9rem;
    line-height: 1.4;
}

.wallet-info small {
    display: block;
    opacity: 0.8;
    font-weight: 600;
}

.wallet-address {
    margin-bottom: 0.25rem;
}

.connect-btn, .disconnect-btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--border-radius);
    background: white;
    color: var(--primary-color);
    font-family: var(--font-body);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-normal);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.connect-btn:hover, .disconnect-btn:hover {
    background: var(--background-secondary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-medium);
}

/* Navigation */
.library-nav {
    background: var(--background-secondary);
    padding: 0;
    display: flex;
    border-bottom: 3px solid var(--border-color);
    overflow-x: auto;
}

.nav-btn {
    flex: 1;
    min-width: 150px;
    padding: 1.25rem 1.5rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font-body);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-normal);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border-bottom: 3px solid transparent;
    position: relative;
    overflow: hidden;
    white-space: nowrap;
}

.nav-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(139, 69, 19, 0.1), transparent);
    transition: var(--transition-slow);
}

.nav-btn:hover::before {
    left: 100%;
}

.nav-btn:hover {
    background: rgba(139, 69, 19, 0.1);
    color: var(--primary-color);
    transform: translateY(-2px);
}

.nav-btn.active {
    background: var(--background-paper);
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    box-shadow: 0 -2px 10px rgba(139, 69, 19, 0.2);
}

.nav-btn i {
    transition: var(--transition-normal);
}

.nav-btn:hover i {
    transform: scale(1.1);
}

/* Main Content */
.library-main {
    padding: 2rem;
}

.library-section {
    display: none;
    animation: fadeInUp 0.5s ease-out;
}

.library-section.active {
    display: block;
}

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

.section-header {
    text-align: center;
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: linear-gradient(135deg, rgba(139, 69, 19, 0.05), rgba(210, 105, 30, 0.05));
    border-radius: var(--border-radius-large);
    border: 2px solid var(--border-color);
    position: relative;
    overflow: hidden;
}

.section-header::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(139, 69, 19, 0.03) 0%, transparent 70%);
    animation: backgroundRotate 20s linear infinite;
}

@keyframes backgroundRotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.section-header h2 {
    font-family: var(--font-serif);
    font-size: 2rem;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    position: relative;
    z-index: 1;
}

.section-header p {
    color: var(--text-secondary);
    font-size: 1.1rem;
    position: relative;
    z-index: 1;
}

/* Content Grid */
.content-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    align-items: start;
}

/* Audio Library Grid */
.audio-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 2rem;
    align-items: start;
}

/* Gallery Grid */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 2rem;
    align-items: start;
}

@media (max-width: 968px) {
    .content-grid {
        grid-template-columns: 1fr;
    }
    
    .audio-grid {
        grid-template-columns: 1fr;
    }
    
    .gallery-grid {
        grid-template-columns: 1fr;
    }

    .nav-btn {
        font-size: 0.9rem;
        padding: 1rem;
        min-width: 120px;
    }

    .library-header {
        flex-direction: column;
        text-align: center;
    }

    .wallet-section {
        align-items: center;
    }
}

/* Card Styles */
.card {
    background: var(--background-paper);
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius-large);
    padding: 1.5rem;
    box-shadow: var(--shadow-medium);
    transition: var(--transition-normal);
    position: relative;
    overflow: hidden;
}

.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color), var(--accent-color));
    transform: translateX(-100%);
    transition: var(--transition-slow);
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-heavy);
}

.card:hover::before {
    transform: translateX(0);
}

.card h3 {
    font-family: var(--font-serif);
    color: var(--primary-color);
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.3rem;
}

/* Form Styles */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    background: white;
    font-family: var(--font-body);
    font-size: 1rem;
    transition: var(--transition-normal);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(139, 69, 19, 0.1);
    transform: translateY(-1px);
}

/* Arguments Section */
.arguments-section {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 2px solid var(--border-color);
}

.arguments-section h4 {
    color: var(--primary-color);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.argument-group {
    margin-bottom: 1rem;
    padding: 1rem;
    background: var(--background-secondary);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    transition: var(--transition-normal);
}

.argument-group:hover {
    background: rgba(139, 69, 19, 0.05);
}

.argument-controls {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    align-items: center;
}

.arg-type {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background: white;
    font-family: var(--font-body);
}

.remove-arg-btn {
    padding: 0.5rem;
    background: var(--error-color);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition-normal);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
}

.remove-arg-btn:hover {
    background: #8B0000;
    transform: scale(1.05);
}

.argument-input {
    position: relative;
}

.arg-value, .arg-text-area {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background: white;
    font-family: var(--font-body);
    font-size: 1rem;
    transition: var(--transition-normal);
}

.arg-text-area {
    resize: vertical;
    min-height: 120px;
    font-family: 'Courier New', monospace;
    line-height: 1.5;
}

.arg-value:focus, .arg-text-area:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(139, 69, 19, 0.1);
}

.add-arg-btn {
    width: 100%;
    padding: 0.75rem;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    font-family: var(--font-body);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-normal);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1rem;
}

.add-arg-btn:hover {
    background: var(--secondary-color);
    transform: translateY(-2px);
}

/* Submit Buttons */
.submit-btn {
    width: 100%;
    padding: 1rem 2rem;
    border: none;
    border-radius: var(--border-radius);
    font-family: var(--font-body);
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-normal);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-top: 2rem;
}

.read-btn {
    background: var(--success-color);
    color: white;
}

.read-btn:hover:not(:disabled) {
    background: #1F7A1F;
    transform: translateY(-2px);
    box-shadow: var(--shadow-medium);
}

.write-btn {
    background: var(--primary-color);
    color: white;
}

.write-btn:hover:not(:disabled) {
    background: #723A10;
    transform: translateY(-2px);
    box-shadow: var(--shadow-medium);
}

.submit-btn:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
    transform: none;
}

/* Results Display */
.results-display, .transaction-status {
    height: fit-content;
    min-height: 300px;
}

.results-content {
    min-height: 200px;
    max-height: 600px;
    overflow-y: auto;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    color: var(--text-muted);
    text-align: center;
    padding: 2rem;
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* Result Items */
.result-item, .transaction-item {
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--background-secondary);
    border-radius: var(--border-radius);
    border-left: 4px solid var(--primary-color);
    transition: var(--transition-normal);
}

.result-item:hover, .transaction-item:hover {
    background: rgba(139, 69, 19, 0.05);
    transform: translateX(5px);
}

.result-header, .transaction-header {
    display: flex;
    justify-content: between;
    align-items: center;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--primary-color);
}

.result-content, .transaction-content {
    background: white;
    padding: 1rem;
    border-radius: var(--border-radius);
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
}

.result-meta, .transaction-meta {
    margin-top: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

/* Gallery Styles */
.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: var(--border-radius);
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition-normal);
    background: var(--background-secondary);
}

.upload-area:hover {
    border-color: var(--primary-color);
    background: rgba(139, 69, 19, 0.05);
}

.upload-area.dragover {
    border-color: var(--secondary-color);
    background: rgba(210, 105, 30, 0.1);
}

.upload-area i {
    font-size: 2rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.image-preview-section, .decoded-preview-section {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 2px solid var(--border-color);
}

.image-preview-container, .decoded-preview-container {
    margin-bottom: 1rem;
}

.image-preview-container img, .decoded-preview-container img {
    max-width: 100%;
    max-height: 300px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-medium);
    margin-bottom: 1rem;
}

.image-info {
    background: var(--background-secondary);
    padding: 1rem;
    border-radius: var(--border-radius);
    margin-bottom: 1rem;
}

.info-item {
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.info-item:last-child {
    margin-bottom: 0;
}

.base64-display {
    background: white;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1rem;
    min-height: 200px;
    max-height: 400px;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
    line-height: 1.4;
    word-break: break-all;
    white-space: pre-wrap;
}

/* Action Buttons */
.action-btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--border-radius);
    font-family: var(--font-body);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-normal);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0.25rem;
}

.encode-btn, .decode-btn {
    background: var(--primary-color);
    color: white;
}

.encode-btn:hover, .decode-btn:hover {
    background: #723A10;
    transform: translateY(-2px);
}

.copy-btn {
    background: var(--success-color);
    color: white;
}

.copy-btn:hover {
    background: #1F7A1F;
    transform: translateY(-2px);
}

.clear-btn {
    background: var(--error-color);
    color: white;
}

.clear-btn:hover {
    background: #8B0000;
    transform: translateY(-2px);
}

.download-btn {
    background: var(--secondary-color);
    color: white;
}

.download-btn:hover {
    background: #A0522D;
    transform: translateY(-2px);
}

.info-btn {
    background: var(--warning-color);
    color: white;
}

.info-btn:hover {
    background: #B8860B;
    transform: translateY(-2px);
}

.goal-btn {
    background: var(--accent-color);
    color: white;
}

.goal-btn:hover {
    background: var(--secondary-color);
    transform: translateY(-2px);
}

.encoding-controls, .decoder-controls, .output-controls, .decoded-controls {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: 1rem;
}

/* Micro Chapter Editor Styles */
.goal-section {
    margin-bottom: 2rem;
}

.goal-controls {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

.goal-display {
    margin-top: 1.5rem;
    padding: 1.5rem;
    background: var(--background-secondary);
    border-radius: var(--border-radius);
    border: 2px solid var(--border-color);
}

.goal-info {
    margin-bottom: 1.5rem;
}

.goal-info > div {
    margin-bottom: 0.5rem;
    font-size: 1rem;
}

.progress-container {
    position: relative;
}

.progress-bar {
    width: 100%;
    height: 20px;
    background: rgba(139, 69, 19, 0.1);
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--success-color), var(--primary-color));
    border-radius: 10px;
    transition: width 0.3s ease;
    width: 0%;
}

.progress-text {
    text-align: center;
    margin-top: 0.5rem;
    font-weight: 600;
    color: var(--primary-color);
}

.editor-section {
    margin-bottom: 1.5rem;
}

.editor-controls {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.chapter-editor-card textarea {
    min-height: 300px;
    font-family: var(--font-body);
    line-height: 1.6;
    resize: vertical;
}

.word-stats {
    margin-top: 1rem;
    padding: 1rem;
    background: var(--background-secondary);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.stat-item {
    font-size: 0.9rem;
}

.stat-item strong {
    color: var(--primary-color);
}

/* Compact Style Formatter Styles */
.formatting-tools {
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--background-secondary);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
}

.format-buttons {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.format-btn {
    padding: 0.5rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition-normal);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.format-btn:hover {
    background: var(--secondary-color);
    transform: scale(1.05);
}

.format-info {
    display: flex;
    justify-content: flex-end;
}

.format-costs-display {
    margin-top: 1rem;
    padding: 1rem;
    background: rgba(139, 69, 19, 0.05);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
}

.costs-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.cost-item {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.formatter-editor-card textarea {
    min-height: 250px;
    font-family: 'Courier New', monospace;
    line-height: 1.5;
    resize: vertical;
}

.formatter-stats {
    margin-top: 1rem;
    padding: 1rem;
    background: var(--background-secondary);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
}

.preview-controls {
    margin-bottom: 1rem;
}

.preview-tabs {
    display: flex;
    gap: 0.25rem;
    background: var(--background-secondary);
    padding: 0.25rem;
    border-radius: var(--border-radius);
}

.preview-tab {
    flex: 1;
    padding: 0.5rem 1rem;
    background: transparent;
    border: none;
    border-radius: var(--border-radius);
    color: var(--text-secondary);
    font-family: var(--font-body);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-normal);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.preview-tab.active {
    background: var(--primary-color);
    color: white;
}

.preview-tab:hover:not(.active) {
    background: rgba(139, 69, 19, 0.1);
}

.preview-section {
    background: white;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    min-height: 300px;
    max-height: 500px;
    overflow-y: auto;
}

.formatted-preview {
    font-family: var(--font-body);
    line-height: 1.6;
}

.formatted-preview h1, .formatted-preview h2, .formatted-preview h3 {
    color: var(--primary-color);
    margin-bottom: 0.5rem;
    font-family: var(--font-serif);
}

.formatted-preview p {
    margin-bottom: 1rem;
}

.formatted-preview strong {
    color: var(--primary-color);
    font-weight: 700;
}

.formatted-preview em {
    color: var(--secondary-color);
    font-style: italic;
}

.formatted-preview blockquote {
    border-left: 4px solid var(--accent-color);
    margin: 1rem 0;
    padding-left: 1rem;
    color: var(--text-secondary);
    font-style: italic;
}

.raw-preview {
    font-family: 'Courier New', monospace;
    line-height: 1.5;
    font-size: 0.9rem;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: modalFadeIn 0.3s ease-out;
}

@keyframes modalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--background-paper);
    border-radius: var(--border-radius-large);
    box-shadow: var(--shadow-heavy);
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    animation: modalSlideIn 0.3s ease-out;
    position: relative;
}

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

.modal-header {
    padding: 1.5rem;
    border-bottom: 2px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    color: var(--primary-color);
    margin: 0;
    font-family: var(--font-serif);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    transition: var(--transition-normal);
}

.modal-close:hover {
    color: var(--error-color);
    transform: scale(1.1);
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1.5rem;
    border-top: 2px solid var(--border-color);
    text-align: right;
}

.wallet-options {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 1rem;
}

.wallet-option {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--background-secondary);
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition-normal);
    text-align: left;
    width: 100%;
}

.wallet-option:hover {
    border-color: var(--primary-color);
    background: rgba(139, 69, 19, 0.05);
    transform: translateY(-2px);
}

.wallet-icon {
    font-size: 1.5rem;
    color: var(--primary-color);
}

.wallet-info strong {
    display: block;
    color: var(--primary-color);
    margin-bottom: 0.25rem;
}

.wallet-info small {
    color: var(--text-muted);
}

/* Loading Modal */
.loading-modal .modal-content {
    max-width: 400px;
    text-align: center;
}

.loading-content {
    padding: 2rem;
}

.loading-spinner {
    font-size: 3rem;
    color: var(--primary-color);
    margin-bottom: 1rem;
}

.loading-spinner i {
    animation: spin 1s linear infinite;
}

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

/* Error Modal */
.error-header {
    background: var(--error-color);
    color: white;
    border-radius: var(--border-radius-large) var(--border-radius-large) 0 0;
}

.error-header h3 {
    color: white;
}

/* Success Modal */
.success-header {
    background: var(--success-color);
    color: white;
    border-radius: var(--border-radius-large) var(--border-radius-large) 0 0;
}

.success-header h3 {
    color: white;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .library-header {
        padding: 1.5rem;
    }
    
    .library-title {
        font-size: 2rem;
    }
    
    .library-main {
        padding: 1rem;
    }
    
    .section-header {
        padding: 1rem;
    }
    
    .section-header h2 {
        font-size: 1.5rem;
    }
    
    .card {
        padding: 1rem;
    }
    
    .stats-grid, .costs-grid {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }
    
    .format-buttons {
        justify-content: center;
    }
    
    .editor-controls, .goal-controls, .encoding-controls, .decoder-controls, .output-controls {
        justify-content: center;
    }
    
    .modal-content {
        margin: 1rem;
        width: calc(100% - 2rem);
    }
    
    .nav-btn {
        padding: 1rem 0.5rem;
        font-size: 0.8rem;
        min-width: 100px;
    }
}

/* Utility Classes */
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }

.hidden { display: none !important; }
.visible { display: block !important; }

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--background-secondary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

/* Focus styles for accessibility */
button:focus,
input:focus,
textarea:focus,
select:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --border-color: #333;
        --text-muted: #333;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Writing Tools Styles from Second App */
.writing-tools-section {
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 2px solid var(--border-color);
}

.writing-tool {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.writing-tool:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.tool-content {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Progress Styles */
.progress-section {
    background: var(--bg-secondary);
    padding: 1.5rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

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

.progress-label {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.progress-counter {
    font-family: 'Courier New', monospace;
    color: var(--accent-color);
    font-weight: bold;
    font-size: 0.9rem;
}

.progress-bar {
    position: relative;
    height: 8px;
    background: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-color), var(--primary-color));
    border-radius: 4px;
    transition: width 0.3s ease;
    position: relative;
}

.progress-markers {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}

.marker {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background: rgba(255, 255, 255, 0.8);
}

.marker.warning {
    background: var(--warning-color);
}

.marker.danger {
    background: var(--error-color);
}

.progress-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.progress-percentage {
    font-weight: 600;
    color: var(--text-primary);
}

/* Goal Section */
.goal-section {
    background: var(--bg-secondary);
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.goal-section .form-group {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 0.5rem;
}

.goal-section input {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.9rem;
}

.tool-btn-small {
    padding: 0.5rem 1rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.tool-btn-small:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.tool-btn-small.secondary {
    background: var(--text-secondary);
}

.tool-btn-small.secondary:hover {
    background: var(--error-color);
}

/* Editor Section */
.editor-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

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

.editor-actions {
    display: flex;
    gap: 0.5rem;
}

.tool-btn.small {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
    border-radius: 4px;
}

.chapter-textarea,
.formatter-textarea {
    width: 100%;
    min-height: 200px;
    padding: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-family: 'Crimson Text', serif;
    font-size: 1rem;
    line-height: 1.6;
    resize: vertical;
    transition: border-color 0.3s ease;
}

.chapter-textarea:focus,
.formatter-textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.chapter-textarea.warning {
    border-color: var(--warning-color);
}

.chapter-textarea.danger,
.formatter-textarea.danger {
    border-color: var(--error-color);
}

.formatter-textarea.warning {
    border-color: var(--warning-color);
}

/* Editor Stats */
.editor-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 1rem;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.stat-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.stat-value {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    font-family: 'Courier New', monospace;
}

/* Format Toolbar */
.format-toolbar {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    flex-wrap: wrap;
}

.toolbar-group {
    display: flex;
    gap: 0.5rem;
}

.format-btn {
    padding: 0.5rem 0.75rem;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.format-btn:hover {
    background: var(--primary-color);
    color: white;
    transform: translateY(-1px);
}

.format-btn:active {
    transform: translateY(0);
}

/* Format Costs */
.format-costs {
    background: var(--bg-secondary);
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.cost-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.cost-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.5rem;
}

.cost-item {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-family: 'Courier New', monospace;
}

/* Preview Section */
.preview-section {
    background: var(--card-bg);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

.preview-header {
    background: var(--bg-secondary);
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

.preview-label {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.preview-content {
    padding: 1.5rem;
    min-height: 120px;
    font-family: 'Crimson Text', serif;
    line-height: 1.6;
    color: var(--text-primary);
}

.preview-content em {
    color: var(--text-secondary);
    font-style: italic;
}

.preview-content strong {
    font-weight: 600;
    color: var(--accent-color);
}

.preview-content h3 {
    color: var(--primary-color);
    margin: 0 0 1rem 0;
    font-size: 1.2rem;
}

.preview-content blockquote {
    border-left: 4px solid var(--accent-color);
    padding-left: 1rem;
    margin: 1rem 0;
    font-style: italic;
    color: var(--text-secondary);
}

.preview-content p {
    margin: 0 0 1rem 0;
}

.preview-content p:last-child {
    margin-bottom: 0;
}

/* Tool Button Styles */
.tool-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.2rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
}

.tool-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.tool-btn:active {
    transform: translateY(0);
}

.tool-btn.secondary {
    background: var(--text-secondary);
}

.tool-btn.secondary:hover {
    background: var(--text-primary);
}

/* Responsive Design for Writing Tools */
@media (max-width: 768px) {
    .writing-tools-section .audio-grid {
        grid-template-columns: 1fr;
    }
    
    .format-toolbar {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .toolbar-group {
        justify-content: center;
    }
    
    .goal-section .form-group {
        flex-direction: column;
        align-items: stretch;
    }
    
    .editor-actions {
        flex-wrap: wrap;
    }
}
