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

:root {
    --text-color: #2c2c2c;
    --bg-color: #fdfbf7;
    --muted-color: #888;
    --border-color: #e0ddd5;
    --highlight-color: #f5f0e6;
    --font-serif: 'EB Garamond', Georgia, serif;
    --font-size-body: 1.2rem;
    --line-height: 1.7;
    --column-gap: 4rem;
    --page-padding: 3rem;
    --gutter-width: clamp(2.5rem, 6vw, 6rem);
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: var(--font-serif);
    font-size: var(--font-size-body);
    line-height: var(--line-height);
    color: var(--text-color);
    background-color: var(--bg-color);
}

.view {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.hidden {
    display: none !important;
}

/* Library View */
#library-view {
    padding: var(--page-padding);
    overflow-y: auto;
}

.library-container {
    max-width: 500px;
    margin: 0 auto;
    width: 100%;
}

.library-title {
    font-size: 2.5rem;
    font-weight: 400;
    margin-bottom: 1.5rem;
    letter-spacing: 0.02em;
    text-align: center;
}

.library-search-container {
    position: relative;
    margin-bottom: 2rem;
}

.library-search {
    width: 100%;
    padding: 0.75rem 1rem;
    padding-left: 2.5rem;
    font-family: var(--font-serif);
    font-size: 1.1rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: transparent;
    color: var(--text-color);
    transition: border-color 0.2s;
}

.library-search:focus {
    outline: none;
    border-color: var(--muted-color);
}

.library-search::placeholder {
    color: var(--muted-color);
}

.library-search-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted-color);
    pointer-events: none;
}

.section-title {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--muted-color);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 0.75rem;
}

.recently-read {
    margin-bottom: 2rem;
}

.book-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.book-item {
    padding: 1rem 1.25rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s;
}

.book-item:hover {
    background-color: var(--highlight-color);
    border-color: var(--muted-color);
}

.book-item-title {
    font-size: 1.15rem;
    font-weight: 500;
    margin-bottom: 0.2rem;
}

.book-item-author {
    font-size: 0.95rem;
    color: var(--muted-color);
    font-style: italic;
}

.no-results {
    text-align: center;
    color: var(--muted-color);
    font-style: italic;
    padding: 2rem;
}

/* Reader View */
#reader-view {
    padding: var(--page-padding);
    padding-top: 1rem;
    padding-bottom: 1rem;
}

.reader-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1rem;
    flex-shrink: 0;
}

.cache-only-indicator {
    padding: 0.2rem 0.55rem;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted-color);
    background: rgba(0, 0, 0, 0.04);
}

#reader-view.speed-reading-active .reader-content,
#reader-view.speed-reading-active .chapter-title,
#reader-view.speed-reading-active .reader-footer {
    display: none;
}

#reader-view.speed-reading-active .reader-gutter {
    display: none;
}

.header-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--muted-color);
    padding: 0.5rem;
    border-radius: 4px;
    transition: color 0.2s, background-color 0.2s;
}

.header-btn:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.header-btn:hover {
    color: var(--text-color);
    background-color: var(--highlight-color);
}

.header-btn.active {
    color: var(--text-color);
    background-color: var(--highlight-color);
}

.book-title {
    flex: 1;
    font-size: 1.1rem;
    font-weight: 500;
    letter-spacing: 0.02em;
}

.search-container {
    position: relative;
    width: 200px;
}

.search-input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    padding-left: 2rem;
    font-family: var(--font-serif);
    font-size: 0.95rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: transparent;
    color: var(--text-color);
    transition: border-color 0.2s;
}

.search-input:focus {
    outline: none;
    border-color: var(--muted-color);
}

.search-input::placeholder {
    color: var(--muted-color);
}

.search-icon {
    position: absolute;
    left: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted-color);
    pointer-events: none;
}

.search-results {
    position: absolute;
    top: 80px;
    left: var(--page-padding);
    right: var(--page-padding);
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.search-result-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
}

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

.search-result-item:hover {
    background-color: var(--highlight-color);
}

.search-result-chapter {
    font-size: 0.85rem;
    color: var(--muted-color);
    margin-bottom: 0.25rem;
}

.search-result-snippet {
    font-size: 0.95rem;
}

.search-result-snippet mark {
    background-color: #fff3cd;
    padding: 0 2px;
}

.chapter-title {
    font-size: 1.5rem;
    font-weight: 400;
    text-align: center;
    margin-bottom: 1.5rem;
    flex-shrink: 0;
}

