/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-hover: #1c2333;
    --border: #30363d;
    --text: #e6edf3;
    --text-secondary: #8b949e;
    --accent: #58a6ff;
    --accent-dim: #1f6feb;
    --green: #3fb950;
    --orange: #d29922;
    --code-bg: #1a1e26;
    --max-width: 800px;
    --nav-height: 56px;
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.7;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

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

.hidden { display: none !important; }

/* === Header === */
.header {
    background: linear-gradient(135deg, #1a1e2e 0%, #0d1117 100%);
    border-bottom: 1px solid var(--border);
    padding: 24px 16px 20px;
    text-align: center;
}

.logo { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.5px; }
.subtitle { color: var(--text-secondary); font-size: 0.9rem; margin-top: 4px; }

.progress-bar-container {
    max-width: 300px;
    margin: 12px auto 0;
    background: var(--border);
    border-radius: 4px;
    height: 6px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--green);
    border-radius: 4px;
    transition: width 0.5s ease;
    width: 0%;
}

.progress-text { color: var(--text-secondary); font-size: 0.8rem; margin-top: 6px; }

/* === TOC === */
.toc { max-width: var(--max-width); margin: 0 auto; padding: 12px 12px 24px; }

.day-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 16px 8px 6px;
}

.toc-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 8px;
    text-decoration: none;
    color: var(--text);
    transition: background 0.2s, border-color 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.toc-card:hover, .toc-card:active {
    background: var(--surface-hover);
    border-color: var(--accent-dim);
    text-decoration: none;
}

.toc-card.completed { border-left: 3px solid var(--green); }

.toc-number {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--accent-dim);
    color: #fff;
    font-weight: 700;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toc-card.completed .toc-number { background: var(--green); }

.toc-info { flex: 1; min-width: 0; }
.toc-info h2 { font-size: 0.95rem; font-weight: 600; line-height: 1.3; }
.toc-info p { font-size: 0.8rem; color: var(--text-secondary); margin-top: 2px; }
.toc-meta { font-size: 0.7rem; color: var(--text-secondary); opacity: 0.7; display: block; margin-top: 4px; }

.toc-status {
    flex-shrink: 0;
    width: 10px; height: 10px;
    border-radius: 50%;
    background: var(--border);
    transition: background 0.3s;
}
.toc-status.read { background: var(--green); }

/* === Footer === */
.footer {
    text-align: center;
    padding: 24px 16px 32px;
    color: var(--text-secondary);
    font-size: 0.8rem;
}
.footer a { color: var(--accent); }

/* === Reading View === */
.read-nav {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    height: var(--nav-height);
    padding: 0 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    gap: 8px;
}

.btn-back {
    flex-shrink: 0;
    background: none;
    border: none;
    color: var(--accent);
    font-size: 0.9rem;
    padding: 8px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.btn-back:active { opacity: 0.6; }

.read-title {
    flex: 1;
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.read-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.btn-nav {
    background: none;
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 1.1rem;
    width: 32px; height: 32px;
    border-radius: 6px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    -webkit-tap-highlight-color: transparent;
}
.btn-nav:active { background: var(--border); }
.btn-nav:disabled { opacity: 0.3; cursor: default; }

.read-page { font-size: 0.75rem; color: var(--text-secondary); min-width: 30px; text-align: center; }

/* === Article Content === */
.read-content {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 20px 16px 100px;
}

.read-content h1 { font-size: 1.5rem; margin: 0 0 16px; line-height: 1.3; border-bottom: 1px solid var(--border); padding-bottom: 12px; }
.read-content h2 { font-size: 1.25rem; margin: 32px 0 12px; color: var(--accent); }
.read-content h3 { font-size: 1.05rem; margin: 24px 0 10px; color: var(--text); }
.read-content h4 { font-size: 0.95rem; margin: 20px 0 8px; color: var(--text-secondary); }

.read-content p { margin: 0 0 12px; }

.read-content ul, .read-content ol { margin: 0 0 12px; padding-left: 20px; }
.read-content li { margin-bottom: 4px; }

.read-content blockquote {
    margin: 12px 0;
    padding: 12px 16px;
    background: rgba(88,166,255,0.08);
    border-left: 3px solid var(--accent);
    border-radius: 0 8px 8px 0;
    color: var(--text);
    font-size: 0.9rem;
}
.read-content blockquote p:last-child { margin-bottom: 0; }

.read-content code {
    background: var(--code-bg);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85em;
    font-family: "SF Mono", "Fira Code", "Consolas", monospace;
    color: #79c0ff;
}

.read-content pre {
    margin: 12px 0;
    padding: 14px;
    background: var(--code-bg);
    border-radius: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border);
}

.read-content pre code {
    background: none;
    padding: 0;
    font-size: 0.82rem;
    line-height: 1.6;
    color: var(--text);
}

.read-content table {
    width: 100%;
    margin: 12px 0;
    border-collapse: collapse;
    font-size: 0.82rem;
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.read-content th, .read-content td {
    padding: 8px 10px;
    border: 1px solid var(--border);
    text-align: left;
    white-space: nowrap;
}

.read-content th { background: var(--surface); font-weight: 600; }
.read-content tr:nth-child(even) { background: rgba(255,255,255,0.02); }

.read-content hr { border: none; border-top: 1px solid var(--border); margin: 24px 0; }

.read-content strong { color: #fff; }

/* Collapsible sections for fragmented reading */
.read-content h2 { cursor: pointer; position: relative; padding-right: 30px; }
.read-content h2::after {
    content: '▾';
    position: absolute;
    right: 0;
    color: var(--text-secondary);
    font-size: 0.8em;
    transition: transform 0.2s;
}
.read-content h2.collapsed::after { transform: rotate(-90deg); }
.read-content h2.collapsed + * { display: none; }

/* === Bottom Navigation === */
.read-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 100;
}

.btn-bottom {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 0.8rem;
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.btn-bottom:active { background: var(--border); }

.btn-mark-read {
    background: var(--accent-dim);
    border-color: var(--accent-dim);
    color: #fff;
    font-weight: 600;
}
.btn-mark-read.marked {
    background: var(--green);
    border-color: var(--green);
}

/* === Loading === */
.loading { text-align: center; padding: 40px; color: var(--text-secondary); }

/* === Scroll to top === */
.scroll-top {
    position: fixed;
    bottom: 70px;
    right: 16px;
    width: 40px; height: 40px;
    border-radius: 50%;
    background: var(--accent-dim);
    color: #fff;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    z-index: 99;
    display: none;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.scroll-top:active { transform: scale(0.9); }

/* === Responsive === */
@media (min-width: 768px) {
    .toc { padding: 20px 24px 32px; }
    .toc-card { padding: 18px 20px; }
    .read-content { padding: 24px 24px 100px; }
    .read-content h1 { font-size: 1.8rem; }
}
