/* ============================================
   StoryVault - Theme System & Layout
   ============================================ */

/* ---------- CSS Variables (Themes) ---------- */
:root,
.theme-light {
    --bg: #f8f9fa;
    --bg-card: #ffffff;
    --bg-nav: #2c3e50;
    --text: #1a1a2e;
    --text-muted: #6c757d;
    --text-nav: #ecf0f1;
    --border: #dee2e6;
    --accent: #6c5ce7;
    --accent-hover: #5a4bd1;
    --danger: #e74c3c;
    --success: #27ae60;
    --radius: 8px;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --reader-bg: #ffffff;
    --reader-text: #1a1a2e;
    --reader-width: 720px;
}

.theme-dark {
    --bg: #1a1a2e;
    --bg-card: #16213e;
    --bg-nav: #0f3460;
    --text: #e8e8e8;
    --text-muted: #a0a0b0;
    --text-nav: #e8e8e8;
    --border: #2a2a4a;
    --accent: #a29bfe;
    --accent-hover: #8c84f5;
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
    --reader-bg: #16213e;
    --reader-text: #e8e8e8;
}

.theme-sepia {
    --bg: #f5ecd7;
    --bg-card: #faf3e0;
    --bg-nav: #8b6914;
    --text: #3e2c1a;
    --text-muted: #7a6a5a;
    --text-nav: #faf3e0;
    --border: #d4c5a9;
    --accent: #8b6914;
    --accent-hover: #7a5d12;
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
    --reader-bg: #faf3e0;
    --reader-text: #3e2c1a;
}

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

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

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
img { max-width: 100%; height: auto; }

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 20px;
}

/* ---------- Navbar ---------- */
.navbar {
    background: var(--bg-nav);
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.nav-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 56px;
}

.logo {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--text-nav) !important;
    letter-spacing: -0.5px;
}

.nav-links { display: flex; gap: 20px; align-items: center; }
.nav-links a {
    color: var(--text-nav);
    font-size: 0.9rem;
    font-weight: 500;
    opacity: 0.85;
}
.nav-links a:hover { opacity: 1; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-block;
    padding: 8px 18px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text);
    cursor: pointer;
    transition: all 0.15s;
    text-align: center;
}
.btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}
.btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.btn-primary:hover {
    background: var(--accent-hover);
    color: #fff;
}
.btn-sm { padding: 5px 12px; font-size: 0.8rem; }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-disabled { opacity: 0.5; cursor: default; pointer-events: none; }

/* ---------- Hero ---------- */
.hero {
    text-align: center;
    padding: 50px 0 30px;
}
.hero h1 { font-size: 2.2rem; margin-bottom: 8px; }
.hero p { color: var(--text-muted); font-size: 1.1rem; }

.genre-pills {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 20px;
}
.pill {
    padding: 6px 16px;
    border-radius: 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    font-size: 0.85rem;
    color: var(--text-muted);
}
.pill.active, .pill:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- Story Grid (Discover) ---------- */
.story-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 24px;
    padding: 20px 0 60px;
}

.story-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: transform 0.15s;
}
.story-card:hover { transform: translateY(-3px); }
.story-card a { color: inherit; }

.story-cover {
    aspect-ratio: 3 / 4;
    overflow: hidden;
    background: var(--border);
}
.story-cover img { width: 100%; height: 100%; object-fit: cover; }

.cover-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--text-nav);
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
}

.story-info { padding: 14px; }
.story-info h3 { font-size: 1rem; margin-bottom: 4px; }
.story-author { font-size: 0.85rem; color: var(--text-muted); }
.story-meta { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }

/* ---------- Forms ---------- */
form { display: flex; flex-direction: column; gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); }
.form-note { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }
.form-row { display: flex; gap: 16px; }
.form-row .form-group { flex: 1; }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="file"],
textarea,
select {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color 0.15s;
}
input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--accent);
}

