:root {
  --bg: #fdf6f9;
  --bg2: #f3ecfb;
  --card: #ffffff;
  --ink: #3b2b45;
  --muted: #8a7a94;
  --line: #eadff0;
  --accent: #d9568d;
  --accent2: #8b62d9;
  --soft: #fbe6ef;
  --soft2: #efe6fb;
  --good: #2f9e6a;
  --bad: #d2493f;
  --shadow: 0 6px 24px rgba(120, 70, 140, .10);
  --radius: 20px;
  --fh: "Mali";
  --on-accent: #fff;
  /* สีตัวอักษรตามธาตุ (ไม้ ไฟ ดิน ทอง น้ำ) · โหมดสว่างใช้โทนเข้มให้อ่านออก · ดาว = --gold */
  --el0: #2c7a43; --el1: #c2412d; --el2: #93622a; --el3: #626b77; --el4: #2a5bbf; --gold: #a87800;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1622; --bg2: #221a2c; --card: #2a2133; --ink: #f2e9f6; --muted: #b3a3bd;
    --line: #3c3048; --accent: #f07fb0; --accent2: #b494f0; --soft: #3a2433; --soft2: #30264a;
    --good: #5cc995; --bad: #f07a70; --shadow: 0 6px 24px rgba(0, 0, 0, .35); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1c1622; --bg2: #221a2c; --card: #2a2133; --ink: #f2e9f6; --muted: #b3a3bd;
  --line: #3c3048; --accent: #f07fb0; --accent2: #b494f0; --soft: #3a2433; --soft2: #30264a;
  --good: #5cc995; --bad: #f07a70; --shadow: 0 6px 24px rgba(0, 0, 0, .35); color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; color: var(--ink);
  position: relative;
  background-color: var(--bg);
  font: 400 16px/1.65 "IBM Plex Sans Thai", system-ui, sans-serif;
}
h1, h2, h3, .brand, .big { font-family: var(--fh), "IBM Plex Sans Thai", sans-serif; line-height: 1.3; }
h1 { font-size: 1.7rem; margin: .2em 0 .3em; }
h2 { font-size: 1.3rem; margin: 0 0 .5em; }
h3 { font-size: 1.1rem; margin: 0 0 .4em; }
a { color: var(--accent); }
.wrap { max-width: 720px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.center { text-align: center; }
.row { display: flex; align-items: center; }
.gap { gap: 10px; }
.wrapflex { flex-wrap: wrap; }
.grow { flex: 1; }
.hidden { display: none !important; }

/* header */
.top {
  position: sticky; top: 0; z-index: 10; display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.top-r { display: flex; align-items: center; gap: 8px; min-width: 0; }
.theme-btn {
  flex: none; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: var(--card);
  font-size: 1.05rem; line-height: 1; cursor: pointer; display: grid; place-items: center; padding: 0;
}
.theme-btn:active { transform: scale(.92); }
.brand { font-size: 1.25rem; font-weight: 700; color: var(--ink); text-decoration: none; }
.brand-ic { display: inline-block; animation: float 3s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-3px); } }
.profile-btn {
  border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 999px;
  padding: 6px 14px; font: inherit; font-size: .9rem; cursor: pointer; max-width: 45vw;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* cards */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; margin: 16px 0; border: 1px solid var(--line);
}
.hero { text-align: center; padding: 22px 8px 6px; }
.hero p { margin: 0; }
.menu { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin: 18px 0; }
@media (min-width: 560px) { .menu { grid-template-columns: repeat(3, 1fr); } }
.tile {
  display: flex; flex-direction: column; gap: 4px; padding: 18px 14px; border-radius: var(--radius);
  text-decoration: none; color: var(--ink); background: var(--card); border: 1px solid var(--line);
  box-shadow: var(--shadow); transition: transform .15s ease;
}
.tile:hover, .tile:focus-visible { transform: translateY(-3px); }
.tile .ic { font-size: 2rem; }
.tile b { font-family: var(--fh), sans-serif; font-size: 1.05rem; }
.tile span.small { color: var(--muted); line-height: 1.4; }
.tile.t1 { background: linear-gradient(135deg, #ffe3ec, #fff); }
.tile.t2 { background: linear-gradient(135deg, #e6f0ff, #fff); }
.tile.t3 { background: linear-gradient(135deg, #fff1d9, #fff); }
.tile.t4 { background: linear-gradient(135deg, #e7f8ec, #fff); }
.tile.t5 { background: linear-gradient(135deg, #efe3ff, #fff); }
.tile.t6 { background: linear-gradient(135deg, #ffe6f6, #fff); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .tile { background: var(--card) !important; }
}

.back { display: inline-block; margin-top: 14px; text-decoration: none; font-weight: 500; }

/* forms */
label { display: block; font-weight: 500; margin: 10px 0; }
input, select {
  display: block; width: 100%; margin-top: 4px; padding: 11px 14px; font: inherit; color: var(--ink);
  background: var(--bg); border: 1.5px solid var(--line); border-radius: 14px;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }
input.phone { font-size: 1.4rem; letter-spacing: .12em; text-align: center; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.check input { width: auto; margin: 0; }
.btn {
  display: inline-block; border: 0; border-radius: 999px; padding: 12px 22px; font: inherit; font-weight: 600;
  color: var(--on-accent); background: linear-gradient(135deg, var(--accent), var(--accent2)); cursor: pointer;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 30%, transparent);
}
.btn:active { transform: scale(.97); }
.btn.block { display: block; width: 100%; margin-top: 12px; }
.btn.ghost { background: transparent; color: var(--accent); box-shadow: none; border: 1.5px solid var(--line); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.chip {
  border: 1.5px solid var(--line); background: var(--card); color: var(--ink); border-radius: 999px;
  padding: 6px 14px; font: inherit; font-size: .92rem; cursor: pointer;
}
.chip.on { border-color: var(--accent); background: var(--soft); color: var(--accent); font-weight: 600; }

/* colors */
.swatches { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 560px) { .swatches { grid-template-columns: repeat(4, 1fr); } }
.sw { border-radius: 16px; padding: 12px; border: 1px solid var(--line); background: var(--bg); }
.sw .dots { display: flex; gap: 4px; margin-bottom: 6px; }
.sw .dot { width: 30px; height: 30px; border-radius: 50%; border: 2px solid rgba(255,255,255,.7); box-shadow: 0 1px 4px rgba(0,0,0,.15); }
.sw b { display: block; font-size: .95rem; }
.sw .cname { font-family: var(--fh), sans-serif; font-size: 1.05rem; }
.sw.bad { background: color-mix(in srgb, var(--bad) 10%, var(--bg)); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.today-strip { display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; margin-top: 10px; }
.today-strip .dot { width: 22px; height: 22px; border-radius: 50%; display: inline-block; vertical-align: middle; }

/* phone */
.digits { display: flex; justify-content: center; gap: 3px; margin: 10px 0; flex-wrap: wrap; }
.digit {
  width: 26px; height: 40px; border-radius: 8px; display: grid; place-items: center;
  font-family: var(--fh), sans-serif; font-size: 1.15rem; font-weight: 700; background: var(--bg); border: 1px solid var(--line);
}
.digit.dim { opacity: .45; }
.pair { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.pair:last-child { border-bottom: 0; }
.pair .num {
  flex: none; min-width: 52px; text-align: center; font-family: var(--fh), sans-serif; font-weight: 700; font-size: 1.2rem;
  border-radius: 12px; padding: 4px 8px;
}
.lv3 { background: color-mix(in srgb, var(--good) 22%, transparent); color: var(--good); }
.lv2 { background: color-mix(in srgb, var(--good) 11%, transparent); color: var(--good); }
.lv1 { background: var(--soft2); color: var(--accent2); }
.lv0 { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); }
.stars { font-size: 1.8rem; letter-spacing: .1em; }
.big { font-size: 2.6rem; font-weight: 700; margin: 0; }

/* bazi */
.pillars { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; }
.pl { border-radius: 16px; padding: 10px 4px; background: var(--bg); border: 1px solid var(--line); }
.pl.day { border: 2px solid var(--accent); background: var(--soft); }
.pl .lab { font-size: .8rem; color: var(--muted); }
.pl .ch { font-size: 1.9rem; line-height: 1.25; font-weight: 600; }
.pl .el { font-size: .78rem; }
.bars { display: grid; gap: 8px; }
.bar { display: grid; grid-template-columns: 74px 1fr 28px; align-items: center; gap: 8px; }
.bar .track { height: 14px; border-radius: 999px; background: var(--bg); overflow: hidden; border: 1px solid var(--line); }
.bar .fill { height: 100%; border-radius: 999px; transition: width .6s ease; }
.pill { display: inline-block; border-radius: 999px; padding: 2px 10px; font-size: .85rem; background: var(--soft2); color: var(--accent2); margin: 2px 2px; }
.warn { background: color-mix(in srgb, #f5b43a 18%, var(--card)); border: 1px solid color-mix(in srgb, #f5b43a 50%, var(--line)); border-radius: 14px; padding: 10px 14px; font-size: .9rem; }

/* mbti */
.q { padding: 14px 0; border-bottom: 1px dashed var(--line); }
.q p { margin: 0 0 8px; font-weight: 500; }
.scale { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.scale .end { font-size: .75rem; color: var(--muted); width: 54px; }
.scale .end.r { text-align: right; }
.scale button {
  width: 38px; height: 38px; border-radius: 50%; border: 2px solid var(--line); background: var(--card); cursor: pointer; flex: none;
}
.scale button:nth-of-type(1), .scale button:nth-of-type(5) { width: 42px; height: 42px; }
.scale button:nth-of-type(3) { width: 30px; height: 30px; }
.scale button.on { background: var(--accent); border-color: var(--accent); }
.progress { height: 8px; background: var(--bg); border-radius: 999px; overflow: hidden; margin: 8px 0; }
.progress div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .3s; }
.sticky-prog { position: sticky; top: 56px; z-index: 5; background: var(--card); padding: 6px 0; }
.axis { margin: 10px 0; }
.axis .lbl { display: flex; justify-content: space-between; font-size: .88rem; }
.type-code { font-family: var(--fh), sans-serif; font-size: 3rem; font-weight: 700; letter-spacing: .08em; margin: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent2)); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* tarot */
.deck { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 8px; margin: 12px 0; }
.back-card {
  aspect-ratio: 2 / 3; border-radius: 10px; border: 2px solid #e9d3a3; cursor: pointer;
  background: radial-gradient(circle at 50% 50%, #f6d98a 0 12%, transparent 13%),
    repeating-linear-gradient(45deg, #5a3b8c 0 6px, #4a2f78 6px 12px);
  transition: transform .2s, opacity .2s;
}
.back-card:hover { transform: translateY(-4px); }
.back-card.picked { opacity: .15; pointer-events: none; }
.spread { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 560px) { .spread.three { grid-template-columns: repeat(3, 1fr); } }
.tcard { perspective: 800px; }
.tcard .inner { position: relative; transition: transform .7s; transform-style: preserve-3d; min-height: 180px; }
.tcard.flip .inner { transform: rotateY(180deg); }
.tcard .face, .tcard .rear {
  backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: 16px; position: absolute; inset: 0;
}
.tcard .rear { background: repeating-linear-gradient(45deg, #5a3b8c 0 8px, #4a2f78 8px 16px); border: 3px solid #e9d3a3; }
.tcard .face {
  position: relative; transform: rotateY(180deg); padding: 14px; text-align: center;
  background: linear-gradient(160deg, #fff8e8, #f6e7ff); color: #3b2b45; border: 3px solid #e9d3a3;
}
.tcard .sym { font-size: 2.6rem; display: inline-block; }
.tcard.rev .sym { transform: rotate(180deg); }
.tcard .pos { font-size: .8rem; color: #8a7a94; }
.tcard .nm { font-family: var(--fh), sans-serif; font-weight: 700; font-size: 1.1rem; }
.tcard .en { font-size: .8rem; color: #8a7a94; }
.tcard p { margin: 6px 0 0; font-size: .92rem; text-align: left; }

/* match */
.two { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 560px) { .two { grid-template-columns: 1fr 1fr; } }
.meter { position: relative; width: 170px; height: 170px; margin: 6px auto; }
.meter svg { transform: rotate(-90deg); }
.meter .val { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--fh), sans-serif; font-size: 2.4rem; font-weight: 700; }
.fact { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.fact:last-child { border-bottom: 0; }
.fact .ic { font-size: 1.35rem; flex: none; width: 40px; display: flex; flex-direction: column; align-items: center; line-height: 1.25; }
.plus { color: var(--good); font-weight: 600; }
.minus { color: var(--bad); font-weight: 600; }

/* dialog / toast / footer */
dialog { border: 0; border-radius: var(--radius); padding: 0; width: min(92vw, 400px); background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(40, 20, 50, .45); }
.dlg { padding: 20px; }
.dlg .row { justify-content: flex-end; margin-top: 14px; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 30px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; transition: .25s; z-index: 50; font-size: .92rem;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.foot { text-align: center; color: var(--muted); font-size: .82rem; padding-top: 10px; padding-bottom: max(24px, env(safe-area-inset-bottom)); }
.fade { animation: fade .35s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
body::before { content: ""; position: fixed; inset: 0; z-index: -1; background: linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%); pointer-events: none; }

/* ===== ธีมเท่ (data-style="cool") — ดำด้าน + ทอง · ฟอนต์เหลี่ยม · มุมคมขึ้น ===== */
:root[data-style="cool"] {
  --bg: #0d1015; --bg2: #141a22; --card: #19202a; --ink: #e8ecf1; --muted: #8f9aa8;
  --line: #2b3440; --accent: #e3a53c; --accent2: #c26a2c; --soft: #2a2416; --soft2: #1f2833;
  --good: #4cc38a; --bad: #ef6a5e; --shadow: 0 6px 22px rgba(0, 0, 0, .45);
  --radius: 10px; --fh: "Chakra Petch"; --on-accent: #16110a; color-scheme: dark;
}
[data-style="cool"] h1, [data-style="cool"] h2, [data-style="cool"] .brand { letter-spacing: .02em; }
:root[data-style="cool"] .tile { background: linear-gradient(135deg, var(--soft2), var(--card)) !important; border-top: 2px solid var(--accent); }
[data-style="cool"] .tile.t2, [data-style="cool"] .tile.t4, [data-style="cool"] .tile.t6 { border-top-color: var(--accent2); }
[data-style="cool"] .chip, [data-style="cool"] .btn, [data-style="cool"] .profile-btn,
[data-style="cool"] input, [data-style="cool"] select { border-radius: 8px; }
[data-style="cool"] .pill, [data-style="cool"] .lv1 { color: var(--accent); }
[data-style="cool"] dialog::backdrop { background: rgba(0, 0, 0, .6); }
[data-style="cool"] body::before {
  background:
    repeating-linear-gradient(135deg, rgba(255, 255, 255, .018) 0 2px, transparent 2px 9px),
    radial-gradient(ellipse at 50% -10%, rgba(227, 165, 60, .10), transparent 55%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%);
}
.own { display: inline-block; font-size: .72rem; font-weight: 600; line-height: 1.5; padding: 0 8px; border-radius: 999px;
  border: 1px dashed color-mix(in srgb, var(--muted) 60%, transparent); color: var(--muted); background: var(--card); vertical-align: middle; white-space: normal; max-width: 100%; }
.theme-btn.on { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
@media (max-width: 420px) { .top { padding-left: 12px; padding-right: 12px; } .brand { font-size: 1.1rem; } .top-r { gap: 6px; } .theme-btn { width: 34px; height: 34px; } }
.foot .powered { margin: 4px 0 0; font-size: .8rem; letter-spacing: .03em; }
.foot .powered b { font-family: var(--fh), sans-serif; background: linear-gradient(135deg, var(--accent), var(--accent2)); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ===== สีตัวอักษรธาตุ/ดาว บนพื้นเข้ม (หวานโหมดมืด + เท่) ===== */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --el0: #5fc27a; --el1: #f27d69; --el2: #d9a66d; --el3: #b9c1ca; --el4: #7aa7f5; --gold: #e8b53c; --on-accent: #1c1622; }
}
:root[data-theme="dark"] { --el0: #5fc27a; --el1: #f27d69; --el2: #d9a66d; --el3: #b9c1ca; --el4: #7aa7f5; --gold: #e8b53c; --on-accent: #1c1622; }
:root[data-style="cool"] { --el0: #5fc27a; --el1: #f27d69; --el2: #d9a66d; --el3: #b9c1ca; --el4: #7aa7f5; --gold: #efbe4f; --on-accent: #16110a; }
