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

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --success: #10b981;
    --error: #ef4444;
    --warning: #f59e0b;
    --bg: #f9fafb;
    --surface: #ffffff;
    --text: #1f2937;
    --text-light: #6b7280;
    --border: #e5e7eb;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: var(--text);
    line-height: 1.6;
}

.container {
    max-width: 700px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    text-align: center;
    color: white;
    margin-bottom: 40px;
    margin-top: 20px;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.subtitle {
    font-size: 1.1rem;
    opacity: 0.95;
    font-weight: 300;
}

/* Main Content */
main {
    flex: 1;
}

/* Cards */
.card {
    background: var(--surface);
    border-radius: 12px;
    padding: 30px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s ease-out;
}

.card h2 {
    font-size: 1.5rem;
    margin-bottom: 20px;
    color: var(--text);
}

.card h3 {
    font-size: 1.1rem;
    margin-bottom: 15px;
    color: var(--text);
}

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

/* Form */
.form-group {
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

label {
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text);
    font-size: 0.95rem;
}

.label-with-info {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    width: fit-content;
    max-width: 100%;
}

.info-tip-toggle {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--primary);
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    min-width: 22px;
    height: 22px;
    line-height: 1;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.info-tip-toggle:hover,
.info-tip-toggle:focus-visible {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.08);
    outline: none;
}

.info-tip {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    z-index: 20;
    width: min(360px, 85vw);
    background: #111827;
    color: #f9fafb;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 0.82rem;
    line-height: 1.45;
    font-weight: 400;
    box-shadow: 0 8px 20px rgba(17, 24, 39, 0.25);
}

input[type="text"],
input[type="number"],
input[type="email"],
input[type="url"] {
    padding: 12px 14px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
}

