/* ---- 字体（本地托管的可变字体，见 fonts/） ---- */
/* Noto Serif SC 只含页面会用到的字符；改动页面文案后需重新生成，见 README */
@font-face {
  font-family: 'Noto Serif SC';
  font-weight: 200 900;
  font-display: swap;
  src: url('../fonts/noto-serif-sc.woff2?v=dd18346c') format('woff2');
}
@font-face {
  font-family: 'Cormorant Garamond';
  font-weight: 300 700;
  font-display: swap;
  src: url('../fonts/cormorant-garamond.woff2?v=5d618c46') format('woff2');
}

/* ---- 变量（默认为「松釉青灰」，JS 按主题覆盖 --bg0 / --accent） ---- */
/* 注册成颜色，切换主题时两个变量本身渐变，用到它们的地方（含进度底色、色点外圈、骨架灰条）
   一起按同一节奏变色，不用每处单独写 transition */
@property --bg0 {
  syntax: '<color>';
  inherits: true;
  initial-value: #e8efe9;
}
@property --accent {
  syntax: '<color>';
  inherits: true;
  initial-value: #59705f;
}

:root {
  --bg0: #e8efe9;
  --accent: #59705f;
  --ink: #1b1f23;
  --muted: #5b6570;
  --track: color-mix(in srgb, var(--accent) 15%, transparent);
  --theme-dur: .8s;
  --ease-theme: var(--theme-dur) ease;
  /* 回弹（由 Motion 的 spring 生成）：数字落定 / 色点按下松开 */
  --spring-soft: linear(0, .0663, .2105, .3763, .5332, .6669, .7733, .8533, .9107, .9499, .9754, .9911, 1, 1.0044, 1.0061, 1.0062, 1.0055, 1.0045, 1.0035, 1.0026, 1.0018, 1.0012, 1.0008, 1, 1);
  --spring-pop: linear(0, .12, .3667, .6221, .8271, .9637, 1.0379, 1.0658, 1.0652, 1.051, 1.0332, 1.0174, 1.006, .9992, .9961, 1, .996, .9972, .9984, .9993, .9999, 1, 1);
  --font-serif: 'Noto Serif SC', 'Songti SC', 'STSong', serif;
  --font-num: 'Cormorant Garamond', 'Times New Roman', serif;
  /* 桌面版（设计稿 3a，1920×1080）的缩放单位：1 设计像素 = var(--s) */
  --s: min(calc(100vw / 1920), calc(100vh / 1080));
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

body {
  min-height: 100vh;
  min-height: 100svh;
  background-color: var(--bg0);
  color: var(--ink);
  font-family: var(--font-serif);
  font-variant-numeric: lining-nums;
  -webkit-font-smoothing: antialiased;
}

/* 首次套用主题之后才开（scripts/theme.js 加 theme-ready），打开页面时不从默认色渐变过去 */
:root.theme-ready {
  transition: --bg0 var(--ease-theme), --accent var(--ease-theme);
}

/* ---- 背景：每个主题一层柔光 + 颗粒，切换时交叉淡入 ---- */
.bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.bg-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: var(--b0);
  opacity: 0;
  /* 旧主题等新主题完全盖住后再撤，两层同时半透明会透出底色、颗粒也忽浓忽淡 */
  transition: opacity 0s linear var(--theme-dur);
}

.bg-layer.is-active {
  z-index: 1;
  opacity: 1;
  transition: opacity var(--ease-theme);
}

.blob {
  position: absolute;
  border-radius: 50%;
  will-change: transform;
}

.blob-a {
  left: 50%;
  top: -40%;
  width: calc(1800 * var(--s));
  height: calc(1350 * var(--s));
  background: radial-gradient(closest-side, var(--b1), transparent);
  animation: flowA 26s ease-in-out infinite alternate;
}

.blob-b {
  left: -24%;
  top: 46%;
  width: calc(1500 * var(--s));
  height: calc(1200 * var(--s));
  background: radial-gradient(closest-side, var(--blob-b), transparent);
  animation: flowB 32s ease-in-out infinite alternate;
}

.blob-c {
  left: 26%;
  top: 18%;
  width: calc(960 * var(--s));
  height: calc(960 * var(--s));
  background: radial-gradient(closest-side, var(--blob-c), transparent);
  animation: flowC 38s ease-in-out infinite alternate;
}

.bg-layer:not(.is-active) .blob {
  animation-play-state: paused;
}

.grain {
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20width%3D%27180%27%20height%3D%27180%27%3E%3Cfilter%20id%3D%27n%27%3E%3CfeTurbulence%20type%3D%27fractalNoise%27%20baseFrequency%3D%27.85%27%20numOctaves%3D%272%27%20stitchTiles%3D%27stitch%27%2F%3E%3CfeColorMatrix%20values%3D%270%200%200%200%200%200%200%200%200%200%200%200%200%200%200%200%200%200%20.09%200%27%2F%3E%3C%2Ffilter%3E%3Crect%20width%3D%27100%25%27%20height%3D%27100%25%27%20filter%3D%27url%28%23n%29%27%2F%3E%3C%2Fsvg%3E");
}

