/* =========================================================
   Miếu Vui — giao diện "giấy dó, mực tàu, dấu son"
   ========================================================= */
@font-face {
  font-family: 'Absolute VH';
  src: url('../fonts/absolute-vh.ttf') format('truetype');
  font-display: swap;
}

:root {
  /* nền trang: đỏ sẫm */
  --bg: #3f0a0f;
  --bg-2: #6b1219;
  --cream: #fbf0da;
  --cream-soft: #e9cdbb;
  --gold: #eebd55;
  --gold-soft: #f6d98f;
  --gold-line: rgba(238, 189, 85, .38);

  /* giấy dó cho hộp thoại, lá xăm */
  --paper: #efe6d2;
  --paper-2: #f8f2e4;
  --paper-3: #e2d4b6;
  --ink: #221c18;
  --ink-soft: #62564c;
  --line: rgba(34, 28, 24, .18);
  --son: #b3261e;
  --son-deep: #7f1a14;
  --bamboo: #e6cf98;
  --tube: #c99b57;
  --tube-dark: #8a6232;
  --jade: #3f6f5a;
  --amber: #a86a12;

  --font: 'Be Vietnam Pro', system-ui, sans-serif;
  --serif: 'Noto Serif', Georgia, serif;
  --seal-font: 'Saira Extra Condensed', 'Arial Narrow', sans-serif;
  --display: 'Absolute VH', 'Noto Serif', serif;

  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
  --ease-out: cubic-bezier(.2, .8, .2, 1);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); overflow-x: clip; }
