/* 导入本地字体 */
@import url('../fonts/fonts.css');

@font-face {
    font-family: 'RecommendedPinyinFont';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('../misc/推荐字体.ttf') format('truetype');
}

/* Tailwind CSS 自定义样式 */
.content-auto {
    content-visibility: auto;
}

.scrollbar-hide {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.scrollbar-hide::-webkit-scrollbar {
    display: none;
}

.text-shadow {
    text-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.transition-height {
    transition: max-height 0.3s ease-in-out;
}

.pinyin-handwriting {
    font-family: 'RecommendedPinyinFont', 'Comic Neue', 'Schoolbell', 'Kalam', 'Microsoft YaHei', 'SimSun', sans-serif;
    font-weight: 400;
    letter-spacing: 1px;
    font-variant: normal;
}

.tone-clickable {
    cursor: text;
    border-radius: 6px;
    white-space: nowrap;
    word-break: keep-all;
    overflow-wrap: normal;
    transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

.tone-clickable:hover {
    background-color: rgba(22, 93, 255, 0.06);
}

.tone-clickable:focus {
    outline: none;
    background-color: rgba(22, 93, 255, 0.08);
    box-shadow: inset 0 0 0 1px rgba(22, 93, 255, 0.35);
}

.control-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

@media (min-width: 1024px) {
    .control-panel {
        max-height: calc(100vh - 7rem);
        overflow-y: auto;
        overscroll-behavior: contain;
        scrollbar-gutter: stable;
        padding-right: 4px;
    }
}

.panel-note {
    padding: 12px 14px;
    border: 1px solid rgba(22, 93, 255, 0.12);
    border-radius: 16px;
    background: linear-gradient(135deg, rgba(22, 93, 255, 0.08), rgba(54, 207, 201, 0.08));
}

.panel-note-icon {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: #165DFF;
    color: #fff;
    flex-shrink: 0;
}

.panel-card {
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid #e5e7eb;
    border-radius: 18px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
    padding: 14px;
    transition: box-shadow 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
}

.panel-card:hover {
    border-color: rgba(22, 93, 255, 0.18);
    box-shadow: 0 14px 34px rgba(15, 23, 42, 0.08);
    transform: translateY(-1px);
}

.panel-card-emphasis {
    box-shadow: 0 12px 32px rgba(22, 93, 255, 0.08);
}

.panel-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
    font-size: 15px;
    font-weight: 600;
    color: #111827;
}

.compact-setting-box {
    padding: 10px 12px;
    border: 1px solid #eef2f7;
    border-radius: 14px;
    background: #f8fafc;
}

.compact-color-picker {
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    padding: 6px 8px;
    background: #fff;
    min-height: 44px;
}

.control-panel textarea,
.control-panel input[type="text"] {
    background: #fff;
}

.export-btn {
    background: linear-gradient(135deg, #ff7d00, #ff9a3d);
    color: #fff;
    border: 1px solid rgba(0, 0, 0, 0.04);
    font-weight: 600;
}

.export-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 10px 20px rgba(255, 125, 0, 0.28);
}

.export-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* 单选框样式 */
.radio-check[data-checked="true"] .w-2 {
    display: block;
}

.radio-check[data-checked="false"] .w-2 {
    display: none;
}

/* 田字格样式 */
.grid-container {
    position: relative;
    display: inline-block;
    margin: 5px;
}

.character-grid {
    border: 1px solid #333;
    position: relative;
    background: white;
}

.grid-lines {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.character-group {
    display: inline-block;
    margin: 0;
    padding: 0;
}

.words-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    align-items: flex-start;
    justify-content: flex-start;
}

.grid-line {
    position: absolute;
    background-color: #ccc;
}

.grid-line.horizontal {
    width: 100%;
    height: 1px;
    top: 50%;
}

.grid-line.vertical {
    height: 100%;
    width: 1px;
    left: 50%;
}

.grid-line.diagonal1 {
    width: 141.42%;
    height: 1px;
    top: 50%;
    left: -20.71%;
    transform: rotate(45deg);
}

.grid-line.diagonal2 {
    width: 141.42%;
    height: 1px;
    top: 50%;
    left: -20.71%;
    transform: rotate(-45deg);
}

/* 拼音样式 */
.pinyin-text {
    text-align: center;
    margin-bottom: 5px;
    color: #666;
}

/* 字符样式 */
.character-text {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: bold;
    color: #333;
    pointer-events: none;
    line-height: 1;
}

/* 打印样式优化 */
@media print {
    /* 隐藏浏览器默认的页眉页脚 */
    @page {
        margin: 0;
        size: A4 portrait;
    }

    /* 默认不打印背景颜色，避免 Tailwind 淡灰色背景出现在 PDF 中 */
    * {
        -webkit-print-color-adjust: economy !important;
        print-color-adjust: economy !important;
        color-adjust: economy !important;
    }

    /* 隐藏页面上的非打印元素 */
    body > header,
    body > footer,
    #helpModal,
    /* 隐藏左侧控制面板 */
    main > div > div:first-child,
    /* 隐藏预览区域顶部的标题和按钮栏 (注意：不要隐藏整个卡片容器) */
    main > div > div:nth-child(2) > div:first-child > div:first-child,
    /* 隐藏导出按钮等 */
    #exportPdfBtn,
    #themeToggle,
    #helpBtn,
    /* 隐藏滚动条样式 */
    ::-webkit-scrollbar {
        display: none !important;
    }

    /* 确保 body 和 main 占满全屏 */
    body, main, html {
        width: 100%;
        margin: 0;
        padding: 0;
        background: white;
        overflow: visible !important;
    }
    
    main {
        max-width: none !important;
    }
    
    /* 调整右侧内容区域 */
    main > div > div:nth-child(2) {
        display: block !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    /* 调整卡片容器 (bg-white) */
    main > div > div:nth-child(2) > div:first-child {
        box-shadow: none !important;
        margin: 0 !important;
        padding: 0 !important;
        background: transparent !important;
    }

    /* 重置预览容器外层 div 的样式 (去除背景、边框、滚动条) */
    main > div > div:nth-child(2) > div:first-child > div:nth-child(2) {
        border: none !important;
        background: white !important;
        padding: 0 !important;
        margin: 0 !important;
        min-height: 0 !important;
        overflow: visible !important;
        display: block !important; /* 取消 flex */
        box-shadow: none !important;
    }
    
    #previewContainer {
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* 页面分页控制 */
    .preview-page {
        margin: 0 auto !important;
        box-shadow: none !important;
        /* 打印时保持A4尺寸 */
        width: 210mm !important;
        /* 略小于A4高度，避免浏览器打印取整导致多出空白页 */
        height: 296mm !important;
        min-height: 296mm !important;
        max-height: 296mm !important;
        padding: 15px 25px !important;
        border: none !important;
        box-sizing: border-box !important;
        break-inside: avoid-page !important;
        page-break-inside: avoid !important;
        /* 隐藏溢出内容 */
        overflow: hidden !important;
    }
    
    .preview-page:not(:last-child) {
        break-after: page !important;
        page-break-after: always !important;
    }

    .preview-page:last-child {
        break-after: auto !important;
        page-break-after: auto !important;
    }
    
    /* 隐藏原有的打印区域 */
    #printArea {
        display: none !important;
    }
}

/* 响应式设计 */
@media (max-width: 768px) {
    .control-panel {
        gap: 12px;
    }

    .panel-card,
    .panel-note {
        padding: 14px;
        border-radius: 14px;
    }

    .panel-title {
        font-size: 14px;
        margin-bottom: 10px;
    }

    .compact-setting-box {
        padding: 10px;
    }

    .grid-container {
        margin: 3px;
    }
    
    .character-text {
        font-size: 20px;
    }
    
    .pinyin-text {
        font-size: 12px;
    }
}

/* 模态框样式 */
.modal-overlay {
    background-color: rgba(0, 0, 0, 0.5);
}

.modal-content {
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

/* 按钮样式 */
.btn-primary {
    background-color: #165DFF;
    color: white;
    padding: 8px 16px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary:hover {
    background-color: #0E4FD1;
    transform: translateY(-1px);
}

.btn-primary:disabled {
    background-color: #ccc;
    cursor: not-allowed;
    transform: none;
}

/* 输入框样式 */
.form-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    transition: all 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: #165DFF;
    box-shadow: 0 0 0 3px rgba(22, 93, 255, 0.1);
}

/* 卡片样式 */
.card {
    background: white;
    border-radius: 12px;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    padding: 20px;
    transition: all 0.2s;
}

.card:hover {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

/* 预览页面分页样式 */
.preview-page {
    width: 210mm;
    height: 297mm;
    padding: 15px 25px;
    margin: 20px auto;
    background: white;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    box-sizing: border-box;
    position: relative;
    overflow: hidden;
}

.page-number {
    position: absolute;
    left: 50%;
    bottom: 10px;
    transform: translateX(-50%);
    font-size: 14px;
    font-weight: 600;
    color: #374151;
    line-height: 1;
    white-space: nowrap;
}

.answer-page-content {
    width: 100%;
}

.answer-page-title {
    text-align: center;
    font-weight: 700;
    margin-bottom: 20px;
    color: #111827;
}

.answer-list {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    align-content: flex-start;
}

.answer-subtitle {
    width: 100%;
    margin: 12px 0 6px;
    line-height: 1.5;
}

.answer-line {
    display: inline-block;
    padding: 4px 16px 4px 0;
    font-size: 18px;
    line-height: 1.8;
    color: #111827;
    white-space: nowrap;
}

@media print {
    .preview-page {
        margin: 0;
        box-shadow: none;
        break-after: auto;
        page-break-after: auto;
    }

    .preview-page:not(:last-child) {
        break-after: page;
        page-break-after: always;
    }

    .page-number {
        bottom: 8px;
    }
}
