:root {
    --bg-color: #f4f1ea;
    /* Rice paper color */
    --text-color: #2c2c2c;
    /* Ink black */
    --accent-color: #b22222;
    /* Seal red */
    --secondary-text: #5d5d5d;
    --card-bg: #ffffff;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
    --font-serif: 'Noto Serif SC', serif;
    --font-sans: 'Noto Sans SC', sans-serif;
    --nav-height: 60px;
    --footer-height: 80px;
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-sans);
    line-height: 1.8;
    -webkit-font-smoothing: antialiased;
    height: 100vh;
    overflow: hidden;
    /* Prevent body scroll, handle in views */
}

#app {
    height: 100%;
    width: 100%;
    position: relative;
}

.view {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow-y: auto;
    background-color: var(--bg-color);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.view.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.98);
    z-index: 0;
}

.view.active {
    opacity: 1;
    pointer-events: auto;
    transform: scale(1);
    z-index: 1;
}

/* Login View Styles */
#login-view {
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: var(--bg-color);
}

.login-container {
    text-align: center;
    background: var(--card-bg);
    padding: 60px;
    border-radius: 8px;
    box-shadow: var(--shadow);
    max-width: 400px;
    width: 90%;
}

.login-box {
    margin-top: 40px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.login-box input {
    padding: 12px;
    font-size: 1rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-family: var(--font-sans);
    outline: none;
    transition: border-color 0.3s;
}

.login-box input:focus {
    border-color: var(--text-color);
}

.login-box button {
    background-color: var(--text-color);
    color: var(--bg-color);
    border: none;
    padding: 12px;
    font-size: 1rem;
    cursor: pointer;
    border-radius: 4px;
    transition: opacity 0.3s;
}

.login-box button:hover {
    opacity: 0.9;
}

.error-msg {
    color: var(--accent-color);
    font-size: 0.9rem;
    min-height: 1.5em;
}

/* Bookshelf Styles */
#bookshelf-view {
    padding: 40px 20px;
}

.main-header {
    text-align: center;
    margin-bottom: 60px;
    border-bottom: 2px solid var(--text-color);
    padding-bottom: 20px;
    position: relative;
    max-width: 1000px;
    margin-left: auto;
    margin-right: auto;
}

.main-header::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 4px;
    background-color: var(--accent-color);
}

.logo {
    font-family: var(--font-serif);
    font-size: 3rem;
    font-weight: 700;
    letter-spacing: 0.2em;
    margin-bottom: 5px;
}

.subtitle {
    font-family: var(--font-serif);
    font-size: 1.2rem;
    color: var(--secondary-text);
    letter-spacing: 0.1em;
    font-style: italic;
}

.books-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 40px;
    max-width: 1000px;
    margin: 0 auto;
}

.book-item {
    cursor: pointer;
    transition: transform 0.3s ease;
    -webkit-tap-highlight-color: transparent;
    /* Remove highlight on tap */
}

@media (hover: hover) {
    .book-item:hover {
        transform: translateY(-10px);
    }
}

.book-item:active {
    transform: scale(0.98);
}

.book-cover {
    background-color: #8b4513;
    /* SaddleBrown */
    height: 280px;
    border-radius: 4px;
    box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.2);
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
    border-left: 10px solid #5d2e0c;
    /* Spine */
}

.book-cover::before {
    content: '';
    position: absolute;
    top: 20px;
    bottom: 20px;
    left: 20px;
    right: 20px;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.book-title-vertical {
    writing-mode: vertical-rl;
    font-family: var(--font-serif);
    color: #fff;
    font-size: 2rem;
    letter-spacing: 0.5em;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.book-author {
    position: absolute;
    bottom: 15px;
    right: 15px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.9rem;
    font-family: var(--font-serif);
}

.book-info {
    margin-top: 15px;
    text-align: center;
}

.book-info h3 {
    font-family: var(--font-serif);
    font-size: 1.2rem;
    margin-bottom: 5px;
}

.book-info p {
    color: var(--secondary-text);
    font-size: 0.9rem;
}

/* Reader Styles */
#reader-view {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.reader-nav {
    height: var(--nav-height);
    background-color: var(--bg-color);
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    flex-shrink: 0;
}

.nav-btn {
    background: none;
    border: none;
    font-family: var(--font-serif);
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    color: var(--text-color);
}

.nav-btn .icon {
    margin-right: 5px;
    font-size: 1.2rem;
}

#reader-title {
    font-family: var(--font-serif);
    font-weight: bold;
    font-size: 1.1rem;
}

