/* ════════════════════════════════════════════════════════════
   RESPONSIVE — breakpoints 320→640 (mobile), 641→1024 (tablet),
                1025+ (desktop sidebar), 1200+ (wide)
   ════════════════════════════════════════════════════════════ */

/* ── Mobile: up to 640px ───────────────────────────────────── */

@media (max-width: 640px) {

  /* Layout */
  .app-main {
    width: 100%;
    max-width: 100%;
    padding: 0 0 calc(var(--mobile-nav-clearance, 96px) + env(safe-area-inset-bottom));
  }

  .app-main--home,
  .app-main--profile,
  .app-main--take,
  .app-main--search,
  .app-main--narrow {
    max-width: 100%;
  }

  /* Remove side borders on mobile */
  .feed-column,
  .profile-column,
  .take-detail,
  .search-shell,
  .explore-shell,
  .notifications-shell {
    border-left: 0;
    border-right: 0;
  }

  /* Home header */
  .home-head {
    gap: 0;
    padding: 0;
  }

  .home-head__bar {
    grid-template-columns: 28px minmax(0, 1fr) 28px;
    gap: 6px;
    padding: 6px var(--space-3) 4px;
  }

  .home-head__spacer {
    width: 28px;
    height: 28px;
  }

  .home-head__brand {
    width: 58px;
    height: 30px;
  }

  .home-head__utility {
    width: 28px;
    height: 28px;
  }

  body[data-page="home"] .feed-head__inner {
    padding: 0;
  }

  .home-switch__btn {
    min-height: 58px;
    padding: 8px 12px 16px;
    font-size: clamp(0.96rem, 0.88rem + 0.7vw, 1.15rem);
  }

  .home-switch {
    gap: 8px;
    padding: 10px var(--space-3) 16px;
  }

  .feed-state,
  .feed-empty {
    padding: 12px var(--space-3);
    font-size: 0.82rem;
  }

  /* Take items - tighter on mobile */
  .feed-stream .take-item,
  .profile-feed:not(.profile-feed--grid) .take-item,
  .take-item {
    grid-template-columns: 38px minmax(0, 1fr);
    gap: 10px;
    padding: 12px var(--space-3);
  }

  .feed-stream .take-item__avatar,
  .profile-feed:not(.profile-feed--grid) .take-item__avatar,
  .take-item__avatar {
    width: 34px;
    height: 34px;
    font-size: 0.7rem;
  }

  .feed-stream .take-item__meta,
  .profile-feed:not(.profile-feed--grid) .take-item__meta {
    margin-bottom: 5px;
    gap: 5px;
    font-size: 0.75rem;
  }

  .feed-stream .take-item__text,
  .profile-feed:not(.profile-feed--grid) .take-item__text,
  .take-item__text {
    font-size: clamp(0.96rem, 0.92rem + 0.3vw, 1.08rem);
    line-height: 1.44;
  }

  .feed-stream .take-item__media,
  .profile-feed:not(.profile-feed--grid) .take-item__media,
  .take-item__media {
    margin-top: 10px;
    max-width: 100%;
  }

  .feed-stream .take-item__media--split,
  .profile-feed:not(.profile-feed--grid) .take-item__media--split,
  .take-item__media--split {
    aspect-ratio: 4 / 3;
  }

  /* Actions */
  .take-item__meta {
    align-items: flex-start;
  }

  .take-item__meta-main {
    gap: 5px;
  }

  .take-item__share-mobile {
    display: inline-flex;
    min-width: 38px;
    min-height: 38px;
    margin-top: -4px;
  }

  .take-item__actions-top {
    gap: 6px;
  }

  .take-item__actions {
    gap: 2px;
  }

  .take-item__actions-side {
    gap: 4px;
  }

  .take-item__actions .take-action--share {
    display: none;
  }

  .take-action {
    min-height: 38px;
    min-width: 40px;
    padding: 0 9px;
  }

  .take-action--vote {
    min-width: 48px;
    min-height: 46px;
    padding: 4px 5px;
  }

  .take-action--vote .take-action__stack {
    flex-direction: row;
    gap: 4px;
  }

  .take-action--vote .take-action__label {
    display: none;
  }

  .take-action--comments .take-action__icon .app-icon {
    width: 21px;
    height: 21px;
  font-size: 21px;
}

  .take-action--judge {
    min-width: 70px;
    min-height: 38px;
    padding: 0 8px;
    font-size: 0.66rem;
  }

  .take-vote-split {
    margin-top: 10px;
  }

  .home-switch__btn {
    min-height: 30px;
    padding: 0 10px;
    font-size: 0.72rem;
  }

  /* Profile */
  .profile-head {
    padding: var(--space-3);
    gap: var(--space-2);
  }

  .profile-head__hero {
    grid-template-columns: 72px minmax(0, 1fr);
    gap: var(--space-3);
  }

  .profile-avatar {
    width: 72px;
    height: 72px;
    font-size: 0.92rem;
  }

  .profile-username {
    font-size: 1.2rem;
  }

  .profile-stat {
    min-height: 52px;
  }

  .profile-stat strong {
    font-size: 1.1rem;
  }

  .profile-stat span {
    font-size: 0.74rem;
  }

  .profile-bio {
    max-width: 100%;
    font-size: 0.9rem;
    line-height: 1.5;
  }

  .profile-head__actions {
    width: 100%;
  }

  .profile-head__actions .btn {
    flex: 1;
    min-height: 38px;
  }

  .profile-controls {
    padding-left: var(--space-2);
    padding-right: var(--space-2);
  }

  .profile-tab {
    min-height: 38px;
    padding: 0 10px;
  }

  .view-toggle {
    padding-left: 4px;
  }

  .view-toggle__btn {
    min-width: 40px;
    padding: 0 8px;
  }

  .profile-feed--grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  /* Comments */
  .comments-shell {
    padding: var(--space-3);
  }

  .comments-shell__head {
    gap: var(--space-2);
    padding-bottom: var(--space-2);
  }

  .comment-compose {
    margin-top: var(--space-2);
    padding: 8px;
    gap: 8px;
  }

  .comment-compose__field textarea {
    min-height: 44px;
    padding: 10px 12px;
  }

  .comment-item {
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 10px;
  }

  .comment-item__avatar {
    width: 34px;
    height: 34px;
  }

  .comment-item__text {
    font-size: 0.88rem;
    line-height: 1.52;
  }

  .comment-item__actions {
    column-gap: 18px;
    row-gap: 10px;
    margin-top: 10px;
  }

  .comment-action {
    min-height: 38px;
    padding: 6px 8px;
    font-size: 0.86rem;
    font-weight: 750;
  }

  .comment-action--like {
    --comment-like-icon-size: 18px;
    gap: 7px;
  }

  .comment-action--like .comment-action__icon .app-icon {
    width: var(--comment-like-icon-size);
    height: var(--comment-like-icon-size);
  font-size: var(--comment-like-icon-size);
}

  .comment-action--like .comment-action__count {
    font-size: 0.84rem;
    font-weight: 750;
  }

  .comment-action--icon-plain {
    min-height: 36px;
    padding: 6px 0;
    gap: 7px;
  }

  .comment-action--icon-plain .comment-action__icon .app-icon {
    width: 20px;
    height: 20px;
  font-size: 20px;
}

  /* Create / Compose */
  .composer-modal__dialog {
    width: 100%;
    margin: 0;
    max-height: 100dvh;
    height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  .composer-head {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: var(--space-3);
    background: var(--color-surface);
  }

  .composer-form {
    padding: var(--space-3);
    gap: var(--space-3);
  }

  .take-textarea {
    min-height: 120px;
  }

  .image-preview-placeholder {
    min-height: 100px;
  }

  .composer-side {
    display: none;
  }

  /* Search */
  .search-shell__head {
    padding: 16px var(--space-3) 14px;
  }

  .search-discovery {
    padding: 0 var(--space-3) 14px;
  }

  .page-search {
    padding: 12px var(--space-3) 0;
  }

  .search-group__head,
  .search-state,
  .search-topic-card,
  .category-keywords,
  .explore-card,
  .notification-item,
  .notification-empty {
    padding-left: var(--space-3);
    padding-right: var(--space-3);
  }

  /* Notification items */
  .notification-item {
    grid-template-columns: 40px minmax(0, 1fr) auto;
    gap: 10px;
    padding-top: 12px;
    padding-bottom: 12px;
  }

  .notification-item__avatar {
    width: 40px;
    height: 40px;
  }

  /* Hide desktop-only notifications drawer on mobile */
  .notifications-drawer {
    display: none !important;
  }

  /* Feed empty visual on mobile */
  .feed-empty-visual {
    padding: 24px var(--space-3) 28px;
  }

  .feed-personalization {
    padding: 16px var(--space-3) 18px;
    gap: 12px;
  }

  .feed-personalization__chips {
    gap: 8px;
  }

  /* Auth on mobile */
  .auth-main {
    padding: var(--space-3);
    gap: var(--space-3);
  }

  /* Search suggestions */
  .search-suggestions {
    border-radius: var(--radius-2);
  }
}

/* ── Very small screens: up to 360px ──────────────────────── */

@media (max-width: 360px) {
  .home-head__brand {
    width: 84px;
  }

  .feed-stream .take-item,
  .take-item {
    padding: 10px var(--space-2);
    gap: 8px;
  }

  .take-action {
    min-height: 36px;
    min-width: 36px;
    padding: 0 7px;
  }

  /* Narrower vote button so it fits on 320px without overflowing */
  .take-action--vote {
    min-width: 50px;
    min-height: 46px;
    padding: 4px 5px;
    font-size: 0.72rem;
  }

  .profile-head__hero {
    grid-template-columns: 64px minmax(0, 1fr);
  }

  .profile-avatar {
    width: 64px;
    height: 64px;
  }
}

/* ── iPhone common sizes: 375px–412px ─────────────────────── */

@media (min-width: 361px) and (max-width: 430px) {
  /* Slightly larger avatar and spacing for common iPhone screen sizes */
  .feed-stream .take-item,
  .profile-feed:not(.profile-feed--grid) .take-item {
    grid-template-columns: 38px minmax(0, 1fr);
    gap: 10px;
    padding: 13px var(--space-3);
  }

  .feed-stream .take-item__avatar,
  .profile-feed:not(.profile-feed--grid) .take-item__avatar {
    width: 36px;
    height: 36px;
  }

  /* Profile grid: 2-column on narrow phones, 3-column on wider phones */
  .profile-feed--grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /* Vote buttons fit comfortably at this range */
  .take-action--vote {
    min-width: 54px;
    padding: 4px 6px;
  }

  /* Comfortable profile stat sizing */
  .profile-stat strong {
    font-size: 1.08rem;
  }

  .profile-stat span {
    font-size: 0.68rem;
    line-height: 1.15;
  }
}

/* ── Tablet: 641px–1024px ──────────────────────────────────── */

@media (min-width: 641px) and (max-width: 1024px) {
  .top-nav {
    display: none;
  }

  .app-main {
    width: min(100%, 860px);
    margin: 0 auto;
    padding: var(--space-3) var(--space-3) calc(var(--mobile-nav-clearance, 96px) + env(safe-area-inset-bottom));
  }

  .feed-column,
  .profile-column,
  .take-detail,
  .search-shell,
  .explore-shell,
  .notifications-shell {
    border-left: var(--line);
    border-right: var(--line);
  }

  body[data-page="home"] .feed-column {
    border-left: 0;
    border-right: 0;
  }

  body[data-page="settings"] .feed-column {
    border-left: 0;
    border-right: 0;
  }

  body[data-page="category"] .feed-column {
    border-left: 0;
    border-right: 0;
  }

  .notifications-drawer {
    display: none !important;
  }

  .profile-head {
    padding: var(--space-5) var(--space-4);
  }

  .profile-head__hero {
    grid-template-columns: 92px minmax(0, 1fr);
  }
}

/* ── Desktop auth layout ───────────────────────────────────── */

@media (min-width: 1025px) {
  .auth-main {
    grid-template-columns: minmax(260px, 0.9fr) minmax(420px, 520px) minmax(260px, 320px);
  }

  .setup-shell {
    grid-template-columns: minmax(280px, 360px) minmax(480px, 1fr) minmax(260px, 320px);
    align-items: start;
  }

  .setup-brand,
  .setup-panel,
  .setup-rail {
    position: sticky;
    top: 104px;
  }
}

/* ── Desktop sidebar layout ────────────────────────────────── */

@media (min-width: 1025px) {
  .top-nav {
    display: block;
    position: fixed;
    top: 16px;
    left: max(14px, calc((100vw - (var(--max-width) + var(--desktop-nav-width) + var(--desktop-nav-gap))) / 2));
    width: var(--desktop-nav-width);
    z-index: 45;
    border-bottom: 0;
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .top-nav__inner {
    width: 100%;
    min-height: calc(100vh - 32px);
    padding: 0;
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-3);
  }

  .brand {
    min-width: 0;
    margin: 0;
    text-align: left;
    justify-content: flex-start;
    gap: 6px;
    font-size: 0.88rem;
    padding: 4px 2px 12px;
    border-bottom: var(--line);
  }

  .brand__mark {
    width: 64px;
    height: 36px;
  }

  .desktop-nav {
    flex: 1 1 auto;
    width: 100%;
    margin-left: 0;
    display: flex;
    min-height: 0;
  }

  .desktop-nav__list {
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    flex: 1 1 auto;
    gap: 4px;
    padding-bottom: 18px;
  }

  .desktop-nav__link {
    width: 100%;
    min-height: 48px;
    justify-content: flex-start;
    padding: 0 14px;
    border-radius: var(--radius-2);
    font-size: 0.86rem;
  }

  .desktop-nav__icon {
    width: 20px;
    height: 20px;
    margin-right: 12px;
  }

  .desktop-nav__icon .app-icon {
    width: 20px;
    height: 20px;
  font-size: 20px;
}

  .bottom-nav {
    display: none;
  }

  .app-main {
    width: min(100%, calc(var(--max-width) + var(--desktop-nav-width) + var(--desktop-nav-gap)));
    margin: 0 auto;
    padding-left: calc(var(--desktop-nav-width) + var(--desktop-nav-gap));
    padding-right: var(--space-5);
    padding-top: var(--space-4);
    padding-bottom: var(--space-7);
  }

  .app-main--narrow {
    max-width: calc(var(--max-width-narrow) + (var(--space-4) * 2));
  }

  .app-main--take {
    max-width: none;
  }

  body[data-page="settings"] .app-main--narrow {
    max-width: none;
  }

  .app-main--search {
    max-width: none;
  }

  .app-main--profile {
    max-width: none;
  }

  .feed-column,
  .profile-column,
  .take-detail,
  .search-shell,
  .explore-shell,
  .notifications-shell {
    border-left: var(--line);
    border-right: var(--line);
  }

  body[data-page="home"] .feed-column {
    border-left: 0;
    border-right: 0;
  }

  body[data-page="settings"] .feed-column {
    border-left: 0;
    border-right: 0;
  }

  body[data-page="category"] .feed-column {
    border-left: 0;
    border-right: 0;
  }

  .home-head {
    gap: 0;
    padding: 0;
  }

  .home-head__bar {
    grid-template-columns: 32px minmax(0, 1fr) 32px;
    gap: 8px;
    padding: 6px var(--space-4) 4px;
  }

  .home-head__spacer {
    width: 32px;
    height: 32px;
  }

  .home-head__brand {
    display: inline-flex;
    width: 64px;
    height: 34px;
  }

  .home-head__utility {
    display: inline-flex;
  }

  .home-switch__btn {
    min-height: 56px;
    padding: 8px 16px 14px;
    font-size: clamp(1rem, 0.92rem + 0.45vw, 1.3rem);
  }

  .theme-toggle {
    right: calc(50% - var(--max-width-narrow) / 2 - 52px);
    bottom: 28px;
  }
}

/* ── Wide: 1200px + ────────────────────────────────────────── */

@media (min-width: 1200px) {
  .app-main--home,
  .app-main--take {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: var(--space-5);
    align-items: start;
  }

  .side-column {
    display: block;
    position: sticky;
    top: var(--space-4);
  }

  .profile-feed--grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
