/* ==================== 打印样式 - A4精确适配 ==================== */

@page {
    size: A4 portrait;
    margin: 12mm 15mm;
}

@media print {
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    body {
        background: white !important;
        padding: 0 !important;
        margin: 0 !important;
        color: #000 !important;
    }

    .no-print,
    .top-bar,
    .difficulty-bar,
    .numpad-grid,
    .func-bar,
    .status-bar,
    .big-newgame-btn,
    .bottom-nav,
    .site-nav,
    .page-header,
    .print-options-card,
    .print-preview-card,
    .site-footer,
    .hero-section,
    .page-section,
    .modal-mask,
    .user-card,
    .game-right > *:not(.board-wrap):not(.print-page) {
        display: none !important;
    }

    .app-container {
        max-width: none !important;
        width: 100% !important;
        padding: 0 !important;
    }

    .board-wrap {
        box-shadow: none !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    /* 打印页面容器 */
    .print-page {
        page-break-after: always;
        width: 100%;
    }
    .print-page:last-child {
        page-break-after: auto;
    }

    /* ========== 单题/页 ========== */
    .print-layout-1 {
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .print-layout-1 .print-title {
        font-size: 16pt;
        font-weight: bold;
        text-align: center;
        margin-bottom: 6mm;
        color: #000;
    }

    .print-layout-1 .print-puzzle {
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .print-layout-1 .board {
        width: 170mm;
        height: 170mm;
        font-size: 24pt;
    }

    .print-layout-1 .puzzle-footer {
        width: 170mm;
        display: flex;
        justify-content: space-between;
        align-items: flex-end;
        margin-top: 6mm;
    }

    .print-layout-1 .puzzle-number {
        font-size: 11pt;
        color: #333;
    }

    .print-layout-1 .puzzle-number strong {
        font-size: 12pt;
    }

    .print-layout-1 .qr-code {
        width: 22mm;
        height: 22mm;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .print-layout-1 .qr-code svg {
        width: 100%;
        height: 100%;
        display: block;
    }

    /* ========== 2题/页（上下排列） ========== */
    .print-layout-2 {
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 6mm;
    }

    .print-layout-2 .print-puzzle {
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .print-layout-2 .print-title {
        font-size: 12pt;
        font-weight: bold;
        text-align: center;
        margin-bottom: 3mm;
        color: #000;
    }

    .print-layout-2 .board {
        width: 105mm;
        height: 105mm;
        font-size: 16pt;
    }

    .print-layout-2 .puzzle-footer {
        width: 105mm;
        display: flex;
        justify-content: space-between;
        align-items: flex-end;
        margin-top: 4mm;
    }

    .print-layout-2 .puzzle-number {
        font-size: 9pt;
        color: #333;
    }

    .print-layout-2 .puzzle-number strong {
        font-size: 10pt;
    }

    .print-layout-2 .qr-code {
        width: 16mm;
        height: 16mm;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .print-layout-2 .qr-code svg {
        width: 100%;
        height: 100%;
        display: block;
    }

    /* ========== 4题/页（2x2排列） ========== */
    .print-layout-4 {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-template-rows: 1fr 1fr;
        gap: 6mm 8mm;
        justify-items: center;
    }

    .print-layout-4 .print-puzzle {
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .print-layout-4 .print-title {
        font-size: 10.5pt;
        font-weight: bold;
        text-align: center;
        margin-bottom: 2.5mm;
        color: #000;
    }

    .print-layout-4 .board {
        width: 80mm;
        height: 80mm;
        font-size: 13pt;
    }

    .print-layout-4 .puzzle-footer {
        width: 80mm;
        display: flex;
        justify-content: space-between;
        align-items: flex-end;
        margin-top: 3mm;
    }

    .print-layout-4 .puzzle-number {
        font-size: 8pt;
        color: #333;
    }

    .print-layout-4 .puzzle-number strong {
        font-size: 9pt;
    }

    .print-layout-4 .qr-code {
        width: 14mm;
        height: 14mm;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .print-layout-4 .qr-code svg {
        width: 100%;
        height: 100%;
        display: block;
    }

    /* ========== 棋盘打印样式 ========== */
    .board {
        border: 2px solid #000 !important;
        background: #fff !important;
        border-radius: 0 !important;
    }

    .cell {
        border-right: 1px solid #999 !important;
        border-bottom: 1px solid #999 !important;
        background: #fff !important;
        color: #000 !important;
        font-size: inherit !important;
        border-radius: 0 !important;
    }

    .cell.given {
        font-weight: bold !important;
        color: #000 !important;
    }

    /* 粗线分隔 - 3x3宫格 */
    .cell:nth-child(3n) {
        border-right: 2px solid #000 !important;
    }
    .cell:nth-child(9n) {
        border-right: none !important;
    }

    .row:nth-child(3) .cell,
    .row:nth-child(6) .cell {
        border-bottom: 2px solid #000 !important;
    }

    .row:last-child .cell {
        border-bottom: none !important;
    }

    /* 隐藏游戏状态样式 */
    .cell.selected,
    .cell.highlight,
    .cell.same-num,
    .cell.error,
    .cell .notes {
        display: none !important;
    }

    .cell.user-num {
        color: #333 !important;
        font-weight: normal !important;
    }

    /* 打印答案模式 */
    .print-show-answer .cell {
        color: #000 !important;
        font-weight: normal !important;
    }

    /* 防止分页截断题目 */
    .print-puzzle {
        page-break-inside: avoid;
    }
}

/* ==================== 打印预览（屏幕上） ==================== */
@media screen {
    .a4-preview {
        background: #fff;
        border: 1px solid #ddd;
        box-shadow: 0 4px 12px rgba(0,0,0,0.1);
        position: relative;
        overflow: hidden;
    }

    .a4-preview-inner {
        padding: 20px;
    }

    .a4-preview-label {
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        background: var(--primary);
        color: #fff;
        font-size: 11px;
        padding: 2px 12px;
        border-radius: 0 0 6px 6px;
        z-index: 2;
    }

    .a4-preview-title {
        text-align: center;
        font-size: 15px;
        font-weight: 600;
        color: var(--text);
        margin-bottom: 6px;
    }

    .a4-preview-meta {
        display: flex;
        justify-content: space-between;
        font-size: 11px;
        color: var(--text-hint);
        margin-bottom: 12px;
    }

    /* 预览棋盘 */
    .preview-board {
        display: grid;
        grid-template-columns: repeat(9, 1fr);
        grid-template-rows: repeat(9, 1fr);
        width: 100%;
        aspect-ratio: 1 / 1;
        border: 2px solid #333;
        background: #fff;
    }

    .preview-cell {
        display: flex;
        align-items: center;
        justify-content: center;
        border-right: 1px solid #ccc;
        border-bottom: 1px solid #ccc;
        font-size: 14px;
        color: #333;
    }

    .preview-cell.given {
        font-weight: bold;
        color: #000;
    }

    .preview-cell.empty {
        color: #ddd;
    }

    /* 3x3 宫格粗线分隔 */
    .preview-cell:nth-child(9n) {
        border-right: none;
    }

    .preview-cell.row-3,
    .preview-cell.row-6 {
        border-bottom: 2px solid #333;
    }

    .preview-cell:nth-child(9n+3),
    .preview-cell:nth-child(9n+6) {
        border-right: 2px solid #333;
    }

    .a4-preview .print-layout-1,
    .a4-preview .print-layout-2,
    .a4-preview .print-layout-4 {
        transform-origin: top left;
    }

    .print-puzzle {
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .print-title {
        font-weight: 600;
        color: var(--text);
    }

    .puzzle-footer {
        display: flex;
        justify-content: space-between;
        align-items: flex-end;
    }

    .puzzle-number {
        font-size: 12px;
        color: var(--text-sub);
    }

    .puzzle-number strong {
        color: var(--text);
    }

    .qr-code {
        background: #fff;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .qr-code svg {
        width: 100%;
        height: 100%;
        display: block;
    }
}
