/*
 * GlimWorld shared view layout
 * Loaded after the legacy and platform styles so responsive rules stay
 * consistent without changing view content, behavior, or creator canvases.
 */

:root {
  --gw-layout-gutter: clamp(14px, 2.4vw, 34px);
  --gw-layout-content: 1480px;
}

html,
body {
  max-width: 100%;
  overflow-x: clip;
}

#main-content {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.view {
  width: 100%;
  max-width: var(--gw-layout-content);
  min-width: 0;
  box-sizing: border-box;
  margin-inline: auto;
  padding-inline: var(--gw-layout-gutter);
}

.view > *,
.view section,
.view header,
.view article,
.view form {
  min-width: 0;
  box-sizing: border-box;
}

.view :is(h1, h2, h3, h4) {
  overflow-wrap: break-word;
}

.view :is(img, video, iframe) {
  max-width: 100%;
}

/* Keep common content columns fluid and let cards shrink before they overflow. */
.view :is(.library-grid, .feature-cards, .achievements-grid, .gw-resume-grid,
  .gw-home-resume-grid, .gw-qa-grid, .gw-social-actions, .edu-grid,
  #eduGrid, #discoveryGrid, #draftsGrid, #achievementGrid, #leaderboardGrid) {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr));
  min-width: 0;
}

.view :is(.library-card, .edu-card, .ach-card, .gw-panel, .gw-qa-card,
  .gw-social-action, .gw-world-card, .gw-lesson-card, .gw-shop-card,
  .gw-friend-card, .shop-item) {
  min-width: 0;
  max-width: 100%;
}

.view :is(.library-controls, .gw-shop-toolbar, .gw-section-head,
  .gw-shop-hub-nav, .gw-social-actions, .gw-hero-ctas) {
  min-width: 0;
  flex-wrap: wrap;
}

.view :is(input, select, textarea) {
  max-width: 100%;
  min-width: 0;
}

.view :is(button, [role="button"], a, summary, select, input[type="button"],
  input[type="submit"]) {
  touch-action: manipulation;
}

/* Homepage: keep the feature story and quick actions balanced across widths. */
#view-home .gw-hero {
  grid-template-columns: minmax(0, 1.12fr) minmax(0, .88fr);
  width: 100%;
}

#view-home .gw-hero-copy,
#view-home .gw-hero-art {
  min-width: 0;
}

#view-home .gw-hero h1 {
  max-width: 14ch;
  font-size: clamp(34px, 5vw, 58px);
  line-height: 1.02;
}

#view-home .gw-qa-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

/* Discovery and drafts: preserve the grid/list modes while making columns
   fit available width rather than forcing a fixed minimum on small screens. */
#view-discovery .library-controls,
#view-drafts .library-controls {
  align-items: center;
  gap: 10px;
}

#view-discovery .library-controls > *,
#view-drafts .library-controls > * {
  min-width: 0;
  max-width: 100%;
}

#view-discovery .library-grid,
#view-drafts .library-grid {
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 248px), 1fr));
  gap: clamp(10px, 1.5vw, 18px);
}

#view-discovery .library-grid.list-view .library-thumb,
#view-drafts .library-grid.list-view .library-thumb {
  width: clamp(112px, 18vw, 170px);
}

/* Shop: the preview sidebar becomes a normal-width top block on compact screens. */
#view-shop .shop-layout {
  grid-template-columns: minmax(230px, .72fr) minmax(0, 1.8fr);
  min-width: 0;
}

#view-shop .shop-layout > *,
#view-shop .shop-layout > :first-child {
  min-width: 0;
}

#view-shop .shop-layout > :first-child {
  top: calc(var(--gw-shell-height, var(--gw-tbh, 64px)) + 14px);
}

#view-shop :is(.shop-grid, #shopItems, #gwShopCatalog, #avatarShopGrid,
  #communityShopGrid, #tradeGrid) {
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr));
  min-width: 0;
}

/* Education: controls wrap and lesson cards use the same readable density. */
#view-education .library-controls,
#view-education .gw-edu-teacher-tools,
#view-education .gw-edu-more-filters {
  min-width: 0;
}

#view-education :is(.edu-grid, #eduGrid) {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 250px), 1fr));
}

/* Social, destination, and progress views. */
#view-social .gw-social-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
}

#view-social :is(.messages-layout, .groups-layout, .social-layout) {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.45fr);
  min-width: 0;
}

#view-explore :is(.explore-grid, .destination-grid),
#view-jams :is(.jam-grid, .library-grid),
#view-daily :is(.daily-grid, .daily-challenges),
#view-achievements .achievements-grid,
#view-leaderboard :is(.leaderboard-list, .leaderboard-grid) {
  min-width: 0;
}

#view-achievements .achievements-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 245px), 1fr));
}

/* Creator and play screens: only constrain the surrounding layout. The
   studio/playground canvas and its sizing rules are intentionally untouched. */
#view-build > *,
#view-play > *,
#view-multiplayer > * {
  min-width: 0;
  max-width: 100%;
}

#view-build .studio-tabs-bar,
#view-build .studio-tool-row,
#view-build .studio-panel-header,
#view-multiplayer :is(.room-actions, .room-toolbar) {
  flex-wrap: wrap;
}

@media (min-width: 1600px) {
  :root { --gw-layout-content: 1560px; }
}

@media (max-width: 1023px) {
  #view-home .gw-hero {
    grid-template-columns: minmax(0, 1fr) minmax(200px, .8fr);
  }

  #view-home .gw-qa-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #view-shop .shop-layout {
    grid-template-columns: minmax(200px, .72fr) minmax(0, 1.8fr);
    gap: 16px;
  }
}

@media (max-width: 767px) {
  .view {
    padding: 16px clamp(12px, 3.5vw, 20px) 30px;
  }

  .view :is(.gw-section-head, .gw-home-happenings-head) {
    align-items: flex-start;
    gap: 8px;
  }

  .view :is(.library-controls, .gw-shop-toolbar) > * {
    flex: 1 1 145px;
    max-width: 100%;
  }

  #view-home .gw-hero {
    grid-template-columns: minmax(0, 1fr);
  }

  #view-home .gw-hero-art {
    min-height: 160px;
  }

  #view-shop .shop-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  #view-shop .shop-layout > :first-child {
    position: static;
  }

  #view-social :is(.messages-layout, .groups-layout, .social-layout) {
    grid-template-columns: minmax(0, 1fr);
  }

  #view-discovery .library-grid.list-view .library-thumb,
  #view-drafts .library-grid.list-view .library-thumb {
    width: clamp(92px, 28vw, 145px);
  }

  #view-build .studio-tabs-bar {
    overflow-x: auto;
    flex-wrap: nowrap;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }
}

@media (max-width: 480px) {
  .view {
    padding-inline: 12px;
  }

  .view :is(.library-controls, .gw-shop-toolbar) {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .view :is(.library-controls, .gw-shop-toolbar) > :first-child {
    grid-column: 1 / -1;
  }

  #view-home .gw-qa-grid {
    gap: 8px;
  }

  #view-discovery .library-grid,
  #view-drafts .library-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 210px), 1fr));
  }

  #view-discovery .library-grid.list-view .library-card,
  #view-drafts .library-grid.list-view .library-card {
    flex-direction: column;
  }

  #view-discovery .library-grid.list-view .library-thumb,
  #view-drafts .library-grid.list-view .library-thumb {
    width: 100%;
    min-height: 130px;
  }
}

:where(button, a, input, select, textarea, summary, [role="button"]):focus-visible {
  outline: 3px solid var(--gw-accent, #f2741b);
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .view *,
  .view *::before,
  .view *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
