/* 长历 -- the surface. Values come from assets/tokens.css only.
 *
 * The one structural idea: the calendar is a single continuous grid of week
 * rows. A month boundary is a rule and a gutter label, never a gap and never
 * a fresh card, so 8/31 and 9/1 sit next to each other the way they do in
 * life. `blocks` layout exists for people who want the familiar month card,
 * and it reuses the same cells.
 */

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

html { color-scheme: light dark; caret-color: var(--accent); accent-color: var(--accent);
       scrollbar-color: var(--line-strong) var(--surface); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* CJK next to Latin and digits wants air; this is the global default. */
  text-spacing-trim: space-all;
}

h1, h2, h3 { margin: 0; font-weight: 600; line-height: var(--leading-tight); }

::selection { background: var(--accent-soft); color: var(--fg); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--radius-sm); }

.vh {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}
.skip {
  position: absolute; left: var(--space-3); top: var(--space-3);
  z-index: 20; padding: var(--space-2) var(--space-4);
  background: var(--accent); color: var(--accent-fg);
  border-radius: var(--radius); text-decoration: none;
  transform: translateY(-350%);
  transition: transform var(--dur-base) var(--ease-out);
}
.skip:focus { transform: translateY(0); }

[data-num], .num { font-variant-numeric: tabular-nums slashed-zero; }
.label {
  font-size: var(--text-xs); font-weight: 500; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--fg-3);
}

/* --- controls ---------------------------------------------------------- */
.btn {
  font: inherit; font-size: var(--text-sm); color: var(--fg-2);
  background: var(--surface); border: var(--line-w) solid var(--line);
  border-radius: var(--radius); padding: var(--space-2) var(--space-3);
  min-height: 34px; cursor: pointer;
  transition: background var(--dur-micro) var(--ease-out),
              color var(--dur-micro) var(--ease-out),
              border-color var(--dur-micro) var(--ease-out);
}
.btn:hover { background: var(--surface-2); color: var(--fg); }
.btn:active { background: var(--surface-2); }
.btn[aria-pressed="true"] {
  background: var(--fg); color: var(--bg); border-color: var(--fg);
}
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.btn-icon { min-width: 34px; padding-inline: var(--space-2); font-size: var(--text-lg); line-height: 1; }

.ctl-group { display: flex; align-items: center; gap: var(--space-1); }
.ctl-group .seg { border-radius: 0; margin-inline-start: -1px; }
.ctl-group .seg:first-of-type { border-start-start-radius: var(--radius); border-end-start-radius: var(--radius); margin-inline-start: 0; }
.ctl-group .seg:last-of-type { border-start-end-radius: var(--radius); border-end-end-radius: var(--radius); }
.count-group { gap: var(--space-2); }
.count-steps { display: flex; }

.theme-toggle .theme-mark {
  display: block; width: 13px; height: 13px; border-radius: 50%;
  border: 1.5px solid currentColor;
  background: linear-gradient(90deg, currentColor 0 50%, transparent 50% 100%);
}

/* --- masthead ---------------------------------------------------------- */
.masthead {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-4) var(--space-5);
  padding: var(--space-4) var(--space-5) var(--space-3);
  border-bottom: var(--line-w) solid var(--line-strong);
  background: var(--bg);
  position: sticky; top: 0; z-index: 12;
}
.brand { margin-inline-end: auto; }
.brand h1 {
  font-family: var(--font-almanac); font-size: var(--text-2xl);
  letter-spacing: 0.14em; font-weight: 600;
}
.brand-sub {
  margin: var(--space-1) 0 0; font-size: var(--text-xs); color: var(--fg-3);
  letter-spacing: 0.04em;
}
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }

/* --- the ribbon: the 節氣盤 unrolled ------------------------------------ */
/* The ribbon holds its place under the masthead. On an endless sheet a minimap
 * that scrolls away is gone exactly when it is wanted: this lane is how the
 * reader sees the whole year at once and how they glide to another part of it,
 * so it stays and the sheet moves underneath. --chrome-h is measured in ui.js,
 * because this bar's height changes with the viewport. */
