/* ============================================================
   SaveBook - Design System
   Modern, reader-first interface with a soft blue accent.
   ============================================================ */

:root {
    --bg: #f8fafc;
    --bg-elevated: #ffffff;
    --bg-muted: #f1f5f9;
    --text: #0f172a;
    --text-soft: #475569;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-soft: #dbeafe;
    --success: #16a34a;
    --success-hover: #15803d;
    --secondary: #7c3aed;
    --danger: #dc2626;
    --warning: #d97706;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow: 0 4px 16px rgba(15, 23, 42, 0.06);
    --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.08);
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: "SF Mono", Menlo, Consolas, monospace;
    --max-width: 1080px;
}

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

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: var(--primary);
    text-decoration: none;
}
a:hover { text-decoration: underline; }

img { max-width: 100%; height: auto; display: block; }

button { font-family: inherit; cursor: pointer; }

input, select, textarea {
    font-family: inherit;
    font-size: 1rem;
    color: var(--text);
}

.container {
    width: 100%;
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 1.25rem;
}

.hidden { display: none !important; }

/* ============================================================
   Navigation
   ============================================================ */
.nav {
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
    backdrop-filter: blur(8px);
}
.nav-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 1.25rem;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--text);
}
.nav-brand:hover { text-decoration: none; }
.nav-logo { width: 28px; height: 28px; }
.nav-links {
    display: flex;
    align-items: center;
    gap: 1.75rem;
}
.nav-link {
    color: var(--text-soft);
    font-weight: 500;
    font-size: 0.95rem;
    transition: color 0.15s;
}
.nav-link:hover { color: var(--primary); text-decoration: none; }
.nav-link.active { color: var(--primary); }
.nav-link-soft { color: var(--text-muted); }
.nav-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text);
    padding: 0.4rem;
    border-radius: var(--radius-sm);
}
.nav-toggle:hover { background: var(--bg-muted); }

@media (max-width: 720px) {
    .nav-toggle { display: block; }
    .nav-links {
        display: none;
        position: absolute;
        top: 64px;
        left: 0;
        right: 0;
        flex-direction: column;
        gap: 0;
        background: var(--bg-elevated);
        border-bottom: 1px solid var(--border);
        padding: 0.5rem 0;
        box-shadow: var(--shadow);
    }
    .nav-links.open { display: flex; }
    .nav-link { padding: 0.85rem 1.25rem; width: 100%; }
    .nav-link:hover { background: var(--bg-muted); }
}

/* ============================================================
   Hero
   ============================================================ */
.hero {
    padding: 4rem 0 3rem;
    background: linear-gradient(180deg, #eff6ff 0%, var(--bg) 100%);
}
.hero-title {
    font-size: clamp(1.9rem, 4vw, 2.8rem);
    font-weight: 800;
    line-height: 1.15;
    text-align: center;
    margin-bottom: 0.75rem;
    letter-spacing: -0.02em;
}
.hero-subtitle {
    text-align: center;
    color: var(--text-soft);
    font-size: 1.1rem;
    margin-bottom: 2.5rem;
}

/* ============================================================
   Card
   ============================================================ */
.card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.75rem;
    box-shadow: var(--shadow);
}

.convert-form { max-width: 640px; margin: 0 auto; }

/* ============================================================
   Form
   ============================================================ */
.form-field { margin-bottom: 1.25rem; }
.form-label {
    display: block;
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
    color: var(--text);
}
.form-input,
.form-select {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1.5px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form-input:focus,
.form-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}
.form-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin: 0.5rem 0;
}
.form-hint code {
    font-family: var(--font-mono);
    font-size: 0.85em;
    background: var(--bg-muted);
    padding: 0.1em 0.4em;
    border-radius: 4px;
}
.form-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.85rem;
}
.form-row .form-label { margin: 0; }
.form-select { width: auto; min-width: 120px; }

.form-checkbox {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    cursor: pointer;
    padding: 0.4rem 0;
    font-size: 0.95rem;
    color: var(--text-soft);
}
.form-checkbox input { width: 18px; height: 18px; cursor: pointer; }

/* Format toggle */
.format-toggle {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}
.format-toggle input { display: none; }
.format-option {
    border: 1.5px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 0.9rem 1rem;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    text-align: center;
}
.format-option strong { font-size: 1rem; }
.format-option span { font-size: 0.8rem; color: var(--text-muted); }
.format-toggle input:checked + .format-option {
    border-color: var(--primary);
    background: var(--primary-soft);
    color: var(--primary-hover);
}
.format-toggle input:checked + .format-option span { color: var(--primary-hover); opacity: 0.8; }

/* Advanced */
.advanced {
    margin-bottom: 1.25rem;
    border-top: 1px dashed var(--border);
    padding-top: 1rem;
}
.advanced-toggle {
    cursor: pointer;
    color: var(--primary);
    font-weight: 500;
    font-size: 0.9rem;
    list-style: none;
    user-select: none;
}
.advanced-toggle::-webkit-details-marker { display: none; }
.advanced-toggle::before {
    content: "▸ ";
    transition: transform 0.15s;
    display: inline-block;
}
.advanced[open] .advanced-toggle::before { content: "▾ "; }
.advanced-body { padding-top: 0.85rem; }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.95rem;
    transition: all 0.15s;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

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

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

.btn-secondary { background: var(--secondary); color: white; }
.btn-secondary:hover { background: #6d28d9; }

.btn-soft {
    background: var(--bg-muted);
    color: var(--text-soft);
}
.btn-soft:hover { background: var(--border); }

.btn-block { width: 100%; padding: 0.95rem 1.5rem; font-size: 1rem; }

/* ============================================================
   Progress
   ============================================================ */
.progress { max-width: 640px; margin: 1.5rem auto 0; }
.progress-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-soft);
}
.progress-percent { font-weight: 600; color: var(--primary); }
.progress-track {
    height: 8px;
    background: var(--bg-muted);
    border-radius: 999px;
    overflow: hidden;
}
.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), #60a5fa);
    border-radius: 999px;
    transition: width 0.3s ease;
}

