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

:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --success-color: #10b981;
    --success-hover: #059669;
    --error-color: #ef4444;
    --error-hover: #dc2626;
    --secondary-color: #6b7280;
    --secondary-hover: #4b5563;
    --background: #f9fafb;
    --card-background: #ffffff;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --reader-bg: #0f172a;
    --reader-surface: #111827;
    --reader-text: #e5e7eb;
    --reader-muted: #9ca3af;
    --reader-link: #93c5fd;
    --top-nav-height: 3.5rem;
}

body[data-theme="light"] {
    --reader-bg: #f9fafb;
    --reader-surface: #ffffff;
    --reader-text: #111827;
    --reader-muted: #6b7280;
    --reader-link: #2563eb;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    margin: 0 auto;
    padding: 2rem;
    width: 100%;
}

header {
    text-align: center;
    margin-bottom: 2rem;
}

.top-nav {
    position: sticky;
    top: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    column-gap: 1rem;
    padding: 0.75rem 1rem;
    margin-bottom: 1.5rem;
    background: var(--background);
    border-bottom: 1px solid var(--border-color);
    width: 100%;
    min-height: var(--top-nav-height);
}

.nav-left {
    font-weight: 700;
    color: var(--text-primary);
    font-size: 1.05rem;
    white-space: nowrap;
}

.nav-center {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    white-space: nowrap;
}

.nav-right {
    justify-self: end;
    min-width: 1px;
}

.auth-area {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    justify-content: flex-end;
    min-height: 40px;
}

.auth-profile {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0.5rem;
    border-radius: 999px;
    background: var(--card-background);
    border: 1px solid var(--border-color);
}

.auth-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
}

.auth-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
}

.auth-logout {
    padding: 0.5rem 1rem;
}

.nav-link {
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    background: var(--card-background);
    font-weight: 500;
    transition: all 0.2s;
    white-space: nowrap;
}

.nav-link:hover {
    background: var(--border-color);
}

.nav-link.active {
    background: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
}

.nav-link.locked {
    opacity: 0.6;
    cursor: not-allowed;
    position: relative;
}

.nav-link.locked:hover::after {
    content: 'Log In Required';
    position: absolute;
    top: 120%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-primary);
    color: #fff;
    padding: 0.35rem 0.6rem;
    border-radius: 6px;
    font-size: 0.75rem;
    white-space: nowrap;
    z-index: 20;
}

h1 {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.125rem;
}

h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.card {
    background: var(--card-background);
    border-radius: 12px;
    padding: 2rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
}

.reader-card {
    padding: 0;
    overflow: hidden;
    background: var(--reader-bg);
    color: var(--reader-text);
    border: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    flex-direction: column;
}

.reader-tools-row {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--reader-surface);
    padding: 0.75rem 2rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 1.5rem;
}

.reader-scroll {
    padding: 1rem 2rem 2rem;
    background: var(--reader-bg);
}

.reader-meta h2 {
    margin-bottom: 0.25rem;
    color: var(--reader-text);
}

.reader-byline {
    color: var(--reader-muted);
    margin-bottom: 0.5rem;
    font-size: 0.95rem;
}

.reader-source {
    color: var(--reader-link);
    font-size: 0.9rem;
    text-decoration: none;
}

.reader-source:hover {
    text-decoration: underline;
}

.reader-tools {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: nowrap;
}

.font-controls {
    display: inline-flex;
    gap: 0.5rem;
}

.reader-content {
    padding: 0.75rem 0 0;
    font-size: var(--reader-font-size, 18px);
    line-height: 1.75;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    color: var(--reader-text);
    background: var(--reader-bg);
    max-width: 900px;
    margin: 0 auto;
}

.reader-content p {
    margin: 0 0 1.35em;
}

.convert-card {
    max-width: 900px;
    margin: 0 auto;
}

.convert-label {
    display: block;
    font-weight: 600;
    color: var(--text-primary);
    margin-top: 0.75rem;
}

.convert-input {
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 1rem;
    margin-top: 0.5rem;
    background: var(--card-background);
    color: var(--text-primary);
}

.convert-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.convert-textarea {
    width: 100%;
    min-height: 280px;
    resize: vertical;
    padding: 1rem;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 1rem;
    line-height: 1.6;
    background: var(--card-background);
    color: var(--text-primary);
    margin-top: 0.5rem;
}

.convert-textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.convert-actions {
    margin-top: 1rem;
}

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

.reader-content h1,
.reader-content h2,
.reader-content h3,
.reader-content h4 {
    color: var(--reader-text);
    margin: 1.5rem 0 0.75rem;
    line-height: 1.25;
}

.reader-content h1 {
    font-size: 2.2rem;
}

.reader-content h2 {
    font-size: 1.8rem;
}

.reader-content h3 {
    font-size: 1.5rem;
}

