/* แสดงผล (views/result.js): one screen. Left/top: natal pillars (ปฏิ ลัคนา narrower) + key summary.
   Right/bottom: main tabs, a wrapping row of item chips, then the item text (only the text scrolls). */
.rs-h1 { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.rs-view { display: grid; gap: 10px; min-height: 0; }
.rs-left { min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: 10px; }
.rs-chart { flex: none; padding: 0; overflow: hidden; }
.rs-chart .pillars { border-radius: var(--radius) var(--radius) 0 0; overflow: hidden; }
.rs-chart button.glyph[aria-pressed] { cursor: pointer; }
.rs-legend { padding: 6px 12px 8px; border-top: 1px solid var(--line); }

/* ปฏิ / ลัคนา: narrower columns (≈ .58 of a main pillar), smaller glyphs and lighter text */
.rs-chart .pillars { --ga: 26px; grid-template-columns: repeat(2, minmax(40px, .58fr)); }
.rs-chart .pcol:is([data-col="pregnancy"], [data-col="life"]) .glyph { font-size: var(--ga); min-width: calc(var(--ga) + 6px); font-weight: 600; }
.rs-chart .pcol:is([data-col="pregnancy"], [data-col="life"]) .phead .t { font-size: 13px; font-weight: 600; }
.rs-chart .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; }
.rs-chart .pcol:is([data-col="pregnancy"], [data-col="life"]) .hidden-row { gap: 1px; flex-wrap: wrap; }
.rs-chart .pcol:is([data-col="pregnancy"], [data-col="life"]) .hid { min-width: 0; }
.rs-chart .pcol:is([data-col="pregnancy"], [data-col="life"]) .hid .g { font-size: 13px; font-weight: 500; }
.rs-chart .pcol:is([data-col="pregnancy"], [data-col="life"]) .hid .e { display: none; }
.rs-chart .pcol:is([data-col="pregnancy"], [data-col="life"]) .mark { font-size: 12px; }
.rs-chart .pcol:is([data-col="pregnancy"], [data-col="life"]) .pbody { padding-inline: 1px; }

