/* =========================================================
   全科核心素养提分系统 - 平台总主页专用样式表 (home.css)
   多端多设备全维自适应引擎 (Tier 1 ~ Tier 4 & 矮横屏全兼容)
   严格对齐初中数学移动端/多浏览器高兼容性规范
   ========================================================= */

/* ==================== 1. 全局与多浏览器基础重置 ==================== */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  -webkit-tap-highlight-color: transparent;
}

body.platform-home-body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-main, #f8fafc);
  color: var(--text-main, #0f172a);
  font-family: var(--font-sans, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-overflow-scrolling: touch;
  overflow-x: hidden;
  width: 100%;
}

/* ==================== 2. 顶部平台控制栏 (安全区感知) ==================== */
.platform-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color, #e2e8f0);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
  padding-top: env(safe-area-inset-top, 0px);
  padding-left: max(0px, env(safe-area-inset-left, 0px));
  padding-right: max(0px, env(safe-area-inset-right, 0px));
  transition: all 0.2s ease;
}

.platform-header-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 24px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.platform-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
  flex-shrink: 0;
}

.platform-brand-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #3b82f6);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
  flex-shrink: 0;
}

.platform-brand-texts {
  display: flex;
  flex-direction: column;
}

.platform-brand-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: #0f172a;
  line-height: 1.2;
  white-space: nowrap;
}

.platform-brand-badge {
  font-size: 11px;
  font-weight: 600;
  color: #2563eb;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

/* 顶部右侧控制按钮组 */
.platform-header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
  flex-shrink: 0;
}

/* 通知铃铛按钮 */
.header-action-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  border: 1px solid var(--border-color, #e2e8f0);
  background: #ffffff;
  color: #475569;
  cursor: pointer;
  transition: all 0.18s ease;
  padding: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.header-action-btn:hover {
  background: #f1f5f9;
  color: #1e293b;
  border-color: #cbd5e1;
}

.header-action-btn:active {
  transform: scale(0.96);
}

.header-action-btn.has-unread::after {
  content: '';
  position: absolute;
  top: 7px;
  right: 7px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: #ef4444;
  border: 2px solid #ffffff;
}

/* 多语种切换器 */
.language-selector-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.language-select-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 12px;
  background: #ffffff;
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: #334155;
  cursor: pointer;
  transition: all 0.18s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

.language-select-btn:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.language-select-btn:active {
  transform: scale(0.97);
}

/* 学习者档案卡胶囊 */
.user-capsule-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.user-profile-capsule {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 14px 0 8px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 9999px;
  color: #1e40af;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

.user-profile-capsule:hover {
  background: #dbeafe;
  border-color: #93c5fd;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.15);
}

.user-profile-capsule:active {
  transform: scale(0.97);
}

.capsule-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #2563eb;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.capsule-chevron {
  color: #60a5fa;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

/* ==================== 3. 浮层弹窗通用样式与防溢出保障 ==================== */
.flyout-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: #ffffff;
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 12px;
  box-shadow: 0 12px 30px -4px rgba(0, 0, 0, 0.15), 0 4px 10px -2px rgba(0, 0, 0, 0.06);
  display: none;
  flex-direction: column;
  z-index: 1050;
  animation: popoverFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  -webkit-overflow-scrolling: touch;
}

.flyout-popover.active {
  display: flex;
}

@keyframes popoverFadeIn {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 通知浮窗面板 */
#notification-popover {
  width: 340px;
  max-width: calc(100vw - 20px);
}

.popover-header {
  padding: 14px 16px;
  border-bottom: 1px solid #f1f5f9;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.popover-title {
  font-size: 14px;
  font-weight: 700;
  color: #0f172a;
}

.popover-action-link {
  font-size: 12px;
  color: #2563eb;
  background: none;
  border: none;
  padding: 4px 6px;
  cursor: pointer;
  font-weight: 500;
  border-radius: 4px;
  touch-action: manipulation;
}

.popover-action-link:hover {
  text-decoration: underline;
  background: #eff6ff;
}

.notification-list {
  max-height: 320px;
  overflow-y: auto;
  padding: 6px 0;
}

.notification-item {
  padding: 10px 16px;
  border-bottom: 1px solid #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: background 0.15s ease;
}

.notification-item:hover {
  background: #f8fafc;
}

.notification-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.notification-tag {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  background: #eff6ff;
  color: #2563eb;
}

.notification-time {
  font-size: 11px;
  color: #94a3b8;
}

.notification-text {
  font-size: 12px;
  color: #334155;
  line-height: 1.4;
  margin: 0;
  word-break: break-word;
}

/* 用户档案卡下拉面板 */
#user-popover {
  width: 280px;
  max-width: calc(100vw - 20px);
  padding: 16px;
}

