/* Base Reset */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Dark Mode Variables */
:root {
    --bg-color: #FBFBF9;
    --text-color: #333;
    --card-bg: #fff;
    --header-bg: #fff;
    --border-color: #eee;
    --tooltip-bg: rgba(0, 0, 0, 0.85);
    --tooltip-text: #fff;
    --modal-overlay: rgba(0, 0, 0, 0.5);
    --btn-hover: #f5f5f5;
}

body.dark-mode {
    --bg-color: #121212;
    --text-color: #E0E0E0;
    --card-bg: #1E1E1E;
    --header-bg: #1E1E1E;
    --border-color: #333;
    --tooltip-bg: rgba(255, 255, 255, 0.9);
    --tooltip-text: #121212;
    --modal-overlay: rgba(0, 0, 0, 0.7);
    --btn-hover: #2a2a2a;
}

body {
    font-family: 'Noto Serif KR', serif;
    background-color: var(--bg-color);
    /* KakaoPage paper color or dark mode */
    color: var(--text-color);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.3s, color 0.3s;
}

/* Views Management */
.view-container {
    display: none;
    min-height: 100vh;
}

.view-container.active {
    display: flex;
    flex-direction: column;
}

/* Home / Library View */
.home-header {
    padding: 20px;
    background-color: var(--header-bg);
    border-bottom: 1px solid var(--border-color);
}

.header-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.home-header h1 {
    font-size: 20px;
    font-weight: 500;
}

.library-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 16px;
    padding: 20px;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.novel-card {
    background: var(--card-bg);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    cursor: pointer;
    transition: transform 0.2s, background-color 0.3s;
    display: flex;
    flex-direction: column;
    position: relative;
}

.novel-card:hover {
    transform: translateY(-4px);
}

.btn-info-card {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    backdrop-filter: blur(2px);
    z-index: 2;
}

.btn-info-card:hover {
    background: rgba(0, 0, 0, 0.8);
}

.novel-cover {
    width: 100%;
    aspect-ratio: 2/3;
    object-fit: cover;
    background-color: #eee;
    display: block;
    /* Ensure no inline-block gaps */
}

.novel-info {
    padding: 12px;
}

.novel-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
    /* Multiline ellipsis */
    display: -webkit-box;
    line-clamp: 2;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.novel-author {
    font-size: 12px;
    color: #666;
}

/* Viewer View */
.viewer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background-color: var(--header-bg);
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    border-bottom: 1px solid var(--border-color);
    transition: transform 0.3s ease;
}

.viewer-header.ui-hidden {
    transform: translateY(-100%);
}

.viewer-header h2 {
    font-size: 16px;
    font-weight: 500;
    max-width: 65vw;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-color);
    transition: color 0.3s;
}

.btn-icon.bookmarked {
    color: #ffd700;
    fill: #ffd700;
}

.viewer-content {
    flex-grow: 1;
    padding: 24px 20px 60px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    /* KakaoPage reading style */
    font-size: 18px;
    /* Larger text for reading */
    line-height: 1.8;
    color: var(--text-color);
    word-break: break-all;
    /* better wrap for korean */
    padding-bottom: 90px;
    /* Space for the floating footer */
}

.viewer-content p {
    margin-bottom: 24px;
    text-indent: 14px;
    /* Korean novel style indent */
}

.viewer-content h1,
.viewer-content h2,
.viewer-content h3 {
    margin-top: 1.5em;
    margin-bottom: 1em;
    font-weight: 600;
    font-size: 1.25em;
    text-indent: 0;
}

/* Term Tag Interaction */
span.term {
    border-bottom: 1.5px dashed #999;
    cursor: pointer;
    position: relative;
    color: inherit;
    padding-bottom: 2px;
}

span.term:hover,
span.term:active {
    color: #e74c3c;
    border-bottom-color: #e74c3c;
}

/* Tooltip */
.term-tooltip {
    position: fixed;
    top: 60px;
    /* Moved to top */
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--tooltip-bg);
    color: var(--tooltip-text);
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 14px;
    max-width: 90vw;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    text-align: left;
    /* Left align requested */
    transition: opacity 0.3s ease, top 0.3s ease;
    opacity: 1;
    line-height: 1.5;
    pointer-events: none;
    /* Let clicks pass through */
}

.term-tooltip.hidden {
    opacity: 0;
    top: 40px;
    pointer-events: none;
}

/* Footer Navigation */
.viewer-footer {
    display: flex;
    justify-content: space-between;
    padding: 16px 20px;
    background-color: var(--bg-color);
    max-width: 800px;
    width: 100%;
    border-top: 1px solid var(--border-color);
    transition: background-color 0.3s, transform 0.3s ease;
    position: fixed;
    /* Stick footer to bottom */
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
}

.viewer-footer.ui-hidden {
    transform: translate(-50%, 100%);
}

.viewer-footer.ui-hidden {
    transform: translate(-50%, 100%);
}

.btn-nav {
    padding: 10px 20px;
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    font-family: 'Noto Serif KR', serif;
    font-weight: 500;
    transition: background-color 0.3s, color 0.3s;
}

.btn-nav:hover {
    background-color: var(--btn-hover);
}

.btn-nav:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Responsive adjust for PC */
@media (min-width: 768px) {
    .viewer-content {
        font-size: 20px;
        padding: 40px 60px 80px;
    }

    .library-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
        gap: 24px;
    }


    .term-tooltip {
        max-width: 400px;
    }
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--modal-overlay);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
    transition: opacity 0.3s;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: var(--card-bg);
    padding: 24px;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    color: var(--text-color);
}

.close-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
    color: #999;
}

.close-btn:hover {
    color: var(--text-color);
}

/* Info Modal Typography */
.info-title {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 8px;
}

.info-author {
    font-size: 14px;
    color: #666;
    margin-bottom: 16px;
}

.info-desc {
    font-size: 14px;
    line-height: 1.6;
    margin-bottom: 20px;
    white-space: pre-wrap;
}

.info-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.info-badge {
    background: var(--btn-hover);
    padding: 4px 10px;
    border-radius: 16px;
    font-size: 12px;
    color: var(--text-color);
}

/* Bookmarks List */
#bookmarks-list {
    list-style: none;
    margin-top: 16px;
}

#bookmarks-list li {
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
}

#bookmarks-list li:hover {
    background-color: var(--btn-hover);
}