/* ======================================================================
 * Taro — ไพ่ทาโรต์แห่งป่าจันทรา
 * ธีม: ป่ายามค่ำคืน · กระดาษครีม · ทองโบราณ (เข้ากับลายสีน้ำของไพ่)
 * ====================================================================== */
:root {
  --bg: #0c1613;
  --bg2: #12211c;
  --panel: rgba(19, 33, 28, 0.74);
  --panel-2: rgba(28, 46, 39, 0.72);
  --line: rgba(223, 196, 128, 0.22);
  --line-2: rgba(223, 196, 128, 0.42);
  --gold: #d9b867;
  --gold-2: #f2d995;
  --cream: #f4ebd3;
  --text: #ece3cb;
  --muted: #b1aa93;
  --teal: #7fb8bf;
  --moss: #86ad7c;
  --rose: #e2a08d;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --radius: 18px;
  --card-ar: 0.558;
  --font-th: "IBM Plex Sans Thai", "Sarabun", "Noto Sans Thai", system-ui, sans-serif;
  --font-display: "Charm", "IBM Plex Sans Thai", serif;
  --font-en: "Cormorant Garamond", Georgia, serif;
  --ease: cubic-bezier(.2, .75, .25, 1);
  --header-h: 64px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  min-height: 100vh;
  font: 400 16px/1.65 var(--font-th);
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 78% -10%, rgba(127, 184, 191, 0.16), transparent 60%),
    radial-gradient(900px 600px at 10% 110%, rgba(134, 173, 124, 0.14), transparent 60%),
    linear-gradient(180deg, #0b1512 0%, #0f1c18 55%, #0b1411 100%);
  background-color: var(--bg);
  background-attachment: fixed;
  overflow-x: hidden;
}
#sky { position: fixed; inset: 0; z-index: 0; pointer-events: none; }
img { max-width: 100%; display: block; }
button, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.tiny { font-size: 12.5px; line-height: 1.5; }
.center { text-align: center; }
a { color: var(--gold-2); }

/* ---------- Buttons ---------- */
button { cursor: pointer; }
.primary, .ghost {
  border-radius: 999px; padding: 10px 22px; font-weight: 500; letter-spacing: .2px;
  transition: transform .15s var(--ease), background .2s, border-color .2s, box-shadow .2s;
}
.primary {
  border: 1px solid #f5dd9b;
  background: linear-gradient(180deg, #ecd08a 0%, #c9a24f 100%);
  color: #221a0a;
  box-shadow: 0 6px 24px rgba(217, 184, 103, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.5);
}
.primary:hover, .primary.g-hover { transform: translateY(-1px); box-shadow: 0 10px 30px rgba(217, 184, 103, 0.4), inset 0 1px 0 rgba(255,255,255,.5); }
.primary:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.ghost { border: 1px solid var(--line-2); background: rgba(255, 255, 255, 0.03); color: var(--cream); }
.ghost:hover, .ghost.g-hover { background: rgba(217, 184, 103, 0.12); border-color: var(--gold); }
.small { padding: 6px 14px; font-size: 14px; }
.big { padding: 14px 26px; font-size: 17px; width: 100%; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.03); color: var(--cream);
  transition: background .2s, border-color .2s;
}
.icon-btn svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover, .icon-btn.g-hover { border-color: var(--gold); background: rgba(217, 184, 103, 0.1); }
.icon-btn[aria-pressed="true"] { border-color: var(--gold); background: rgba(217, 184, 103, 0.2); color: var(--gold-2); }
#btnSound .on { display: none; }
#btnSound[aria-pressed="true"] .on { display: block; }
#btnSound[aria-pressed="true"] .off { display: none; }
:focus-visible { outline: 2px solid var(--gold-2); outline-offset: 3px; }

/* ---------- Header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50; height: var(--header-h);
  display: flex; align-items: center; gap: 16px; padding: 0 20px;
  background: linear-gradient(180deg, rgba(11, 21, 18, 0.92), rgba(11, 21, 18, 0.7));
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--cream); flex: none; }
.brand img { width: 26px; height: 46px; border-radius: 4px; object-fit: cover; box-shadow: 0 0 0 1px var(--line-2); }
.brand span { display: flex; flex-direction: column; line-height: 1.1; }
.brand b { font: 600 22px/1 var(--font-en); letter-spacing: 2px; color: var(--gold-2); }
.brand small { font-size: 11.5px; color: var(--muted); }
.nav { display: flex; gap: 4px; margin: 0 auto; }
.nav a {
  text-decoration: none; color: var(--muted); padding: 7px 14px; border-radius: 999px; font-size: 15px;
  transition: color .2s, background .2s;
}
.nav a:hover, .nav a.g-hover { color: var(--cream); background: rgba(255,255,255,.04); }
.nav a.active { color: var(--gold-2); background: rgba(217, 184, 103, 0.12); }
.tools { display: flex; gap: 8px; flex: none; }

main { position: relative; z-index: 1; }
.view { max-width: 1180px; margin: 0 auto; padding: 28px 20px 80px; animation: viewIn .5s var(--ease); }
@keyframes viewIn { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Home ---------- */
.hero { text-align: center; padding: 18px 0 30px; }
.eyebrow { color: var(--gold); letter-spacing: 2px; font-size: 13px; margin: 0 0 22px; }
.hero h1, .page-head h1 {
  font: 700 clamp(38px, 6vw, 64px)/1.5 var(--font-display); margin: 0; color: var(--cream);
  text-shadow: 0 0 30px rgba(242, 217, 149, 0.25);
}
.page-head h1 { font-size: clamp(32px, 4.5vw, 48px); }
.lead { color: var(--muted); max-width: 620px; margin: 10px auto 0; font-size: 16.5px; }
.page-head { text-align: center; margin-bottom: 26px; padding-top: 10px; }