/* Two-column reading area */
.reader-stage {
    flex: 1;
    display: flex;
    min-height: 0;
}

.reader-gutter {
    width: var(--gutter-width);
    border: none;
    background: linear-gradient(90deg, rgba(245, 240, 230, 0.65), rgba(245, 240, 230, 0));
    cursor: pointer;
    padding: 0;
    transition: background-color 0.2s, opacity 0.2s;
}

.reader-gutter-left {
    background: linear-gradient(90deg, rgba(245, 240, 230, 0.65), rgba(245, 240, 230, 0));
}

.reader-gutter-right {
    background: linear-gradient(270deg, rgba(245, 240, 230, 0.65), rgba(245, 240, 230, 0));
}

.reader-gutter:hover,
.reader-gutter:focus-visible {
    background-color: var(--highlight-color);
    outline: none;
}

.reader-gutter:active {
    opacity: 0.8;
}

.reader-content {
    flex: 1;
    display: flex;
    gap: var(--column-gap);
    overflow: hidden;
    min-height: 0;
}

.column {
    flex: 1;
    overflow: hidden;
}

.paragraph {
    text-indent: 1.5em;
    margin-bottom: 0;
    text-align: justify;
    hyphens: auto;
    cursor: pointer;
}

.paragraph:first-child {
    text-indent: 0;
}

.paragraph.highlighted {
    background-color: var(--highlight-color);
    margin-left: -0.5rem;
    margin-right: -0.5rem;
    padding: 0.25rem 0.5rem;
    border-radius: 2px;
}

/* Footer */
.reader-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    margin-top: 1rem;
    flex-shrink: 0;
}

.nav-hint {
    font-size: 0.8rem;
    color: var(--muted-color);
}

kbd {
    display: inline-block;
    padding: 0.1rem 0.4rem;
    font-family: var(--font-serif);
    font-size: 0.75rem;
    background-color: var(--highlight-color);
    border: 1px solid var(--border-color);
    border-radius: 3px;
    margin: 0 0.1rem;
}

.page-indicator {
    font-size: 0.85rem;
    color: var(--muted-color);
}

/* No content message */
.no-content {
    text-align: center;
    color: var(--muted-color);
    font-style: italic;
    margin-top: 2rem;
}

/* Imported badge */
.imported-badge {
    display: inline-block;
    margin-left: 0.5rem;
    color: #5a8f5a;
    font-size: 0.9em;
}

.book-item.imported {
    border-color: #c5dfc5;
}

/* Importing overlay */
#importing-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(253, 251, 247, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
}

#importing-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.importing-message {
    font-size: 1.3rem;
    color: var(--text-color);
    font-style: italic;
}

.importing-message::after {
    content: '';
    animation: ellipsis 1.5s infinite;
}

@keyframes ellipsis {
    0% { content: ''; }
    25% { content: '.'; }
    50% { content: '..'; }
    75% { content: '...'; }
}

/* Chapter list overlay */
.chapter-list-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(253, 251, 247, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.chapter-list-container {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
    max-width: 500px;
    width: 90%;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
}

.chapter-list-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.chapter-list-header h3 {
    font-size: 1.3rem;
    font-weight: 500;
    margin: 0 0 0.25rem 0;
}

.chapter-list-hint {
    font-size: 0.8rem;
    color: var(--muted-color);
}

.chapter-list {
    list-style: none;
    margin: 0;
    padding: 0.5rem 0;
    overflow-y: auto;
    flex: 1;
}

.chapter-list-item {
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    transition: background-color 0.15s;
    display: flex;
    align-items: baseline;
    gap: 0.75rem;
}

.chapter-list-item:hover {
    background-color: var(--highlight-color);
}

.chapter-list-item.selected {
    background-color: var(--highlight-color);
}

.chapter-list-item.current {
    font-weight: 500;
}

.chapter-list-item.current::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    background-color: var(--text-color);
    border-radius: 50%;
    margin-right: 0.5rem;
}

.chapter-number {
    color: var(--muted-color);
    font-size: 0.85rem;
    min-width: 2rem;
}

.chapter-name {
    flex: 1;
}

/* Voice notification */
.voice-notification {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    padding: 1rem 1.25rem;
    max-width: 350px;
    z-index: 1001;
    animation: slideIn 0.3s ease;
}

.voice-notification-content {
    font-size: 0.9rem;
    line-height: 1.5;
}

.voice-notification-content strong {
    color: var(--text-color);
}

.voice-notification-content small {
    color: var(--muted-color);
    display: block;
    margin-top: 0.25rem;
}

