// ============ 玄境 content data ============
// language context (React is loaded before this file)
window.LangContext = React.createContext('cn');
window.useLang = () => React.useContext(window.LangContext);
// pick(lang, cn, en)
window.L = (lang, cn, en) => (lang === 'en' ? en : cn);

// 调后端：POST JSON，出错抛异常（调用方负责兜底，保证后端未就绪时体验不崩）
window.api = async (path, body) => {
  const res = await fetch(path, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) });
  const data = await res.json().catch(() => ({}));
  if (!res.ok || data.ok === false) throw new Error(data.error || 'request failed');
  return data;
};

// 双币显示：价格以 USD 为准，¥ 为约算（汇率写死，定期可调）
window.CNY_RATE = 7.2;
window.cny = (usd) => '¥' + Math.round(usd * window.CNY_RATE).toLocaleString('en-US');
window.usd = (usd) => '$' + Number(usd).toLocaleString('en-US');

// 微信号：把数字 0 标红加粗 + 等宽字体，与字母 o 一眼区分（复制出来仍是 Akw0od）
function WeChatId({ style } = {}) {
  return (
    <span style={{ fontFamily: 'Consolas, "Courier New", monospace', letterSpacing: '.06em', whiteSpace: 'nowrap', ...style }}>
      Akw<span style={{ color: '#E0533C', fontWeight: 800 }}>0</span>od
    </span>
  );
}
window.WeChatId = WeChatId;

const NAV = [
  { en: 'Gateway', cn: '玄門', href: '#gateway' },
  { en: 'Arts', cn: '數術', href: '#arts' },
  { en: 'Talismans', cn: '符籙', href: '#talisman' },
  { en: 'Master', cn: '道長', href: '#master' },
  { en: 'Karma', cn: '香火', href: '#karma' },
];

// 玄门数术 — four discipline cards
const ARTS = [
  { icon: 'star',    href: '#booking', title: '大六壬神課', titleEn: 'Da Liu Ren Divination',
    desc: '三式之首，月將加時起課。布天地盤、四課三傳，問事斷應，精準入微。',
    descEn: 'Foremost of the Three Cosmic Boards. Casts heaven-and-earth plates, four lessons and three transmissions — judging any matter with precise timing.',
    price: 'PDF $99 起 · 全盤 $199', priceEn: 'PDF from $99 · Full $199' },
  { icon: 'sun',     href: '#booking', title: '子平八字批命', titleEn: 'Ziping BaZi Reading',
    desc: '排布四柱神煞，推演大運流年。可出 PDF 命書，亦可全盤語音詳解。',
    descEn: 'Lay out the Four Pillars and trace the great cycles. Delivered as a PDF life-book or a full voice reading.',
    price: 'PDF $99 起 · 全盤 $188', priceEn: 'PDF from $99 · Full $188' },
  { icon: 'compass', href: '#appt',    title: '堪輿風水化煞', titleEn: 'Feng Shui & Geomancy',
    desc: '陽宅陰宅，尋龍點穴，化解形煞。視情況而定，需現場勘驗者請預約。',
    descEn: 'Yang and yin dwellings — trace the dragon, dissolve malign forms. Priced by case; on-site surveys by appointment.',
    price: '潤金面議 · 預約', priceEn: 'On request · by appointment' },
  { icon: 'talisman', href: '#talisman', title: '靈符符籙', titleEn: 'Talismans & Charms',
    desc: '親手繪製開光靈符，求財、姻緣、平安、事業，皆可依願定製。',
    descEn: 'Hand-drawn, consecrated talismans — wealth, love, protection, career — each made to your wish.',
    price: '依願定製 · 咨詢', priceEn: 'Made to wish · enquire' },
];

// 订阅服务 — three bookable products
const PRODUCTS = [
  {
    id: 'liuren',
    art: 'luopan',
    title: '大六壬全盤斷事', titleEn: 'Da Liu Ren · Full Reading',
    tag: '尋人找物 · 求職斷運 · 吉凶成敗……', tagEn: 'Lost people & things · career · the outcome of any matter…',
    priceText: '$99 – $199',
    options: [
      { label: '大六壬命書 · PDF 詳批　$99 起 · ¥713 起', labelEn: 'Da Liu Ren report · PDF · from $99', price: 99 },
      { label: '大六壬全盤 · 一事精斷 · 語音講解　$199 · ¥1,433', labelEn: 'Full chart · one matter · voice reading · $199', price: 199 },
    ],
    body: [
      { lead: '', leadEn: '', text: '大六壬與奇門、太乙並稱「三式」，居三式之首，是中國古代最高層次的預測學之一。',
        textEn: 'Da Liu Ren stands at the head of the “Three Cosmic Boards” (with Qimen and Taiyi) — among the very highest forms of prediction in Chinese antiquity.' },
      { lead: '', leadEn: '', text: '以月將加時起課，布天地盤、四課三傳，判斷人事吉凶與成敗應期，事無不占。',
        textEn: 'From the lunar general placed upon the hour it casts the chart — heaven and earth plates, four lessons and three transmissions — to judge fortune, success, and exact timing. No matter lies beyond it.' },
      { lead: '問事斷應', leadEn: 'Any Matter', text: '尋人尋物、官司求職、疾病財運，一事一斷，應期精準。',
        textEn: 'Lost people and objects, lawsuits, career, illness, wealth — one matter per reading, with precise timing.' },
      { lead: '交付方式', leadEn: 'Delivery', text: '可出 PDF 命書詳批，或加語音全盤講解；複雜事項由道長親為推演。',
        textEn: 'Delivered as a PDF report, or with a full voice explanation; complex matters divined by the Master in person.' },
    ],
  },
  {
    id: 'bazi',
    art: 'wuxing',
    title: '子平八字批命', titleEn: 'Ziping BaZi · Life Reading',
    tag: '事業財運 · 姻緣子嗣 · 一生格局……', tagEn: 'Career & wealth · marriage & children · life structure…',
    priceText: '$99 – $188',
    options: [
      { label: '八字命書 · PDF 詳批　$99 起 · ¥713 起', labelEn: 'BaZi life-book · PDF report · from $99', price: 99 },
      { label: '八字全盤 · 語音講解　$188 · ¥1,354', labelEn: 'Full chart · voice reading · $188', price: 188 },
    ],
    body: [
      { lead: '', leadEn: '', text: '子平八字（又稱四柱命理）以唐代大師李虛中為奠基，由宋代徐子平系統化完善。若說奇門遁甲是「排兵布陣」的戰場地圖，子平八字便是你與生俱來的「人生劇本」。',
        textEn: 'Ziping BaZi (the Four Pillars of Destiny) was founded by the Tang master Li Xuzhong and systematised by the Song scholar Xu Ziping. If Qimen Dunjia is a battlefield map of formations, BaZi is the life-script you are born with.' },
      { lead: '', leadEn: '', text: '以出生之年、月、日、時排成四柱八字，透過陰陽五行之生克制化，洞見一生格局。',
        textEn: 'From the year, month, day, and hour of birth we cast the four pillars, and through the generating and controlling cycles of yin-yang and the five elements we read the shape of a whole life.' },
      { lead: '事業財官', leadEn: 'Career & Status', text: '官星、財星定品階高低，論求謀進取之道。',
        textEn: 'The officer and wealth stars set your rank and reveal the path of ambition.' },
      { lead: '婚姻情感', leadEn: 'Marriage & Love', text: '夫妻宮與配偶星，看姻緣早晚、相處厚薄。',
        textEn: 'The spouse palace and partner star show when love comes and how warm it stays.' },
      { lead: '健康根基', leadEn: 'Health & Roots', text: '五行旺衰失衡之處，即身心需調養之所。',
        textEn: 'Where the five elements fall out of balance is where body and mind need care.' },
      { lead: '大運流年', leadEn: 'Cycles & Years', text: '十年一運，順勢而為。知進退，明取舍。',
        textEn: 'Fortune turns every ten years; move with it. Know when to advance and when to yield.' },
    ],
  },
];