.home-grid { display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); gap: 22px; align-items: start; }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.panel-head h2 { margin: 0; font: 700 28px/1.2 var(--font-display); color: var(--gold-2); }
.field-label { display: block; margin: 18px 0 8px; font-weight: 500; color: var(--cream); font-size: 15px; }
.field-label:first-of-type { margin-top: 4px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.03); color: var(--text);
  border-radius: 999px; padding: 7px 16px; font-size: 15px; transition: all .2s;
}
.chip:hover, .chip.g-hover { border-color: var(--line-2); }
.chip[aria-checked="true"], .chip.on { background: rgba(217, 184, 103, 0.18); border-color: var(--gold); color: var(--gold-2); }
.chip .ic { margin-right: 6px; opacity: .85; }

.spreads { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.spread-opt {
  position: relative; text-align: left; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.025);
  border-radius: 14px; padding: 12px 12px 10px; transition: all .2s; min-height: 108px;
  display: flex; flex-direction: column; gap: 6px;
}
.spread-opt:hover, .spread-opt.g-hover { border-color: var(--line-2); background: rgba(255,255,255,.05); }
.spread-opt[aria-checked="true"] { border-color: var(--gold); background: rgba(217, 184, 103, 0.12); box-shadow: 0 0 0 1px var(--gold) inset; }
.spread-opt b { font-weight: 500; font-size: 14.5px; line-height: 1.35; color: var(--cream); }
.spread-opt small { color: var(--muted); font-size: 12.5px; }
.spread-mini { position: relative; height: 34px; margin-bottom: 2px; }
.spread-mini i {
  position: absolute; width: 12px; height: 20px; border-radius: 2px;
  background: linear-gradient(160deg, #e9dcb7, #b9a676); box-shadow: 0 1px 3px rgba(0,0,0,.4);
}

.q-wrap { display: flex; gap: 8px; }
.q-wrap input, textarea, .lib-tools input, .set-input {
  flex: 1; min-width: 0; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.25); color: var(--cream); outline: none; transition: border-color .2s;
}
.q-wrap input:focus, textarea:focus, .lib-tools input:focus, .set-input:focus { border-color: var(--gold); }
::placeholder { color: rgba(177, 170, 147, 0.7); }
#btnStart { margin-top: 22px; }
.setup .tiny { margin: 12px 0 0; }

/* Daily */
.daily-body { display: flex; gap: 18px; align-items: flex-start; }
.daily-card { flex: none; width: 150px; border: 0; padding: 0; background: none; }
.daily-text { flex: 1; min-width: 0; }
.daily-text h3 { margin: 0 0 2px; font: 600 24px/1.2 var(--font-en); color: var(--gold-2); }
.daily-text .th-name { color: var(--cream); margin-bottom: 8px; }
.daily-text p { margin: 6px 0; font-size: 15px; }
.kw { color: var(--teal); font-size: 13.5px; }
.lucky { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.lucky span { font-size: 13px; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--gold-2); }

/* ---------- 3D card ---------- */
.card3d { perspective: 1200px; aspect-ratio: var(--card-ar); display: block; position: relative; }
.card-inner {
  position: absolute; inset: 0; transform-style: preserve-3d;
  transition: transform .9s var(--ease);
}
.card3d.flipped .card-inner { transform: rotateY(180deg); }
.face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: 7%/3.9%; overflow: hidden; background: #e8dcbc;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 240, 200, 0.25);
}
.face img { width: 100%; height: 100%; object-fit: cover; }
.face.front { transform: rotateY(180deg); }
.card3d.rev .face.front img { transform: rotate(180deg); }
.card3d.glow .face.front { box-shadow: 0 0 0 1px rgba(255, 240, 200, 0.5), 0 0 40px rgba(242, 217, 149, 0.45), 0 12px 30px rgba(0,0,0,.5); }
.daily-card:not(.flipped):hover .card-inner, .daily-card.g-hover:not(.flipped) .card-inner { transform: translateY(-4px) rotateZ(-1deg); }
.daily-card:not(.flipped) .face.back { animation: breatheGlow 3s ease-in-out infinite; }
@keyframes breatheGlow { 50% { box-shadow: 0 10px 28px rgba(0,0,0,.5), 0 0 26px rgba(242, 217, 149, 0.35), 0 0 0 1px rgba(255,240,200,.35); } }