.user-card-profile {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid #f1f5f9;
  margin-bottom: 10px;
}

.user-card-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2563eb, #3b82f6);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  flex-shrink: 0;
}

.user-card-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.user-card-name {
  font-size: 14px;
  font-weight: 700;
  color: #0f172a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-card-role {
  font-size: 12px;
  color: #64748b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-card-menu {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.user-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  color: #334155;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  background: transparent;
  border: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s ease;
  touch-action: manipulation;
}

.user-menu-item:hover {
  background: #f1f5f9;
  color: #2563eb;
}

.user-menu-item:active {
  background: #e2e8f0;
}

/* 语言下拉菜单 */
#language-popover {
  width: 160px;
  padding: 6px 0;
}

.lang-menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 14px;
  font-size: 13px;
  color: #334155;
  cursor: pointer;
  transition: background 0.15s ease;
  touch-action: manipulation;
}

.lang-menu-item:hover {
  background: #eff6ff;
  color: #2563eb;
}

.lang-menu-item.active {
  color: #2563eb;
  font-weight: 600;
  background: #f8fafc;
}

/* ==================== 4. 平台主区域横幅与栅格 ==================== */
.platform-main {
  flex: 1;
  max-width: 1240px;
  width: 100%;
  margin: 0 auto;
  padding: 32px 24px 64px 24px;
  padding-left: max(24px, env(safe-area-inset-left, 0px));
  padding-right: max(24px, env(safe-area-inset-right, 0px));
  box-sizing: border-box;
}

/* 标头宣传区 */
.hero-section {
  text-align: center;
  margin-bottom: 40px;
}

.hero-pill-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 14px;
  border-radius: 9999px;
  background: #eff6ff;
  border: 1px solid #dbeafe;
  color: #2563eb;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 12px;
}

.hero-title {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: #0f172a;
  margin: 0 0 10px 0;
  line-height: 1.25;
}

.hero-subtitle {
  font-size: 15px;
  color: #64748b;
  max-width: 680px;
  margin: 0 auto;
  line-height: 1.6;
}

/* ==================== 5. 学段专区纵向流 ==================== */
.stage-section {
  margin-bottom: 44px;
}

.stage-section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border-color, #e2e8f0);
  padding-bottom: 10px;
  gap: 12px;
}

.stage-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.stage-section-title {
  font-size: 20px;
  font-weight: 700;
  color: #0f172a;
  margin: 0;
}

.stage-section-desc {
  font-size: 13px;
  color: #64748b;
  margin: 0;
}

/* 学科卡片自适应栅格 (默认 4 列) */
.subject-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
}

/* ==================== 6. 单个学科卡片通用样式 ==================== */
.subject-card {
  position: relative;
  background: #ffffff;
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: var(--radius-lg, 14px);
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 180px;
  box-sizing: border-box;
  text-decoration: none;
  color: inherit;
  transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  min-width: 0;
  word-break: break-word;
  overflow-wrap: break-word;
}

/* 卡片顶部行：图标与状态标签 */
.subject-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 8px;
}

.subject-icon-box {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: #f1f5f9;
  color: #475569;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.subject-status-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
  white-space: nowrap;
  flex-shrink: 0;
}

/* 中部学科名称与年级体系 */
.subject-title {
  font-size: 17px;
  font-weight: 700;
  color: #0f172a;
  margin: 0 0 6px 0;
  line-height: 1.3;
}

.subject-desc {
  font-size: 12px;
  color: #64748b;
  line-height: 1.5;
  margin: 0 0 12px 0;
  flex: 1;
}

.subject-grades {
  font-size: 11px;
  color: #94a3b8;
  font-weight: 500;
  margin-bottom: 14px;
  line-height: 1.4;
}