// 符籙 — 按願定製的靈符（面議 / 咨詢，不入購物車）
const TALISMANS = [
  { name: '招財進寶符', nameEn: 'Wealth & Fortune', glyph: '財',
    desc: '催旺正財偏財，廣納四方財氣。宜經商、求職、投資謀利者。',
    descEn: 'Stirs both steady and windfall wealth, drawing fortune from all directions — for business, career, and investment.' },
  { name: '姻緣和合符', nameEn: 'Love & Union', glyph: '緣',
    desc: '牽繫良緣、和合情感，化解口角隔閡。宜求偶、復合、固寵。',
    descEn: 'Binds good affinity and harmony, dissolving quarrels — for finding love, reconciliation, and keeping devotion.' },
  { name: '平安護身符', nameEn: 'Peace & Protection', glyph: '安',
    desc: '護佑出入平安、驅邪避煞。宜遠行、體弱、運勢低迷者。',
    descEn: 'Guards your comings and goings and wards off the malign — for travel, frailty, and low fortune.' },
  { name: '事業文昌符', nameEn: 'Career & Wisdom', glyph: '昌',
    desc: '開智慧、旺文昌，助考試升遷、文書順遂、貴人相扶。',
    descEn: 'Opens wisdom and the Wenchang star — for exams, promotion, smooth paperwork, and benefactors.' },
];

// 本命流年 — 12 earthly branches + zodiac, each with a short reading
const BRANCHES = [
  { zhi:'子', animal:'鼠', animalEn:'Rat',     el:'水', read:'子水居北，智圓行方。今歲財帛暗動，宜守正謀遠，水到渠成。',
    readEn:'Zi Water sits in the north — wise and principled. This year wealth stirs quietly; hold to what is right and plan far, and success will flow of its own accord.' },
  { zhi:'丑', animal:'牛', animalEn:'Ox',      el:'土', read:'丑土厚載，沉穩納福。流年貴人在側，勤耕不輟，倉廩自盈。',
    readEn:'Chou Earth carries much, steady and blessed. A benefactor stands beside you this year; keep tilling without pause and the granary fills itself.' },
  { zhi:'寅', animal:'虎', animalEn:'Tiger',   el:'木', read:'寅木初生，銳氣方剛。本命之年宜借勢而起，然戒驕躁，方得善終。',
    readEn:'Yin Wood newly sprung, keen and bold. In your zodiac year, rise on the momentum — but guard against pride and haste to end well.' },
  { zhi:'卯', animal:'兔', animalEn:'Rabbit',  el:'木', read:'卯木向榮，柔中見韌。人緣和合，情誼可期，唯需明辨真偽。',
    readEn:'Mao Wood toward flourishing, supple yet tough. Harmony with others and warm friendships await — only learn to tell the true from the false.' },
  { zhi:'辰', animal:'龍', animalEn:'Dragon',  el:'土', read:'辰為天羅，藏龍納雲。今歲格局開闊，宜謀大事，亦防樹大招風。',
    readEn:'Chen is the heaven-net, hiding dragons and gathering clouds. The year opens wide for great undertakings — but a tall tree catches the wind.' },
  { zhi:'巳', animal:'蛇', animalEn:'Snake',   el:'火', read:'巳火內明，謀定後動。智慧加身，暗處生機，靜待其時而發。',
    readEn:'Si Fire bright within, acting only after planning. Wisdom is upon you and opportunity hides in shadow; wait quietly for its hour.' },
  { zhi:'午', animal:'馬', animalEn:'Horse',   el:'火', read:'午火當旺，本命太歲。歲在丙午，火上加火，宜化烈為光，廣結善緣。',
    readEn:'Wu Fire at its peak — your year of the reigning sign. In a Bing-Wu year, fire piles on fire: turn the blaze into light and forge many good bonds.' },
  { zhi:'未', animal:'羊', animalEn:'Goat',    el:'土', read:'未土含香，溫潤生財。藝業精進有成，家宅和睦，福祿綿長。',
    readEn:'Wei Earth holds fragrance, warm and wealth-bearing. Skill and craft advance, the home is harmonious, and blessings run long.' },
  { zhi:'申', animal:'猴', animalEn:'Monkey',  el:'金', read:'申金善變，機巧通達。流年動中求財，遠行有利，慎防口舌是非。',
    readEn:'Shen Metal ever-shifting, clever and adept. Seek wealth in motion this year; travel favours you — but beware quarrels and gossip.' },
  { zhi:'酉', animal:'雞', animalEn:'Rooster', el:'金', read:'酉金至銳，鋒芒內斂。今歲名聲漸顯，宜守信重諾，金石可鏤。',
    readEn:'You Metal at its sharpest, its edge kept within. Your name rises this year; keep faith and your word, and even stone can be carved.' },
  { zhi:'戌', animal:'狗', animalEn:'Dog',     el:'土', read:'戌為地網，忠義守成。家業根基穩固，宜謹守本分，積德培元。',
    readEn:'Xu is the earth-net, loyal and steadfast. The family foundation is firm; keep to your duty, do good, and nourish your roots.' },
  { zhi:'亥', animal:'豬', animalEn:'Pig',     el:'水', read:'亥水歸藏，厚積薄發。今歲宜韜光養晦，靜水流深，來歲必有大成。',
    readEn:'Hai Water returns to storage, gathering deep before it gives. This year, keep your light veiled — still waters run deep — and next year brings great reward.' },
];

