/* ---------- 既有 modal：只把外框改透明，遮罩沿用頁面原本的 backdrop ---------- */
#townNews .modal-content {
  background: transparent;
  border: 0;
  box-shadow: none;
}
#townNews .modal-body {
  padding: 0;
}

/* ---------- 變數 ---------- */
.cvp-popup,
.cvp-close {
  --espresso: #3a2218;
  --roast: #6b3e26;
  --caramel: #d9963f;
  --crema: #f6e7cf;
  --milk: #fffbf4;
  --cherry: #c8323c;
  --cherry-dk: #9e2230;
  --font:
    "Noto Sans TC", "Noto Sans", "PingFang TC", "Microsoft JhengHei", system-ui,
    sans-serif;
  font-family: var(--font);
  font-size: 16px; /* 用 px 固定，不受頁面 html 字級（如 62.5%）影響 */
  line-height: 1.5;
  color: var(--espresso);
  text-align: left;
}

/* ---------- 隔離頁面全域樣式（h2 / p / dl / a / img 等） ----------
:where() 不增加權重，後面的 .cvp-* 規則仍可正常覆蓋 */
.cvp-popup,
.cvp-popup *,
.cvp-popup *::before,
.cvp-popup *::after,
.cvp-close {
  box-sizing: border-box;
}
.cvp-popup :where(h2, p, dl, dt, dd, a, span, div) {
  margin: 0;
  padding: 0;
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  font-style: normal;
  line-height: inherit;
  letter-spacing: inherit;
  color: inherit;
  text-transform: none;
  text-decoration: none;
  text-shadow: none;
  background: none;
  border: 0;
}
.cvp-popup :where(img, svg) {
  max-width: none;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: none;
  vertical-align: top;
}
.cvp-popup a.cvp-cta:hover,
.cvp-popup a.cvp-cta:focus,
.cvp-popup a.cvp-cta:visited {
  color: #fff;
  text-decoration: none;
}

/* ---------- 彈窗內容 ---------- */
.cvp-popup {
  --w: min(340px, 86vw);
  position: relative;
  width: var(--w);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  outline: none;
}
.cvp-popup > * {
  position: relative;
  z-index: 2;
}

/* ---------- 光暈：貼合票券輪廓的柔光，隨票券吐出才亮起 ---------- */
.cvp-halo {
  position: absolute !important;
  z-index: 1 !important;
  left: 4%;
  right: 4%;
  top: 24%;
  bottom: 17%;
  border-radius: 48px;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(
    70% 60% at 50% 50%,
    rgba(255, 244, 230, 0.95),
    rgba(255, 214, 190, 0.55) 60%,
    rgba(255, 200, 180, 0) 100%
  );
  filter: blur(26px);
}
.cvp-is-open .cvp-halo {
  animation: cvp-bloom 1s ease 1.45s forwards;
}
@keyframes cvp-bloom {
  0% {
    opacity: 0;
    transform: scale(0.85);
  }
  60% {
    opacity: 1;
    transform: scale(1.04);
  }
  100% {
    opacity: 0.9;
    transform: scale(1);
  }
}

/* ---------- 跑出的配件：從票券後方往外迸出，帶自身光暈與速度線 ---------- */
/* ✏️ 調整配件：下方 .cvp-d-* 可改大小(width)、位置(left/right/top)、飛出方向(--dx/--dy)、出場時間(--delay)、速度線顏色(--tc) */
.cvp-deco {
  position: absolute !important;
  pointer-events: none;
  opacity: 0;
}
.cvp-deco img {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: auto;
  transform: rotate(var(--r));
  filter: drop-shadow(0 0 5px rgba(255, 248, 236, 0.95))
    drop-shadow(0 0 14px rgba(255, 214, 180, 0.7));
}
.cvp-deco.cvp-front {
  z-index: 4 !important;
}
.cvp-deco.cvp-back {
  z-index: 1 !important;
}
.cvp-deco.cvp-back img {
  filter: blur(1.4px) drop-shadow(0 0 10px rgba(255, 236, 214, 0.9));
} /* 景深：後方配件略糊 */

