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

:root {
    --bg: #fafaf8;
    --text: #1a1a1a;
    --text-muted: #666;
    --accent: #2d5a27;
    --border: #e0ddd8;
    --card-bg: #fff;
    --hover: #f5f3ef;
    --audio-bg: #f0efe8;
    --highlight: rgba(45, 90, 39, 0.08);
    --font: 'Georgia', 'Times New Roman', serif;
    --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

[data-theme="dark"] {
    --bg: #1a1a1a;
    --text: #e0ddd8;
    --text-muted: #999;
    --accent: #7cb574;
    --border: #333;
    --card-bg: #242424;
    --hover: #2a2a2a;
    --audio-bg: #242424;
    --highlight: rgba(124, 181, 116, 0.1);
}

html { font-size: 18px; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.7;
    transition: background 0.3s, color 0.3s;
    -webkit-font-smoothing: antialiased;
}

/* ---- Layout ---- */
.container {
    max-width: 720px;
    margin: 0 auto;
    padding: 1rem;
}

/* ---- Header ---- */
.site-header {
    padding: 2rem 1rem 1rem;
    text-align: center;
    border-bottom: 1px solid var(--border);
    margin-bottom: 2rem;
}

.site-header h1 {
    font-size: 1.8rem;
    font-weight: 400;
    letter-spacing: 0.05em;
    margin-bottom: 0.3rem;
}

.site-header .subtitle {
    font-family: var(--font-ui);
    font-size: 0.8rem;
    color: var(--text-muted);
}

.header-controls {
    margin-top: 1rem;
    display: flex;
    justify-content: center;
    gap: 1rem;
    align-items: center;
}

/* ---- Theme toggle ---- */
.theme-toggle {
    background: none;
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    font-family: var(--font-ui);
}

/* ---- Search ---- */
.search-box {
    font-family: var(--font-ui);
    font-size: 0.85rem;
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--card-bg);
    color: var(--text);
    width: 200px;
}

/* ---- Story cards (homepage) ---- */
.story-grid {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.story-card {
    display: block;
    padding: 1.2rem 1rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--card-bg);
    text-decoration: none;
    color: var(--text);
    transition: background 0.2s, border-color 0.2s;
}

.story-card:hover {
    background: var(--hover);
    border-color: var(--accent);
}

.story-card h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.3rem;
}

.story-meta {
    font-family: var(--font-ui);
    font-size: 0.75rem;
    color: var(--text-muted);
}

.audio-badge {
    color: var(--accent);
    font-weight: 600;
}

/* ---- Story page (chapter list) ---- */
.story-info {
    text-align: center;
    margin-bottom: 2rem;
}

.story-info h1 {
    font-size: 1.6rem;
    margin-bottom: 0.3rem;
}

.story-info .meta {
    font-family: var(--font-ui);
    font-size: 0.8rem;
    color: var(--text-muted);
}

.chapter-list {
    list-style: none;
}

.chapter-list li a {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.8rem 0.6rem;
    border-bottom: 1px solid var(--border);
    text-decoration: none;
    color: var(--text);
    transition: background 0.2s;
}

.chapter-list li a:hover {
    background: var(--hover);
}

.ch-num {
    font-family: var(--font-ui);
    font-size: 0.7rem;
    color: var(--text-muted);
    min-width: 3rem;
}

.ch-title {
    flex: 1;
    font-size: 0.95rem;
}

.ch-meta {
    font-family: var(--font-ui);
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ---- Chapter reader ---- */
.chapter-header {
    text-align: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.chapter-header .story-link {
    font-family: var(--font-ui);
    font-size: 0.75rem;
    color: var(--text-muted);
    text-decoration: none;
}

.chapter-header .story-link:hover { color: var(--accent); }

.chapter-header h1 {
    font-size: 1.4rem;
    margin-top: 0.5rem;
    font-weight: 400;
}

.chapter-header .ch-indicator {
    font-family: var(--font-ui);
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ---- Prose content ---- */
.prose p {
    margin-bottom: 1.2rem;
    text-indent: 1.5em;
    cursor: pointer;
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    transition: background 0.2s;
}

.prose p:first-child { text-indent: 0; }

.prose p.active {
    background: var(--highlight);
}

.prose p:hover {
    background: var(--highlight);
}

.prose hr.scene-break {
    border: none;
    text-align: center;
    margin: 2rem 0;
}

.prose hr.scene-break::before {
    content: "* * *";
    color: var(--text-muted);
    font-size: 0.9rem;
    letter-spacing: 0.5em;
}

/* ---- Audio player ---- */
.audio-player {
    position: sticky;
    bottom: 0;
    background: var(--audio-bg);
    border-top: 1px solid var(--border);
    padding: 0.8rem 1rem;
    z-index: 100;
    margin: 2rem -1rem 0;
}

.audio-controls {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.play-btn {
    background: var(--accent);
    color: #fff;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.progress-bar {
    flex: 1;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    cursor: pointer;
    position: relative;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    width: 0%;
    transition: width 0.1s;
}

.time {
    font-family: var(--font-ui);
    font-size: 0.7rem;
    color: var(--text-muted);
    min-width: 80px;
    text-align: right;
    flex-shrink: 0;
}

.speed-btn {
    font-family: var(--font-ui);
    font-size: 0.7rem;
    background: none;
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.2rem 0.5rem;
    border-radius: 3px;
    cursor: pointer;
    flex-shrink: 0;
}

.sync-hint {
    font-family: var(--font-ui);
    font-size: 0.65rem;
    color: var(--text-muted);
    text-align: center;
    margin-top: 0.4rem;
}

/* ---- Chapter navigation ---- */
.chapter-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 0;
    margin-top: 2rem;
    border-top: 1px solid var(--border);
    font-family: var(--font-ui);
    font-size: 0.85rem;
}

.chapter-nav a {
    color: var(--accent);
    text-decoration: none;
}

.chapter-nav a:hover { text-decoration: underline; }

/* ---- Back link ---- */
.back-link {
    font-family: var(--font-ui);
    font-size: 0.8rem;
    color: var(--text-muted);
    text-decoration: none;
    display: inline-block;
    margin-bottom: 1.5rem;
}

.back-link:hover { color: var(--accent); }

/* ---- Reading progress bar ---- */
.reading-progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    background: var(--accent);
    z-index: 200;
    transition: width 0.1s;
}

/* ---- Mobile ---- */
@media (max-width: 600px) {
    html { font-size: 16px; }
    .container { padding: 0.8rem; }
    .site-header { padding: 1.5rem 0.8rem 0.8rem; }
    .site-header h1 { font-size: 1.4rem; }
    .chapter-header h1 { font-size: 1.2rem; }
    .audio-controls { gap: 0.5rem; }
    .time { min-width: 60px; font-size: 0.65rem; }
    .search-box { width: 140px; }
}