// 今日玄机 — drawn hexagram results
const HEXAGRAMS = [
  { name:'乾', nameEn:'Qián · The Creative', gua:'䷀', judge:'元亨利貞', judgeEn:'Supreme success through perseverance',
    line:'天行健，君子以自強不息。', lineEn:'Heaven moves with strength; the noble one never ceases to strengthen himself.',
    text:'群龍無首，吉。今日諸事順遂，宜進取，然不可逞強居首，謙退乃得長久。',
    textEn:'A flight of dragons without a leader — fortune. Today all goes smoothly; press forward — yet do not force your way to the front. Humility and yielding bring lasting good.' },
  { name:'坤', nameEn:'Kūn · The Receptive', gua:'䷁', judge:'厚德載物', judgeEn:'Great virtue that carries all things',
    line:'地勢坤，君子以厚德載物。', lineEn:'The earth’s condition is receptive; the noble one carries the world with ample virtue.',
    text:'直方大，不習無不利。今日宜守不宜攻，包容承載，靜待時機自然成。',
    textEn:'Straight, square, and great — without effort, nothing fails to benefit. Today hold rather than attack; embrace and bear with patience, and the moment will ripen on its own.' },
  { name:'屯', nameEn:'Zhūn · Difficulty at the Beginning', gua:'䷂', judge:'剛柔始交', judgeEn:'The first meeting of the firm and yielding',
    line:'雲雷屯，君子以經綸。', lineEn:'Clouds and thunder: the noble one brings order out of confusion.',
    text:'萬事開頭難。今日如初春破土，雖有阻滯，守正待援，終見光明。',
    textEn:'All beginnings are hard. Today is like spring breaking through soil — though blocked, hold to what is right and await help; light will come at last.' },
  { name:'蒙', nameEn:'Méng · Youthful Folly', gua:'䷃', judge:'山下出泉', judgeEn:'A spring rising at the foot of the mountain',
    line:'山下出泉，蒙。', lineEn:'A spring wells up below the mountain: the image of youthful folly.',
    text:'童蒙求我。今日宜虛心請教，撥開迷霧。心誠則明，妄動則昧。',
    textEn:'The young seek the teacher. Today, ask with an open mind and the fog will lift. A sincere heart sees clearly; rash action only blinds.' },
  { name:'需', nameEn:'Xū · Waiting', gua:'䷄', judge:'雲上于天', judgeEn:'Clouds rise to the heavens',
    line:'雲上于天，需。', lineEn:'Clouds rise into the sky: the image of waiting.',
    text:'有孚，光亨。今日宜耐心等待，飲食宴樂以養其志，急則生變。',
    textEn:'With sincerity, there is radiant success. Today, wait with patience; nourish your spirit with food and ease — haste only breeds trouble.' },
  { name:'晉', nameEn:'Jìn · Progress', gua:'䷢', judge:'明出地上', judgeEn:'Brightness rising over the earth',
    line:'明出地上，晉。', lineEn:'The sun emerges over the earth: the image of progress.',
    text:'康侯用錫馬蕃庶。今日如旭日東升，前程漸明，宜順勢而上，光明在前。',
    textEn:'The capable lord is granted horses in abundance. Today is like the rising sun — the road ahead grows bright; ride the momentum upward, for light lies before you.' },
  { name:'井', nameEn:'Jǐng · The Well', gua:'䷯', judge:'木上有水', judgeEn:'Water above wood',
    line:'木上有水，井。', lineEn:'Water over wood: the image of the well.',
    text:'改邑不改井。今日宜修養德行、滋養他人，源遠則流長，靜守得福。',
    textEn:'Towns may change, but the well does not. Today, cultivate virtue and nourish others; a deep source flows far. Quiet steadfastness brings blessing.' },
  { name:'兌', nameEn:'Duì · The Joyous', gua:'䷹', judge:'麗澤兌', judgeEn:'Joined lakes, the image of joy',
    line:'麗澤兌，君子以朋友講習。', lineEn:'Lakes resting together: the noble one joins with friends to learn.',
    text:'兌，亨，利貞。今日和悅可親，宜溝通交友，喜慶將至，言而有信。',
    textEn:'Joy — success through perseverance. Today you are warm and approachable; reach out and make friends. Celebration draws near; keep your word.' },
  { name:'訟', nameEn:'Sòng · Conflict', gua:'䷅', judge:'天水違行', judgeEn:'Heaven and water move apart',
    line:'天與水違行，訟；君子以作事謀始。', lineEn:'Heaven and water go their separate ways: the noble one plans the start of every matter with care.',
    text:'爭未必得。今日宜退讓求和，謀事慎其始，防口舌官非；和解則吉，強爭招凶。',
    textEn:'A quarrel rarely profits the victor. Today, yield and seek peace; plan carefully from the outset and beware disputes — reconciliation brings fortune, forcing the issue brings harm.' },
  { name:'師', nameEn:'Shī · The Army', gua:'䷆', judge:'地中有水', judgeEn:'Water within the earth',
    line:'地中有水，師；君子以容民畜眾。', lineEn:'Water within the earth: the noble one nourishes the people and gathers a multitude.',
    text:'師出以律。今日宜紀律嚴明、用人得當，師出有名則勝；妄動無紀則敗。',
    textEn:'An army marches by discipline. Today, keep order and place the right people well; act with just cause and you prevail — rashness without rule fails.' },
  { name:'比', nameEn:'Bǐ · Holding Together', gua:'䷇', judge:'地上有水', judgeEn:'Water over the earth',
    line:'地上有水，比；先王以建萬國，親諸侯。', lineEn:'Water over the earth: the ancient kings founded states and drew the lords close.',
    text:'比，吉。今日宜親賢結盟、團結互助，誠心相待則眾人歸附，孤立則危。',
    textEn:'Holding together — fortune. Today, ally with the worthy and unite in mutual aid; sincerity draws others to you, while isolation invites danger.' },
  { name:'小畜', nameEn:'Xiǎo Chù · Small Taming', gua:'䷈', judge:'風行天上', judgeEn:'Wind moving over heaven',
    line:'風行天上，小畜；君子以懿文德。', lineEn:'Wind moves across the heavens: the noble one refines the grace of his character.',
    text:'密雲不雨。今日小有蓄積，大事未成，宜養德待時、積小成大，不可強求。',
    textEn:'Dense clouds, yet no rain. Today brings small gains but not the great prize; cultivate virtue and bide your time — small steps build the whole.' },
  { name:'履', nameEn:'Lǚ · Treading', gua:'䷉', judge:'上天下澤', judgeEn:'Heaven above, lake below',
    line:'上天下澤，履；君子以辨上下，定民志。', lineEn:'Heaven above, the lake below: the noble one distinguishes high from low and settles the people’s will.',
    text:'履虎尾，不咥人，亨。今日如履薄冰，謹守禮分、步步小心，雖險而安。',
    textEn:'Treading on the tiger’s tail — it does not bite. Today, walk as on thin ice; keep to propriety and tread with care, and danger turns to safety.' },
  { name:'泰', nameEn:'Tài · Peace', gua:'䷊', judge:'天地交泰', judgeEn:'Heaven and earth in union',
    line:'天地交，泰；后以財成天地之道，輔相天地之宜。', lineEn:'Heaven and earth unite: the ruler completes the way of heaven and earth and aids what is fitting.',
    text:'小往大來，吉亨。今日天地交通、上下和合，諸事順遂，正是進取興業之時。',
    textEn:'The small departs, the great approaches — fortune and success. Today heaven and earth commune, high and low are in accord; all goes well — a time to advance and build.' },
  { name:'否', nameEn:'Pǐ · Standstill', gua:'䷋', judge:'天地不交', judgeEn:'Heaven and earth do not meet',
    line:'天地不交，否；君子以儉德辟難，不可榮以祿。', lineEn:'Heaven and earth do not commune: the noble one withdraws in thrift to escape trouble, not courting honour or pay.',
    text:'否之匪人。今日上下隔閉、時運不通，宜守正韜晦、儉以避禍，靜待否極泰來。',
    textEn:'Standstill, set by the unworthy. Today the ways are blocked and fortune stalled; hold to what is right, lie low and spare yourself — wait, for the worst turns to peace.' },
  { name:'同人', nameEn:'Tóng Rén · Fellowship', gua:'䷌', judge:'天與火同', judgeEn:'Heaven and fire together',
    line:'天與火，同人；君子以類族辨物。', lineEn:'Heaven and fire: the noble one sorts the clans and discerns all things.',
    text:'同人于野，亨。今日宜開誠布公、廣結同心，去私存公則大事可成。',
    textEn:'Fellowship in the open — success. Today, be open and gather kindred hearts; set aside the selfish for the common good, and great things succeed.' },
  { name:'大有', nameEn:'Dà Yǒu · Great Possession', gua:'䷍', judge:'火在天上', judgeEn:'Fire high in the heavens',
    line:'火在天上，大有；君子以遏惡揚善，順天休命。', lineEn:'Fire high in the heavens: the noble one curbs evil and furthers good, obeying heaven’s blessing.',
    text:'大有，元亨。今日豐盛富有、聲勢正旺，宜謙和守正、揚善積德，盛而不驕方久。',
    textEn:'Great possession — supreme success. Today is rich and rising; stay humble and upright, foster good and store virtue — abundance kept without pride endures.' },
  { name:'謙', nameEn:'Qiān · Modesty', gua:'䷎', judge:'地中有山', judgeEn:'A mountain within the earth',
    line:'地中有山，謙；君子以裒多益寡，稱物平施。', lineEn:'A mountain within the earth: the noble one takes from the much to add to the little, weighing things to give evenly.',
    text:'謙，亨，君子有終。今日宜謙退守柔、不矜不伐，謙德之人終得善果，諸事可成。',
    textEn:'Modesty — success; the noble one carries it through. Today, yield and stay humble, neither boasting nor vaunting; the modest soul ends well, and matters come to fruit.' },
  { name:'豫', nameEn:'Yù · Enthusiasm', gua:'䷏', judge:'雷出地奮', judgeEn:'Thunder bursts from the earth',
    line:'雷出地奮，豫；先王以作樂崇德。', lineEn:'Thunder bursts forth from the earth: the ancient kings made music to honour virtue.',
    text:'豫，利建侯行師。今日氣勢振奮、宜順勢而動、預作準備，然樂不可過、安不忘危。',
    textEn:'Enthusiasm favours appointing helpers and setting out. Today spirits rise — move with the momentum and prepare ahead; yet do not over-revel, and in ease forget not danger.' },
  { name:'隨', nameEn:'Suí · Following', gua:'䷐', judge:'澤中有雷', judgeEn:'Thunder within the lake',
    line:'澤中有雷，隨；君子以嚮晦入宴息。', lineEn:'Thunder within the lake: the noble one rests at nightfall.',
    text:'隨，元亨利貞。今日宜順時隨勢、擇善而從，與人相隨而守正，動靜得宜則無咎。',
    textEn:'Following — supreme and furthering through constancy. Today, move with the times and follow what is good; go along with others yet keep upright, and timing rightly, you err not.' },
  { name:'蠱', nameEn:'Gǔ · Work on the Decayed', gua:'䷑', judge:'山下有風', judgeEn:'Wind beneath the mountain',
    line:'山下有風，蠱；君子以振民育德。', lineEn:'Wind beneath the mountain: the noble one rouses the people and nurtures virtue.',
    text:'蠱，元亨，利涉大川。今日積弊待整，宜正本清源、革故鼎新，敢於任事則亂可治。',
    textEn:'Decay — supreme success; it furthers crossing the great stream. Today old ills await mending; clear the source and renew the worn; take the task in hand and disorder is cured.' },
  { name:'臨', nameEn:'Lín · Approach', gua:'䷒', judge:'澤上有地', judgeEn:'Earth above the lake',
    line:'澤上有地，臨；君子以教思無窮，容保民無疆。', lineEn:'Earth above the lake: the noble one teaches without end and shelters the people without limit.',
    text:'臨，元亨利貞，至于八月有凶。今日陽氣方長、機運漸臨，宜把握當下進取，然盛極須防後衰。',
    textEn:'Approach — supreme and furthering; by the eighth month, misfortune. Today the light waxes and opportunity draws near; seize the moment to advance, but at the peak guard against the decline that follows.' },
  { name:'觀', nameEn:'Guān · Contemplation', gua:'䷓', judge:'風行地上', judgeEn:'Wind moving over the earth',
    line:'風行地上，觀；先王以省方觀民設教。', lineEn:'Wind moves over the earth: the ancient kings surveyed the regions, observed the people, and set forth teaching.',
    text:'觀，盥而不薦，有孚顒若。今日宜靜觀深察、以誠示人，多看少動、明察形勢而後行。',
    textEn:'Contemplation: the ablution made, the offering not yet brought, full of trust and dignity. Today, watch and discern deeply, show sincerity; look much and act little, read the situation before you move.' },
  { name:'噬嗑', nameEn:'Shì Kè · Biting Through', gua:'䷔', judge:'雷電噬嗑', judgeEn:'Thunder and lightning',
    line:'雷電，噬嗑；先王以明罰勑法。', lineEn:'Thunder and lightning: the ancient kings made penalties clear and laws firm.',
    text:'噬嗑，亨，利用獄。今日有梗阻當決，宜剛斷除害、明辨是非，去其間隔則通達。',
    textEn:'Biting through — success; it furthers the use of justice. Today an obstacle must be broken; act decisively to remove the harm and judge right from wrong — clear the blockage and the way opens.' },
  { name:'賁', nameEn:'Bì · Grace', gua:'䷕', judge:'山下有火', judgeEn:'Fire at the foot of the mountain',
    line:'山下有火，賁；君子以明庶政，無敢折獄。', lineEn:'Fire at the foot of the mountain: the noble one brightens all affairs but dares not decide cases by show alone.',
    text:'賁，亨，小利有攸往。今日宜修飾文采、以禮成事，然華麗為表、質實為本，文質相宜方美。',
    textEn:'Grace — success; in small matters it furthers a goal. Today, adorn with refinement and accomplish through form; yet ornament is the surface and substance the root — beauty lies in their balance.' },
  { name:'剝', nameEn:'Bō · Splitting Apart', gua:'䷖', judge:'山附於地', judgeEn:'The mountain crumbling to the earth',
    line:'山附於地，剝；上以厚下安宅。', lineEn:'The mountain rests on the earth, crumbling: those above secure their base by strengthening what is below.',
    text:'剝，不利有攸往。今日陰盛陽衰、根基動搖，宜止而不進、厚培根本，靜待剝極而復。',
    textEn:'Splitting apart — it does not further any goal. Today the dark waxes and the light wanes, the foundation shaken; halt rather than advance, strengthen the roots, and wait for the turn back to growth.' },
  { name:'復', nameEn:'Fù · Return', gua:'䷗', judge:'雷在地中', judgeEn:'Thunder within the earth',
    line:'雷在地中，復；先王以至日閉關。', lineEn:'Thunder within the earth: the ancient kings closed the passes at the solstice.',
    text:'復，亨。出入無疾，反復其道，七日來復。今日一陽來復、生機初動，宜順時休養、靜中蓄力，否極泰來。',
    textEn:'Return — success. Going out and coming in without harm; the way comes round in seven days. Today the first light returns and life stirs anew; rest with the season and gather strength in stillness — the worst gives way to the good.' },
  { name:'無妄', nameEn:'Wú Wàng · Innocence', gua:'䷘', judge:'天下雷行', judgeEn:'Thunder rolling under heaven',
    line:'天下雷行，物與無妄；先王以茂對時，育萬物。', lineEn:'Thunder rolls beneath heaven, and all things attain the natural: the kings, rich in virtue and timely, nurtured all beings.',
    text:'無妄，元亨利貞。今日宜守本分、行其所當行，不存妄念、不取非分，順乎自然則吉。',
    textEn:'Innocence — supreme and furthering through constancy. Today, keep to your part and do what is right; harbour no false schemes and grasp nothing undue — follow nature and fortune is yours.' },
  { name:'大畜', nameEn:'Dà Chù · Great Taming', gua:'䷙', judge:'天在山中', judgeEn:'Heaven within the mountain',
    line:'天在山中，大畜；君子以多識前言往行，以畜其德。', lineEn:'Heaven within the mountain: the noble one studies the words and deeds of old to store up virtue.',
    text:'大畜，利貞，不家食吉，利涉大川。今日宜厚積學養、蓄勢待發，所蓄者大、所成者遠。',
    textEn:'Great taming — furthering through constancy; good fortune in not eating at home, furthering the crossing of the great stream. Today, store up learning and gather force; great is what you amass, and far what you achieve.' },
  { name:'頤', nameEn:'Yí · Nourishment', gua:'䷚', judge:'山下有雷', judgeEn:'Thunder beneath the mountain',
    line:'山下有雷，頤；君子以慎言語，節飲食。', lineEn:'Thunder beneath the mountain: the noble one is careful with words and temperate in eating.',
    text:'頤，貞吉。觀頤，自求口實。今日宜慎言節食、養身養德，所養得正則吉，貪縱則損。',
    textEn:'Nourishment — perseverance brings fortune. Watch what nourishes, and seek your own sustenance. Today, guard your words and meals, nourish body and virtue; nourish rightly and prosper, indulge and you harm yourself.' },
  { name:'大過', nameEn:'Dà Guò · Great Excess', gua:'䷛', judge:'澤滅木', judgeEn:'The lake drowning the trees',
    line:'澤滅木，大過；君子以獨立不懼，遯世無悶。', lineEn:'The lake rises over the trees: the noble one stands alone unafraid and withdraws from the world without distress.',
    text:'大過，棟橈，利有攸往，亨。今日負重過甚、棟梁將曲，宜非常之時行非常之事，當機立斷則通。',
    textEn:'Great excess — the ridgepole bends; it furthers a goal, success. Today the load is too great and the beam sags; in extraordinary times take extraordinary action — decide at the moment and you pass through.' },
  { name:'坎', nameEn:'Kǎn · The Abysmal Water', gua:'䷜', judge:'水洊至', judgeEn:'Water flowing on, ceaseless',
    line:'水洊至，習坎；君子以常德行，習教事。', lineEn:'Water flows on unceasing: the noble one keeps constant in virtue and practices the work of teaching.',
    text:'習坎，有孚，維心亨。今日重險當前，宜誠信守正、心定不亂，習險而後出險，慎之則無咎。',
    textEn:'The abysmal repeated — with sincerity, the heart wins through. Today danger lies layered before you; hold to faith and stay upright, the mind steady; learn the peril and so escape it — with care, you err not.' },
  { name:'離', nameEn:'Lí · The Clinging Fire', gua:'䷝', judge:'明兩作離', judgeEn:'Brightness rising twice',
    line:'明兩作，離；大人以繼明照于四方。', lineEn:'Brightness rises twice: the great one carries on the light to illumine the four quarters.',
    text:'離，利貞，亨。畜牝牛吉。今日光明附麗、文明在外，宜依附正道、柔順守中，明而不過則亨。',
    textEn:'The clinging — furthering through constancy, success; tending the cow brings fortune. Today brightness clings and culture shines forth; attach to the right way, be yielding and centred — bright but not excessive, and all goes well.' },
  { name:'咸', nameEn:'Xián · Influence', gua:'䷞', judge:'山上有澤', judgeEn:'A lake upon the mountain',
    line:'山上有澤，咸；君子以虛受人。', lineEn:'A lake rests on the mountain: the noble one receives others with an open heart.',
    text:'咸，亨，利貞，取女吉。今日感應相通、情意交感，宜以誠相待、虛心納人，姻緣交往皆吉。',
    textEn:'Influence — success, furthering through constancy; to wed brings fortune. Today hearts respond and feelings meet; treat others with sincerity and an open mind — for love and dealings alike, fortune.' },
  { name:'恆', nameEn:'Héng · Duration', gua:'䷟', judge:'雷風相與', judgeEn:'Thunder and wind together',
    line:'雷風，恆；君子以立不易方。', lineEn:'Thunder and wind: the noble one stands firm and does not change his course.',
    text:'恆，亨，無咎，利貞，利有攸往。今日宜持之以恆、守常不變，貴在堅持，三心二意則無成。',
    textEn:'Duration — success, no blame, furthering through constancy and a goal. Today, persevere and hold steady; worth lies in perseverance — waver between two minds and nothing comes of it.' },
  { name:'遯', nameEn:'Dùn · Retreat', gua:'䷠', judge:'天下有山', judgeEn:'A mountain beneath heaven',
    line:'天下有山，遯；君子以遠小人，不惡而嚴。', lineEn:'A mountain beneath heaven: the noble one keeps the petty at a distance, stern without rancour.',
    text:'遯，亨，小利貞。今日宜急流勇退、知幾而避，遠離是非小人，退而能守則身全。',
    textEn:'Retreat — success; in small things, constancy furthers. Today, withdraw while you can and avoid trouble before it forms; keep clear of the petty and strife — to retreat and hold is to keep yourself whole.' },
  { name:'大壯', nameEn:'Dà Zhuàng · Great Power', gua:'䷡', judge:'雷在天上', judgeEn:'Thunder high in the heavens',
    line:'雷在天上，大壯；君子以非禮弗履。', lineEn:'Thunder high in the heavens: the noble one treads no path that is not proper.',
    text:'大壯，利貞。今日氣盛力強、銳不可當，然壯而宜守正，恃強妄進則折，以禮制力方吉。',
    textEn:'Great power — furthering through constancy. Today strength is at its height, hard to resist; yet might must keep to the right — push rashly on force and you snap, but rein power with propriety and prosper.' },
  { name:'明夷', nameEn:'Míng Yí · Darkening of the Light', gua:'䷣', judge:'明入地中', judgeEn:'The light sinking into the earth',
    line:'明入地中，明夷；君子以蒞眾，用晦而明。', lineEn:'The light sinks into the earth: the noble one, leading the many, veils his brilliance yet stays clear within.',
    text:'明夷，利艱貞。今日光明受損、時局晦暗，宜韜光養晦、內明外晦，守正含章以待天明。',
    textEn:'Darkening of the light — furthering through perseverance in hardship. Today the light is wounded and the times are dim; veil your brilliance, clear within yet dark without, and hold to virtue until dawn returns.' },
  { name:'家人', nameEn:'Jiā Rén · The Family', gua:'䷤', judge:'風自火出', judgeEn:'Wind issuing from fire',
    line:'風自火出，家人；君子以言有物而行有恆。', lineEn:'Wind issues from fire: the noble one’s words have substance and his deeds endure.',
    text:'家人，利女貞。今日宜整飭家室、各正其位，言行誠實有恆，家和則諸事興。',
    textEn:'The family — furthering through the constancy of the woman. Today, set the household in order, each in their proper place; let word and deed be honest and steady — when the home is harmonious, all flourishes.' },
  { name:'睽', nameEn:'Kuí · Opposition', gua:'䷥', judge:'上火下澤', judgeEn:'Fire above, lake below',
    line:'上火下澤，睽；君子以同而異。', lineEn:'Fire above and the lake below: the noble one holds to what is common while allowing difference.',
    text:'睽，小事吉。今日意見相違、人事乖離，宜求同存異、以小事漸通，不可強合，緩圖則諧。',
    textEn:'Opposition — in small matters, fortune. Today views diverge and people pull apart; seek common ground while allowing difference, mending through small things — force no union, and patience brings accord.' },
  { name:'蹇', nameEn:'Jiǎn · Obstruction', gua:'䷦', judge:'山上有水', judgeEn:'Water upon the mountain',
    line:'山上有水，蹇；君子以反身修德。', lineEn:'Water upon the mountain: the noble one turns within and cultivates his virtue.',
    text:'蹇，利西南，不利東北。今日險阻在前、行路艱難，宜反求諸己、待援而動，見險能止方智。',
    textEn:'Obstruction — the southwest furthers, the northeast does not. Today hardship blocks the road; look first to yourself, move when help comes; to see danger and halt is wisdom.' },
  { name:'解', nameEn:'Xiè · Deliverance', gua:'䷧', judge:'雷雨作解', judgeEn:'Thunder and rain breaking forth',
    line:'雷雨作，解；君子以赦過宥罪。', lineEn:'Thunder and rain set in: the noble one pardons faults and forgives wrongs.',
    text:'解，利西南。今日險難初解、陰霾漸散，宜及時行動、寬以待人，速去舊累則生機現。',
    textEn:'Deliverance — the southwest furthers. Today the peril begins to lift and the gloom disperses; act in good time and be lenient to others — shed old burdens quickly and new life appears.' },
  { name:'損', nameEn:'Sǔn · Decrease', gua:'䷨', judge:'山下有澤', judgeEn:'A lake at the mountain’s foot',
    line:'山下有澤，損；君子以懲忿窒欲。', lineEn:'A lake at the foot of the mountain: the noble one curbs his anger and stills his desires.',
    text:'損，有孚，元吉。今日宜減損克制、去奢從簡，損己益人、損下益上，損之得宜反受益。',
    textEn:'Decrease — with sincerity, supreme fortune. Today, reduce and restrain, leave excess for simplicity; lessen the self to benefit others — decrease rightly applied returns as gain.' },
  { name:'益', nameEn:'Yì · Increase', gua:'䷩', judge:'風雷相益', judgeEn:'Wind and thunder reinforcing',
    line:'風雷，益；君子以見善則遷，有過則改。', lineEn:'Wind and thunder: the noble one, seeing good, moves toward it, and having faults, mends them.',
    text:'益，利有攸往，利涉大川。今日宜進取增益、損上益下，見善即從、有過速改，動則有功。',
    textEn:'Increase — it furthers a goal and the crossing of the great stream. Today, advance and grow, giving from above to those below; follow good at once and mend faults fast — to act now brings merit.' },
  { name:'夬', nameEn:'Guài · Breakthrough', gua:'䷪', judge:'澤上於天', judgeEn:'The lake risen above heaven',
    line:'澤上於天，夬；君子以施祿及下，居德則忌。', lineEn:'The lake has risen to heaven: the noble one dispenses reward to those below and is wary of resting on virtue.',
    text:'夬，揚于王庭。今日宜果決去惡、明斷不疑，然剛決之中須存戒懼，光明正大則克。',
    textEn:'Breakthrough — proclaimed in the king’s court. Today, resolve to cut away evil and judge without doubt; yet within the firm decision keep watchful caution — act openly and aright, and you triumph.' },
  { name:'姤', nameEn:'Gòu · Coming to Meet', gua:'䷫', judge:'天下有風', judgeEn:'Wind beneath heaven',
    line:'天下有風，姤；后以施命誥四方。', lineEn:'Wind beneath heaven: the ruler issues commands to the four quarters.',
    text:'姤，女壯，勿用取女。今日不期而遇、陰生于下，宜防微杜漸、警惕小人乘隙，慎交而後安。',
    textEn:'Coming to meet — the woman is bold; do not wed her. Today an unsought encounter, the dark arising below; check it while small and beware the petty slipping in — choose company with care and rest easy.' },
  { name:'萃', nameEn:'Cuì · Gathering Together', gua:'䷬', judge:'澤上於地', judgeEn:'The lake risen over the earth',
    line:'澤上於地，萃；君子以除戎器，戒不虞。', lineEn:'The lake has risen over the earth: the noble one keeps his weapons in repair against the unforeseen.',
    text:'萃，亨。王假有廟，利見大人。今日人聚財聚、群賢畢至，宜順勢相聚、誠以待人，並防聚而生亂。',
    textEn:'Gathering together — success; the king approaches his temple, it furthers seeing the great one. Today people and resources converge, the worthy assemble; gather with the current and meet others sincerely — but guard against the disorder a crowd can breed.' },
  { name:'升', nameEn:'Shēng · Pushing Upward', gua:'䷭', judge:'地中生木', judgeEn:'Wood growing within the earth',
    line:'地中生木，升；君子以順德，積小以高大。', lineEn:'Wood grows within the earth: the noble one, following virtue, heaps up the small to reach the great.',
    text:'升，元亨。用見大人，勿恤，南征吉。今日宜循序漸進、積累而升，順勢求進、得貴人助則步步高。',
    textEn:'Pushing upward — supreme success; seek the great one, do not worry, the southern march brings fortune. Today, rise step by step through steady gain; advance with the current, and with a benefactor’s aid you climb ever higher.' },
  { name:'困', nameEn:'Kùn · Oppression', gua:'䷮', judge:'澤無水困', judgeEn:'A lake gone dry',
    line:'澤無水，困；君子以致命遂志。', lineEn:'A lake with no water: the noble one stakes his life to fulfil his will.',
    text:'困，亨，貞，大人吉，無咎。今日處境困窘、力有不逮，宜守正自持、安困待時，言寡而行篤則終通。',
    textEn:'Oppression — success through constancy; for the great one, fortune and no blame. Today you are hemmed in and stretched thin; hold to virtue and bear the strait, await your time — speak little and act faithfully, and at last the way opens.' },
  { name:'革', nameEn:'Gé · Revolution', gua:'䷰', judge:'澤中有火', judgeEn:'Fire within the lake',
    line:'澤中有火，革；君子以治曆明時。', lineEn:'Fire within the lake: the noble one sets the calendar in order and makes the seasons clear.',
    text:'革，已日乃孚，元亨利貞，悔亡。今日宜順時變革、除舊布新，革之得時、信而後動則悔消。',
    textEn:'Revolution — on the appointed day it wins trust; supreme, furthering, constant, regret vanishes. Today, change with the times, clear the old and set forth the new; reform at the right moment, win trust, then act — and regret melts away.' },
  { name:'鼎', nameEn:'Dǐng · The Cauldron', gua:'䷱', judge:'木上有火', judgeEn:'Fire over wood',
    line:'木上有火，鼎；君子以正位凝命。', lineEn:'Fire over wood: the noble one holds his place aright and consolidates his calling.',
    text:'鼎，元吉，亨。今日如鼎烹新、革故成新，宜安守正位、養賢納能，去舊取新則大吉。',
    textEn:'The cauldron — supreme fortune, success. Today is like the cauldron cooking anew, the old transformed; hold your place aright, foster the worthy and welcome talent — out with the old, in with the new, and great fortune follows.' },
  { name:'震', nameEn:'Zhèn · The Arousing Thunder', gua:'䷲', judge:'洊雷震動', judgeEn:'Thunder rolling upon thunder',
    line:'洊雷，震；君子以恐懼修省。', lineEn:'Thunder rolls upon thunder: the noble one, in fear and trembling, sets his life in order.',
    text:'震，亨。震來虩虩，笑言啞啞。今日震動驚惕、變起倉促，宜臨危不亂、戒慎自省，處驚而定則無喪。',
    textEn:'The arousing — success. Thunder comes with terror, then laughter and words. Today comes a startling jolt, change all at once; meet the crisis unshaken, watchful and self-searching — stay calm amid the shock and lose nothing.' },
  { name:'艮', nameEn:'Gèn · Keeping Still, Mountain', gua:'䷳', judge:'兼山艮止', judgeEn:'Mountains standing together',
    line:'兼山，艮；君子以思不出其位。', lineEn:'Mountains standing together: the noble one’s thoughts do not stray beyond his place.',
    text:'艮其背，不獲其身。今日宜知止而止、安處本位，當行則行、當止則止，動靜不失其時則無咎。',
    textEn:'Keeping the back still, no longer feeling the body. Today, know when to halt and halt, rest in your own place; move when it is time to move, stop when it is time to stop — lose not the right moment, and you err not.' },
  { name:'漸', nameEn:'Jiàn · Gradual Progress', gua:'䷴', judge:'山上有木', judgeEn:'A tree upon the mountain',
    line:'山上有木，漸；君子以居賢德善俗。', lineEn:'A tree on the mountain: the noble one dwells in worthy virtue and betters the customs.',
    text:'漸，女歸吉，利貞。今日宜循序漸進、按部就班，不可躁進，如木之生、緩而能久，正而後吉。',
    textEn:'Gradual progress — the maiden weds with fortune, furthering through constancy. Today, advance by degrees in proper order; do not rush — like a tree’s growth, slow yet lasting; be upright, and fortune follows.' },
  { name:'歸妹', nameEn:'Guī Mèi · The Marrying Maiden', gua:'䷵', judge:'澤上有雷', judgeEn:'Thunder over the lake',
    line:'澤上有雷，歸妹；君子以永終知敝。', lineEn:'Thunder over the lake: the noble one, mindful of the end, foresees what may go wrong.',
    text:'歸妹，征凶，無攸利。今日名分未正、行之欠當，宜守禮慎動、慮其終始，妄進則悔，靜守為宜。',
    textEn:'The marrying maiden — to set forth brings misfortune, nothing furthers. Today the standing is unsettled and the move ill-fitting; keep to propriety and act with care, weigh beginning and end — push rashly and regret, hold still and fare better.' },
  { name:'豐', nameEn:'Fēng · Abundance', gua:'䷶', judge:'雷電皆至', judgeEn:'Thunder and lightning arriving together',
    line:'雷電皆至，豐；君子以折獄致刑。', lineEn:'Thunder and lightning arrive together: the noble one decides cases and carries out punishment.',
    text:'豐，亨，王假之，勿憂，宜日中。今日豐盛至極、聲勢正隆，宜把握盛時、明斷果行，然盛極須防轉衰。',
    textEn:'Abundance — success; the king attains it, do not grieve, be like the sun at noon. Today fullness is at its height and momentum strong; seize the prime, judge clearly and act; yet at the zenith guard against the turn to decline.' },
  { name:'旅', nameEn:'Lǚ · The Wanderer', gua:'䷷', judge:'山上有火', judgeEn:'Fire upon the mountain',
    line:'山上有火，旅；君子以明慎用刑，而不留獄。', lineEn:'Fire on the mountain: the noble one is clear and careful in punishment and lets no case linger.',
    text:'旅，小亨，旅貞吉。今日如客在途、根基未穩，宜謙和謹慎、柔順處下，安分守己則小有所成。',
    textEn:'The wanderer — small success; for the traveller, constancy brings fortune. Today you are like a guest on the road, your footing unsure; be humble and careful, yielding and low — keep to your part and small gains come.' },
  { name:'巽', nameEn:'Xùn · The Gentle Wind', gua:'䷸', judge:'隨風相巽', judgeEn:'Wind following upon wind',
    line:'隨風，巽；君子以申命行事。', lineEn:'Wind follows upon wind: the noble one repeats his orders and carries out his affairs.',
    text:'巽，小亨，利有攸往，利見大人。今日宜謙遜順從、漸進滲透，如風之入、無孔不入，柔以濟事則通。',
    textEn:'The gentle — small success; it furthers a goal and seeing the great one. Today, be humble and complying, advancing by gentle penetration; like the wind that enters everywhere, accomplish through softness and the way opens.' },
  { name:'渙', nameEn:'Huàn · Dispersion', gua:'䷺', judge:'風行水上', judgeEn:'Wind moving over the water',
    line:'風行水上，渙；先王以享于帝立廟。', lineEn:'Wind moves over the water: the ancient kings made offering to God and raised temples.',
    text:'渙，亨。王假有廟，利涉大川。今日宜渙散疑慮、聚渙為通，化解隔閡、凝聚人心，散中求聚則濟。',
    textEn:'Dispersion — success; the king approaches his temple, it furthers crossing the great stream. Today, scatter doubts and turn dispersion to flow; dissolve estrangement and draw hearts together — seek union within the scattering, and you cross over.' },
  { name:'節', nameEn:'Jié · Limitation', gua:'䷻', judge:'澤上有水', judgeEn:'Water over the lake',
    line:'澤上有水，節；君子以制數度，議德行。', lineEn:'Water over the lake: the noble one sets measure and number, and weighs conduct and virtue.',
    text:'節，亨。苦節不可貞。今日宜有所節制、量入為出，守度則通，然節而過苦則難久，適中為佳。',
    textEn:'Limitation — success; bitter limitation cannot be made lasting. Today, hold to restraint and spend by what you take in; keep within bounds and the way is clear — but limits too harsh cannot endure, so the middle course is best.' },
  { name:'中孚', nameEn:'Zhōng Fú · Inner Truth', gua:'䷼', judge:'澤上有風', judgeEn:'Wind over the lake',
    line:'澤上有風，中孚；君子以議獄緩死。', lineEn:'Wind over the lake: the noble one deliberates cases and stays the death sentence.',
    text:'中孚，豚魚吉，利涉大川。今日宜以誠感物、信實待人，中心誠信則豚魚可動，諸事可成。',
    textEn:'Inner truth — even pigs and fishes bring fortune; it furthers crossing the great stream. Today, move others by sincerity and meet people with honest faith; with truth at the core even the dullest are stirred, and matters succeed.' },
  { name:'小過', nameEn:'Xiǎo Guò · Small Excess', gua:'䷽', judge:'山上有雷', judgeEn:'Thunder upon the mountain',
    line:'山上有雷，小過；君子以行過乎恭，喪過乎哀，用過乎儉。', lineEn:'Thunder on the mountain: the noble one is over-respectful in conduct, over-grieved in mourning, over-thrifty in spending.',
    text:'小過，亨，利貞。可小事，不可大事。今日宜小處用心、稍過於恭儉，謹小慎微則吉，圖大事則不及。',
    textEn:'Small excess — success, furthering through constancy; fit for small matters, not great ones. Today, attend to little things, leaning slightly to humility and thrift; mind the small and the careful, and fortune comes — reach for the great and you fall short.' },
  { name:'既濟', nameEn:'Jì Jì · After Completion', gua:'䷾', judge:'水在火上', judgeEn:'Water over fire',
    line:'水在火上，既濟；君子以思患而豫防之。', lineEn:'Water over fire: the noble one thinks of trouble and forearms against it.',
    text:'既濟，亨小，利貞，初吉終亂。今日事已初成、各得其位，宜守成防危、慎終如始，安不忘亂則保。',
    textEn:'After completion — success in small things, furthering through constancy; fortune at the start, disorder at the end. Today the work is just done and each is in place; hold what is gained and guard against danger, ending as carefully as you began — in safety forget not disorder, and you keep it.' },
  { name:'未濟', nameEn:'Wèi Jì · Before Completion', gua:'䷿', judge:'火在水上', judgeEn:'Fire over water',
    line:'火在水上，未濟；君子以慎辨物居方。', lineEn:'Fire over water: the noble one is careful to discern things and set each in its place.',
    text:'未濟，亨。小狐汔濟，濡其尾，無攸利。今日事猶未竟、功虧一簣，宜謹慎善始善終，臨末尤須慎，勿因急躁而前功盡棄。',
    textEn:'Before completion — success. The little fox, nearly across, wets its tail; nothing furthers. Today the task is unfinished, a hair short of done; be careful to finish as well as you began — near the end most of all take care, lest haste undo all your effort.' },
];

