/**
 * Phase 1 — Page-level responsive (Home dashboard inside workbench shell).
 * Mobile-first overrides: true native layouts, not scaled-down desktop.
 */

/* ── Compact home (mobile + iPad portrait, ≤1024px) ── */
@media (max-width: 1024px) {
  html[data-shell="dashboard"] .main-scroll:not(.main-scroll--module) {
    padding: 0 0 calc(var(--mobile-tab-h) + 12px + env(safe-area-inset-bottom, 0px));
    scrollbar-width: none;
  }

  html[data-shell="dashboard"] .main-scroll:not(.main-scroll--module)::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
  }

  html[data-shell="dashboard"] .home-dashboard--compact {
    padding: 12px 14px calc(24px + env(safe-area-inset-bottom, 0px));
  }

  /* Hero — vertical stack, auto height */
  html[data-shell="dashboard"] .hero-banner {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    min-height: 0;
    margin-bottom: 12px;
    border-radius: 16px;
    overflow: hidden;
    background-position: center 15%;
  }

  html[data-shell="dashboard"] .hero-banner::before {
    width: 100%; 
  }

  html[data-shell="dashboard"] .hero-copy {
    flex: none;
    max-width: none;
    padding: 16px 14px 10px;
  }

  html[data-shell="dashboard"] .hero-greeting {
    font-size: 15px;
    margin-bottom: 6px;
  }

  html[data-shell="dashboard"] .hero-title-line {
    font-size: 22px;
    line-height: 1.2;
  }

  html[data-shell="dashboard"] .hero-title-gradient {
    font-size: 26px;
    line-height: 1.15;
  }

  html[data-shell="dashboard"] .hero-sub {
    font-size: 14px;
    font-weight: 700;
    max-width: 58%;
    margin-bottom: 10px;
  }

  html[data-shell="dashboard"] .hero-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  html[data-shell="dashboard"] .stat-pill {
    flex: unset;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 0;
    padding: 8px 6px;
    border-radius: 12px;
    text-align: center;
  }

  html[data-shell="dashboard"] .stat-pill img {
    width: 22px;
    height: 22px;
  }

  html[data-shell="dashboard"] .stat-pill-text {
    align-items: center;
    gap: 1px;
  }

  html[data-shell="dashboard"] .stat-pill .label {
    font-size: 10px;
  }

  html[data-shell="dashboard"] .stat-pill .value {
    font-size: 13px;
  }

  /* Speech bubble — compact banner, not rotated overlay */
  html[data-shell="dashboard"] .speech-bubble {
    position: relative;
    top: auto;
    right: auto;
    margin: 0 12px 12px;
    display: block;
  }

  html[data-shell="dashboard"] .speech-bubble__card {
    width: 100%;
    max-width: none;
    padding: 12px 14px;
    border-radius: 14px;
    transform: none;
    filter: none;
    box-shadow: 0 2px 10px rgba(59, 76, 150, 0.1);
    text-align: left;
  }

  html[data-shell="dashboard"] .speech-bubble__card::after {
    display: none;
  }

  html[data-shell="dashboard"] .speech-line--compact {
    margin: 0;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.45;
    text-align: left;
  }

  html[data-shell="dashboard"] .speech-bubble__card.is-done .speech-bubble-icon,
  html[data-shell="dashboard"] .speech-line--compact .speech-bubble-icon {
    opacity: 1;
  }

  /* Sections */
  html[data-shell="dashboard"] .section-bg,
  html[data-shell="dashboard"] .explore-section {
    border-radius: 16px;
    padding: 14px 12px 16px;
    margin-bottom: 12px;
  }

  html[data-shell="dashboard"] .section-head {
    margin-bottom: 12px;
  }

  html[data-shell="dashboard"] .section-head h3 {
    font-size: 17px;
  }

  /* Explore — native vertical list */
  html[data-shell="dashboard"] .explore-mobile-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }

  html[data-shell="dashboard"] .explore-mobile-card {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 14px;
    border-radius: 14px;
    color: #fff;
    text-decoration: none;
    border: none;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.12);
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.15s ease;
  }

  html[data-shell="dashboard"] a.explore-mobile-card:active {
    transform: scale(0.98);
  }

  html[data-shell="dashboard"] .explore-mobile-card__icon {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 14px; 
  }

  html[data-shell="dashboard"] .explore-mobile-card__icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }

  html[data-shell="dashboard"] .explore-mobile-card__body {
    flex: 1;
    min-width: 0;
    text-align: left;
  }

  html[data-shell="dashboard"] .explore-mobile-card__body h4 {
    margin: 0 0 3px;
    font-size: 15px;
    font-weight: 800;
    line-height: 1.25;
  }

  html[data-shell="dashboard"] .explore-mobile-card__body p {
    margin: 0;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.35;
    opacity: 0.92;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  html[data-shell="dashboard"] .explore-mobile-card__cta {
    flex-shrink: 0;
    font-size: 11px;
    font-weight: 800;
    opacity: 0.9;
    white-space: nowrap;
  }

  html[data-shell="dashboard"] .explore-mobile-card.blue {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  }

  html[data-shell="dashboard"] .explore-mobile-card.purple {
    background: linear-gradient(135deg, #8b5cf6 0%, #6d28d9 100%);
  }

  html[data-shell="dashboard"] .explore-mobile-card.pink {
    background: linear-gradient(135deg, #ec4899 0%, #db2777 100%);
  }

  html[data-shell="dashboard"] .explore-mobile-card.green {
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
  }

  html[data-shell="dashboard"] .explore-mobile-card.orange {
    background: linear-gradient(135deg, #f59e0b 0%, #ea580c 100%);
  }

  html[data-shell="dashboard"] .explore-mobile-card.teal {
    background: linear-gradient(135deg, #14b8a6 0%, #0d9488 100%);
  }

  /* Popular tools — 4-column grid */
  html[data-shell="dashboard"] .section-bg--tools .tools-row {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px 8px;
    overflow: visible;
    scroll-snap-type: none;
    padding-bottom: 0;
  }

  html[data-shell="dashboard"] .section-bg--tools .tool-item {
    flex: unset;
    min-width: 0;
  }

  html[data-shell="dashboard"] .section-bg--tools .tool-circle {
    width: 52px;
    height: 52px;
    margin-bottom: 6px;
    border-radius: 14px;
  }

  html[data-shell="dashboard"] .section-bg--tools .tool-item span {
    font-size: 11px;
    line-height: 1.2;
  }

  /* Recent media & world — two columns on mobile */
  html[data-shell="dashboard"] .cards-row--6,
  html[data-shell="dashboard"] .world-row--6 {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px;
  }

  html[data-shell="dashboard"] .project-card .thumb {
    aspect-ratio: 1 / 1;
    border-radius: 12px;
  }

  html[data-shell="dashboard"] .project-card .title,
  html[data-shell="dashboard"] .recent-media-title {
    font-size: 12px;
    text-align: left;
    margin-top: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  html[data-shell="dashboard"] .world-card {
    aspect-ratio: 1 / 1;
    border-radius: 12px;
  }

  html[data-shell="dashboard"] .world-card .overlay {
    padding: 8px;
  }

  html[data-shell="dashboard"] .world-card .overlay span {
    font-size: 12px;
    line-height: 1.2;
    text-align: center;
  }
}

/* ── Phone-only home tweaks (≤768px) ── */
@media (max-width: 768px) {
  html[data-shell="dashboard"] .home-dashboard--compact {
    padding: 10px 12px calc(16px + env(safe-area-inset-bottom, 0px));
  }
}

/* ── Tablet home (769–1024px, iPad portrait) ── */
@media (min-width: 769px) and (max-width: 1024px) {
  html[data-shell="dashboard"] .hero-banner {
    min-height: 280px;
  }

  html[data-shell="dashboard"] .hero-greeting {
    font-size: 17px;
  }

  html[data-shell="dashboard"] .hero-title-line {
    font-size: 24px;
  }

  html[data-shell="dashboard"] .hero-title-gradient {
    font-size: 32px;
  }

  html[data-shell="dashboard"] .hero-sub {
    font-size: 15px;
    max-width: 72%;
  }

  html[data-shell="dashboard"] .hero-copy {
    width: 100%;
    box-sizing: border-box;
  }

  html[data-shell="dashboard"] .hero-stats {
    width: 55%;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
  }

  html[data-shell="dashboard"] .stat-pill {
    width: 100%;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    padding: 12px 14px;
    min-width: 0;
  }

  html[data-shell="dashboard"] .stat-pill img {
    width: 30px;
    height: 30px;
  }

  html[data-shell="dashboard"] .stat-pill-text {
    align-items: flex-start;
    flex: 1;
    min-width: 0;
  }

  html[data-shell="dashboard"] .stat-pill .label {
    font-size: 11px;
  }

  html[data-shell="dashboard"] .stat-pill .value {
    font-size: 15px;
  }

  html[data-shell="dashboard"] .section-head h3 {
    font-size: 19px;
  }

  html[data-shell="dashboard"] .section-bg--tools .tools-row {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 14px 10px;
  }

  html[data-shell="dashboard"] .section-bg--tools .tool-circle {
    width: 66px;
    height: 66px;
    margin-bottom: 8px;
    border-radius: 16px;
  }

  html[data-shell="dashboard"] .section-bg--tools .tool-item span {
    font-size: 13px;
    line-height: 1.25;
  }

  html[data-shell="dashboard"] .explore-swiper .swiper-slide {
    height: auto;
  }

  html[data-shell="dashboard"] .explore-swiper .explore-card {
    width: 100%;
    max-width: 100%;
    min-height: 220px;
  }

  html[data-shell="dashboard"] .cards-row--6,
  html[data-shell="dashboard"] .world-row--6 {
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  }
}

/* ── iPad landscape / iPad Pro narrow desktop (1025–1366px) ── */
@media (min-width: 1025px) and (max-width: 1366px) {
  html[data-shell="dashboard"] .app {
    grid-template-columns: 72px minmax(0, 1fr) !important;
  }

  html[data-shell="dashboard"] .sidebar-left .sidebar-toggle {
    display: none !important;
  }

  html[data-shell="dashboard"] .main-scroll:not(.main-scroll--module) {
    padding-bottom: 24px;
  }

  html[data-shell="dashboard"] .hero-banner {
    min-height: 350px;
  }

  html[data-shell="dashboard"] .explore-card {
    width: 100%;
    max-width: 100%;
    min-height: 240px;
  }

  html[data-shell="dashboard"] .cards-row--6,
  html[data-shell="dashboard"] .world-row--6 {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }
}

/* ── Home stage panel (≤1366px): widgets below AI World, multi-column cards ── */
@media (max-width: 1366px) {
  html[data-shell="dashboard"] .home-stage-panel {
    margin-top: 4px;
  }

  html[data-shell="dashboard"] .home-stage-panel .sidebar-right {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    overflow: visible;
    flex: none;
    min-height: 0;
    width: 100%;
  }

  html[data-shell="dashboard"] .home-stage-panel .widget {
    border-radius: 18px;
    min-width: 0;
    width: auto;
    max-width: none;
    height: auto;
  }

  html[data-shell="dashboard"] .home-stage-panel .mission-widget {
    border-radius: 20px;
  }

  html[data-shell="dashboard"] .home-stage-panel .mission-widget__content {
    flex-direction: column;
    align-items: stretch;
  }

  html[data-shell="dashboard"] .home-stage-panel .mission-widget__visual {
    align-self: center;
    margin-top: 10%;
    width: 100%;
    height: 100%;
  }

  html[data-shell="dashboard"] .home-stage-panel .mission-widget__visual img {
    height: 138px;
    width: auto;
  }
  
  html[data-shell="dashboard"] .home-stage-panel .progress-widget__body {
    flex-direction: column;
    gap: 12px;
  }
  
  html[data-shell="dashboard"] .home-stage-panel .progress-stats {
    padding-right: 0;
    gap: 10px;
  }

  html[data-shell="dashboard"] .home-stage-panel .progress-widget__divider {
    display: none;
  }

  html[data-shell="dashboard"] .home-stage-panel .progress-badge {
    justify-content: center;
    text-align: center;
    flex-direction: row;
    width: 100%;
  }
  .progress-badge__text{
    font-size: 15px;
  }

  html[data-shell="dashboard"] .home-stage-panel .leader-list li {
    padding: 8px 0;
  }

  html[data-shell="dashboard"] .home-stage-panel .rewards-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    margin-bottom: 14px;
  }

  html[data-shell="dashboard"] .home-stage-panel .reward-day {
    flex: unset;
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 14px;
    box-sizing: border-box;
  }

  html[data-shell="dashboard"] .home-stage-panel .reward-day__label {
    text-align: left;
  }
}

@media (min-width: 769px) and (max-width: 1024px) {
  html[data-shell="dashboard"] .home-stage-panel .sidebar-right {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 768px) {
  html[data-shell="dashboard"] .home-stage-panel .sidebar-right {
    grid-template-columns: repeat(1, minmax(0, 1fr));
    gap: 10px;
  }
}

/* ── Learn AI — critical CSS (sync in index.html, prevents FOUC on hard refresh) ── */
.learn-ai-shell {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background: #f6f8fc;
}

/* Hide until Vue marks ready — avoids unstyled flash while route chunk CSS loads */
.learn-ai-shell:not(.learn-ai-shell--ready) {
  visibility: hidden;
}

.learn-ai-shell.learn-ai-shell--ready {
  visibility: visible;
}

.learn-ai-shell .learn-body {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

@media (max-width: 1024px) {
  .learn-desktop-only {
    display: none !important;
  }

  html[data-shell="dashboard"] .learn-ai-shell .learn-body {
    padding: 0 0 calc(16px + var(--mobile-tab-h, 68px) + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(180deg, #eef2fa 0%, #f6f8fc 28%, #f6f8fc 100%);
  }

  .learn-ai-shell .learn-mobile-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 0 14px;
  }

  .learn-ai-shell .lesson-grid.learn-desktop-only {
    display: none !important;
  }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .learn-ai-shell .learn-mobile-list {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    padding: 0 14px;
  }
}

@media (min-width: 1025px) {
  .learn-mobile-only {
    display: none !important;
  }

  .learn-ai-shell .learn-mobile-list {
    display: none !important;
  }
}

/* ── Billing / Usage — critical shell (sync load, FOUC guard) ── */
.billing-shell,
.usage-shell {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.usage-shell:not(.usage-shell--ready) {
  visibility: hidden;
}

.usage-shell.usage-shell--ready {
  visibility: visible;
}

@media (max-width: 1024px) {
  .usage-desktop-only {
    display: none !important;
  }

  html[data-shell="dashboard"] .main-scroll--module .usage-shell .canvas-body.page-body,
  html[data-shell="dashboard"] .usage-shell .page-body {
    min-height: 0;
    padding: 0 !important;
    overflow: hidden;
    background: #f3f5fa;
  }

  .usage-shell .usage-m-page {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    height: 100%;
  }
}

@media (min-width: 1025px) {
  .usage-mobile-only {
    display: none !important;
  }
}

@media (max-width: 1024px) {
  html[data-shell="dashboard"] .billing-shell .billing-body,
  html[data-shell="dashboard"] .usage-shell .page-body {
    min-height: 0;
  }
}