/* 位移按色块自身尺寸的百分比，手机版色块缩小后幅度同比缩小 */
@keyframes flowA {
  0% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(-15%, 13%) scale(1.12); }
  100% { transform: translate(-5%, 24%) scale(.95); }
}

@keyframes flowB {
  0% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(22%, -18%) scale(1.18); }
  100% { transform: translate(36%, -5%) scale(1.02); }
}

@keyframes flowC {
  0% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(-38%, -14%) scale(1.25); }
  100% { transform: translate(25%, 19%) scale(.9); }
}

/* ---- 页面骨架：色点 / 主体 / 页脚 ---- */
.page {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: max(20px, calc(56 * var(--s))) max(20px, calc(192 * var(--s))) max(24px, calc(72 * var(--s)));
  overflow-x: clip;
}

/* ---- 主题色点 ---- */
.themes {
  display: flex;
  justify-content: flex-end;
  gap: max(12px, calc(18 * var(--s)));
}

.theme-dot {
  position: relative;
  appearance: none;
  border: none;
  padding: 0;
  width: max(14px, calc(18 * var(--s)));
  height: max(14px, calc(18 * var(--s)));
  border-radius: 50%;
  background: var(--dot);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  /* 外圈从色点边缘向外长出来，而不是凭空淡入 */
  box-shadow: 0 0 0 0 var(--bg0), 0 0 0 0 var(--dot);
  transition: box-shadow .35s cubic-bezier(.2, .7, .3, 1), transform .7s var(--spring-pop);
}

@media (hover: hover) {
  .theme-dot:hover {
    transform: scale(1.15);
  }
}

.theme-dot:active {
  transform: scale(.86);
  transition-duration: .35s, .12s;
  transition-timing-function: cubic-bezier(.2, .7, .3, 1), ease-out;
}

/* 扩大点击区域，不改变视觉尺寸 */
.theme-dot::after {
  content: '';
  position: absolute;
  inset: -8px;
}

.theme-dot[aria-pressed='true'] {
  box-shadow: 0 0 0 3px var(--bg0), 0 0 0 4.5px var(--dot);
}

.theme-dot:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 5px;
}

/* ---- 主体 ---- */
.hero {
  align-self: center;
  display: flex;
  flex-direction: column;
  padding: 24px 0;
}

/* 首屏骨架（主体和页脚） */
.hero,
.foot {
  /* 灰条跟随主题色 */
  --skullet-base: color-mix(in srgb, var(--accent) 16%, transparent);
  --skullet-highlight: rgb(255 255 255 / .45);
  /* 文字条只画字身（大写高度到基线），细一些，上下行不粘连 */
  --skullet-text-top: cap-height;
  --skullet-text-bottom: baseline;
}

/* 脚本接管前先藏住 -- 占位，避免闪一下 */
.hero[data-pending],
.foot[data-pending] {
  visibility: hidden;
}

/* 大号数字在骨架里画成整块（index.html 里标了 skullet-block），给它圆角 */
.hero [skullet-block] {
  border-radius: calc(18 * var(--s));
}

/* skullet 把内容包进一层 pane，保持原来的排布：主体纵向；
   页脚沿用它自己的排法（桌面横排、两端对齐，手机竖排），所以一层层从 .foot 继承。
   骨架阶段 pane 里还有 loading、ghost 两层，骨架内容在 ghost 里，也要照这样排 */
.hero > [skullet-pane] {
  display: flex;
  flex-direction: column;
}

.foot > [skullet-pane],
.foot > [skullet-pane] > [skullet-loading],
.foot > [skullet-pane] > [skullet-loading] > [skullet-ghost] {
  display: flex;
  flex: 1;
  flex-direction: inherit;
  flex-wrap: inherit;
  justify-content: inherit;
  gap: inherit;
}

.headline {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: calc(22 * var(--s));
  font-weight: 400;
}

.headline-aside {
  font-size: max(16px, calc(32 * var(--s)));
  color: var(--muted);
}

.headline-aside:empty {
  display: none;
}

.headline-name {
  font-size: max(30px, calc(72 * var(--s)));
  font-weight: 600;
  line-height: 1;
  letter-spacing: .08em;
  color: var(--accent);
}

.clock {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: calc(30 * var(--s));
  margin-top: calc(40 * var(--s));
  font-variant-numeric: lining-nums tabular-nums;
}

.clock-days,
.clock-hms {
  font-family: var(--font-num);
  font-variant-numeric: lining-nums tabular-nums;
}

