/* Cây Cộng Hưởng — "Bình minh kỳ quan": trời xanh đậm kiểu Pepsi chuyển vàng bình minh. Chỉ đặt lại các biến của
   wish-tree-base.css và thêm phần trang trí. Màu sự kiện được src/event/apply-event-config.js ghi đè từ
   EVENT.palette (các biến --event-*, --page-bg, --ink, --ink-soft, --accent); giá trị ở đây chỉ là mặc định. */
:root {
  --page-bg: #0a1a44;
  --ink: #eaf3ff;
  --ink-soft: #9db6dd;
  --accent: #f2c879;
  --event-sky-top: #0a1a44;
  --event-sky-mid: #1b4fa8;
  --event-horizon: #f2c879;
  --event-gold: #f2c879;
  --event-light: #bfe3ff;
  --event-leaf: #ffe9a8;
  --event-brand: #1b4fa8;
  --event-deep: #08183e;
  --event-paper-ink: #14264d;
  --event-gold-rgb: 242 200 121;
  --event-light-rgb: 191 227 255;
  --event-brand-rgb: 27 79 168;
  --event-deep-rgb: 8 24 62;
  --event-night-rgb: 2 8 28;
  --event-paper-ink-rgb: 20 38 77;
  --event-gold-hi: #f6dba3;
  --event-gold-lo: #e4bc72;
  --event-gold-hi-hover: #f9e5bb;
  --event-gold-lo-hover: #f3cf8a;
  --event-brand-hi: #3a69b6;
  --event-brand-hi-hover: #4e7abe;
  --event-brand-lo-hover: #3b66b5;
  --event-brand-dark: #133977;
  --event-brand-darker: #0a1e3f;
  --title-color: #ffffff;
  --title-font: 'Be Vietnam Pro', system-ui, sans-serif;
  --title-shadow: 0 0 26px rgb(var(--event-light-rgb) / 0.45), 0 2px 0 rgb(var(--event-night-rgb) / 0.45);
  --heading-font: 'Cormorant Garamond', Georgia, serif;
  --panel-bg: rgb(var(--event-deep-rgb) / 0.86);
  --panel-ring: rgb(var(--event-gold-rgb) / 0.5);
  --panel-shadow: 0 24px 50px -18px rgb(var(--event-night-rgb) / 0.9);
  --panel-text: #b7c9e6;
  --panel-text-strong: #fff2cc;
  --button-bg: linear-gradient(180deg, var(--event-gold-hi), var(--event-gold-lo));
  --button-bg-hover: linear-gradient(180deg, var(--event-gold-hi-hover), var(--event-gold-lo-hover));
  --button-text: var(--event-deep);
  --button-ring: rgba(255, 244, 214, 0.65);
  --chip-bg: rgb(var(--event-deep-rgb) / 0.74);
  --chip-text: #eaf3ff;
  --chip-ring: rgb(var(--event-gold-rgb) / 0.5);
  --credit-color: rgb(var(--event-light-rgb) / 0.62);
}

/* ---------- Đầu cây: dòng nhỏ, dòng lớn, dòng phụ, ngày ---------- */
.brand__program {
  font-size: clamp(11px, 0.55vw + 8px, 15px);
  font-weight: 600;
  letter-spacing: 0.3em;
  padding-left: 0.3em;
  color: var(--accent); /* không ép chữ hoa: tên chương trình viết đúng ở event-config ("PreAOP27") */
  text-shadow: 0 1px 8px rgb(var(--event-night-rgb) / 0.6);
}

.brand__title {
  margin: clamp(5px, 1vh, 10px) auto 0;
  font-family: var(--title-font);
  font-weight: 800;
  font-size: clamp(16px, min(6vw, 5.6dvh), 62px); /* một hàng: vw giữ vừa bề ngang điện thoại */
  line-height: 1.08;
  letter-spacing: 0.035em;
  white-space: nowrap;
}

.brand__tagline {
  margin-top: 4px !important;
  font-family: var(--title-font);
  font-weight: 600;
  font-size: clamp(14px, min(4.2vw, 3.9dvh), 43px); /* ~0.7 lần dòng lớn: nhỏ hơn dòng lớn, lớn hơn dòng tên chương trình */
  letter-spacing: 0.3em;
  padding-left: 0.3em;
  color: var(--event-light);
  text-shadow: 0 1px 8px rgb(var(--event-night-rgb) / 0.6);
}

.brand__divider {
  position: relative;
  width: 84px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
}

