/* ==========================================================================
   SaiGonGiaiTri — tấm vé đổi tên miền

   Bảng màu và nhịp lấy từ short-drama (Tailwind v4 mặc định):
   zinc-950 nền, zinc-900 panel, zinc-800 viền, zinc-400 chữ phụ, red-500 accent.
   Giá trị ghi dạng oklch đúng như build của short-drama sinh ra, không phải
   hex pha lại, để hai bên không lệch màu theo thời gian.

   Hình dáng vẫn là một tấm vé xé: nền tối phẳng, không gradient, không kính mờ.
   ========================================================================== */

:root {
  /* bề mặt */
  --bg:          oklch(14.1% 0.005 285.823);  /* zinc-950 */
  --panel:       oklch(21%   0.006 285.885);  /* zinc-900 */
  --panel-soft:  oklch(22.5% 0.006 285.9);    /* giấy cuống vé, nhích khỏi panel */
  --line:        oklch(27.4% 0.006 286.033);  /* zinc-800 */
  --line-strong: oklch(37%   0.013 285.805);  /* zinc-700 */

  /* chữ */
  --ink:         #ffffff;
  --muted:       oklch(70.5% 0.015 286.067);  /* zinc-400 */
  --dim:         oklch(64% 0.014 286);        /* giữa zinc-500 và zinc-400: 4.9:1, vẫn lùi hơn zinc-400 */

  /* accent — một màu, dùng cho con dấu và đường xé */
  --accent:      oklch(63.7% 0.237 25.331);   /* red-500 */
  --accent-soft: oklch(70.4% 0.191 22.216);   /* red-400 */
  --accent-deep: oklch(57.7% 0.245 27.325);   /* red-600: nền nút, trắng đạt 4.77:1 */
  --accent-pale: oklch(80.8% 0.114 19.571);   /* red-300 */

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", "Noto Sans", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
               "Liberation Mono", "Courier New", monospace;

  /* nhịp chuyển động của short-drama (constants/motion.ts) */
  --motion-ms: 460ms;
  --motion-ease: cubic-bezier(0.22, 1.12, 0.36, 1);

  --pad-x: clamp(20px, 4vw, 40px);
  --pad-y: clamp(24px, 4.5vh, 40px);

  --notch-a: 100% 0;
  --notch-b: 100% 100%;
  --notch-stub-a: 0 0;
  --notch-stub-b: 0 100%;
}

*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background-color: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: clamp(12px, 3vw, 40px);
}

