/* Pocket desktop. Load last; desktop styling above 700px stays unchanged. */
#mobile-home-brand,
.mobile-close-label {
  display: none;
}

@media (max-width: 700px) {
  :root {
    --taskbar-height: 52px;
    --mobile-app-gray: #a8a8a8;
    --mobile-app-ink: #202020;
  }

  html,
  body {
    height: 100%;
    height: 100dvh;
    overscroll-behavior: none;
  }

  #desktop {
    top: env(safe-area-inset-top, 0px);
    bottom: calc(var(--taskbar-height) + env(safe-area-inset-bottom, 0px));
  }

  /* The original landscape remains behind the home screen and open apps. */
  #mobile-home-brand,
  #brand-fallback {
    position: absolute;
    top: clamp(24px, 5.5vh, 48px);
    left: 50%;
    display: block;
    width: calc(100% - 32px);
    max-width: 520px;
    transform: translateX(-50%);
    pointer-events: none;
  }

  #mobile-wordmark {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 1188 / 199;
  }

  #desktop-icons {
    inset: clamp(116px, 17vh, 164px) auto 12px 50%;
    width: calc(100% - 28px);
    max-width: 520px;
    max-height: none;
    transform: translateX(-50%);
    grid-auto-flow: row;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: none;
    grid-auto-columns: auto;
    grid-auto-rows: max-content;
    align-content: start;
    justify-items: center;
    gap: clamp(15px, 2.8vh, 28px) 8px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    padding: 4px 2px 16px;
  }

  .desktop-icon {
    width: 100%;
    height: auto;
    min-height: 122px;
    padding: 4px 0;
    gap: 7px;
    touch-action: manipulation;
  }

  .desktop-icon .icon-art {
    width: 100%;
    height: clamp(76px, 22vw, 104px);
  }

  .desktop-icon[data-app="about"] .icon-art {
    width: 100%;
  }

  .desktop-icon .about-cloud {
    width: 100%;
    max-width: 204px;
    height: auto;
  }

  .desktop-icon .pat-canvas {
    width: auto;
    height: 100%;
    max-width: 100%;
    aspect-ratio: 875 / 700;
  }

  .desktop-icon .icon-art svg,
  .desktop-icon .icon-art .detailed-icon {
    width: clamp(76px, 22vw, 104px);
    height: clamp(76px, 22vw, 104px);
  }

  .desktop-icon .icon-label {
    max-width: 100%;
    font-size: clamp(18px, 5.2vw, 24px);
    line-height: 1.15;
    padding: 1px 2px;
    letter-spacing: 0;
    text-shadow: 1px 1px #141414, -1px -1px #141414,
      1px -1px #141414, -1px 1px #141414, 0 2px #141414;
  }

  body.mobile-app-open #mobile-home-brand,
  body.mobile-app-open #brand-fallback,
  body.mobile-app-open #desktop-icons,
  .window.mobile-background {
    display: none !important;
  }

  /* One app fills the usable screen. Inline desktop geometry is retained by JS. */
  #windows > .window {
    left: 8px !important;
    top: 12px !important;
    right: 8px !important;
    bottom: 12px !important;
    width: calc(100% - 16px) !important;
    height: calc(100% - 24px) !important;
    min-width: 0;
    min-height: 0;
    max-width: none;
    max-height: none;
    margin: 0;
    overflow: hidden;
    box-shadow: inset -1px -1px #808080, inset 1px 1px #dfdfdf,
      2px 2px 0 rgb(0 0 0 / 18%);
  }

  .window .titlebar,
  .window.active .titlebar {
    height: 48px;
    gap: 7px;
    padding: 2px 2px 2px 6px;
    background: #383838;
    color: #fff;
    touch-action: manipulation;
  }

  .window .window-title {
    font-size: 17px;
    letter-spacing: 0;
  }

  .titlebar .title-icon {
    display: flex;
    flex: none;
    align-items: center;
    justify-content: center;
  }

  .titlebar .title-icon svg {
    width: 25px;
    height: 25px;
  }

  .titlebar .title-icon img {
    max-width: 31px;
    max-height: 24px;
  }

  .titlebar .title-icon .pat-canvas {
    width: 29px;
    height: 24px;
  }

  .window-controls .minimize,
  .window-controls .maximize,
  .window-menu,
  .window-status,
  .window > .window-resize-handle {
    display: none !important;
  }

  .window-controls .close {
    width: 74px;
    height: 44px;
    margin-left: 2px;
    padding: 0 10px;
    font: 16px "MS Sans Serif", Tahoma, Arial, sans-serif;
    touch-action: manipulation;
  }

  .window-controls .close::before,
  .window-controls .close::after {
    display: none;
  }

  .mobile-close-label {
    display: inline;
  }

  #windows > .window > .window-content {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    padding: 24px 18px 30px;
    overflow: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    background: var(--mobile-app-gray);
    color: var(--mobile-app-ink);
    box-shadow: inset 1px 1px #808080, inset -1px -1px #dfdfdf;
    scrollbar-color: #c0c0c0 #999;
  }

  .window .app-page {
    max-width: none;
    min-width: 0;
  }

  .window h2,
  .window .editorial-page h2 {
    margin: 0 0 18px;
    font-size: clamp(26px, 7.1vw, 34px);
    line-height: 1.14;
    letter-spacing: -.6px;
    color: var(--mobile-app-ink);
  }

  .window h3,
  .window .editorial-page h3 {
    font-size: 21px;
    line-height: 1.25;
    color: var(--mobile-app-ink);
  }

  .window p,
  .window .editorial-page p,
  .window .editorial-page p.lead,
  .window .editorial-page .editorial-introduction {
    max-width: none;
    font-size: 16px;
    line-height: 1.6;
    color: var(--mobile-app-ink);
    overflow-wrap: break-word;
  }

  .window .eyebrow,
  .window .editorial-page .eyebrow,
  .window .editorial-page .section-index,
  .window .editorial-page .editorial-footer p,
  .window .coming-soon,
  .window .draft-note,
  .window .empty-state .small-note {
    color: #373737;
  }

  .window .editorial-page .company-hero {
    flex-direction: column;
    align-items: stretch;
    gap: 26px;
    padding: 10px 0 25px;
    margin-bottom: 25px;
    border-bottom-color: #828282;
  }

  .company-hero > .window-brand-artwork,
  .company-hero > .hero-copy {
    flex: none;
    width: 100%;
    max-width: none;
    min-width: 0;
  }

  .window .window-brand-artwork {
    justify-content: center;
    background: transparent;
  }

  .window .window-brand-artwork img,
  .window .window-brand-artwork.pat-wordmark img {
    width: 100%;
    height: auto;
    max-width: 100%;
    max-height: 180px;
    object-fit: contain;
  }

  .window .hero-copy {
    display: flex;
    flex-direction: column;
  }

  .window .project-status {
    order: 1;
    align-self: flex-start;
    margin-top: 18px;
    padding: 7px 10px;
    border: 1px solid #626262;
    font: 14px "MS Sans Serif", Tahoma, Arial, sans-serif;
    letter-spacing: 0;
    text-transform: none;
    color: var(--mobile-app-ink);
  }

  .project-status .status-dot {
    display: none;
  }

  .editorial-columns {
    grid-template-columns: minmax(0, 1fr);
    gap: 23px;
  }

  .editorial-section,
  .editorial-page .editorial-footer,
  .training-step {
    border-top-color: #828282;
  }

  .training-step {
    grid-template-columns: 24px minmax(0, 1fr);
    gap: 12px;
  }

  .window .editorial-page .editorial-footer {
    flex-direction: column;
    align-items: stretch;
    gap: 21px;
    margin-top: 25px;
    padding-top: 23px;
  }

  .window .action-row {
    gap: 12px;
  }

  .window .classic-button,
  .window .editorial-page .classic-button {
    min-height: 44px;
    padding: 9px 13px;
    font-size: 16px;
    touch-action: manipulation;
  }

  .window .demo-footer .action-row {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    gap: 12px;
  }

  .window .coming-soon {
    display: block;
    white-space: normal;
    text-align: center;
    font-size: 14px;
    margin-bottom: 8px;
  }

  .window .empty-state {
    padding: 36px 0 24px;
  }

  .window .empty-state .empty-art {
    width: 84px;
    height: 84px;
    margin-bottom: 25px;
  }


  .window .help-list {
    font-size: 15px;
    line-height: 1.6;
    padding-left: 21px;
  }

  .window .help-list li {
    margin-bottom: 13px;
  }

  #windows > .window[data-app="weather"] > .window-content {
    padding: 0;
    overflow: hidden;
    touch-action: auto;
    background: #d4d0c8;
  }

  /* Keep the familiar bevel, with 44px touch targets and room for the home bar. */
  #taskbar {
    height: calc(var(--taskbar-height) + env(safe-area-inset-bottom, 0px));
    gap: 4px;
    padding: 3px 4px calc(3px + env(safe-area-inset-bottom, 0px));
  }

  #start-button {
    min-width: 99px;
    height: 44px;
    gap: 6px;
    padding: 3px 9px;
    font-size: 18px;
    touch-action: manipulation;
  }

  #start-icon svg {
    width: 27px;
    height: 27px;
  }

  #task-buttons,
  #taskbar > .taskbar-divider,
  #clock-date {
    display: none;
  }

  .system-tray {
    height: 44px;
    margin-left: auto;
    padding: 0;
    gap: 0;
    border: 0;
    box-shadow: none;
  }

  .system-tray #sound-button {
    width: 44px;
    height: 44px;
    padding: 0;
    border-left: 1px solid #808080;
    border-right: 1px solid #fff;
    box-shadow: inset 1px 0 #fff, 1px 0 #808080;
    touch-action: manipulation;
  }

  #sound-button svg {
    width: 24px;
    height: 24px;
  }

  #clock-button {
    min-width: 65px;
    height: 44px;
    padding: 0 6px;
    font-size: 14px;
    line-height: 1;
    touch-action: manipulation;
  }

  #start-menu {
    left: 6px;
    bottom: calc(var(--taskbar-height) + env(safe-area-inset-bottom, 0px));
    min-width: 0;
    width: min(324px, calc(100% - 12px));
    max-height: calc(100dvh - var(--taskbar-height) - env(safe-area-inset-bottom, 0px) - env(safe-area-inset-top, 0px) - 12px);
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .popup button,
  .start-items button {
    min-height: 44px;
    font-size: 14px;
    touch-action: manipulation;
  }

  .no-script {
    left: 8px;
    right: 8px;
    top: 12px;
    max-height: calc(100% - 24px);
    overflow: auto;
  }
}

/* Keep every home icon reachable on short phones and landscape viewports. */
@media (max-width: 700px) and (max-height: 560px) {
  #mobile-home-brand,
  #brand-fallback {
    top: 13px;
    max-width: 340px;
    width: calc(100% - 40px);
  }

  #desktop-icons {
    top: 81px;
    gap: 12px 8px;
  }

  .desktop-icon {
    min-height: 111px;
  }

  .desktop-icon .icon-art {
    height: 76px;
  }

  .desktop-icon .icon-art svg,
  .desktop-icon .icon-art .detailed-icon {
    width: 76px;
    height: 76px;
  }

  .desktop-icon .about-cloud {
    max-width: 170px;
  }

  .desktop-icon .icon-label {
    font-size: 18px;
  }

  #windows > .window {
    top: 6px !important;
    bottom: 6px !important;
    height: calc(100% - 12px) !important;
  }
}