.ribbon-wrap {
  padding: var(--space-3) var(--space-5) var(--space-2);
  border-bottom: var(--line-w) solid var(--line);
  background: var(--surface);
  position: sticky; top: var(--masthead-h, 3.9rem); z-index: 11;
}
.ribbon-head {
  display: flex; align-items: center; gap: var(--space-2);
  margin-bottom: var(--space-2);
}
.ribbon-year {
  font-family: var(--font-almanac); font-size: var(--text-lg);
  letter-spacing: 0.06em; min-width: 5ch; text-align: center;
}
.ribbon-hint { margin-inline-start: auto; font-size: var(--text-xs); color: var(--fg-3); }
.ribbon { position: relative; }
.ribbon svg { display: block; width: 100%; height: 104px; touch-action: pan-y; cursor: grab; }
.ribbon svg.dragging { cursor: grabbing; }

.rb-lane-bg { fill: var(--bg); }
.rb-rule { stroke: var(--line); stroke-width: 1; }
.rb-rule-strong { stroke: var(--line-strong); stroke-width: 1; }
.rb-month-label { fill: var(--fg-3); font-size: 10px; font-family: var(--font-body); }
.rb-term-tick { stroke: var(--line-strong); stroke-width: 1; }
.rb-term-tick.major { stroke: var(--fg-2); stroke-width: 1.5; }
.rb-term-label {
  fill: var(--fg-2); font-size: 9.5px; font-family: var(--font-almanac);
  letter-spacing: 0.04em;
}
.rb-holiday { fill: var(--st-holiday-field); }
.rb-holiday-edge { stroke: var(--st-holiday-ink); stroke-width: 1; fill: none; }
.rb-makeup { fill: var(--st-makeup-ink); }
.rb-holiday-name { fill: var(--st-holiday-ink); font-size: 9.5px; font-family: var(--font-body); }
.rb-mark { fill: var(--mark-edge); }
.rb-today { stroke: var(--accent); stroke-width: 1.5; }
.rb-window {
  fill: var(--accent); fill-opacity: 0.10;
  stroke: var(--accent); stroke-width: 1.5;
  transition: none;
}
.rb-window-grip { fill: var(--accent); }
.rb-unknown { fill: var(--fg-3); fill-opacity: 0.10; }

/* --- stage layout ------------------------------------------------------ */
.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 21rem;
  gap: 0;
  align-items: start;
}
.grid-wrap { min-width: 0; padding: var(--space-4) var(--space-5) var(--space-8); }
.range-title {
  display: flex; align-items: baseline; gap: var(--space-3);
  font-family: var(--font-almanac); font-size: var(--text-xl);
  letter-spacing: 0.04em; margin-bottom: var(--space-3);
}
.range-title-sub { font-family: var(--font-body); font-size: var(--text-xs); color: var(--fg-3); letter-spacing: 0.04em; }
.grid-note { margin: var(--space-3) 0 0; font-size: var(--text-xs); color: var(--fg-3); min-height: 1.2em; }
.keys { margin: var(--space-2) 0 0; font-size: var(--text-xs); color: var(--fg-3); }
.keys kbd {
  font-family: var(--font-mono); font-size: 0.92em;
  padding: 1px var(--space-1); margin-inline: 1px;
  border: var(--line-w) solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface);
}

/* --- the grid ---------------------------------------------------------- */
/* One CSS grid: a gutter for month labels plus seven weekday columns. Every
 * row is a real consecutive week; nothing is padded, nothing is blank. */
.grid { outline-offset: 4px; }
.gsheet {
  display: grid;
  grid-template-columns: 2.9rem repeat(7, minmax(0, 1fr));
  border-top: var(--line-w) solid var(--line-strong);
  border-left: var(--line-w) solid var(--line);
  /* The sheet prepends weeks above the viewport when the reader scrolls up,
   * and corrects the scroll by exactly the height it inserted. The browser's
   * own scroll anchoring does the same thing heuristically, and the two
   * together corrected twice -- every prepend shoved the sheet down by eight
   * rows, which read as 今天 landing two months late. One compensator, and it
   * is the one that knows what it inserted. */
  overflow-anchor: none;
}
.gsheet + .gsheet { margin-top: var(--space-6); }

.gh {
  grid-column: 2 / span 7;
  display: grid; grid-template-columns: repeat(7, minmax(0, 1fr));
  position: sticky; top: var(--sheet-top, 3.9rem); z-index: 8;
  background: var(--bg);
  border-bottom: var(--line-w) solid var(--line-strong);
}
.gh-gutter {
  position: sticky; top: var(--sheet-top, 3.9rem); z-index: 8;
  background: var(--bg); border-bottom: var(--line-w) solid var(--line-strong);
}
.gh span {
  padding: var(--space-2) var(--space-2);
  font-size: var(--text-xs); font-weight: 500; letter-spacing: 0.1em;
  color: var(--fg-3); text-align: center;
  border-right: var(--line-w) solid var(--line);
}
.gh span.we { color: var(--fg-2); }

