/* === 全局基础样式 === */
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: #f2f4f7; margin: 0; display: flex; height: 100vh; overflow: hidden; }

/* === 侧边栏 (PC端) === */
.sidebar { width: 500px; background: white; padding: 25px; box-shadow: 4px 0 15px rgba(0,0,0,0.05); display: flex; flex-direction: column; overflow-y: auto; z-index: 10; flex-shrink: 0; }
.sidebar h2 { margin: 0 0 15px 0; color: #2c3e50; font-size: 20px; border-bottom: 2px solid #f0f0f0; padding-bottom: 12px; display: flex; justify-content: space-between; align-items: center; }
.device-badge { font-size: 12px; padding: 4px 8px; border-radius: 4px; background: #eee; color: #666; font-weight: normal; }

.section-title { margin: 20px 0 10px 0; font-size: 15px; font-weight: bold; color: #333; display: flex; align-items: center; border-left: 4px solid #2196F3; padding-left: 10px; }

.input-group { margin-bottom: 12px; }
.input-group label { display: block; font-size: 13px; color: #666; margin-bottom: 5px; font-weight: 500; }
.input-group input, .input-group textarea { width: 100%; padding: 12px; border: 1px solid #ddd; border-radius: 8px; font-size: 14px; box-sizing: border-box; transition: 0.2s; }
.input-group input:focus, .input-group textarea:focus { border-color: #2196F3; outline: none; box-shadow: 0 0 0 2px rgba(33, 150, 243, 0.1); }
.input-group textarea { resize: vertical; min-height: 120px; font-family: "Courier New", monospace; }

/* 工具箱样式 */
.tools-box { background: #f0f7ff; padding: 15px; border-radius: 10px; border: 1px solid #cce4ff; margin-bottom: 15px; }
.detect-btn { width: 100%; padding: 10px; background: #1976d2; color: white; border: none; border-radius: 6px; cursor: pointer; font-weight: bold; font-size: 14px; margin-bottom: 12px; transition: 0.2s; }
.detect-btn:hover { background: #1565c0; transform: translateY(-1px); }

/* 名字映射列表 */
.name-map-list { display: flex; flex-direction: column; gap: 8px; max-height: 200px; overflow-y: auto; padding-right: 5px; margin-bottom: 5px; }
.name-map-item { display: flex; align-items: center; gap: 8px; background: white; padding: 8px; border-radius: 6px; border: 1px solid #e0e0e0; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
.old-name-label { width: 60px; font-size: 13px; font-weight: bold; color: #333; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.arrow { color: #bbb; font-size: 12px; }
.new-name-input { flex: 1; padding: 6px; font-size: 13px; border: 1px solid #ccc; border-radius: 4px; }
.dice-btn { cursor: pointer; background: #f5f5f5; border: 1px solid #ddd; border-radius: 4px; padding: 4px 8px; font-size: 16px; transition: 0.2s; }
.dice-btn:hover { background: #e0e0e0; }

.apply-btn { width: 100%; padding: 12px; background: #2e7d32; color: white; border: none; border-radius: 6px; cursor: pointer; font-weight: bold; font-size: 14px; margin-top: 10px; display: none; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }
.apply-btn:hover { background: #1b5e20; transform: translateY(-1px); }

.chapter-clean-btn { background: #ff9800; color: white; border: none; padding: 12px; width: 100%; border-radius: 8px; cursor: pointer; margin-top: 10px; font-size: 14px; font-weight: bold; display: flex; align-items: center; justify-content: center; gap: 8px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }
.chapter-clean-btn:hover { background: #f57c00; transform: translateY(-1px); }

/* 底部生成按钮组 */
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; margin-top: 20px; padding-bottom: 40px; }
.btn { padding: 15px; border: none; border-radius: 8px; color: white; cursor: pointer; font-weight: bold; font-size: 15px; transition: 0.2s; box-shadow: 0 4px 6px rgba(0,0,0,0.1); }
.btn:hover { transform: translateY(-2px); opacity: 0.95; }
.btn:active { transform: scale(0.98); }

/* === 预览区 (PC端) === */
.preview-area { flex: 1; background: #cbd2d9; padding: 40px; display: flex; justify-content: center; align-items: flex-start; overflow-y: auto; }
#status-msg { margin-top: 15px; padding: 15px; background: #e8f5e9; color: #2e7d32; border-radius: 6px; font-size: 14px; text-align: center; display: none; font-weight: bold; border: 1px solid #c8e6c9;}

/* === 2K 画布 (核心修复：取消Flex的高度自适应，改为内容撑开) === */
#render-canvas {
    width: 1080px; height: 1440px;
    background: #fff; position: relative;
    box-shadow: 0 30px 80px rgba(0,0,0,0.3);
    transform-origin: top center; transform: scale(0.45); flex-shrink: 0;
    display: flex; flex-direction: column;
    overflow: hidden; /* 强制裁剪溢出内容 */
}

.card-container { 
    width: 100%; height: 100%; 
    padding: 20px 40px 40px 40px; 
    box-sizing: border-box; 
    display: flex; flex-direction: column; 
}

.inner-card { 
    background: rgba(255,255,255,0.96); 
    border-radius: 24px; 
    flex: 1; 
    padding: 60px 55px; 
    display: flex; flex-direction: column; 
    box-shadow: 0 10px 30px rgba(0,0,0,0.06); 
    position: relative; overflow: hidden; 
}

.novel-font { font-family: "Source Han Serif CN", "Songti SC", "SimSun", serif; color: #222; }

/* 关键：body-text 不能设置 fixed height 或 overflow hidden，否则无法测量内容 */
.body-text { display: block; }

.body-text p { 
    font-size: 46px; 
    line-height: 1.55; 
    text-align: justify; 
    text-indent: 2em; 
    margin-top: 0; 
    margin-bottom: 24px; 
    letter-spacing: 0px; 
}

/* 封面 */
.cover-header { text-align: center; margin-bottom: 50px; border-bottom: 3px dashed rgba(0,0,0,0.1); padding-bottom: 30px; }
.main-title { 
    font-size: 82px; font-weight: 900; line-height: 1.25; margin-bottom: 20px; color: #111; letter-spacing: -2px; word-break: break-word; 
}
.type-tag { display: inline-block; font-size: 32px; color: #666; background: rgba(0,0,0,0.05); padding: 12px 30px; border-radius: 60px; font-weight: 500; }

/* 底部与顶部信息 */
.likes-count { font-weight: bold; font-size: 34px; }
.page-indicator { position: absolute; top: 30px; right: 40px; font-size: 24px; color: rgba(255,255,255,0.7); font-family: sans-serif; }

.footer-inside { 
    margin-top: auto; padding-top: 20px; display: flex; justify-content: space-between; align-items: center; border-top: 2px solid rgba(0,0,0,0.06); font-family: sans-serif; color: #888; font-size: 28px; 
    min-height: 60px; 
}
.footer-inside .likes-count { color: #555; }

/* 正文页顶部栏 */
.header-outside { 
    display: flex; justify-content: space-between; align-items: center; 
    padding: 10px 10px 20px 10px; 
    height: 60px; 
    font-family: -apple-system, sans-serif; 
    color: #333; /* 深灰文字 */
    font-size: 30px; 
    font-weight: 700;
}
/* 给文字加个白边，防背景色太深 */
.header-outside span { text-shadow: 0px 0px 8px rgba(255,255,255,0.8); }
.header-outside .likes-count { color: #d32f2f; font-size: 36px; }

/* 配色主题 */
.theme-green { background: linear-gradient(150deg, #5da882, #3a6b56); } .theme-green .inner-card { background: #f2fbf6; } .theme-green .main-title { color: #2e5f4a; }
.theme-pink { background: linear-gradient(150deg, #ea9f9f, #c76e6e); } .theme-pink .inner-card { background: #fff8f8; } .theme-pink .main-title { color: #a34747; }
.theme-blue { background: linear-gradient(150deg, #5b7cba, #2a3d5e); } .theme-blue .inner-card { background: #f4f8ff; } .theme-blue .main-title { color: #2a3d5e; }
.theme-brown { background: linear-gradient(150deg, #a67c52, #5e462e); } .theme-brown .inner-card { background: #fffcf6; } .theme-brown .main-title { color: #5e462e; }

/* === 📱 手机端适配 (Media Queries) === */
@media screen and (max-width: 768px) {
    body { flex-direction: column; height: auto; overflow-y: auto; }
    .sidebar { width: 100%; padding: 20px; box-shadow: none; overflow: visible; height: auto;}
    
    /* 手机上预览区缩小显示 */
    .preview-area { 
        height: 300px; 
        padding: 10px;
        background: #eee;
        flex: none; 
        order: -1; 
        border-bottom: 1px solid #ddd;
    }
    
    /* 预览画布在手机上缩放得更小 */
    #render-canvas {
        transform: scale(0.25); 
        transform-origin: top center;
        margin-bottom: -1000px; 
    }

    .btn-row { grid-template-columns: 1fr; gap: 10px; } 
    
    .sidebar h2 { font-size: 18px; }
    .input-group label { font-size: 14px; }
    .btn { font-size: 16px; padding: 12px; }
}