:root {
    --bg-color: #f4f4f4;
    --text-color: #333;
    --header-bg: #fff;
    --card-bg: #fff;
    --primary-color: #d32f2f;
    /* Reddish tone like reference */
    --link-color: #333;
    --meta-color: #666;
    --border-color: #ddd;
    --shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    --font-main: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

[data-theme="dark"] {
    --bg-color: #1a1a1a;
    --text-color: #e0e0e0;
    --header-bg: #2d2d2d;
    --card-bg: #2d2d2d;
    --primary-color: #ff5252;
    --link-color: #e0e0e0;
    --meta-color: #aaa;
    --border-color: #444;
    --shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

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

body {
    font-family: var(--font-main);
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    transition: background-color 0.3s, color 0.3s;
}

a {
    text-decoration: none;
    color: var(--link-color);
}

a:hover {
    color: var(--primary-color);
}

/* Header */
header {
    background-color: var(--header-bg);
    padding: 1rem;
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo {
    font-weight: bold;
    font-size: 1.2rem;
    color: var(--primary-color);
}

.theme-toggle {
    background: none;
    border: 1px solid var(--border-color);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-color);
    font-size: 0.9rem;
}

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

/* Index - Grid */
.story-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.story-card {
    background: var(--card-bg);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: transform 0.2s;
    display: flex;
    flex-direction: column;
}

.story-card:hover {
    transform: translateY(-2px);
}

.story-cover {
    width: 100%;
    aspect-ratio: 3/4;
    object-fit: cover;
}

.story-info {
    padding: 0.5rem;
}

.story-title {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Story Detail */
.story-header {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    background: var(--card-bg);
    padding: 1rem;
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.detail-cover {
    width: 120px;
    height: 160px;
    object-fit: cover;
    border-radius: 4px;
    flex-shrink: 0;
}

.detail-info {
    flex: 1;
}

.detail-title {
    font-size: 1.4rem;
    margin-bottom: 0.5rem;
    color: var(--primary-color);
}

.detail-meta {
    font-size: 0.9rem;
    color: var(--meta-color);
    margin-bottom: 0.25rem;
}

.read-btn {
    display: inline-block;
    background: var(--primary-color);
    color: white;
    padding: 0.5rem 1.5rem;
    border-radius: 20px;
    margin-top: 0.5rem;
    font-size: 0.9rem;
    font-weight: 500;
}

.read-btn:hover {
    color: white;
    opacity: 0.9;
}

.story-summary {
    background: var(--card-bg);
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
    text-align: justify;
}

.chapter-list {
    background: var(--card-bg);
    border-radius: 8px;
    padding: 0.5rem 0;
    box-shadow: var(--shadow);
}

.chapter-item {
    display: block;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

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

.chapter-item:hover {
    background-color: rgba(0, 0, 0, 0.05);
    color: var(--primary-color);
}

/* Reading Page */
.reading-container {
    max-width: 900px;
    margin: 0 auto;
    background: var(--card-bg);
    min-height: 100vh;
    padding: 2rem 1rem;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.05);
}

.chapter-title {
    text-align: center;
    margin-bottom: 2rem;
    color: var(--primary-color);
}

.chapter-content {
    font-size: 1.2rem;
    line-height: 1.8;
    margin-bottom: 3rem;
    padding: 0 0.5rem;
    text-align: justify;
}

.chapter-nav {
    display: flex;
    justify-content: space-between;
    padding-top: 2rem;
    border-top: 1px solid var(--border-color);
}

.nav-btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-color);
    cursor: pointer;
}

.nav-btn.disabled {
    opacity: 0.5;
    pointer-events: none;
    cursor: default;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: 0.3s;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: 8px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.modal-title {
    margin-bottom: 1rem;
    color: var(--primary-color);
}

.modal-text {
    margin-bottom: 1.5rem;
}

.shopee-btn {
    display: inline-block;
    background: #FF5722;
    color: white;
    padding: 0.75rem 2rem;
    border-radius: 4px;
    text-transform: uppercase;
    font-weight: bold;
    border: none;
    cursor: pointer;
}

.shopee-btn:hover {
    color: white;
    background: #E64A19;
}

.modal-close {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    color: var(--text-color);
    line-height: 1;
}

.modal-close:hover {
    color: var(--primary-color);
}

/* Mobile Responsiveness */
@media (max-width: 600px) {
    .story-header {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }

    .detail-info {
        width: 100%;
    }

    .detail-title {
        font-size: 1.2rem;
    }
}