input[type="text"]:focus,
input[type="number"]:focus,
input[type="email"]:focus,
input[type="url"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

textarea {
    padding: 12px 14px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 0.95rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
    min-height: 76px;
    resize: vertical;
}

textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

small {
    display: block;
    margin-top: 6px;
    color: var(--text-light);
    font-size: 0.85rem;
}

code {
    background: var(--bg);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: "Monaco", "Courier New", monospace;
    color: var(--primary);
}

/* Advanced Settings */
.advanced-settings {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 20px;
    cursor: pointer;
    user-select: none;
}

.advanced-settings summary {
    font-weight: 600;
    color: var(--primary);
    cursor: pointer;
}

.advanced-settings summary:hover {
    opacity: 0.8;
}

.follow-next-options {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 20px;
    cursor: pointer;
    user-select: none;
}

.follow-next-options summary {
    font-weight: 600;
    color: var(--primary);
    cursor: pointer;
}

.follow-next-options summary:hover {
    opacity: 0.8;
}

.metadata-section {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 20px;
    cursor: pointer;
    user-select: none;
}

.metadata-section summary {
    font-weight: 600;
    color: var(--primary);
    cursor: pointer;
}

.metadata-section summary:hover {
    opacity: 0.8;
}

.settings-content {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

/* Buttons */
button {
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    justify-content: center;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

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

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

.btn-secondary {
    background: #374151;
    color: white;
    margin-top: 8px;
}

.btn-secondary:hover:not(:disabled) {
    background: #1f2937;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-text {
    display: inline-block;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.8s linear infinite;
}

.spinner.hidden {
    display: none;
}

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

/* Status Cards */
.status-card,
.error-card,
.success-card {
    display: none;
    border-left: 5px solid var(--border);
}

.status-card.visible,
.error-card.visible,
.success-card.visible {
    display: block;
}

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

.error-card p {
    color: var(--error);
    font-weight: 500;
}

.success-card {
    border-left-color: var(--success);
    background: #f0fdf4;
}

.success-card h3 {
    color: var(--success);
}

.status-content {
    margin: 15px 0;
}

.status-item {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

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

.status-label {
    font-weight: 500;
    color: var(--text-light);
}

.status-value {
    font-weight: 600;
    color: var(--text);
}

.download-btn {
    background: var(--success);
    color: white;
    padding: 10px 20px;
    border-radius: 6px;
    text-decoration: none;
    display: inline-block;
    margin-top: 15px;
    text-align: center;
}

.download-btn:hover {
    background: #059669;
}

.continue-actions {
    margin-top: 14px;
    padding: 12px;
    border: 1px solid #fbbf24;
    border-radius: 8px;
    background: #fffbeb;
}

.continue-prompt-message {
    color: #92400e;
    font-weight: 600;
    margin-bottom: 8px;
}

.continue-prompt-buttons {
    display: flex;
    gap: 10px;
}

.continue-prompt-buttons .btn {
    width: auto;
    min-width: 150px;
    margin-top: 0;
}

.ebook-item {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.ebook-item-main {
    min-width: 0;
}

.ebook-item-meta {
    color: var(--text-light);
    font-size: 0.86rem;
    margin-top: 4px;
    word-break: break-word;
}

.ebook-item-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ebook-download-btn {
    margin-top: 0;
    min-width: 120px;
}

.ebook-remove-btn {
    margin-top: 0;
    width: auto;
    min-width: 100px;
}

.cover-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.cover-preview {
    margin-top: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    background: var(--bg);
    max-width: 260px;
}

.cover-preview img {
    width: 100%;
    display: block;
    border-radius: 6px;
}

.replacement-rule {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto auto auto;
    gap: 8px;
    margin-bottom: 10px;
    align-items: start;
}

.replacement-rule select {
    padding: 10px;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: white;
}

.replacement-remove {
    border: none;
    background: var(--error);
    color: white;
    border-radius: 8px;
    padding: 10px 12px;
    margin-top: 2px;
}

.replacement-toggle {
    border: none;
    border-radius: 8px;
    padding: 10px 12px;
    margin-top: 2px;
    color: white;
}

.replacement-toggle.active {
    background: var(--success);
}

.replacement-toggle.inactive {
    background: var(--warning);
}

.replacement-rule.is-inactive {
    opacity: 0.6;
}

.rule-section {
    margin-top: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    background: var(--bg);
}

.rule-section summary {
    font-weight: 600;
    cursor: pointer;
    color: var(--text);
}

.host-selector-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 10px 0;
}

.host-selector-row label {
    margin: 0;
}

.host-selector-row select {
    flex: 1;
    padding: 8px;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: white;
}

.replacement-panel {
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}

.replacement-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 12px;
}

.replacement-list {
    margin-top: 10px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    max-height: 200px;
    overflow-y: auto;
}

.replacement-list-item {
    padding: 8px;
    margin-bottom: 6px;
    background: white;
    border-radius: 4px;
    border: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.btn-sm {
    padding: 4px 8px;
    font-size: 0.85rem;
}

.preview-controls {
    margin-top: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.preview-controls label {
    margin: 0;
    font-weight: 600;
    color: var(--text);
}

.preview-controls input {
    width: 80px;
    padding: 8px;
    border: 2px solid var(--border);
    border-radius: 6px;
}

.inline-check {
    flex-direction: row;
    align-items: center;
    gap: 10px;
}

.inline-check label {
    margin-bottom: 0;
}

.preview-content-box {
    margin-top: 10px;
    background: #111827;
    color: #e5e7eb;
    border-radius: 8px;
    padding: 12px;
    max-height: 300px;
    overflow: auto;
    white-space: pre-wrap;
    font-size: 0.9rem;
}

.preview-actions {
    display: flex;
    gap: 10px;
    margin-top: 16px;
}

#previewCard .btn {
    margin-top: 0;
}

/* Utilities */
.hidden {
    display: none !important;
}

.visible {
    display: block !important;
}

/* Responsive */
@media (max-width: 600px) {
    header h1 {
        font-size: 1.8rem;
    }

    .subtitle {
        font-size: 0.95rem;
    }

    .cover-grid,
    .replacement-rule,
    .preview-actions {
        grid-template-columns: 1fr;
        display: grid;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .card {
        padding: 20px;
    }

    .card h2 {
        font-size: 1.3rem;
    }

    .continue-prompt-buttons {
        flex-direction: column;
    }

    .continue-prompt-buttons .btn {
        width: 100%;
    }

    .ebook-item {
        flex-direction: column;
        align-items: flex-start;
    }

    .ebook-item-actions {
        width: 100%;
    }

    .ebook-item-actions .btn,
    .ebook-item-actions .download-btn {
        width: 100%;
    }
}