/* Ba vòng sóng nhỏ ở giữa vạch ngăn: dấu hiệu "cộng hưởng" */
.brand__divider::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--panel-bg), 0 0 0 3px var(--accent);
  background: var(--accent);
  transform: translate(-50%, -50%);
}

.brand__date { color: var(--event-light); text-shadow: 0 1px 8px rgb(var(--event-night-rgb) / 0.6); }

/* ---------- Bảng điều khiển phía dưới: kính xanh đậm viền vàng ---------- */
.wish-panel::before {
  content: '';
  position: absolute;
  top: 5px;
  right: 5px;
  bottom: 5px;
  left: 5px;
  border: 1px solid rgb(var(--event-gold-rgb) / 0.2);
  border-radius: 19px;
  pointer-events: none;
}

/* Nút chính: mở phiếu viết thư (styles/letter-sheet.css) */
.wish-write {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  height: 52px;
  border: 0;
  border-radius: 999px;
  background: var(--button-bg);
  box-shadow: inset 0 0 0 1px var(--button-ring), 0 10px 24px -10px rgb(var(--event-gold-rgb) / 0.55);
  color: var(--button-text);
  font: 700 14px/1 'Be Vietnam Pro', system-ui, sans-serif;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.15s ease;
}

.wish-write:hover { background: var(--button-bg-hover); }
.wish-write:active { transform: scale(0.98); }
.wish-write:focus-visible { outline: 2px solid var(--event-light); outline-offset: 2px; }
.wish-write[hidden] { display: none; }

.wish-panel__links {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0 10px;
  margin-top: 4px;
}

.wish-panel__links .story-reopen { margin: 0; }

/* Dòng trạng thái sau khi gửi: nằm ngay trên bảng, ngoài luồng để bảng không đổi cỡ làm cảnh bố trí lại */
.wish-status {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  width: max-content;
  max-width: calc(100% - 16px);
  padding: 8px 18px;
  border-radius: 18px;
  background: var(--panel-bg);
  box-shadow: inset 0 0 0 1px var(--panel-ring), 0 10px 24px -14px rgb(var(--event-night-rgb) / 0.9);
  color: var(--panel-text-strong);
  font: 600 13.5px/1.35 'Be Vietnam Pro', system-ui, sans-serif;
  text-align: center;
  transform: translateX(-50%);
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.wish-status small { display: block; margin-top: 2px; font-size: 11.5px; font-weight: 400; color: var(--panel-text); }
.wish-status:empty { opacity: 0; } /* vẫn được vẽ để trình đọc màn hình nghe được câu sau */

.wish-status[data-tone='error'] {
  color: #ffd2c0;
  box-shadow: inset 0 0 0 1px rgba(255, 130, 100, 0.75), 0 10px 24px -14px rgb(var(--event-night-rgb) / 0.9);
}

/* Hai nút phụ: đọc thư của tôi, xem lại lời tựa */
.story-reopen {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
  margin: 2px auto 0;
  padding: 4px 8px;
  border: 0;
  background: none;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.2;
  color: var(--event-light);
  opacity: 0.9;
  cursor: pointer;
}
.story-reopen[hidden] { display: none; }
.story-reopen:hover, .story-reopen:focus-visible { opacity: 1; text-decoration: underline; text-underline-offset: 3px; }
.story-reopen .icon { width: 14px; height: 14px; }

/* ---------- Bộ đếm cam kết ---------- */
.tally { position: relative; }
.tally__count { transition: opacity 0.4s ease; }
.is-offline .tally__count { opacity: 0.55; }

.tally {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  margin-top: 10px;
  padding: 7px 22px 8px;
  border-radius: 16px;
  background: rgb(var(--event-deep-rgb) / 0.8); /* sáng nền bên dưới thay đổi liên tục: giữ con số rõ nét */
  box-shadow: inset 0 0 0 1px rgb(var(--event-gold-rgb) / 0.5), 0 10px 30px -14px rgb(var(--event-night-rgb) / 0.85);
}

.tally p { margin: 0; }
.tally__row { display: flex; align-items: center; gap: 10px; }

.tally__count {
  display: inline-block;
  font-family: var(--title-font);
  font-weight: 800;
  font-size: clamp(30px, 4.6vh, 46px);
  line-height: 1;
  color: var(--accent);
  text-shadow: 0 0 18px rgb(var(--event-gold-rgb) / 0.5);
  font-variant-numeric: tabular-nums;
}

.tally__count.is-bumped { animation: count-bump 0.6s ease; }
.tally__caption { margin-top: 4px !important; font-size: 12px; letter-spacing: 0.03em; color: var(--ink); }

.tally__offline {
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgb(var(--event-deep-rgb) / 0.78);
  color: var(--ink-soft);
  font-size: 11px;
  letter-spacing: 0.04em;
  white-space: nowrap;
  transform: translateX(-50%);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.4s ease, visibility 0s linear 0.4s;
}

.tally__offline::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: offline-pulse 1.4s ease-in-out infinite;
}

