:root {
    font-family:
        "Inter",
        "PingFang SC",
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
    background: #eef2ff;
    color: #1f2937;
    --sheet-width: 210mm;
    --sheet-height: 297mm;
    --page-margin-inline: 10mm;
    --page-margin-block: 18.5mm;
    --page-width: calc(var(--sheet-width) - 2 * var(--page-margin-inline));
    --page-height: calc(var(--sheet-height) - 2 * var(--page-margin-block));
    --print-page-padding: 10mm;
}

body {
    margin: 0;
    padding: 32px;
    -webkit-text-size-adjust: 100%;
}

.hidden {
    display: none !important;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    background: #fff;
    border-radius: 18px;
    padding: 24px 28px 32px;
    box-shadow: 0 30px 80px rgba(79, 70, 229, 0.15);
}

h1 {
    margin: 0 0 10px;
    font-size: 26px;
    font-weight: 700;
}

.intro {
    margin-top: 0;
    color: #6b7280;
}

.controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 12px;
    margin: 24px 0 8px;
}

label.inline {
    display: flex;
    flex-direction: column;
    font-size: 13px;
    color: #4b5563;
    gap: 4px;
}

input,
select {
    border-radius: 10px;
    border: 1px solid #cbd5f5;
    padding: 8px 10px;
    font-size: 14px;
    background: #f8fafc;
}

button {
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, #4c6ef5, #7c3aed);
    color: #fff;
    font-weight: 600;
    font-size: 15px;
    cursor: pointer;
    transition: opacity 0.2s ease;
}

button:hover {
    opacity: 0.9;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

button.ghost {
    background: transparent;
    border: 1px solid rgba(76, 110, 245, 0.5);
    color: #4c6ef5;
    padding: 6px 12px;
}

button.ghost:hover {
    opacity: 1;
    background: rgba(76, 110, 245, 0.08);
}

button.ghost:disabled {
    background: transparent;
    border-color: rgba(50, 50, 50, 1);
    color: #94a3b8;
}

.message {
    margin-top: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    background: #eef2ff;
    color: #4338ca;
}

.message.ok {
    background: #ecfdf5;
    color: #047857;
}

.message.error {
    background: #fef2f2;
    color: #b91c1c;
}

.message.warn {
    background: #fefce8;
    color: #92400e;
}

.current {
    margin: 14px 0 18px;
    font-weight: 600;
    color: #374151;
}

.boards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 24px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.section-header h2 {
    margin: 0;
}

.board {
    border-collapse: collapse;
    width: 100%;
    background: #f9fafb;
    border: 3px solid #1f2937;
}

.board-wrapper {
    position: relative;
}

.board td {
    border: 1px solid #cbd5f5;
    width: calc(100% / 9);
    text-align: center;
    padding: 0;
    position: relative;
    overflow: hidden;
}

.board td::before {
    content: "";
    display: block;
    padding-top: 100%;
}

.board td span {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(14px, 1.8vw, 22px);
    font-weight: 600;
    padding: 0;
}

body.answer-page .board td span {
    font-size: clamp(22px, 2vw, 26px);
}

.mask-layer {
    position: absolute;
    inset: 12px;
    border-radius: 10px;
    display: none;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: #475569;
    background: rgba(248, 250, 252, 0.95);
}

.board.with-mask {
    position: relative;
}

.mask-layer.active {
    display: flex;
}

.board td:nth-child(3n) {
    border-right: 2px solid #0f172a;
}

.board tr:nth-child(3n) td {
    border-bottom: 2px solid #0f172a;
}

.lookup {
    margin-top: 28px;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
}

.lookup-top {
    margin-top: 12px;
    justify-content: flex-start;
}

.lookup label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 13px;
}

.print-panel {
    margin-top: 32px;
}

.print-note {
    margin: 0 0 12px;
    color: #6b7280;
    font-size: 14px;
}

.print-controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    align-items: end;
}

.print-controls .checkbox span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #475569;
}

.print-controls label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 13px;
}

.print-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.layout-inputs {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.layout-inputs input {
    width: 64px;
    text-align: center;
}

.print-layer {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 1000;
}

.print-layer.active {
    display: flex;
}

.print-overlay {
    background: #fff;
    border-radius: 20px;
    width: min(100%, 1100px);
    max-height: calc(100% - 40px);
    display: flex;
    flex-direction: column;
    box-shadow: 0 30px 80px rgba(15, 23, 42, 0.35);
}

.print-overlay-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #e2e8f0;
    gap: 16px;
}

.print-overlay-actions {
    display: flex;
    gap: 10px;
}

.print-meta-text {
    margin: 4px 0 0;
    font-size: 12px;
    color: #64748b;
}

.print-overlay-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow: auto;
}

.print-preview-viewport {
    max-width: 100%;
    padding: 16px;
    box-sizing: border-box;
    overflow: auto;
}

.print-preview-viewport::after {
    content: "";
    display: block;
    height: 1px;
}

.print-area {
    width: var(--page-width);
    min-height: var(--page-height);
    background: #fff;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    transform-origin: top left;
    display: none;
}

#printArea h1 {
    font-size: 20px;
    margin: 0 0 6px;
}

#printArea p {
    font-size: 12px;
    margin: 0 0 10px;
    color: #475569;
}

.print-section {
    margin-top: 8px;
}

.print-section.answers {
    margin-top: 24px;
}

#printPagesContainer,
#answerPagesContainer {
    display: flex;
    flex-direction: column;
    gap: 12mm;
    align-items: center;
}

.answer-stack.hidden {
    display: none;
}

.answer-stack {
    page-break-before: always;
}