/* ---------- Reading view ---------- */
#view-reading { max-width: 1320px; padding-top: 14px; }
.reading-head { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; min-height: 48px; }
.rh-title { flex: 1; min-width: 0; text-align: center; }
.rh-spread { font: 700 24px/1.2 var(--font-display); color: var(--gold-2); }
.rh-q { color: var(--muted); font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rh-count { min-width: 76px; text-align: right; color: var(--gold-2); font-variant-numeric: tabular-nums; }

/* Shuffle stage */
.stage { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: calc(100vh - var(--header-h) - 110px); gap: 16px; }
.deck-stack { position: relative; width: 150px; aspect-ratio: var(--card-ar); cursor: pointer; }
.deck-stack .sc {
  position: absolute; inset: 0; border-radius: 7%/3.9%; overflow: hidden;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 240, 200, 0.22);
  background: #e8dcbc url(../assets/web/back.webp) center/cover;
  transition: transform .35s var(--ease);
  transform: translate(calc(var(--i) * -0.6px), calc(var(--i) * -0.8px));
}
.deck-stack.riffle .sc { animation: riffle .9s var(--ease) both; animation-delay: calc(var(--i) * 18ms); }
.deck-stack.riffle .sc:nth-child(odd) { animation-name: riffleL; }
@keyframes riffle {
  0% { transform: translate(0, 0) rotate(0); }
  35% { transform: translate(92px, -10px) rotate(9deg); }
  70% { transform: translate(8px, -24px) rotate(-2deg); }
  100% { transform: translate(calc(var(--i) * -0.6px), calc(var(--i) * -0.8px)); }
}
@keyframes riffleL {
  0% { transform: translate(0, 0) rotate(0); }
  35% { transform: translate(-92px, -10px) rotate(-9deg); }
  70% { transform: translate(-8px, -24px) rotate(2deg); }
  100% { transform: translate(calc(var(--i) * -0.6px), calc(var(--i) * -0.8px)); }
}
.deck-stack::after {
  content: ""; position: absolute; inset: -30px; border-radius: 30px; z-index: -1;
  background: radial-gradient(closest-side, rgba(242, 217, 149, 0.25), transparent); animation: pulse 4s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: .35; transform: scale(1.08); } }
.breath { width: 180px; height: 4px; border-radius: 4px; background: rgba(255,255,255,.08); overflow: hidden; margin-top: 12px; }
.breath span { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, var(--teal), var(--gold)); transform-origin: left; animation: breath 8s ease-in-out infinite; }
@keyframes breath { 0%, 100% { transform: scaleX(0.08); } 50% { transform: scaleX(1); } }
.stage-msg { font: 400 22px/1.4 var(--font-display); color: var(--cream); text-align: center; margin: 4px 16px; min-height: 31px; }
.stage-actions { display: flex; gap: 12px; }
.gesture-only { display: none; }
body.gesture-on .gesture-only { display: block; }