.sr {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   Tấm vé
   -------------------------------------------------------------------------- */

.ticket {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  width: min(1080px, 100%);
  min-height: min(560px, calc(100dvh - 2 * clamp(12px, 3vw, 40px)));
  isolation: isolate;
}

.ticket__body {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: clamp(24px, 4vh, 40px);
  padding: var(--pad-y) var(--pad-x);
  background-color: var(--panel);
  border: 1px solid var(--line);
  border-right: 0;
  border-radius: 16px 0 0 16px;
  /* mép xé do JS ghi vào sau khi cuống vé rời ra */
  clip-path: var(--body-clip, none);
  /* lỗ bấm vé ở hai đầu đường xé: cắt hẳn, không vẽ đè */
  -webkit-mask-image:
    radial-gradient(circle 7px at var(--notch-a), transparent 97%, #000 100%),
    radial-gradient(circle 7px at var(--notch-b), transparent 97%, #000 100%);
  -webkit-mask-composite: source-in;
  mask-image:
    radial-gradient(circle 7px at var(--notch-a), transparent 97%, #000 100%),
    radial-gradient(circle 7px at var(--notch-b), transparent 97%, #000 100%);
  mask-composite: intersect;
}

/* đường perforation khi vé còn nguyên */
.seam {
  position: absolute;
  top: 0; bottom: 0;
  right: 0;
  width: 0;
  border-right: 1px dashed var(--line-strong);
  pointer-events: none;
  transition: opacity 160ms ease-out;
}

/* khe hở để lộ nền khi cuống vé đã rời */
.tear-void {
  position: absolute;
  top: 0; bottom: 0;
  right: -0.5px;
  width: 0;
  background: var(--bg);
  opacity: 0;
  pointer-events: none;
  transition:
    width var(--motion-ms) var(--motion-ease),
    opacity 220ms ease-out;
}

/* --------------------------------------------------------------------------
   Masthead
   -------------------------------------------------------------------------- */

.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: clamp(15px, 1.5vw, 17px);
  font-weight: 900;
  letter-spacing: -0.019em;
  color: var(--ink);
}

.brand__mark {
  width: 1.15em;
  height: 1.15em;
  flex: none;
  color: var(--accent);
}

.brand__name-accent { color: var(--accent); }

.masthead__meta {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--dim);
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   Stage — tên miền
   -------------------------------------------------------------------------- */

.stage {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
  min-height: 0;
}

.eyebrow {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--dim);
}

/* Ô địa chỉ: đúng ngôn ngữ của `domain-notice.tsx` — nền đỏ rất nhạt,
   viền đỏ mờ, chữ đỏ nhạt, bo góc, ngắt dòng an toàn với tên miền dài. */
.domain-box {
  margin: 0;
  padding: 14px 16px;
  border: 1px solid color-mix(in oklch, var(--accent) 20%, transparent);
  border-radius: 12px;
  background-color: color-mix(in oklch, var(--accent) 5%, transparent);
}

.domain {
  display: block;
  font-size: clamp(27px, 5.2vw, 52px);
  font-weight: 700;
  line-height: 1.16;
  letter-spacing: -0.02em;
  color: var(--accent-pale);
  overflow-wrap: anywhere;
  -webkit-user-select: all;
  user-select: all;
  -webkit-tap-highlight-color: transparent;
}

/* --------------------------------------------------------------------------
   Ba trạng thái của địa chỉ

   `pending`  — đang hỏi API, hiện khung chờ thay cho địa chỉ
   `ready`    — đã có địa chỉ từ API
   `fallback` — API hỏng, dùng địa chỉ in sẵn, nói rõ là bản dự phòng

   Không có JS thì `<html>` không mang `data-domain-state`, nên thanh địa chỉ
   hiện địa chỉ in sẵn như cũ — trang không bao giờ treo ở khung chờ.
   -------------------------------------------------------------------------- */

/* khung chờ: cùng hình dạng với chữ thật để không nhảy bố cục khi tải xong */
.domain__pending { display: none; }

.skel {
  display: block;
  border-radius: 6px;
  background-color: var(--line);
  animation: skel-pulse 1.6s ease-in-out infinite;
}

@keyframes skel-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: .45; }
}

.skel--lg { height: clamp(28px, 4.4vw, 42px); width: min(100%, 30ch); }
.skel--md { height: clamp(28px, 4.4vw, 42px); width: min(58%, 16ch); margin-top: 8px; }
.skel--sm { height: 13px; width: 15ch; }

/* Ghi chú mặc định ẩn: không có JS thì trang không có `data-domain-state`,
   nên nếu để nó hiện sẵn thì người tắt JS sẽ đọc "Đang lấy dữ liệu…" mãi mãi. */
.domain__note {
  display: none;
  margin-top: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--dim);
}

/* --- pending --- */
[data-domain-state="pending"] .domain { display: none; }
[data-domain-state="pending"] .domain__pending { display: block; }
[data-domain-state="pending"] .domain__note { display: block; }

/* --- ready --- */
[data-domain-state="ready"] .domain__note { display: none; }

/* --- fallback: vẫn hiện địa chỉ, nhưng nói thẳng đây là bản dự phòng --- */
[data-domain-state="fallback"] .domain--unverified {
  /* gạch chân chấm: đọc được, nhưng không giả vờ là dữ liệu tươi */
  text-decoration: underline dotted color-mix(in oklch, var(--accent-pale) 55%, transparent);
  text-underline-offset: 6px;
  text-decoration-thickness: 2px;
}
[data-domain-state="fallback"] .domain__note {
  display: block;
  color: var(--accent-pale);
}

/* cuống vé lặp lại địa chỉ: cùng nhịp chờ */
[data-domain-state="pending"] .stub__addr { display: none; }
.stub__addr-skel { display: none; }
[data-domain-state="pending"] .stub__addr-skel { display: block; margin-top: 8px; }

/* nút sao chép chỉ có nghĩa khi đã biết địa chỉ */
.copy:disabled {
  opacity: .55;
  cursor: not-allowed;
}
.copy:disabled:hover { background-color: var(--accent-deep); }

.lede {
  margin: 0;
  max-width: 46ch;
  font-size: clamp(13.5px, 1.2vw, 15px);
  line-height: 1.65;
  color: var(--muted);
  text-wrap: pretty;
}

.lede--en { color: var(--dim); }

/* --------------------------------------------------------------------------
   Con dấu — khoảnh khắc duy nhất của trang
   -------------------------------------------------------------------------- */