// 缘主香火 — testimonials
const TESTI = [
  { quote:'本命年事業受阻，幸得道長點撥，以奇門運籌方位，輔以靈符化煞。如今雲開月明，已升任主管，無量壽福！',
    quoteEn:'In my zodiac year my career stalled. Thank heaven for the Master’s guidance — he set the Qimen directions and added a talisman to dispel the harm. Now the clouds have parted and the moon shines; I’ve been promoted to manager. Boundless blessings!',
    name:'林信女', nameEn:'Devotee Lin', tag:'奇門化解', tagEn:'Qimen Resolution' },
  { quote:'宅邸一直不安寧，道長親臨堪輿，點出白虎探頭之局。布下風水陣法後，家宅安寧，財氣也逐漸匯聚。',
    quoteEn:'My home was never at peace. The Master came in person to survey it and pointed out a “White Tiger peering in” formation. After he arrayed the feng shui, the household grew calm and wealth began to gather.',
    name:'張善信', nameEn:'Believer Zhang', tag:'陽宅勘驗', tagEn:'Home Survey' },
  { quote:'聽道長批解八字，猶如醍醐灌頂。過去的坎坷全數印證，對未來的指引也讓我豁然開朗，不再執迷。',
    quoteEn:'Hearing the Master read my BaZi was like cool wisdom poured over my head. Every past hardship was confirmed, and his guidance for the future cleared my mind — I cling to my delusions no more.',
    name:'王居士', nameEn:'Layman Wang', tag:'八字詳批', tagEn:'Full BaZi Reading' },
];