/* Board */
.board-wrap { position: relative; }
.board { position: relative; margin: 0 auto; transition: height .6s var(--ease); }
.slot {
  position: absolute; aspect-ratio: var(--card-ar);
  transition: left .6s var(--ease), top .6s var(--ease), width .6s var(--ease), transform .6s var(--ease);
}
.slot .ph {
  position: absolute; inset: 0; border-radius: 7%/3.9%; border: 1.5px dashed rgba(223, 196, 128, 0.4);
  display: grid; place-items: center; color: rgba(242, 217, 149, 0.75); font: 600 20px var(--font-en);
  background: rgba(217, 184, 103, 0.04);
}
.slot.next .ph { border-color: var(--gold-2); background: rgba(217, 184, 103, 0.12); animation: slotPulse 1.6s ease-in-out infinite; }
@keyframes slotPulse { 50% { box-shadow: 0 0 24px rgba(242, 217, 149, 0.35); } }
.slot .card3d { position: absolute; inset: 0; width: 100%; }
.slot.filled .ph { opacity: 0; }
.slot .slot-label {
  position: absolute; left: 50%; top: 100%; transform: translateX(-50%); margin-top: 6px;
  white-space: nowrap; font-size: 13px; color: var(--muted); text-align: center; line-height: 1.3;
  pointer-events: none;
}
.slot[data-rot="90"] .slot-label { display: none; }
.slot .slot-label b { color: var(--gold-2); font-weight: 500; }
.board.revealing .slot.filled:not(.open) { cursor: pointer; }
.board.revealing .slot.filled:not(.open) .card-inner { animation: waitFlip 2.4s ease-in-out infinite; }
.board.revealing .slot.filled:not(.open):hover .card-inner,
.board.revealing .slot.filled:not(.open).g-hover .card-inner { animation: none; transform: translateY(-6px) scale(1.03); }
@keyframes waitFlip { 50% { transform: translateY(-3px); } }
.slot.open { cursor: zoom-in; }
.slot.active .face.front { box-shadow: 0 0 0 2px var(--gold-2), 0 0 34px rgba(242, 217, 149, .5); }
.board.compact .slot .slot-label { font-size: 11px; white-space: normal; width: calc(100% + 28px); line-height: 1.25; }
.board.nolabel .slot .slot-label { display: none; }
#view-reading.split { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); column-gap: 32px; align-items: start; }
#view-reading.split .reading-head { grid-column: 1 / -1; }
#view-reading.split .board-wrap { position: sticky; top: calc(var(--header-h) + 12px); }
#view-reading.split .interp { margin-top: 0; max-width: none; }
.board-actions { display: flex; justify-content: center; gap: 10px; margin: 18px 0 6px; min-height: 42px; flex-wrap: wrap; }

/* Fan */
.fan-wrap { position: relative; margin-top: 8px; }
.fan-msg { text-align: center; margin: 0 0 4px; color: var(--cream); font: 400 20px/1.3 var(--font-display); }
.fan { position: relative; height: 260px; outline: none; user-select: none; -webkit-user-select: none; touch-action: pan-x; }
.fan-card {
  position: absolute; left: 50%; bottom: 14px; width: var(--cw, 96px); aspect-ratio: var(--card-ar);
  margin-left: calc(var(--cw, 96px) / -2); padding: 0; border: 0; background: none;
  transform-origin: 50% var(--origin, 1200px);
  transform: rotate(calc(var(--a, 0deg) + var(--sa, 0deg))) translateY(var(--ly, 0px));
  transition: transform .45s var(--ease), opacity .35s;
  transition-delay: var(--d, 0ms);
}
.fan-card .fc {
  position: absolute; inset: 0; border-radius: 7%/3.9%;
  background: #e8dcbc url(../assets/web/back-sm.webp) center/cover;
  box-shadow: -3px 2px 8px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 240, 200, 0.28);
  transition: box-shadow .2s, filter .2s;
}
.fan-card.hover { --ly: -34px; z-index: 5; transition-delay: 0ms; }
.fan-card.near { --ly: -12px; transition-delay: 0ms; }
.fan-card.hover .fc { box-shadow: 0 0 0 1.5px var(--gold-2), 0 0 26px rgba(242, 217, 149, 0.55), 0 10px 20px rgba(0,0,0,.5); }
.fan-card.gone { opacity: 0; pointer-events: none; }
.fan.gathered .fan-card { transform: rotate(0deg) translateY(-40px); opacity: 0; transition-delay: 0ms; }
.fan.locked .fan-card { pointer-events: none; }
.fan.ribbon { display: flex; height: auto; overflow-x: auto; overflow-y: visible; padding: 46px 24px 16px 70px; scroll-snap-type: x proximity; scrollbar-width: thin; }
.fan.ribbon .fan-card { position: relative; left: auto; bottom: auto; flex: none; margin-left: -46px; transform: translateY(var(--ly, 0)); }
.fan.ribbon.gathered .fan-card { transform: translateY(30px); }
.fan-tools { display: flex; justify-content: center; gap: 10px; margin-top: 4px; }
@media (min-width: 760px) { .fan-tools { position: absolute; right: 8px; top: 0; margin: 0; justify-content: flex-end; max-width: 40%; gap: 6px; } }
.fan-wrap.done { animation: fanOut .6s var(--ease) forwards; }
@keyframes fanOut { to { opacity: 0; transform: translateY(60px); } }

