:root {
  --bg: #0b0a14;
  --panel: #14122180;
  --line: #2a2545;
  --ink: #ece9f5;
  --dim: #9a93b8;
  --gold: #d9b45f;
  --violet: #8b7ad8;
}
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -10%, #2a1f5288, transparent),
    radial-gradient(ellipse 60% 40% at 90% 100%, #1f2a5266, transparent);
  background-attachment: fixed;
  color: var(--ink);
  font-family: "Sukhumvit Set", "Noto Sans Thai", -apple-system, system-ui, sans-serif;
  line-height: 1.75;
  min-height: 100vh;
  padding: 2rem 1.25rem 5rem;
}
.wrap { max-width: 820px; margin: 0 auto; }

header { text-align: center; padding: 2.5rem 0 1rem; }
.mark { font-size: 2rem; color: var(--gold); letter-spacing: .5em; margin-bottom: 1rem; }
h1 { font-size: clamp(1.8rem, 5vw, 2.6rem); font-weight: 600; letter-spacing: -.01em; }
.sub { color: var(--dim); margin-top: .75rem; font-size: .95rem; }

.disclaimer {
  border: 1px solid var(--line); background: var(--panel);
  border-radius: 10px; padding: 1rem 1.25rem; margin: 2rem 0;
  font-size: .88rem; color: var(--dim);
}
.disclaimer strong { color: var(--ink); font-weight: 600; }
.disclaimer em { color: var(--violet); font-style: normal; }

