/*── Mobile & tablet — loaded after os-theme.css; desktop unchanged ──*/

@media (max-width: 768px) {
  html {
    overflow-x: clip;
  }

  .wallet-dropdown-nav-items {
    display: block;
    padding-bottom: 10px;
    margin-bottom: 10px;
    border-bottom: 1px solid var(--border);
  }

  .page-max,
  .view-wrapper,
  .container,
  .feed-max,
  .feed-wrapper,
  .issues-page,
  header .header-inner,
  footer .footer-inner {
    max-width: 100%;
    min-width: 0;
  }

  /* Header — 2-row layout: logo + utilities / full-width search */
  header {
    height: auto;
    min-height: 0;
    padding: 0 max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
    padding-top: env(safe-area-inset-top, 0);
  }
  header .header-inner {
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    grid-template-rows: auto auto;
    align-items: center;
    gap: 6px 8px;
    padding: 8px 0 10px;
  }
  .header-top {
    display: contents;
  }
  header .logo {
    grid-column: 1;
    grid-row: 1;
    font-size: 18px;
    min-width: 0;
  }
  .header-search {
    grid-column: 1 / -1;
    grid-row: 2;
    order: unset;
    flex: none;
    width: 100%;
    max-width: none;
    margin: 0;
    justify-self: stretch;
  }
  .header-search .search-kbd {
    display: none;
  }
  .header-search.search-wrapper-inline .search-input,
  .header-search.search-wrapper-inline .search-input:focus {
    padding-right: 12px;
  }
  header nav {
    display: contents;
    margin-left: 0;
    width: auto;
  }
  header nav > a,
  header nav > .header-nav-btn,
  header nav > .theme-toggle {
    display: none;
  }
  #notificationInboxWrap {
    grid-column: 3;
    grid-row: 1;
    justify-self: end;
  }
  #walletArea {
    grid-column: 4;
    grid-row: 1;
    justify-self: end;
    flex-shrink: 1;
    min-width: 0;
  }
  header .btn-icon,
  header .theme-toggle,
  header .notification-bell {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    margin: 0;
  }
  .theme-toggle {
    margin: 0;
    flex-shrink: 0;
  }
  .wallet-btn,
  .wallet-btn-connected {
    max-width: 100%;
    min-height: 44px;
  }
  .wallet-addr {
    max-width: 72px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .wallet-dropdown {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: none;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    z-index: 200;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .wallet-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 199;
    background: rgba(0, 0, 0, 0.35);
    border: none;
    padding: 0;
    margin: 0;
    cursor: pointer;
  }
  .wallet-backdrop[hidden] {
    display: none;
  }
  .notification-panel {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: auto;
    max-height: 85vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    z-index: 200;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .notification-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 199;
    background: rgba(0, 0, 0, 0.35);
    border: none;
    padding: 0;
    margin: 0;
    cursor: pointer;
  }
  .notification-backdrop[hidden] {
    display: none;
  }
  .wallet-btn:not(.wallet-btn-connected) .wallet-btn-label {
    display: none;
  }
  .wallet-btn:not(.wallet-btn-connected) {
    padding: 0;
    min-width: 44px;
    width: 44px;
    justify-content: center;
    gap: 0;
  }
  .wallet-btn:not(.wallet-btn-connected) svg {
    width: 18px;
    height: 18px;
  }

  /* Global search — clear 2-row header */
  .global-search-overlay {
    padding-top: calc(var(--header-height, 96px) + 8px);
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
  .global-search-panel {
    max-height: calc(100dvh - var(--header-height, 96px) - 24px);
  }
  .gs-pill {
    min-height: 44px;
    padding: 0 14px;
  }

  /* Contribution graph — horizontal scroll on narrow screens */
  .contrib-graph-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .contrib-graph--year .contrib-graph-grid {
    min-width: max(100%, 672px);
    width: max-content;
  }

  /* Home */
  .home-hero {
    padding-bottom: 20px;
    margin-bottom: 20px;
  }
  .hero-wordmark {
    font-size: 28px;
  }
  .hero-tagline {
    font-size: 16px;
  }
  .hero-cta {
    flex-direction: column;
    align-items: stretch;
  }
  .hero-cta .hero-btn-primary,
  .hero-cta .hero-btn-secondary {
    width: 100%;
    justify-content: center;
  }
  .repos-header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .search-wrapper-inline {
    width: 100%;
  }
  .search-wrapper-inline .search-input {
    width: 100%;
  }
  .search-wrapper-inline .search-input:focus {
    width: 100%;
  }
  .install-grid {
    grid-template-columns: 1fr;
  }
  .install-pane + .install-pane {
    border-left: none;
    border-top: 1px solid var(--border);
  }
  .install-cmd {
    white-space: pre-wrap;
    word-break: break-all;
  }
  .home-feed-header {
    flex-direction: column;
    align-items: stretch;
  }
  .browse-controls {
    width: 100%;
  }
  .browse-control {
    flex: 1;
    min-width: 140px;
  }
  .browse-filter {
    flex: 1;
    min-width: 0;
  }
  .browse-filter-btn {
    width: 100%;
    justify-content: space-between;
  }
  .browse-filter .ref-dropdown {
    left: 0;
    right: 0;
    min-width: 0;
    width: 100%;
  }
  .repo-grid.repo-tiles {
    grid-template-columns: 1fr;
  }
  .browse-repo-stat--time {
    margin-left: 0;
  }
  .activity-row {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 10px 12px;
    align-items: start;
    padding: 12px;
  }
  .activity-avatars {
    grid-column: 1;
    align-self: start;
  }
  .activity-main {
    grid-column: 2;
    min-width: 0;
  }
  .activity-group-header.activity-row {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: none;
  }
  .activity-group-header .activity-main {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    grid-column: 2;
  }
  .activity-group-header .activity-avatars {
    grid-column: 1;
    grid-row: auto;
    align-self: start;
  }
  .activity-group-header .activity-copy {
    grid-column: unset;
    grid-row: unset;
  }
  .activity-group-header .activity-side {
    grid-column: 2;
    flex-direction: row;
    flex-wrap: wrap;
    justify-self: start;
    margin-top: 4px;
  }
  .activity-group-header .activity-detail--group {
    grid-column: unset;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    width: 100%;
  }
  .activity-group-header .activity-detail-end {
    margin-left: 0;
    justify-content: flex-start;
  }
  .activity-group-header .activity-context {
    grid-column: unset;
    white-space: normal;
  }
  .activity-group {
    --activity-thread-x: 26px;
  }
  .activity-group.is-expanded::before {
    top: 40px;
  }
  .activity-row--nested .activity-avatar {
    margin-left: 3px;
  }
  .activity-group-items {
    margin-left: 0;
    padding: 0;
  }
  .activity-back-to-start {
    right: 16px;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px) + 48px);
    padding: 9px 14px;
    font-size: 12px;
    min-height: 44px;
  }
  .activity-copy {
    flex-wrap: wrap;
    gap: 4px;
  }
  .activity-side {
    grid-column: 2;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    justify-self: start;
    flex-wrap: wrap;
    max-width: 100%;
  }
  .activity-side-meta {
    white-space: normal;
    word-break: break-all;
  }
  .activity-detail {
    flex-wrap: wrap;
  }
  .activity-chip {
    max-width: 100%;
  }
  .activity-detail--group .activity-detail-start {
    flex-wrap: wrap;
  }
  .activity-context {
    white-space: normal;
  }

  /* Repo / tree */
  .view-header {
    padding-bottom: 12px;
    margin-bottom: 10px;
  }
  .view-header-title {
    font-size: 18px;
    word-break: break-word;
  }
  .breadcrumb {
    font-size: 12px;
    line-height: 1.5;
    margin-bottom: 10px;
  }
  .repo-toolbar,
  .ref-selector {
    width: 100%;
  }
  .ref-btn {
    width: 100%;
    max-width: 100%;
    justify-content: space-between;
  }
  .ref-dropdown {
    left: 0;
    right: 0;
    width: 100%;
    max-width: none;
  }
  .stats-bar {
    gap: 6px;
    margin-bottom: 12px;
  }
  .stats-bar .stat-item,
  .stats-bar .star-btn,
  .star-dropdown .star-btn {
    min-height: 44px;
    font-size: 12px;
    padding: 0 10px;
    flex: 1 1 calc(50% - 4px);
  }
  .star-dropdown {
    flex: 1 1 100%;
    max-width: 100%;
  }
  .star-btn-action,
  .star-btn-count {
    flex: 1;
    justify-content: center;
    min-height: 44px;
  }
  .star-gazers-dropdown {
    right: 0;
    left: auto;
    min-width: min(280px, calc(100vw - 1.5rem));
  }
  .clone-dropdown {
    flex: 1 1 100%;
    margin-left: 0;
  }
  .stats-bar .clone-btn {
    width: 100%;
    justify-content: center;
    min-height: 44px;
  }
  .clone-popup {
    left: 0;
    right: 0;
    width: auto;
    max-width: none;
  }
  .file-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .file-table-header {
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px 12px;
  }
  .file-table-header .commit-msg {
    flex-basis: 100%;
    white-space: normal;
  }
  .file-table-header .time {
    margin-left: 0;
  }
  .view-wrapper .file-table .row {
    padding: 0 12px;
    min-height: 44px;
  }
  .repo-layout {
    gap: 16px;
  }

  /* Commits — override column stack from styles.css */
  .commit-item,
  #commitSlot .commit-item,
  .view-wrapper .commit-item {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 8px;
    padding: 12px;
  }
  .commit-item .info {
    flex: 1;
    min-width: 0;
  }
  .commit-item .msg {
    font-size: 14px;
    word-break: break-word;
  }
  .commit-item .sha-col {
    align-self: center;
    margin-left: auto;
  }
  .page-heading {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  .page-heading .back-link {
    margin-left: 0 !important;
  }

  /* Issues / PRs */
  .issues-header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .issues-header .btn-primary {
    width: 100%;
    justify-content: center;
  }
  .issues-filters {
    flex-wrap: wrap;
    gap: 6px;
    padding-bottom: 10px;
  }
  .issues-filter-btn {
    flex: 1 1 auto;
    min-width: 0;
    justify-content: center;
    min-height: 44px;
  }
  .issue-row {
    padding: 12px;
  }
  .issue-detail-title {
    font-size: 1.35rem;
    word-break: break-word;
  }

  /* Profile */
  .profile-page,
  .profile-edit-page {
    padding: 0;
  }
  .profile-top {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  .profile-contrib-card {
    padding: 12px;
    overflow-x: auto;
  }
  .activity-compact-section {
    padding: 12px;
  }
  .activity-compact-header {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .activity-compact-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }
  .activity-compact-load-more {
    min-height: 44px;
    padding: 12px;
    width: 100%;
    font-size: 14px;
  }
  .activity-compact-row {
    grid-template-columns: 16px minmax(0, 1fr);
    grid-template-rows: auto auto;
    padding: 10px 8px;
    min-height: 44px;
  }
  .activity-compact-main {
    grid-column: 2;
    grid-row: 1;
  }
  .activity-compact-time {
    grid-column: 2;
    grid-row: 2;
    justify-self: start;
  }
  .contrib-graph-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .contrib-month-label {
    font-size: 9px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .profile-header {
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 16px;
    gap: 12px;
  }
  .profile-wallet {
    flex-wrap: wrap;
    justify-content: center;
    width: 100%;
  }
  .profile-wallet code {
    font-size: 11px;
    word-break: break-all;
    text-align: center;
    white-space: normal;
  }
  .profile-links {
    justify-content: center;
  }

  /* Blob / diff */
  .blob-header {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
  }
  .blob-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }
  .blob-actions .btn-small {
    min-height: 44px;
    width: 100%;
    justify-content: center;
    font-size: 12px;
    padding: 0 8px;
  }
  .blob-code {
    font-size: 12px;
  }
  .diff-page {
    padding: 0;
  }
  .diff-subject {
    font-size: 1.1rem;
    word-break: break-word;
  }
  .diff-stats-bar {
    flex-wrap: wrap;
    gap: 6px;
    align-items: flex-start;
  }
  .diff-expand-all {
    margin-left: 0;
    width: 100%;
    min-height: 44px;
  }
  .diff-stat-bar {
    margin-left: 0;
    flex-wrap: wrap;
  }
  .diff-file-toc li {
    flex-wrap: wrap;
    align-items: flex-start;
  }
  .diff-toc-path {
    flex: 1 1 100%;
    white-space: normal;
    word-break: break-all;
    min-width: 0;
  }
  .diff-toc-stats {
    margin-left: 0;
  }
  .diff-meta {
    gap: 8px;
  }
  .diff-breadcrumb {
    font-size: 12px;
  }
  .diff-stats-bar {
    flex-wrap: wrap;
    gap: 6px;
  }
  .diff-file-header {
    flex-wrap: wrap;
  }
  .diff-file-path {
    flex-basis: 100%;
    min-width: 0;
    word-break: break-all;
  }

  /* Modals & toasts */
  .wallet-modal {
    width: calc(100vw - 24px);
    max-width: none;
    margin: 12px auto;
  }
  .file-finder-inner {
    width: calc(100vw - 24px);
    max-width: none;
  }
  #toastContainer {
    left: 12px;
    right: 12px;
    bottom: 12px;
  }
  .toast {
    max-width: none;
  }

  /* Footer */
  footer {
    padding: 16px 12px;
  }
  footer .footer-inner {
    flex-direction: column;
    text-align: center;
    gap: 10px;
  }

  /* Touch-friendly icon buttons */
  .btn-icon,
  .theme-toggle {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }

  /* Forms */
  .form-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .form-actions .btn-primary,
  .form-actions .btn-secondary,
  .form-actions .btn-small {
    width: 100%;
    justify-content: center;
  }
  .profile-edit-form .form-section {
    padding: 16px;
  }
}

@media (max-width: 480px) {
  .container {
    padding: 12px;
  }
  .header-badge {
    display: none;
  }
  .hero-wordmark {
    font-size: 24px;
  }
  .wallet-btn-connected .wallet-addr,
  .wallet-btn-connected .dropdown-chevron {
    display: none;
  }
  .wallet-btn-connected {
    padding: 0;
    min-width: 44px;
    justify-content: center;
  }
  .browse-controls {
    flex-direction: column;
    align-items: stretch;
  }
  .browse-control {
    flex-direction: column;
    align-items: stretch;
    min-width: 0;
    width: 100%;
  }
  .browse-control-label {
    white-space: normal;
  }
  .stats-bar .stat-item {
    flex: 1 1 calc(50% - 3px);
    justify-content: center;
    min-width: 0;
  }
  .blob-actions {
    grid-template-columns: 1fr;
  }
}