/* 速度線：由配件中心朝票券方向（來的方向）拖出，角度由 JS 依 --dx/--dy 算出 --a */
.cvp-trail {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  z-index: 0;
  transform: rotate(var(--a, 0deg));
}
.cvp-trail span {
  position: absolute;
  left: 6px;
  border-radius: 4px;
  transform-origin: left center;
  opacity: 0;
  background: linear-gradient(
    90deg,
    var(--tc, #fff) 0%,
    color-mix(in srgb, var(--tc, #fff) 50%, transparent) 40%,
    transparent 100%
  );
  box-shadow: 0 0 6px rgba(255, 240, 220, 0.7);
  filter: blur(0.5px);
}
.cvp-trail span:nth-child(1) {
  top: -12px;
  width: 62px;
  height: 4px;
}
.cvp-trail span:nth-child(2) {
  top: -3px;
  width: 104px;
  height: 6px;
}
.cvp-trail span:nth-child(3) {
  top: 9px;
  width: 52px;
  height: 4px;
}
.cvp-deco.cvp-back .cvp-trail span {
  filter: blur(1.4px);
}

/* --dx/--dy：起點相對最終位置的位移（指向票券中心）；--delay：出場時間 */
.cvp-d-bean1 {
  width: 44px;
  left: -9%;
  top: 30%;
  --r: -20deg;
  --dx: 110px;
  --dy: 60px;
  --delay: 1.65s;
  --tc: #b9784a;
}
.cvp-d-milk {
  width: 54px;
  right: -7%;
  top: 36%;
  --r: 12deg;
  --dx: -110px;
  --dy: 40px;
  --delay: 1.7s;
  --tc: #8ec2ec;
}
.cvp-d-heart1 {
  width: 38px;
  left: -6%;
  top: 58%;
  --r: -14deg;
  --dx: 100px;
  --dy: -20px;
  --delay: 1.75s;
  --tc: #f07a83;
}
.cvp-d-heart2 {
  width: 26px;
  right: -4%;
  top: 21%;
  --r: 16deg;
  --dx: -90px;
  --dy: 90px;
  --delay: 1.68s;
  --tc: #f7b9bd;
}
.cvp-d-bean2 {
  width: 34px;
  right: -8%;
  top: 63%;
  --r: 35deg;
  --dx: -100px;
  --dy: -30px;
  --delay: 1.8s;
  --tc: #b9784a;
}
.cvp-d-heart3 {
  width: 22px;
  left: 4%;
  top: 16%;
  --r: -8deg;
  --dx: 80px;
  --dy: 110px;
  --delay: 1.72s;
  --tc: #f7b9bd;
}
.cvp-d-bean3 {
  width: 28px;
  left: -2%;
  top: 76%;
  --r: 60deg;
  --dx: 90px;
  --dy: -80px;
  --delay: 1.85s;
  --tc: #b9784a;
}
.cvp-d-spark {
  width: 30px;
  right: 6%;
  top: 77%;
  --r: 0deg;
  --dx: -70px;
  --dy: -90px;
  --delay: 1.78s;
  --tc: #f5cf7a;
}

.cvp-is-open .cvp-deco {
  animation:
    cvp-burst 0.7s cubic-bezier(0.15, 1.25, 0.35, 1) var(--delay) forwards,
    cvp-float 2.4s ease-in-out calc(var(--delay) + 0.7s) 1; /* 只漂一次，整體動態約 5 秒內結束（WCAG 2.2.2） */
}
.cvp-is-open .cvp-trail span {
  animation: cvp-streak 0.9s cubic-bezier(0.2, 0.8, 0.3, 1) var(--delay)
    forwards;
}
.cvp-is-open .cvp-trail span:nth-child(1) {
  animation-delay: calc(var(--delay) + 0.05s);
}
.cvp-is-open .cvp-trail span:nth-child(3) {
  animation-delay: calc(var(--delay) + 0.1s);
}
@keyframes cvp-burst {
  0% {
    opacity: 0;
    transform: translate(var(--dx), var(--dy)) scale(0.2);
    filter: blur(6px);
  }
  35% {
    opacity: 1;
    filter: blur(3px);
  }
  100% {
    opacity: 1;
    transform: translate(0, 0) scale(1);
    filter: blur(0);
  }
}
/* 衝出時拉長，停下後縮短並留下淡淡殘影 */
@keyframes cvp-streak {
  0% {
    opacity: 0;
    transform: scaleX(0.2);
  }
  30% {
    opacity: 1;
    transform: scaleX(1.5);
  }
  100% {
    opacity: 0.7;
    transform: scaleX(0.6);
  }
}
@keyframes cvp-float {
  0%,
  100% {
    translate: 0 0;
  }
  50% {
    translate: 0 -8px;
  }
}

/* 標題 */
.cvp-popup-title::before {
  content: "";
  position: absolute;
  inset: -6px -18px;
  z-index: -1;
  border-radius: 20px;
  background: rgba(255, 236, 222, 0.28);
  filter: blur(12px);
}
.cvp-popup-title {
  margin: 0 0 18px;
  font-size: clamp(25px, 7.6vw, 32px);
  font-weight: 900;
  letter-spacing: 0.04em;
  color: var(--milk);
  text-shadow:
    0 0 2px #fff,
    0 0 6px rgba(255, 255, 255, 0.9),
    0 0 14px rgba(255, 214, 186, 0.8),
    0 2px 0 var(--roast);
  opacity: 0;
  transform: translateY(10px);
}

/* ---------- 出券機 ---------- */
.cvp-machine {
  position: relative;
  width: 100%;
  z-index: 3;
  opacity: 0;
  transform: translateY(-14px) scale(0.96);
}
.cvp-machine-goods {
  position: relative;
  height: 56px;
  margin: 0 10%;
  overflow: hidden;
}
.cvp-machine-goods img {
  position: absolute;
  left: 50%;
  width: 70px;
  height: auto;
  transform: translateX(-50%) rotate(15deg) translateY(0%);
  transform-origin: center bottom;
}
.cvp-machine-body {
  position: relative;
  height: 62px;
  border-radius: 22px 22px 14px 14px;
  background: linear-gradient(
    180deg,
    #8a5233 0%,
    var(--roast) 45%,
    #4c2b1c 100%
  );
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.18),
    inset 0 -4px 0 rgba(0, 0, 0, 0.25),
    0 10px 18px rgba(0, 0, 0, 0.3);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 12px 20px 0;
  border-bottom: 3px solid #2a170f;
}
.cvp-machine-body span {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--crema);
  opacity: 0.85;
  letter-spacing: 0.08em;
}
.cvp-machine-body span:last-child {
  letter-spacing: 0.04em;
}
.cvp-machine-slot {
  /* 出券口上半：屬於機身，會蓋住票券頂端 */
  position: absolute;
  left: 7%;
  right: 7%;
  bottom: 0;
  height: 9px;
  border-radius: 9px 9px 0 0;
  background: #1e110b;
  box-shadow: inset 0 3px 4px rgba(0, 0, 0, 0.7);
}
.cvp-machine-slot::before {
  /* 出券指示 */
  content: "";
  position: absolute;
  left: 50%;
  top: -16px;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--caramel);
}
.cvp-machine.cvp-printing .cvp-machine-body {
  animation: cvp-shake 0.12s linear 8;
}
@keyframes cvp-shake {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(1px);
  }
}