/* ---------- ฟอร์ม ---------- */
form {
  border: 1px solid var(--line); background: var(--panel);
  border-radius: 14px; padding: 1.75rem; margin-bottom: 2rem;
}
label { display: block; font-size: .85rem; color: var(--dim); margin-bottom: .5rem; }
.hint { color: #6f6890; }
.field { margin-bottom: 1.25rem; }

input, select {
  width: 100%; background: #0e0d1a; border: 1px solid var(--line);
  border-radius: 8px; padding: .85rem 1rem; color: var(--ink);
  font-size: 1.05rem; font-family: inherit;
}
input:focus, select:focus { outline: none; border-color: var(--violet); }

/* วัน / เดือน / ปี — ปีกว้างสุดเพราะโชว์ทั้ง พ.ศ. และ ค.ศ. */
.dob { display: grid; grid-template-columns: .8fr 1.2fr 1.4fr; gap: .6rem; }
@media (max-width: 460px) { .dob { grid-template-columns: 1fr; } }

.age { color: var(--gold); font-size: .88rem; margin-top: .6rem; min-height: 1.3em; }
.err { color: #e08a8a; font-size: .88rem; margin-bottom: .8rem; min-height: 1.2em; }

button[type=submit] {
  width: 100%; background: linear-gradient(135deg, var(--gold), #b8923f);
  color: #1a1508; border: 0; border-radius: 8px; padding: .95rem;
  font-size: 1rem; font-weight: 600; font-family: inherit; cursor: pointer;
}
button[type=submit]:hover { filter: brightness(1.08); }

/* ---------- ผลลัพธ์ ---------- */
#result { display: none; }
#result.show { display: block; animation: rise .6s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } }

.tabs {
  display: flex; gap: .4rem; margin-bottom: 1.5rem;
  overflow-x: auto; padding-bottom: .4rem;
}
.tab {
  flex: 0 0 auto; background: transparent; border: 1px solid var(--line);
  color: var(--dim); border-radius: 999px; padding: .5rem 1.1rem;
  font-size: .9rem; font-family: inherit; cursor: pointer; white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab.on { background: var(--violet); border-color: var(--violet); color: #fff; }

.card {
  border: 1px solid var(--line); background: var(--panel);
  border-radius: 14px; padding: 1.5rem 1.75rem; margin-bottom: 1.25rem;
}
.card h2 {
  font-size: .75rem; text-transform: uppercase; letter-spacing: .15em;
  color: var(--gold); font-weight: 600; margin-bottom: 1rem;
}
.headline { font-size: 1.45rem; font-weight: 600; margin-bottom: .5rem; }
.meta { color: var(--dim); font-size: .88rem; margin-bottom: 1rem; }
.body-text { color: #c9c4dd; }
.converge { border-color: #4a3d1f; background: linear-gradient(160deg, #1c1730, #14122180); }
.converge .headline { color: var(--gold); }

/* กล่องแจ้งเตือนปีชง */
.chong-alert {
  border: 1px solid var(--line); border-radius: 12px;
  padding: 1.1rem 1.35rem; margin-bottom: 1.25rem;
  border-left-width: 4px;
}
.chong-alert.warn { border-left-color: #e0a04d; background: #3a2a1288; }
.chong-alert.soft { border-left-color: var(--violet); background: #241f4088; }
.chong-alert.calm { border-left-color: #3fae6a; background: #16281f88; }
.ca-title { font-size: 1.05rem; font-weight: 600; color: var(--ink); margin-bottom: .35rem; }
.ca-body { font-size: .9rem; color: #c9c4dd; line-height: 1.7; }

/* บล็อกคำอ่านในหน้าพื้นดวง (ราศี / คนเกิดวัน...) */
.reading-block { margin-top: 1.25rem; padding-top: 1.25rem; border-top: 1px solid var(--line); }
.reading-block:first-of-type { margin-top: 1rem; }
.rb-label {
  font-size: .8rem; font-weight: 600; color: var(--gold);
  letter-spacing: .05em; margin-bottom: .5rem;
}

/* ชิปเนื้อคู่ในหน้าความรัก */
.match-chips { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .7rem; }
.chip {
  border: 1px solid var(--violet); color: #ded7f5; background: #8b7ad822;
  border-radius: 999px; padding: .35rem .95rem; font-size: .92rem; font-weight: 600;
}
.chip.warn { border-color: #b8923f; color: var(--gold); background: #d9b45f18; }
.body-text.sm { font-size: .9rem; }

/* ดูดวงคู่ */
.couple-intro { color: var(--dim); font-size: .9rem; margin-bottom: 1.5rem; }
.couple-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; margin-bottom: 1rem; }
@media (max-width: 560px) { .couple-grid { grid-template-columns: 1fr; } }
.couple-person { border: 1px solid var(--line); border-radius: 10px; padding: 1rem; background: #0e0d1a80; }
.cp-title { font-size: .8rem; font-weight: 600; color: var(--gold); margin-bottom: .7rem; }
.cp-name { margin-bottom: .6rem; }
.couple-btn {
  width: 100%; background: linear-gradient(135deg, #e87fae, #b8923f);
  color: #1a0812; border: 0; border-radius: 8px; padding: .9rem;
  font-size: 1rem; font-weight: 600; font-family: inherit; cursor: pointer; margin-top: .3rem;
}
.couple-btn:hover { filter: brightness(1.08); }

.couple-result { margin-top: 1.75rem; padding-top: 1.5rem; border-top: 1px solid var(--line); animation: rise .5s ease both; }
.cr-people { text-align: center; font-size: 1.05rem; margin-bottom: 1rem; }
.cr-people span { color: var(--dim); font-size: .85rem; }
.cr-score { text-align: center; font-size: 3rem; font-weight: 700; line-height: 1; }
.cr-score span { font-size: 1.2rem; font-weight: 600; }
.cr-meter { height: 10px; background: #0e0d1a; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; margin: .9rem 0; }
.cr-fill { height: 100%; border-radius: 999px; transition: width .8s ease; }
.cr-band { text-align: center; font-size: 1.05rem; font-weight: 600; margin-bottom: .5rem; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }

/* จุดสีมงคล */
.v-colors { display: flex; flex-wrap: wrap; gap: .5rem .9rem; font-size: .95rem; }
.sw {
  display: inline-block; width: .85em; height: .85em; border-radius: 50%;
  background: var(--c); margin-right: .35em; vertical-align: -1px;
  border: 1px solid #ffffff33; box-shadow: 0 0 0 1px #0006;
}
.sw.big { width: 1.15em; height: 1.15em; vertical-align: -3px; margin-right: .45em; }

/* เสื้อสีมงคลวันนี้ */
.today-wear {
  text-align: center; padding: 1.4rem 1rem; margin-bottom: 1.25rem;
  border: 1px solid #4a3d1f; border-radius: 12px;
  background: linear-gradient(160deg, #1c1730, #14122180);
}
.tw-head { font-size: .85rem; color: var(--dim); }
.tw-main { font-size: 1.7rem; font-weight: 600; color: var(--gold); margin: .5rem 0 .4rem; }
.tw-note { font-size: .85rem; color: var(--dim); }

/* แถบสีเสื้อ 7 วัน */
.week-strip { margin-top: 1.25rem; }
.ws-title {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .1em;
  color: var(--dim); margin-bottom: .6rem;
}
.ws-row { display: flex; gap: .45rem; }
.ws-cell {
  flex: 1; text-align: center; padding: .65rem .2rem;
  border: 1px solid var(--line); border-radius: 8px; background: #0e0d1a80;
}
.ws-cell.on { border-color: var(--gold); background: #3a2f1a55; }
.ws-cell .sw { display: block; margin: 0 auto .4rem; width: 1.1em; height: 1.1em; }
.ws-day { font-size: .8rem; color: var(--dim); }
.ws-cell.on .ws-day { color: var(--gold); font-weight: 600; }
.tile { border: 1px solid var(--line); border-radius: 10px; padding: 1.1rem; background: #0e0d1a80; }
.tile .k { font-size: .72rem; color: var(--dim); letter-spacing: .08em; text-transform: uppercase; }
.tile .v { font-size: 1.2rem; font-weight: 600; margin-top: .3rem; }
.tile .n { font-size: .85rem; color: var(--dim); margin-top: .4rem; line-height: 1.6; }

/* ---------- ไพ่ ---------- */
.spread-head { margin-bottom: 1.5rem; }
.spread-head h3 { font-size: 1.4rem; font-weight: 600; }
.spread-head p { color: var(--dim); font-size: .88rem; margin-top: .3rem; }

/* ===== ขั้นที่ 1: สับไพ่ ===== */
.shuffle-wrap { text-align: center; padding: 2.5rem 0 1rem; }
.pile { position: relative; width: 120px; height: 176px; margin: 0 auto 1.5rem; }
.pile-card {
  position: absolute; inset: 0;
  border: 1px solid var(--line); border-radius: 12px;
  background:
    radial-gradient(circle at 50% 50%, #241d47, #0e0d1a 70%),
    repeating-linear-gradient(45deg, #1a1630 0 6px, #14122a 6px 12px);
  display: flex; align-items: center; justify-content: center;
  color: var(--gold); font-size: 1.8rem;
  transform: translateY(calc(var(--p) * -2px));
}
.pile-card span { opacity: .5; }
.pile.shuffling .pile-card { animation: riffle .55s ease-in-out infinite; animation-delay: calc(var(--p) * .07s); }
@keyframes riffle {
  0%, 100% { transform: translate(0, calc(var(--p) * -2px)) rotate(0); }
  30%  { transform: translate(-46px, -12px) rotate(-9deg); }
  60%  { transform: translate(44px, -6px) rotate(8deg); }
}
.stage-msg { color: var(--gold); font-size: .95rem; letter-spacing: .05em; }

/* ===== ขั้นที่ 2: กางสำรับให้จิ้มเลือก ===== */
.pick-wrap { text-align: center; }
.pick-prompt { color: var(--ink); font-size: 1rem; margin-bottom: 1.75rem; line-height: 1.7; }
.pick-prompt b { color: var(--gold); }
.pick-count { color: var(--dim); font-size: .9rem; }

.fan {
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: .6rem; padding: 1rem .25rem;
}
.fan-card {
  flex: 0 0 auto; width: 58px; height: 88px;
  border: 1px solid var(--line); border-radius: 9px;
  background:
    radial-gradient(circle at 50% 40%, #2a2250, #0e0d1a 72%),
    repeating-linear-gradient(45deg, #1a1630 0 5px, #14122a 5px 10px);
  display: flex; align-items: center; justify-content: center;
  color: var(--gold); cursor: pointer;
  transform: rotate(var(--tilt));
  transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
}
.fan-mark { font-size: 1.1rem; opacity: .55; font-weight: 600; }
.fan-card:hover, .fan-card:focus-visible {
  transform: rotate(0) translateY(-10px) scale(1.06);
  border-color: var(--gold); box-shadow: 0 8px 24px #0009; outline: none;
}
.fan-card.chosen {
  border-color: var(--gold);
  background: linear-gradient(160deg, #3a2f1a, #1c1730);
  transform: rotate(0) translateY(-6px);
  cursor: default;
}
.fan-card.chosen .fan-mark { opacity: 1; color: var(--gold); }
.fan-card[aria-disabled="true"] { pointer-events: none; }
.pick-actions { margin-top: 1.75rem; }

@media (prefers-reduced-motion: reduce) {
  .pile.shuffling .pile-card { animation: none; }
  .fan-card { transition: none; }
}

/* ===== ขั้นที่ 3: อ่านผล ===== */
.reveal-head { color: var(--dim); font-size: .9rem; margin-bottom: 1.25rem; }

.tcards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; }

.tcard {
  border: 1px solid var(--line); background: var(--panel);
  border-radius: 14px; padding: 1.35rem; display: flex; flex-direction: column;
  animation: deal .5s ease both; animation-delay: calc(var(--i) * .09s);
}
@keyframes deal { from { opacity: 0; transform: translateY(14px) scale(.97); } }

.tcard-pos { margin-bottom: 1rem; }
.pos-name {
  display: block; font-size: .72rem; letter-spacing: .12em;
  text-transform: uppercase; color: var(--gold); font-weight: 600;
}
.pos-hint { display: block; font-size: .8rem; color: var(--dim); line-height: 1.5; margin-top: .2rem; }

/* ---------- การพลิกไพ่ (3D) ---------- */
.flip {
  perspective: 1000px; width: 178px; height: 300px;
  margin: 0 auto 1rem; cursor: pointer; background: none; border: 0; padding: 0;
}
.flip:focus-visible { outline: 2px solid var(--violet); outline-offset: 4px; border-radius: 10px; }

.flip-inner {
  position: relative; width: 100%; height: 100%;
  transform-style: preserve-3d;
  transition: transform .7s cubic-bezier(.4, .2, .2, 1);
}
.flip.open .flip-inner { transform: rotateY(180deg); }

.face {
  position: absolute; inset: 0;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}

/* หลังไพ่ */
.back {
  background:
    radial-gradient(circle at 50% 50%, #241d47, #0e0d1a 70%),
    repeating-linear-gradient(45deg, #1a1630 0 6px, #14122a 6px 12px);
  color: var(--gold);
}
.back-mark { font-size: 2.4rem; opacity: .55; }
.flip:hover .back { border-color: var(--gold); }

/* หน้าไพ่ — หมุนไว้ 180° รอให้ flip-inner หมุนมาเจอ */
.front { transform: rotateY(180deg); background: #0e0d1a; }
.tcard.rev .front { border-color: #4a3560; }
.card-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tcard.rev .card-img { transform: rotate(180deg); }   /* ไพ่กลับหัว = ภาพกลับหัวตามตำรา */
.glyph { font-size: 2rem; color: var(--violet); }      /* fallback ถ้าไม่มีภาพ */

.card-cap {
  text-align: center; margin-bottom: .9rem;
  opacity: 0; transition: opacity .4s ease .35s;
}
.tcard.open .card-cap { opacity: 1; }
.tcard-name { font-size: 1.1rem; font-weight: 600; }
.tcard-sub { display: block; font-size: .75rem; color: var(--dim); margin-top: .2rem; }
.rev-tag {
  position: absolute; top: .6rem; right: .6rem; font-size: .65rem; z-index: 2;
  letter-spacing: .1em; color: #fff; background: #4a3560cc;
  border-radius: 999px; padding: .2rem .6rem;
}

/* ข้อความโผล่หลังพลิกเสร็จ */
.tcard-text {
  color: #c9c4dd; font-size: .92rem; line-height: 1.7;
  opacity: 0; transform: translateY(6px);
  transition: opacity .4s ease .35s, transform .4s ease .35s;
}
.tcard.open .tcard-text { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  .flip-inner, .tcard-text, .tcard { transition: none; animation: none; }
}

/* ---------- ปุ่มรอง ---------- */
.spread-actions { display: flex; gap: .6rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.ghost {
  background: transparent; border: 1px solid var(--line); color: var(--ink);
  border-radius: 8px; padding: .6rem 1.2rem; font-size: .88rem;
  font-family: inherit; cursor: pointer;
}
.ghost:hover:not(:disabled) { border-color: var(--violet); color: #fff; }
.ghost:disabled { color: var(--dim); cursor: default; opacity: .6; }

.spread-note {
  color: var(--dim); font-size: .85rem; margin-top: 1.5rem;
  border-left: 2px solid var(--violet); padding-left: 1rem;
}

footer {
  text-align: center; color: var(--dim); font-size: .8rem;
  margin-top: 3rem; padding-top: 2rem; border-top: 1px solid var(--line); line-height: 1.8;
}
footer strong { color: var(--ink); }
footer em { color: var(--violet); font-style: normal; }
.dim { color: #6f6890; }