.voice-notification.fade-out {
    opacity: 0;
    transition: opacity 0.5s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* TTS container and speed indicator */
.tts-container {
    position: relative;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.25rem;
}

.speed-reading-container {
    display: flex;
    align-items: center;
}

.tts-speed {
    font-size: 0.6rem;
    color: var(--muted-color);
}

.tts-speed:empty {
    display: none;
}

.tts-mode {
    font-size: 0.55rem;
    color: var(--muted-color);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    padding: 1px 3px;
    border-radius: 2px;
    background: rgba(0,0,0,0.05);
}

.tts-mode:empty {
    display: none;
}

.tts-mode.openai {
    color: #10a37f;
    background: rgba(16, 163, 127, 0.1);
}

.tts-mode.browser {
    color: #666;
    background: rgba(0,0,0,0.08);
}

/* Speed notification */
.speed-notification {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    font-size: 2rem;
    font-weight: 500;
    padding: 1rem 2rem;
    border-radius: 12px;
    z-index: 1002;
    animation: fadeInScale 0.15s ease;
}

.speed-notification.fade-out {
    opacity: 0;
    transition: opacity 0.3s ease;
}

@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.8);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

/* ========================================
   Illustration Mode Styles
   ======================================== */

/* Illustration toggle button active state */
.illustration-container .header-btn.active {
    background: var(--highlight-color);
}

.illustration-container .header-btn.active svg {
    fill: var(--text-color);
    fill-opacity: 0.15;
}

/* Illustration column */
.illustration-column {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    min-height: 0;
}

.illustration-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

/* Skeleton placeholder */
.illustration-skeleton {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--highlight-color);
    border-radius: 4px;
    position: relative;
    overflow: hidden;
}

.skeleton-shimmer {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.4) 50%,
        transparent 100%
    );
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.skeleton-text {
    position: relative;
    z-index: 1;
    color: var(--muted-color);
    font-style: italic;
    font-size: 0.9rem;
}

/* Illustration error state */
.illustration-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    color: var(--muted-color);
    font-style: italic;
}

.illustration-error svg {
    opacity: 0.5;
}

/* Style notification (similar to voice notification) */
.style-notification {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    padding: 1rem 1.25rem;
    max-width: 350px;
    z-index: 1001;
    animation: slideIn 0.3s ease;
}

.style-notification-content {
    font-size: 0.9rem;
    line-height: 1.4;
}

.style-notification-content small {
    color: var(--muted-color);
}

.style-notification.fade-out {
    opacity: 0;
    transform: translateX(20px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

/* Make illustration image clickable when prompt editing is enabled */
.illustration-image.editable {
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.illustration-image.editable:hover {
    transform: scale(1.02);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
}

/* ========================================
   Speed Reading Styles
   ======================================== */

.speed-reading-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2rem;
    background: #000;
    color: #fff;
    z-index: 120;
}

.speed-reading-stage {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    width: min(700px, 90vw);
}

.speed-reading-word {
    font-size: 3.5rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    color: #fff;
}

.speed-reading-word .pivot {
    color: #c0392b;
}

.speed-reading-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    color: #fff;
}

.speed-reading-play {
    border: 1px solid #fff;
    background: #fff;
    color: #000;
    padding: 0.5rem 1rem;
    border-radius: 999px;
    cursor: pointer;
}

.speed-reading-exit {
    border: 1px solid #fff;
    background: transparent;
    color: #fff;
    padding: 0.5rem 1.2rem;
    border-radius: 999px;
    cursor: pointer;
}

.speed-reading-slider {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.95rem;
    color: #fff;
}

.speed-reading-slider input[type="range"] {
    accent-color: #c0392b;
}

.speed-reading-wpm {
    min-width: 80px;
    text-align: right;
    color: #fff;
}

.speed-reading-chapter-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 130;
}

.speed-reading-chapter-card {
    border: 1px solid #333;
    background: #111;
    color: #fff;
    padding: 2rem 2.5rem;
    border-radius: 12px;
    text-align: center;
    width: min(480px, 90vw);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.08);
}

.speed-reading-chapter-card h3 {
    font-size: 1.6rem;
    margin-bottom: 1.5rem;
}

.speed-reading-chapter-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.speed-reading-btn {
    border-radius: 999px;
    padding: 0.6rem 1.4rem;
    font-size: 0.95rem;
    border: 1px solid #fff;
    cursor: pointer;
}

.speed-reading-btn-primary {
    background: #fff;
    color: #000;
    border-color: #fff;
}