/* The gutter is the 月建 lane -- the ribbon's month ring, stood on end. It
 * carries the alternating month band so the cells never have to, which is
 * what keeps the four status colours meaning exactly one thing each. */
.gutter {
  grid-column: 1; position: relative;
  border-right: var(--line-w) solid var(--line-strong);
  border-bottom: var(--line-w) solid var(--line);
  background: var(--surface);
}
.gutter[data-band="1"] { background: var(--surface-2); }
.gutter b {
  position: sticky; top: calc(var(--sheet-top, 3.9rem) + 2.7rem);
  display: block; padding: var(--space-2) 0;
  font-family: var(--font-almanac); font-weight: 600;
  font-size: var(--text-xs); color: var(--fg-2);
  text-align: center; letter-spacing: 0.02em;
}

/* a cell */
.cell {
  position: relative;
  min-height: 4.4rem;
  /* The bottom of every cell is the reader's lane -- a ruled line under the
   * day, the way a printed diary leaves one. Reserving it on every cell (not
   * only marked ones) is what lets a mark appear without growing the row, and
   * the scrolling sheet depends on every row being exactly one height. */
  --lane: 1.05rem;
  padding: var(--space-2) var(--space-2) var(--lane);
  border-right: var(--line-w) solid var(--line);
  border-bottom: var(--line-w) solid var(--line);
  background: var(--st-workday-field);
  cursor: pointer;
  user-select: none;
  transition: background var(--dur-micro) var(--ease-out);
}
.cell:hover { background: var(--surface-2); }

/* The month division: a heavy rule running from the 1st to the end of that
 * row, then continuing under the earlier days of the row below. A month
 * boundary really does fall mid-week, and a stepped rule says so; a card
 * would have to lie about it with a row of blanks. */
.cell[data-mrule="1"] { border-top: 2px solid var(--line-strong); }
/* No "月" suffix on the 1st: "1月" reads as January, not "the 1st". The
 * gutter label and the heavy rule already say the month turned over. */

.d-num {
  display: block;
  font-family: var(--font-almanac);
  font-size: var(--text-lg); font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.1; letter-spacing: 0.01em;
  color: var(--st-workday-ink);
}
.d-label {
  display: block; margin-top: var(--space-1);
  font-size: var(--text-xs); line-height: var(--leading-cjk);
  color: var(--fg-3);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* Two inks, three emphases. A block-printed almanac has exactly two inks, so
 * a 节气 is not allowed a hue of its own: it earns its place with the almanac
 * face at full ink strength while ordinary lunar days sit back at --fg-3. */
.d-label.is-festival { color: var(--st-holiday-ink); }
.d-label.is-term {
  color: var(--fg); font-family: var(--font-almanac);
  letter-spacing: 0.04em; font-weight: 600;
}
.d-label.is-lunar-month { color: var(--fg-2); font-family: var(--font-almanac); }

/* the status program -- four roles, nothing else carries colour */
.cell[data-st="holiday"] { background: var(--st-holiday-field); }
.cell[data-st="holiday"] .d-num { color: var(--st-holiday-ink); }
.cell[data-st="weekend"] { background: var(--st-weekend-field); }
.cell[data-st="weekend"] .d-num { color: var(--st-weekend-ink); }
.cell[data-st="makeup"] { background: var(--st-makeup-field); }
.cell[data-st="makeup"] .d-num { color: var(--st-makeup-ink); }
/* 班: section hatching, the patent-sheet way of saying "different material" */
.cell[data-st="makeup"]::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(
    45deg, transparent 0 6px, var(--st-hatch) 6px 7px);
  opacity: 0.4;
}

/* the 休/班 badge, top-right, exactly as a printed calendar prints it */
.d-mark {
  position: absolute; top: 3px; right: 3px;
  font-size: 10px; line-height: 1.4;
  padding: 0 3px; border-radius: var(--radius-sm);
  font-family: var(--font-almanac); letter-spacing: 0;
}
.d-mark.rest { background: var(--st-holiday-ink); color: var(--accent-fg); }
.d-mark.work { background: var(--st-makeup-ink); color: var(--bg); }