/* ==================== 已就绪卡片 (初中数学标杆) ==================== */
.subject-card.is-ready {
  border-color: #93c5fd;
  box-shadow: 0 4px 16px -2px rgba(37, 99, 235, 0.1);
  cursor: pointer;
  background: linear-gradient(180deg, #ffffff 0%, #f8faff 100%);
  touch-action: manipulation;
}

.subject-card.is-ready:hover {
  transform: translateY(-4px);
  border-color: #2563eb;
  box-shadow: 0 12px 28px -4px rgba(37, 99, 235, 0.18);
}

.subject-card.is-ready:active {
  transform: translateY(-1px);
}

.subject-card.is-ready .subject-icon-box {
  background: #eff6ff;
  color: #2563eb;
}

.subject-card.is-ready .subject-status-badge {
  background: #ecfdf5;
  color: #059669;
  border: 1px solid #a7f3d0;
}

.subject-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.subject-enter-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: 8px;
  background: #2563eb;
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  width: 100%;
  justify-content: center;
  touch-action: manipulation;
}

.subject-card.is-ready:hover .subject-enter-btn {
  background: #1d4ed8;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.3);
}

/* ==================== 敬请期待卡片 (其余19科：点击不动作) ==================== */
.subject-card.is-disabled {
  background: #fdfdfd;
  opacity: 0.85;
  pointer-events: none; /* 关键：点击不动作，静默防误触 */
  cursor: default;
}

.subject-card.is-disabled .subject-status-badge {
  background: #f1f5f9;
  color: #64748b;
  border: 1px solid #e2e8f0;
}

.subject-card.is-disabled .subject-desc {
  color: #94a3b8;
}

.subject-disabled-badge-bottom {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  border-radius: 6px;
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  color: #94a3b8;
  font-size: 12px;
  font-weight: 500;
  width: 100%;
  box-sizing: border-box;
}

/* ==================== 7. 页脚规范 ==================== */
.platform-footer {
  background: #ffffff;
  border-top: 1px solid var(--border-color, #e2e8f0);
  padding: 24px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  padding-left: max(24px, env(safe-area-inset-left, 0px));
  padding-right: max(24px, env(safe-area-inset-right, 0px));
  text-align: center;
  font-size: 13px;
  color: #64748b;
}

.platform-footer-inner {
  max-width: 1240px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

/* 轻量提示弹窗 (Toast) */
.platform-toast {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(15, 23, 42, 0.94);
  color: #ffffff;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 10px 25px -3px rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: all 0.22s ease;
  z-index: 9999;
  white-space: nowrap;
  max-width: calc(100vw - 32px);
  text-align: center;
}

.platform-toast.active {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* =========================================================
   8. 响应式设计分层架构 (Tier 1 ~ Tier 4 & 手机矮横屏保障)
   完全对标初中数学成熟适配标准
   ========================================================= */

/* Tier 3: iPad 与平板主流尺寸 (769px ~ 1024px) */
@media (max-width: 1024px) {
  .platform-header-inner {
    padding: 0 18px;
  }
  .platform-main {
    padding: 24px 18px 48px 18px;
  }
  .subject-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
  }
  .hero-title {
    font-size: 28px;
  }
}

/* Tier 2: 主流手机端与折叠屏 (481px ~ 768px) */
@media (max-width: 768px) {
  .platform-header-inner {
    height: 56px;
    padding: 0 14px;
  }
  .platform-brand-icon {
    width: 34px;
    height: 34px;
    border-radius: 8px;
  }
  .platform-brand-title {
    font-size: 16px;
  }
  .platform-brand-badge {
    display: none; /* 移动端精简：隐藏徽章防挤占 */
  }

  /* 学习者胶囊精简文案 */
  .user-profile-capsule {
    padding: 0 10px 0 6px;
    height: 34px;
    font-size: 12px;
  }
  .header-action-btn {
    width: 34px;
    height: 34px;
  }
  .language-select-btn {
    height: 34px;
    padding: 0 8px;
    font-size: 12px;
  }

  /* 浮层在手机端固定防溢出 */
  .flyout-popover {
    position: fixed !important;
    top: calc(56px + env(safe-area-inset-top, 0px) + 8px) !important;
    right: max(12px, env(safe-area-inset-right, 0px)) !important;
    max-width: calc(100vw - 24px) !important;
    max-height: calc(85vh - 60px) !important;
    overflow-y: auto !important;
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.22) !important;
  }
  #notification-popover {
    width: calc(100vw - 24px) !important;
    max-width: 340px !important;
  }
  #user-popover {
    width: calc(100vw - 24px) !important;
    max-width: 290px !important;
  }

  .platform-main {
    padding: 20px 14px 44px 14px;
  }

  .hero-section {
    margin-bottom: 28px;
  }
  .hero-title {
    font-size: 24px;
  }
  .hero-subtitle {
    font-size: 13.5px;
    line-height: 1.5;
  }

  .stage-section-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    margin-bottom: 14px;
  }
  .stage-section-title {
    font-size: 18px;
  }
  .stage-section-desc {
    font-size: 12px;
  }

  .subject-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
  .subject-card {
    padding: 16px 14px;
    min-height: 165px;
  }
  .subject-title {
    font-size: 15.5px;
  }
}