window.DATA = { NAV, ARTS, PRODUCTS, BRANCHES, HEXAGRAMS, TESTI, TALISMANS };

// ============ 八字排盘引擎 ============
const GAN = ['甲','乙','丙','丁','戊','己','庚','辛','壬','癸'];
const ZHI = ['子','丑','寅','卯','辰','巳','午','未','申','酉','戌','亥'];
const GAN_EL = ['木','木','火','火','土','土','金','金','水','水'];
const ZHI_EL = ['水','土','木','木','土','火','火','土','金','金','土','水'];
const EL_COLOR = { 木:'#4E7B3A', 火:'#B23B22', 土:'#A8772A', 金:'#9C8A52', 水:'#2E5670' };
const EL_EN = { 木:'Wood', 火:'Fire', 土:'Earth', 金:'Metal', 水:'Water' };
const ZHI_ANIMAL = ['鼠','牛','虎','兔','龍','蛇','馬','羊','猴','雞','狗','豬'];
const ZHI_ANIMAL_EN = ['Rat','Ox','Tiger','Rabbit','Dragon','Snake','Horse','Goat','Monkey','Rooster','Dog','Pig'];
const MONTH_ZHI = { 1:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7, 8:8, 9:9, 10:10, 11:11, 12:0 }; // Greg month → 地支 index (丑寅卯…子), 节气略

