/* Phone layout overrides. Keep these after the Win95 theme and list controls.
   Composer sizing, positioning and backdrop rules live in the reply fix. */
@media (max-width: 767px) {
  /* The native drawer backdrop is a body sibling. Release only the open
     drawer from the theme's #app stacking context, while keeping page and
     composer controls below the backdrop. Normal modal/editor layers stay intact. */
  body.tm-mobile-v3 #app.drawerOpen { z-index: auto !important; }
  body.tm-mobile-v3 #app.drawerOpen > .App-content {
    position: relative !important;
    z-index: 0 !important;
  }
  body.tm-mobile-v3 #app.drawerOpen > .App-navigation { z-index: 0 !important; }
  body.tm-mobile-v3 #app.drawerOpen ~ .w95-taskbar,
  body.tm-mobile-v3 #app.drawerOpen ~ .w95-start-menu,
  body.tm-mobile-v3 #app.drawerOpen ~ .tm-mobile-v3-nav { display: none !important; }
  body.tm-mobile-v3 .App-drawer {
    width: min(var(--drawer-width, 270px), calc(100vw - 48px));
    max-height: 100dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: #c0c0c0;
  }
  body.tm-mobile-v3 #drawer .App-header {
    position: static !important;
    width: auto !important;
    margin: 0 !important;
  }
  body.tm-mobile-v3 #drawer .App-header > .container {
    display: block !important;
    width: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 10px !important;
  }
  body.tm-mobile-v3 #drawer .Header-title,
  body.tm-mobile-v3 #drawer .Header-primary,
  body.tm-mobile-v3 #drawer .Header-secondary,
  body.tm-mobile-v3 #drawer .Header-controls {
    display: block !important;
    float: none !important;
    width: 100% !important;
    min-width: 0 !important;
    margin: 0 !important;
  }
  body.tm-mobile-v3 #drawer .Header-title {
    padding: 8px 0 14px !important;
    white-space: normal !important;
    overflow-wrap: anywhere;
  }
  body.tm-mobile-v3 #drawer .Header-controls > li {
    display: block !important;
    width: 100% !important;
    margin: 0 0 8px !important;
    padding: 0 !important;
  }
  body.tm-mobile-v3 #drawer .Header-controls > li > .Dropdown,
  body.tm-mobile-v3 #drawer .Header-controls > li > .Button,
  body.tm-mobile-v3 #drawer .Header-controls > li > .Dropdown > .Dropdown-toggle,
  body.tm-mobile-v3 #drawer .Search:not(.w95-find-active),
  body.tm-mobile-v3 #drawer .Search:not(.w95-find-active) .FormControl {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }
  body.tm-mobile-v3 #drawer .Header-controls > li > .Button,
  body.tm-mobile-v3 #drawer .Header-controls > li > .Dropdown > .Dropdown-toggle {
    min-height: 44px !important;
    height: auto !important;
    text-align: left !important;
    white-space: normal !important;
  }

  /* Open the category tree below its toggle. The old 42vh bottom sheet
     nested two scrolling areas and put the final entries under the taskbar. */
  body.tm-mobile-v3 .IndexPage-nav .sideNav {
    max-height: none !important;
    overflow: visible !important;
  }
  body.tm-mobile-v3 .IndexPage-nav .App-titleControl > .Dropdown-menu {
    top: calc(var(--tm-mobile-view-top, 0px) + 50px) !important;
    bottom: auto !important;
    left: calc(var(--tm-mobile-view-left, 0px) + 6px) !important;
    right: auto !important;
    width: calc(var(--tm-mobile-view-width, 100vw) - 12px) !important;
    max-height: calc(var(--tm-mobile-view-height, 100dvh) - 104px - env(safe-area-inset-bottom, 0px)) !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 6px !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
    touch-action: pan-y;
  }
  body.tm-mobile-v3 .IndexPage-nav .App-titleControl.open > .Dropdown-toggle {
    position: relative !important;
    z-index: 1040 !important;
  }
  /* Keep outside-tap dismissal without tinting the page behind this menu. */
  body.tm-mobile-v3 .IndexPage-nav .App-titleControl > .dropdown-backdrop {
    background: transparent !important;
  }

  /* Keep one title, the account header and the existing five quick links. */
  body.tm-mobile-v3 .win95-menubar,
  body.tm-mobile-v3 .win95-toolbar,
  body.tm-mobile-v3 .win95-addressbar,
  body.tm-mobile-v3 .win95-window-buttons {
    display: none !important;
  }
  body.tm-mobile-v3 .win95-titlebar {
    min-height: 36px !important;
    height: auto !important;
    padding: 6px 8px !important;
  }
  body.tm-mobile-v3 .win95-title-left { min-width: 0; }
  body.tm-mobile-v3 .tm-mobile-v3-nav {
    gap: 4px !important;
    padding: 4px !important;
  }
  body.tm-mobile-v3 .tm-mobile-v3-nav a {
    height: 44px !important;
    font-size: 12px !important;
  }
  body.tm-mobile-v3 .Header .container {
    min-height: 48px !important;
    gap: 4px;
  }
  body.tm-mobile-v3 .Header-secondary > ul {
    min-width: 0;
    max-width: 100%;
    flex-wrap: wrap;
    gap: 4px;
  }
  body.tm-mobile-v3 .Header-secondary .item-search { min-width: 0; }
  body.tm-mobile-v3 .Header-secondary .item-flags .Button,
  body.tm-mobile-v3 .Header-secondary .item-notifications .Button,
  body.tm-mobile-v3 .Header-secondary .item-session .Button {
    min-height: 44px !important;
    height: 44px !important;
  }
  body.tm-mobile-v3 .Header-secondary .item-flags .Button,
  body.tm-mobile-v3 .Header-secondary .item-notifications .Button {
    width: 44px !important;
    min-width: 44px !important;
  }

  /* Outer padding belongs to the page, never to an over-wide post margin. */
  body.tm-mobile-v3 .IndexPage > .container,
  body.tm-mobile-v3 .DiscussionPage > .container,
  body.tm-mobile-v3 .TagsPage > .container,
  body.tm-mobile-v3 .UserPage > .container,
  body.tm-mobile-v3 .SettingsPage > .container {
    padding-left: 8px !important;
    padding-right: 8px !important;
  }
  body.tm-mobile-v3 .IndexPage-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
  }
  body.tm-mobile-v3 .IndexPage-toolbar-view,
  body.tm-mobile-v3 .IndexPage-toolbar-action { margin: 0; }
  body.tm-mobile-v3 .DiscussionHero { margin: 8px !important; }
  body.tm-mobile-v3 .DiscussionHero-title {
    font-size: 20px;
    line-height: 1.4;
    overflow-wrap: anywhere;
  }
  body.tm-mobile-v3 .DiscussionPage .PostStream .Post {
    width: 100% !important;
    margin: 10px 0 !important;
    padding: 32px 6px 6px !important;
  }
  body.tm-mobile-v3 .DiscussionPage .PostStream .Post-body {
    padding: 12px 10px !important;
    font-size: 15px !important;
    line-height: 1.75 !important;
  }
  body.tm-mobile-v3 .Post-body,
  body.tm-mobile-v3 .Post-header,
  body.tm-mobile-v3 .Post-footer {
    min-width: 0;
    overflow-wrap: anywhere;
  }
  body.tm-mobile-v3 .Post-body blockquote {
    margin-left: 0;
    margin-right: 0;
    padding-left: 12px;
    padding-right: 8px;
  }
  body.tm-mobile-v3 .Post-body pre {
    max-width: 100%;
    overflow-x: auto;
    tab-size: 4;
  }
  body.tm-mobile-v3 .Post-body audio { max-width: 100%; }
  body.tm-mobile-v3 .Post-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
  }
  body.tm-mobile-v3 .Post-actions > li { margin: 0 !important; }
  body.tm-mobile-v3 .DiscussionPage .PostStream .Post-actions .Button,
  body.tm-mobile-v3 .DiscussionPage .PostStream .Post-footer .Button {
    min-height: 44px !important;
    padding: 8px 10px !important;
  }

  /* Explorer has two visible columns on phones: title and replies. */
  body.tm-mobile-v3 .w95-explorer-head,
  body.tm-mobile-v3 .w95-explorer-row {
    grid-template-columns: minmax(0, 1fr) 58px !important;
  }
  body.tm-mobile-v3 .w95-explorer-head {
    min-height: 40px;
    height: auto !important;
  }
  body.tm-mobile-v3 .w95-explorer-head > :nth-child(5),
  body.tm-mobile-v3 .w95-explorer-time { display: none !important; }
  body.tm-mobile-v3 .w95-explorer-list > .w95-explorer-item > .w95-explorer-row {
    min-height: 56px !important;
    font-size: 13px !important;
  }
  body.tm-mobile-v3 .w95-explorer-name {
    min-height: 52px;
    padding: 9px 7px !important;
    align-items: center;
  }
  body.tm-mobile-v3 .w95-explorer-name span:last-child {
    white-space: normal !important;
    overflow-wrap: anywhere;
    line-height: 1.5;
  }
  body.tm-mobile-v3 .w95-explorer-file { flex-shrink: 0; }
  body.tm-mobile-v3 .DiscussionListItem-title {
    white-space: normal;
    overflow-wrap: anywhere;
    line-height: 1.5;
  }
  body.tm-mobile-v3 .DiscussionListItem-info {
    white-space: normal;
    overflow-wrap: anywhere;
    line-height: 1.6;
  }

  /* Profile identity and actions stay in normal flow instead of overlapping. */
  body.tm-mobile-v3 .UserPage .UserCard--hero {
    padding-top: 38px !important;
    margin: 8px !important;
  }
  body.tm-mobile-v3 .UserPage .UserCard--hero::after { display: none !important; }
  body.tm-mobile-v3 .UserPage .UserCard--hero .container { padding: 0 !important; }
  body.tm-mobile-v3 .UserPage .UserCard--hero .UserCard-profile {
    min-height: 100px !important;
    padding: 10px 12px 12px !important;
    text-align: left !important;
    display: flow-root;
  }
  body.tm-mobile-v3 .UserPage .UserCard--hero .UserCard-avatar {
    float: left !important;
    width: 64px !important;
    margin: 0 12px 10px 0 !important;
  }
  body.tm-mobile-v3 .UserPage .UserCard--hero .UserCard-avatar .Avatar {
    width: 64px !important;
    height: 64px !important;
  }
  body.tm-mobile-v3 .UserPage .UserCard--hero .UserCard-identity {
    font-size: 18px !important;
    line-height: 1.5;
    overflow-wrap: anywhere;
  }
  body.tm-mobile-v3 .UserPage .UserCard--hero .UserCard-badges {
    margin-left: 0 !important;
  }
  body.tm-mobile-v3 .UserPage .UserCard--hero .UserCard-info {
    display: flex;
    flex-wrap: wrap;
    gap: 5px 12px;
    clear: both;
    margin-top: 10px;
    line-height: 1.6;
  }
  body.tm-mobile-v3 .UserPage .UserCard--hero .UserCard-info > li {
    max-width: 100%;
    margin-right: 0;
    overflow-wrap: anywhere;
  }
  body.tm-mobile-v3 .UserPage .UserCard--hero .UserCard-controls {
    position: static !important;
    float: none !important;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 5px;
    margin: 0 !important;
    padding: 0 10px 8px;
  }
  body.tm-mobile-v3 .UserPage-nav .Dropdown-menu,
  body.tm-mobile-v3 .SettingsPage-nav .Dropdown-menu {
    max-height: min(55dvh, 420px) !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
  }
  body.tm-mobile-v3 .UserPage-nav .Dropdown-menu > li > a,
  body.tm-mobile-v3 .UserPage-nav .Dropdown-menu > li > button,
  body.tm-mobile-v3 .SettingsPage-nav .Dropdown-menu > li > a {
    min-height: 44px !important;
    white-space: normal !important;
  }

  /* Review fields and long filenames must shrink inside their grid cells. */
  body.tm-mobile-v3 .tm-review-page,
  body.tm-mobile-v3 .tm-bug-page,
  body.tm-mobile-v3 .tm-resource-page,
  body.tm-mobile-v3 .tm-module-page { padding-left: 8px !important; padding-right: 8px !important; }
  body.tm-mobile-v3 .tm-review-receipt-head,
  body.tm-mobile-v3 .tm-resource-receipt-head,
  body.tm-mobile-v3 .tm-resource-admin-head,
  body.tm-mobile-v3 .tm-module-receipt-head,
  body.tm-mobile-v3 .tm-module-admin-head,
  body.tm-mobile-v3 .tm-bug-receipt-head {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 8px;
    overflow-wrap: anywhere;
  }
  body.tm-mobile-v3 .tm-review-grid > div,
  body.tm-mobile-v3 .tm-review-detail-grid > div,
  body.tm-mobile-v3 .tm-resource-detail-grid > div,
  body.tm-mobile-v3 .tm-module-detail-grid > div {
    grid-template-columns: minmax(0, 82px) minmax(0, 1fr) !important;
    min-width: 0;
    overflow-wrap: anywhere;
  }
  body.tm-mobile-v3 .tm-review-code,
  body.tm-mobile-v3 .tm-review-receipt code,
  body.tm-mobile-v3 .tm-resource-receipt code,
  body.tm-mobile-v3 .tm-resource-admin-row code,
  body.tm-mobile-v3 .tm-module-receipt code,
  body.tm-mobile-v3 .tm-module-admin-row code,
  body.tm-mobile-v3 .tm-bug-receipt code,
  body.tm-mobile-v3 .tm-bug-admin-row code {
    white-space: normal;
    overflow-wrap: anywhere;
  }
  body.tm-mobile-v3 .tm-review-panel-button,
  body.tm-mobile-v3 .tm-resource-panel-button,
  body.tm-mobile-v3 .tm-bug-panel-button {
    width: 100% !important;
    min-width: 0 !important;
    white-space: normal !important;
    overflow-wrap: anywhere;
  }

  /* Larger controls avoid cramped tap targets and iOS focus zoom. */
  body.tm-mobile-v3 .IndexPage .Button,
  body.tm-mobile-v3 .UserPage .Button,
  body.tm-mobile-v3 .SettingsPage .Button,
  body.tm-mobile-v3 .tm-review-page .Button,
  body.tm-mobile-v3 .tm-resource-page .Button,
  body.tm-mobile-v3 .tm-module-page .Button,
  body.tm-mobile-v3 .tm-bug-page .Button,
  body.tm-mobile-v3 .tm-list-controls .Button,
  body.tm-mobile-v3 .tm-list-pagination .Button {
    min-height: 44px !important;
  }
  body.tm-mobile-v3 .tm-list-controls .FormControl,
  body.tm-mobile-v3 .tm-list-jump .FormControl,
  body.tm-mobile-v3 .UserPage .FormControl,
  body.tm-mobile-v3 .tm-review-page .FormControl,
  body.tm-mobile-v3 .tm-resource-page .FormControl,
  body.tm-mobile-v3 .tm-module-page .FormControl,
  body.tm-mobile-v3 .tm-bug-page .FormControl {
    min-height: 44px !important;
    font-size: 16px !important;
  }
  body.tm-mobile-v3 .tm-list-controls { padding: 10px; gap: 10px; }
  body.tm-mobile-v3 .tm-list-controls .tm-list-search { flex-basis: 100%; }
  body.tm-mobile-v3 .tm-list-controls .tm-list-filter { flex: 1 1 120px; }
  body.tm-mobile-v3 .tm-list-controls .tm-list-actions { flex-wrap: wrap; }
  body.tm-mobile-v3 .tm-list-pages { gap: 6px; }
  body.tm-mobile-v3 .tm-list-pagination .tm-list-page {
    min-width: 44px;
    padding-left: 10px;
    padding-right: 10px;
  }
  body.tm-mobile-v3 .tm-list-jump { flex-wrap: wrap; }
  body.tm-mobile-v3 .tm-list-jump .FormControl { width: 72px; }
  body.tm-mobile-v3 .tm-list-summary { line-height: 1.5; }
  body.tm-mobile-v3 .tm-review-bound-card-details > summary { padding: 12px 0; }

  /* Search remains usable in short landscape viewports. */
  body.tm-mobile-v3 .Search.w95-find-active {
    top: 8px !important;
    width: calc(100vw - 16px) !important;
    max-height: calc(100dvh - 16px) !important;
    overflow-y: auto;
    padding-top: 52px !important;
  }
  body.tm-mobile-v3 .w95-find-title { height: 42px; }
  body.tm-mobile-v3 .w95-find-title button {
    width: 40px !important;
    height: 38px !important;
    min-width: 40px !important;
  }
  body.tm-mobile-v3 .Search.w95-find-active .Search-input input {
    height: 44px !important;
    font-size: 16px !important;
  }
  body.tm-mobile-v3 .Search.w95-find-active .Dropdown-menu,
  body.tm-mobile-v3 .Search.w95-find-active .Search-results {
    min-height: 0 !important;
    max-height: min(45dvh, 280px) !important;
  }
  body.tm-mobile-v3 .Search.w95-find-active .Dropdown-menu a,
  body.tm-mobile-v3 .Search.w95-find-active .Search-results a {
    min-height: 44px !important;
    padding: 10px 7px !important;
    white-space: normal;
    overflow-wrap: anywhere;
  }
}

@media (max-width: 360px) {
  body.tm-mobile-v3 .tm-review-grid > div,
  body.tm-mobile-v3 .tm-review-detail-grid > div,
  body.tm-mobile-v3 .tm-resource-detail-grid > div,
  body.tm-mobile-v3 .tm-module-detail-grid > div {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 3px;
  }
}