.stamp {
  position: absolute;
  right: 0;
  bottom: clamp(0px, 4vh, 28px);
  display: grid;
  gap: 2px;
  justify-items: center;
  padding: 8px 16px 7px;
  border: 2px solid var(--accent);
  border-radius: 6px;
  color: var(--accent-pale);
  text-transform: uppercase;
  line-height: 1;
  opacity: 0;
  /* Gốc ở góc dưới-phải: lúc phóng to 1.5 lần con dấu nở về phía trong khung,
     nên trạng thái ẩn không đẩy mép phải ra ngoài màn hình hẹp. */
  transform-origin: 100% 100%;
  transform: rotate(-8deg) scale(1.5);
  pointer-events: none;
  /* mực loang trên giấy */
  -webkit-mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='120' height='120'><filter id='s'><feTurbulence type='fractalNoise' baseFrequency='.55' numOctaves='2'/><feColorMatrix type='matrix' values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 -1.7 1.42'/></filter><rect width='120' height='120' filter='url(%23s)'/></svg>");
  -webkit-mask-size: 120px 120px;
  mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='120' height='120'><filter id='s'><feTurbulence type='fractalNoise' baseFrequency='.55' numOctaves='2'/><feColorMatrix type='matrix' values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 -1.7 1.42'/></filter><rect width='120' height='120' filter='url(%23s)'/></svg>");
  mask-size: 120px 120px;
}

.stamp__vi {
  font-size: clamp(15px, 1.7vw, 19px);
  font-weight: 900;
  letter-spacing: 0.01em;
}

.stamp__en {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.22em;
  color: var(--accent);
}

/* --------------------------------------------------------------------------
   Chân vé
   -------------------------------------------------------------------------- */

.ticket__foot {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  line-height: 1.55;
  color: var(--dim);
}

.ticket__notice {
  max-width: 54ch;
  text-wrap: pretty;
}

.open {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background-color: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition:
    border-color 160ms ease-out,
    color 160ms ease-out;
}
.open:hover {
  border-color: var(--accent);
  color: var(--ink);
}
.open::after {
  content: "→";
  font-size: 13px;
  line-height: 1;
}

/* --------------------------------------------------------------------------
   Cuống vé
   -------------------------------------------------------------------------- */

.stub {
  position: relative;
  z-index: 1;
  width: clamp(196px, 21vw, 244px);
  transform-origin: 100% 50%;
  filter: drop-shadow(0 8px 24px oklch(0% 0 0 / 0.45));
  transition:
    transform var(--motion-ms) var(--motion-ease),
    filter var(--motion-ms) var(--motion-ease);
  will-change: transform;
}