.speed-reading-btn-secondary {
    background: transparent;
    color: #fff;
}

/* ========================================
   Prompt Editing Modal
   ======================================== */

.prompt-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.prompt-modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
}

.prompt-modal-container {
    position: relative;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    animation: modalSlideIn 0.2s ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.prompt-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.prompt-modal-header h3 {
    font-size: 1.2rem;
    font-weight: 500;
    margin: 0;
}

.prompt-modal-close {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--muted-color);
    padding: 0.25rem;
    border-radius: 4px;
    transition: color 0.2s, background-color 0.2s;
}

.prompt-modal-close:hover {
    color: var(--text-color);
    background-color: var(--highlight-color);
}

.prompt-modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.prompt-modal-hint {
    font-size: 0.9rem;
    color: var(--muted-color);
    margin-bottom: 1rem;
    line-height: 1.5;
}

.prompt-textarea {
    width: 100%;
    padding: 1rem;
    font-family: var(--font-serif);
    font-size: 1rem;
    line-height: 1.6;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: white;
    color: var(--text-color);
    resize: vertical;
    min-height: 150px;
    transition: border-color 0.2s;
}

.prompt-textarea:focus {
    outline: none;
    border-color: var(--muted-color);
}

.prompt-textarea::placeholder {
    color: var(--muted-color);
    font-style: italic;
}

.prompt-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
}

.prompt-btn {
    padding: 0.6rem 1.25rem;
    font-family: var(--font-serif);
    font-size: 0.95rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.prompt-btn-secondary {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--muted-color);
}

.prompt-btn-secondary:hover {
    border-color: var(--muted-color);
    color: var(--text-color);
}

.prompt-btn-primary {
    background: var(--text-color);
    border: 1px solid var(--text-color);
    color: var(--bg-color);
}

.prompt-btn-primary:hover {
    background: #1a1a1a;
}

.prompt-btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Generating mode */
.prompt-generating {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
    gap: 1rem;
    color: var(--muted-color);
    font-style: italic;
}

.prompt-generating-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--text-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Preview mode */
.prompt-preview-container {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem;
    background: var(--highlight-color);
    border-radius: 6px;
    min-height: 200px;
    max-height: 400px;
}

.prompt-preview-image {
    max-width: 100%;
    max-height: 380px;
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* ========================================
   Character Feature Styles
   ======================================== */

/* Character Toast Notification */
.character-toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    display: flex;
    align-items: stretch;
    max-width: 400px;
    z-index: 1500;
    animation: toastSlideIn 0.4s ease;
    overflow: hidden;
}

.character-toast-portrait {
    width: 80px;
    min-height: 100px;
    flex-shrink: 0;
    position: relative;
    background: var(--highlight-color);
}

.character-toast-portrait img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.character-toast-content {
    padding: 1rem;
    flex: 1;
    min-width: 0;
}

.character-toast-title {
    font-size: 0.75rem;
    color: var(--muted-color);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
}

.character-toast-name {
    font-size: 1.1rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.character-toast-desc {
    font-size: 0.85rem;
    color: var(--muted-color);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.character-toast-close {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--muted-color);
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    line-height: 1;
}

.character-toast-close:hover {
    color: var(--text-color);
}

.character-toast.fade-out {
    opacity: 0;
    transform: translateX(20px);
    transition: all 0.4s ease;
}

@keyframes toastSlideIn {
    from { opacity: 0; transform: translateX(100%); }
    to { opacity: 1; transform: translateX(0); }
}

/* Character Modal (shared styles for browser and chat) */
.character-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.character-modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
}

.character-modal-container {
    position: relative;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    animation: modalSlideIn 0.2s ease;
}

.character-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.character-modal-header h3 {
    font-size: 1.2rem;
    font-weight: 500;
    margin: 0;
}

.character-modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--muted-color);
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    line-height: 1;
    border-radius: 4px;
    transition: color 0.2s, background-color 0.2s;
}

.character-modal-close:hover {
    color: var(--text-color);
    background-color: var(--highlight-color);
}

.character-modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

/* Character List View */
.character-list-view {
    min-height: 200px;
}

.character-list-empty {
    text-align: center;
    color: var(--muted-color);
    font-style: italic;
    padding: 2rem;
}

.character-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 1rem;
}

.character-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s;
}

.character-card:hover {
    background-color: var(--highlight-color);
    border-color: var(--muted-color);
}

.character-card-portrait {
    width: 80px;
    height: 100px;
    border-radius: 6px;
    overflow: hidden;
    background: var(--highlight-color);
    margin-bottom: 0.75rem;
}