.reader-content h4 {
    font-size: 1.25rem;
}

.reader-content img,
.reader-content figure img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 1rem auto;
}

.reader-content figure {
    margin: 1.5rem auto;
}

.reader-content figcaption {
    font-size: 0.9em;
    color: var(--reader-muted);
    text-align: center;
    margin-top: 0.5rem;
}

.reader-content a {
    color: var(--reader-link);
}

.error-card {
    border-color: var(--error-color);
    background: #fef2f2;
}

/* API Configuration */
.config-form {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.config-form label {
    font-weight: 500;
    color: var(--text-secondary);
    align-self: center;
}

.config-form input {
    flex: 1;
    min-width: 250px;
    padding: 0.625rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    transition: all 0.2s;
}

.config-form input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.status-message {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.875rem;
    display: none;
}

.status-message.success {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #6ee7b7;
    display: block;
}

.status-message.error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
    display: block;
}

/* Upload Area */
.info-text {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: 12px;
    padding: 2rem;
    text-align: center;
    transition: all 0.3s;
    background: var(--background);
    margin-bottom: 1.5rem;
}

.upload-area.dragover {
    border-color: var(--primary-color);
    background: rgba(79, 70, 229, 0.05);
    transform: scale(1.02);
}

.upload-label {
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    color: var(--text-secondary);
}

.upload-label svg {
    color: var(--primary-color);
}

.upload-label span {
    font-size: 1rem;
}

/* File List */
.file-list {
    margin-bottom: 1.5rem;
}

.file-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    background: var(--background);
    border-radius: 8px;
    margin-bottom: 0.5rem;
    border: 1px solid var(--border-color);
}

.file-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
    min-width: 0;
}

.file-icon {
    color: var(--primary-color);
    flex-shrink: 0;
}

.file-details {
    flex: 1;
    min-width: 0;
}

.file-name {
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-size {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.file-remove {
    background: none;
    border: none;
    color: var(--error-color);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 6px;
    transition: background 0.2s;
    flex-shrink: 0;
}

.file-remove:hover {
    background: #fee2e2;
}

/* Buttons */
button {
    font-family: inherit;
    font-size: 1rem;
    font-weight: 500;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-block;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    width: 100%;
    padding: 1rem;
    font-size: 1.125rem;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
}

.btn-primary:disabled {
    background: var(--secondary-color);
    cursor: not-allowed;
    opacity: 0.5;
}

.btn-secondary {
    background: var(--background);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 0.75rem 1.5rem;
}

.btn-secondary:hover {
    background: var(--border-color);
}

.btn-success {
    background: var(--success-color);
    color: white;
    padding: 0.75rem 1.5rem;
    border: 1px solid var(--success-color);
}

.btn-success:hover {
    background: var(--success-hover);
    border-color: var(--success-hover);
}

.btn-success:disabled {
    background: var(--secondary-color);
    border-color: var(--secondary-color);
    cursor: not-allowed;
    opacity: 0.5;
}

.font-btn.active {
    background: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
}

/* Progress Bar */
.progress-bar {
    width: 100%;
    height: 12px;
    background: var(--background);
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 1rem;
}

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

@keyframes shimmer {
    0% {
        background-position: -1000px 0;
    }
    100% {
        background-position: 1000px 0;
    }
}

.progress-text {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Messages */
.success-message {
    color: var(--success-color);
    font-size: 1.125rem;
    margin-bottom: 1.5rem;
    text-align: center;
}

.error-message {
    color: var(--error-color);
    font-size: 1rem;
    margin-bottom: 1.5rem;
    text-align: center;
    line-height: 1.6;
}

/* Footer */
footer {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-top: auto;
}

/* Responsive */
@media (max-width: 640px) {
    :root {
        --top-nav-height: 3rem;
    }

    .container {
        padding: 1rem;
    }

    .top-nav {
        column-gap: 0.5rem;
        padding: 0.5rem 0.75rem;
    }

    .nav-left {
        font-size: 0.95rem;
    }

    .nav-center {
        gap: 0.5rem;
    }

    .nav-link {
        font-size: 0.9rem;
        padding: 0.4rem 0.75rem;
    }

    .auth-name {
        display: none;
    }

    h1 {
        font-size: 2rem;
    }

    .card {
        padding: 1.5rem;
    }

    .config-form {
        flex-direction: column;
    }

    .config-form input {
        min-width: 100%;
    }

    .file-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .reader-tools-row {
        padding: 0.6rem 1.25rem;
    }

    .reader-tools {
        gap: 0.5rem;
    }

    .reader-scroll {
        padding: 0.9rem 1.25rem 1.75rem;
    }

    .reader-content {
        padding-top: 0.6rem;
        max-width: 100%;
    }
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.card {
    animation: fadeIn 0.3s ease;
}
