/* ดวงBazi · อี้จิง — mobile-only. Tokens are the ดวงBazi set (bazi-web/styles.css) plus a few soft pastels
   derived from accent-soft / jade for the "cute" layer. No purple, no neon. */
:root {
  --ground: #F4F5F2; --card: #FFFFFF; --line: #D9DDD6; --ink: #1A1D1B; --muted: #5A625D;
  --control: #8B938D; --soft: #EEF0EB; --accent: #A8271C; --accent-soft: #FBEDEA; --jade: #1E6650;
  --link: #6B2FA0;
  /* five elements, indexed like engine ELEMENTS: 0 ทอง 1 น้ำ 2 ไม้ 3 ไฟ 4 ดิน */
  --el-0: #4F5B66; --el-1: #1C5FA8; --el-2: #1F7A3D; --el-3: #B3261E; --el-4: #8A5A12;
  --radius: 10px; --font: 'IBM Plex Sans Thai', system-ui, sans-serif; --han: 'Noto Serif TC', 'Songti SC', serif;
  /* cute layer */
  --r-card: 18px; --r-btn: 14px;
  --jade-soft: #E3F1EB; --jade-line: #BFDCCF; --accent-line: #F1D3CD;
  --gold: #EFC862; --gold-deep: #B9852F; --gold-soft: #FBF4DD; --blush: #F2A79B;
  --good: #1E6650; --warn: #8A5A12; --bad: #A8271C;
  --frame-w: 480px; --tabbar-h: 60px; --topbar-h: 52px;
  --gutter: max(14px, env(safe-area-inset-left));
  --gutter-r: max(14px, env(safe-area-inset-right));
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; }
body { background: var(--ground); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.5; overflow-x: hidden; -webkit-tap-highlight-color: transparent; }
a { color: var(--link); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea, .input { font-size: 16px; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
main:focus { outline: none; }
h1 { font-size: 20px; margin: 0; line-height: 1.3; } h2 { font-size: 17px; margin: 0; } h3 { font-size: 15px; margin: 0; }
p { margin: 0; }
[hidden] { display: none !important; }
.boot { padding: 40px 16px; color: var(--muted); text-align: center; }
.muted { color: var(--muted); } .small { font-size: 13px; } .center { text-align: center; }
.han { font-family: var(--han); font-weight: 700; }
.label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); }

/* ---------- Frame: single centred mobile column ---------- */
.frame { width: 100%; max-width: var(--frame-w); margin: 0 auto; min-height: 100vh; min-height: 100dvh; background: var(--ground); position: relative; }
@media (min-width: 520px) { .frame { border-left: 1px solid var(--line); border-right: 1px solid var(--line); } }

.topbar { position: sticky; top: 0; z-index: 15; background: var(--card); border-bottom: 1px solid var(--line);
  min-height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: calc(6px + env(safe-area-inset-top)) var(--gutter-r) 6px var(--gutter); display: flex; align-items: center; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; color: var(--ink); min-height: 44px; }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: #fff; font-family: var(--han); font-size: 19px; display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 0 #7E1C14; }