.character-card-portrait img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.character-card-portrait.pending {
    display: flex;
    align-items: center;
    justify-content: center;
}

.character-card-portrait.pending svg {
    color: var(--muted-color);
    opacity: 0.5;
}

.character-card-name {
    font-size: 0.95rem;
    font-weight: 500;
    text-align: center;
    line-height: 1.3;
}

/* Flowing character layout - primary large cards first, secondary smaller below */
.character-grid:has(.character-flow) {
    display: block;
}

.character-flow {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-start;
}

.character-flow .character-card {
    flex: 0 0 auto;
}

/* Large cards for PRIMARY characters */
.character-card-large {
    width: 130px;
    padding: 1rem;
}

.character-card-large .character-card-portrait {
    width: 100px;
    height: 125px;
}

.character-card-large .character-card-name {
    font-size: 1.05rem;
}

/* Small cards for SECONDARY characters */
.character-card-small {
    width: 90px;
    padding: 0.75rem;
}

.character-card-small .character-card-portrait {
    width: 60px;
    height: 75px;
    margin-bottom: 0.5rem;
}

.character-card-small .character-card-name {
    font-size: 0.85rem;
}

/* Character Detail View */
.character-detail-view {
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.character-back-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: none;
    border: none;
    color: var(--muted-color);
    font-family: var(--font-serif);
    font-size: 0.9rem;
    cursor: pointer;
    padding: 0.5rem 0;
    margin-bottom: 1rem;
    transition: color 0.2s;
}

.character-back-btn:hover {
    color: var(--text-color);
}

.character-detail {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.character-portrait-large {
    width: 160px;
    height: 200px;
    border-radius: 8px;
    overflow: hidden;
    background: var(--highlight-color);
    margin-bottom: 1rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.character-portrait-large img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.character-detail h4 {
    font-size: 1.3rem;
    font-weight: 500;
    margin-bottom: 0.75rem;
}

.character-detail p {
    font-size: 1rem;
    color: var(--muted-color);
    line-height: 1.6;
    margin-bottom: 1rem;
    max-width: 400px;
}

.character-first-appearance {
    font-size: 0.9rem;
    color: var(--muted-color);
    text-decoration: none;
    margin-bottom: 1.5rem;
    transition: color 0.2s;
}

.character-first-appearance:hover {
    color: var(--text-color);
    text-decoration: underline;
}

.character-chat-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    background: var(--text-color);
    color: var(--bg-color);
    border: none;
    border-radius: 6px;
    font-family: var(--font-serif);
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s;
}

.character-chat-btn:hover {
    background: #1a1a1a;
}

/* Character Chat Modal */
.character-chat-container {
    position: relative;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 500px;
    height: 70vh;
    max-height: 600px;
    display: flex;
    flex-direction: column;
    animation: modalSlideIn 0.2s ease;
}

.character-chat-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.chat-portrait-small {
    width: 40px;
    height: 50px;
    border-radius: 6px;
    object-fit: cover;
}

.character-chat-header h3 {
    flex: 1;
    font-size: 1.1rem;
    font-weight: 500;
    margin: 0;
}

/* Chat Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.chat-message {
    max-width: 85%;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    line-height: 1.5;
    font-size: 0.95rem;
}

.chat-message.user {
    align-self: flex-end;
    background: var(--text-color);
    color: var(--bg-color);
    border-bottom-right-radius: 4px;
}

.chat-message.character {
    align-self: flex-start;
    background: var(--highlight-color);
    color: var(--text-color);
    border-bottom-left-radius: 4px;
}

.chat-message.loading {
    color: var(--muted-color);
    font-style: italic;
}

.chat-message.loading::after {
    content: '';
    animation: ellipsis 1.5s infinite;
}

/* Chat Input */
.chat-input-container {
    display: flex;
    gap: 0.75rem;
    padding: 1rem;
    border-top: 1px solid var(--border-color);
}

.chat-input-container textarea {
    flex: 1;
    padding: 0.75rem;
    font-family: var(--font-serif);
    font-size: 0.95rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: white;
    color: var(--text-color);
    resize: none;
    transition: border-color 0.2s;
}

.chat-input-container textarea:focus {
    outline: none;
    border-color: var(--muted-color);
}

.chat-input-container textarea::placeholder {
    color: var(--muted-color);
}

.chat-send-btn {
    padding: 0.75rem;
    background: var(--text-color);
    color: var(--bg-color);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-send-btn:hover {
    background: #1a1a1a;
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