/* ---------- Alerts ---------- */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    margin-bottom: 16px;
}
.alert-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.alert-error { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }

/* ---------- Modal ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}
.modal {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 32px;
    width: 100%;
    max-width: 400px;
    position: relative;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}
.modal h2 { margin-bottom: 20px; }
.modal-close {
    position: absolute;
    top: 12px;
    right: 16px;
    font-size: 1.5rem;
    color: var(--text-muted);
}
.modal-footer { text-align: center; margin-top: 16px; font-size: 0.9rem; }
.modal-footer a { font-weight: 600; }

/* ---------- Reader View ---------- */
.reader-container {
    max-width: var(--reader-width);
    margin: 0 auto;
    padding: 30px 20px 80px;
}

.reader-header { text-align: center; margin-bottom: 30px; }
.reader-header h1 { font-size: 1.8rem; }
.reader-actions {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    margin-top: 12px;
    flex-wrap: wrap;
}

.theme-switcher {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.theme-btn {
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 0.8rem;
    border: 1px solid var(--border);
    color: var(--text-muted);
}
.theme-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* Chapter Navigation */
.chapter-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 30px;
}
.chapter-nav.bottom { margin-top: 40px; margin-bottom: 0; }
.chapter-select {
    padding: 6px 10px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text);
    font-size: 0.85rem;
    max-width: 250px;
}

/* Chapter Content */
.chapter-content {
    background: var(--reader-bg);
    padding: 40px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    line-height: 1.9;
    font-size: 1.05rem;
}
.chapter-content h2 {
    font-size: 1.5rem;
    margin-bottom: 24px;
    text-align: center;
}
.content-body {
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* ---------- Dashboard ---------- */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 30px 0 20px;
}

.story-form {
    background: var(--bg-card);
    padding: 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 30px;
}
.story-form h2 { margin-bottom: 16px; font-size: 1.2rem; }

.story-list { margin-top: 10px; }
.story-list-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 12px;
}
.story-list-cover {
    width: 60px;
    height: 80px;
    flex-shrink: 0;
    border-radius: 4px;
    overflow: hidden;
    background: var(--border);
}
.story-list-cover img { width: 100%; height: 100%; object-fit: cover; }
.cover-placeholder.small {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: #fff;
}
.story-list-info { flex: 1; }
.story-list-info h3 { font-size: 1rem; }
.story-list-info h3 a { color: var(--text); }
.story-list-info h3 a:hover { color: var(--accent); }

.story-list-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* Badges */
.badge {
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 10px;
    text-transform: uppercase;
    font-weight: 600;
}
.badge-draft { background: #ffeaa7; color: #6b5b00; }
.badge-published { background: #a8e6cf; color: #1a6b3c; }

/* ---------- Editor ---------- */
.editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 0 20px;
}

.editor-layout {
    display: flex;
    gap: 24px;
    align-items: flex-start;
}

.chapter-sidebar {
    width: 300px;
    flex-shrink: 0;
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}
.chapter-sidebar h2, .chapter-sidebar h3 { font-size: 1rem; margin-bottom: 12px; }

.chapter-list { list-style: none; margin-bottom: 20px; }
.chapter-list li {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.88rem;
}
.drag-handle { cursor: grab; color: var(--text-muted); }
.chapter-link { flex: 1; color: var(--text); }
.chapter-link.active { color: var(--accent); font-weight: 600; }
.view-link { color: var(--text-muted); font-size: 0.85rem; }

.chapter-editor {
    flex: 1;
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
}
.chapter-editor h2 { font-size: 1.2rem; margin-bottom: 16px; }

/* ---------- Utilities ---------- */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
    .story-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 16px; }
    .editor-layout { flex-direction: column; }
    .chapter-sidebar { width: 100%; }
    .chapter-content { padding: 24px; }
    .form-row { flex-direction: column; }
    .story-list-item { flex-wrap: wrap; }
    .nav-links { gap: 12px; font-size: 0.85rem; }
}
