/* 浮墨邮局 · 票样与邮封
   作用域：只有 :root 的 --post-* 变量，以及 .philatelic / .postal-dialog 内部。 */

:root {
  --post-ink: #19172a;        /* 护邮卡、正文 */
  --post-ink-soft: #57515f;   /* 次要文字 */
  --post-paper: #fdf8ea;      /* 票纸 */
  --post-sheet: #fffaf0;      /* 信纸 */
  --post-line: #cdbf9f;       /* 分隔线，仅装饰 */
  --post-blue: #2947ad;       /* 帽蓝：票框、链接、焦点 */
  --post-orange: #ff7a45;     /* 仅“最新”与主操作 */
  --post-font: system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  --post-numeral: "Helvetica Neue", Arial, "PingFang SC", sans-serif;
  --post-gap: 16px;
  --post-mount: 7px;          /* 护邮卡露边 */
  --post-perf-r: 3.5px;       /* 齿孔半径 */
  --post-perf-s: 11px;        /* 齿孔间距 */
  --post-hover: 160ms;
  --post-enter: 220ms;
  --post-ease: cubic-bezier(.2, .7, .2, 1);
}

.philatelic, .postal-dialog {
  color: var(--post-ink);
  font-family: var(--post-font);
  line-height: 1.5;
}
:is(.philatelic, .postal-dialog) *,
:is(.philatelic, .postal-dialog) *::before,
:is(.philatelic, .postal-dialog) *::after { box-sizing: border-box; }

/* ---------- 月份与网格 ---------- */
.philatelic .post-notice {
  margin: 0 0 20px;
  padding: 10px 14px;
  border: 1px solid var(--post-ink);
  border-left-width: 5px;
  background: var(--post-sheet);
  font-size: .875rem;
}
.philatelic .post-month { container: post-month / inline-size; margin: 0 0 36px; }
.philatelic .post-month-head {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px;
  margin: 0 0 18px; padding: 0 0 8px;
  border-bottom: 2px solid var(--post-ink);
}
.philatelic .post-month-name { margin: 0; font-size: 1.5rem; line-height: 1.2; font-weight: 800; }
.philatelic .post-month-meta { margin: 0; color: var(--post-ink-soft); font-size: .875rem; }
.philatelic .post-empty { margin: 0; padding: 4px 0; color: var(--post-ink-soft); }

/* 上限4列；每列不足13.75rem就减列 */
.philatelic .post-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(max(13.75rem, (100% - 3 * var(--post-gap)) / 4), 1fr));
  gap: var(--post-gap);
  margin: 0; padding: 0; list-style: none;
}
.philatelic .post-grid > li { display: flex; min-width: 0; margin: 0; }

/* ---------- 护邮卡：外层 button ---------- */
.philatelic .post-card {
  position: relative;
  display: flex; flex: 1; min-width: 0; width: 100%;
  margin: 0; padding: var(--post-mount);
  border: 0; border-radius: 3px;
  background: var(--post-ink); color: var(--post-ink);
  font: inherit; text-align: start;
  cursor: pointer;
}
.philatelic .post-card:focus-visible { outline: 3px solid var(--post-blue); outline-offset: 3px; }
.philatelic .post-latest {
  position: absolute; z-index: 1; top: -9px; inset-inline-end: 12px;
  padding: 1px 9px; border: 1px solid var(--post-ink);
  background: var(--post-orange); color: var(--post-ink);
  font-size: .8125rem; font-weight: 800;
}