.clock-days {
  font-size: calc(520 * var(--s));
  font-weight: 500;
  line-height: .78;
  letter-spacing: -.03em;
}

/* 桌面版：「天」和时分秒与天数排成一行 */
.clock-side {
  display: contents;
}

.clock-unit {
  font-size: calc(80 * var(--s));
  margin-right: calc(48 * var(--s));
}

.clock-hms {
  font-size: calc(210 * var(--s));
  font-weight: 400;
  line-height: 1;
  letter-spacing: .01em;
}

/* 数字翻动：旧数字略向下沉、模糊着很快淡掉，新数字从上方带一点回弹落定。
   位移不到 .2em、旧数字先走，两个数字不会在行外叠成重影；
   同时变的几位从右往左错开一点（scripts/countdown.js 设 animation-delay） */
.digit {
  position: relative;
  display: inline-block;
}

.digit-in,
.digit-out {
  display: inline-block;
}

.digit-in {
  animation:
    digitInMove .75s var(--spring-soft) both,
    digitInFade .4s cubic-bezier(.2, .7, .3, 1) both;
}

.digit-out {
  position: absolute;
  left: 0;
  top: 0;
  animation: digitOut .22s cubic-bezier(.2, .6, .4, 1) both;
}

@keyframes digitInMove {
  0% { transform: translateY(-.16em); }
  100% { transform: none; }
}

/* 前 25% 不显出来，等旧数字先淡掉大半，两个数字不糊在一起 */
@keyframes digitInFade {
  0%, 25% { opacity: 0; filter: blur(.04em); }
  100% { opacity: 1; filter: none; }
}

@keyframes digitOut {
  0% { transform: none; opacity: 1; filter: none; }
  100% { transform: translateY(.12em); opacity: 0; filter: blur(.03em); }
}

.info {
  margin-top: calc(44 * var(--s));
  font-size: max(15px, calc(26 * var(--s)));
  color: var(--muted);
  text-wrap: balance;
}

.range-to:not(:empty)::before {
  content: ' 至 ';
}

.range-total::before {
  content: ' · ';
}

.info-progress,
.vprogress {
  display: none;
}

.progress {
  width: 100%;
  margin-top: calc(72 * var(--s));
  display: flex;
  flex-direction: column;
  gap: max(10px, calc(16 * var(--s)));
}

.progress-track {
  height: max(3px, calc(4 * var(--s)));
  border-radius: 2px;
  background: var(--track);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 100%;
  background: var(--accent);
  transform-origin: left center;
  transform: scaleX(0);
  transition: transform .6s ease;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  font-size: max(14px, calc(22 * var(--s)));
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---- 页脚 ---- */
.foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px calc(84 * var(--s));
  font-size: max(14px, calc(22 * var(--s)));
}

.foot-item {
  display: flex;
  gap: max(12px, calc(18 * var(--s)));
  align-items: baseline;
}

/* 没有下一个节日时只隐藏内容，位置留着，「下个周日」不跟着挪 */
.foot-item.is-empty {
  visibility: hidden;
}

.foot-label {
  font-size: max(13px, calc(19 * var(--s)));
  color: var(--muted);
  letter-spacing: .1em;
}

.foot-when::before {
  content: ' · ';
}

.foot-item.is-today .foot-value {
  display: none;
}

.foot-item.is-today .foot-when::before {
  content: none;
}

/* 桌面版多位数天数：两位数 340、三位及以上 260（设计稿 daysSizeW） */
@media (min-width: 641px) {
  .clock[data-digits='2'] .clock-days {
    font-size: calc(340 * var(--s));
  }

  .clock[data-digits='3'] .clock-days,
  .clock[data-digits='4'] .clock-days {
    font-size: calc(260 * var(--s));
  }
}

