/* Offline common Chinese font subsets; preserve calendar glyphs. */
@font-face {
    font-family: 'Chiron GoRound TC';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('./fonts/chiron-goround-tc.woff2') format('woff2');
}
@font-face {
    font-family: 'Noto Serif SC';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('./fonts/noto-serif-sc.woff2') format('woff2');
}
@font-face {
    font-family: 'ZCOOL KuaiLe';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('./fonts/zcool-kuaile.woff2') format('woff2');
}
@font-face {
    font-family: 'Zhi Mang Xing';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('./fonts/zhi-mang-xing.woff2') format('woff2');
}

* { box-sizing: border-box; }

/* 顶部加宽留空避开状态栏/刘海屏；底部叠加安全区 */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    margin: 0;
    padding: 52px 12px 16px 12px;
    padding-bottom: 16px;
    padding-bottom: calc(16px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)));
    background: #f4f6f9;
    color: #333;
}

h2 { font-size: 16px; margin: 0 0 12px 0; text-align: center; }

.steps-header { display: flex; justify-content: space-between; margin-bottom: 10px; background: #fff; padding: 5px; border-radius: 8px; box-shadow: 0 2px 6px rgba(0,0,0,0.04); }
.step-tab { flex: 1; min-width: 0; text-align: center; font-size: 11px; padding: 6px 0; color: #999; font-weight: 600; border-radius: 6px; cursor: pointer; }
.step-tab.active { background: #007aff; color: #fff; }

.step-content { display: none; }
.step-content.active { display: block; }

.panel { background: #fff; padding: 10px; border-radius: 10px; box-shadow: 0 2px 8px rgba(0,0,0,0.04); margin-bottom: 10px; }
.control-group { margin-bottom: 10px; }
.control-group:last-child { margin-bottom: 0; }
label { display: block; font-size: 11px; margin-bottom: 4px; color: #555; font-weight: 600; }
select, input[type="text"], input[type="number"] { width: 100%; padding: 6px; font-size: 12px; border: 1px solid #ddd; border-radius: 6px; background: #fafafa; }

/* Flex 间距基线用子项 margin，增强用 gap（由 main.js 行为检测启用） */
.row { display: flex; }
.row > * + * { margin-left: 6px; }
.row > div { flex: 1; min-width: 0; }

/* 负 margin 方案，可在 flex-wrap 换行时保持等距 */
.chip-group { display: flex; flex-wrap: wrap; margin: -3px; }
.chip-group > .chip { margin: 3px; }
.chip {
    flex: 1; min-width: 50px; border: 1.5px solid #ddd; border-radius: 6px; padding: 6px 4px;
    text-align: center; font-size: 11px; cursor: pointer; background: #fafafa; font-weight: 500;
    transition: all 0.2s; display: flex; align-items: center; justify-content: center;
}
.chip.active { border-color: #007aff; background: #eef6ff; color: #007aff; font-weight: 600; }

.align-group { display: flex; margin: 0 -3px; }
.align-group > .chip { flex: 1; margin: 0 3px; }

.mark-chip-group { display: flex; }
.mark-chip-group > * + * { margin-left: 8px; }
.mark-chip { flex: 1; min-width: 0; height: 38px; border: 1.5px solid #ddd; border-radius: 6px; display: flex; align-items: center; justify-content: center; cursor: pointer; background: #fafafa; transition: all 0.2s; }
.mark-chip.active { border-color: #007aff; background: #eef6ff; }

.checkbox-grid { display: grid; grid-template-columns: repeat(3, 1fr); grid-gap: 6px; }
.checkbox-label { display: flex; align-items: center; font-size: 11px; cursor: pointer; background: #fafafa; padding: 5px; border-radius: 4px; border: 1px solid #eee; }
.checkbox-label input { width: auto; margin-right: 4px; }

.color-row { display: flex; align-items: center; justify-content: space-between; font-size: 11px; padding: 3px 0; }
input[type="color"] { -webkit-appearance: none; appearance: none; border: none; width: 22px; height: 22px; border-radius: 4px; cursor: pointer; background: none; }
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: 1px solid #ccc; border-radius: 4px; }

.btn-group { display: flex; margin-top: 8px; }
.btn-group > * + * { margin-left: 6px; }
.btn { flex: 1; min-width: 0; padding: 8px; font-size: 12px; background: #007aff; color: #fff; border: none; border-radius: 6px; font-weight: bold; cursor: pointer; text-align: center; }
.btn-secondary { background: #e4e6eb; color: #333; }
.btn[disabled] { opacity: 0.6; cursor: default; }

/* 整年导出按钮与下拉并排时的底部对齐容器 */
.btn-inline-wrap { display: flex; align-items: flex-end; }
.btn-inline-wrap > .btn { flex: 1; min-width: 0; }

.preview-toolbar { display: flex; justify-content: center; align-items: center; margin-bottom: 6px; font-size: 11px; }
.preview-toolbar > * + * { margin-left: 6px; }
.bg-btn { padding: 2px 6px; border-radius: 4px; border: 1px solid #ccc; background: #fff; cursor: pointer; }
.bg-btn.active { background: #333; color: #fff; border-color: #333; }

/* Flex gap 增强层：仅在 JS 实测生效时启用，并清除基线 margin */
.supports-flex-gap .row { column-gap: 6px; }
.supports-flex-gap .row > * + * { margin-left: 0; }
.supports-flex-gap .chip-group { gap: 6px; margin: 0; }
.supports-flex-gap .chip-group > .chip { margin: 0; }
.supports-flex-gap .align-group { column-gap: 6px; margin: 0; }
.supports-flex-gap .align-group > .chip { margin: 0; }
.supports-flex-gap .mark-chip-group { column-gap: 8px; }
.supports-flex-gap .mark-chip-group > * + * { margin-left: 0; }
.supports-flex-gap .btn-group { column-gap: 6px; }
.supports-flex-gap .btn-group > * + * { margin-left: 0; }
.supports-flex-gap .preview-toolbar { column-gap: 6px; }
.supports-flex-gap .preview-toolbar > * + * { margin-left: 0; }
.supports-flex-gap .btn-inline-wrap { column-gap: 6px; }

.preview-container {
    display: flex; justify-content: center; align-items: center;
    min-height: 290px; border-radius: 10px; padding: 12px;
    overflow: hidden; position: relative;
    background-image: linear-gradient(45deg, #ccc 25%, transparent 25%), linear-gradient(-45deg, #ccc 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #ccc 75%), linear-gradient(-45deg, transparent 75%, #ccc 75%);
    background-size: 16px 16px; background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
}
.preview-container.bg-white { background-image: none; background-color: #ffffff; }
.preview-container.bg-black { background-image: none; background-color: #121212; color: #ffffff; }

#card {
    width: 290px;
    background: transparent;
    position: relative;
    padding: 10px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: all 0.2s;
}

.template-basic .card-header { padding-bottom: 6px; margin-bottom: 6px; border-bottom: 1px solid transparent; }
.template-basic .card-header.has-line { border-bottom-color: rgba(0,0,0,0.15); }
.template-basic .calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; grid-gap: 2px; }
.template-basic .week-header { font-size: 10px; padding-bottom: 4px; font-weight: bold; }

.template-basic .grid-cell {
    padding: 2px 0;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    height: 34px;
    width: 100%;
    position: relative;
}

.template-boxed { border: 1.5px solid var(--border-color, #333); padding: 8px; background: transparent; }
.template-boxed .card-header { padding-bottom: 8px; margin-bottom: 0; }
.template-boxed .calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    text-align: center;
    border-top: 1.5px solid var(--border-color, #333);
    border-left: 1.5px solid var(--border-color, #333);
}
.template-boxed .week-header {
    font-size: 10px;
    font-weight: bold;
    padding: 5px 0;
    border-right: 1px solid var(--border-color, #333);
    border-bottom: 1px solid var(--border-color, #333);
}
.template-boxed .grid-cell {
    height: 36px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    border-right: 1px solid var(--border-color, #333);
    border-bottom: 1px solid var(--border-color, #333);
    position: relative;
    cursor: pointer;
}

/* 标记层：用负 margin 居中而非 transform，保证 html2canvas 导出位置一致。
   top 百分比由 JS 按是否显示农历/节日动态写入内联样式 */
.mark-wrapper {
    position: absolute;
    width: 28px;
    height: 28px;
    top: 38%;
    left: 50%;
    margin-top: -14px;
    margin-left: -14px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 0;
}
.mark-wrapper img { display: block; width: 28px; height: 28px; }

/* 必须“已定位 + 正数 z-index”：html2canvas 不承认 flex 子项的 z-index，
   未加 position 时会被绝对定位的标记层盖住，导出图里数字就消失了 */
.solar-num { font-size: 11px; font-weight: 600; line-height: 1.2; position: relative; z-index: 2; }

.sub-slot {
    height: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 1;
}
.lunar-text { font-size: 7px; line-height: 1; transform: scale(0.9); }
.festival-text { font-size: 7px; color: #ff3b30; line-height: 1; transform: scale(0.85); font-weight: 600; }

.card-footer { font-size: 9px; text-align: center; padding-top: 4px; margin-top: 6px; border-top: 1px solid transparent; }
.card-footer.has-line { border-top-color: rgba(0,0,0,0.08); }
.template-boxed .card-footer { border-top: none; padding-top: 6px; }

/* Grid 间距使用 Chrome 61 可解析的 grid-gap */
.multi-month-box { display: grid; grid-template-columns: repeat(4, 1fr); grid-gap: 4px; margin-top: 4px; }
.month-chip { padding: 4px; font-size: 11px; text-align: center; border: 1px solid #ddd; border-radius: 4px; background: #fafafa; cursor: pointer; }
.month-chip.selected { background: #007aff; color: #fff; border-color: #007aff; }

/* 整年年历导出容器（由 JS 创建并挂载到离屏位置）。
   注意不能用 visibility:hidden，html2canvas 会照搬该属性导致导出空白 */
#yearlyStage {
    position: absolute;
    left: -10000px;
    top: 0;
    background: transparent;
    padding: 20px;
    pointer-events: none;
}

.status-toast {
    position: fixed;
    left: 50%;
    bottom: 16px;
    bottom: calc(16px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)));
    margin-left: -110px;
    width: 220px;
    padding: 8px 10px;
    border-radius: 18px;
    background: rgba(0, 0, 0, 0.78);
    color: #fff;
    font-size: 12px;
    text-align: center;
    z-index: 99;
    display: none;
}
.status-toast.show { display: block; }

@font-face { font-family: 'Freckle Face'; font-style: normal; font-weight: 400; font-display: swap; src: url('./fonts/freckle-face.woff2') format('woff2'); }
.control-hint { font-size: 11px; line-height: 1.6; color: #777; margin: 6px 0 10px; }
.typography-controls { background: #fff; border-radius: 8px; padding: 10px; margin-top: 10px; }
.typography-controls summary { cursor: pointer; font-size: 12px; font-weight: 600; color: #555; }
.size-controls { margin-top: 8px; }
.size-controls label { display: flex; align-items: center; min-width: 0; margin: 0; min-height: 30px; }
.size-controls label > span { width: 76px; flex-shrink: 0; }
.size-controls output { width: 42px; text-align: right; flex-shrink: 0; color: #007aff; font-weight: normal; }
.size-controls input { display: block; flex: 1; min-width: 0; width: 100%; margin: 0 8px; }
.spacing-controls { display: flex; margin-top: 8px; }
.spacing-controls > label { flex: 1; min-width: 0; margin: 0; }
.spacing-controls > label + label { margin-left: 12px; }
.spacing-controls span { display: block; }
.spacing-controls output { float: right; color: #007aff; font-weight: normal; }
.spacing-controls input { display: block; width: 100%; margin: 6px 0 0; }
.preview-container { overflow: auto; }
#card { flex-shrink: 0; transition: none; }
.card-title { font-size: var(--sizeTitle, 18px); line-height: 1.25; }
.card-sub { font-size: var(--sizeYear, 9px) !important; line-height: 1.4; }
.template-basic .week-header, .template-boxed .week-header { font-size: var(--sizeWeek, 10px); }
.solar-num { font-size: var(--sizeDate, 11px); }
.lunar-text, .festival-text { font-size: var(--sizeLunar, 7px); }
.sub-slot { height: calc(var(--sizeLunar, 7px) + 5px); flex-shrink: 0; }
.no-date-sub .sub-slot { display: none; }
.card-footer { font-size: var(--sizeFooter, 9px); }
.template-basic .grid-cell, .template-boxed .grid-cell {
    height: var(--cellHeight, 34px);
    min-height: 0;
    padding: 0;
    justify-content: center;
}
.template-boxed .grid-cell { height: var(--cellHeight, 36px); }

textarea { box-sizing: border-box; width:100%; border:1px solid #ddd; border-radius:6px; padding:8px; font:12px/1.6 sans-serif; resize:vertical; }
.quote-controls { margin-top:12px; padding-top:10px; border-top:1px solid #eee; }
.quote-controls summary { cursor:pointer; font-size:12px; font-weight:600; color:#45505f; padding:4px 0; }
#quoteMonthLabel { margin-left:6px; font-weight:400; color:#89919c; font-size:11px; }
.quote-editor { margin-top:10px; }
.quote-editor textarea { min-height:74px; background:#fafbfd; }
@media (max-width:600px) { .quote-editor textarea { font-size:16px; } }
.quote-style-row { display:grid; grid-template-columns:minmax(0,1fr) 64px minmax(0,1fr); grid-gap:12px; margin-top:12px; align-items:start; }
.quote-style-row label { margin:0; line-height:18px; }
.quote-style-row select, .quote-style-row input[type="color"] { display:block; margin:4px 0 0; width:100%; height:34px; box-sizing:border-box; border:1px solid #dde2e8; border-radius:6px; background:#fafbfd; }
.quote-style-row input[type="color"] { padding:4px; cursor:pointer; }
.quote-editor .control-hint { margin:10px 0 0; }
.monthly-quote { white-space:pre-wrap; overflow-wrap:break-word; word-wrap:break-word; line-height:1.6; margin-top:10px; }
.diagnostics { font-size:12px; line-height:1.6; margin:14px 0; }
.diagnostics button { margin:6px 6px 0 0; padding:8px; }
.preview-container { justify-content:flex-start; overflow:hidden; }
#card { margin:0 auto; }

.web-intro { text-align:center; color:#777; font-size:12px; }
body.web-version { max-width:1100px; margin:0 auto; }
#imageResult { position:fixed; top:0; bottom:0; left:0; right:0; z-index:1000; background:rgba(24,32,45,.48); display:flex; align-items:center; justify-content:center; padding:24px; box-sizing:border-box; }
#imageResult[hidden] { display:none; }
.result-dialog { width:760px; max-width:100%; height:82vh; max-height:840px; min-height:0; display:flex; flex-direction:column; overflow:hidden; background:#fff; border-radius:18px; box-shadow:0 24px 80px #0004; font-family:-apple-system,BlinkMacSystemFont,'Segoe UI','Microsoft YaHei',sans-serif; }
.result-header { display:flex; align-items:center; justify-content:space-between; padding:18px 22px; border-bottom:1px solid #edf0f3; }
.result-header h3 { margin:0; font-size:17px; font-weight:600; color:#202938; }
.result-header p { margin:5px 0 0; font-size:12px; color:#88909c; }
#closeResult { width:34px; height:34px; padding:0; border:0; border-radius:50%; background:#f0f2f5; color:#637083; font:24px/1 sans-serif; cursor:pointer; }
.result-stage { flex:1; min-height:0; display:flex; align-items:center; justify-content:center; overflow:hidden; padding:24px; background-color:#f8f9fb; background-image:linear-gradient(45deg,#e9edf1 25%,transparent 25%),linear-gradient(-45deg,#e9edf1 25%,transparent 25%),linear-gradient(45deg,transparent 75%,#e9edf1 75%),linear-gradient(-45deg,transparent 75%,#e9edf1 75%); background-size:16px 16px; background-position:0 0,0 8px,8px -8px,-8px 0; }
#resultImage { display:block; min-width:0; min-height:0; width:auto; height:auto; max-width:100%; max-height:100%; object-fit:contain; }
.result-footer { display:flex; align-items:center; justify-content:space-between; padding:14px 22px; border-top:1px solid #edf0f3; }
.result-footer span { color:#88909c; font-size:12px; }
#resultDownload { display:inline-block; padding:10px 22px; background:#007aff; color:#fff; border-radius:9px; text-decoration:none; font-size:13px; font-weight:600; }
#resultDownload:hover { background:#0068db; }
@media (max-width:600px) { #imageResult { padding:12px; } .result-dialog { height:85vh; border-radius:14px; } .result-header,.result-footer { padding:14px 16px; } .result-stage { padding:16px; } }
@media (min-width:850px) {
 body.web-version { display:grid; grid-template-columns:minmax(0,460px) minmax(0,1fr); grid-gap:16px 32px; padding:28px; }
 body.web-version > h2, .web-intro { grid-column:1 / -1; margin:0; }
 .steps-header, .step-content { grid-column:1; }
 .preview-toolbar { grid-column:2; grid-row:3; align-self:start; }
 .preview-container { grid-column:2; grid-row:4 / span 3; align-self:start; position:sticky; top:20px; }
 .step-content { grid-row:4 / span 3; }
}