.reader-layout {
    flex: 1;
    display: flex;
    overflow: hidden;
}

.reader-content {
    flex: 1;
    overflow-y: auto;
    padding: 40px;
    max-width: 800px;
    /* Limit line length for readability */
    margin: 0 auto;
    /* Center if notes are hidden or on large screen */
}

.reader-notes {
    width: 350px;
    background-color: #fff;
    border-left: 1px solid rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    padding: 20px;
    box-shadow: -5px 0 15px rgba(0, 0, 0, 0.02);
}

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

.notes-header h3 {
    font-family: var(--font-serif);
    font-size: 1.1rem;
}

.notes-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.small-btn {
    font-size: 0.8rem;
    padding: 4px 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    color: var(--secondary-text);
}

.small-btn:hover {
    border-color: var(--text-color);
    color: var(--text-color);
    background: none;
}

#save-status {
    font-size: 0.8rem;
    color: var(--secondary-text);
}

#chapter-notes {
    flex: 1;
    width: 100%;
    border: none;
    resize: none;
    font-family: var(--font-sans);
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text-color);
    background-color: transparent;
    outline: none;
}

.chapter-nav {
    height: var(--footer-height);
    background-color: var(--bg-color);
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 40px;
    flex-shrink: 0;
}

/* Content Styles (Reused) */
.chapter-title {
    font-family: var(--font-serif);
    font-size: 2rem;
    text-align: center;
    margin-bottom: 40px;
    color: var(--text-color);
}

.paragraph-card {
    background: var(--card-bg);
    margin-bottom: 30px;
    border-radius: 8px;
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}

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

.original-text {
    padding: 30px;
    font-family: var(--font-serif);
    font-size: 1.25rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    position: relative;
}

.original-text::before {
    content: '原文';
    position: absolute;
    top: 10px;
    left: 10px;
    font-size: 0.7rem;
    color: var(--accent-color);
    border: 1px solid var(--accent-color);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-sans);
}

.translation-text {
    padding: 30px;
    background-color: rgba(244, 241, 234, 0.3);
    color: var(--secondary-text);
    font-size: 1.1rem;
    position: relative;
}

.translation-text::before {
    content: '译文';
    position: absolute;
    top: 10px;
    left: 10px;
    font-size: 0.7rem;
    color: var(--secondary-text);
    border: 1px solid var(--secondary-text);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-sans);
}

button {
    background: none;
    border: 1px solid var(--text-color);
    padding: 10px 20px;
    font-family: var(--font-serif);
    cursor: pointer;
    transition: all 0.3s ease;
    color: var(--text-color);
}

button:hover:not(:disabled) {
    background: var(--text-color);
    color: var(--bg-color);
}

button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    border-color: var(--secondary-text);
}

#current-chapter-display {
    font-family: var(--font-serif);
    font-weight: bold;
}

/* Responsive */
@media (max-width: 768px) {
    .reader-layout {
        flex-direction: column;
    }

    .reader-notes {
        width: 100%;
        height: 200px;
        /* Fixed height for mobile notes */
        border-left: none;
        border-top: 1px solid rgba(0, 0, 0, 0.1);
    }

    .paragraph-card {
        flex-direction: column;
    }

    .original-text,
    .translation-text {
        border-right: none;
    }

    .chapter-nav {
        padding: 0 10px;
    }

    .chapter-nav button {
        padding: 5px 10px;
        font-size: 0.9rem;
    }
}

@media (min-width: 769px) {
    .paragraph-card {
        flex-direction: row;
    }

    .original-text,
    .translation-text {
        flex: 1;
        border-bottom: none;
    }

    .original-text {
        border-right: 1px solid rgba(0, 0, 0, 0.05);
    }
}