/* ดวงจร view (views/luck.js) — tokens from styles.css only.
   Desktop (≥ 901px) and mobile (≤ 900px) both fit one screen: views/luck.js measures the space and sets
   --g (glyph size), --hg (hidden-stem size), .fit-1 / .fit-2 (drop element words) on the board. Only the reading
   text and the hit list scroll inside their own panes. */
.luck-view { display: flex; flex-direction: column; gap: 12px; }

/* Control row */
.luck-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.luck-bar h1 { font-size: 18px; }
.luck-step { display: flex; gap: 6px; }
.luck-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.luck-inline { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.luck-inline .input { width: 124px; color: var(--ink); font-weight: 400; }
.luck-inline .input[type="time"] { width: 112px; }
.luck-date { position: relative; margin-left: auto; }
.luck-date-btn { padding: 0 12px; white-space: nowrap; font-weight: 500; color: var(--link); }

/* Panes */
.luck-work { display: flex; flex-direction: column; gap: 12px; }
.luck-work .card { padding: 10px; min-width: 0; }
.luck-pane-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-bottom: 6px; }
.luck-pane-head h2 { font-size: 15px; }
.luck-pane-head .btn { margin-left: auto; }
.luck-chart .luck-pane-head > .row { margin-left: auto; font-size: 12px; }

