/* 桌面横屏宽屏模式：内容区左右铺开、压缩无效留白、提高单屏信息密度 */
@media screen and (min-width: 900px) and (min-height: 560px) and (orientation: landscape) {
  body {
    --xj-wide-gutter: clamp(24px, 1.9vw, 48px);
  }

  /* ---------- 内容外壳统一满宽 ---------- */
  body[data-xj-page="home"] .container,
  body[data-xj-page="curriculum"] .container,
  body[data-xj-page="classroom"] .container,
  body[data-xj-page="events"] .container,
  body[data-xj-page="logistics"] .container,
  body[data-xj-page="materials"] .container,
  body[data-xj-page="downloads"] .dl-container,
  body[data-xj-page="arts"] .ea-shell,
  body[data-xj-page="portal"] .shell,
  body[data-xj-page="apply"] .shell,
  body[data-xj-page="apply"] main,
  body[data-xj-page="sitemap"] .sm-container,
  body[data-xj-page="student"] main,
  body[data-xj-page="student"] .masthead-inner {
    width: calc(100% - var(--xj-wide-gutter) * 2) !important;
    max-width: none !important;
  }

  body[data-xj-page="report"] main,
  body[data-xj-page="app"] .page {
    width: calc(100% - var(--xj-wide-gutter) * 2) !important;
    max-width: none !important;
  }

  body[data-xj-page="collector"] .page {
    width: min(1680px, calc(100% - var(--xj-wide-gutter) * 2)) !important;
    max-width: none !important;
  }

  /* ---------- 首页：首屏压缩、正文满宽、卡片增列 ---------- */
  body[data-xj-page="home"] .coverflow {
    --cf-size: clamp(280px, min(37vh, 24vw), 370px);
    min-height: min(78vh, 720px);
    padding: clamp(74px, 8vh, 90px) 0 clamp(20px, 3vh, 28px);
  }

  body[data-xj-page="home"] .section {
    padding: 54px 0 !important;
  }

  body[data-xj-page="home"] .service-grid {
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)) !important;
    gap: 16px !important;
  }

  body[data-xj-page="home"] .about-visual {
    aspect-ratio: auto !important;
    height: clamp(340px, 31vw, 460px) !important;
  }

  body[data-xj-page="home"] .figure {
    aspect-ratio: auto !important;
    height: clamp(520px, 50vw, 720px) !important;
  }

  body[data-xj-page="home"] .course-catalog {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }

  body[data-xj-page="home"] .course-group.wide {
    grid-column: auto !important;
  }

  /* ---------- 课程 / 教室 / 赛事：压缩纵向留白 ---------- */
  body[data-xj-page="curriculum"] .layout {
    margin: 22px 0 42px !important;
  }

  body[data-xj-page="classroom"] .section {
    padding: 42px 0 !important;
  }

  body[data-xj-page="logistics"] .section {
    padding: 48px 0 !important;
  }

  body[data-xj-page="logistics"] .section.tight {
    padding: 34px 0 !important;
  }

  body[data-xj-page="events"] .page-head {
    padding: 8px 0 0 !important;
    align-items: flex-start !important;
  }

  body[data-xj-page="materials"] .page-head {
    padding: 28px 0 6px !important;
  }

  /* ---------- 下载中心：四列并排 ---------- */
  body[data-xj-page="downloads"] .dl-container {
    padding: 28px 0 44px !important;
  }

  body[data-xj-page="downloads"] .dl-grid {
    grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)) !important;
    gap: 16px !important;
  }

  /* ---------- 网站地图：多列展开 ---------- */
  body[data-xj-page="sitemap"] .sm-container {
    padding: 28px 0 44px !important;
  }

  body[data-xj-page="sitemap"] .sm-groups {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)) !important;
    gap: 16px !important;
  }

  /* ---------- 门户：赛事卡片自动增列 ---------- */
  body[data-xj-page="portal"] .shell {
    margin: 18px auto 42px !important;
  }

  body[data-xj-page="portal"] .student-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 16px !important;
  }

  body[data-xj-page="portal"] .grid {
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)) !important;
  }

  /* ---------- 电子艺术：卡片自动增列 ---------- */
  body[data-xj-page="arts"] .ea-grid {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)) !important;
  }

  /* ---------- 教师申请 / 采集器：压缩首屏留白 ---------- */
  body[data-xj-page="apply"] .shell {
    margin-top: 22px !important;
  }

  body[data-xj-page="collector"] .page {
    padding-top: 34px !important;
    padding-bottom: 48px !important;
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    column-gap: 22px !important;
    align-items: start !important;
  }

  body[data-xj-page="collector"] .page > .eyebrow,
  body[data-xj-page="collector"] .page > h1,
  body[data-xj-page="collector"] .page > .lead,
  body[data-xj-page="collector"] .page > .back {
    grid-column: 1 / -1;
  }

  body[data-xj-page="collector"] .page > .card {
    margin-top: 0 !important;
  }

  body[data-xj-page="collector"] .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  /* ---------- 法律页：正文加宽但不牺牲可读性 ---------- */
  body[data-xj-page="legal"] {
    --wrap: 1280px;
  }

  body[data-xj-page="legal"] .hero {
    padding-top: 34px !important;
  }

  /* ---------- 教学中心：左导航 + 内容区铺满 ---------- */
  @media (min-width: 1800px) {
    body[data-xj-page="home"] .course-catalog {
      grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
    }
  }

  body[data-xj-page="logistics"] .product-visual img {
    height: clamp(560px, 60vh, 760px) !important;
    object-fit: cover !important;
  }

  body[data-xj-page="teacher"] #appPage {
    grid-template-columns: 148px minmax(0, 1fr) !important;
    justify-content: stretch !important;
    padding: 14px var(--xj-wide-gutter) 30px !important;
    column-gap: 20px !important;
  }

  body[data-xj-page="teacher"] main,
  body[data-xj-page="teacher"] .moduleView,
  body[data-xj-page="teacher"] .teacherTempPwdTip {
    width: 100% !important;
    max-width: none !important;
  }
}