/* ---------- 票券 ---------- */
.cvp-ticket-clip {
  position: relative;
  width: 88%;
  margin-top: -3px;
  padding: 0 10px 22px;
  z-index: 2;
  clip-path: inset(0 -80px -80px -80px);
}
.cvp-ticket-clip::before {
  /* 出券口下半：在票券後方，票券從這裡穿出 */
  content: "";
  position: absolute;
  top: 0;
  left: 3px;
  right: 3px;
  height: 10px;
  border-radius: 0 0 10px 10px;
  background: #1e110b;
  box-shadow:
    inset 0 -2px 3px rgba(0, 0, 0, 0.6),
    0 2px 0 rgba(255, 255, 255, 0.18);
}
.cvp-ticket {
  position: relative;
  z-index: 1;
}
.cvp-ticket {
  transform: translateY(-104%);
  filter: drop-shadow(0 0 2px rgba(255, 255, 255, 0.9))
    drop-shadow(0 0 14px rgba(255, 236, 218, 0.85))
    drop-shadow(0 0 34px rgba(255, 196, 170, 0.55));
}
.cvp-ticket-main {
  background: var(--milk);
  position: relative;
}
/* 微露條碼：只露出下半段、不顯示號碼，上方像是還留在出券口裡 */
.cvp-barcode-peek {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  height: 28px;
  margin: -24px -20px 16px;
  padding-bottom: 8px;
  overflow: hidden;
  border-bottom: 2px dashed rgba(107, 62, 38, 0.3);
}
.cvp-barcode {
  display: flex;
  width: 210px;
  height: 44px;
  flex: none;
}
.cvp-barcode span {
  display: block;
  height: 100%;
  background: var(--espresso);
}