/* today: the reading pointer */
.cell[data-today="1"] { box-shadow: inset 0 0 0 2px var(--accent); z-index: 2; }
.cell[data-today="1"] .d-num { color: var(--accent); }

/* selection */
.cell[data-sel="1"] { background: var(--accent-soft); }
.cell[data-sel="1"][data-st="holiday"] { background: var(--st-holiday-field); }
/* The selection is one rectangle drawn across many cells: top and bottom on
 * every cell, left only on the first, right only on the last. Composed inset
 * shadows rather than borders, so the four cases combine without four rules
 * and without touching the cell's box. */
.cell[data-sel="1"]::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  --edge-l: 0; --edge-r: 0;
  box-shadow:
    inset 0 2px 0 var(--accent),
    inset 0 -2px 0 var(--accent),
    inset var(--edge-l) 0 0 var(--accent),
    inset var(--edge-r) 0 0 var(--accent);
}
.cell[data-sel-start="1"]::before { --edge-l: 2px; }
.cell[data-sel-end="1"]::before { --edge-r: -2px; }

/* --- the reader's hand -------------------------------------------------
 * A mark is not a fifth status role and carries no hue. It is drawn in a
 * different material -- graphite over print -- in the lane every cell
 * reserves, so the four status colours keep meaning exactly one thing each
 * and the sheet still reads as one printing.
 */
.d-tag {
  position: absolute; inset-inline: 0; bottom: 0;
  height: var(--lane);
  display: flex; align-items: center;
  padding-inline: 4px;
  font-family: var(--font-almanac);
  font-size: 10px; line-height: 1; letter-spacing: 0.06em;
  color: var(--mark-ink);
  background: var(--mark-field);
  border-top: var(--line-w) solid var(--mark-rule);
  white-space: nowrap; overflow: hidden;
  pointer-events: none;
}
/* The brace. A run opens and closes with a heavier stroke, which is what makes
 * ten marked cells read as one ten-day thing instead of ten identical ones --
 * the same job the stepped rule does for a month boundary. */
.cell[data-mark-start="1"] .d-tag { border-inline-start: 2px solid var(--mark-edge); }
.cell[data-mark-end="1"] .d-tag { border-inline-end: 2px solid var(--mark-edge); }

/* --- the mark bar: what you do with a selection, next to the selection --- */
.markbar {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: var(--space-2) var(--space-3);
  margin-bottom: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--surface);
  border: var(--line-w) solid var(--line);
  border-left: 2px solid var(--mark-edge);
}
/* One height whether it is hinting or acting, so the sheet below never moves --
 * and pinned under the ribbon, because the sheet is endless. Selecting days
 * four screens down the year is useless if the labels stayed at the top of the
 * document: the reader drags, nothing appears to happen, and the chips they
 * needed are a thousand pixels above. Sticky keeps its place in the flow, so
 * pinning it costs no shift. */
.markbar {
  min-height: 2.6rem;
  position: sticky; top: var(--chrome-h, 3.9rem); z-index: 9;
}
.mb-live { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); flex: 1; }
.mb-live[hidden], .mb-hint[hidden] { display: none; }
.mb-hint { font-size: var(--text-xs); color: var(--fg-3); }
.mb-span { font-size: var(--text-sm); color: var(--fg-2); }
.mb-span b { font-family: var(--font-mono); color: var(--fg); font-size: var(--text-base); }
.mb-when { color: var(--fg-3); }
.mb-chips { display: flex; flex-wrap: wrap; gap: var(--space-1); }
.mb-clear { margin-inline-start: auto; }

.chip {
  display: inline-flex; align-items: center; gap: var(--space-1);
  font: inherit; font-size: var(--text-sm);
  padding: var(--space-1) var(--space-2);
  color: var(--fg); background: var(--bg);
  border: var(--line-w) solid var(--line-strong);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--dur-micro) var(--ease-out);
}
.chip:hover { background: var(--mark-field); border-color: var(--mark-edge); }
.chip kbd {
  font-family: var(--font-mono); font-size: 10px; color: var(--fg-3);
  border: 0; padding: 0; background: none;
}
.chip-custom { color: var(--fg-2); }