/* 超宽屏：让首页封面流也铺满左右，不留两侧大块空白 */
@media screen and (min-width: 2100px) and (orientation: landscape) {
  body[data-xj-page="home"] .coverflow {
    --cf-size: clamp(400px, 18vw, 470px) !important;
  }
}

/* ===== 全站弹窗统一圆角矩形 ===== */
:root { --xj-modal-radius: 22px; }

.modalBox,
.modal > .modal-card,
.modal-backdrop > .modal,
.mat-modal,
.wx-modal-card,
.ea-modal-card,
.cert-modal-panel,
.cl-modal,
.route-sheet,
.modal > .box {
  border-radius: var(--xj-modal-radius) !important;
}

/* 横屏：弹窗四周留出可见间距，宽度收敛，高度不再顶满屏幕 */
@media screen and (orientation: landscape) {
  .modal:has(.modalBox),
  .modal:has(.modal-card),
  .modal:has(.box) {
    padding: 20px 24px !important;
  }

  .modalBox {
    width: min(900px, calc(100vw - 48px)) !important;
    max-width: calc(100vw - 48px) !important;
    max-height: calc(100dvh - 40px) !important;
  }
  .modalBox.small {
    width: min(560px, calc(100vw - 48px)) !important;
  }
  .reportModal .reportModalBox {
    width: min(1180px, calc(100vw - 48px)) !important;
    height: calc(100dvh - 40px) !important;
    max-height: calc(100dvh - 40px) !important;
  }

  .modal > .modal-card {
    width: min(760px, calc(100vw - 48px)) !important;
    max-height: calc(100dvh - 40px) !important;
  }
  .modal > .modal-card.plan-card,
  .modal > .modal-card.works-card {
    width: min(1000px, calc(100vw - 48px)) !important;
  }
  .modal > .modal-card.track-card {
    width: min(820px, calc(100vw - 48px)) !important;
    max-height: calc(100dvh - 40px) !important;
  }

  .modal-backdrop {
    padding: 20px 24px !important;
  }
  .modal-backdrop > .modal {
    width: min(900px, calc(100vw - 48px)) !important;
    max-height: calc(100dvh - 40px) !important;
    margin: 0 auto !important;
  }
  .modal-backdrop > .modal.pay-modal {
    width: min(560px, calc(100vw - 48px)) !important;
  }
  .modal-backdrop > .modal.event-detail {
    width: min(1000px, calc(100vw - 48px)) !important;
  }
  .modal-backdrop > .modal.reg-detail {
    width: min(1020px, calc(100vw - 48px)) !important;
  }

  body:not(.mat-detail-mode) .mat-modal {
    width: calc(100vw - 48px) !important;
    height: calc(100dvh - 40px) !important;
    max-height: 960px !important;
  }

  .wx-modal {
    padding: 20px 24px !important;
  }
  .wx-modal-card {
    max-width: min(560px, calc(100vw - 48px)) !important;
  }
  .ea-modal-card {
    width: min(640px, calc(100vw - 48px)) !important;
    max-height: calc(100dvh - 40px) !important;
  }

  .modal > .box {
    width: min(620px, calc(100vw - 48px)) !important;
  }
  .route-sheet {
    width: min(1000px, calc(100vw - 48px)) !important;
    max-height: calc(100dvh - 40px) !important;
  }
  .classEndCard {
    width: min(680px, calc(100vw - 64px)) !important;
  }
}