/* Summary: type (big), ให้คุณ / ให้โทษ / ปกติ with marks, score */
.rs-sum { min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.rs-typeline { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 12px; }
.rs-type { font-size: 22px; line-height: 1.25; }
.rs-tname { font-size: 16px; font-weight: 600; color: var(--muted); }
.rs-score { font-size: 15px; color: var(--muted); white-space: nowrap; } .rs-score b { font-size: 20px; color: var(--ink); }
.rs-favs { display: flex; flex-direction: column; gap: 4px; }
.rs-favrow { display: flex; align-items: baseline; gap: 10px; border-left: 4px solid var(--line); padding: 2px 0 2px 10px; }
.rs-favrow.is-fav { border-left-color: var(--fav); } .rs-favrow.is-unfav { border-left-color: var(--unfav); } .rs-favrow.is-norm { border-left-color: var(--norm); }
.rs-favk { flex: none; width: 6.2em; font-size: 14px; font-weight: 600; color: var(--muted); }
.rs-favv { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 14px; font-size: 18px; }
.rs-eli { display: inline-flex; align-items: baseline; gap: 3px; white-space: nowrap; }
.rs-eli .mark { font-size: 16px; } .rs-eli .mark.fav { font-size: 18px; }
.rs-eli-q { font-size: .85em; font-weight: 500; }
.rs-eli-if { font-size: .75em; font-weight: 500; color: var(--ink); }
.rs-note { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; border-top: 1px dashed var(--line); padding-top: 8px; font-size: 14px; color: var(--muted); }
.rs-note .reading { max-width: none; }

/* Panel + main tabs */
.rs-panel { min-width: 0; min-height: 0; display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.rs-tabs { flex: none; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; padding: 6px; border-bottom: 1px solid var(--line); background: var(--soft); }
.rs-tab { min-width: 0; min-height: 44px; padding: 0 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); font-size: 15px; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rs-tab:hover { background: var(--soft); }
.rs-tab[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.rs-tab-short { display: none; }
.rs-body { flex: 1 1 auto; min-height: 0; overflow: hidden; padding: 8px 14px 12px; display: flex; flex-direction: column; gap: 8px; }
.rs-body > * { flex: none; }
.rs-body > .rs-text { flex: 1 1 auto; }
.rs-sec-h { font-size: 17px; }

/* Level 2: item chips, wrapping (desktop) */
.rs-sub { display: flex; flex-wrap: wrap; gap: 4px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.rs-sc { min-width: 0; max-width: 15em; min-height: 44px; display: inline-flex; align-items: center; gap: 6px; padding: 0 10px 0 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); font-size: 14px; font-weight: 600; line-height: 1.2; color: var(--ink); text-align: left; }
.rs-sc:hover { background: var(--soft); }
.rs-sc[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.rs-sc-n { flex: none; min-width: 20px; height: 20px; border-radius: 10px; background: var(--soft); color: var(--muted); font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.rs-sc[aria-pressed="true"] .rs-sc-n { background: var(--accent); color: #fff; }
.rs-sc-t { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Many items (set by fitChips in result.js): narrower titles, then numbers only */
.rs-sub-s .rs-sc { max-width: 9em; }
.rs-sub-xs .rs-sc { max-width: 6.2em; padding-right: 6px; }
.rs-sub-n .rs-sc { min-width: 44px; justify-content: center; padding: 0 4px; }
.rs-sub-n .rs-sc-t { display: none; }

/* คำอ่านดวง: the 7 position chips (one row) */
.rs-chips { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.rs-chip { min-width: 0; min-height: 52px; display: flex; align-items: center; justify-content: center; gap: 4px; padding: 2px 4px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); line-height: 1.1; }
.rs-chip:hover { background: var(--soft); }
.rs-chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.rs-chip-k { display: flex; flex-direction: column; align-items: center; font-size: 14px; font-weight: 600; }
.rs-chip-k small { font-size: 12px; font-weight: 500; color: var(--muted); }
.rs-chip .han { font-size: 24px; line-height: 1.1; }
.rs-chip .mark { align-self: flex-start; font-size: 13px; }

/* Selected item: title / subtitle, section switch, text */
.rs-ihead { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 12px; }
.rs-rtitle { font-size: 19px; }
.lf-sub { font-size: 14px; font-weight: 600; color: var(--muted); white-space: pre-line; line-height: 1.35; }
.rs-var, .lf-sec { flex-wrap: nowrap; gap: 4px; }
.rs-var > button, .lf-sec > button { min-height: 44px; padding: 0 12px; font-size: 14px; white-space: nowrap; }
.rs-var > button small { font-size: 12px; font-weight: 500; }
.rs-text { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; border-top: 1px solid var(--line); padding-top: 8px; }
.rs-text .reading { font-size: 17px; line-height: 1.65; max-width: 72ch; }
.rs-text:focus { outline: none; } .rs-text:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* น้ำหนักธาตุ: two radars + compact table */
.rs-body > .rs-el { flex: 1 1 auto; }
.rs-el { min-height: 0; display: flex; flex-direction: column; gap: 6px; }
.rs-el > * { flex: none; }
.rs-radars { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.rs-rfig { margin: 0; min-width: 0; min-height: 0; display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 8px; padding: 4px 6px 2px; }
.rs-rfig figcaption { flex: none; font-size: 15px; line-height: 1.3; }
.rs-rbox { flex: 1 1 auto; min-height: 0; position: relative; overflow: hidden; }
.rs-radar { position: absolute; inset: 0; display: block; }
.rs-radar text { fill: var(--ink); }
.rs-radar tspan { fill: currentColor; }
.rs-radar .rs-rl { color: var(--ink); } .rs-radar .rs-rv { color: var(--muted); }
.rs-radar .mark.fav { font-size: 14px; }
.rs-rg { fill: none; stroke: var(--line); stroke-width: 1; }
.rs-rp { fill: var(--accent); fill-opacity: .16; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.rs-rp-d { fill: var(--accent); }
.rs-rw { fill: var(--band); fill-opacity: .06; stroke: var(--band); stroke-width: 1.5; stroke-dasharray: 5 3; stroke-linejoin: round; }
.rs-rlegend { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 16px; color: var(--muted); }
.rs-rlegend > span { display: inline-flex; align-items: center; gap: 6px; }
.rs-sw { display: inline-block; width: 18px; height: 0; border-top: 2px solid var(--accent); }
.rs-sw-w { border-top: 2px dashed var(--band); }
.rs-sums { margin-left: auto; gap: 14px !important; font-size: 14px; color: var(--ink); }
.rs-sums > span { white-space: nowrap; }
.rs-etable th, .rs-etable td { padding: 3px 8px; vertical-align: middle; font-size: 14px; }
.rs-etable thead th { font-size: 12px; }
.rs-etable td:not(.rs-erel), .rs-etable thead th:nth-child(n+3) { text-align: right; }
.rs-etable tbody th { font-size: 15px; font-weight: 700; }
.rs-etable .rs-ep b { color: var(--accent); }
.rs-fieldnote { line-height: 1.35; }
.rs-rsw { flex-wrap: nowrap; gap: 4px; }
.rs-rsw > button { min-height: 44px; padding: 0 12px; font-size: 14px; }
.rs-mnote h3 { font-size: 15px; margin-bottom: 4px; }
.rs-mnote .reading { font-size: 15px; color: var(--muted); }

/* ---------- Desktop (≥ 901px): left/right, whole view fits the window ---------- */
@media (min-width: 901px) {
  .page:has(> .rs-view) { max-width: 1600px; padding: 8px 16px; gap: 0; }
  .rs-view { height: calc(100vh - var(--rs-top, 66px) - 8px); min-height: 440px; overflow: hidden;
    grid-template-columns: minmax(360px, 41%) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
  /* Pillars sized by the window height so chart + summary fit the column */
  .rs-chart .pillars { --ga: clamp(20px, 3.3vh, 32px); }
  .rs-chart .phead { min-height: 0; padding: clamp(4px, .9vh, 10px) 2px; gap: 0; }
  .rs-chart .phead .t { font-size: 17px; line-height: 1.25; } .rs-chart .phead .s { font-size: 12px; line-height: 1.2; }
  .rs-chart .pbody { gap: clamp(2px, .9vh, 12px); padding: clamp(4px, 1vh, 14px) 2px clamp(4px, .9vh, 12px); }
  .rs-chart .pcell { gap: 0; }
  .rs-chart .glyph { font-size: clamp(28px, 5.4vh, 52px); line-height: 1.15; min-height: 0; }
  .rs-chart .pcol:not([data-col="pregnancy"]):not([data-col="life"]) .glyph { min-width: 44px; }
  .rs-chart .pcell .god { min-height: 0; padding: 1px 2px; }
  .rs-chart .hidden-row { padding-top: clamp(3px, .8vh, 10px); }
  .rs-sum { flex: 1 1 auto; padding: 12px 14px; }
}
@media (min-width: 901px) and (max-height: 640px) {
  .rs-type { font-size: 19px; }
  .rs-favv { font-size: 16px; }
  .rs-legend { display: none; }
  .rs-fieldnote { display: none; }
}
@media (min-width: 901px) and (max-width: 1180px) {
  .rs-view { grid-template-columns: minmax(360px, 43%) minmax(0, 1fr); }
  /* Three hidden stems must fit a main column: glyph + mark side by side, element word dropped */
  .rs-chart .hidden-row { gap: 1px; }
  .rs-chart .hid { flex-direction: row; align-items: center; min-width: 0; }
  .rs-chart .hid .e { display: none; }
  .rs-chart .hid .g { font-size: 16px; }
  .rs-chart .hid .mark { font-size: 12px; }
  .rs-tab { font-size: 14px; padding: 0 3px; }
  .rs-sc { max-width: 12em; }
  .rs-chip { gap: 2px; padding: 2px; }
  .rs-chip .han { font-size: 21px; }
  .rs-etable th, .rs-etable td { padding: 3px 5px; }
}

/* ---------- Mobile (≤ 900px): one screen between the top bar and the bottom tab bar ---------- */
@media (max-width: 900px) {
  .page:has(> .rs-view) { padding-top: 6px; padding-bottom: calc(var(--tabbar-h, 58px) + env(safe-area-inset-bottom) + 6px); gap: 0; }
  .rs-view { gap: 6px; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); overflow: hidden;
    height: calc(100vh - var(--rs-top, 60px) - var(--tabbar-h, 58px) - env(safe-area-inset-bottom) - 6px);
    height: calc(100dvh - var(--rs-top, 60px) - var(--tabbar-h, 58px) - env(safe-area-inset-bottom) - 6px); }
  .rs-left { gap: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
  .rs-chart { border: 0; border-radius: 0; }
  .rs-chart .pillars { border-radius: 0; --ga: 18px; grid-template-columns: repeat(2, minmax(34px, .62fr)); }
  .rs-chart .phead { min-height: 0; padding: 3px 1px; }
  .rs-chart .phead .t { font-size: 15px; }
  .rs-chart .pbody { gap: 2px; padding: 3px 0 3px; }
  .rs-chart .glyph { font-size: 25px; min-height: 0; line-height: 1.2; }
  .rs-chart .pcol:is([data-col="pregnancy"], [data-col="life"]) .glyph { min-width: 0; padding: 0 1px; }
  .rs-chart .pcell .god { min-height: 0; padding: 1px 0; line-height: 1.25; }
  .rs-chart .hidden-row { padding-top: 2px; }
  .rs-chart .hid .e { display: none; }
  .rs-chart .hid { flex-direction: row; align-items: center; gap: 0; }
  .rs-chart .hid .g { font-size: 15px; }
  .rs-chart .hid .mark { font-size: 12px; }
  .rs-chart .pcol:is([data-col="pregnancy"], [data-col="life"]) .hid .g { font-size: 12px; }
  .rs-chart .pcol:is([data-col="pregnancy"], [data-col="life"]) .hidden-row { flex-wrap: nowrap; }
  .rs-chart .pcol:is([data-col="pregnancy"], [data-col="life"]) .hid .mark { display: none; }
  /* Key summary line right under the chart */
  .rs-sum { border: 0; border-top: 2px solid var(--ink); border-radius: 0; padding: 5px 8px 6px; gap: 3px; }
  .rs-typeline { flex-wrap: nowrap; gap: 8px; }
  .rs-type { font-size: 17px; min-width: 0; }
  .rs-tname { font-size: 14px; }
  .rs-score { font-size: 13px; } .rs-score b { font-size: 16px; }
  .rs-favs { flex-direction: row; flex-wrap: wrap; gap: 2px 6px; }
  .rs-favrow { gap: 4px; border-left-width: 3px; padding: 0 0 0 5px; }
  .rs-favk { width: auto; font-size: 13px; }
  .rs-k-pre { display: none; }
  .rs-favv { font-size: 15px; gap: 0 5px; }
  .rs-eli .mark, .rs-eli .mark.fav { font-size: 14px; }
  /* Section panel */
  .rs-tabs { padding: 3px; gap: 3px; }
  .rs-tab { padding: 0 2px; font-size: 14px; }
  .rs-tab-full { display: none; } .rs-tab-short { display: inline; }
  .rs-body { padding: 6px 8px 8px; gap: 6px; }
  .rs-sec-h { font-size: 16px; }
  /* Chips: one sideways-scrolling strip */
  .rs-sub { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; scrollbar-width: none; padding-bottom: 0; border-bottom: 0; }
  .rs-sub::-webkit-scrollbar { display: none; }
  .rs-sc { flex: 0 0 auto; max-width: 13em; }
  .rs-chips { display: flex; }
  .rs-chip { flex: 0 0 auto; min-height: 44px; padding: 0 8px; }
  .rs-chip .han { font-size: 21px; }
  .rs-rtitle { font-size: 16px; }
  .lf-sub { font-size: 13px; white-space: normal; }
  .rs-var, .lf-sec { width: 100%; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .rs-var > button, .lf-sec > button { padding: 0 4px; }
  .rs-text { padding-top: 6px; }
  .rs-text .reading { font-size: 16px; line-height: 1.6; }
  /* น้ำหนักธาตุ: one radar at a time (switch), the rest scrolls inside the panel */
  .rs-body-el { overflow-y: auto; overscroll-behavior: contain; }
  .rs-body > .rs-el { flex: none; }
  .rs-rsw { width: 100%; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rs-radars { flex: none; grid-template-columns: minmax(0, 1fr); }
  .rs-rfig.is-off { display: none; }
  .rs-rfig { border: 0; padding: 0; }
  .rs-rfig figcaption { display: none; }
  .rs-rbox { flex: none; height: 280px; }
  .rs-sums { margin-left: 0; }
  .rs-etable th, .rs-etable td { padding: 4px 3px; font-size: 13px; }
  .rs-etable { table-layout: fixed; }
  .rs-etable thead th { font-size: 12px; overflow-wrap: anywhere; word-break: break-all; line-height: 1.2; }
  .rs-etable thead th:first-child { width: 3.8em; }
  .rs-etable thead th:nth-child(2) { width: 6.6em; }
  .rs-etable tbody th { font-size: 14px; }
}
/* Short phones: element text under each glyph goes (the glyph colour carries it) to leave room for the reading */
@media (max-width: 900px) and (max-height: 700px) {
  .rs-chart .pcell .ele { display: none; }
}