/* ---------- 齿孔纸与票框 ---------- */
:is(.philatelic, .postal-dialog) .post-paper {
  --hole: radial-gradient(circle, #0000 var(--post-perf-r), #000 calc(var(--post-perf-r) + .5px));
  display: flex; flex: 1; min-width: 0;
  padding: 10px;
  background: var(--post-paper);
  -webkit-mask:
    linear-gradient(#000 0 0) center / calc(100% - 2 * var(--post-perf-r) - 1px) calc(100% - 2 * var(--post-perf-r) - 1px) no-repeat,
    var(--hole) calc(var(--post-perf-s) / -2) calc(var(--post-perf-s) / -2) / var(--post-perf-s) var(--post-perf-s) round;
  mask:
    linear-gradient(#000 0 0) center / calc(100% - 2 * var(--post-perf-r) - 1px) calc(100% - 2 * var(--post-perf-r) - 1px) no-repeat,
    var(--hole) calc(var(--post-perf-s) / -2) calc(var(--post-perf-s) / -2) / var(--post-perf-s) var(--post-perf-s) round;
}
/* 基础样式即“类型未说明”，未知枚举自动落到这里 */
:is(.philatelic, .postal-dialog) .post-frame {
  display: flex; flex-direction: column; flex: 1; min-width: 0; gap: 8px;
  padding: 10px;
  border: 2px dotted var(--post-blue);
}
:is(.philatelic, .postal-dialog) .post-paper[data-type="reset"] .post-frame { border-style: solid; }
:is(.philatelic, .postal-dialog) .post-paper[data-type="scheduled"] .post-frame { border-style: dashed; }

/* 类型 */
:is(.philatelic, .postal-dialog) .post-type {
  display: flex; align-items: baseline; gap: 6px;
  font-size: .8125rem; font-weight: 800; line-height: 1.35;
  overflow-wrap: anywhere;
}
:is(.philatelic, .postal-dialog) .post-type::before {
  content: ""; flex: none; width: 10px; height: 10px;
  border: 2px dotted currentColor; border-radius: 50%;
}
:is(.philatelic, .postal-dialog) .post-type[data-type="reset"]::before { border-style: solid; border-radius: 0; background: currentColor; }
:is(.philatelic, .postal-dialog) .post-type[data-type="scheduled"]::before { border-style: solid; border-radius: 0; transform: rotate(45deg) scale(.85); }

/* 票图：日期数字。重置=实底刻线，预告=空心，未说明=斜纹 */
:is(.philatelic, .postal-dialog) .post-date { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
:is(.philatelic, .postal-dialog) .post-day {
  display: grid; place-items: center;
  min-height: 84px;
  background: repeating-linear-gradient(135deg, #2947ad24 0 1px, #0000 1px 7px);
  color: var(--post-blue);
  font: 800 3.5rem/1 var(--post-numeral);
  font-variant-numeric: tabular-nums; letter-spacing: -.04em;
}
:is(.philatelic, .postal-dialog) .post-paper[data-type="reset"] .post-day {
  background: repeating-linear-gradient(0deg, #ffffff1f 0 1px, #0000 1px 5px), var(--post-blue);
  color: var(--post-paper);
}
:is(.philatelic, .postal-dialog) .post-paper[data-type="scheduled"] .post-day {
  background: none; border-block: 1px solid var(--post-blue);
}
:is(.philatelic, .postal-dialog) .post-time {
  font-size: .8125rem; font-variant-numeric: tabular-nums; color: var(--post-ink-soft);
}

/* 标题三行；全文在邮封 */
:is(.philatelic, .postal-dialog) .post-title {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; line-clamp: 3;
  overflow: hidden;
  font-size: 1rem; font-weight: 750; line-height: 1.4;
  overflow-wrap: anywhere;
}
/* 对象与核验：换行，绝不截断 */
:is(.philatelic, .postal-dialog) .post-scope {
  align-self: flex-start; max-width: 100%;
  padding: 3px 7px; border: 1px solid var(--post-ink);
  font-size: .8125rem; line-height: 1.4;
  overflow-wrap: anywhere;
}
:is(.philatelic, .postal-dialog) .post-proof {
  display: flex; align-items: flex-start; gap: 7px;
  padding-top: 8px; border-top: 1px solid var(--post-line);
  font-size: .8125rem; line-height: 1.4;
  overflow-wrap: anywhere;
}
:is(.philatelic, .postal-dialog) .post-frame > .post-proof { margin-top: auto; }

/* 核验戳形：x 双环带勾 / agy 虚环 / multi 叠环 / 其余单环 */
:is(.philatelic, .postal-dialog) .post-mark {
  position: relative; flex: none; width: 16px; height: 16px; margin-top: 1px;
  border: 1.5px solid currentColor; border-radius: 50%;
}
:is(.philatelic, .postal-dialog) .post-proof[data-proof="x"] .post-mark { outline: 1px solid currentColor; outline-offset: 1.5px; }
:is(.philatelic, .postal-dialog) .post-proof[data-proof="x"] .post-mark::after {
  content: ""; position: absolute; left: 4px; top: 1px; width: 5px; height: 8px;
  border: solid currentColor; border-width: 0 2px 2px 0; transform: rotate(42deg);
}
:is(.philatelic, .postal-dialog) .post-proof[data-proof="x"] { gap: 10px; padding-inline-start: 3px; }
:is(.philatelic, .postal-dialog) .post-proof[data-proof="agy"] .post-mark { border-style: dashed; }
:is(.philatelic, .postal-dialog) .post-proof[data-proof="multi"] .post-mark { margin-inline-end: 6px; }
:is(.philatelic, .postal-dialog) .post-proof[data-proof="multi"] .post-mark::after {
  content: ""; position: absolute; left: 4.5px; top: -1.5px; width: 16px; height: 16px;
  border: 1.5px solid currentColor; border-radius: 50%;
}

/* ---------- 窄容器：先两列，再单列 ---------- */
@container post-month (max-width: 33rem) {
  .philatelic .post-grid { --post-gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .philatelic .post-card { --post-mount: 5px; }
  .philatelic .post-paper { padding: 8px; }
  .philatelic .post-frame { padding: 7px; }
  .philatelic .post-day { min-height: 64px; font-size: 2.75rem; }
  .philatelic .post-title { font-size: .9375rem; }
}
/* rem 阈值：用户放大根字号时也会转单列 */
@container post-month (max-width: 21.75rem) {
  .philatelic .post-grid { grid-template-columns: minmax(0, 1fr); }
  .philatelic .post-frame { display: grid; grid-template-columns: 5.25rem minmax(0, 1fr); align-content: start; gap: 7px 10px; }
  .philatelic .post-frame > * { grid-column: 2; }
  .philatelic .post-frame > .post-date { grid-column: 1; grid-row: 1 / span 4; }
  .philatelic .post-frame > .post-scope { justify-self: start; }
}
/* 集成方测得两列放不下时设置 data-columns="1" */
.philatelic .post-grid[data-columns="1"] { grid-template-columns: minmax(0, 1fr); }
.philatelic .post-grid[data-columns="1"] .post-frame { display: grid; grid-template-columns: 5.25rem minmax(0, 1fr); align-content: start; gap: 7px 10px; }
.philatelic .post-grid[data-columns="1"] .post-frame > * { grid-column: 2; }
.philatelic .post-grid[data-columns="1"] .post-frame > .post-date { grid-column: 1; grid-row: 1 / span 4; }
.philatelic .post-grid[data-columns="1"] .post-frame > .post-scope { justify-self: start; }

/* ---------- 邮封 ---------- */
.postal-dialog {
  container: postal / inline-size;
  box-sizing: border-box;
  width: min(880px, calc(100vw - 32px));
  max-width: none; max-height: calc(100dvh - 32px);
  padding: 0; border: 2px solid var(--post-ink); border-radius: 4px;
  background: var(--post-sheet);
  overflow: auto; overscroll-behavior: contain;
}
.postal-dialog::backdrop { background: rgb(25 23 42 / .68); }
.postal-dialog .postal-bar {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 8px 8px 20px;
  background: var(--post-sheet);
  border-bottom: 6px solid;
  border-image: repeating-linear-gradient(115deg, var(--post-blue) 0 16px, var(--post-sheet) 16px 24px, var(--post-ink) 24px 40px, var(--post-sheet) 40px 48px) 6;
}
.postal-dialog .postal-bar-title { margin: 0; font-size: .875rem; font-weight: 700; }
.postal-dialog .postal-bar form { margin: 0; }
.postal-dialog .postal-close {
  min-width: 44px; min-height: 44px; padding: 0 14px;
  border: 1px solid var(--post-ink); border-radius: 22px;
  background: transparent; color: inherit; font: inherit; cursor: pointer;
}
.postal-dialog .postal-body { display: grid; grid-template-columns: 264px minmax(0, 1fr); }
.postal-dialog .postal-stamp { padding: 28px 22px; background: var(--post-ink); }
.postal-dialog .postal-stamp .post-day { min-height: 128px; font-size: 5rem; }
.postal-dialog .postal-sheet { min-width: 0; padding: 28px 32px 32px; }
.postal-dialog .postal-title { margin: 8px 0 12px; font-size: 1.625rem; line-height: 1.3; font-weight: 800; overflow-wrap: anywhere; }
.postal-dialog .postal-summary { max-width: 38em; margin: 0 0 20px; line-height: 1.7; overflow-wrap: anywhere; }
.postal-dialog .postal-facts { margin: 0 0 24px; border-top: 1px solid var(--post-line); }
.postal-dialog .postal-facts > div {
  display: grid; grid-template-columns: 8.5em minmax(0, 1fr); gap: 4px 16px;
  padding: 10px 0; border-bottom: 1px solid var(--post-line);
}
.postal-dialog .postal-facts dt { color: var(--post-ink-soft); }
.postal-dialog .postal-facts dd { margin: 0; overflow-wrap: anywhere; }
.postal-dialog .postal-facts .post-proof { padding-top: 0; border-top: 0; font-size: 1rem; }
.postal-dialog .postal-facts .post-mark { margin-top: 4px; }
.postal-dialog a { color: var(--post-blue); text-underline-offset: 3px; overflow-wrap: anywhere; }
.postal-dialog .postal-action {
  display: inline-flex; align-items: center; min-height: 48px; padding: 8px 22px;
  border: 1px solid var(--post-ink); border-radius: 24px;
  background: var(--post-orange); color: var(--post-ink);
  font-weight: 750; text-decoration: none;
}
.postal-dialog :is(a, button):focus-visible { outline: 3px solid var(--post-blue); outline-offset: 3px; }

@container postal (max-width: 39rem) {
  .postal-dialog .postal-body { grid-template-columns: minmax(0, 1fr); }
  .postal-dialog .postal-stamp { padding: 14px; }
  .postal-dialog .postal-stamp .post-day { min-height: 72px; font-size: 3rem; }
  .postal-dialog .postal-stamp :is(.post-title, .post-scope, .post-proof) { display: none; } /* 信纸内均有全文 */
  .postal-dialog .postal-sheet { padding: 20px 18px 26px; }
  .postal-dialog .postal-title { font-size: 1.375rem; }
  .postal-dialog .postal-facts > div { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- 动效：仅两处，均为 transition，可中途反向 ---------- */
@media (prefers-reduced-motion: no-preference) {
  .philatelic .post-paper { transition: transform var(--post-hover) var(--post-ease); }
  .postal-dialog {
    opacity: 0; transform: translateY(8px);
    transition: opacity var(--post-enter) var(--post-ease), transform var(--post-enter) var(--post-ease),
      overlay var(--post-enter) allow-discrete, display var(--post-enter) allow-discrete;
  }
  .postal-dialog[open] { opacity: 1; transform: none; }
  @starting-style { .postal-dialog[open] { opacity: 0; transform: translateY(8px); } }
}
@media (prefers-reduced-motion: no-preference) and (hover: hover) and (pointer: fine) {
  .philatelic .post-card:hover .post-paper { transform: translateY(-3px); }
}

@media (forced-colors: active) {
  :is(.philatelic, .postal-dialog) .post-paper { -webkit-mask: none; mask: none; }
  .philatelic .post-card { border: 1px solid ButtonText; }
  .philatelic .post-card:focus-visible, .postal-dialog :is(a, button):focus-visible { outline-color: Highlight; }
}