/* Tier 1: 极小屏手机专项优化 (<= 480px, 如 iPhone SE, 华为/小米紧凑屏) */
@media (max-width: 480px) {
  .platform-header-inner {
    height: 52px;
    padding: 0 10px;
  }
  .platform-brand {
    gap: 8px;
  }
  .platform-brand-icon {
    width: 30px;
    height: 30px;
  }
  .platform-brand-title {
    font-size: 14.5px;
  }

  .platform-header-controls {
    gap: 6px;
  }

  /* 小屏上胶囊隐藏长文字，只保留头像与极简标识 */
  .user-profile-capsule span[data-i18n] {
    display: none;
  }
  .user-profile-capsule {
    padding: 0 6px;
    gap: 4px;
  }
  #current-lang-label {
    display: none; /* 只显示地球图标 */
  }
  .language-select-btn {
    padding: 0 7px;
  }

  /* 弹层全屏宽度居中边距 */
  .flyout-popover {
    right: 8px !important;
    left: 8px !important;
    width: auto !important;
    max-width: none !important;
  }

  .platform-main {
    padding: 16px 10px 36px 10px;
  }

  .hero-section {
    margin-bottom: 22px;
  }
  .hero-title {
    font-size: 20px;
  }
  .hero-subtitle {
    font-size: 12.5px;
  }

  /* 极小屏单列垂直堆叠，阅读体验最舒适 */
  .subject-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .subject-card {
    padding: 14px 12px;
    min-height: auto;
  }
  .subject-enter-btn {
    min-height: 42px; /* 触控手指热区保障 */
    font-size: 14px;
  }
}

/* ==================== 手机矮横屏专项底线保障 (Landscape & max-height: 500px) ====================
   国内外主流手机 (iPhone, 华为, 小米, vivo, OPPO, 三星等) 横屏专用
   高度仅 320px~450px，收紧上下空白，确保纵向视野开阔，不产生大面积阻挡 */
@media (orientation: landscape) and (max-height: 500px) {
  .platform-header-inner {
    height: 44px;
    padding: 0 16px;
  }
  .platform-brand-icon {
    width: 26px;
    height: 26px;
    border-radius: 6px;
  }
  .platform-brand-title {
    font-size: 14px;
  }
  .platform-brand-badge {
    display: none;
  }
  .header-action-btn,
  .language-select-btn,
  .user-profile-capsule {
    height: 30px;
  }
  .capsule-avatar {
    width: 20px;
    height: 20px;
  }

  .flyout-popover {
    top: calc(44px + 6px) !important;
    max-height: 75vh !important;
  }

  .platform-main {
    padding: 14px 16px 28px 16px;
  }
  .hero-section {
    margin-bottom: 14px;
  }
  .hero-pill-badge {
    display: none;
  }
  .hero-title {
    font-size: 18px;
    margin-bottom: 4px;
  }
  .hero-subtitle {
    display: none; /* 矮横屏隐藏副标题，省出宝贵首屏空间 */
  }

  .stage-section {
    margin-bottom: 24px;
  }
  .stage-section-header {
    margin-bottom: 10px;
    padding-bottom: 6px;
  }
  .stage-section-title {
    font-size: 16px;
  }

  /* 矮横屏采用 3 列横排，高效浏览 */
  .subject-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
  }
  .subject-card {
    padding: 12px 10px;
    min-height: auto;
  }
}