.fly { position: fixed; z-index: 90; pointer-events: none; aspect-ratio: var(--card-ar); }
.fly .fc { position: absolute; inset: 0; border-radius: 7%/3.9%; background: #e8dcbc url(../assets/web/back.webp) center/cover; box-shadow: 0 0 30px rgba(242,217,149,.5), 0 20px 40px rgba(0,0,0,.5); }

/* Interpretation */
.interp { max-width: 860px; margin: 26px auto 0; display: flex; flex-direction: column; gap: 16px; }
.interp-item {
  display: grid; grid-template-columns: 96px 1fr; gap: 18px; padding: 18px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  animation: itemIn .7s var(--ease) both;
}
@keyframes itemIn { from { opacity: 0; transform: translateY(14px); } }
.interp-item .thumb { align-self: start; width: 96px; border-radius: 7%/3.9%; overflow: hidden; box-shadow: 0 6px 16px rgba(0,0,0,.4); cursor: zoom-in; border: 0; padding: 0; background: none; }
.interp-item .thumb.rev img { transform: rotate(180deg); }
.pos-tag { display: inline-block; font-size: 12.5px; color: var(--bg); background: var(--gold); border-radius: 999px; padding: 1px 10px; margin-bottom: 4px; font-weight: 500; }
.pos-desc { color: var(--muted); font-size: 13px; margin-left: 6px; }
.interp-item h3 { margin: 4px 0 0; font: 600 22px/1.3 var(--font-th); color: var(--gold-2); }
.interp-item h3 .en { font: 500 17px var(--font-en); color: var(--muted); margin-left: 8px; }
.rev-badge { font: 500 12px var(--font-th); color: var(--rose); border: 1px solid rgba(226,160,141,.5); border-radius: 999px; padding: 1px 8px; margin-left: 8px; vertical-align: middle; }
.interp-item p { margin: 8px 0 0; }
.interp-item .adv { color: var(--moss); font-size: 14.5px; }

.summary h2, .ai-panel h2 { margin: 0 0 10px; font: 700 28px/1.2 var(--font-display); color: var(--gold-2); }
.summary p { margin: 8px 0; }
.summary b { color: var(--gold-2); font-weight: 500; }
.verdict { display: flex; align-items: center; gap: 16px; padding: 14px 16px; border-radius: 14px; background: rgba(217,184,103,.1); border: 1px solid var(--line-2); margin: 6px 0 12px; }
.verdict .v { font: 700 34px/1 var(--font-display); color: var(--gold-2); white-space: nowrap; }
.verdict.no .v { color: var(--rose); }
.verdict.maybe .v { color: var(--teal); }
.advice-box { margin-top: 12px; padding: 12px 16px; border-left: 3px solid var(--moss); background: rgba(134,173,124,.08); border-radius: 0 10px 10px 0; }
.ai-panel .ai-out { white-space: pre-wrap; }
.ai-panel .ai-out p { margin: 0 0 10px; }
.ai-loading { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.ai-loading i { width: 8px; height: 8px; border-radius: 50%; background: var(--gold); animation: dot 1.2s infinite; }
.ai-loading i:nth-child(2) { animation-delay: .2s; } .ai-loading i:nth-child(3) { animation-delay: .4s; }
@keyframes dot { 50% { opacity: .2; transform: scale(.6); } }
.row-end { display: flex; justify-content: flex-end; margin-top: 6px; }
textarea { width: 100%; resize: vertical; }
.final-actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin-top: 6px; }

/* ---------- Library ---------- */
.lib-tools { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 20px; }
.lib-tools input { max-width: 320px; }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 16px; }
.lib-item { border: 0; padding: 0; background: none; text-align: center; color: var(--text); transition: transform .2s var(--ease); }
.lib-item:hover, .lib-item.g-hover { transform: translateY(-4px); }
.lib-item img { width: 100%; aspect-ratio: var(--card-ar); object-fit: cover; border-radius: 7%/3.9%; box-shadow: 0 6px 16px rgba(0,0,0,.45); background: #e8dcbc; }
.lib-item span { display: block; font-size: 13px; margin-top: 6px; line-height: 1.3; }
.lib-item small { color: var(--muted); font-size: 11.5px; }

/* ---------- Journal ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.stat b { display: block; font: 700 30px/1.1 var(--font-en); color: var(--gold-2); }
.stat span { color: var(--muted); font-size: 13.5px; }
.journal-list { display: flex; flex-direction: column; gap: 12px; }
.j-item { display: flex; gap: 16px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; }
.j-cards { display: flex; flex: none; }
.j-cards img { width: 38px; aspect-ratio: var(--card-ar); object-fit: cover; border-radius: 3px; margin-right: -12px; box-shadow: 0 2px 6px rgba(0,0,0,.5); border: 1px solid rgba(255,240,200,.25); }
.j-cards img.rev { transform: rotate(180deg); }
.j-cards { padding-right: 12px; }
.j-main { flex: 1; min-width: 0; }
.j-main b { color: var(--cream); font-weight: 500; }
.j-main div { color: var(--muted); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.j-actions { display: flex; gap: 6px; flex: none; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; border: 1px dashed var(--line); border-radius: 16px; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: 16px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(4, 9, 8, 0.72); backdrop-filter: blur(4px); animation: fadeIn .25s; }
.modal-box {
  position: relative; width: min(880px, 100%); max-height: calc(100vh - 32px); overflow: auto;
  background: linear-gradient(180deg, #15261f, #101d18); border: 1px solid var(--line-2); border-radius: 22px;
  padding: 26px; box-shadow: 0 30px 80px rgba(0,0,0,.6); animation: popIn .35s var(--ease);
}
@keyframes fadeIn { from { opacity: 0; } }
@keyframes popIn { from { opacity: 0; transform: translateY(12px) scale(.98); } }
.modal-x { position: absolute; right: 14px; top: 14px; z-index: 2; }
.cd { display: grid; grid-template-columns: 260px 1fr; gap: 26px; }
.cd-img { position: relative; }
.cd-img img { border-radius: 7%/3.9%; box-shadow: 0 16px 40px rgba(0,0,0,.55); width: 100%; transition: transform .6s var(--ease); }
.cd-img.rev img { transform: rotate(180deg); }
.cd h2 { margin: 0; font: 600 34px/1.1 var(--font-en); color: var(--gold-2); }
.cd .th-name { font-size: 19px; color: var(--cream); margin: 2px 0 4px; }
.cd .meta { color: var(--muted); font-size: 13.5px; }
.tabs { display: flex; gap: 6px; margin: 14px 0 10px; }
.cd dl { margin: 0; display: grid; grid-template-columns: 88px 1fr; gap: 8px 12px; }
.cd dt { color: var(--gold); font-size: 14px; padding-top: 1px; }
.cd dd { margin: 0; font-size: 15px; }
.settings h2 { margin: 0 0 14px; font: 700 30px var(--font-display); color: var(--gold-2); }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.set-row:last-child { border-bottom: 0; }
.set-row .t b { display: block; font-weight: 500; color: var(--cream); }
.set-row .t span { font-size: 13.5px; color: var(--muted); }
.set-col { flex-direction: column; align-items: stretch; }
.switch { position: relative; width: 50px; height: 28px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: rgba(255,255,255,.12); border: 1px solid var(--line); transition: .2s; }
.switch span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--cream); transition: .2s var(--ease); }
.switch input:checked + span { background: var(--gold); }
.switch input:checked + span::after { transform: translateX(22px); background: #231b0b; }
.set-input { width: 100%; margin-top: 8px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 20px); z-index: 300; opacity: 0;
  background: rgba(20, 33, 28, 0.96); border: 1px solid var(--line-2); color: var(--cream);
  padding: 10px 18px; border-radius: 999px; font-size: 14.5px; transition: all .3s var(--ease); pointer-events: none;
  max-width: calc(100vw - 32px); text-align: center; box-shadow: var(--shadow);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Gesture ---------- */
#gCursor {
  position: fixed; left: 0; top: 0; width: 44px; height: 44px; margin: -22px 0 0 -22px; z-index: 400;
  pointer-events: none; display: none; transition: opacity .2s; will-change: transform;
}
body.gesture-on #gCursor.visible { display: block; }
#gCursor svg { width: 100%; height: 100%; overflow: visible; }
#gCursor .ring { fill: rgba(242, 217, 149, 0.12); stroke: var(--gold-2); stroke-width: 2; transition: all .15s; }
#gCursor .prog { fill: none; stroke: var(--teal); stroke-width: 3.5; stroke-dasharray: 113.1; stroke-dashoffset: 113.1; transform: rotate(-90deg); transform-origin: center; stroke-linecap: round; }
#gCursor.pinch .ring { fill: rgba(242, 217, 149, 0.5); transform: scale(.72); transform-origin: center; }
#gCursor.fist .ring { stroke: var(--rose); }
#gPanel {
  position: fixed; right: 16px; bottom: 16px; z-index: 120; width: 220px;
  background: rgba(12, 22, 19, 0.92); border: 1px solid var(--line-2); border-radius: 16px; overflow: hidden; box-shadow: var(--shadow);
}
.g-video { position: relative; aspect-ratio: 4/3; background: #000; }
.g-video video, .g-video canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.g-video video { opacity: .55; }
.g-status { padding: 8px 12px 2px; font-size: 13.5px; color: var(--gold-2); }
.g-help { display: flex; flex-wrap: wrap; gap: 2px 10px; padding: 2px 12px 10px; font-size: 11.5px; color: var(--muted); }

/* ---------- Share canvas (hidden) ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .home-grid { grid-template-columns: 1fr; }
  .spreads { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  :root { --header-h: 58px; }
  .topbar { padding: 0 12px; gap: 8px; }
  .brand small { display: none; }
  .brand b { font-size: 19px; }
  .nav { margin: 0 auto; }
  .nav a { padding: 6px 9px; font-size: 14px; }
  .icon-btn { width: 36px; height: 36px; }
  .tools { gap: 6px; }
  .view { padding: 18px 16px 70px; }
  .panel { padding: 18px 16px; }
  .daily-card { width: 118px; }
  .interp-item { grid-template-columns: 70px 1fr; gap: 14px; padding: 14px; }
  .interp-item .thumb { width: 70px; }
  .interp-item h3 { font-size: 20px; }
  .interp-item h3 .en { display: block; margin: 0; }
  .cd { grid-template-columns: 1fr; }
  .cd-img { max-width: 220px; margin: 0 auto; }
  .modal-box { padding: 20px 16px; }
  .j-item { flex-wrap: wrap; }
  .j-actions { width: 100%; justify-content: flex-end; }
  .lib-grid { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 12px; }
  .rh-spread { font-size: 20px; }
  #gPanel { width: 150px; right: 10px; bottom: 10px; }
  .g-help { display: none; }
  .stage-msg { font-size: 19px; }
}
@media (max-width: 420px) {
  .brand span { display: none; }
  .nav a { padding: 6px 7px; font-size: 13.5px; }
  .spreads { gap: 8px; }
  .spread-opt { padding: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ================= v3: ถามแม่หมอ / คำตอบ / อ่านไพ่ละเอียด ================= */
.topic-tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.topic-tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; padding: 14px 14px 12px;
  border-radius: 16px; border: 1px solid var(--line); background: rgba(255,255,255,.03); color: var(--text); transition: all .2s;
}
.topic-tile:hover, .topic-tile.g-hover { border-color: var(--line-2); transform: translateY(-2px); }
.topic-tile[aria-checked="true"] { border-color: var(--gold); background: linear-gradient(160deg, rgba(217,184,103,.22), rgba(217,184,103,.06)); box-shadow: 0 0 0 1px var(--gold) inset; }
.tt-ic { font-size: 22px; color: var(--gold-2); line-height: 1; margin-bottom: 4px; }
.topic-tile b { font-weight: 600; font-size: 17px; color: var(--cream); }
.topic-tile small { font-size: 12.5px; color: var(--muted); line-height: 1.4; }
.q-input { width: 100%; padding: 13px 16px; border-radius: 14px; border: 1px solid var(--line); background: rgba(0,0,0,.25); color: var(--cream); outline: none; font-size: 16px; }
.q-input:focus { border-color: var(--gold); }
.q-ideas { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.q-idea { font-size: 13.5px; padding: 5px 12px; border-radius: 999px; border: 1px dashed var(--line-2); background: transparent; color: var(--muted); transition: all .2s; }
.q-idea:hover, .q-idea.g-hover { color: var(--gold-2); border-color: var(--gold); border-style: solid; }
.extra-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 14px; margin-top: 16px; align-items: start; }
.mini-field { display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; color: var(--muted); }
.mini-field input { padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: rgba(0,0,0,.25); color: var(--cream); outline: none; }
.mini-field input:focus { border-color: var(--gold); }
.chips.small .chip { font-size: 13px; padding: 5px 11px; }
.spread-current {
  width: 100%; display: flex; align-items: center; gap: 16px; text-align: left; padding: 14px 16px; border-radius: 16px;
  border: 1px solid var(--gold); color: var(--text);
  background: linear-gradient(135deg, rgba(217,184,103,.22), rgba(217,184,103,.05) 60%, rgba(127,184,191,.08));
  box-shadow: 0 0 0 1px rgba(217,184,103,.35) inset, 0 8px 24px rgba(0,0,0,.25); transition: transform .2s, box-shadow .2s;
}
.spread-current:hover, .spread-current.g-hover { transform: translateY(-1px); box-shadow: 0 0 0 1px var(--gold) inset, 0 10px 28px rgba(0,0,0,.3), 0 0 24px rgba(242,217,149,.18); }
.sc-mini { position: relative; flex: none; width: 92px; height: 58px; border-radius: 10px; background: rgba(0,0,0,.25); border: 1px solid var(--line); }
.sc-mini i { position: absolute; width: 12px; height: 20px; border-radius: 2px; background: linear-gradient(160deg, #f2e2b8, #c9a24f); box-shadow: 0 1px 3px rgba(0,0,0,.5); margin-top: 12px; }
.sc-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.sc-text b { font: 700 22px/1.25 var(--font-display); color: var(--gold-2); }
.sc-text small { color: var(--muted); font-size: 13px; }
.sc-change { flex: none; display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 999px; background: var(--gold); color: #231b0b; font-weight: 600; font-size: 14px; }
.sc-change i { font-style: normal; transition: transform .2s; }
.spread-current[aria-expanded="true"] .sc-change i { transform: rotate(180deg); }
.spread-list { margin-top: 10px; animation: itemIn .3s var(--ease) both; }
@media (max-width: 480px) { .sc-mini { width: 64px; } .sc-text b { font-size: 19px; } .sc-change { padding: 6px 10px; font-size: 13px; } }
.spread-opt .rec { position: absolute; top: 8px; right: 8px; font-size: 11px; padding: 1px 8px; border-radius: 999px; background: var(--gold); color: #231b0b; font-weight: 600; }
#btnStart { margin-top: 18px; }

/* คำตอบ */
.answer-box {
  position: relative; padding: 22px 24px; border-radius: 20px; border: 1px solid var(--gold);
  background: radial-gradient(120% 140% at 0% 0%, rgba(217,184,103,.18), rgba(19,33,28,.92) 60%);
  box-shadow: 0 20px 50px rgba(0,0,0,.45), 0 0 40px rgba(242,217,149,.12); animation: itemIn .7s var(--ease) both; scroll-margin-top: 80px;
}
.ab-label { font: 700 22px/1.2 var(--font-display); color: var(--gold-2); margin-bottom: 6px; }
.ab-verdict { display: inline-block; font: 700 30px/1.2 var(--font-display); color: var(--gold-2); margin: 2px 0 6px; }
.ab-verdict.no { color: var(--rose); } .ab-verdict.maybe { color: var(--teal); }
.ab-text { font-size: 18px; line-height: 1.8; color: var(--cream); margin: 0; }
.ab-timing { margin-top: 12px; font-size: 15px; color: var(--teal); }

/* ไพ่ทีละใบ */
.interp-item { scroll-margin-top: 80px; }
.interp-item .headline { margin: 10px 0 2px; font: 700 22px/1.35 var(--font-display); color: var(--cream); }
.interp-item .reading-text { font-size: 16.5px; line-height: 1.9; color: var(--text); margin: 8px 0 0; }
.interp-item.flash { animation: flash 1.2s ease; }
@keyframes flash { 30% { box-shadow: 0 0 0 2px var(--gold), 0 0 40px rgba(242,217,149,.35); } }
.reading-wait { margin-top: 10px; }
.shimmer { height: 12px; border-radius: 6px; margin-top: 10px; background: linear-gradient(90deg, rgba(255,255,255,.05) 25%, rgba(242,217,149,.15) 50%, rgba(255,255,255,.05) 75%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
.shimmer.short { width: 60%; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* สรุป */
.summary .story { font-size: 16.5px; line-height: 1.9; }
.areas { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 14px 0; }
.area { padding: 12px 14px; border-radius: 12px; background: rgba(255,255,255,.035); border: 1px solid var(--line); }
.area b { color: var(--gold-2); font-weight: 600; }
.area p { margin: 4px 0 0 !important; font-size: 15px; }
.dodont { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 14px 0; }
.dodont > div { padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); }
.dodont .do { background: rgba(134,173,124,.08); } .dodont .do b { color: var(--moss); }
.dodont .dont { background: rgba(226,160,141,.07); } .dodont .dont b { color: var(--rose); }
.dodont ul { margin: 6px 0 0; padding-left: 18px; } .dodont li { margin: 4px 0; font-size: 15px; }
.mini-cards { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 12px; font-size: 13px; color: var(--muted); }
.mini-cards b { color: var(--cream); font-weight: 500; }

/* ถามต่อ */
.ask-panel h2 { margin: 0 0 4px; font: 700 26px/1.2 var(--font-display); color: var(--gold-2); }
.chat { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: 16px; font-size: 15.5px; line-height: 1.75; animation: itemIn .4s var(--ease) both; }
.msg.me { align-self: flex-end; background: rgba(217,184,103,.18); border: 1px solid var(--line-2); border-bottom-right-radius: 4px; }
.msg.her { align-self: flex-start; background: rgba(255,255,255,.05); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.err { color: var(--rose); }
.ask-row { display: flex; gap: 8px; margin-top: 10px; }
.ask-row input { flex: 1; min-width: 0; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: rgba(0,0,0,.25); color: var(--cream); outline: none; }
.ask-row input:focus { border-color: var(--gold); }

/* แถบเปิดใบถัดไป */
.reveal-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; display: flex; justify-content: center; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(0deg, rgba(11,21,18,.96) 55%, rgba(11,21,18,0)); pointer-events: none; }
.reveal-bar button { pointer-events: auto; min-width: 260px; max-width: 100%; padding: 13px 24px; font-size: 16px; }

@media (max-width: 960px) {
  .topic-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .extra-row { grid-template-columns: 1fr; }
  .areas, .dodont { grid-template-columns: 1fr; }
  .answer-box { padding: 18px 16px; }
  .ab-text { font-size: 16.5px; }
  .interp-item .reading-text { font-size: 16px; }
  .interp-item { display: block; }
  .interp-item .thumb { width: 78px; float: left; margin: 2px 14px 6px 0; }
  .interp-item .reading-text, .interp-item .headline, .interp-item .reading-wait { clear: both; }
}

#view-reading { padding-bottom: 120px; }
#statusWrap .field-label { margin-top: 18px; }

.fan-tools { flex-wrap: wrap; }