/* ---- 手机版（设计稿 2f：个位数出血，多位数放大，右侧竖向进度） ---- */
@media (max-width: 640px) {
  .page {
    padding: 8px 24px max(28px, env(safe-area-inset-bottom));
  }

  .theme-dot {
    width: 14px;
    height: 14px;
  }

  .foot-label {
    font-size: 13px;
  }

  .blob-a { width: 744px; height: 558px; }
  .blob-b { width: 620px; height: 496px; }
  .blob-c { width: 397px; height: 397px; }

  .themes {
    gap: 30px;
    min-height: 44px;
    align-items: center;
    margin-right: -3px;
  }

  .theme-dot::after {
    inset: -15px;
  }

  /* 右边让出竖向进度的位置，长日期折行时不压到竖条上 */
  .hero {
    padding: 24px 20px 24px 4px;
  }

  .headline {
    gap: 10px;
  }

  .headline-aside {
    font-size: 17px;
  }

  .headline-name {
    font-size: 38px;
    line-height: 1.1;
  }

  /* 多位数：天数一行，时分秒另起一行 */
  .clock {
    flex-wrap: wrap;
    column-gap: 14px;
    row-gap: 26px;
    margin-top: 32px;
  }

  /* 窄屏（约 360px 以下）按屏宽缩小，「天」不被挤到下一行，也不贴上右侧竖向进度：
     数字 + 间距 + 「天」要留在竖条左边 16px 以内，100vw - 140px 是留给数字的宽度，
     两位数约 .9em 宽、三位数约 1.35em 宽 */
  .clock-days {
    font-size: min(250px, (100vw - 140px) * 1.1);
    line-height: .76;
    letter-spacing: -.04em;
  }

  .clock[data-digits='3'] .clock-days,
  .clock[data-digits='4'] .clock-days {
    font-size: min(176px, (100vw - 140px) * .74);
  }

  .clock-unit {
    font-size: 40px;
    margin-right: 0;
  }

  .clock-hms {
    flex-basis: 100%;
    font-size: 58px;
  }

  /* 个位数：数字放大到 340px 并伸出左边缘，「天」和时分秒叠在右侧 */
  .clock[data-digits='1'] {
    flex-wrap: nowrap;
    align-items: flex-end;
    margin-top: 20px;
    margin-left: -58px;
  }

  .clock[data-digits='1'] .clock-days {
    font-size: 340px;
    line-height: .74;
    letter-spacing: -.05em;
    color: var(--accent);
  }

  /* 揭开时 skullet 给骨架层和内容层加遮罩，遮罩只管层自己的框，伸出左边的个位数会被切掉一截。
     把层的框往左扩出伸出的距离、再用内边距抵消，排版不变 */
  .hero > [skullet-pane] {
    margin-left: -64px;
    padding-left: 64px;
  }

  .clock[data-digits='1'] .clock-side {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-bottom: 6px;
  }

  .clock[data-digits='1'] .clock-unit {
    font-size: 34px;
  }

  .clock[data-digits='1'] .clock-hms {
    flex-basis: auto;
    font-size: 40px;
  }

  .info {
    margin-top: 32px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 15px;
    line-height: 1.5;
  }

  .range-to:not(:empty)::before {
    content: ' — ';
  }

  .range-total::before {
    content: none;
  }

  .info-progress {
    display: block;
    margin-top: 12px;
    font-size: 13px;
  }

  .progress {
    display: none;
  }

  .vprogress {
    display: block;
    position: absolute;
    right: 34px;
    /* 上端竖排标签最多 3 个字，约 60px 高；再往上要和主题色点那一行隔开 */
    top: 122px;
    bottom: 170px;
    width: 2px;
    border-radius: 1px;
    background: var(--track);
  }

  .vprogress-fill {
    position: absolute;
    inset: 0;
    background: var(--accent);
    transform-origin: center top;
    transform: scaleY(0);
    transition: transform .6s ease;
  }

  .vprogress-dot {
    position: absolute;
    left: -4px;
    top: 0;
    width: 10px;
    height: 10px;
    margin-top: -5px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 3px var(--bg0);
    transition: top .6s ease;
  }

  .vprogress-pct {
    position: absolute;
    left: 50%;
    bottom: -40px;
    transform: translateX(-50%);
    font-size: 13px;
    color: var(--muted);
    white-space: nowrap;
  }

  /* 上端标签：等待期是上一个假期的名字（最多 3 个字），从竖条顶端往上排 */
  .vprogress-label {
    position: absolute;
    left: 50%;
    bottom: calc(100% + 13px);
    transform: translateX(-50%);
    writing-mode: vertical-rl;
    white-space: nowrap; /* 只设 bottom 时可用高度不够，不禁止折行就会一字一列 */
    font-size: 12px;
    letter-spacing: .3em;
    color: var(--muted);
  }

  .foot {
    flex-direction: column;
    gap: 14px;
    padding: 0 4px;
    font-size: 15px;
  }

  .foot-item {
    gap: 14px;
  }

  .foot-label {
    width: 76px;
    flex: none;
    white-space: nowrap;
  }

  .foot-text {
    display: contents;
  }

  .foot-value {
    flex: 1;
    min-width: 0;
  }

  .foot-when {
    color: var(--muted);
  }

  .foot-when::before {
    content: none;
  }

  .foot-item.is-today .foot-value {
    display: inline;
  }
}

@media (prefers-reduced-motion: reduce) {
  :root.theme-ready,
  .bg-layer,
  .bg-layer.is-active,
  .theme-dot,
  .progress-fill,
  .vprogress-fill,
  .vprogress-dot {
    transition: none;
  }

  .blob,
  .digit-in,
  .digit-out {
    animation: none !important;
  }

  .digit-out {
    display: none;
  }

  .theme-dot {
    transform: none !important;
  }
}