.cvp-name-barcode {
  display: flex;
  justify-content: center;
  margin-top: 10px;
}
.cvp-name-barcode .cvp-barcode {
  height: 30px;
}

.cvp-ticket-main {
  padding: 24px 20px 34px;
  text-align: center;
  background:
    radial-gradient(
      120% 70% at 50% 62%,
      var(--crema) 0%,
      rgba(246, 231, 207, 0) 60%
    ),
    linear-gradient(
      115deg,
      rgba(255, 214, 214, 0.45) 0%,
      rgba(255, 255, 255, 0) 38%,
      rgba(255, 255, 255, 0) 62%,
      rgba(205, 240, 226, 0.55) 100%
    ),
    var(--milk);
  /* 底部鋸齒：上方實色 + 底部固定 12px 的圓孔帶，兩層重疊 2px，避免高度有小數時底緣殘留一條線 */
  -webkit-mask:
    linear-gradient(#000, #000) top center/100% calc(100% - 10px) no-repeat,
    radial-gradient(circle 7px at 50% 100%, #0000 96%, #000) bottom center/24px
      12px repeat-x;
  mask:
    linear-gradient(#000, #000) top center/100% calc(100% - 10px) no-repeat,
    radial-gradient(circle 7px at 50% 100%, #0000 96%, #000) bottom center/24px
      12px repeat-x;
}
.cvp-ticket-month {
  display: inline-block;
  margin: 6px 0 10px;
  padding: 4px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  color: var(--cherry-dk);
  background: rgba(200, 50, 60, 0.1);
}
.cvp-ticket-name {
  margin: 0;
  font-size: clamp(24px, 8vw, 32px);
  font-weight: 900;
  line-height: 1.18;
  color: var(--espresso);
  letter-spacing: 0.03em;
}
.cvp-ticket-name .cvp-ticket-hl {
  font-size: clamp(28px, 10vw, 36px);
  margin-bottom: 1rem;
  color: #c8323c;
}
.cvp-ticket-art {
  display: block;
  width: 80%;
  height: auto;
  margin: 12px auto 0;
}

/* ---------- CTA 與關閉 ---------- */
.cvp-sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.cvp-cta {
  display: block;
  text-align: center;
  text-decoration: none;
  margin-top: 6px;
  width: 84%;
  padding: 15px 0;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
  font-size: 19px;
  font-weight: 900;
  letter-spacing: 0.08em;
  color: #fff;
  background: linear-gradient(
    180deg,
    #de4a52,
    var(--cherry) 55%,
    var(--cherry-dk)
  );
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.35),
    0 6px 0 #7a1824,
    0 12px 20px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transform: translateY(10px);
  transition:
    transform 0.12s ease,
    box-shadow 0.12s ease;
}
.cvp-cta:active {
  transform: translateY(4px) !important;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.35),
    0 2px 0 #7a1824,
    0 6px 12px rgba(0, 0, 0, 0.3);
}
.cvp-close {
  -webkit-appearance: none;
  appearance: none;
  padding: 0;
  font: inherit;
  margin: 26px auto 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid rgba(255, 255, 255, 0.7);
  background: rgba(255, 255, 255, 0.12);
  display: grid;
  place-items: center;
  opacity: 0;
}
.cvp-close svg {
  width: 18px;
  height: 18px;
}
.cvp-cta:focus-visible,
.cvp-close:focus-visible {
  outline: 3px solid var(--caramel);
  outline-offset: 4px;
}

/* ---------- 進場動畫 ---------- */
.cvp-is-open .cvp-machine {
  animation: cvp-drop 0.45s cubic-bezier(0.2, 1.4, 0.4, 1) 0.1s forwards;
}
.cvp-is-open .cvp-popup-title {
  animation: cvp-rise 0.4s ease 0.05s forwards;
}
.cvp-is-open .cvp-ticket {
  animation: cvp-print 1.3s cubic-bezier(0.5, 0.05, 0.3, 1) 0.55s forwards;
}
.cvp-is-open .cvp-cta {
  animation: cvp-rise 0.35s ease 1.85s forwards;
}
.cvp-is-open .cvp-close {
  animation: cvp-fade 0.3s ease 2s forwards;
}
@keyframes cvp-drop {
  to {
    opacity: 1;
    transform: none;
  }
}
@keyframes cvp-rise {
  to {
    opacity: 1;
    transform: none;
  }
}
@keyframes cvp-fade {
  to {
    opacity: 1;
  }
}
@keyframes cvp-print {
  0% {
    transform: translateY(-104%);
  }
  12% {
    transform: translateY(-92%);
  }
  22% {
    transform: translateY(-90%);
  }
  85% {
    transform: translateY(2%);
  }
  100% {
    transform: translateY(0);
  }
}

/* ---------- 矮螢幕（如 iPhone SE）：壓縮間距，讓關閉按鈕不必捲動就看得到 ---------- */
@media (max-height: 760px) {
  .cvp-popup-title {
    margin-bottom: 10px;
    font-size: clamp(22px, 6.6vw, 28px);
  }
  .cvp-machine-goods {
    height: 40px;
  }
  .cvp-machine-body {
    height: 54px;
    padding-top: 9px;
  }
  .cvp-ticket-main {
    padding-bottom: 26px;
  }
  .cvp-barcode-peek {
    height: 24px;
    margin-bottom: 10px;
  }
  .cvp-ticket-month {
    margin: 2px 0 6px;
  }
  .cvp-ticket-name {
    font-size: clamp(24px, 7vw, 30px);
  }
  .cvp-ticket-art {
    width: 52%;
    margin: 8px auto 0;
  }
  .cvp-ticket-clip {
    padding-bottom: 14px;
  }
  .cvp-cta {
    padding: 12px 0;
    font-size: 17px;
  }
  .cvp-close {
    margin-top: 16px;
  }
  .cvp-name-barcode {
    margin-top: 6px;
  }
  .cvp-name-barcode .cvp-barcode {
    height: 22px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cvp-is-open .cvp-machine,
  .cvp-is-open .cvp-popup-title,
  .cvp-is-open .cvp-ticket,
  .cvp-is-open .cvp-cta,
  .cvp-is-open .cvp-close {
    animation: none;
    opacity: 1;
    transform: none;
  }
  .cvp-is-open .cvp-halo {
    animation: none;
    opacity: 1;
  }
  .cvp-is-open .cvp-deco {
    animation: none;
    opacity: 1;
  }
  .cvp-is-open .cvp-trail span {
    animation: none;
    opacity: 0.7;
    transform: scaleX(0.6);
  }
}