/* --- the marks card ---------------------------------------------------- */
.mk-totals { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-4); margin-bottom: var(--space-3); }
.mk-total { font-size: var(--text-sm); color: var(--fg-3); }
.mk-total b {
  font-family: var(--font-almanac); font-weight: 600;
  color: var(--fg); margin-inline-end: var(--space-2); letter-spacing: 0.04em;
}
.mk-total span { font-family: var(--font-mono); color: var(--mark-ink); font-weight: 600; }

.mk-list { list-style: none; margin: 0 0 var(--space-3); padding: 0; }
.mk-list li { display: flex; align-items: stretch; gap: var(--space-1); }
.mk-run {
  flex: 1; display: grid; grid-template-columns: 3.4rem minmax(0, 1fr) auto;
  gap: var(--space-2); align-items: baseline; text-align: start;
  font: inherit; font-size: var(--text-xs);
  padding: var(--space-2) var(--space-1);
  background: none; border: 0; border-bottom: var(--line-w) solid var(--line);
  color: var(--fg-2); cursor: pointer;
}
.mk-run:hover { background: var(--mark-field); }
.mk-run-label { font-family: var(--font-almanac); color: var(--mark-ink); font-weight: 600; }
.mk-run-span { color: var(--fg-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mk-run-days { font-family: var(--font-mono); color: var(--fg-2); }
.mk-del {
  font: inherit; font-size: var(--text-xs); line-height: 1;
  padding-inline: var(--space-2);
  background: none; border: 0; border-bottom: var(--line-w) solid var(--line);
  color: var(--fg-3); cursor: pointer;
}
.mk-del:hover { color: var(--accent); }
.mk-more { font-size: var(--text-xs); color: var(--fg-3); margin: 0 0 var(--space-3); }
.mk-acts { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.mk-sub { margin: var(--space-3) 0 0; font-size: var(--text-xs); color: var(--fg-3); line-height: var(--leading-cjk); }
.mk-sub a { color: var(--fg-2); text-decoration: underline; text-decoration-color: var(--line-strong); }
.mk-sub a:hover { color: var(--accent); text-decoration-color: var(--accent); }
.mk-note { margin: var(--space-2) 0 0; font-size: var(--text-xs); color: var(--fg-3); line-height: var(--leading-cjk); }
.linkish {
  font: inherit; font-size: inherit; padding: 0;
  background: none; border: 0; color: var(--fg-2); cursor: pointer;
  text-decoration: underline; text-decoration-color: var(--line-strong);
}
.linkish:hover { color: var(--accent); }

.day-card dd .tag-mark { font-family: var(--font-almanac); color: var(--mark-ink); font-weight: 600; }
.dc-mark-span { color: var(--fg-3); font-size: var(--text-xs); }
.dr-tag {
  font-family: var(--font-almanac); font-size: var(--text-xs);
  color: var(--mark-ink); padding-inline: var(--space-2);
  border-left: 2px solid var(--mark-edge);
}
.swatch.s-mark { background: var(--mark-field); border-color: var(--mark-rule); border-left: 2px solid var(--mark-edge); }

/* the cursor is only meaningful while the grid has focus; otherwise it would
 * sit on top of today's marker on first paint and read as a mis-coloured today */
.grid:focus .cell[data-cursor="1"],
.grid:focus-within .cell[data-cursor="1"] {
  outline: 2px solid var(--focus); outline-offset: -2px; z-index: 3;
}

/* days outside the requested range, kept because the week is whole */
.cell[data-outside="1"] .d-num { color: var(--fg-3); }
.cell[data-outside="1"] .d-label { opacity: 0.6; }

/* --- blocks layout ----------------------------------------------------- */
.blocks { display: grid; gap: var(--space-5); grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr)); }
.block-h {
  font-family: var(--font-almanac); font-size: var(--text-base);
  letter-spacing: 0.08em; padding-bottom: var(--space-2);
  border-bottom: var(--line-w) solid var(--line-strong);
  margin-bottom: 0;
}
.block .gsheet { grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 0; }
.block .cell { min-height: 3.2rem; --lane: 0.9rem; }
.block .d-num { font-size: var(--text-base); }
.block .gh { grid-column: 1 / span 7; position: static; }
.block .cell[data-mstart="1"] { border-top: var(--line-w) solid var(--line); }
/* a blank leading cell only exists in blocks layout, where the month is the unit */
.pad { border-right: var(--line-w) solid var(--line); border-bottom: var(--line-w) solid var(--line); }

/* --- day layout -------------------------------------------------------- */
.daylist { display: grid; gap: 0; border-top: var(--line-w) solid var(--line-strong); }
.dayrow {
  display: grid; grid-template-columns: 5.5rem minmax(0, 1fr) auto;
  gap: var(--space-4); align-items: center;
  padding: var(--space-3) var(--space-3);
  border-bottom: var(--line-w) solid var(--line);
  cursor: pointer;
  transition: background var(--dur-micro) var(--ease-out);
}
.dayrow:hover { background: var(--surface); }
.dayrow[data-st="holiday"] { background: var(--st-holiday-field); }
.dayrow[data-st="weekend"] { background: var(--st-weekend-field); }
.dayrow[data-sel="1"] { background: var(--accent-soft); }
.dayrow[data-today="1"] { box-shadow: inset 3px 0 0 var(--accent); }
.dayrow .dr-date { display: flex; align-items: baseline; gap: var(--space-2); }
.dayrow .dr-n {
  font-family: var(--font-almanac); font-size: var(--text-3xl);
  font-variant-numeric: tabular-nums; line-height: 1;
}
.dayrow[data-st="holiday"] .dr-n { color: var(--st-holiday-ink); }
.dayrow[data-today="1"] .dr-n { color: var(--accent); }
.dayrow .dr-wd { font-size: var(--text-xs); color: var(--fg-3); }
.dayrow .dr-mid { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); font-size: var(--text-sm); }
.dayrow .dr-lunar { font-family: var(--font-almanac); color: var(--fg-2); letter-spacing: 0.04em; }
.dayrow .dr-fest { color: var(--st-holiday-ink); }
.dayrow .dr-term { color: var(--fg); font-family: var(--font-almanac); font-weight: 600; }
.dayrow .dr-mark { font-size: var(--text-xs); }