body {
  margin: 0; min-height: 100dvh;
  font-family: var(--font); color: var(--cream);
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse 80% 45% at 50% 32%, rgba(238, 189, 85, .16), transparent 70%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 .14 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23f)'/%3E%3C/svg%3E"),
    linear-gradient(180deg, var(--bg-2) 0%, var(--bg) 60%);
  background-attachment: fixed;
}
html.no-scroll, html.no-scroll body, html.no-scroll .device-scroll { overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; border-radius: 6px; }
.modal :focus-visible { outline-color: var(--son); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Dấu triện ---------- */
.seal-slot { display: inline-block; line-height: 0; }
.seal { display: block; width: 100%; height: auto; overflow: visible; }

/* ---------- Thanh trên ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: transparent;
  transition: background .3s, box-shadow .3s, -webkit-backdrop-filter .3s, backdrop-filter .3s;
}
/* chưa cuộn: header trong suốt, liền với nền; đã cuộn: kính mờ + bóng mềm, không có đường cắt */
.top.scrolled {
  background: rgba(74, 12, 18, .78);
  -webkit-backdrop-filter: blur(14px) saturate(1.2); backdrop-filter: blur(14px) saturate(1.2);
  box-shadow: 0 10px 24px -14px rgba(0,0,0,.75);
}
.logo { width: 42px; color: var(--gold); transform: rotate(-4deg); flex: none; }
.top-meta { display: grid; line-height: 1.25; min-width: 0; }
.top-meta b { font-family: var(--serif); font-size: 17px; color: var(--cream); }
.top-meta span { font-family: var(--serif); font-size: 15px; font-weight: 500; color: var(--cream); letter-spacing: .01em; }
.top-meta span::first-letter { text-transform: uppercase; }
.ghost-icon {
  margin-left: auto; width: 50px; padding: 4px; border: 0; background: none; color: var(--cream-soft);
  transition: color .2s, transform .3s var(--ease-spring);
}
.ghost-icon[aria-pressed="true"] { color: var(--gold); }
.ghost-icon:active { transform: scale(.9) rotate(-6deg); }

/* ---------- Trang ---------- */
.page { max-width: 560px; margin: 0 auto; padding: 0 16px calc(32px + env(safe-area-inset-bottom)); overflow-x: clip; }

.intro { position: relative; padding: 0 30px; margin-top: -8px; text-align: center; }
.intro-head { display: grid; justify-items: center; }
.eyebrow { margin: 2px 0 0; font-size: clamp(9px, 2.4vw, 11px); letter-spacing: .26em; opacity: .9; text-transform: uppercase; color: var(--gold); font-weight: 600; }
.intro h1 {
  margin: 0; font-family: var(--display); font-weight: 400; font-size: clamp(80px, 26vw, 128px); line-height: .98; white-space: nowrap;
  color: #ffe6a6; background: linear-gradient(180deg, #fff3c9 10%, #f3c763 55%, #d99a2b 90%); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 4px 0 var(--son-deep)) drop-shadow(0 0 1px #3a0a07) drop-shadow(0 12px 22px rgba(0,0,0,.45));
  padding: 0 .12em;
}
.intro-sub { margin: 10px 0 0; max-width: 32ch; font-size: 15px; line-height: 1.55; color: var(--cream-soft); }
.vertical-note {
  margin: 0; writing-mode: vertical-rl; font-family: var(--serif); font-style: italic;
  font-size: 14px; color: var(--gold); letter-spacing: .08em; opacity: .85;
  position: absolute; right: 0; top: 8px; white-space: nowrap;
}

/* ---------- Bàn thờ + ống ---------- */
.altar { position: relative; display: grid; justify-items: center; margin-top: clamp(14px, 3svh, 30px); }
#jarMount { position: relative; z-index: 2; display: grid; justify-items: center; }
.altar-table {
  position: relative; z-index: 1; width: min(92%, 400px); height: 26px; margin-top: -30px; border-radius: 8px 8px 3px 3px;
  background: linear-gradient(180deg, #a0703a, #c48b4b 55%, #a8743c);
  box-shadow: inset 0 2px 0 rgba(255,225,170,.25), 0 12px 0 #5a3c1d, 0 12px 0 1.5px var(--ink), 0 22px 22px -6px rgba(0,0,0,.55);
  border: 1.5px solid var(--ink);
}
.altar-table::after {
  content: ''; position: absolute; top: 37px; left: 9%; right: 9%; height: 26px;
  border-left: 10px solid #4a3218; border-right: 10px solid #4a3218;
}

.jar { position: relative; background: none; border: 0; padding: 0; width: min(64vw, 300px, 31svh); touch-action: manipulation; cursor: pointer; }
.jar svg { position: relative; width: 100%; display: block; overflow: visible; transform-origin: 50% 92%; will-change: transform; }
.jar .stick { will-change: transform, opacity; }
.jar .stick .body { transition: filter .2s ease; }
.jar .stick.on .body { filter: brightness(1.15) drop-shadow(0 0 4px rgba(238,189,85,.9)); }
.jar.shaking { cursor: progress; }
.jar-shadow { position: absolute; left: 16%; right: 16%; bottom: 6px; height: 16px; border-radius: 50%; background: radial-gradient(closest-side, rgba(0,0,0,.45), transparent); will-change: transform; }

.floor { position: relative; z-index: 3; min-height: 68px; width: 100%; display: grid; place-items: center; margin-top: 2px; }
.fallen { background: none; border: 0; display: grid; justify-items: center; gap: 10px; padding: 10px 14px; }
.fallen:not(.ready) { pointer-events: none; }
.fallen-stick {
  display: block; width: 210px; height: 20px; border-radius: 10px; position: relative;
  background:
    linear-gradient(90deg, #9e2416, #df5a3a 10px, #b8301f 24px, transparent 24px),
    linear-gradient(180deg, #c9954a, #f1d79a 40%, #c08a3e);
  border: 1.6px solid var(--ink); transform: rotate(-4deg);
  box-shadow: 0 8px 8px -3px rgba(0,0,0,.5);
  transition: transform .35s var(--ease-spring), box-shadow .35s ease; will-change: transform;
}
.fallen-stick::after { content: ''; position: absolute; left: 32px; right: 12px; top: 4px; height: 2.5px; border-radius: 2px; background: rgba(255,255,255,.5); }
.fallen-stick i { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); font-style: normal; font-family: var(--serif); font-weight: 700; font-size: 12px; color: rgba(60,35,10,.8); }
.fallen-hint {
  font-size: 13px; font-weight: 600; color: var(--ink); background: var(--gold);
  padding: 6px 12px; border-radius: 999px; opacity: 0; transform: translateY(6px);
  transition: opacity .35s ease, transform .35s var(--ease-out);
}
.fallen.ready .fallen-hint { opacity: 1; transform: none; }
.fallen.ready .fallen-stick { animation: glow 2.4s ease-in-out .3s infinite; }
.fallen.picked .fallen-stick { transform: translateY(-24px) rotate(0) scale(1.06); }
@media (hover: hover) { .fallen.ready:hover .fallen-stick { transform: translateY(-8px) rotate(-1deg) scale(1.03); box-shadow: 0 14px 12px -4px rgba(0,0,0,.4), 0 0 18px rgba(238,189,85,.5); } }
@keyframes glow {
  0%, 100% { box-shadow: 0 6px 6px -2px rgba(0,0,0,.45), 0 0 0 0 rgba(238,189,85,0); }
  50% { box-shadow: 0 6px 6px -2px rgba(0,0,0,.45), 0 0 16px 2px rgba(238,189,85,.45); }
}

/* ---------- Ô hỏi + nút lắc ---------- */
.ask { display: grid; gap: 10px; margin-top: 8px; }
.ask label { font-size: 14px; font-weight: 600; color: var(--gold); }
.ask input {
  width: 100%; font: inherit; font-size: 16px; /* ≥16px: iOS không tự zoom */
  padding: 15px 16px; border-radius: 14px; border: 2px solid transparent;
  color: var(--ink); background: var(--cream);
  box-shadow: inset 0 2px 4px rgba(0,0,0,.08);
  transition: border-color .2s, box-shadow .2s;
}
.ask input::placeholder { color: #9a8678; }
.ask input:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 4px rgba(238,189,85,.25); }
.btn-shake {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  min-height: 60px; padding: 12px 18px; border-radius: 14px; border: 0;
  background: linear-gradient(180deg, var(--gold-soft), var(--gold));
  color: var(--ink); font-family: var(--serif); font-weight: 700; font-size: 20px;
  box-shadow: 0 5px 0 #a8792a, 0 12px 20px -8px rgba(0,0,0,.6);
  transition: transform .12s ease, box-shadow .12s ease, filter .2s;
}
.btn-shake .seal-slot { width: 46px; color: var(--son-deep); transform: rotate(-6deg); transition: transform .3s var(--ease-spring); }
.btn-shake:active { transform: translateY(4px); box-shadow: 0 1px 0 #a8792a, 0 4px 10px -6px rgba(0,0,0,.6); }
@media (hover: hover) { .btn-shake:hover { filter: brightness(1.05); } .btn-shake:hover .seal-slot { transform: rotate(-12deg) scale(1.08); } }
.ask-tip { margin: 0; text-align: center; font-size: 11px; color: var(--cream-soft); opacity: .7; }

/* ---------- Lưới 6 ô ---------- */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 22px; }
.tile {
  display: grid; justify-items: center; align-content: center; gap: 8px; min-height: 104px; padding: 14px 6px;
  border-radius: 16px; border: 1.5px solid var(--gold-line);
  background: rgba(0,0,0,.24); color: var(--cream); font-size: 13.5px; font-weight: 500;
  transition: transform .25s var(--ease-spring), background .2s, border-color .2s;
}
.tile .seal-slot { width: 44px; color: var(--gold); transition: transform .3s var(--ease-spring); }
.tile:active { transform: scale(.96); background: rgba(238,189,85,.12); }
@media (hover: hover) {
  .tile:hover { transform: translateY(-3px); border-color: var(--gold); background: rgba(238,189,85,.08); }
  .tile:hover .seal-slot { transform: scale(1.12) rotate(-6deg); }
}

/* ---------- Lá quẻ hôm nay ---------- */
.today-slip {
  margin-top: 14px; width: 100%; display: flex; align-items: center; gap: 14px; text-align: left;
  padding: 14px 16px; border-radius: 16px; border: 1.5px solid var(--gold-line);
  background: rgba(0,0,0,.24); color: var(--cream);
  transition: transform .3s var(--ease-spring), border-color .2s;
}
.slip-date {
  flex: none; display: grid; place-items: center; align-content: center; width: 54px; height: 62px; border-radius: 10px;
  background: var(--gold); color: var(--ink); font-size: 12px; line-height: 1.1;
}
.slip-date b { font-family: var(--serif); font-size: 24px; display: block; }
.slip-main { display: grid; gap: 2px; min-width: 0; }
.slip-main b { font-family: var(--serif); font-size: 16px; }
.slip-main small { color: var(--cream-soft); font-size: 13px; line-height: 1.4; }
.slip-arrow { margin-left: auto; font-size: 20px; color: var(--gold); transition: transform .3s var(--ease-spring); }
@media (hover: hover) { .today-slip:hover { transform: translateY(-2px); border-color: var(--gold); } .today-slip:hover .slip-arrow { transform: translateX(4px); } }
.today-slip:active { transform: scale(.98); }

.foot { margin-top: 28px; text-align: center; font-size: 14.5px; line-height: 1.55; color: var(--cream-soft); opacity: .85; font-style: italic; font-family: var(--serif); }

/* ---------- Nút chuyển Mobile / Web (chỉ màn rộng) ---------- */
.view-switch { display: none; }
@media (min-width: 720px) {
  .view-switch {
    position: fixed; z-index: 40; top: 14px; left: 50%; translate: -50% 0;
    display: inline-flex; gap: 2px; padding: 4px; border-radius: 999px;
    background: rgba(20, 4, 6, .72); border: 1px solid var(--gold-line);
    -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
    box-shadow: 0 10px 24px -12px rgba(0,0,0,.8);
  }
  .view-switch button {
    display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 999px;
    border: 0; background: transparent; color: var(--cream-soft); font-size: 13px; font-weight: 600;
    transition: background .2s, color .2s;
  }
  .view-switch svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  .view-switch button[aria-pressed="true"] { background: var(--gold); color: var(--ink); }
  .view-switch button:not([aria-pressed="true"]):hover { color: var(--cream); background: rgba(238,189,85,.12); }

  /* ----- Mobile: app nằm trong khung điện thoại ----- */
  html[data-view="mobile"] body {
    min-height: 100dvh; display: grid; justify-items: center; align-content: start; padding: 64px 16px 24px;
    background: radial-gradient(ellipse 60% 50% at 50% 30%, #4a0d12, #1a0406 75%);
  }
  html[data-view="mobile"] .device {
    position: relative; width: 400px; height: min(860px, calc(100dvh - 88px)); flex: none;
    border-radius: 46px; border: 10px solid #140607; overflow: hidden;
    transform: translateZ(0); /* phần tử fixed bên trong (modal, toast, hoạ tiết) bám theo khung */
    box-shadow: 0 0 0 1.5px #5a3a22, 0 0 0 7px rgba(238,189,85,.06), 0 40px 90px -30px rgba(0,0,0,.9);
    background-color: var(--bg);
    background-image:
      radial-gradient(ellipse 80% 45% at 50% 32%, rgba(238, 189, 85, .16), transparent 70%),
      linear-gradient(180deg, var(--bg-2) 0%, var(--bg) 60%);
  }
  html[data-view="mobile"] .device-scroll { position: relative; z-index: 1; height: 100%; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none; }
  html[data-view="mobile"] .device-scroll::-webkit-scrollbar { display: none; }
  html[data-view="mobile"] .jar { width: 250px; }
  html[data-view="mobile"] .intro h1 { font-size: 100px; }
  html[data-view="mobile"] .eyebrow { font-size: 10.5px; }
  html[data-view="mobile"] .drum { width: 380px; }

  /* ----- Web: bố cục 2 cột ----- */
  html[data-view="web"] .top { padding-inline: max(20px, calc((100vw - 1120px) / 2)); }
  html[data-view="web"] .page {
    max-width: 1120px; padding: 8px 24px 40px;
    display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); column-gap: clamp(28px, 5vw, 72px); align-items: start;
  }
  html[data-view="web"] .stage { position: sticky; top: 76px; }
  html[data-view="web"] .panel { padding-top: clamp(24px, 9vh, 120px); }
  html[data-view="web"] .jar { width: min(330px, 40svh); }
  html[data-view="web"] .tiles { grid-template-columns: repeat(4, 1fr); }
  html[data-view="web"] .tile { min-height: 100px; font-size: 13px; }
  html[data-view="web"] .ask-tip { text-align: left; }
  html[data-view="web"] .vertical-note { display: none; }
  html[data-view="web"] .intro h1 { font-size: clamp(84px, 8.5vw, 124px); }
}

/* ---------- Nút ---------- */
/* nút có gờ dày phía dưới (cùng kiểu nút Lắc xăm) — bấm thì lún xuống */
.btn {
  border-radius: 14px; padding: 12px 20px; min-height: 48px; margin-bottom: 4px;
  font-weight: 700; font-size: 15px; border: 0;
  transition: transform .12s ease, box-shadow .12s ease, filter .2s;
}
.btn.primary {
  background: linear-gradient(180deg, #c9352b, var(--son)); color: var(--paper-2);
  box-shadow: 0 4px 0 var(--son-deep), 0 10px 16px -8px rgba(80, 10, 6, .55);
}
.btn.ghost {
  background: linear-gradient(180deg, #fbf6ec, #efe5d2); color: var(--ink);
  box-shadow: inset 0 0 0 1.5px #d8ccb4, 0 4px 0 #c9b995, 0 10px 16px -10px rgba(60, 40, 20, .35);
}
.btn.primary:active { transform: translateY(4px); box-shadow: 0 0 0 var(--son-deep), 0 4px 8px -6px rgba(80, 10, 6, .5); }
.btn.ghost:active { transform: translateY(4px); box-shadow: inset 0 0 0 1.5px #d8ccb4, 0 0 0 #c9b995, 0 4px 8px -6px rgba(60, 40, 20, .3); }
@media (hover: hover) { .btn:hover { filter: brightness(1.04); } }

/* ---------- Modal / bottom sheet ---------- */
.modal-wrap {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; justify-content: flex-end; align-items: center;
}
.modal-backdrop {
  position: absolute; inset: 0; background: rgba(22, 5, 7, .58);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  opacity: 0; transition: opacity .3s ease;
}
.modal {
  position: relative; width: 100%; max-width: 560px; max-height: calc(100% - 28px);
  display: flex; flex-direction: column; outline: none;
  background: var(--paper-2); color: var(--ink);
  border-radius: 28px 28px 0 0; overflow: hidden;
  box-shadow: 0 -18px 40px -16px rgba(0,0,0,.55);
  transform: translateY(105%);
  transition: transform .42s cubic-bezier(.32, .72, 0, 1);
}
.modal-wrap.open .modal-backdrop { opacity: 1; }
.modal-wrap.open .modal { transform: none; }
.modal-wrap.closing .modal { transition-duration: .26s; transition-timing-function: cubic-bezier(.4, 0, 1, 1); }
.modal.dragging { transition: none; }

.sheet-head {
  position: relative; z-index: 2; flex: none; padding: 12px 20px 14px;
  background: var(--paper-2); touch-action: none; cursor: grab;
  border-bottom: 1px solid transparent; transition: border-color .2s, box-shadow .2s;
}
.modal.dragging .sheet-head { cursor: grabbing; }
.sheet-head.lifted { border-bottom-color: var(--line); box-shadow: 0 6px 14px -10px rgba(34,28,24,.45); }
.grip { width: 44px; height: 5px; border-radius: 3px; background: rgba(34,28,24,.2); margin: 0 auto 12px; }
.sheet-title { display: flex; align-items: center; gap: 14px; padding-right: 48px; min-height: 52px; }
.sheet-text { min-width: 0; }
.modal-han { flex: none; width: 52px; color: var(--son); }
.modal-han .seal { transform: rotate(-4deg); }
.modal h2 { margin: 0; font-family: var(--serif); font-weight: 700; font-size: 21px; line-height: 1.25; text-wrap: balance; }
.modal-sub { margin: 4px 0 0; font-size: 13.5px; color: var(--ink-soft); line-height: 1.5; text-wrap: pretty; }
.modal-x {
  position: absolute; top: 22px; right: 14px; width: 44px; height: 44px; display: grid; place-items: center;
  border-radius: 50%; border: 0; background: rgba(34,28,24,.07); color: var(--ink);
  transition: background .2s, transform .2s var(--ease-spring);
}
.modal-x svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.modal-x:hover { background: rgba(34,28,24,.13); }
.modal-x:active { transform: scale(.9); }

.modal-body {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: 4px 20px 20px; -webkit-overflow-scrolling: touch;
}
.modal-body:only-of-type, .modal-body:last-child { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }

.modal-actions {
  flex: none; position: relative; z-index: 2;
  display: grid; grid-template-columns: 1fr; gap: 10px;
  padding: 12px 20px calc(14px + env(safe-area-inset-bottom));
  background: var(--paper-2); border-top: 1px solid transparent; transition: border-color .2s, box-shadow .2s;
}
.modal-actions.lifted { border-top-color: var(--line); box-shadow: 0 -8px 16px -12px rgba(34,28,24,.45); }
.modal-actions[data-count="2"] { grid-template-columns: 1fr 1.5fr; }
.modal-actions[data-count="2"] .btn.primary { order: 2; }
.modal-actions[data-count="3"] { grid-template-columns: 1fr 1fr; }
.modal-actions[data-count="3"] .btn.primary { grid-column: 1 / -1; order: -1; }
.modal-actions .btn { min-height: 52px; font-size: 16px; }

/* sheet lá xăm: nhường chỗ cho bức liễn — đầu sheet chỉ còn tay nắm, tiêu đề ẩn cho trình đọc màn hình */
.modal.paper .sheet-head { padding: 8px 20px 12px; border-bottom: 0; box-shadow: none; }
.modal.paper .grip { margin-bottom: 0; }
.modal.paper .sheet-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.modal.paper .modal-x { top: 6px; right: 10px; width: 34px; height: 34px; z-index: 3; }
.modal.paper .modal-x svg { width: 17px; height: 17px; }
.modal.paper .modal-body { padding: 0 22px 14px; }
.modal.paper { max-height: calc(100% - 10px); }

/* Web + màn rộng: hộp thoại nổi giữa màn hình */
@media (min-width: 720px) {
  html[data-view="web"] .modal-wrap { justify-content: center; padding: 32px; }
  html[data-view="web"] .modal {
    max-width: 460px; max-height: min(86vh, 760px); border-radius: 24px;
    transform: translateY(14px) scale(.97); opacity: 0;
    transition: transform .3s var(--ease-out), opacity .22s ease;
    box-shadow: 0 40px 80px -24px rgba(0,0,0,.65);
  }
  html[data-view="web"] .modal.wide { max-width: 600px; }
  html[data-view="web"] .modal-wrap.open .modal { opacity: 1; transform: none; }
  html[data-view="web"] .grip { display: none; }
  html[data-view="web"] .sheet-head { cursor: default; touch-action: auto; padding-top: 22px; }
  html[data-view="web"] .modal-x { top: 18px; }
  html[data-view="web"] .modal-body { padding-bottom: 22px; }
  html[data-view="web"] .modal-actions { padding-bottom: 18px; }
}

/* ---------- Lá xăm: bức liễn giấy dó treo ---------- */
.slip {
  --paper: #efe0bd;
  --paper-ink: #2b1d12;
  --silk: #7d1712;
  position: relative; max-width: 360px; margin: 0 auto; padding: 16px 0 0;
  --rx: 0deg; --ry: 0deg; --mx: 50%; --my: 0%;
  transform: perspective(900px) rotateX(var(--rx)) rotateY(var(--ry));
  transition: transform .5s var(--ease-out);
  filter: drop-shadow(0 18px 18px rgba(34, 20, 12, .32));
}
.slip.tilting { transition: transform .08s linear; }

/* dây treo + đinh */
.hanger {
  position: absolute; top: 0; left: 50%; width: 110px; height: 19px; translate: -50% 0;
  background:
    radial-gradient(circle at 50% 4px, #d8b46a 0 3.5px, #6b4a1f 4px 5px, transparent 5.5px),
    linear-gradient(to bottom right, transparent calc(50% - 1px), #5a3b22 calc(50% - .5px) calc(50% + .5px), transparent calc(50% + 1px)) left / 50% 100% no-repeat,
    linear-gradient(to bottom left, transparent calc(50% - 1px), #5a3b22 calc(50% - .5px) calc(50% + .5px), transparent calc(50% + 1px)) right / 50% 100% no-repeat;
}
/* trục gỗ trên / dưới, hai đầu núm */
.roller {
  position: relative; z-index: 2; display: block; height: 14px; margin: 0 -6px; border-radius: 7px;
  background: linear-gradient(180deg, #8a5a2e 0%, #c78f52 30%, #6e4120 70%, #3d2210 100%);
  box-shadow: 0 3px 4px -1px rgba(0,0,0,.45);
}
.roller::before, .roller::after {
  content: ''; position: absolute; top: -3px; width: 14px; height: 20px; border-radius: 5px;
  background: linear-gradient(180deg, #e8c27a, #b0802f 45%, #6f4c16);
  box-shadow: inset 0 0 0 1px rgba(60, 35, 8, .6);
}
.roller::before { left: -8px; }
.roller::after { right: -8px; }
.roller.bottom { height: 18px; border-radius: 9px; }
.roller.bottom::before, .roller.bottom::after { top: -2px; height: 22px; }

/* cuộn mở: lòng giấy trải dài theo hàng lưới (0fr → 1fr) nên trục dưới tự trôi xuống */
.scroll-reveal { display: grid; grid-template-rows: 1fr; }
.scroll-body { min-height: 0; overflow: hidden; margin: -2px 0; }

/* viền lụa gấm đỏ */
.scroll-silk {
  padding: 9px 9px 10px;
  background-color: var(--silk);
  background-image:
    radial-gradient(circle, rgba(238, 189, 85, .22) 0 1px, transparent 1.6px),
    radial-gradient(circle, rgba(238, 189, 85, .14) 0 1px, transparent 1.6px),
    linear-gradient(90deg, rgba(0,0,0,.25), transparent 12%, transparent 88%, rgba(0,0,0,.25));
  background-size: 9px 9px, 9px 9px, 100% 100%;
  background-position: 0 0, 4.5px 4.5px, 0 0;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.35);
}

/* lòng giấy dó: sợi giấy + ố vàng + mép sẫm */
.scroll-paper {
  position: relative; padding: 14px 14px 16px; color: var(--paper-ink);
  background-color: var(--paper);
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='p'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9 .045' numOctaves='3' seed='4'/%3E%3CfeColorMatrix values='0 0 0 0 .42  0 0 0 0 .3  0 0 0 0 .16  0 0 0 .5 -.12'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23p)'/%3E%3C/svg%3E"),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='s'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.012' numOctaves='3' seed='9'/%3E%3CfeColorMatrix values='0 0 0 0 .55  0 0 0 0 .36  0 0 0 0 .12  0 0 0 1.4 -.72'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23s)'/%3E%3C/svg%3E"),
    radial-gradient(ellipse 75% 65% at 50% 45%, transparent 55%, rgba(120, 72, 28, .32) 100%);
  box-shadow: inset 0 0 0 1px rgba(90, 55, 20, .35), inset 0 0 18px rgba(110, 66, 24, .25);
}
/* khung chỉ mực kép bên trong tờ giấy */
.scroll-paper::before {
  content: ''; position: absolute; inset: 7px; pointer-events: none;
  border: 1px solid rgba(125, 23, 18, .55); outline: 1px solid rgba(125, 23, 18, .3); outline-offset: -4px;
}
/* ánh sáng khi nghiêng */
.scroll-paper::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(circle at var(--mx) var(--my), rgba(255, 246, 220, .5), transparent 45%);
  opacity: 0; transition: opacity .3s; mix-blend-mode: soft-light;
}
.slip.tilting .scroll-paper::after { opacity: 1; }
.scroll-paper > * { position: relative; }

.slip-head { display: grid; grid-template-columns: 50px 1fr 54px; align-items: center; gap: 6px; }
.slip-no { width: 50px; color: #a3201a; transform: rotate(-4deg); mix-blend-mode: multiply; }
.slip-lvl { width: 54px; transform: rotate(5deg); mix-blend-mode: multiply; }
.lvl-0 .slip-lvl { color: #a3201a; }
.lvl-1 .slip-lvl { color: #9a5a12; }
.lvl-2 .slip-lvl { color: #2f6b50; }
.lvl-3 .slip-lvl { color: #6b4a22; }
.slip-title {
  margin: 0; text-align: center; font-family: var(--display); font-weight: 400;
  font-size: clamp(28px, 8.4vw, 34px); line-height: 1.05; color: #3a160c; text-wrap: balance;
  text-shadow: 0 1px 0 rgba(255, 240, 210, .5);
}
.slip-q { margin: 8px auto 0; max-width: 34ch; text-align: center; font-size: 13px; line-height: 1.4; color: rgba(43,29,18,.72); font-style: italic; font-family: var(--serif); }
.slip-q b { font-style: normal; color: var(--paper-ink); }
.paper-rule { display: flex; align-items: center; gap: 10px; margin: 6px 18px 6px; color: #a3201a; }
.paper-rule i { flex: 1; height: 1px; background: linear-gradient(90deg, transparent, rgba(125,23,18,.55), transparent); }
.paper-rule b { font-size: 12px; font-weight: 400; }
.slip-verse {
  margin: 0; text-align: center;
  font-family: var(--serif); font-style: italic; font-size: 14.5px; line-height: 1.6; color: #3b2a1a;
}
/* bốn ô kẻ như sổ cũ */
.slip-rows {
  list-style: none; margin: 12px 0 0; padding: 0;
  display: grid; grid-template-columns: 1fr 1fr;
  border-top: 1px solid rgba(90, 55, 20, .35); border-left: 1px solid rgba(90, 55, 20, .35);
}
.slip-rows li {
  display: grid; grid-template-columns: 28px 1fr; align-items: start; gap: 7px; padding: 8px 8px 9px;
  border-right: 1px solid rgba(90, 55, 20, .35); border-bottom: 1px solid rgba(90, 55, 20, .35);
}
.mini-seal { width: 28px; margin-top: 1px; color: #a3201a; mix-blend-mode: multiply; }
.slip-rows p { margin: 0; font-size: 12.8px; line-height: 1.4; color: #2b1d12; }
.slip-advice {
  margin: 10px 0 0; padding: 8px 12px; text-align: center;
  background: rgba(163, 32, 26, .08); border: 1px dashed rgba(163, 32, 26, .45); border-radius: 2px;
  font-family: var(--serif); font-size: 14.5px; line-height: 1.45; font-weight: 500;
}
.slip-advice b { display: block; margin-bottom: 2px; font-family: var(--font); font-size: 10.5px; letter-spacing: .2em; text-transform: uppercase; color: #a3201a; }

.slip.compact { max-width: 300px; }
.slip.compact .scroll-paper { padding: 12px 12px 14px; }
.slip.compact .slip-title { font-size: 24px; }
.slip.compact .slip-head { grid-template-columns: 40px 1fr 44px; }
.slip.compact .slip-verse { font-size: 13.5px; }
.slip.compact .slip-no { width: 40px; }
.slip.compact .slip-lvl { width: 44px; }

/* mở lá xăm: liễn trải từ trục trên xuống, chữ hiện dần */
.modal-wrap.open .modal.paper .scroll-reveal { animation: unroll 1s cubic-bezier(.3, .7, .2, 1) .15s both; }
.modal-wrap.open .modal.paper .scroll-paper > *,
.modal-wrap.open .modal.paper .slip-rows > li { animation: rise .5s var(--ease-out) both; }
.modal.paper .scroll-paper > :nth-child(1) { animation-delay: .45s !important; }
.modal.paper .scroll-paper > :nth-child(2) { animation-delay: .55s !important; }
.modal.paper .scroll-paper > :nth-child(3) { animation-delay: .65s !important; }
.modal.paper .scroll-paper > :nth-child(4) { animation-delay: .72s !important; }
.modal.paper .scroll-paper > :nth-child(5) { animation-delay: .8s !important; }
.modal.paper .scroll-paper > :nth-child(6) { animation-delay: .88s !important; }
.modal.paper .scroll-paper > :nth-child(7) { animation-delay: .96s !important; }
.modal.paper .slip-rows > li:nth-child(2) { animation-delay: 1.02s !important; }
.modal.paper .slip-rows > li:nth-child(3) { animation-delay: 1.08s !important; }
.modal.paper .slip-rows > li:nth-child(4) { animation-delay: 1.14s !important; }
@keyframes unroll { from { grid-template-rows: 0fr; } to { grid-template-rows: 1fr; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Keo ---------- */
.blocks-stage {
  display: flex; justify-content: center; gap: 22px; padding: 96px 0 8px; min-height: 200px; align-items: end;
  perspective: 620px; perspective-origin: 50% 20%;
}
/* mặt sàn nghiêng: mọi thứ của miếng keo nằm trong hệ toạ độ này (trục Z = hướng lên khỏi sàn) */
.mb { position: relative; width: 120px; height: 64px; transform-style: preserve-3d; transform: rotateX(56deg); }
.mb-ground { position: absolute; inset: 0; transform-style: preserve-3d; }
.mb-shadow {
  position: absolute; inset: 6px 4px 0; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(40, 18, 10, .7), rgba(40, 18, 10, .25) 60%, transparent);
  filter: blur(3px); opacity: .6; will-change: transform, opacity;
}
.mb-rot { position: absolute; inset: 0; transform-style: preserve-3d; will-change: transform; }
.mb-slice {
  position: absolute; inset: 0; display: block; transform-origin: 60px 30px;
  clip-path: path('M6 50 C9 20 36 4 60 4 C84 4 111 20 114 50 C113 59 104 62 95 57 C84 50 73 46 60 46 C47 46 36 50 25 57 C16 62 7 59 6 50 Z');
}
.mb-slice.edge { background: #2a0c07; }
/* mặt phẳng: gỗ sơn son nhạt, vân gỗ đồng tâm, không bóng */
.mb-slice.flat {
  background:
    repeating-radial-gradient(ellipse 70% 120% at 50% 115%, rgba(80, 18, 8, .22) 0 1.2px, transparent 1.6px 6px),
    radial-gradient(ellipse 90% 80% at 45% 30%, #e7825f, #c4482c 55%, #9b2c19);
}
/* mặt khum: sơn bóng, có vệt sáng */
.mb-slice.dome {
  background:
    radial-gradient(ellipse 34% 26% at 40% 30%, rgba(255, 228, 210, .85), rgba(255, 190, 160, .25) 60%, transparent 75%),
    radial-gradient(ellipse 80% 75% at 45% 40%, #e2553a, #b52e1c 55%, #7c180d);
}
.blocks-result { text-align: center; font-size: 15px; line-height: 1.55; min-height: 48px; margin: 6px 0 0; color: var(--ink-soft); }
.blocks-result b { font-family: var(--serif); font-size: 21px; color: var(--ink); }
.blocks-result.yes b { color: var(--jade); }
.blocks-result.no b { color: var(--son); }
.blocks-result.laugh b { color: var(--amber); }

/* ---------- Form ---------- */
.form { display: grid; gap: 14px; }
.form label, .form > span { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.form input {
  width: 100%; font: inherit; font-size: 16px; padding: 12px 14px; border-radius: 10px;
  color: var(--ink); background: #fffdf7; border: 1.5px solid var(--line);
  transition: border-color .2s, box-shadow .2s;
}
.form input:focus { outline: none; border-color: var(--son); box-shadow: 0 0 0 3px rgba(179,38,30,.12); }
.form.two { grid-template-columns: 1fr; }
@media (min-width: 420px) { .form.two { grid-template-columns: 1fr 1fr; } }
.mono { font-family: ui-monospace, Menlo, monospace !important; font-size: 13px !important; }

/* ---------- Sổ quẻ ---------- */
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab { flex: 1; border: 0; background: none; padding: 10px 4px; font-size: 14px; font-weight: 500; color: var(--ink-soft); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab em { font-style: normal; font-size: 11px; opacity: .7; }
.tab.on { color: var(--son); border-bottom-color: var(--son); }
.hist-list { list-style: none; margin: 4px 0 0; padding: 0; }
.hist-item {
  width: 100%; display: flex; align-items: center; gap: 14px; text-align: left;
  padding: 12px 4px; border: 0; border-bottom: 1px dashed var(--line); background: none;
  transition: background .2s, padding .25s var(--ease-out);
}
.hist-no { flex: none; min-width: 44px; text-align: center; font-family: var(--serif); font-weight: 700; color: var(--son); font-size: 17px; transition: transform .25s var(--ease-spring); }
.hist-main { display: grid; min-width: 0; }
.hist-main b { font-family: var(--serif); font-size: 15.5px; }
.hist-main small { font-size: 12px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (hover: hover) { .hist-item:hover { background: rgba(179,38,30,.05); padding-left: 10px; } .hist-item:hover .hist-no { transform: scale(1.1) rotate(-4deg); } }
.hist-item:active { background: rgba(179,38,30,.08); }
.empty { text-align: center; color: var(--ink-soft); padding: 28px 0 8px; font-family: var(--serif); font-style: italic; }
.link-btn { margin: 14px auto 0; display: block; background: none; border: 0; text-decoration: underline; font-size: 13px; }
.link-btn.danger { color: var(--son); }

/* ---------- Thiệp được gửi (nội dung trong thẻ treo) ---------- */
.gift { display: grid; justify-items: center; gap: 14px; padding: 14px 0 26px; text-align: center; }
.gift-kicker { margin: 0; font-family: var(--serif); font-style: italic; font-size: 15px; color: var(--cream-soft); }
.gift-box { width: 100%; gap: 2px; padding: 10px 12px 14px; }
.gift-box strong { font-family: var(--display); font-weight: 400; font-size: 40px; line-height: 1.08; color: var(--gold-soft); text-wrap: balance; overflow-wrap: anywhere; }
.gift-box small { font-family: var(--serif); font-style: italic; font-size: 15px; color: var(--cream-soft); }
@keyframes plqDrift { 0%, 100% { translate: 0 0; } 50% { translate: 6px -3px; } }

/* ---------- Đôi ta ---------- */
.score-seal { width: 120px; margin: 0 auto; color: var(--son); transform: rotate(-4deg); }
.verdict { text-align: center; line-height: 1.55; margin: 14px 0 16px; color: var(--ink-soft); }
.verdict b { font-family: var(--serif); font-size: 20px; color: var(--ink); }
.pair { display: grid; gap: 12px; }
@media (min-width: 560px) { .pair { grid-template-columns: 1fr 1fr; } }

/* ---------- Toast ---------- */
#toastRoot { position: fixed; left: 0; right: 0; bottom: calc(24px + env(safe-area-inset-bottom)); display: grid; justify-items: center; z-index: 80; pointer-events: none; }
.toast { background: var(--ink); color: var(--paper-2); padding: 10px 16px; border-radius: 999px; font-size: 14px; opacity: 0; transform: translateY(10px); transition: all .25s; }
.toast.show { opacity: 1; transform: none; }


/* ---------- Hoạ tiết Đông Sơn ---------- */
.decor { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; color: var(--gold); }
.decor .d { position: absolute; display: block; opacity: .13; }
/* lớp hạt nhiễu đen, rất nhẹ, trên nền */
.decor::after {
  content: ''; position: absolute; inset: 0; pointer-events: none; opacity: .28;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.1' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 .6 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
  background-size: 180px 180px;
}
.decor .motif { display: block; width: 100%; height: auto; overflow: visible; }
.d-sun { width: 110px; top: 70px; right: -18px; opacity: .16 !important; animation: spin 90s linear infinite; }
.d-bird1 { display: none; width: 150px; animation: drift 14s ease-in-out infinite alternate; } /* mobile: chim lẻ bị cắt mép và đè lên vành trống → ẩn */
.d-bird2 { width: 110px; top: 8%; left: 34%; transform: scaleX(-1); opacity: .09 !important; }
.d-deer { width: 120px; bottom: 16%; right: -14px; }
.d-cloud1 { width: 190px; top: 62%; left: -60px; animation: drift 18s ease-in-out infinite alternate-reverse; }
.d-cloud2 { width: 160px; bottom: 3%; right: 20%; opacity: .08 !important; }
.d-corner { width: 64px; opacity: .22 !important; }
.d-corner.tl { top: calc(8px + env(safe-area-inset-top)); left: 8px; display: none; }
.d-corner.br { bottom: 8px; right: 8px; transform: rotate(180deg); }
@keyframes drift { from { translate: 0 0; } to { translate: 18px -10px; } }
@keyframes spin { to { rotate: 360deg; } }
.page { position: relative; z-index: 1; }
.top { z-index: 20; }

/* mặt trống đồng sau ống xăm */
.drum {
  position: absolute; z-index: 0; left: 50%; top: -10px; width: min(100%, 420px); aspect-ratio: 1;
  translate: -50% 0; color: var(--gold); opacity: .2; pointer-events: none;
  -webkit-mask-image: radial-gradient(closest-side, #000 72%, transparent 100%);
          mask-image: radial-gradient(closest-side, #000 72%, transparent 100%);
}
.drum .motif { width: 100%; height: 100%; display: block; animation: spin 160s linear infinite; }
.altar > #jarMount { z-index: 2; }

@media (min-width: 720px) {
  html[data-view="web"] .decor .d { opacity: .16; }
  html[data-view="web"] .d-sun { width: 150px; right: 8%; top: 90px; }
  html[data-view="web"] .d-bird1 { display: block; width: 220px; left: 4%; top: 30%; }
  html[data-view="web"] .d-bird2 { width: 160px; left: auto; right: 12%; top: 46%; }
  html[data-view="web"] .d-deer { width: 170px; right: 9%; bottom: 12%; }
  html[data-view="web"] .d-cloud1 { width: 260px; left: 3%; top: 64%; }
  html[data-view="web"] .d-cloud2 { width: 220px; right: 30%; }
  html[data-view="web"] .d-corner.tl { display: block; }
  html[data-view="web"] .d-corner { width: 90px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ---------- Thẻ treo (kết quả quẻ) ---------- */
.hang-wrap { position: fixed; inset: 0; z-index: 70;
  --hg-rim: #7e161d; --hg-top: #6b1219; --hg-mid: #551016; --hg-bot: #3f0a0f;
  --hg-panel: rgba(20, 2, 4, .38); --hg-line: rgba(238, 189, 85, .4); --hg-gold: #eebd55; --hg-text: #fbf0da; }
.hang-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .8); opacity: 0; transition: opacity .35s ease; }
.hang-wrap.open .hang-backdrop { opacity: 1; }
.hang-scroll {
  position: absolute; inset: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none;
  display: grid; justify-items: center; align-items: center;
  padding: calc(30px + env(safe-area-inset-top)) 14px calc(16px + env(safe-area-inset-bottom));
}
.hang-scroll::-webkit-scrollbar { display: none; }
.hang-stage { position: relative; width: min(100%, 360px); display: flex; flex-direction: column; align-items: center; outline: none; transform: translateY(-115vh); }
.hang-wrap.open .hang-stage { animation: hangDrop .95s cubic-bezier(.3, .9, .3, 1) both; }
.hang-wrap.closing .hang-stage { animation: hangLift .4s cubic-bezier(.6, 0, .9, .4) both; }
.hang-wrap.closing .hang-backdrop { opacity: 0; }
@keyframes hangDrop {
  0% { transform: translateY(-115vh); }
  58% { transform: translateY(16px); }
  74% { transform: translateY(-7px); }
  88% { transform: translateY(3px); }
  100% { transform: translateY(0); }
}
@keyframes hangLift { from { transform: translateY(0); } to { transform: translateY(-115vh); } }

.hg-card { position: relative; width: 100%; transform-origin: 50% -40px; filter: drop-shadow(0 24px 26px rgba(0, 0, 0, .5)); }
.hang-wrap.open .hg-card { animation: hangSway 2.6s ease-in-out .75s both; }
@keyframes hangSway { 0% { rotate: 0deg; } 20% { rotate: 2.6deg; } 45% { rotate: -1.8deg; } 70% { rotate: .9deg; } 100% { rotate: 0deg; } }
.hg-string { position: absolute; left: 50%; bottom: calc(100% - 14px); width: 2px; height: 120vh; translate: -50% 0; background: linear-gradient(transparent, var(--hg-rim) 30%); }
.hg-knot { position: absolute; left: 50%; top: 12px; width: 9px; height: 9px; translate: -50% 0; border-radius: 50%; background: #3a0410; box-shadow: 0 0 0 2px var(--hg-gold); z-index: 1; }
.hg-crown { display: block; width: 100%; height: 44px; margin-bottom: -1px; overflow: visible; }
.hg-crown-rim { fill: var(--hg-rim); }
.hg-crown-fill { fill: var(--hg-top); }
.hg-crown-line { fill: none; stroke: var(--hg-gold); stroke-width: 1.6; }
.hg-body {
  position: relative; padding: 2px 26px 48px; border-radius: 0 0 16px 16px; color: var(--hg-text);
  border: 6px solid var(--hg-rim); border-top: 0;
  background:
    radial-gradient(ellipse 80% 40% at 50% 18%, rgba(238, 189, 85, .14), transparent 70%),
    linear-gradient(180deg, var(--hg-top) 0%, var(--hg-mid) 55%, var(--hg-bot) 100%);
}
.hg-body::after {
  content: ''; position: absolute; left: 6px; right: 6px; top: -1px; bottom: 8px; pointer-events: none;
  border: 1.6px solid var(--hg-gold); border-top: 0; border-radius: 0 0 9px 9px;
}
.hg-body::before {
  content: ''; position: absolute; inset: 0; pointer-events: none; opacity: .4; mix-blend-mode: overlay; border-radius: inherit;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 .35 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
.hg-key { position: absolute; width: 16px; height: 16px; fill: none; stroke: var(--hg-gold); stroke-width: 2; stroke-linecap: square; }
.hg-key.tl { left: 11px; top: 2px; }
.hg-key.tr { right: 11px; top: 2px; transform: scaleX(-1); }
.hg-key.bl { left: 11px; bottom: 13px; transform: scaleY(-1); }
.hg-key.br { right: 11px; bottom: 13px; transform: scale(-1); }
.hg-lantern { position: absolute; top: 20px; width: 13px; height: 28px; transform-origin: 50% 0; animation: lanternSwing 3.2s ease-in-out infinite; }
.hg-lantern.l { left: 9px; }
.hg-lantern.r { right: 9px; animation-delay: -1.6s; }
.hg-lantern .lb { fill: #c8281f; stroke: var(--hg-gold); stroke-width: 1.4; }
.hg-lantern .ln { fill: none; stroke: var(--hg-gold); stroke-width: 1.3; stroke-linecap: round; }
@keyframes lanternSwing { 0%, 100% { rotate: -5deg; } 50% { rotate: 5deg; } }
.hg-cloud { position: absolute; z-index: 2; width: 64px; filter: drop-shadow(0 3px 4px rgba(40, 0, 6, .45)); animation: plqDrift 6s ease-in-out infinite; }
.hg-cloud .cf { fill: #fbe0a6; stroke: #c98a3a; stroke-width: 1.4; }
.hg-cloud .cs { fill: none; stroke: #c98a3a; stroke-width: 1.4; stroke-linecap: round; }
.hg-cloud.c1 { right: -20px; top: 22px; }
.hg-cloud.c2 { left: -38px; top: 52%; width: 64px; animation-delay: -3s; animation-direction: reverse; }
.hg-content { position: relative; }

/* túi nút dưới chân thẻ, có mái cong nhô lên ở giữa */
.hg-pocket {
  position: relative; z-index: 1; width: calc(100% + 14px); margin-top: -36px;
  display: grid; grid-template-columns: 1fr; gap: 10px; padding: 12px 14px 13px;
  border-radius: 18px; background: linear-gradient(180deg, var(--hg-rim), #5a1016);
  box-shadow: inset 0 0 0 2px var(--hg-gold), inset 0 0 0 5px #6b1219, inset 0 0 0 6px rgba(246, 207, 126, .5), 0 14px 22px -12px rgba(0, 0, 0, .6);
}
.hg-pocket[data-count="2"] { grid-template-columns: 1fr 1fr; }
.hg-pocket-top { position: absolute; left: 22%; width: 56%; top: -17px; height: 18px; overflow: visible; pointer-events: none; }
.hg-pocket-top .pf { fill: var(--hg-rim); }
.hg-pocket-top .pl { fill: none; stroke: var(--hg-gold); stroke-width: 2; }
.hg-btn {
  position: relative; min-height: 50px; border-radius: 10px; border: 0; font: inherit; font-weight: 700; font-size: 17px; cursor: pointer;
  transition: transform .15s var(--ease-out), filter .15s;
}
.hg-btn.primary { color: #7a2a06; background: linear-gradient(180deg, #ffe6a3, #f4c35a 60%, #e5a83a); box-shadow: inset 0 -2px 0 rgba(150, 80, 10, .35), 0 0 0 1.5px #fff2c8; }
.hg-btn.soft { color: #a3142a; background: linear-gradient(180deg, #ffe4e4, #f7b4b6); box-shadow: inset 0 -2px 0 rgba(150, 30, 40, .25), 0 0 0 1.5px #ffeeee; }
.hg-btn:active { transform: scale(.97); filter: brightness(.96); }
@media (hover: hover) { .hg-btn:hover { filter: brightness(1.05); } }
.hg-tie { width: 2px; height: 18px; background: rgba(255, 243, 226, .55); }
.hg-x {
  width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; cursor: pointer;
  background: rgba(255, 255, 255, .06); border: 1.5px solid rgba(255, 243, 226, .8); color: var(--hg-text);
}
.hg-x svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.hg-x:active { transform: scale(.94); }

/* nội dung quẻ trên thẻ đỏ */
.pq { display: grid; gap: 8px; }
.pq-head { display: grid; grid-template-columns: 54px 1fr 54px; align-items: center; gap: 4px; }
.pq-seal { width: 54px; color: var(--hg-gold); }
.pq-head .pq-seal:first-child { transform: rotate(-5deg); }
.pq-head .pq-seal:last-child { transform: rotate(5deg); }
.pq-title { text-align: center; display: grid; gap: 2px; }
.pq-title small { font-size: 10.5px; letter-spacing: .04em; white-space: nowrap; text-transform: uppercase; color: var(--hg-gold); }
.pq-title h3 {
  margin: 0; font-family: var(--display); font-weight: 400; font-size: 36px; line-height: 1.02; color: var(--gold-soft);
  text-shadow: 0 2px 0 rgba(0, 0, 0, .35); text-wrap: balance;
}
.pq-q { margin: -2px 0 0; text-align: center; font-family: var(--serif); font-style: italic; font-size: 14px; line-height: 1.4; color: var(--cream-soft); }
.pq-q b { font-style: normal; color: var(--hg-text); }
.pq-box { display: grid; gap: 4px; padding: 9px 12px 11px; border: 1px solid var(--hg-line); border-radius: 10px; background: var(--hg-panel); text-align: center; }
.pq-label, .pq-rows b, .pq-advice b { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--hg-gold); }
.pq-label::before, .pq-label::after { content: '◆'; font-size: 6px; vertical-align: middle; margin: 0 7px; opacity: .8; }
.pq-verse { margin: 0; text-align: center; font-family: var(--serif); font-size: 17.5px; line-height: 1.42; text-wrap: balance; color: var(--hg-text); }
.pq-rows { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pq-rows li { min-width: 0; padding: 7px 10px 8px; border-radius: 10px; background: var(--hg-panel); border: 1px solid rgba(238, 189, 85, .22); }
.pq-rows p { margin: 2px 0 0; font-size: 14px; line-height: 1.4; color: var(--hg-text); }
.pq-advice { margin: 0; padding: 9px 12px 10px; border-radius: 10px; background: var(--hg-panel); border: 1px solid rgba(238, 189, 85, .22); font-size: 15.5px; line-height: 1.4; color: var(--hg-text); }
.pq-advice b { display: block; margin-bottom: 2px; }
.hang-wrap.open .pq > * { animation: rise .5s var(--ease-out) both; }
.hang-wrap.open .pq > :nth-child(1) { animation-delay: .7s; }
.hang-wrap.open .pq > :nth-child(2) { animation-delay: .8s; }
.hang-wrap.open .pq > :nth-child(3) { animation-delay: .88s; }
.hang-wrap.open .pq > :nth-child(4) { animation-delay: .96s; }
.hang-wrap.open .pq > :nth-child(5) { animation-delay: 1.04s; }
@media (prefers-reduced-motion: reduce) {
  .hang-wrap.open .hang-stage, .hang-wrap.open .hg-card, .hang-wrap.open .pq > *, .hg-lantern, .hg-cloud { animation: none; transform: none; }
}
