/* ==========================================================
   Điện thoại & máy tính bảng (< 900px). Tải SAU CÙNG; mọi quy tắc
   nằm trong media query nên giao diện desktop (>= 900px) không đổi.
   ========================================================== */

@media (max-width: 899px) {
  :root {
    --safe-b: env(safe-area-inset-bottom, 0px);
    --safe-l: env(safe-area-inset-left, 0px);
    --safe-r: env(safe-area-inset-right, 0px);
    --fab: 12px; /* khoảng cách nút nổi tới mép */
  }

  /* ---------- Hiệu năng: bỏ nền cố định + hoà trộn toàn màn hình ---------- */
  body { background-attachment: scroll; }
  body::after { mix-blend-mode: normal; opacity: .06; }

  /* ---------- Header + menu ---------- */
  .site-header { padding-left: max(var(--gutter), var(--safe-l)); padding-right: max(var(--gutter), var(--safe-r)); }
  /* ngăn kéo menu (bề rộng, lề an toàn): khối "Menu" trong main.css */

  /* ---------- Hero ---------- */
  .hero-content { padding-bottom: calc(clamp(20px, 3.5svh, 32px) + var(--safe-b)); }
  .hero-card-body { padding: 12px 14px; }
  .hero-card strong { text-wrap: balance; }
  .hero-card { border-radius: 8px 24px 8px 8px; }
  .hero-card img { width: 96px; }
  .hero-countdown { grid-template-columns: 82px minmax(0, 1fr); column-gap: 8px; min-height: 56px; }
  .hero-countdown-days b { font-size: clamp(44px, 11vw, 52px); }
  .hero-countdown-days span { font-size: 8px !important; }
  .hero-countdown-time { gap: 8px; grid-template-columns: repeat(3, minmax(38px, max-content)); }
  .hero-countdown-time b { font-size: 17px; }

  /* ---------- Lời mở đầu + quạt thẻ (hàng cuộn ngang tràn mép) ---------- */
  .fan {
    margin-left: calc(-1 * var(--gutter)); margin-right: calc(-1 * var(--gutter));
    padding: 24px var(--gutter) 16px;
    overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch;
    scroll-padding-inline: var(--gutter);
  }
  .fan::after { content: ""; flex: none; width: 1px; } /* chừa lề phải khi cuộn tới cuối */
  .fan-card span { font-size: 13px; }

  /* ---------- Hành trình (vuốt ngang) ---------- */
  .journey-head { padding-top: 72px; }
  /* mỗi mùa chiếm trọn bề ngang, mùa bên cạnh nằm hẳn ngoài khung (không lộ chữ bị cắt) */
  .journey-track { gap: 0; padding: 8px 0 24px; }
  .season {
    flex: 0 0 100%; padding: 0 var(--gutter); scroll-snap-align: center; scroll-snap-stop: always;
    grid-template-columns: minmax(0, 1fr); gap: 18px; /* không cho cột chữ tràn rộng hơn thẻ */
  }
  #hanh-trinh .season-count { top: auto; bottom: 12px; } /* số thứ tự ảnh: góc dưới, không nằm dưới header */
  .season-photos { aspect-ratio: 4 / 3.25; }
  .season-text { gap: 10px; }
  .has-gsap .season-text .season-numeral, .season-text .season-numeral {
    position: static; display: block; opacity: 1;
    font-size: clamp(64px, 19vw, 104px); line-height: .82;
    margin: 2px 0 -2px -.04em;
    -webkit-text-stroke-width: 1.5px;
  }
  .season-title { font-size: clamp(24px, 6.2vw, 32px); }
  .season-slogan { font-size: clamp(22px, 6vw, 26px); }
  .season-fact-body small { font-size: 13px; }
  .season-fact-value { font-size: 15px; }
  #hanh-trinh .season-count { font-size: 13px; }

  .journey-rail { padding-bottom: 32px; }
  .journey-rail-years {
    margin: 0 calc(-1 * var(--gutter)); padding: 0 var(--gutter);
    scroll-padding-inline: var(--gutter); overscroll-behavior-x: contain;
    grid-template-columns: repeat(10, 64px);
  }
  .journey-rail-years::after { content: ""; width: 1px; }
  .rail-year { min-height: 48px; font-size: 13px; }
  .journey-note { font-size: 13px; }

  /* ---------- Cuộn phim ---------- */
  .reels { padding: 64px 0 80px; }

  /* ---------- Sách hồi ức ---------- */
  .memories { padding-top: 88px; padding-bottom: 140px; }
  .memories-head { margin-bottom: 20px; }
  #hoi-uc.book-pending .book { height: clamp(260px, 78vw, 72svh); }
  #hoi-uc .book.book3d { height: clamp(260px, 78vw, 72svh); }
  #hoi-uc.book3d-active .book-arrow { width: 52px; height: 52px; bottom: -66px; }
  #hoi-uc.book3d-active .book-arrow--prev { left: calc(50% - 70px); }
  #hoi-uc.book3d-active .book-arrow--next { right: calc(50% - 70px); }
  #hoi-uc.book3d-active .book-controls { margin-top: 96px; }
  .book-indicator { font-size: 16px; text-shadow: 0 1px 12px rgba(0, 30, 8, .45); }

  /* ---------- Tâm tình ---------- */
  .letters { padding: 88px 0 96px; }
  .wish-form { padding: 22px 20px 26px; }
  .wish-form input[type="file"] { font-size: 15px; }
  .wish-form input[type="file"]::file-selector-button { min-height: 44px; padding: 8px 16px; }
  .submit-button { min-height: 52px; }
  .remove-image { width: 40px; height: 40px; top: -14px; right: -14px; font-size: 22px; }
  .wish-entry { padding: 18px; }
  .wish-entry time { font-size: 13px; }
  .wish-remove { padding: 12px 0 4px; font-size: 14px; }

  /* ---------- Footer: chừa chỗ nút nhạc / viên mùa ---------- */
  .site-footer { padding-top: 112px; padding-bottom: calc(84px + var(--safe-b)); }
  .footer-row { flex-direction: column; align-items: flex-start; gap: 12px; }
  .back-top {
    display: inline-flex; align-items: center; min-height: 44px; padding: 0;
    border-bottom: 0; text-decoration: underline; text-decoration-color: var(--green);
    text-decoration-thickness: 1.5px; text-underline-offset: 6px;
  }

  /* ---------- Nút nổi: viên mùa + nút nhạc (vùng an toàn) ---------- */
  .season-pill { left: calc(var(--fab) + var(--safe-l)); bottom: calc(var(--fab) + var(--safe-b)); min-height: 56px; max-width: calc(100vw - 2 * var(--fab) - 72px); }
  .season-pill b { font-size: 15px; white-space: nowrap; }
  .nt-music { right: calc(var(--fab) + var(--safe-r)); bottom: calc(var(--fab) + 4px + var(--safe-b)); }
  .countdown-bell {
    right: calc(72px + var(--safe-r));
    bottom: calc(var(--fab) + 4px + var(--safe-b));
    width: 48px;
    height: 48px;
  }
  .countdown-bell.is-near-back-top {
    bottom: calc(76px + var(--safe-b));
  }
  .countdown-floating {
    right: calc(var(--fab) + var(--safe-r));
    bottom: calc(68px + var(--safe-b));
    width: calc(100vw - 24px - var(--safe-l) - var(--safe-r));
  }
  .countdown-floating.is-near-back-top {
    bottom: calc(136px + var(--safe-b));
  }

  /* ---------- Mục lục 10 mùa ---------- */
  .season-index { padding: max(16px, env(safe-area-inset-top, 0px)) var(--gutter) calc(48px + var(--safe-b)); }
  .season-index-head { position: sticky; top: 0; z-index: 2; margin: 0 calc(-1 * var(--gutter)) 16px; padding: 8px var(--gutter); background: linear-gradient(180deg, #F6FBF1 70%, rgba(246, 251, 241, 0)); }
  .season-index-close { width: 52px; height: 52px; flex: none; }

  /* ---------- Xem ảnh lớn ---------- */
  .lightbox { padding: 72px 8px calc(96px + var(--safe-b)); }
  .lightbox-figure img { max-height: calc(100svh - 220px); }
  .lightbox-figure figcaption { font-size: 15px; text-align: center; padding: 0 12px; }
  .lightbox-nav { bottom: calc(20px + var(--safe-b)); background: rgba(8, 30, 17, .5); }
  .lightbox-close { top: 12px; right: 12px; }
}

/* ---------- Điện thoại (< 600px) ---------- */
@media (max-width: 599px) {
  /* thẻ đếm ngược: chừa chỗ nút nhạc ở góc phải dưới */
  .hero-content { padding-bottom: calc(76px + var(--safe-b)); gap: 16px; }
  .hero-script { font-size: 28px; }
  .hero-card img { width: 88px; }
  .hero-card strong { font-size: 19px; }

  .statement { padding-top: 72px; padding-bottom: 72px; }

  .marquee-track { font-size: 44px; }

  /* sách: canvas cao để đọc từng trang (book3d.js phóng vào một trang khi khung dọc) */
  #hoi-uc.book-pending .book, #hoi-uc .book.book3d { height: min(142vw, 74svh); min-height: 0; }
  .memories-head h2 { font-size: clamp(38px, 11vw, 52px); }

  .journey-head h2, .letters-head h2 { font-size: clamp(40px, 11.5vw, 56px); }

  /* ánh sáng trôi: tắt chuyển động trên điện thoại cho nhẹ máy */
  .light, .light--soft { animation: none; }

  /* mục lục: 2 cột */
  .season-index-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .index-card { padding: 8px 8px 12px; gap: 8px; }
  .index-card-roman { font-size: 38px; left: 14px; top: 12px; }
  .index-card b { font-size: 15px; }
  .index-card small { font-size: 12.5px; }
  .season-index-head h2 { font-size: 36px; }
}

/* ---------- Tablet dọc (600–899px): mỗi mùa hai cột ảnh | chữ ---------- */
@media (min-width: 600px) and (max-width: 899px) {
  .season { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: center; gap: 32px; }
  .season-photos { aspect-ratio: 4 / 4.6; }
}

@media (max-width: 380px) {
  .hero-title { font-size: 12vw; } /* "mười mùa MỘC" giữ trên một dòng */
  .season-fact:not(.season-fact--wide) .season-fact-value { font-size: 16px; }
  .season-facts { column-gap: 10px; }
  .hero-card img { width: 76px; }
}

/* ---------- Điện thoại xoay ngang ---------- */
@media (max-width: 899px) and (max-height: 500px) and (orientation: landscape) {
  .hero-content { flex-direction: row; align-items: flex-end; gap: 20px; padding-bottom: calc(20px + var(--safe-b)); padding-right: calc(var(--gutter) + 60px); }
  .hero-title { font-size: clamp(34px, 11.5svh, 56px); }
  .hero-script { font-size: 24px; }
  .hero-card { width: min(300px, 36vw); }
  .hero-card img { width: 72px; }
  .hero-card strong { font-size: 17px; }
  .hero-card span { font-size: 14px; }

  .season { grid-template-columns: minmax(0, .95fr) minmax(0, 1.05fr); align-items: center; }
  .season-photos { aspect-ratio: auto; height: min(76svh, 320px); }
  .has-gsap .season-text .season-numeral, .season-text .season-numeral { font-size: 56px; }

  #hoi-uc .book.book3d, #hoi-uc.book-pending .book { height: min(80svh, 46vw); }
  .lightbox-figure img { max-height: calc(100svh - 110px); }
  .lightbox { padding-top: 16px; padding-bottom: 16px; grid-template-columns: auto 1fr auto; }
  .lightbox-nav { position: static; }
}

/* Máy cảm ứng màn rộng (tablet ngang): sách 3D tải trễ → giữ sẵn chiều cao như khi đã dựng */
@media (min-width: 900px) and (pointer: coarse) {
  #hoi-uc.book-pending .book { height: min(90vh, 64vw); min-height: 300px; }
}

@media (max-width: 899px) and (prefers-reduced-motion: reduce) {
  .fan, .journey-track, .journey-rail-years { scroll-behavior: auto; }
}

/* ---------- Hiệu năng cảm ứng / màn nhỏ: bỏ lọc nặng, hoà trộn, animation vô tận trang trí ---------- */
@media (max-width: 899px), (pointer: coarse) {
  .countdown-panel { backdrop-filter: none; -webkit-backdrop-filter: none; background: rgba(255, 253, 246, .96); box-shadow: 0 10px 24px -16px rgba(12, 46, 27, .4); }
  .ls-wind, .deco--grass-l, .deco--grass-r, .nt-music.is-playing::after { animation: none; }
  .ls, .fx-line-inner, .flow-leaf { will-change: auto; }
  .ls-friends, .deco--hills, .flow-line, .flow-leaf, .nt-bf-wing svg { filter: none; }
  .marquee { box-shadow: none; }
  .nt-music { box-shadow: 0 4px 10px -6px rgba(12, 46, 27, .6); }
  body { background-blend-mode: normal; }
  .has-seams body, .has-seams .statement.paper, .has-seams .journey, .has-seams .reels.paper, .has-seams .archive, .has-seams .letters { background-blend-mode: normal; transition: none; }
}
