:root {
    --berry-dark: #8e2157;
    --berry-mid: #c94b7c;
    --paper: #fffdf8;
    --line: #c74f7b;
    --line-soft: rgba(199, 79, 123, 0.35);
    --ink: #4b2a3d;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Kaiti TC", "STKaiti", "Songti TC", "Noto Serif TC", serif;
    color: var(--ink);
    background: linear-gradient(135deg, #ffeef2, #ffd8e5 35%, #ffeaf2);
}

.site-header {
    padding: 20px 24px;
    border-bottom: 1px solid rgba(142, 33, 87, 0.15);
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(6px);
}

.site-header h1 {
    margin: 8px 0 6px;
}

.site-header p {
    margin: 0;
    color: #7c4761;
}

.back-link {
    color: var(--berry-dark);
    text-decoration: none;
    font-size: 0.95rem;
}

.layout {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 20px;
    padding: 20px;
}

.panel {
    background: rgba(255, 255, 255, 0.86);
    border: 1px solid rgba(142, 33, 87, 0.15);
    border-radius: 14px;
    padding: 14px;
    position: sticky;
    top: 12px;
    height: fit-content;
}

label {
    display: block;
    font-size: 0.9rem;
    margin: 10px 0 6px;
    color: #6a3f55;
}

textarea,
input,
select {
    width: 100%;
    border: 1px solid rgba(142, 33, 87, 0.25);
    border-radius: 10px;
    padding: 8px 10px;
    font-size: 0.95rem;
    background: #fff;
}

textarea {
    resize: vertical;
    min-height: 160px;
}

.row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.row.row-single {
    grid-template-columns: 1fr;
}

.label-sub {
    font-weight: 400;
    color: #8a5b73;
    font-size: 0.88em;
}

.actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 14px;
}

.actions.actions-5 {
    grid-template-columns: repeat(3, 1fr);
}

@media (max-width: 400px) {
    .actions.actions-5 {
        grid-template-columns: 1fr 1fr;
    }
}

button {
    border: none;
    border-radius: 10px;
    padding: 10px;
    font-size: 0.92rem;
    cursor: pointer;
    background: linear-gradient(135deg, var(--berry-mid), var(--berry-dark));
    color: #fff;
}

button:hover {
    filter: brightness(1.05);
}

.status {
    margin: 10px 0 0;
    font-size: 0.85rem;
    color: #70455d;
}

.preview-wrap {
    min-width: 0;
}

.preview {
    display: grid;
    gap: 16px;
}

/* 描紅版：格線略淡，與範字協調 */
.preview.preview--hong,
.preview.preview--trace {
    --line-soft: rgba(199, 79, 123, 0.22);
}

.copy-style-hint {
    font-size: 0.85rem;
    color: #7c4761;
    line-height: 1.45;
    margin: 0.45rem 0 0;
}

.preview--a4 .page {
    max-width: 210mm;
    margin-left: auto;
    margin-right: auto;
}

.preview--a4l .page {
    max-width: 297mm;
    margin-left: auto;
    margin-right: auto;
}

.preview--letter .page {
    max-width: 8.5in;
    margin-left: auto;
    margin-right: auto;
}

.page {
    background: var(--paper);
    border-radius: 10px;
    box-shadow: 0 8px 30px rgba(142, 33, 87, 0.12);
    padding: 18px;
    border: 1px solid rgba(142, 33, 87, 0.1);
    overflow-x: auto;
}

.page-title {
    font-size: 0.85rem;
    color: #8a5b73;
    margin-bottom: 10px;
}

.grid {
    display: grid;
    gap: 0;
    border: 1px solid var(--line-soft);
    width: max-content;
    max-width: none;
    margin-left: auto;
    margin-right: auto;
}

.cell {
    position: relative;
    border-right: 1px solid var(--line-soft);
    border-bottom: 1px solid var(--line-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #3d2130;
    background: #fff;
    overflow: hidden;
}

.cell.col-last {
    border-right: none;
}

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

.cell-inner {
    position: relative;
    z-index: 2;
}

.cell-inner--hong,
.cell-inner--trace {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    font-weight: 400;
}

.cell-inner--hong svg,
.cell-inner--trace svg {
    flex: 1 1 auto;
    display: block;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    overflow: visible;
}

.cell.tian::before,
.cell.mi::before,
.cell.mi::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
}

/* 內格線：勿用 1% 寬漸層（小格子會變次像素而看不見）；改用固定 1px 十字線 */
.cell.tian::before,
.cell.mi::before {
    background-image:
        linear-gradient(var(--line-soft), var(--line-soft)),
        linear-gradient(var(--line-soft), var(--line-soft));
    background-size: 1px 100%, 100% 1px;
    background-position: center center;
    background-repeat: no-repeat;
}

/* 米字格對角線：以中心為準的固定寬度色帶，避免百分比過細 */
.cell.mi::after {
    background-image:
        linear-gradient(45deg, transparent calc(50% - 1px), var(--line-soft) calc(50% - 1px), var(--line-soft) calc(50% + 1px), transparent calc(50% + 1px)),
        linear-gradient(-45deg, transparent calc(50% - 1px), var(--line-soft) calc(50% - 1px), var(--line-soft) calc(50% + 1px), transparent calc(50% + 1px));
}

@media (max-width: 980px) {
    .layout {
        grid-template-columns: 1fr;
    }

    .panel {
        position: static;
    }
}

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

    .site-header,
    .panel {
        display: none;
    }

    .layout {
        display: block;
        padding: 0;
    }

    .page {
        box-shadow: none;
        border: none;
        margin: 0;
        padding: 0;
        overflow: visible;
        break-after: page;
        page-break-after: always;
    }

    .page-title {
        display: none;
    }
}
