/* ============ 主题变量 ============ */
:root {
  --font-sans: "PingFang SC", "HarmonyOS Sans SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  --font-serif: "Songti SC", "STSong", "Noto Serif SC", "Source Han Serif SC", "SimSun", serif;

  --r-lg: 18px;
  --r-md: 12px;
  --r-sm: 9px;

  --spring: #3f8f63;
  --summer: #c1503c;
  --autumn: #c0872c;
  --winter: #4a76a6;

  --spring-tint: rgba(63, 143, 99, .13);
  --summer-tint: rgba(193, 80, 60, .12);
  --autumn-tint: rgba(192, 135, 44, .15);
  --winter-tint: rgba(74, 118, 166, .13);
}

html[data-theme="light"] {
  --bg: #f2efe6;
  --bg-2: #e9e5d9;
  --surface: #fbf9f4;
  --surface-2: #f5f2ea;
  --ink: #232019;
  --ink-2: #5f594c;
  --muted: #938b78;
  --line: rgba(35, 32, 25, 0.10);
  --line-2: rgba(35, 32, 25, 0.06);
  --cinnabar: #b5372a;
  --cinnabar-soft: rgba(181, 55, 42, 0.10);
  --shadow: 0 1px 2px rgba(40, 34, 20, .05), 0 8px 24px -12px rgba(40, 34, 20, .18);
}

html[data-theme="dark"] {
  --bg: #16151a;
  --bg-2: #1d1c22;
  --surface: #1e1d23;
  --surface-2: #26242c;
  --ink: #ece7dc;
  --ink-2: #b3ac9d;
  --muted: #7d766a;
  --line: rgba(236, 231, 220, 0.12);
  --line-2: rgba(236, 231, 220, 0.07);
  --cinnabar: #e2604d;
  --cinnabar-soft: rgba(226, 96, 77, 0.14);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px -14px rgba(0, 0, 0, .6);

  --spring: #63b585;
  --summer: #e0705a;
  --autumn: #dba54b;
  --winter: #6f9dcb;

  --spring-tint: rgba(99, 181, 133, .17);
  --summer-tint: rgba(224, 112, 90, .16);
  --autumn-tint: rgba(219, 165, 75, .17);
  --winter-tint: rgba(111, 157, 203, .17);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--ink);
  background: var(--bg);
  background-image:
    radial-gradient(1200px 600px at 12% -8%, var(--cinnabar-soft), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(74, 118, 166, .10), transparent 62%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  transition: background-color .35s ease, color .35s ease;
}

button { font-family: inherit; color: inherit; }

.app {
  max-width: 1160px;
  margin: 0 auto;
  padding: 26px 22px 40px;
}

/* ============ 顶栏 ============ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.brand { display: flex; align-items: center; gap: 13px; }

.seal {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  border-radius: 11px;
  background: var(--cinnabar);
  color: #fff;
  font-family: var(--font-serif);
  font-size: 25px;
  line-height: 1;
  box-shadow: 0 4px 14px -4px var(--cinnabar);
  letter-spacing: 0;
}

.brand-text h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: .06em;
}

.brand-text p {
  margin: 3px 0 0;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: .1em;
}

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

.seg {
  display: flex;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  border-radius: 999px;
}

.seg-btn {
  border: 0;
  background: transparent;
  padding: 6px 17px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  color: var(--muted);
  transition: all .2s;
}

.seg-btn.is-on {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .08);
  font-weight: 600;
}

.icon-btn {
  min-width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  cursor: pointer;
  font-size: 17px;
  line-height: 1;
  transition: all .18s;
}

.icon-btn:hover { background: var(--surface-2); border-color: var(--ink-2); }
.icon-btn.small { min-width: 26px; height: 26px; font-size: 15px; }

.ghost-btn {
  height: 36px;
  padding: 0 15px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  transition: all .18s;
}

a.ghost-btn {
  height: 36px;
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.ghost-btn:hover { background: var(--surface-2); border-color: var(--ink-2); }

/* ============ 导航条 ============ */
.nav {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.title-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--r-sm);
  min-width: 168px;
  text-align: left;
}

.title-btn:hover { background: var(--surface-2); }

#titleMain {
  font-family: var(--font-serif);
  font-size: 25px;
  font-weight: 600;
  letter-spacing: .04em;
  line-height: 1.15;
}

#titleSub {
  font-size: 11.5px;
  color: var(--muted);
  letter-spacing: .08em;
}

.picker {
  position: absolute;
  top: 48px; left: 0;
  z-index: 20;
  width: 288px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow);
}

.picker-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.picker-row label { font-size: 12px; color: var(--muted); }