.print-page {
    width: var(--page-width);
    min-height: var(--page-height);
    border: 1px dashed #cbd5f5;
    border-radius: 12px;
    padding: var(--print-page-padding);
    box-sizing: border-box;
    display: grid;
    grid-auto-rows: auto;
    grid-template-columns: repeat(var(--cols, 1), auto);
    grid-template-rows: repeat(var(--rows, 1), auto);
    row-gap: clamp(1cm, var(--gap, 1.6cm), 4cm);
    column-gap: clamp(1cm, var(--gap, 1.6cm), 4cm);
    justify-content: center;
    page-break-inside: avoid;
}

.print-page.answers-page {
    row-gap: 1cm;
    column-gap: 1cm;
}

.print-page.answers-page::before {
    content: "答案";
    grid-column: 1 / -1;
    font-weight: 600;
    margin-bottom: 4mm;
}

.print-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.print-item-bar {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-align: center;
    margin: 0 0 2px;
    font-size: 12px;
    color: #475569;
}

.print-item-bar > span {
    flex: 1;
}

.print-item-bar-spacer {
    flex: 0;
    font-size: 10px;
}

.print-item-content {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    flex-wrap: wrap;
}

.print-item-content .board-holder {
    flex: 0 0 auto;
}

.qr-wrapper {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    padding: 6px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #fff;
    flex-direction: column;
    gap: 6px;
}

.qr-wrapper img {
    width: var(--qr-size, 96px);
    height: var(--qr-size, 96px);
}

.qr-hint {
    font-size: 10px;
    color: #475569;
    text-align: center;
    line-height: 1.3;
}

.admin-table-wrapper {
    margin-top: 24px;
    overflow-x: auto;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.admin-table th,
.admin-table td {
    border: 1px solid #e5e7eb;
    padding: 10px 12px;
    text-align: left;
    white-space: nowrap;
}

.admin-table th {
    background: #f1f5f9;
    font-weight: 600;
}

.admin-table th.sortable {
    cursor: pointer;
    user-select: none;
}

.admin-table th.sortable.active[data-dir="asc"]::after {
    content: " ↑";
}

.admin-table th.sortable.active[data-dir="desc"]::after {
    content: " ↓";
}

.admin-pagination {
    margin: 16px 0 0;
    display: flex;
    align-items: center;
    gap: 12px;
}

.admin-action {
    padding: 6px 12px;
    border: 1px solid #ef4444;
    background: #fee2e2;
    color: #b91c1c;
    border-radius: 6px;
    cursor: pointer;
}

.admin-action:hover {
    background: #fecaca;
}

.link-button {
    background: transparent;
    border: none;
    color: #2563eb;
    text-decoration: underline;
    cursor: pointer;
    padding: 0;
    font: inherit;
}

.print-item-label {
    font-size: 12px;
    color: #475569;
    margin: 0;
    text-align: left;
}

.print-item-meta-inline {
    font-size: 12px;
    color: #64748b;
    text-align: right;
}

table.sudoku {
    border-collapse: collapse;
    border: 2px solid #0f172a;
}

table.sudoku td {
    width: var(--cell-size, 34px);
    height: var(--cell-size, 34px);
    border: 1px solid #555;
    text-align: center;
    padding: 0;
}

table.sudoku td.divider-right {
    border-right-width: 2px;
}

table.sudoku td.divider-bottom {
    border-bottom-width: 2px;
}

table.sudoku td span {
    font-size: var(--font-size, 18px);
    font-weight: 700;
}

@media screen {
    #printArea {
        display: none;
    }

    body.preview-print #printLayer {
        display: flex;
    }

    body.preview-print #printArea {
        display: block;
        width: var(--page-width);
    }

    body.preview-print .print-page {
        width: var(--page-width);
    }
}

@page {
    size: A4 portrait;
    margin: var(--page-margin-block) var(--page-margin-inline);
}

@media print {
    body {
        background: #fff;
        padding: 0;
    }

    .no-print {
        display: none !important;
    }

    #printArea {
        display: block;
        width: var(--page-width);
        margin: 0 auto;
        transform: none !important;
    }

    .print-layer {
        position: static;
        padding: 0;
        background: transparent;
    }

    .print-overlay {
        box-shadow: none;
        border-radius: 0;
    }

    .print-page {
        border: none;
        width: var(--page-width);
        min-height: var(--page-height);
        padding: var(--print-page-padding);
    }

    .print-page:not(:last-child) {
        page-break-after: always;
    }

    .print-overlay-body {
        padding: 0;
    }
}

/* legacy print preview styles removed */

@media (max-width: 640px) {
    body {
        padding: 16px;
    }

    .container {
        padding: 20px;
    }
}
.print-page.answers-page {
    row-gap: 1cm;
    column-gap: 1cm;
}
.print-preview-viewport[data-scale] .print-area {
    display: block;
    transform: scale(var(--preview-scale, 1));
    transform-origin: top left;
}

.print-preview-viewport[data-scale] {
    --preview-scale: var(--preview-scale, 1);
}

body.answer-page {
    padding: 24px 16px 48px;
    background: #eef2ff;
    -webkit-text-size-adjust: 100%;
}

.answer-shell {
    max-width: 960px;
    margin: 0 auto;
    background: #fff;
    border-radius: 18px;
    padding: 24px 28px 32px;
    box-shadow: 0 30px 80px rgba(15, 23, 42, 0.12);
}

.answer-header h1 {
    margin: 0;
    font-size: 26px;
}

.answer-meta {
    margin: 6px 0 0;
    color: #475569;
    font-size: 14px;
}

.answer-board-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 24px;
    margin-top: 16px;
    justify-items: center;
}

.answer-content h2 {
    margin-bottom: 6px;
}

.answer-only {
    width: min(420px, 100%);
}