.page { display: block; padding: 14px var(--gutter-r) calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 20px) var(--gutter); overflow-x: clip; }
.stack { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.stack-sm { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.page-head .page-title { flex: 1; min-width: 0; }
.page-head h1 { font-size: 20px; }
.section-title { font-size: 16px; font-weight: 700; margin-bottom: 2px; }

/* ---------- Bottom tab bar (ดวงBazi mobile pattern) ---------- */
.tabbar { position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); width: 100%; max-width: var(--frame-w); z-index: 15;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.tabbar a { flex: 1 1 0; min-width: 0; min-height: var(--tabbar-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  padding: 4px 2px; color: var(--ink); font-size: 12px; font-weight: 500; border-radius: 0; }
.tabbar a span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabbar a[aria-current="page"] { color: var(--accent); font-weight: 700; background: var(--accent-soft); }
.tabbar a[aria-current="page"] svg { transform: translateY(-1px); }

/* ---------- Cards & controls ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-card); padding: 14px; min-width: 0; }
.card.soft { background: var(--accent-soft); border-color: var(--accent-line); }
.card-inner { background: #FAFBF8; border: 1px solid var(--line); border-radius: 14px; padding: 14px; min-width: 0; }
.card.flush-tabs { padding: 0; overflow: hidden; }
.error-box { border: 1px solid var(--accent); color: var(--accent); background: var(--accent-soft); }

.btn { min-height: 44px; padding: 0 16px; border-radius: var(--r-btn); border: 1px solid var(--control); background: var(--card); color: var(--ink); font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-align: center; line-height: 1.25; transition: transform .12s ease, background-color .15s ease; }
.btn:active:not([disabled]) { transform: translateY(1px) scale(.99); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 3px 0 #7E1C14; }
.btn.primary:active:not([disabled]) { transform: translateY(2px); box-shadow: 0 1px 0 #7E1C14; }
.btn.big { min-height: 54px; font-size: 17px; width: 100%; border-radius: 16px; }
.btn.small { min-height: 44px; padding: 0 12px; font-size: 14px; }
.btn.icon { width: 44px; padding: 0; flex: none; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger-text { color: var(--accent); }
.btn[disabled] { opacity: .45; cursor: not-allowed; box-shadow: none; }
.input { min-height: 46px; padding: 0 14px; border: 1px solid var(--control); border-radius: 12px; background: #fff; width: 100%; margin-top: 6px; }
textarea.input { padding: 10px 14px; min-height: 76px; resize: vertical; line-height: 1.5; }
select.input { margin-top: 0; padding-right: 8px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row-2 .btn { width: 100%; }
.sticky-cta { position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 10px); z-index: 5; }
.ic { flex: none; }

/* Element chips: pastel tint, element colour text */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips.col { flex-direction: column; align-items: center; gap: 4px; }
.el-chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 700; line-height: 1.5; white-space: nowrap; }
.el-chip .pos { font-weight: 500; opacity: .85; }
.el-chip .el { font-weight: 500; }
.el-chip .el::before { content: '·'; margin-right: 4px; }
.el-bg-0 { background: #E8ECEF; color: var(--el-0); } .el-bg-1 { background: #E3EDF9; color: var(--el-1); }
.el-bg-2 { background: #E1F1E5; color: var(--el-2); } .el-bg-3 { background: #FBE5E2; color: var(--el-3); }
.el-bg-4 { background: #F4EBDA; color: var(--el-4); }

/* Hexagram drawing */
.hex { display: block; overflow: visible; }
.hex .ln rect { fill: var(--ink); }
.hex .ln.mark rect { fill: var(--accent); }
.hex .ln.empty rect { fill: none; stroke: var(--control); stroke-width: 1.4; stroke-dasharray: 4 4; opacity: .6; }
.hex-name { display: flex; flex-direction: column; align-items: inherit; min-width: 0; line-height: 1.3; }
.hex-name .kw { font-size: 12px; color: var(--muted); font-weight: 600; }
.hex-name .han { font-size: 28px; line-height: 1.2; }
.hex-name .th { font-size: 17px; font-weight: 700; overflow-wrap: anywhere; }
.hex-name .py { font-size: 13px; color: var(--accent); }
.hex-name.sm .han { font-size: 24px; } .hex-name.sm .th { font-size: 13.5px; } .hex-name.sm .py, .hex-name.sm .kw { font-size: 11.5px; }
.hex-name.lg { align-items: center; text-align: center; } .hex-name.lg .han { font-size: 42px; } .hex-name.lg .th { font-size: 21px; }
.star { color: var(--accent); }
.mark-note { color: var(--accent); font-weight: 600; }

/* ---------- Mascot ---------- */
.mascot-row { display: flex; align-items: center; gap: 10px; }
.mascot-wrap { flex: none; animation: bob 3.4s ease-in-out infinite; }
.mascot { display: block; overflow: visible; }
.bubble { position: relative; flex: 1; min-width: 0; background: var(--card); border: 1px solid var(--accent-line); border-radius: 18px; padding: 10px 14px; font-weight: 500; font-size: 15px; line-height: 1.5; }
.bubble::before { content: ''; position: absolute; left: -7px; top: 50%; width: 12px; height: 12px; background: var(--card); border-left: 1px solid var(--accent-line); border-bottom: 1px solid var(--accent-line); transform: translateY(-50%) rotate(45deg); }
.mascot-row.compact .bubble { font-size: 14px; padding: 8px 12px; }

.mascot .m-skin { fill: #F7E7C6; stroke: #6B5330; stroke-width: 2.2; }
.mascot .m-shell { fill: #BFE0D2; stroke: var(--jade); stroke-width: 2.5; }
.mascot .m-shell-cell { fill: #A3D1BE; stroke: var(--jade); stroke-width: 1.3; }
.mascot .m-belly { fill: #FBF3DE; stroke: var(--jade); stroke-width: 1.6; }
.mascot .m-tri rect { fill: var(--jade); }
.mascot .m-cap { fill: #2E3A35; }
.mascot .m-knot { fill: var(--accent); }
.mascot .m-cheek { fill: var(--blush); opacity: .8; }
.mascot .m-stroke { fill: none; stroke: #2A2420; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.mascot .m-mouth-grin, .mascot .m-mouth-o { fill: #8F2018; }
.mascot .m-beard { fill: #fff; stroke: #CFC6B3; stroke-width: 1.2; }
.mascot .m-shadow { fill: rgba(26, 29, 27, .10); }
.mascot .m-spark path { fill: #E6A700; }
.mascot .m-dots circle { fill: #fff; stroke: var(--control); stroke-width: 1.2; }
.mascot .m-eyes, .mascot .m-mouth, .mascot .m-spark, .mascot .m-dots { display: none; }
.mascot[data-mood="idle"] .m-eyes-open, .mascot[data-mood="idle"] .m-mouth-smile,
.mascot[data-mood="happy"] .m-eyes-happy, .mascot[data-mood="happy"] .m-mouth-grin,
.mascot[data-mood="think"] .m-eyes-think, .mascot[data-mood="think"] .m-mouth-hmm, .mascot[data-mood="think"] .m-dots,
.mascot[data-mood="excited"] .m-eyes-star, .mascot[data-mood="excited"] .m-mouth-o,
.mascot[data-mood="cheer"] .m-eyes-happy, .mascot[data-mood="cheer"] .m-mouth-grin, .mascot[data-mood="cheer"] .m-spark { display: inline; }
.mascot .m-eyes-open { transform-box: fill-box; transform-origin: center; animation: blink 4.6s infinite; }
.mascot .m-head { transform-box: view-box; transform-origin: 60px 70px; }
.mascot[data-mood="think"] .m-head { transform: rotate(-6deg); transition: transform .3s ease; }
.mascot .m-arm-r { transform-box: view-box; transform-origin: 96px 78px; }
.mascot[data-mood="cheer"] .m-arm-r { animation: wave .55s ease-in-out infinite alternate; }
.mascot[data-mood="excited"] .m-body { transform-box: view-box; transform-origin: 60px 110px; animation: wiggle .28s ease-in-out infinite alternate; }
.mascot[data-mood="cheer"] .m-spark { animation: twinkle 1.1s ease-in-out infinite; }
.mascot[data-mood="think"] .m-dots circle { animation: twinkle 1.6s ease-in-out infinite; }
.mascot[data-mood="think"] .m-dots circle:nth-child(2) { animation-delay: .2s; }
.mascot[data-mood="think"] .m-dots circle:nth-child(3) { animation-delay: .4s; }
.mascot.pop .m-body { transform-box: view-box; transform-origin: 60px 110px; animation: hop .5s cubic-bezier(.3, 1.6, .5, 1); }
.mascot.pop[data-mood="excited"] .m-body { animation: wiggle .28s ease-in-out infinite alternate; }

@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
@keyframes blink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(.1); } }
@keyframes wave { from { transform: rotate(0deg); } to { transform: rotate(-38deg); } }
@keyframes wiggle { from { transform: rotate(-3deg); } to { transform: rotate(3deg); } }
@keyframes hop { 0% { transform: translateY(0) scale(1, 1); } 30% { transform: translateY(-9px) scale(.97, 1.04); } 65% { transform: translateY(0) scale(1.04, .96); } 100% { transform: translateY(0) scale(1, 1); } }
@keyframes twinkle { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px) scale(.97); } to { opacity: 1; transform: none; } }

/* ---------- Home ---------- */
.hero { padding: 16px 14px; }
.hero .bubble { font-size: 15.5px; }
.method { display: flex; align-items: center; gap: 14px; padding: 14px; min-height: 80px; border-radius: var(--r-card); border: 1px solid var(--line); background: var(--card); color: var(--ink);
  transition: transform .12s ease; }
.method:active { transform: scale(.985); }
.method-art { flex: none; width: 60px; height: 60px; border-radius: 50%; background: var(--gold-soft); display: flex; align-items: center; justify-content: center; }
.method-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.method-title { font-weight: 700; font-size: 17px; }
.method-desc { font-size: 13.5px; color: var(--muted); }
.method-go { flex: none; font-size: 26px; color: var(--control); line-height: 1; }
.method.primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 4px 0 #7E1C14; min-height: 96px; }
.method.primary .method-title { font-size: 19px; }
.method.primary .method-desc, .method.primary .method-go { color: rgba(255, 255, 255, .88); }
.method.primary .method-art { background: rgba(255, 255, 255, .18); width: 66px; height: 66px; }
.method-ic .ln rect { fill: var(--jade); }
.mi-coin { fill: var(--gold); stroke: var(--gold-deep); stroke-width: 1.6; }
.mi-hole { fill: var(--accent); stroke: var(--gold-deep); stroke-width: 1.2; }
.mi-paper { fill: #fff; stroke: var(--jade); stroke-width: 1.8; }
.mi-line { stroke: var(--jade); stroke-width: 2.4; stroke-linecap: round; fill: none; }
.mi-num { font: 700 14px var(--font); fill: var(--accent); }
.q-banner { background: var(--card); border: 1px dashed var(--control); border-radius: 12px; padding: 8px 12px; font-size: 14px; overflow-wrap: anywhere; }

/* ---------- Coin ---------- */
.card.toss-stage { text-align: center; display: flex; flex-direction: column; gap: 10px; background: var(--jade-soft); border-color: var(--jade-line); }
.toss-stage .bubble { text-align: left; border-color: var(--jade-line); }
.toss-stage .bubble::before { border-color: var(--jade-line); }
.coins { display: flex; justify-content: center; gap: 14px; padding: 34px 0 2px; }
.coin { display: flex; flex-direction: column; align-items: center; gap: 6px; width: 78px; }
.coin-stage { position: relative; width: 72px; height: 72px; perspective: 520px; }
.coin-inner { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; z-index: 1; }
.coin-face { position: absolute; inset: 0; width: 100%; height: 100%; -webkit-backface-visibility: hidden; backface-visibility: hidden; }
.coin-face.tails { transform: rotateY(180deg); }
.coin.is-t .coin-inner { transform: rotateY(180deg); }
.coin-shadow { position: absolute; left: 12%; right: 12%; bottom: -8px; height: 8px; border-radius: 50%; background: rgba(26, 29, 27, .14); }
.coin-tag { font-size: 14px; font-weight: 700; min-height: 22px; padding: 0 10px; border-radius: 999px; background: var(--card); border: 1px solid var(--jade-line); }
.coin.is-h .coin-tag { color: var(--gold-deep); border-color: #E7CF8E; background: var(--gold-soft); }
.coin.is-t .coin-tag { color: var(--jade); }
.heads .c-metal { fill: var(--gold); stroke: var(--gold-deep); stroke-width: 2.4; }
.heads .c-inner { fill: none; stroke: #D8A84A; stroke-width: 1.4; }
.heads .c-hole { fill: none; stroke: var(--gold-deep); stroke-width: 1.8; }
.tails .c-metal { fill: #DCE9E2; stroke: #6E8F81; stroke-width: 2.4; }
.tails .c-inner { fill: none; stroke: #A9C4B8; stroke-width: 1.4; }
.tails .c-hole { fill: none; stroke: #6E8F81; stroke-width: 1.8; }
.c-cheek { fill: var(--blush); opacity: .7; }
.c-stroke { fill: none; stroke: #2A2420; stroke-width: 2; stroke-linecap: round; }
.c-mouth { fill: #2A2420; }
.c-shine { fill: none; stroke: rgba(255, 255, 255, .8); stroke-width: 2.4; stroke-linecap: round; }
.coin.idle .coin-inner { animation: coin-idle 2.6s ease-in-out infinite; }
.coin.idle:nth-child(2) .coin-inner { animation-delay: .3s; }
.coin.idle:nth-child(3) .coin-inner { animation-delay: .6s; }
.coin.flip-h .coin-inner { animation: flip-h var(--flip-ms, 1000ms) cubic-bezier(.25, .7, .35, 1) forwards; }
.coin.flip-t .coin-inner { animation: flip-t var(--flip-ms, 1000ms) cubic-bezier(.25, .7, .35, 1) forwards; }
.coin.flip-h .coin-shadow, .coin.flip-t .coin-shadow { animation: coin-shadow var(--flip-ms, 1000ms) ease-out; }
@keyframes coin-idle { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg) translateY(-2px); } }
@keyframes flip-h {
  0% { transform: translateY(0) rotateY(0deg); }
  42% { transform: translateY(-36px) rotateY(900deg); }
  78% { transform: translateY(0) rotateY(1800deg); }
  89% { transform: translateY(-8px) rotateY(1800deg); }
  100% { transform: translateY(0) rotateY(1800deg); } }
@keyframes flip-t {
  0% { transform: translateY(0) rotateY(0deg); }
  42% { transform: translateY(-36px) rotateY(990deg); }
  78% { transform: translateY(0) rotateY(1980deg); }
  89% { transform: translateY(-8px) rotateY(1980deg); }
  100% { transform: translateY(0) rotateY(1980deg); } }
@keyframes coin-shadow { 0%, 100% { transform: scaleX(1); opacity: 1; } 42% { transform: scaleX(.45); opacity: .45; } }

.counter { font-size: 20px; font-weight: 700; color: var(--jade); }
.toss-result { min-height: 1.5em; }
.toss-controls { display: grid; gap: 10px; margin-top: 4px; }
.result-box { background: var(--card); border: 2px solid var(--accent); border-radius: var(--r-card); padding: 14px; display: flex; flex-direction: column; gap: 14px; animation: rise .35s ease-out; }

/* Ladder (hexagram being built, top row = line 6) */
.ladder { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.rung { display: grid; grid-template-columns: 62px minmax(0, 1fr) 46px 34px; align-items: center; gap: 8px; min-height: 40px; padding: 4px 8px; border-radius: 12px; }
.rung-no { font-size: 13px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.rung-line .hex { width: 100%; height: auto; max-width: 160px; }
.rung.empty .rung-line { height: 12px; border: 1.5px dashed var(--line); border-radius: 999px; max-width: 160px; }
.rung.filled { animation: rise .35s ease-out; }
.rung.is-mark { background: var(--accent-soft); }
.rung.is-mark .rung-no { color: var(--accent); }
.rung-coins { display: flex; gap: 3px; }
.rung-val { font-size: 13px; font-weight: 700; }
.dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; vertical-align: -1px; }
.dot.h { background: var(--gold); border: 1.5px solid var(--gold-deep); }
.dot.t { background: #DCE9E2; border: 1.5px solid #6E8F81; }
.legend { margin-top: 10px; }

/* Preview (shared by toss / pick / word) */
.preview { display: flex; gap: 14px; align-items: center; min-width: 0; }
.preview-hex { flex: none; padding: 12px; background: var(--ground); border-radius: 14px; }
.preview-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.empty-note { padding: 14px 0 4px; }

/* ---------- Pick ---------- */
.picker-nav { display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px; gap: 8px; align-items: center; margin-bottom: 14px; }
.picker-nav select { min-height: 44px; text-overflow: ellipsis; }
.pick-rows { display: flex; flex-direction: column; gap: 8px; }
.pick-row { display: grid; grid-template-columns: 58px minmax(0, 1fr) 48px; gap: 8px; align-items: center; }
.pick-row .rung-no { font-size: 13px; }
.pick-row.is-mark .rung-no { color: var(--accent); }
.line-btn { min-height: 50px; display: flex; align-items: center; gap: 10px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); min-width: 0; }
.line-btn .hex { flex: 1; width: 100%; height: auto; max-width: 160px; min-width: 0; }
.line-btn:active { transform: scale(.98); }
.line-val { flex: none; width: 34px; font-size: 13px; font-weight: 700; color: var(--muted); }
.mark-btn { width: 48px; height: 48px; border: 0; background: none; padding: 0; display: flex; align-items: center; justify-content: center; border-radius: 50%; }
.mark-btn .mk { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--control); background: var(--card); display: flex; align-items: center; justify-content: center; font-size: 15px; line-height: 1; transition: transform .15s ease; }
.mark-btn.auto .mk { border-style: dashed; border-color: var(--accent); color: var(--accent); }
.mark-btn.on .mk { background: var(--accent); border-color: var(--accent); color: #fff; transform: scale(1.08); }
.pick .card.soft { display: flex; flex-direction: column; gap: 12px; }
.pick .card.soft .btn.ghost { align-self: flex-start; color: var(--accent); }

/* ---------- Segmented / tabs / chips ---------- */
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg-btn { min-height: 44px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-weight: 600; font-size: 14px; }
.seg-btn[aria-pressed="true"] { background: var(--jade); border-color: var(--jade); color: #fff; }
.seg.wide .seg-btn { flex: 1 1 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 10px; }
.tabs { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); border-bottom: 1px solid var(--line); background: var(--card); }
.tab { min-height: 48px; border: 0; background: none; font-weight: 600; font-size: 14.5px; color: var(--muted); border-bottom: 3px solid transparent; padding: 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.tabs.many .tab { font-size: 13px; padding: 0 2px; }
.tab-panel { padding: 14px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.tab-panel:focus-visible { outline-offset: -3px; }
.picker { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.picker-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.picker-head .btn { color: var(--jade); }
.chip-row { display: flex; gap: 8px; overflow-x: auto; overscroll-behavior-x: contain; scroll-snap-type: x proximity; padding: 2px 2px 6px; scrollbar-width: none; }
.chip-row::-webkit-scrollbar { display: none; }
.picker.grid .chip-row { flex-wrap: wrap; overflow: visible; }
.chip { flex: none; scroll-snap-align: center; min-height: 44px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-weight: 600; font-size: 14px; white-space: nowrap; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.sec { display: flex; flex-direction: column; gap: 8px; }
.sec-title { color: var(--accent); font-size: 16px; }
.rtext { white-space: pre-line; font-size: 16px; line-height: 1.75; overflow-wrap: anywhere; }
.rtext strong { color: var(--ink); }
.card-head-box { position: relative; background: var(--gold-soft); border: 1px solid #ECD9A3; border-radius: 14px; padding: 22px 14px 14px; margin-top: 8px; }
.card-head-box .ribbon { position: absolute; top: -11px; left: 12px; background: var(--accent); color: #fff; font-size: 12.5px; font-weight: 700; padding: 2px 12px; border-radius: 999px; }
.tri-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.meaning-title { margin-bottom: 8px; font-size: 16px; }

/* ---------- Reading ---------- */
.reading-head { display: flex; align-items: center; gap: 12px; }
.rh-mascot { flex: none; }
.rh-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.rh-q { font-weight: 700; font-size: 17px; overflow-wrap: anywhere; }
.trio { display: flex; flex-direction: column; gap: 12px; }
.trio-cols { display: grid; grid-template-columns: minmax(0, 1fr) 12px minmax(0, 1fr) 12px minmax(0, 1fr); align-items: start; }
.trio-col { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; min-width: 0; }
.trio-arrow { align-self: start; margin-top: 62px; color: var(--control); font-size: 22px; text-align: center; line-height: 1; }
.role { font-size: 12.5px; font-weight: 700; padding: 2px 10px; border-radius: 999px; white-space: nowrap; }
.role-main { background: var(--accent); color: #fff; }
.role-mutual { background: var(--soft); color: var(--ink); }
.role-changed { background: var(--jade); color: #fff; }
.trio-hex { display: block; padding: 10px; background: var(--ground); border-radius: 14px; min-width: 44px; min-height: 44px; }
.trio .el-chip { font-size: 11.5px; padding: 1px 7px; }

.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; position: relative; }
.timeline::before { content: ''; position: absolute; left: 15px; top: 14px; bottom: 14px; width: 2px; background: var(--line); }
.tl-item { display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: 10px; position: relative; }
.tl-dot { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 14px; border: 3px solid var(--card); }
.tl-card { background: #FAFBF8; border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.tl-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.rel-badge { font-size: 12.5px; font-weight: 700; padding: 2px 10px; border-radius: 999px; }
.tone-good .tl-dot { background: var(--good); } .tone-good .rel-badge { background: var(--jade-soft); color: var(--good); }
.tone-warn .tl-dot { background: var(--warn); } .tone-warn .rel-badge { background: #F4EBDA; color: var(--warn); }
.tone-bad .tl-dot { background: var(--bad); } .tone-bad .rel-badge { background: var(--accent-soft); color: var(--bad); }
.tl-card .rtext { font-size: 15px; line-height: 1.65; }
.num-row { display: flex; flex-direction: column; gap: 4px; }
.nums { display: flex; flex-wrap: wrap; gap: 6px; }
.num { min-width: 36px; text-align: center; padding: 2px 8px; border-radius: 8px; background: var(--card); border: 1px solid var(--line); font-weight: 700; font-variant-numeric: tabular-nums; }

.empty-state { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; padding: 28px 16px; }

/* ---------- 64 grid & detail ---------- */
.hex-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.hex-tile { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 4px 10px; min-height: 120px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; color: var(--ink); text-align: center; }
.hex-tile:active { transform: scale(.97); }
.hex-tile .tile-no { position: absolute; top: 5px; left: 7px; font-size: 11px; font-weight: 700; color: var(--muted); }
.hex-tile .hex { margin-top: 6px; }
.hex-tile .han { font-size: 18px; line-height: 1.2; }
.hex-tile .tile-th { font-size: 12px; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.detail-hero { display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px; align-items: center; gap: 4px; }
.detail-center { display: flex; flex-direction: column; align-items: center; gap: 10px; min-width: 0; padding: 6px 0; }
.detail-center .chips { justify-content: center; }

/* ---------- History ---------- */
.hist-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.hist-item { display: flex; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding-right: 4px; }
.hist-link { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; padding: 12px; color: var(--ink); min-height: 64px; }
.hist-hex { flex: none; padding: 8px; background: var(--ground); border-radius: 12px; }
.hist-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.hist-q { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-hex-name { font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-item .del { color: var(--muted); }

/* ---------- Dialog + toast ---------- */
.dialog-backdrop { position: fixed; inset: 0; background: rgba(26, 29, 27, .45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 30; animation: fade .15s ease-out; }
.dialog { background: var(--card); border-radius: var(--r-card); border: 1px solid var(--line); width: 100%; max-width: 420px; padding: 18px; display: flex; flex-direction: column; gap: 12px; animation: rise .2s ease-out; }
.dialog-foot { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 4px; }
@keyframes fade { from { opacity: 0; } }
#toast-root { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px); z-index: 40; display: flex; flex-direction: column; gap: 8px; align-items: center; width: min(calc(100% - 32px), 440px); pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; text-align: center; animation: rise .2s ease-out; transition: opacity .3s ease; }
.toast.out { opacity: 0; }

/* ---------- Shared date blocks (date / sky / word) ---------- */
.pillar.off { opacity: .42; background: var(--card); border-style: dashed; }
.flags-box .seg-btn[aria-pressed="true"] { background: var(--gold-soft); border-color: var(--gold-deep); color: var(--ink); }
.flags-box .seg-btn[aria-pressed="true"]::before { content: '✓ '; color: var(--gold-deep); }

/* ---------- Home: sky icon ---------- */
.mi-tile { fill: var(--jade-soft); stroke: var(--jade); stroke-width: 1.4; }
.mi-tile.alt { fill: var(--gold-soft); stroke: var(--gold-deep); }
.mi-taiji { fill: #fff; }
.mi-taiji-dark { fill: var(--ink); }
.mi-taiji-ring { fill: none; stroke: var(--ink); stroke-width: 1.2; }

/* ---------- Sky chart (#/sky) ---------- */
.sky-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.sky-cell { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px; min-width: 0; min-height: 92px;
  padding: 18px 4px 8px; border-radius: 16px; border: 1.5px solid var(--line); background: var(--card); color: var(--ink); transition: transform .12s ease; }
button.sky-cell:active { transform: scale(.96); }
.sky-cell .hex.tri .ln rect { fill: currentColor; }
.sky-cell .sky-name { font-weight: 700; font-size: 14.5px; line-height: 1.2; color: var(--ink); }
.sky-dir { position: absolute; top: 5px; left: 7px; font-size: 11px; font-weight: 700; color: var(--muted); letter-spacing: .02em; }
.sky-no { position: absolute; top: 5px; right: 6px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); font-size: 12px; font-weight: 700; line-height: 18px; text-align: center; }
.el-tint-0 { background: #F3F5F7; color: var(--el-0); } .el-tint-1 { background: #F0F5FC; color: var(--el-1); }
.el-tint-2 { background: #EFF8F1; color: var(--el-2); } .el-tint-3 { background: #FDF1EF; color: var(--el-3); }
.el-tint-4 { background: #FAF4E9; color: var(--el-4); }
.sky-cell[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset, 0 3px 0 var(--accent-line); background: var(--accent-soft); }
.sky-cell[aria-pressed="true"] .sky-no { background: var(--accent); border-color: var(--accent); color: #fff; }
.sky-cell.center { border-style: dashed; background: var(--ground); padding-top: 8px; }
.sky-fb { font-size: 11.5px; font-weight: 700; color: var(--muted); }
.sky-taiji { animation: spin 18s linear infinite; }
.sky-taiji .tj-light { fill: #fff; } .sky-taiji .tj-dark { fill: var(--ink); } .sky-taiji .tj-ring { fill: none; stroke: var(--ink); stroke-width: 1.4; }
@keyframes spin { to { transform: rotate(360deg); } }
.sky-taiji { transform-box: fill-box; transform-origin: center; }
.sky-pick-note { font-weight: 600; color: var(--jade); }
.sky-sum { font-weight: 600; color: var(--ink); }

/* ---------- Word (#/word) ---------- */
.word-field { display: flex; flex-direction: column; }
.word-field-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.field-note { font-size: 13px; font-weight: 700; color: var(--jade); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.count-box { border-top: 1px dashed var(--line); padding-top: 10px; }

/* ---------- Reading: transforms + display options ---------- */
.tf-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 6px; }
.tf-btn { width: 100%; min-width: 0; padding: 0 6px; gap: 6px; font-size: 13px; border-color: var(--line); white-space: nowrap; overflow: hidden; }
.tf-dot { flex: none; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--control); background: var(--card); }
.tf-btn[aria-pressed="true"] { background: var(--jade-soft); border-color: var(--jade); color: var(--jade); }
.tf-btn[aria-pressed="true"] .tf-dot { background: var(--jade); border-color: var(--jade); box-shadow: inset 0 0 0 3px var(--jade-soft); }
.tf-note { text-align: center; }
.view-opts { gap: 8px; padding: 10px 14px; }
.opt-row { display: grid; grid-template-columns: 44px minmax(0, 1fr); align-items: center; gap: 8px; }
.opt-row .label { margin: 0; }
.hex-detail > .opt-row { padding: 0 2px; }
.en-note { background: var(--gold-soft); border: 1px solid #ECD9A3; border-radius: 10px; padding: 6px 10px; color: var(--ink); }

/* ---------- เหวินหวังกั้ว ---------- */
.ww-day { background: var(--gold-soft); border: 1px solid #ECD9A3; border-radius: 12px; padding: 8px 12px; }
.ww-block { background: #FAFBF8; border: 1px solid var(--line); border-radius: 14px; padding: 12px 10px; }
.ww-head { display: flex; flex-direction: column; gap: 6px; }
.ww-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ww-hexname { font-weight: 700; color: var(--ink); min-height: 32px; display: inline-flex; align-items: center; overflow-wrap: anywhere; }
.ww-palace { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ww-table { display: flex; flex-direction: column; gap: 4px; }
.ww-row { display: grid; grid-template-columns: 62px minmax(0, 1fr) minmax(0, 1fr) 56px 26px; align-items: center; gap: 6px; min-height: 52px; padding: 3px 4px; border-radius: 12px; }
.ww-row.ww-th { min-height: 0; padding-top: 0; padding-bottom: 0; font-size: 11.5px; font-weight: 700; color: var(--muted); }
.ww-row.ww-th > span:last-child { text-align: center; }
.ww-row:not(.ww-th) { background: var(--card); border: 1px solid var(--line); }
.ww-row.is-moving { background: var(--accent-soft); border-color: var(--accent-line); }
.ww-spirit { width: 100%; min-height: 44px; padding: 0 4px; border-radius: 12px; border: 1px solid transparent; font-weight: 700; font-size: 13.5px; line-height: 1.2; }
.ww-spirit:active { transform: scale(.96); }
.sp-0 { background: var(--jade-soft); color: var(--jade); border-color: var(--jade-line); }
.sp-1 { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }
.sp-2 { background: var(--gold-soft); color: var(--gold-deep); border-color: #ECD9A3; }
.sp-3 { background: #F4EBDA; color: var(--el-4); border-color: #E6D3B0; }
.sp-4 { background: #E8ECEF; color: var(--el-0); border-color: #CDD4DA; }
.sp-5 { background: #E3EDF9; color: var(--el-1); border-color: #C3D6EE; }
.ww-rel { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.ww-rel-main { font-weight: 700; font-size: 14px; overflow-wrap: anywhere; }
.ww-hidden { font-size: 12px; color: var(--muted); font-weight: 600; overflow-wrap: anywhere; }
.ww-branch { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.ww-br-th { font-weight: 700; font-size: 15px; }
.ww-br-an { font-size: 11.5px; opacity: .9; overflow-wrap: anywhere; }
.el-text-0 { color: var(--el-0); } .el-text-1 { color: var(--el-1); } .el-text-2 { color: var(--el-2); } .el-text-3 { color: var(--el-3); } .el-text-4 { color: var(--el-4); }
.ww-line { display: flex; align-items: center; gap: 4px; }
.ww-no { font-size: 11px; font-weight: 700; color: var(--muted); width: 8px; }
.is-moving .ww-no { color: var(--accent); }
.ww-line .hex { flex: none; }
.ww-c-role { display: flex; justify-content: center; }
.ww-role { width: 24px; height: 24px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; }
.ww-role.role-s { background: var(--accent); color: #fff; }
.ww-role.role-o { background: var(--card); color: var(--accent); border: 1.5px solid var(--accent); }
.ww-missing { overflow-wrap: anywhere; }
.ww-boxes { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.ww-box { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); color: var(--ink); min-width: 0; }
.ww-ph-row { display: flex; align-items: center; gap: 8px; min-width: 0; overflow-wrap: anywhere; }
.ww-ph-row .hex { flex: none; }

/* ---------- Bottom sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(26, 29, 27, .45); display: flex; align-items: flex-end; justify-content: center; z-index: 30; animation: fade .15s ease-out; }
.sheet { width: 100%; max-width: var(--frame-w); max-height: 78vh; max-height: 78dvh; background: var(--card); border-radius: 22px 22px 0 0; border: 1px solid var(--line); border-bottom: 0;
  padding: 8px var(--gutter-r) calc(16px + env(safe-area-inset-bottom)) var(--gutter); display: flex; flex-direction: column; gap: 6px; animation: sheet-up .22s ease-out; }
.sheet-grip { align-self: center; width: 40px; height: 4px; border-radius: 999px; background: var(--line); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sheet-body { overflow-y: auto; overscroll-behavior: contain; padding-bottom: 6px; }
.sheet-body:focus-visible { outline-offset: -3px; }
@keyframes sheet-up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Very narrow phones (≤ 360px) ---------- */
@media (max-width: 360px) {
  .hex-grid { gap: 6px; }
  .hex-tile { min-height: 112px; }
  .coins { gap: 8px; }
  .tab { font-size: 13.5px; }
  .trio-cols { grid-template-columns: minmax(0, 1fr) 8px minmax(0, 1fr) 8px minmax(0, 1fr); }
  .trio-hex { padding: 8px; }
  .sky-grid { gap: 6px; }
  .sky-cell { min-height: 88px; }
  .ww-row { grid-template-columns: 58px minmax(0, 1fr) minmax(0, 1fr) 50px 24px; gap: 4px; padding: 3px; }
  .ww-row .hex.one { width: 40px; }
  .ww-block { padding: 10px 6px; }
}

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

/* analysis extras */
.tl-intro { display: flex; flex-direction: column; gap: 6px; }
.tl-label { font-weight: 700; }
.tl-heading { font-size: 15px; }

/* ---------- Date-cast screen / mark-type picker ---------- */
.mi-moon { fill: var(--gold); stroke: var(--gold-deep); stroke-width: 1.6; stroke-linejoin: round; }
.mi-eye { fill: var(--gold-deep); }
.mi-smile { fill: none; stroke: var(--gold-deep); stroke-width: 1.6; stroke-linecap: round; }
.mi-pillar { fill: var(--accent); stroke: #7E1C14; stroke-width: 1.2; }
.mi-roof { fill: none; stroke: var(--gold-deep); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.dt-row { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 10px; }
.dt-field { min-width: 0; }
.dt-field .input { min-width: 0; appearance: none; -webkit-appearance: none; }
.dt-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.thai-date { color: var(--muted); min-width: 0; flex: 1; }
.lunar-strip { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 12px; border-radius: 14px; background: var(--gold-soft); border: 1px solid #ECD9A3; font-weight: 700; text-align: center; overflow-wrap: anywhere; }
.lunar-ic { color: var(--gold-deep); flex: none; }
.pillars { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.pillar { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 8px 2px; border: 1px solid var(--line); border-radius: 12px; background: #FAFBF8; text-align: center; min-width: 0; }
.pl-head { font-size: 12px; font-weight: 700; color: var(--muted); }
.pl-stem, .pl-branch { font-size: 17px; font-weight: 700; line-height: 1.3; overflow-wrap: anywhere; }
.pl-branch { border-top: 1px dashed var(--line); padding-top: 2px; width: 82%; }
.pl-animal { font-size: 12px; color: var(--muted); }
.calc-line { color: var(--ink); overflow-wrap: anywhere; }
.mt-box { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-card); padding: 4px 14px; min-width: 0; }
.mt-box.open { padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.mt-sum { min-height: 48px; display: flex; flex-direction: column; justify-content: center; cursor: pointer; padding: 6px 0; }
.mt-cur { font-weight: 600; font-size: 14px; overflow-wrap: anywhere; }
.mt-body { display: flex; flex-direction: column; gap: 6px; padding: 4px 0 10px; }
.mt-list { display: flex; flex-direction: column; gap: 6px; }
.mt-opt { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
.mt-opt:has(input:checked) { border-color: var(--jade); background: var(--jade-soft); }
.mt-opt input { width: 22px; height: 22px; flex: none; accent-color: var(--jade); margin: 0; }
.mt-title { font-size: 14.5px; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.mt-box.locked .mt-list { opacity: .5; }
