:root {
  --bg: #f7f3ec;
  --surface: #ffffff;
  --surface-2: #f3ede4;
  --text: #2b2420;
  --muted: #8a7f75;
  --line: #e6ddd1;
  --accent: #c0392b;
  --accent-soft: #fbe9e6;
  --gold: #a8741a;
  --gold-soft: #f7efdc;
  --weekend: #c0392b;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 6px 24px rgba(60, 40, 20, .06);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15110e;
    --surface: #201a16;
    --surface-2: #2a231e;
    --text: #f1e9df;
    --muted: #a39686;
    --line: #3a312a;
    --accent: #e8695a;
    --accent-soft: #3a1f1b;
    --gold: #d9a54a;
    --gold-soft: #33291a;
    --weekend: #e8695a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

button, select { font: inherit; color: inherit; }

button { cursor: pointer; touch-action: manipulation; user-select: none; -webkit-user-select: none; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- header / footer ---------- */

.site-header { text-align: center; padding: 28px 16px 8px; }
.site-header h1 { margin: 0; font-size: 28px; font-weight: 600; letter-spacing: .08em; }
.tagline { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

.site-footer {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 20px;
  padding: 8px 16px 32px; color: var(--muted); font-size: 13px;
}
kbd {
  display: inline-block; min-width: 1.6em; padding: 0 4px; margin-right: 2px;
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px;
  background: var(--surface); font: 12px/1.6 ui-monospace, monospace; text-align: center;
}

/* ---------- layout ---------- */

.layout {
  max-width: 1040px; margin: 0 auto; padding: 16px;
  display: grid; gap: 16px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-areas: "result calendar" "inputs calendar";
  align-items: start;
}
.result { grid-area: result; }
.inputs { grid-area: inputs; }
.calendar { grid-area: calendar; }

@media (max-width: 820px) {
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "result" "inputs" "calendar"; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.panel h2 { margin: 0 0 12px; font-size: 15px; font-weight: 600; color: var(--muted); letter-spacing: .05em; }

/* ---------- result card ---------- */

.day-nav { display: flex; align-items: center; gap: 8px; }

.arrow {
  flex: none; width: 52px; height: 52px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface-2);
  display: grid; place-items: center; transition: background .15s, transform .08s;
}
.arrow svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.arrow:hover { background: var(--accent-soft); color: var(--accent); }
.arrow:active, .arrow.held { transform: scale(.94); background: var(--accent-soft); color: var(--accent); }

.headline { flex: 1; min-width: 0; text-align: center; touch-action: pan-y; }
.solar-line { font-size: 16px; color: var(--muted); }
.solar-line b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.lunar-big {
  margin: 4px 0 2px;
  font-family: "Songti SC", "STSong", "SimSun", "Noto Serif SC", serif;
  font-size: clamp(36px, 9vw, 52px); font-weight: 700; line-height: 1.15; color: var(--accent);
  letter-spacing: .04em;
}
.ganzhi { font-size: 15px; color: var(--text); }
.ganzhi span { white-space: nowrap; }

.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 14px 0 4px; min-height: 28px; }
.chip {
  padding: 2px 10px; border-radius: 999px; font-size: 13px;
  background: var(--surface-2); color: var(--text); white-space: nowrap;
}
.chip.festival { background: var(--accent-soft); color: var(--accent); }
.chip.term { background: var(--gold-soft); color: var(--gold); }

.steppers { display: flex; justify-content: center; gap: 6px; margin: 14px 0 6px; flex-wrap: wrap; }
.steppers button {
  min-width: 56px; padding: 7px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); font-size: 14px;
}
.steppers button:hover { border-color: var(--accent); color: var(--accent); }
.steppers .today { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.steppers .today:hover { color: #fff; filter: brightness(1.08); }
.steppers.terms { align-items: center; margin-top: 0; }
.steppers.terms button { min-width: 84px; color: var(--gold); }
.steppers.terms button:hover { border-color: var(--gold); color: var(--gold); background: var(--gold-soft); }
.terms-label { font-size: 12px; color: var(--muted); padding: 0 4px; }

.details {
  display: grid; grid-template-columns: auto 1fr; gap: 0; margin: 16px 0 0;
  border-top: 1px solid var(--line);
}
.details dt, .details dd { margin: 0; padding: 9px 4px; border-bottom: 1px solid var(--line); font-size: 14px; }
.details dt { color: var(--muted); padding-right: 16px; white-space: nowrap; }
.details dd { text-align: right; font-variant-numeric: tabular-nums; }

.copy {
  display: block; margin: 14px auto 0; padding: 6px 16px; border-radius: 8px;
  border: 1px dashed var(--line); background: transparent; color: var(--muted); font-size: 13px;
}
.copy:hover { color: var(--accent); border-color: var(--accent); }

/* ---------- inputs ---------- */

.field { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 6px; margin-bottom: 12px; }
.field-label {
  width: 44px; flex: none; font-size: 14px; font-weight: 600;
  color: var(--accent);
}
.field + .field .field-label { color: var(--gold); }
.unit { color: var(--muted); font-size: 14px; margin-right: 4px; }
select {
  appearance: none; -webkit-appearance: none;
  padding: 6px 26px 6px 10px; border-radius: 8px;
  border: 1px solid var(--line); background-color: var(--surface-2);
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 13px) 55%, calc(100% - 8px) 55%;
  background-size: 5px 5px; background-repeat: no-repeat;
  font-size: 15px; font-variant-numeric: tabular-nums; cursor: pointer;
}
select:hover { border-color: var(--accent); }
.hint { margin: 4px 0 0; font-size: 13px; color: var(--muted); }

/* ---------- calendar ---------- */

.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-head h2 { margin: 0; color: var(--text); font-size: 17px; }
.cal-nav {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface-2); font-size: 20px; line-height: 1;
}
.cal-nav:hover { color: var(--accent); border-color: var(--accent); }

.weekdays, .grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.weekdays span { text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0; }
.weekdays .we { color: var(--weekend); }

.cell {
  border: 1px solid transparent; border-radius: 10px; background: transparent;
  padding: 6px 2px; min-height: 66px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  transition: background .12s;
}
.cell:hover { background: var(--surface-2); }
.cell .n { font-size: 17px; font-weight: 600; line-height: 1.2; font-variant-numeric: tabular-nums; }
.cell .l { font-size: 11px; color: var(--muted); line-height: 1.3; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell .g { font-size: 10px; color: var(--muted); opacity: .75; line-height: 1.3; white-space: nowrap; }
.cell.we .n { color: var(--weekend); }
.cell .l.fest { color: var(--accent); }
.cell .l.term { color: var(--gold); }
.cell .l.mon { color: var(--text); font-weight: 600; }
.cell.out { opacity: .35; }
.cell.is-today { border-color: var(--accent); }
.cell.sel { background: var(--accent); }
.cell.sel .n, .cell.sel .l, .cell.sel .g { color: #fff !important; opacity: 1; }

@media (max-width: 420px) {
  .panel { padding: 16px 12px; }
  .arrow { width: 44px; height: 44px; }
  .cell { min-height: 58px; padding: 4px 0; }
  .cell .n { font-size: 15px; }
  .cell .l { font-size: 10px; }
  .cell .g { font-size: 9px; }
  .steppers button { min-width: 0; padding: 7px 10px; }
}