.stub__paper {
  position: absolute;
  inset: 0;
  background-color: var(--panel-soft);
  border-radius: 0 16px 16px 0;
  clip-path: var(--stub-clip, none);
  -webkit-mask-image:
    radial-gradient(circle 7px at var(--notch-stub-a), transparent 97%, #000 100%),
    radial-gradient(circle 7px at var(--notch-stub-b), transparent 97%, #000 100%);
  -webkit-mask-composite: source-in;
  mask-image:
    radial-gradient(circle 7px at var(--notch-stub-a), transparent 97%, #000 100%),
    radial-gradient(circle 7px at var(--notch-stub-b), transparent 97%, #000 100%);
  mask-composite: intersect;
}

.stub__content {
  position: relative;
  z-index: 2;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 18px;
  padding: var(--pad-y) clamp(16px, 1.8vw, 22px);
  clip-path: var(--stub-clip, none);
  -webkit-mask-image:
    radial-gradient(circle 7px at var(--notch-stub-a), transparent 97%, #000 100%),
    radial-gradient(circle 7px at var(--notch-stub-b), transparent 97%, #000 100%);
  -webkit-mask-composite: source-in;
  mask-image:
    radial-gradient(circle 7px at var(--notch-stub-a), transparent 97%, #000 100%),
    radial-gradient(circle 7px at var(--notch-stub-b), transparent 97%, #000 100%);
  mask-composite: intersect;
}

.stub__label {
  margin: 0;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--dim);
}

.stub__addr {
  margin: 8px 0 0;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--muted);
  overflow-wrap: anywhere;
}

/* --- nút sao chép: pill đỏ, đúng kiểu `PILL_BUTTON_HEIGHT_CLASS` --- */

.copy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 40px;
  margin: 4px 0 0;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 999px;
  background-color: var(--accent-deep);
  color: var(--ink);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  transition:
    background-color 160ms ease-out,
    color 160ms ease-out,
    border-color 160ms ease-out;
}

.copy__icon {
  width: 15px;
  height: 15px;
  flex: none;
}

.copy__en { display: none; }

@media (hover: hover) and (pointer: fine) {
  .copy:hover { background-color: var(--accent); }
}

.copy:active { background-color: var(--accent); }

.copy:focus-visible {
  outline: 2px solid var(--accent-pale);
  outline-offset: 3px;
}

/* sau khi đã sao chép: nút lùi về dạng viền, nhường ánh đỏ cho con dấu */
.ticket.is-torn .copy {
  background-color: transparent;
  border-color: var(--line);
  color: var(--muted);
}
.ticket.is-torn .copy .copy__icon { color: var(--accent); }
@media (hover: hover) and (pointer: fine) {
  .ticket.is-torn .copy:hover {
    border-color: var(--accent);
    color: var(--ink);
  }
}

/* mã vạch neo xuống đáy, để nút nằm ngay dưới địa chỉ thay vì lơ lửng */
.stub__code {
  display: grid;
  gap: 8px;
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.barcode {
  display: block;
  width: 100%;
  height: 30px;
  color: var(--line-strong);
}

.stub__no {
  font-family: var(--font-mono);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
  color: var(--dim);
}

/* --------------------------------------------------------------------------
   Trạng thái đã xé
   -------------------------------------------------------------------------- */

.ticket.is-torn .seam { opacity: 0; }

.ticket.is-torn .tear-void {
  width: 10px;
  opacity: 1;
}

/* Cuống vé nhích ra khỏi mép xé. `--lift` đo theo chỗ trống thật của viewport
   để không bao giờ đẩy ra ngoài màn hình. */
.ticket.is-torn .stub {
  transform:
    translateX(var(--lift, 16px))
    translateY(3px)
    rotate(var(--tilt, 1deg));
  filter: drop-shadow(0 14px 32px oklch(0% 0 0 / 0.6));
}

.ticket.is-torn .stamp {
  animation: stamp-down 320ms var(--motion-ease) 120ms both;
}

@keyframes stamp-down {
  0%   { opacity: 0; transform: rotate(-14deg) scale(1.6); }
  60%  { opacity: 1; transform: rotate(-7.5deg) scale(0.97); }
  100% { opacity: 1; transform: rotate(-8deg) scale(1); }
}

/* --------------------------------------------------------------------------
   Hẹp: cuống vé xuống dưới, đường xé nằm ngang
   -------------------------------------------------------------------------- */

@media (max-width: 720px) {
  .shell { padding: 10px; }

  .ticket {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
    min-height: calc(100dvh - 20px - 16px);
  }

  .ticket__body {
    border-right: 1px solid var(--line);
    border-bottom: 0;
    border-radius: 14px 14px 0 0;
    padding: 22px var(--pad-x) 18px;
    gap: 16px;
    --notch-a: 0 100%;
    --notch-b: 100% 100%;
  }

  .seam {
    top: auto; bottom: 0; right: 0; left: 0;
    width: auto; height: 0;
    border-right: 0;
    border-bottom: 1px dashed var(--line-strong);
  }

  .tear-void {
    top: auto; bottom: -0.5px; right: 0;
    height: 0; width: auto;
    transition:
      height var(--motion-ms) var(--motion-ease),
      opacity 220ms ease-out;
  }

  .stub {
    --notch-stub-a: 0 0;
    --notch-stub-b: 100% 0;
    width: 100%;
    transform-origin: 50% 0%;
  }

  .stub__paper { border-radius: 0 0 14px 14px; }

  .stub__content {
    gap: 14px;
    padding: 16px var(--pad-x) 18px;
  }

  .stamp {
    position: static;
    align-self: flex-end;
    margin-top: 4px;
  }

  .ticket.is-torn .tear-void { width: auto; height: 8px; }
  .ticket.is-torn .stub {
    transform: translateY(var(--drop, 12px)) rotate(var(--tilt, -0.7deg));
  }

  .ticket__foot {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .masthead__meta { display: none; }
  .domain { font-size: clamp(24px, 7.2vw, 34px); }
}

@media (max-height: 720px) and (max-width: 720px) {
  .ticket__body { padding: 16px var(--pad-x) 14px; gap: 10px; }
  .stage { gap: 8px; }
  .domain-box { padding: 10px 12px; }
  .domain { font-size: clamp(22px, 6.6vw, 30px); }
  .lede { font-size: 12.5px; }
  .lede--en { display: none; }
  .stub__content { gap: 10px; padding: 12px var(--pad-x) 14px; }
  .stub__code { padding-top: 10px; }
  .barcode { height: 22px; }
  .ticket__foot { padding-top: 10px; }
}

/* Máy rất thấp: cuống vé nằm ngang một hàng */
@media (max-width: 720px) and (max-height: 620px) {
  .stub__content {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    padding: 12px var(--pad-x);
  }
  .stub__addr { margin-top: 4px; }
  .stub__code { display: none; }
  .copy {
    margin: 0;
    min-height: 36px;
    padding: 8px 14px;
    width: auto;
    white-space: nowrap;
  }
  .stamp { margin-top: 0; }
}

/* --------------------------------------------------------------------------
   Giảm chuyển động
   -------------------------------------------------------------------------- */

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

  .ticket.is-torn .stamp {
    opacity: 1;
    transform: rotate(-8deg) scale(1);
    animation: none;
  }

  /* khung chờ đứng yên, vẫn thấy rõ là khung chờ */
  .skel { animation: none; opacity: 1; }
}