function jdn(y, m, d) {
  const a = Math.floor((14 - m) / 12);
  const yy = y + 4800 - a;
  const mm = m + 12 * a - 3;
  return d + Math.floor((153 * mm + 2) / 5) + 365 * yy + Math.floor(yy / 4) - Math.floor(yy / 100) + Math.floor(yy / 400) - 32045;
}

function computeBazi(date) {
  const y = date.getFullYear(), mo = date.getMonth() + 1, d = date.getDate(), h = date.getHours();
  // 年柱 (立春边界从简，用公历年)
  const yGan = ((y - 4) % 10 + 10) % 10, yZhi = ((y - 4) % 12 + 12) % 12;
  // 月柱
  const mZhi = MONTH_ZHI[mo];
  const mOrder = ((mZhi - 2) % 12 + 12) % 12 + 1; // 寅=1
  const mGan = (((yGan % 5) * 2 + 2) + (mOrder - 1)) % 10;
  // 日柱 (JDN 锚定 2000-01-07 = 甲子)
  const J = jdn(y, mo, d);
  const dayIdx = ((J + 49) % 60 + 60) % 60;
  const dGan = dayIdx % 10, dZhi = dayIdx % 12;
  // 时柱
  const hZhi = Math.floor(((h + 1) % 24) / 2) % 12;
  const hGan = ((dGan % 5) * 2 + hZhi) % 10;

  const pillars = [
    { label: '年柱', labelEn: 'Year', sub: '祖业 · 根', subEn: 'Ancestry · Root', gan: yGan, zhi: yZhi },
    { label: '月柱', labelEn: 'Month', sub: '父母 · 苗', subEn: 'Parents · Sprout', gan: mGan, zhi: mZhi },
    { label: '日柱', labelEn: 'Day', sub: '自身 · 花', subEn: 'Self · Flower', gan: dGan, zhi: dZhi },
    { label: '時柱', labelEn: 'Hour', sub: '子嗣 · 果', subEn: 'Offspring · Fruit', gan: hGan, zhi: hZhi },
  ].map(p => ({
    ...p, ganChar: GAN[p.gan], zhiChar: ZHI[p.zhi],
    ganEl: GAN_EL[p.gan], zhiEl: ZHI_EL[p.zhi], animal: ZHI_ANIMAL[p.zhi], animalEn: ZHI_ANIMAL_EN[p.zhi],
  }));

  const count = { 木:0, 火:0, 土:0, 金:0, 水:0 };
  pillars.forEach(p => { count[p.ganEl]++; count[p.zhiEl]++; });

  const dayMaster = GAN[dGan];
  const dmEl = GAN_EL[dGan];
  const entries = Object.entries(count);
  const strong = entries.reduce((a, b) => b[1] > a[1] ? b : a);
  const weak = entries.reduce((a, b) => b[1] < a[1] ? b : a);
  const missing = entries.filter(e => e[1] === 0).map(e => e[0]);

  const verdict =
    `日主${dayMaster}（${dmEl}），生于${pillars[1].zhiChar}月。` +
    `命局${strong[0]}气最旺，${missing.length ? '独缺' + missing.join('、') + '，' : weak[0] + '气偏弱，'}` +
    `宜以${strong[0]}为用、补${missing.length ? missing[0] : weak[0]}为佐。顺其性而调之，则中和有福。`;

  const verdictEn =
    `Day Master ${dayMaster} (${EL_EN[dmEl]}), born in the ${pillars[1].zhiChar} month. ` +
    `${EL_EN[strong[0]]} is the strongest force in the chart, while ` +
    `${missing.length ? EL_EN[missing[0]] + (missing.length > 1 ? ' and ' + missing.slice(1).map(m => EL_EN[m]).join(' and ') : '') + ' is absent' : EL_EN[weak[0]] + ' runs weak'}. ` +
    `Favour ${EL_EN[strong[0]]} as the useful element and supplement ${EL_EN[missing.length ? missing[0] : weak[0]]} to support it. ` +
    `Tune your nature to its grain, and balance will bring blessing.`;

  return { pillars, count, dayMaster, dmEl, verdict, verdictEn, elColor: EL_COLOR, elEn: EL_EN };
}

window.BAZI = { computeBazi, EL_COLOR, EL_EN };