/* 竖屏：四周保留 10px 间距，圆角不被屏幕边缘吞掉 */
@media screen and (orientation: portrait) {
  .modal:has(.modalBox),
  .modal:has(.modal-card),
  .modal:has(.box) {
    padding: 10px !important;
  }

  .modalBox {
    width: calc(100vw - 20px) !important;
    max-width: calc(100vw - 20px) !important;
    max-height: calc(100dvh - 20px) !important;
  }
  .reportModal .reportModalBox {
    width: calc(100vw - 20px) !important;
    height: calc(100dvh - 20px) !important;
    max-height: calc(100dvh - 20px) !important;
  }

  .modal > .modal-card {
    width: calc(100vw - 20px) !important;
    max-height: calc(100dvh - 20px) !important;
  }
  .modal > .modal-card.plan-card {
    height: calc(100dvh - 20px) !important;
    max-height: calc(100dvh - 20px) !important;
  }
  .modal > .modal-card.track-card {
    height: calc(100dvh - 20px) !important;
    max-height: calc(100dvh - 20px) !important;
  }

  .modal-backdrop {
    padding: 10px !important;
  }
  .modal-backdrop > .modal {
    width: calc(100vw - 20px) !important;
    max-height: calc(100dvh - 20px) !important;
    margin: 0 auto !important;
  }

  body:not(.mat-detail-mode) .mat-modal {
    width: calc(100vw - 20px) !important;
    height: calc(100dvh - 20px) !important;
  }

  .wx-modal {
    padding: 12px !important;
  }
  .wx-modal-card {
    max-width: calc(100vw - 24px) !important;
  }
  .ea-modal-card {
    width: calc(100vw - 20px) !important;
    max-height: calc(100dvh - 20px) !important;
  }

  .modal > .box {
    width: calc(100vw - 24px) !important;
  }
  .classEndCard {
    width: calc(100vw - 24px) !important;
  }

  .cert-modal-panel { width: calc(100vw - 20px) !important; }
  .cl-modal { width: calc(100vw - 20px) !important; max-height: calc(100dvh - 20px) !important; }
  .route-sheet { width: calc(100vw - 20px) !important; max-height: calc(100dvh - 20px) !important; }
}

@media screen and (orientation: landscape) and (min-width: 700px) {
  .modal .formGrid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
  .modal .formGrid .wide {
    grid-column: 1 / -1 !important;
  }
  .modal .grid2 {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
  .modal .grid2 .full {
    grid-column: 1 / -1 !important;
  }
  .plan-card .plan-lessons {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    align-items: start !important;
  }
}

@media screen and (orientation: portrait) and (max-width: 760px) {
  .modal .formGrid {
    grid-template-columns: 1fr !important;
  }
  .modal .formGrid .wide {
    grid-column: auto !important;
  }
  .modal .grid2 {
    grid-template-columns: 1fr !important;
  }
  .modal .grid2 .full {
    grid-column: auto !important;
  }
  .plan-card .plan-lessons {
    grid-template-columns: 1fr !important;
  }
}

/* 弹窗内容自身滚动，避免遮罩滚动条二次挤压宽度 */
@media screen and (orientation: landscape) {
  .modal-backdrop { overflow: hidden !important; }
  .modal-backdrop > .modal { overflow: auto !important; }
}
@media screen and (orientation: portrait) {
  .modal-backdrop { overflow: hidden !important; }
  .modal-backdrop > .modal { overflow: auto !important; }
  .classEndMask { padding: 12px !important; }
}

/* 证书说明、ClassIn 导入、航线图等独立弹窗同样跟随屏幕方向 */
@media screen and (orientation: landscape) {
  .cert-modal, .cl-modal-mask, .route-modal { padding: 20px 24px !important; }
}
@media screen and (orientation: portrait) {
  .cert-modal, .cl-modal-mask { padding: 10px !important; }
  .classEndMask { padding: 12px !important; }
}