/* --- rail -------------------------------------------------------------- */
.rail {
  position: sticky; top: 3.9rem;
  display: grid; gap: 0;
  border-left: var(--line-w) solid var(--line-strong);
  background: var(--surface);
  max-height: calc(100dvh - 3.9rem);
  overflow-y: auto;
}
.card { padding: var(--space-4) var(--space-4); border-bottom: var(--line-w) solid var(--line); }
.card-h {
  font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.12em;
  color: var(--fg-3); text-transform: uppercase; margin-bottom: var(--space-3);
}

.day-card .dc-top { display: flex; align-items: baseline; gap: var(--space-3); }
.day-card .dc-n {
  font-family: var(--font-almanac); font-size: var(--text-4xl); line-height: 1;
  font-variant-numeric: tabular-nums;
}
.day-card[data-st="holiday"] .dc-n { color: var(--st-holiday-ink); }
.day-card[data-today="1"] .dc-n { color: var(--accent); }
.day-card .dc-ymd { font-size: var(--text-xs); color: var(--fg-3); }
.day-card .dc-wd { font-size: var(--text-sm); color: var(--fg-2); }
.day-card .dc-lunar {
  font-family: var(--font-almanac); font-size: var(--text-lg);
  letter-spacing: 0.08em; margin-top: var(--space-2);
}
.day-card dl {
  display: grid; grid-template-columns: 4.2rem minmax(0, 1fr);
  gap: var(--space-1) var(--space-3); margin: var(--space-3) 0 0;
  font-size: var(--text-sm);
}
.day-card dt { color: var(--fg-3); font-size: var(--text-xs); align-self: center; }
.day-card dd { margin: 0; color: var(--fg-2); }
.day-card dd .tag-rest { color: var(--st-holiday-ink); font-weight: 600; }
.day-card dd .tag-work { color: var(--fg); font-weight: 600; }

/* ledger */
.lg-row {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: var(--space-3); padding: var(--space-2) 0;
  border-bottom: var(--line-w) solid var(--line);
  font-size: var(--text-sm);
}
.lg-row:last-child { border-bottom: 0; }
.lg-row dt { color: var(--fg-2); }
.lg-k { color: var(--fg-2); }
.lg-v { font-family: var(--font-mono); font-variant-numeric: tabular-nums slashed-zero; color: var(--fg); }
.lg-v.hot { color: var(--st-holiday-ink); font-weight: 600; }
.lg-span { font-size: var(--text-xs); color: var(--fg-3); margin-bottom: var(--space-2); }