/* Natal ธาตุให้คุณ / ให้โทษ line and the ธาตุเมื่อรวมดวงจร button (toolbar on desktop, chip under the hits on mobile) */
.nel { display: inline-flex; align-items: baseline; gap: 4px 14px; white-space: nowrap; font-size: 14px; line-height: 1.3; }
.nel-g { display: inline-flex; align-items: baseline; gap: 4px; }
.nel-k { font-size: 13px; font-weight: 600; color: var(--muted); margin-right: 2px; }
.nel .mark { font-size: 14px; }
.nel-n { font-weight: 700; }
.ov-btn { white-space: nowrap; padding: 0 12px; font-size: 13px; font-weight: 600; }
.ov-btn .v-full, .ov-btn .v-short, .ov-btn .v-chip, .ov-btn .v-tot { display: none; }
.ov-k { color: var(--muted); font-weight: 600; }
.ov-fav { color: var(--fav); } .ov-unfav { color: var(--unfav); } .ov-norm { color: var(--norm); }
.ov-btn .v-full, .ov-btn .v-short, .v-chip, .v-tot { align-items: center; gap: 6px; }
.ov-btn .nel { font-size: 14px; }
.ov-el { display: inline-flex; align-items: baseline; gap: 0; }
.ov-list { display: inline-flex; align-items: baseline; gap: 6px; }
.ov-list .nel-n { font-size: 13px; }
/* ▲ / ▼: score went up / down against the natal score (colour shows the direction only) */
.ov-cue { font-size: 11px; margin-left: 1px; } .ov-cue.up { color: var(--link); } .ov-cue.down { color: var(--band); }
.ov-same { color: var(--muted); font-weight: 500; }
.ov-info { font-size: 14px; font-weight: 400; color: var(--link); line-height: 1; }
.ov-info-t { font-size: 12px; font-weight: 500; color: var(--link); margin-left: -3px; }
.ov-lines { display: flex; flex-direction: column; align-items: flex-start; font-size: 12px; line-height: 1.2; }
/* Dialog */
.luck-ov-dialog { max-width: 620px; }
.luck-ov-dialog .dialog-body { gap: 10px; }
.ov-natal { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.ov-natal .nel { flex-wrap: wrap; white-space: normal; }
.ov-scroll { overflow-x: auto; }
.ov-table th, .ov-table td { padding: 6px 8px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ov-table thead th:nth-child(-n+2), .ov-table tbody td:nth-child(2) { text-align: left; }
.ov-table tbody th { text-align: left; font-size: 15px; }
.ov-table .ov-tot th { text-align: left; font-size: 13px; }
.ov-table tfoot tr:first-child > * { border-top: 2px solid var(--line); }
@media (max-width: 520px) {
  .luck-ov-dialog { padding: 14px; }
  .ov-table th, .ov-table td { padding: 5px 4px; font-size: 13px; }
  .ov-table .ov-st-l { display: none; }
}

/* Pillar grid (desktop board) */
.luck-pillars { --g: 36px; --hg: 16px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.luck-pillars .pcol[data-col="t-decade"] { margin-left: 6px; }
.luck-pillars .pcol.transit:not(.lv-current) .phead { background: var(--band); }
.luck-pillars .pcol.transit:not(.lv-current) button.phead:hover { background: var(--ink); }
.luck-pillars .pcol.lv-current { box-shadow: inset 0 0 0 3px var(--accent); }
.luck-pillars .pcol.lv-current .pbody { background: var(--accent-soft); }
/* Another transit column being read (the active level is unchanged): dashed ink frame, header kept dark */
.luck-pillars .pcol.lv-read { outline: 2px dashed var(--ink); outline-offset: -3px; }
.luck-pillars .pcol.lv-read .pbody { background: var(--soft); }
.luck-pillars .pcol.lv-read .phead { background: var(--ink); }
.luck-pillars button.phead[aria-pressed="true"] { cursor: default; }
.luck-pillars .phead { min-height: 0; padding: 4px 2px; gap: 0; }
.luck-pillars .phead .t { font-size: clamp(14px, calc(var(--g) * .2), 18px); line-height: 1.25; }
.luck-pillars .phead .s { font-size: 12px; line-height: 1.2; overflow-wrap: anywhere; }
/* ปฏิ / ลัคนา (rarely used): narrower columns, smaller glyphs and lighter text; the freed width goes to the rest */
.luck-pillars { --ga: max(16px, calc(var(--g) * .6)); grid-template-columns: repeat(2, minmax(48px, .58fr)); }
.luck-pillars .pcol:is([data-col="pregnancy"], [data-col="life"]) .glyph { font-size: var(--ga); min-width: calc(var(--ga) + 6px); font-weight: 600; }
.luck-pillars .pcol:is([data-col="pregnancy"], [data-col="life"]) .phead .t { font-size: 13px; font-weight: 600; }
.luck-pillars .pcol:is([data-col="pregnancy"], [data-col="life"]) :is(.phead .s, .pcell .ele, .pcell .animal, .pcell .god) { font-size: 12px; font-weight: 400; overflow-wrap: anywhere; text-align: center; }
.luck-pillars .pcol:is([data-col="pregnancy"], [data-col="life"]) .hid .g { font-size: max(12px, calc(var(--hg) * .75)); font-weight: 500; }
.luck-pillars .pcol:is([data-col="pregnancy"], [data-col="life"]) .mark { font-size: 12px; }
.luck-pillars .pcol:is([data-col="pregnancy"], [data-col="life"]) .pbody { padding-inline: 1px; }
/* Arrow lanes: always reserved, sized per period by views/luck.js (--lane0 above stems, --lane1 above branches) */
.luck-pillars .pbody { gap: 2px; padding: var(--lane0, 6px) 2px 4px; }
.luck-pillars .pbody > .pcell + .pcell { margin-top: var(--lane1, 4px); }
.luck-pillars .pcell { gap: 0; }
.luck-pillars .glyph { font-size: var(--g); line-height: 1.15; min-width: calc(var(--g) + 8px); min-height: 0; padding: 0 2px; }
.luck-pillars .pcell .ele, .luck-pillars .pcell .animal { font-size: clamp(12px, calc(var(--g) * .16), 15px); line-height: 1.3; }
.luck-pillars .pcell .god { font-size: clamp(12px, calc(var(--g) * .16), 15px); line-height: 1.3; min-height: 0; padding: 1px 2px; }
.luck-pillars .hidden-row { gap: 2px; padding-top: 3px; }
.luck-pillars .hid { min-width: 0; line-height: 1.2; }
.luck-pillars .hid .g { font-size: var(--hg); }
.luck-pillars .mark { font-size: clamp(12px, calc(var(--g) * .18), 18px); line-height: 1.2; }
.luck-pillars.fit-1 .hid .e, .m-board.fit-1 .hid .e { display: none; }
.luck-pillars.fit-2 .pcell .ele, .m-board.fit-2 .pcell .ele { display: none; }
.luck-pillars span.glyph[role="button"] { cursor: pointer; }
.luck-pillars .glyph.hit-src { border-style: dashed; border-color: var(--ink); }
/* Non-arrow hints */
.luck-pillars .glyph.hint-bad, .luck-pillars .glyph.hint-good { position: relative; }
.luck-pillars .glyph.hint-bad::after, .luck-pillars .glyph.hint-good::after { content: ''; position: absolute; top: 3px; right: 3px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.luck-pillars .glyph.hint-good::after { background: var(--jade); }
.hit-badge { align-self: flex-start; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; line-height: 20px; text-align: center; }
/* Desktop board: the count sits on the glyph's top-left corner so it never widens the column (bigger glyphs fit) */
.luck-pillars .glyph-row { position: relative; }
.luck-pillars .glyph-row > .hit-badge { position: absolute; top: -6px; left: -5px; z-index: 1; pointer-events: none; }

/* Arrows (svg.arrow-layer inside the board) */
.arrow-path { fill: none; stroke-width: 2.5; stroke-linecap: round; }
.arrow-path.k-clash, .arrow-path.k-control { stroke: var(--accent); }
.arrow-path.k-combo { stroke: var(--jade); stroke-dasharray: 7 4; }
.ah-bad { fill: var(--accent); } .ah-good { fill: var(--jade); }
.arrow-pill rect { fill: var(--card); stroke-width: 1.5; }
.arrow-pill.k-clash rect, .arrow-pill.k-control rect { stroke: var(--accent); }
.arrow-pill.k-combo rect { stroke: var(--jade); stroke-dasharray: 3 2; }
.arrow-label { font-family: var(--font); font-size: 12px; font-weight: 700; }
.arrow-label.k-clash, .arrow-label.k-control { fill: var(--accent); }
.arrow-label.k-combo { fill: var(--jade); }
/* One fixed line, so its text changing never moves anything */
.arrow-status { margin: 4px 0 0; font-size: 12px; line-height: 18px; height: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Period chooser: one row of consecutive periods centred on the selection (--cols = cell count, set in the markup),
   with ‹ › step buttons at both ends. Cell = pillar (stem over branch, fav mark beside each) + hit count + short label. */
.chooser { container-type: inline-size; }
.ch-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.ch-head h2 { font-size: 15px; }
.ch-drill { margin-left: auto; padding: 0 10px; font-size: 13px; white-space: nowrap; }
.now-key { font-size: 12px; font-weight: 600; color: var(--jade); border: 1px solid var(--line); border-radius: 4px; padding: 0 6px; box-shadow: inset 0 -3px 0 var(--jade); }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 0 2px; color: var(--muted); }
.crumbs .btn.link { min-height: 44px; padding: 0 2px; font-size: 13px; }
.ch-sum { color: var(--muted); line-height: 1.35; }
.ch-sum b { color: var(--ink); font-weight: 600; }
.cstrip { display: flex; align-items: stretch; gap: 4px; min-width: 0; }
.c-step { flex: none; width: 36px; min-height: 44px; padding: 0; font-size: 22px; line-height: 1; }
.c-step[disabled] { opacity: .45; }
.cgrid { --cols: 11; flex: 1 1 0; min-width: 0; display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); gap: 3px; }
.cg-day { gap: 2px; }
.ccell { position: relative; min-width: 0; min-height: 44px; display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "pair hits" "lab lab";
  align-items: center; justify-items: center; gap: 0; padding: 3px 2px 4px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); line-height: 1.2; }
.ccell:hover { background: var(--soft); }
.ccell.is-sel { background: var(--accent-soft); border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.ccell.is-now { box-shadow: inset 0 -3px 0 var(--jade); }
.ccell.is-sel.is-now { box-shadow: inset 0 0 0 1px var(--accent), inset 0 -3px 0 var(--jade); }
.c-pair { grid-area: pair; display: flex; flex-direction: column; align-items: flex-start; font-size: 16px; line-height: 1.12; }
.c-g { display: flex; align-items: center; gap: 1px; white-space: nowrap; }
.c-m { display: inline-flex; min-width: 9px; } .c-m .mark { font-size: 12px; line-height: 1; }
.c-lab { grid-area: lab; display: flex; align-items: baseline; justify-content: center; gap: 2px; font-size: 12px; white-space: nowrap; max-width: 100%; overflow: hidden; }
.ccell.is-sel .c-lab { font-weight: 700; }
.ccell.is-out .c-lab { color: var(--muted); }
.c-lab small { font-size: 12px; font-weight: 500; }
.c-hits { grid-area: hits; align-self: start; margin-left: 1px; min-width: 16px; height: 16px; padding: 0 3px; border-radius: 8px; background: var(--soft); border: 1px solid var(--line); font-size: 12px; line-height: 14px; text-align: center; }
.c-hits[hidden] { display: none; }
.cg-day .ccell { padding: 2px 1px 4px; }
.cg-day .c-pair { font-size: 15px; }
/* Desktop day strip: number beside the pair (hits under it) so the row stays low; weekday is in the head/title */
.luck-periods .cg-day .ccell { grid-template-columns: auto auto; grid-template-areas: "pair lab" "pair hits"; justify-content: center; align-items: center; column-gap: 3px; padding: clamp(2px, .5vh, 6px) 1px; }
.luck-periods .cg-day .c-lab { align-self: end; flex-direction: column; align-items: center; gap: 0; font-size: 13px; font-weight: 600; line-height: 1.1; }
.luck-periods .cg-day .c-hits { align-self: start; margin-left: 0; }

/* Hits */
.ev-count { display: inline-block; min-width: 22px; padding: 0 6px; border-radius: 11px; background: var(--soft); border: 1px solid var(--line); font-size: 13px; text-align: center; }
.small-toggle { min-height: 44px; padding: 0 10px; font-size: 13px; white-space: nowrap; flex: none; }
.small-toggle[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.ev-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.ev { width: 100%; min-height: 44px; display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; text-align: left; background: var(--card); border: 1px solid var(--line); border-left-width: 4px; border-radius: 8px; padding: 6px 10px; }
.ev:hover { background: var(--soft); }
.ev[aria-pressed="true"] { background: var(--accent-soft); }
.ev.k-clash, .ev.k-control { border-left-color: var(--accent); } .ev.k-combo { border-left-color: var(--jade); border-left-style: dashed; }
.ev-target { flex-basis: 100%; }
.ev-kind { font-weight: 700; font-size: 13px; padding: 0 8px; border-radius: 999px; border: 1px solid currentColor; }
/* Compact hits: one-line chips flowing in a wrapping row (full text in title / aria-label) */
.ev-chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px; }
.ev-chips > li { min-width: 0; }
.ev.ev-chip { width: auto; max-width: 100%; flex-wrap: nowrap; gap: 3px; padding: 0 6px 0 4px; white-space: nowrap; border-left-width: 3px; }
.ev-chip .ev-kind { font-size: 12px; padding: 0 4px; line-height: 18px; }
.ev-pair { font-size: 17px; font-weight: 600; line-height: 1.1; letter-spacing: -1px; }
.ev-tgt { font-size: 13px; color: var(--muted); }
.ev-chip[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.ev-chip[aria-pressed="true"] .ev-tgt { color: var(--ink); }
.ev-chip.is-off { border-style: dashed; }
.k-clash .ev-kind, .k-control .ev-kind { color: var(--accent); }
.k-combo .ev-kind { color: var(--jade); }
.ev-title { font-weight: 600; }
.ev-src { font-size: 13px; font-weight: 600; color: var(--muted); }
.rd-back { margin-left: auto; min-height: 44px; font-size: 13px; }

/* Reading */
.luck-reading:focus { outline: none; }
.luck-reading:focus-visible { outline: 2px solid var(--accent); }
.luck-reading .card-head { margin-bottom: 6px; }
/* Pinned ราศีบน | ราศีล่าง switch; only the chosen side's text (.rd-scroll) scrolls */
.rd-switch { flex: none; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; margin-bottom: 6px; }
.rd-tab { min-width: 0; min-height: 44px; display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 2px; padding: 4px 8px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--card); text-align: left; line-height: 1.2; }
.rd-tab:hover { background: var(--soft); }
.rd-tab[aria-selected="true"] { background: var(--accent-soft); border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.rd-tab.is-target { border-left: 4px solid var(--accent); }
.rd-tab-l { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 5px; min-width: 0; }
.rd-tab-k { font-size: 12px; font-weight: 600; color: var(--muted); }
.rd-tab[aria-selected="true"] .rd-tab-k { color: var(--ink); }
.rd-tab-g { font-size: 20px; font-weight: 700; line-height: 1.1; }
.rd-tab .rd-god { font-size: 13px; }
.rd-tab .tag { max-width: 100%; gap: 2px; padding: 0 6px; font-size: 12px; white-space: normal; }
.rd-scroll { min-height: 0; }
.rd-scroll:focus { outline: none; }
.rd-scroll:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.rd-event { border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 8px; padding: 8px 12px; margin-bottom: 12px; display: flex; flex-direction: column; gap: 6px; background: var(--ground); }
.rd-event.k-combo { border-left-color: var(--jade); }
.rd-event details summary { cursor: pointer; color: var(--link); min-height: 32px; display: flex; align-items: center; }
.rd-row { padding: 2px 2px 8px; display: flex; flex-direction: column; gap: 8px; }
.rd-god { font-weight: 700; }
.rd-text h3 { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.rd-text.alt { border-top: 1px dashed var(--line); padding-top: 8px; }
.tag.tri { color: var(--unfav); }

/* ---------- Desktop: whole view fits one screen; only inner panes scroll ---------- */
@media (min-width: 901px) {
  .page:has(> .luck-view) { max-width: none; padding: 8px 16px; gap: 0; }
  .luck-view { height: calc(100vh - var(--luck-top, 66px) - 8px); overflow: hidden; gap: 8px; }
  .luck-bar { flex: none; flex-wrap: nowrap; }
  .luck-bar .seg { flex-wrap: nowrap; gap: 4px; }
  .luck-bar .seg > button { padding: 0 12px; white-space: nowrap; }
  .luck-step { gap: 4px; }
  .luck-step .btn { padding: 0 12px; white-space: nowrap; }
  .luck-inline { white-space: nowrap; }
  /* Narrow desktop: title folded away (the top nav names the page), date form opens from a button */
  .luck-bar h1 { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .luck-date-pop { display: none; position: absolute; right: 0; top: calc(100% + 6px); z-index: 12; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
  .luck-date.open .luck-date-pop { display: block; }
  .luck-date-pop .luck-form { flex-wrap: nowrap; }

  /* Left: board, then the period chooser strip under it. Right: hits, then the reading (scrolls inside). */
  .luck-work { flex: 1; min-height: 0; display: grid; gap: 8px; grid-template-columns: minmax(0, 1fr) clamp(280px, 27vw, 430px); }
  .luck-main, .luck-side { min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
  /* Board card takes all the height the chooser leaves; the grid stretches and spreads spare height inside the
     columns (views/luck.js first grows the glyphs until they no longer fit). */
  .luck-work .luck-chart { flex: 1 1 0; min-height: 0; overflow: hidden; padding: 8px 10px; display: flex; flex-direction: column; }
  .luck-chart .luck-pane-head, .luck-chart > .error-box, .luck-chart > .arrow-status { flex: none; }
  .luck-chart .luck-board { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
  .luck-chart .luck-pillars { flex: 1 0 auto; }
  .luck-pillars .pbody { justify-content: space-evenly; }
  .luck-chart .luck-pane-head { flex-wrap: nowrap; margin-bottom: 4px; }
  .luck-chart .luck-pane-head h2 { white-space: nowrap; }
  .luck-chart .luck-pane-head > .row { flex-wrap: nowrap; white-space: nowrap; gap: 4px 10px !important; overflow: hidden; }
  .luck-work .luck-periods { flex: none; display: flex; flex-direction: column; gap: 3px; padding: 4px 10px 6px; }
  .luck-periods .c-pair { font-size: clamp(16px, 2.5vh, 28px); }
  .luck-periods .ccell { padding-block: clamp(3px, .6vh, 8px); }
  .luck-periods .c-step { width: clamp(36px, 3vw, 48px); }
  .luck-chart .luck-pane-head.fit-3 > .row { display: none; }
  .luck-view.fit-4 .luck-pillars .hidden-row, .luck-view.fit-4 .luck-pillars .pcell .animal { display: none; }
  .luck-view.fit-5 .luck-periods .ch-head { display: none; }
  .luck-view.fit-6 .luck-chart .luck-pane-head { display: none; }
  .luck-chart .luck-pane-head.fit-3 > .arrow-status { flex: 1 1 0; min-width: 0; margin: 0; text-align: right; }
  .luck-periods .ch-head { flex-wrap: nowrap; min-width: 0; }
  .luck-periods .ch-head h2, .luck-periods .now-key { white-space: nowrap; flex: none; }
  .luck-periods .crumbs { flex-wrap: nowrap; white-space: nowrap; flex: none; }
  .luck-periods .ch-sum { flex: 1 1 0; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .luck-events { flex: 0 1 auto; max-height: 45%; display: flex; flex-direction: column; min-height: 0; }
  .luck-events .luck-pane-head { flex-wrap: nowrap; }
  .luck-events .luck-pane-head h2 { white-space: nowrap; font-size: 14px; overflow: hidden; text-overflow: ellipsis; }
  .luck-events .luck-pane-body { flex: 1; min-height: 0; overflow-y: auto; }
  .luck-reading { flex: 1 1 0; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
  .luck-reading .card-head { flex: none; }
  .luck-reading .rd-scroll { flex: 1 1 0; overflow-y: auto; overscroll-behavior: contain; }
}
@media (min-width: 1280px) {
  .luck-bar h1 { position: static; width: auto; height: auto; overflow: visible; clip-path: none; }
}

/* ---------- Desktop toolbar modes (views/luck.js picks the first that fits on one row: BAR_MODES) ----------
   ''      date form inline, full ธาตุ line + full totals
   d-btn   date form behind its button
   tight   page title folded, tighter level / step buttons
   short   short totals (คุณ / โทษ)
   chip    ธาตุ line folded; the totals become one two-line chip (same dialog) */
@media (min-width: 901px) {
  .luck-bar:not(.d-btn) .luck-date-btn { display: none; }
  .luck-bar:not(.d-btn) .luck-date-pop { display: block; position: static; background: none; border: 0; padding: 0; }
  .luck-bar.tight h1 { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .luck-bar.tight .seg > button { padding: 0 8px; }
  .luck-bar.tight .luck-step .btn { padding: 0 8px; }
  .luck-els { flex: 1 0 auto; min-width: 0; display: flex; align-items: center; justify-content: space-evenly; gap: 8px 16px; }
  .luck-bar.short .luck-els { gap: 8px 10px; }
  .luck-bar .v-full { display: inline-flex; }
  .luck-bar.short .v-full, .luck-bar.chip .v-full { display: none; }
  .luck-bar.short:not(.chip) .v-short { display: inline-flex; }
  .luck-bar.chip:not(.tot) .v-chip { display: inline-flex; }
  .luck-bar.chip.tot .v-tot { display: inline-flex; }
  .luck-bar.chip .nel { display: none; }
  .luck-bar.short .nel { gap: 4px 10px; font-size: 13px; }
  .luck-bar.short .nel-g { gap: 3px; }
  .luck-bar.short .luck-ov-btn { padding: 0 8px; }
}

/* ---------- Mobile: LuckForm arrangement (natal block, Zone A transit pillar + Zone B hits, action row, sheets) ---------- */
@media (max-width: 900px) {
  /* The view fills exactly the space between the top bar and the action row above the tab bar. */
  .page:has(> .luck-m) { padding-top: 6px; padding-bottom: calc(var(--tabbar-h, 58px) + env(safe-area-inset-bottom) + 64px); gap: 0; }
  .luck-m { height: calc(100vh - var(--luck-top, 60px) - var(--tabbar-h, 58px) - env(safe-area-inset-bottom) - 64px);
    height: calc(100dvh - var(--luck-top, 60px) - var(--tabbar-h, 58px) - env(safe-area-inset-bottom) - 64px);
    display: flex; flex-direction: column; gap: 2px; overflow: hidden; }
  .luck-date { display: none; }
  .m-board { --g: 26px; --hg: 14px; position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column;
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
  .m-board > .arrow-layer { z-index: 2; }
  .m-natal { flex: none; border-bottom: 2px solid var(--ink); }
  .m-natal .hid .e { display: none; }
  .m-board .phead { min-height: 0; padding: 3px 1px; }
  .m-board .pbody { gap: 2px; padding: 4px 0 3px; }
  .m-board .glyph { font-size: var(--g); line-height: 1.2; min-width: calc(var(--g) + 12px); min-height: 0; padding: 0 2px; }
  .m-board .pcell .god { min-height: 0; padding: 1px 0; line-height: 1.25; }
  .m-board .pcell .ele, .m-board .pcell .animal { line-height: 1.25; }
  .m-board .hidden-row { padding-top: 2px; }
  .m-board .hid { line-height: 1.15; }
  .m-board .hid .g { font-size: var(--hg); }
  .m-lane { flex: none; height: var(--mlane, 4px); }
  .m-luck { flex: 1; min-height: 0; display: grid; grid-template-columns: auto 16px minmax(0, 1fr); align-items: stretch; }
  .m-zone-a { display: flex; align-items: flex-start; border-right: 1px solid var(--line); align-self: start; }
  .m-side { width: 62px; display: flex; flex-direction: column; align-self: stretch; border-right: 1px solid var(--line); }
  .m-caption { min-height: 44px; border: 0; background: var(--soft); border-bottom: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2px; font-weight: 700; }
  .m-caption .t { font-size: 15px; line-height: 1.2; } .m-caption .s { font-size: 12px; line-height: 1.2; font-weight: 500; color: var(--muted); }
  .m-datecol { flex: 1; min-height: 44px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; padding: 4px 2px; border: 0; background: var(--birth-fill); color: var(--link); font-size: 12px; line-height: 1.2; text-align: center; }
  .m-date-top { font-weight: 700; color: var(--ink); }
  .m-date-sep { color: var(--muted); }
  .m-tpillar { width: 64px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0; background: var(--accent-soft); }
  .m-tpillar .pcell { display: flex; flex-direction: column; align-items: center; }
  .m-tpillar .glyph-row { position: relative; }
  .m-tpillar .hit-badge { position: absolute; top: -4px; right: -10px; }
  .m-tpillar .glyph.hit-src { border-style: dashed; border-color: var(--ink); }
  .m-tpillar .hidden-row { padding-top: 2px; }
  .m-tpillar.is-other { background: var(--soft); outline: 2px dashed var(--ink); outline-offset: -2px; }
  .m-tp-lab { font-size: 12px; font-weight: 700; line-height: 1.2; }
  /* All transit pillars at this moment; tap to read one (the active level keeps its accent frame) */
  .m-strip { flex: none; display: flex; gap: 3px; }
  .m-strip-btn { flex: 1 1 0; min-width: 0; min-height: 44px; display: flex; flex-direction: column; align-items: center; padding: 2px 0 3px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); line-height: 1.1; }
  .m-strip-btn .t { font-size: 12px; color: var(--muted); line-height: 1.2; }
  .m-strip-btn .han { font-size: 16px; }
  .m-strip-btn.is-active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
  .m-strip-btn[aria-pressed="true"] { background: var(--accent-soft); }
  .m-strip-btn[aria-pressed="true"] .t { color: var(--ink); font-weight: 700; }
  .m-natal .glyph.hint-bad, .m-natal .glyph.hint-good { position: relative; }
  .m-natal .glyph.hint-bad::after, .m-natal .glyph.hint-good::after { content: ''; position: absolute; top: 2px; right: 2px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
  .m-natal .glyph.hint-good::after { background: var(--jade); }
  .m-natal span.glyph[role="button"] { cursor: pointer; }
  .m-luck { grid-template-rows: minmax(0, 1fr); }
  .m-zone-b { min-width: 0; min-height: 0; overflow: hidden; padding: 0 8px 6px 0; display: flex; flex-direction: column; gap: 4px; }
  .m-zb-scroll { flex: 1 1 0; min-height: 0; overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 6px; }
  .m-zb-foot { flex: none; display: flex; gap: 4px; }
  .m-hits-head { display: flex; align-items: center; gap: 6px; }
  .m-band { flex: 1; background: var(--band); color: #fff; font-size: 13px; font-weight: 600; padding: 4px 8px; min-height: 28px; display: flex; align-items: center; }
  .m-hits-head .small-toggle { min-height: 44px; padding: 0 8px; }
  .m-hits .ev-chips { gap: 3px; }
  .m-hits .ev-chip { padding: 0 4px 0 3px; gap: 2px; }
  .m-hits .ev-kind { padding: 0 3px; }
  .m-hits .ev-pair { font-size: 15px; }
  .m-hits .ev-tgt { font-size: 12px; }
  .m-read-btn { flex: 1 1 0; min-width: 0; padding: 0 6px; font-size: 14px; line-height: 1.15; }
  .m-ov-btn { flex: 0 1 auto; min-width: 0; max-width: 62%; padding: 0 8px; overflow: hidden; }
  .m-ov-btn:not(.tot) .v-chip { display: inline-flex; }
  .m-ov-btn.tot .v-tot { display: inline-flex; }
  /* changed elements wrap onto a second line (3 a line) rather than falling back to the bare totals */
  .m-ov-btn .v-chip .ov-list { flex-wrap: wrap; max-width: 116px; gap: 0 5px; line-height: 1.15; }
  .m-ov-btn .v-chip .ov-lines { line-height: 1.15; }
  .m-ov-btn .v-tot > .ov-k { display: none; }
  .luck-m .arrow-status { flex: none; margin: 0; padding: 0 4px; }
  .m-date-form { position: fixed; left: 8px; right: 8px; bottom: calc(var(--tabbar-h, 58px) + env(safe-area-inset-bottom) + 68px); z-index: 16; display: flex; flex-direction: column; gap: 8px; }
  .m-date-form[hidden] { display: none; }
  .m-date-form .luck-form { flex-wrap: wrap; }
  .m-date-form .luck-inline { flex: 1 1 140px; }
  .m-date-form .luck-inline .input { width: 100%; font-size: 16px; }
  .m-date-form .btn { flex: 1 1 100%; }
  .m-actions { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h, 58px) + env(safe-area-inset-bottom)); z-index: 14; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px;
    padding: 6px max(8px, env(safe-area-inset-right)) 6px max(8px, env(safe-area-inset-left)); background: var(--ground); border-top: 1px solid var(--line); }
  .m-actions button { min-height: 48px; min-width: 0; padding: 0 2px; border: 1px solid var(--control); border-radius: 8px; background: var(--card); font-size: 13px; font-weight: 600; line-height: 1.15; }
  .m-actions button[disabled] { opacity: .45; }
  /* Chooser: short bottom sheet over the lower half; the natal block stays visible above it */
  .m-ch-backdrop { position: fixed; inset: 0; z-index: 29; background: rgba(26, 29, 27, .45); }
  .m-ch-backdrop[hidden] { display: none; }
  .m-chooser { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h, 58px) + env(safe-area-inset-bottom)); z-index: 30;
    max-height: calc(100dvh - var(--tabbar-h, 58px) - env(safe-area-inset-bottom) - 16px); overflow-y: auto; overscroll-behavior: contain;
    display: flex; flex-direction: column; gap: 6px; background: var(--card); border-top: 1px solid var(--line); border-radius: 12px 12px 0 0;
    padding: 8px max(10px, env(safe-area-inset-right)) 10px max(10px, env(safe-area-inset-left)); }
  .m-chooser[hidden] { display: none; }
  .m-ch-top { display: flex; gap: 6px; align-items: center; }
  .m-sheet-levels { flex: 1; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
  .m-sheet-levels > button { padding: 0 2px; font-size: 13px; }
  .m-chooser .cstrip { gap: 3px; }
  .m-chooser .c-step { width: 32px; }
  .m-chooser .cgrid { gap: 2px; }
  .m-chooser .ccell { grid-template-columns: minmax(0, 1fr); grid-template-areas: "pair" "lab"; min-height: 52px; padding: 4px 1px 3px; }
  .m-chooser .c-hits { position: absolute; top: -5px; right: -3px; z-index: 1; }
  .m-chooser .c-lab { flex-direction: column; align-items: center; line-height: 1.1; }
  /* Reading sheet: the switch stays at the top, only the text scrolls */
  .m-sheet > .dialog-body.luck-reading { overflow: hidden; display: flex; flex-direction: column; gap: 0; padding-bottom: 0; }
  .m-sheet .luck-reading .card-head { flex: none; }
  .m-sheet .rd-scroll { flex: 1 1 0; overflow-y: auto; overscroll-behavior: contain; padding-bottom: 16px; }
  .m-sheet { z-index: 30; }
  .m-sheet[hidden] { display: none; }
  .m-sheet > h2 { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
  .luck-sheet-open body { overflow: hidden; }
}

/* Mobile: board runs edge to edge (same column width as the main screen) so pillar sub-labels do not wrap. */
@media (max-width: 900px) {
  .luck-view.luck-m { margin-inline: calc(-1 * max(8px, env(safe-area-inset-left))) calc(-1 * max(8px, env(safe-area-inset-right))); }
  .luck-view.luck-m .m-board { border-left: 0; border-right: 0; border-radius: 0; }
  .luck-view.luck-m .phead .s { white-space: nowrap; }
}