/* ============================================================
   Result
   ============================================================ */
.result { max-width: 640px; margin: 1.5rem auto 0; }
.result-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.result-badge {
    background: var(--success);
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.result-title {
    font-size: 1.15rem;
    font-weight: 600;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.result-meta {
    background: var(--bg-muted);
    border-radius: var(--radius-sm);
    padding: 1rem;
    margin-bottom: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.result-meta > div {
    display: flex;
    gap: 0.75rem;
    font-size: 0.9rem;
}
.result-meta dt { color: var(--text-muted); width: 70px; flex-shrink: 0; }
.result-meta dd { color: var(--text); font-weight: 500; word-break: break-all; }
.result-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.result-actions .btn { flex: 1; min-width: 120px; }

.kindle-area {
    margin-top: 1.25rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
}

/* ============================================================
   Alerts
   ============================================================ */
.alert {
    max-width: 640px;
    margin: 1.5rem auto 0;
    padding: 1rem 1.25rem;
    border-radius: var(--radius-sm);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
.alert-error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}
.alert strong { font-weight: 600; }

/* ============================================================
   Features section
   ============================================================ */
.features {
    padding: 4rem 0;
    background: var(--bg-elevated);
    border-top: 1px solid var(--border);
}
.section-title {
    text-align: center;
    font-size: 1.85rem;
    font-weight: 700;
    margin-bottom: 2.5rem;
    letter-spacing: -0.01em;
}
.feature-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 2rem;
}
.feature { text-align: center; padding: 0 1rem; }
.feature-icon {
    font-size: 2.4rem;
    margin-bottom: 0.75rem;
}
.feature h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.4rem;
}
.feature p { color: var(--text-soft); font-size: 0.95rem; }

/* ============================================================
   Stats
   ============================================================ */
.stats {
    padding: 3rem 0;
    background: var(--bg);
}
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1.5rem;
    text-align: center;
}
.stat-value {
    display: block;
    font-size: 2.2rem;
    font-weight: 800;
    color: var(--primary);
    line-height: 1;
    margin-bottom: 0.4rem;
}
.stat-label {
    display: block;
    color: var(--text-muted);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ============================================================
   Records page
   ============================================================ */
.records-page { padding: 3rem 0 5rem; }
.page-header { margin-bottom: 2rem; text-align: center; }
.page-header h1 { font-size: 2.2rem; font-weight: 800; margin-bottom: 0.5rem; }
.page-subtitle { color: var(--text-soft); }

.empty-state { text-align: center; padding: 4rem 1rem; }
.empty-state h2 { font-size: 1.4rem; margin-bottom: 0.5rem; }
.empty-state p { color: var(--text-soft); }

.loading {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}
.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--bg-muted);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.records-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.record-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.record-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.record-info { flex: 1; min-width: 0; }
.record-title {
    font-weight: 600;
    margin-bottom: 0.2rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.record-meta {
    display: flex;
    gap: 0.85rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    flex-wrap: wrap;
}
.record-meta a { color: var(--text-muted); }
.record-format {
    background: var(--primary-soft);
    color: var(--primary-hover);
    padding: 0.1rem 0.55rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.record-actions {
    display: flex;
    gap: 0.4rem;
    flex-shrink: 0;
}
.record-actions .btn { padding: 0.5rem 0.9rem; font-size: 0.85rem; }

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    margin-top: 2rem;
}
.page-indicator { color: var(--text-soft); font-size: 0.9rem; }

/* ============================================================
   Help page
   ============================================================ */
.help-page { padding: 3rem 0 5rem; max-width: 760px; }
.prose { font-size: 1rem; }
.prose section { margin-bottom: 2.5rem; }
.prose h2 {
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 1rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--border);
}
.prose h3 { font-size: 1.1rem; font-weight: 600; margin: 1.25rem 0 0.5rem; }
.prose p { margin-bottom: 0.9rem; color: var(--text); }
.prose ol, .prose ul { margin: 0 0 1rem 1.5rem; }
.prose li { margin-bottom: 0.4rem; }
.prose code {
    font-family: var(--font-mono);
    font-size: 0.9em;
    background: var(--bg-muted);
    padding: 0.15em 0.45em;
    border-radius: 4px;
    color: var(--text);
}
.prose pre {
    background: #0f172a;
    color: #e2e8f0;
    padding: 1rem 1.25rem;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 1rem 0;
    font-size: 0.85rem;
    line-height: 1.5;
}
.prose pre code {
    background: transparent;
    color: inherit;
    padding: 0;
}
.prose .faq dt {
    font-weight: 600;
    color: var(--text);
    margin-top: 0.85rem;
}
.prose .faq dd {
    color: var(--text-soft);
    margin-left: 0;
    margin-bottom: 0.5rem;
}

/* ============================================================
   Footer
   ============================================================ */
.footer {
    margin-top: auto;
    padding: 2rem 0;
    background: var(--bg-elevated);
    border-top: 1px solid var(--border);
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}
.footer p { margin: 0.3rem 0; }
.footer a { color: var(--text-soft); }
.footer-tagline { font-size: 0.8rem; opacity: 0.8; }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 600px) {
    .hero { padding: 2.5rem 0 2rem; }
    .card { padding: 1.25rem; }
    .format-toggle { grid-template-columns: 1fr; }
    .record-card {
        flex-direction: column;
        align-items: flex-start;
    }
    .record-actions { width: 100%; }
    .record-actions .btn { flex: 1; }
}