/* bridges */
.bridge {
  display: block; width: 100%; text-align: left;
  padding: var(--space-3); margin-bottom: var(--space-2);
  background: var(--bg); border: var(--line-w) solid var(--line);
  border-radius: var(--radius); cursor: pointer; font: inherit;
  transition: border-color var(--dur-micro) var(--ease-out),
              background var(--dur-micro) var(--ease-out);
}
.bridge:hover { background: var(--surface-2); border-color: var(--line-strong); }
.bridge .br-top { font-size: var(--text-sm); color: var(--fg); }
.bridge .br-top b { font-family: var(--font-mono); font-variant-numeric: tabular-nums; color: var(--st-holiday-ink); }
.bridge .br-sub { font-size: var(--text-xs); color: var(--fg-3); margin-top: var(--space-1); }
.empty { font-size: var(--text-sm); color: var(--fg-3); }

/* legend */
.legend-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2); font-size: var(--text-sm); }
.legend-list li { display: flex; align-items: center; gap: var(--space-2); color: var(--fg-2); }
.swatch {
  width: 1.1rem; height: 1.1rem; border-radius: var(--radius-sm);
  border: var(--line-w) solid var(--line-strong); flex: none; position: relative;
}
.swatch.s-holiday { background: var(--st-holiday-field); border-color: var(--st-holiday-ink); }
.swatch.s-weekend { background: var(--st-weekend-field); }
.swatch.s-workday { background: var(--bg); }
.swatch.s-makeup {
  background: var(--st-makeup-field);
  background-image: repeating-linear-gradient(45deg, transparent 0 4px, var(--st-hatch) 4px 5px);
}
.prov { margin: var(--space-3) 0 0; font-size: var(--text-xs); color: var(--fg-3); line-height: var(--leading-cjk); }
.prov a {
  color: var(--fg-2); text-underline-offset: 0.15em;
  text-decoration-thickness: 1px; text-decoration-color: var(--line-strong);
}
.prov a:hover { color: var(--accent); text-decoration-color: var(--accent); }

/* --- responsive -------------------------------------------------------- */
@media (max-width: 1080px) {
  .stage { grid-template-columns: minmax(0, 1fr); }
  .rail {
    position: static; max-height: none; border-left: 0;
    border-top: var(--line-w) solid var(--line-strong);
    grid-template-columns: repeat(auto-fit, minmax(19rem, 1fr));
  }
  .card { border-right: var(--line-w) solid var(--line); }
}
@media (max-width: 720px) {
  .masthead { position: static; padding-inline: var(--space-3); }
  .ribbon-wrap { position: static; }
  /* the bar still pins on a phone: it is the only way to reach the labels */
  .markbar { top: 0; }
  .brand { margin-inline-end: 0; width: 100%; }
  .controls { width: 100%; gap: var(--space-2); }
  .ribbon-wrap { padding-inline: var(--space-3); }
  .ribbon svg { height: 84px; }
  .grid-wrap { padding-inline: var(--space-3); }
  .gsheet { grid-template-columns: 1.9rem repeat(7, minmax(0, 1fr)); }
  .gh, .gh-gutter { position: static; }
  .gutter b { top: 0; font-size: 10px; letter-spacing: 0; }
  .cell { min-height: 3.5rem; --lane: 0.95rem; padding: var(--space-1) var(--space-1) var(--lane); }
  .d-num { font-size: var(--text-base); }
  .d-label { font-size: 10px; }
  .rail { grid-template-columns: minmax(0, 1fr); }
  .dayrow { grid-template-columns: 4rem minmax(0, 1fr); gap: var(--space-3); }
  /* phone widths are touch in practice, whether or not the pointer media
   * query says so, so the 44px floor applies on width too */
  .btn { min-height: 44px; min-width: 44px; }
  .btn-icon { min-width: 44px; }
}
@media (max-width: 400px) {
  .cell { min-height: 3.1rem; --lane: 0.85rem; }
  .d-label { font-size: 9px; }
}

/* touch targets never drop below 44px on a coarse pointer */
@media (pointer: coarse) {
  .btn { min-height: 44px; }
  .btn-icon { min-width: 44px; }
  .chip { min-height: 44px; }
  .mk-del { min-width: 44px; }
  .cell { min-height: 3.9rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media print {
  .masthead .controls, .ribbon-hint, .rail .bridges, .skip,
  .markbar, .keys, .mk-acts, .mk-sub { display: none; }
  .masthead, .rail { position: static; }
}