.picker-row select {
  flex: 1;
  height: 30px;
  padding: 0 8px;
  font-family: inherit;
  font-size: 13px;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.picker-months {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.picker-months button {
  height: 34px;
  border: 1px solid var(--line-2);
  background: var(--surface-2);
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
}

.picker-months button:hover { border-color: var(--cinnabar); color: var(--cinnabar); }
.picker-months button.on { background: var(--cinnabar); border-color: var(--cinnabar); color: #fff; }

/* ============ 主体 ============ */
.main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 296px;
  gap: 20px;
  align-items: start;
}

.sheet {
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  padding: 16px;
  box-shadow: var(--shadow);
}

.weekhead {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-bottom: 8px;
}

.weekhead span {
  text-align: center;
  font-size: 12px;
  letter-spacing: .18em;
  color: var(--muted);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line-2);
}

.weekhead span.rest { color: var(--cinnabar); opacity: .75; }

.grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

/* ---- 日期格 ---- */
.cell {
  position: relative;
  aspect-ratio: 1 / 1;
  min-height: 66px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: var(--r-md);
  cursor: pointer;
  padding: 0;
  transition: background-color .16s, border-color .16s, transform .16s;
}

.cell:hover { background: var(--surface-2); }
.cell:active { transform: scale(.97); }

.cell .d {
  font-size: 20px;
  font-weight: 500;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.cell .l {
  font-size: 11px;
  line-height: 1.2;
  color: var(--muted);
  letter-spacing: .02em;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell.dim { opacity: .32; }
.cell.rest .d { color: var(--cinnabar); opacity: .8; }

/* ---- 法定假日 / 调休角标 ---- */
.badge {
  position: absolute;
  top: 4px; right: 4px;
  width: 15px; height: 15px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  font-size: 9px;
  line-height: 1;
  font-weight: 600;
}

.badge.off { background: var(--cinnabar); color: #fff; }
.badge.work { color: var(--muted); box-shadow: inset 0 0 0 1px var(--line); }

.cell.off { background: var(--cinnabar-soft); }
.cell.off .d { color: var(--cinnabar); font-weight: 600; }
.cell.work .d,
.cell.work.rest .d { color: var(--ink); opacity: .82; }

.cell.sel {
  background: var(--surface-2);
  border-color: var(--ink-2);
}

/* 选中时保留假日底色 */
.cell.sel.off { background: var(--cinnabar-soft); }
.cell.sel.term { background: var(--term-tint); }

.cell.today .d {
  display: grid;
  place-items: center;
  width: 32px; height: 32px;
  background: var(--cinnabar);
  color: #fff;
  border-radius: 50%;
  font-weight: 600;
  box-shadow: 0 3px 10px -3px var(--cinnabar);
}

.cell.today .l { color: var(--cinnabar); }

.cell.term { background: var(--term-tint); }
.cell.term .l {
  color: var(--term-color);
  font-family: var(--font-serif);
  font-weight: 600;
}
.cell.term::after {
  content: "";
  position: absolute;
  bottom: 5px;
  width: 4px; height: 4px;
  border-radius: 50%;
  background: var(--term-color);
}

.cell.fest .l { color: var(--cinnabar); }

/* 农历初一 → 显示月份名 */
.cell.first .l { color: var(--ink-2); font-family: var(--font-serif); }

.cell.today.term { background: var(--term-tint); }

/* ---- 年视图 ---- */
.year-wrap {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(226px, 1fr));
  gap: 14px;
}

.mini { cursor: pointer; }

.mini-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
  padding: 0 2px;
}

.mini-head b {
  font-family: var(--font-serif);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .05em;
}

.mini-head i {
  font-style: normal;
  font-size: 11px;
  color: var(--muted);
}

.mini:hover .mini-head b { color: var(--cinnabar); }

.mini-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.mini .mc {
  position: relative;
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
  font-size: 10px;
  border-radius: 5px;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

.mini .mc.blank { visibility: hidden; }
.mini .mc.rest { color: var(--cinnabar); opacity: .7; }
.mini .mc.term { background: var(--term-color); color: #fff; font-weight: 600; }
.mini .mc.today { box-shadow: inset 0 0 0 1.5px var(--cinnabar); color: var(--cinnabar); font-weight: 700; }
.mini .mc.off { background: var(--cinnabar-soft); color: var(--cinnabar); }
.mini .mc.work { color: var(--ink-2); box-shadow: inset 0 0 0 1px var(--line); }

/* ============ 节假日图例 ============ */
.legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line-2);
  font-size: 11.5px;
  color: var(--muted);
}

.legend .lg { display: inline-flex; align-items: center; gap: 6px; letter-spacing: .04em; }
.legend .lg .badge { position: static; width: 14px; height: 14px; }
.legend .lg-count { margin-left: auto; letter-spacing: .04em; }
.legend .lg-count b { color: var(--ink-2); font-weight: 600; }
.legend .lg-link { color: var(--muted); text-decoration: none; border-bottom: 1px solid var(--line); }
.legend .lg-link:hover { color: var(--cinnabar); border-color: var(--cinnabar); }
.legend .lg-note { letter-spacing: .06em; }

/* ============ 侧栏 ============ */
.side { display: flex; flex-direction: column; gap: 16px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  padding: 16px 16px 18px;
  box-shadow: var(--shadow);
}

.card-title {
  margin: 0 0 12px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .22em;
  color: var(--muted);
}

/* ---- 节气轮 ---- */
#wheel svg { display: block; width: 100%; height: auto; }
.wheel-label { font-family: var(--font-serif); font-size: 10.5px; fill: var(--muted); }
.wheel-label.on { fill: var(--term-color); font-weight: 700; font-size: 11.5px; }
.wheel-cur { font-family: var(--font-serif); font-size: 26px; fill: var(--ink); font-weight: 600; }
.wheel-sub { font-size: 10.5px; fill: var(--muted); }

.term-note {
  margin: 12px 0 0;
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--ink-2);
  font-family: var(--font-serif);
  letter-spacing: .02em;
  padding-top: 12px;
  border-top: 1px solid var(--line-2);
}

/* ---- 日详情 ---- */
.dt-head { display: flex; align-items: flex-end; gap: 12px; }

.dt-day {
  font-family: var(--font-serif);
  font-size: 44px;
  line-height: .95;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.dt-meta { padding-bottom: 3px; font-size: 12px; color: var(--muted); line-height: 1.6; }
.dt-meta b { font-weight: 600; color: var(--ink-2); }

.dt-lunar {
  margin-top: 12px;
  font-family: var(--font-serif);
  font-size: 15px;
  letter-spacing: .04em;
}

.dt-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

.tag {
  font-size: 11.5px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  color: var(--ink-2);
}

.tag.jq { background: var(--term-tint); border-color: transparent; color: var(--term-color); font-weight: 600; }
.tag.fv { background: var(--cinnabar-soft); border-color: transparent; color: var(--cinnabar); }
.tag.off { background: var(--cinnabar); border-color: transparent; color: #fff; font-weight: 600; }
.tag.work { background: var(--surface-2); border-color: var(--line); color: var(--muted); }

.dt-rows {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line-2);
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.row { display: flex; gap: 10px; font-size: 12px; line-height: 1.6; }
.row .k { flex: 0 0 44px; color: var(--muted); letter-spacing: .08em; }
.row .v { flex: 1; color: var(--ink-2); }
.row .v.yi { color: var(--spring); }
.row .v.ji { color: var(--cinnabar); }

/* ============ 小组件模式 ============ */
html.widget body {
  background: rgba(251, 249, 244, .86);
  background-image: none;
}
html[data-theme="dark"].widget body { background: rgba(30, 29, 35, .84); }
html.widget .topbar,
html.widget .foot { display: none; }
html.widget .app { padding: 10px 10px 14px; }
html.widget .nav { margin-bottom: 10px; gap: 6px; }
html.widget .nav .title-btn { min-width: 0; padding: 2px 4px; }
html.widget #titleMain { font-size: 19px; }
html.widget #titleSub { font-size: 10.5px; }
html.widget .sheet { padding: 10px; box-shadow: none; }
html.widget .side { gap: 10px; }
html.widget .card { padding: 12px; box-shadow: none; }
html.widget .card-title { margin-bottom: 8px; }
html.widget .term-note { display: none; }
html.widget .main { gap: 10px; }

/* ============ 页脚 ============ */
.foot {
  margin-top: 22px;
  font-size: 11.5px;
  color: var(--muted);
  text-align: center;
  letter-spacing: .06em;
  display: flex;
  justify-content: center;
  gap: 10px;
}

.foot .dot { opacity: .5; }

/* ============ 响应式 ============ */
@media (max-width: 900px) {
  .main { grid-template-columns: 1fr; }
  .side { flex-direction: row; flex-wrap: wrap; }
  .side .card { flex: 1 1 280px; }
}

@media (max-width: 560px) {
  .app { padding: 18px 14px 32px; }
  .cell { min-height: 50px; aspect-ratio: auto; }
  .cell .d { font-size: 17px; }
  .cell .l { font-size: 10px; }
  #titleMain { font-size: 21px; }
  .year-wrap { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
