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

:root {
    --bg-color: #f5f5f5;
    --text-color: #333;
    --header-bg: #fff;
    --button-bg: #007bff;
    --button-text: #fff;
    --chapter-title: #2c3e50;
    --border-color: #ddd;
}

body.dark-mode {
    --bg-color: #1a1a1a;
    --text-color: #e0e0e0;
    --header-bg: #2d2d2d;
    --button-bg: #0056b3;
    --button-text: #fff;
    --chapter-title: #4fc3f7;
    --border-color: #444;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    min-height: 100vh;
    transition: background-color 0.3s, color 0.3s;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 0 10px;
}

/* Header */
header {
    background-color: var(--header-bg);
    padding: 15px 0;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    transition: background-color 0.3s, transform 0.3s ease-in-out;
}

header.nav-hidden {
    transform: translateY(-100%);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 15px;
}

h1 {
    font-size: 16px;
    color: var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 60%;
}

.header-buttons {
    display: flex;
    gap: 10px;
    align-items: center;
}

button {
    background-color: var(--button-bg);
    color: var(--button-text);
    border: none;
    padding: 8px 15px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    transition: opacity 0.2s;
}

button:hover {
    opacity: 0.9;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.icon-btn {
    padding: 8px;
    min-width: 36px;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Reading Area */
.reading-area {
    padding: 20px 15px 100px;
    min-height: calc(100vh - 130px);
}

.chapter-number {
    font-size: 14px;
    color: var(--button-bg);
    margin-bottom: 10px;
    text-align: center;
    font-weight: bold;
}

.chapter-content {
    font-size: 18px;
    text-align: justify;
    white-space: pre-line; /* Treat single newlines as breaks, collapse multiple */
    word-wrap: break-word;
    line-height: 1.8;
}

/* Increased line spacing for Chinese text (denser characters) */
body.lang-zh .chapter-content {
    line-height: 1.9;
}

/* Better paragraph spacing within chapter content */
.chapter-content p {
    margin-bottom: 1em;
}

/* Loading State */
.loading {
    text-align: center;
    padding: 50px 20px;
    font-size: 18px;
}

.spinner {
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--button-bg);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Error State */
.error {
    text-align: center;
    padding: 30px 20px;
    color: #d32f2f;
}

.error-btn {
    margin-top: 15px;
}

/* Navigation Footer */
.nav-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: var(--header-bg);
    padding: 10px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    z-index: 99;
    transition: transform 0.3s ease-in-out;
}

.nav-footer.nav-hidden {
    transform: translateY(100%);
}

.nav-info {
    font-size: 12px;
    color: var(--text-color);
    opacity: 0.8;
}

.nav-buttons {
    display: flex;
    gap: 10px;
}

.nav-buttons button {
    flex: 1;
    min-width: 100px;
}

/* Font Size Controls */
.font-controls {
    position: fixed;
    bottom: 15px;
    right: 15px;
    background-color: var(--header-bg);
    border-radius: 30px;
    padding: 5px;
    display: flex;
    gap: 5px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    z-index: 98;
    transition: bottom 0.3s ease;
}

.font-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    padding: 0;
    font-size: 18px;
    font-weight: bold;
}

/* Settings Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0,0,0,0.5);
    z-index: 200;
    overflow: auto;
}

.modal.active {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 20px;
}

.modal-content {
    background-color: var(--header-bg);
    border-radius: 10px;
    padding: 20px;
    width: 100%;
    max-width: 400px;
    margin-top: 50px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-header h2 {
    font-size: 18px;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    color: var(--text-color);
}

/* Definition Panel */
.definition-panel {
    display: none;
    position: fixed;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 20px);
    max-width: 600px;
    max-height: 50vh;
    background-color: var(--header-bg);
    border-radius: 10px;
    box-shadow: 0 -2px 20px rgba(0,0,0,0.3);
    z-index: 150;
    overflow-y: auto;
    transition: opacity 0.3s, transform 0.3s;
}

.definition-panel.active {
    display: block;
}

.def-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    background-color: var(--header-bg);
}

.def-panel-word {
    font-size: 20px;
    font-weight: bold;
    color: var(--button-bg);
}

.def-panel-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-color);
}

.def-panel-content {
    padding: 15px;
}

.def-panel-pinyin {
    font-size: 16px;
    color: var(--text-color);
    opacity: 0.8;
    margin-bottom: 10px;
}

.def-panel-definitions {
    font-size: 16px;
    line-height: 1.6;
}

.def-panel-definition-item {
    margin-bottom: 8px;
    padding-left: 10px;
    border-left: 3px solid var(--button-bg);
}

.def-panel-loading,
.def-panel-error,
.def-panel-empty {
    text-align: center;
    padding: 20px;
    color: var(--text-color);
    opacity: 0.7;
}

.def-panel-word-not-chinese {
    padding: 15px;
    text-align: center;
    color: var(--text-color);
    opacity: 0.7;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 0;
    border-bottom: 1px solid var(--border-color);
}

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

.setting-label {
    font-size: 16px;
}

#chapterInput:focus {
    outline: 2px solid var(--button-bg);
    border-color: var(--button-bg);
}

/* Progress Bar */
.progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    background-color: var(--button-bg);
    width: 0%;
    transition: width 0.3s;
    z-index: 101;
}


/* Responsive adjustments */
@media (max-width: 600px) {
    .chapter-content {
        font-size: 16px;
    }

    h1 {
        font-size: 14px;
    }

    .nav-buttons button {
        min-width: 80px;
        font-size: 12px;
        padding: 8px 10px;
    }
}

/* Hide scrollbar for cleaner look */
.reading-area {
    scrollbar-width: thin;
}