.is-offline .tally__offline { opacity: 1; visibility: visible; transition: opacity 0.4s ease 1.2s, visibility 0s linear 1.2s; }
@keyframes offline-pulse { 50% { opacity: 0.25; } }

@media (max-height: 640px) {
  .tally { margin-top: 6px; padding: 4px 14px 5px; }
  .tally__count { font-size: 26px; }
}

/* ---------- Lời tựa (màn hình 1) ---------- */
.story-intro {
  position: absolute;
  z-index: 10;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-top) + 24px) 22px calc(var(--safe-bottom) + 24px);
  overflow-y: auto;
  /* Chỉ tối phía sau chữ: cây và trời vẫn thấy được xung quanh */
  background: radial-gradient(75% 65% at 50% 50%, rgb(var(--event-night-rgb) / 0.82), rgb(var(--event-night-rgb) / 0.5) 70%, rgb(var(--event-night-rgb) / 0.3));
  opacity: 0;
  transition: opacity 0.7s ease;
}

.story-intro[hidden] { display: none; }
.brand, .wish-panel, .credit, .corner-chip, .fps-badge, .tally { transition: opacity 0.7s ease; }
.is-story-open :is(.brand, .wish-panel, .credit, .corner-chip, .fps-badge) { opacity: 0; pointer-events: none; }
/* Vừa vào app: chỉ còn tên chương trình, chưa có nút, bộ đếm hay lời tựa */
.is-title-hold :is(.wish-panel, .credit, .corner-chip, .fps-badge, .tally) { opacity: 0; pointer-events: none; }
.story-intro.is-visible { opacity: 1; }
.story-intro.is-leaving { opacity: 0; pointer-events: none; }

/* Cỡ chữ theo màn hình: đọc ở khoảng cách tay trên điện thoại, từ cuối phòng trên máy chiếu. Số hạng chiều cao giữ
   cả lời tựa trong một màn 16:9; lề tự động căn giữa, và cuộn được khi cao hơn màn (điện thoại nằm ngang). */
.story-intro__card {
  max-width: min(100%, 26em);
  margin: auto;
  font-size: clamp(16px, min(1.1vw + 11px, 2.9vh), 40px);
  text-align: center;
  text-shadow: 0 1px 10px rgb(var(--event-night-rgb) / 0.95), 0 0 2px rgb(var(--event-night-rgb) / 0.9);
}

.story-intro__line {
  margin: 0 0 0.7em;
  font-family: var(--heading-font);
  font-weight: 600;
  font-size: 1.04em;
  line-height: 1.5;
  color: var(--ink);
  opacity: 0;
  transform: translateY(8px);
  animation: story-line-in 0.9s ease forwards;
  animation-delay: calc(0.4s + var(--i) * 1.1s);
}

.story-intro__line--question { color: #fff; font-size: 1.14em; font-style: italic; text-shadow: 0 0 22px rgb(var(--event-light-rgb) / 0.55), 0 1px 10px rgb(var(--event-night-rgb) / 0.95); }
.story-intro__line--promise { color: var(--accent); font-style: italic; }

.story-intro__button {
  margin-top: 0.5em;
  padding: max(14px, 0.62em) max(26px, 1.15em);
  border: 0;
  border-radius: 999px;
  background: var(--button-bg);
  box-shadow: inset 0 0 0 1px var(--button-ring), 0 12px 30px -12px rgb(var(--event-gold-rgb) / 0.6);
  color: var(--button-text);
  font: 700 max(13px, 0.6em)/1 'Be Vietnam Pro', system-ui, sans-serif;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  opacity: 0;
  animation: story-line-in 0.9s ease forwards;
  animation-delay: calc(0.4s + var(--i) * 1.1s);
}

@keyframes story-line-in { to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  .story-intro__line, .story-intro__button { animation-duration: 0.01s; animation-delay: 0s; }
  .tally__offline::before { animation: none; }
}
