@@ -24,7 +36,6 @@ export const TerminalPage: React.FC = () => {
onClick={() => navigate(-1)}
type="button"
>
-
Back
Terminal
@@ -32,6 +43,7 @@ export const TerminalPage: React.FC = () => {
navigate(-1)}
+ isMobile={false}
/>
);
diff --git a/apps/web/src/styles.css b/apps/web/src/styles.css
index 57157b0..2bcf502 100644
--- a/apps/web/src/styles.css
+++ b/apps/web/src/styles.css
@@ -2873,3 +2873,371 @@ a.nav-item,
background: var(--danger-light, #fee2e2);
color: var(--danger, #dc2626);
}
+
+/* ============================================
+ Mobile Terminal Styles
+ ============================================ */
+
+.mobile-terminal-shell {
+ height: 100vh;
+ overflow: hidden;
+}
+
+.mobile-terminal-wrapper {
+ display: flex;
+ flex-direction: column;
+ height: 100vh;
+ background: #1e1e1e;
+ position: relative;
+ overflow: hidden;
+}
+
+/* Mobile Terminal Header */
+.mobile-terminal-header {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ padding: var(--space-2) var(--space-3);
+ background: #2d2d2d;
+ border-bottom: 1px solid #3e3e3e;
+ flex-shrink: 0;
+ transition: transform 0.3s ease, opacity 0.3s ease;
+ z-index: 100;
+}
+
+.mobile-terminal-header.hidden {
+ transform: translateY(-100%);
+ opacity: 0;
+ pointer-events: none;
+}
+
+.mobile-terminal-header.visible {
+ transform: translateY(0);
+ opacity: 1;
+}
+
+.mobile-terminal-header-left,
+.mobile-terminal-header-right {
+ display: flex;
+ align-items: center;
+ gap: var(--space-2);
+ flex: 0 0 auto;
+}
+
+.mobile-terminal-header-center {
+ display: flex;
+ align-items: center;
+ gap: var(--space-2);
+ flex: 1;
+ justify-content: center;
+ min-width: 0;
+}
+
+.mobile-terminal-header-title {
+ font-size: 0.875rem;
+ font-weight: 500;
+ color: #d4d4d4;
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+}
+
+.mobile-terminal-header-button {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ width: 36px;
+ height: 36px;
+ padding: 0;
+ background: transparent;
+ border: 1px solid #3e3e3e;
+ border-radius: 6px;
+ color: #d4d4d4;
+ cursor: pointer;
+ font-size: 0.875rem;
+ transition: background 0.2s ease;
+}
+
+.mobile-terminal-header-button:hover {
+ background: #3e3e3e;
+}
+
+.mobile-terminal-header-status {
+ width: 8px;
+ height: 8px;
+ border-radius: 50%;
+ background: #666;
+ flex-shrink: 0;
+}
+
+.mobile-terminal-header-status.connecting {
+ background: #f5f543;
+ animation: pulse 1.5s infinite;
+}
+
+.mobile-terminal-header-status.connected {
+ background: #0dbc79;
+}
+
+.mobile-terminal-header-status.disconnected,
+.mobile-terminal-header-status.error {
+ background: #cd3131;
+}
+
+/* Mobile Terminal Content */
+.mobile-terminal-content {
+ flex: 1;
+ min-height: 0;
+ overflow: hidden;
+ position: relative;
+}
+
+/* Special Keys Strip */
+.special-keys-strip {
+ display: flex;
+ align-items: center;
+ gap: 2px;
+ padding: var(--space-1) var(--space-2);
+ background: #2d2d2d;
+ border-top: 1px solid #3e3e3e;
+ overflow-x: auto;
+ -webkit-overflow-scrolling: touch;
+ scrollbar-width: none;
+ flex-shrink: 0;
+ transition: transform 0.3s ease, opacity 0.3s ease;
+ z-index: 100;
+}
+
+.special-keys-strip.hidden {
+ transform: translateY(100%);
+ opacity: 0;
+ pointer-events: none;
+}
+
+.special-keys-strip.visible {
+ transform: translateY(0);
+ opacity: 1;
+}
+
+.special-keys-strip::-webkit-scrollbar {
+ display: none;
+}
+
+.special-key-button {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ min-width: 44px;
+ height: 44px;
+ padding: 0 var(--space-2);
+ background: #3e3e3e;
+ border: 1px solid #4e4e4e;
+ border-radius: 6px;
+ color: #d4d4d4;
+ font-size: 0.75rem;
+ font-weight: 500;
+ cursor: pointer;
+ white-space: nowrap;
+ flex-shrink: 0;
+ transition: background 0.15s ease, transform 0.1s ease;
+ user-select: none;
+ -webkit-user-select: none;
+ touch-action: manipulation;
+}
+
+.special-key-button:active {
+ background: #4e4e4e;
+ transform: scale(0.95);
+}
+
+.special-key-more {
+ background: #2472c8;
+ border-color: #2472c8;
+ color: white;
+}
+
+.special-key-more:active {
+ background: #1e5fa8;
+}
+
+/* Special Keys Panel */
+.special-keys-panel-overlay {
+ position: fixed;
+ top: 0;
+ left: 0;
+ right: 0;
+ bottom: 0;
+ background: rgba(0, 0, 0, 0.5);
+ z-index: 200;
+ display: flex;
+ align-items: flex-end;
+ justify-content: center;
+}
+
+.special-keys-panel {
+ background: #2d2d2d;
+ border-top: 1px solid #3e3e3e;
+ border-radius: 12px 12px 0 0;
+ padding: var(--space-4);
+ width: 100%;
+ max-height: 70vh;
+ overflow-y: auto;
+ animation: slideUp 0.2s ease;
+}
+
+.special-keys-panel-section {
+ display: flex;
+ flex-wrap: wrap;
+ gap: var(--space-2);
+ margin-bottom: var(--space-3);
+}
+
+.special-keys-panel-section:last-child {
+ margin-bottom: 0;
+}
+
+.special-keys-panel-divider {
+ height: 1px;
+ background: #3e3e3e;
+ margin: var(--space-3) 0;
+}
+
+/* Terminal Component Updates */
+.terminal-wrapper.mobile {
+ border: none;
+ border-radius: 0;
+ height: 100%;
+}
+
+.terminal-wrapper.mobile .terminal-header {
+ display: none;
+}
+
+.terminal-header-left {
+ display: flex;
+ align-items: center;
+ gap: var(--space-2);
+}
+
+.terminal-header-right {
+ display: flex;
+ align-items: center;
+ gap: var(--space-2);
+}
+
+.terminal-header-button {
+ padding: var(--space-1) var(--space-2);
+ background: transparent;
+ border: 1px solid #666;
+ border-radius: 4px;
+ color: #d4d4d4;
+ cursor: pointer;
+ font-size: 0.75rem;
+ transition: background 0.2s ease;
+}
+
+.terminal-header-button:hover {
+ background: #3e3e3e;
+}
+
+.terminal-reconnect {
+ margin-left: var(--space-2);
+ padding: var(--space-1) var(--space-2);
+ background: #2472c8;
+ border: none;
+ border-radius: 4px;
+ color: white;
+ cursor: pointer;
+ font-size: 0.75rem;
+}
+
+.terminal-hidden-input {
+ position: absolute;
+ bottom: 0;
+ left: 0;
+ width: 1px;
+ height: 1px;
+ opacity: 0;
+ pointer-events: none;
+}
+
+/* Disable zoom on mobile terminal */
+@media (max-width: 767px) {
+ .mobile-terminal-wrapper {
+ touch-action: none;
+ -webkit-text-size-adjust: none;
+ }
+
+ .mobile-terminal-wrapper * {
+ touch-action: manipulation;
+ }
+
+ .terminal-container {
+ touch-action: none;
+ }
+}
+
+/* Animations */
+@keyframes slideUp {
+ from {
+ transform: translateY(100%);
+ }
+ to {
+ transform: translateY(0);
+ }
+}
+
+@keyframes pulse {
+ 0%, 100% {
+ opacity: 1;
+ }
+ 50% {
+ opacity: 0.5;
+ }
+}
+
+/* Mobile Menu Overlay */
+.mobile-menu-overlay {
+ position: fixed;
+ top: 0;
+ left: 0;
+ right: 0;
+ bottom: 0;
+ background: rgba(0, 0, 0, 0.5);
+ z-index: 50;
+}
+
+.mobile-menu-close {
+ position: absolute;
+ top: var(--space-2);
+ right: var(--space-2);
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ width: 36px;
+ height: 36px;
+ background: transparent;
+ border: none;
+ color: var(--text);
+ cursor: pointer;
+}
+
+/* AppShell mobile menu */
+@media (max-width: 767px) {
+ .shell-nav {
+ position: fixed;
+ top: 0;
+ left: 0;
+ bottom: 0;
+ width: 260px;
+ background: var(--bg);
+ z-index: 100;
+ transform: translateX(-100%);
+ transition: transform 0.3s ease;
+ padding-top: var(--space-8);
+ }
+
+ .shell-nav.mobile-open {
+ transform: translateX(0);
+ }
+}
diff --git a/openspec/changes/mobile-terminal-ux/.openspec.yaml b/openspec/changes/mobile-terminal-ux/.openspec.yaml
new file mode 100644
index 0000000..6894814
--- /dev/null
+++ b/openspec/changes/mobile-terminal-ux/.openspec.yaml
@@ -0,0 +1,2 @@
+schema: spec-driven
+created: 2026-05-24
diff --git a/openspec/changes/mobile-terminal-ux/design.md b/openspec/changes/mobile-terminal-ux/design.md
new file mode 100644
index 0000000..ea6b0d1
--- /dev/null
+++ b/openspec/changes/mobile-terminal-ux/design.md
@@ -0,0 +1,108 @@
+## Context
+
+The current terminal implementation (`apps/web/src/components/terminal.tsx`) uses xterm.js with a fixed header and minimal mobile considerations. The terminal page (`apps/web/src/pages/terminal.tsx`) renders inside the standard AppShell layout (`apps/web/src/components/app-shell.tsx`), which consumes significant viewport space on mobile devices.
+
+On mobile devices (viewport < 768px):
+- The virtual keyboard covers 40-50% of the screen
+- xterm.js touch events conflict with browser touch behavior
+- Special keys (Ctrl, Esc, Tab, Arrows) are not available on mobile keyboards
+- The AppShell header and sidebar waste precious screen real estate
+- No mechanism exists to handle virtual keyboard appearance/disappearance
+
+## Goals / Non-Goals
+
+**Goals:**
+- Make terminal sessions practical on mobile devices for occasional use
+- Provide access to special terminal keys without external keyboard
+- Maximize terminal screen real estate on mobile
+- Handle virtual keyboard gracefully
+- Support full terminal functionality (vim, tmux, etc.)
+
+**Non-Goals:**
+- Native mobile app (stays web-based)
+- Command palette / quick commands (future enhancement)
+- Offline terminal access
+- Mobile-first redesign of the entire application (terminal pages only)
+- Gesture-based text selection (use xterm.js native)
+
+## Decisions
+
+### Decision: Collapsible AppShell, Not Hidden
+
+**Choice**: Collapse AppShell to a minimal auto-hiding header instead of completely hiding it.
+
+**Rationale**: Users need a way to navigate back and access the menu. Complete removal would trap users in the terminal page.
+
+**Alternative considered**: Fullscreen mode with swipe-from-edge to reveal nav. Rejected because it's not discoverable and conflicts with browser gestures.
+
+### Decision: Auto-Hide Header and Keys Strip
+
+**Choice**: Both header and special keys strip auto-hide after 3 seconds of inactivity.
+
+**Rationale**: Maximizes terminal space while keeping controls accessible. Tap to toggle visibility is intuitive.
+
+**Alternative considered**: Always-visible fixed bars. Rejected because they permanently reduce terminal height by ~20%.
+
+### Decision: Hidden Input for Keyboard Management
+
+**Choice**: Use a hidden/transparent input element to maintain virtual keyboard focus.
+
+**Rationale**: xterm.js handles keyboard input directly, but mobile browsers need a focused input to show the virtual keyboard. A hidden input bridges this gap without interfering with xterm.js rendering.
+
+**Alternative considered**: Custom on-screen keyboard. Rejected because native virtual keyboards provide better UX (autocorrect, swipe typing, user's preferred keyboard layout).
+
+### Decision: Special Keys as Bottom Strip, Not Floating
+
+**Choice**: Fixed bottom strip that slides up, not floating action buttons.
+
+**Rationale**: Bottom placement is thumb-friendly and doesn't obscure terminal content. Fixed position makes it always accessible.
+
+**Alternative considered**: Floating action button that expands to a menu. Rejected because it requires two taps for every special key.
+
+### Decision: Debounced Resize (250ms)
+
+**Choice**: 250ms debounce for resize events.
+
+**Rationale**: Mobile keyboard animation is slow and produces multiple resize events. 250ms catches the final state without being sluggish.
+
+**Alternative considered**: No debounce (immediate resize). Rejected because it causes excessive xterm.js refits and WebSocket resize messages.
+
+### Decision: No New Dependencies
+
+**Choice**: Implement using existing React, xterm.js, and browser APIs.
+
+**Rationale**: All required functionality (touch events, viewport API, clipboard) is available natively. Adding libraries increases bundle size for a feature used occasionally.
+
+**Alternative considered**: `react-use` hooks, `xterm-addon-webgl`. Rejected to keep bundle size down.
+
+## Risks / Trade-offs
+
+**[Risk] Visual Viewport API unreliability** → **Mitigation**: Implement fallback using `window.innerHeight` comparison and focus-based detection. Accept imperfect behavior on older browsers.
+
+**[Risk] xterm.js touch conflicts** → **Mitigation**: Use `touch-action: none` on terminal container. Let xterm.js handle its own touch events. Disable browser zoom to prevent pinch conflicts.
+
+**[Risk] WebSocket drops on network change/backgrounding** → **Mitigation**: Implement reconnect logic with exponential backoff. Show clear status to user. Document that mobile networks may cause disconnections.
+
+**[Risk] Clipboard API restrictions on mobile Safari** → **Mitigation**: Use both modern Clipboard API and `document.execCommand('copy')` fallback. Show user feedback on failure.
+
+**[Risk] Screen rotation causes layout flicker** → **Mitigation**: Debounced resize. CSS transitions on layout changes. Consider `orientation` lock prompt for landscape preference.
+
+**[Trade-off] Touch targets vs terminal density** → Larger touch targets mean fewer terminal cells visible. Compromise: 16px minimum font size provides readable text while keeping reasonable cell count.
+
+## Migration Plan
+
+No migration needed. This is a purely additive frontend change that doesn't affect data models, APIs, or existing desktop behavior. Desktop terminal experience remains unchanged.
+
+**Deployment:**
+1. Merge changes to dev branch
+2. Verify on actual mobile devices (iOS Safari, Android Chrome)
+3. Monitor for any desktop regressions
+
+**Rollback:** Revert frontend commit. No database or API changes involved.
+
+## Open Questions
+
+1. Should we implement a landscape orientation prompt? ("Rotate for better experience")
+2. Should font size preference sync across devices (via backend user config) or stay local?
+3. What's the maximum number of special keys to show in the primary strip before requiring "More"?
+4. Should the header show connection status, or is the terminal's own status dot sufficient?
diff --git a/openspec/changes/mobile-terminal-ux/proposal.md b/openspec/changes/mobile-terminal-ux/proposal.md
new file mode 100644
index 0000000..497c2d6
--- /dev/null
+++ b/openspec/changes/mobile-terminal-ux/proposal.md
@@ -0,0 +1,30 @@
+## Why
+
+Terminal sessions are currently desktop-optimized and become practically unusable on mobile devices due to virtual keyboard conflicts, lack of touch gestures, missing special keys, and poor screen utilization. Users occasionally need to access terminal sessions from mobile devices to check logs, run quick commands, or monitor running processes, but the current experience is frustrating.
+
+## What Changes
+
+- **Mobile terminal page layout**: Fullscreen terminal experience with collapsible AppShell chrome on mobile viewports
+- **Special keys toolbar**: Bottom-accessible strip with Esc, Tab, Ctrl, Alt, Arrow keys, and an expandable "More" panel with Home/End/PgUp/PgDn/Ctrl+C/etc
+- **Dynamic viewport handling**: Resize terminal container based on virtual keyboard presence using `visualViewport` API
+- **Touch gesture support**: Disable browser zoom, intercept touch events for terminal interaction
+- **Auto-hiding chrome**: Header and special keys strip auto-hide after inactivity, tap/swipe to reveal
+- **Orientation handling**: Debounced resize for screen rotation
+- **Font scaling**: Responsive font size based on viewport dimensions
+
+## Capabilities
+
+### New Capabilities
+- `mobile-terminal-ux`: Mobile-optimized terminal interface with special keys, dynamic sizing, and touch-friendly interactions
+
+### Modified Capabilities
+- `tool-terminal`: Add mobile-specific requirements for terminal resize, touch handling, and virtual keyboard awareness
+- `frontend-foundation`: Add mobile layout behavior for terminal pages (collapsible AppShell, fullscreen mode)
+
+## Impact
+
+- Frontend: New components (`MobileTerminalHeader`, `SpecialKeysStrip`, `useMobileViewport` hook), modifications to `terminal.tsx`, `terminal-page.tsx`, `app-shell.tsx`
+- Styles: New mobile terminal CSS, touch-action overrides
+- Dependencies: No new dependencies (uses existing xterm.js, React)
+- Browser support: Requires `visualViewport` API (modern browsers)
+- Breaking: None
diff --git a/openspec/changes/mobile-terminal-ux/specs/frontend-foundation/spec.md b/openspec/changes/mobile-terminal-ux/specs/frontend-foundation/spec.md
new file mode 100644
index 0000000..4df005d
--- /dev/null
+++ b/openspec/changes/mobile-terminal-ux/specs/frontend-foundation/spec.md
@@ -0,0 +1,23 @@
+## MODIFIED Requirements
+
+### Requirement: Layout Component
+
+The system SHALL provide a consistent application layout for authenticated screens across desktop and mobile sizes.
+
+#### Scenario: Application shell
+- **GIVEN** the frontend application
+- **THEN** a Layout component SHALL:
+ - Display a header with user info and logout
+ - Display sidebar navigation on desktop
+ - Show main content area
+ - Collapse sidebar into a mobile menu toggle on small viewports
+ - **AND** on mobile terminal pages, provide a minimal collapsible header instead of the full AppShell
+
+#### Scenario: Terminal page mobile layout
+- **GIVEN** a user on a terminal page on a mobile device
+- **WHEN** the page loads
+- **THEN** the full AppShell is replaced with a minimal header
+- **AND** the header contains: back button, menu toggle, instance name, close button
+- **AND** the header auto-hides after 3 seconds of inactivity
+- **AND** tapping the terminal area toggles header visibility
+- **AND** the sidebar navigation is accessible via the menu toggle
diff --git a/openspec/changes/mobile-terminal-ux/specs/mobile-terminal-ux/spec.md b/openspec/changes/mobile-terminal-ux/specs/mobile-terminal-ux/spec.md
new file mode 100644
index 0000000..b4b7823
--- /dev/null
+++ b/openspec/changes/mobile-terminal-ux/specs/mobile-terminal-ux/spec.md
@@ -0,0 +1,121 @@
+## ADDED Requirements
+
+### Requirement: Mobile Terminal Layout
+
+The system SHALL provide a fullscreen terminal experience on mobile devices.
+
+#### Scenario: Mobile terminal page
+- **WHEN** a user navigates to an instance terminal page on a mobile device (viewport width < 768px)
+- **THEN** the AppShell chrome is collapsed to a minimal header
+- **AND** the terminal occupies the full viewport below the header
+- **AND** the header auto-hides after 3 seconds of inactivity
+- **AND** tapping the terminal area toggles header visibility
+
+#### Scenario: Collapsed AppShell header
+- **WHEN** the terminal is in mobile mode
+- **THEN** the header displays:
+ - A back button
+ - A hamburger menu toggle (reveals navigation)
+ - The instance name
+ - A close button
+- **AND** the sidebar navigation is hidden by default
+
+### Requirement: Special Keys Toolbar
+
+The system SHALL provide access to special terminal keys on mobile devices.
+
+#### Scenario: Special keys strip
+- **WHEN** a user is on a mobile terminal
+- **THEN** a strip of special keys is available at the bottom of the screen
+- **AND** the strip contains: Esc, Tab, Ctrl, Alt, Up, Down, Left, Right
+- **AND** the strip auto-hides after 3 seconds of inactivity
+- **AND** swiping up from the bottom reveals the strip
+- **AND** tapping the terminal area hides the strip
+
+#### Scenario: Expanded special keys panel
+- **WHEN** a user taps the "More" button on the special keys strip
+- **THEN** an expanded panel appears with additional keys:
+ - Home, End, Page Up, Page Down
+ - Ctrl+C, Ctrl+D, Ctrl+Z
+ - F1 through F12
+- **AND** tapping outside the panel closes it
+
+#### Scenario: Sending special keys
+- **WHEN** a user taps a special key
+- **THEN** the corresponding escape sequence is sent via WebSocket
+- **AND** the key press is visually acknowledged (brief highlight)
+
+### Requirement: Virtual Keyboard Handling
+
+The system SHALL handle virtual keyboard appearance on mobile devices.
+
+#### Scenario: Keyboard-aware resizing
+- **WHEN** the virtual keyboard appears on a mobile device
+- **THEN** the terminal container resizes to fit the remaining viewport
+- **AND** the special keys strip remains visible above the virtual keyboard
+
+#### Scenario: Visual viewport detection
+- **WHEN** the browser supports the Visual Viewport API
+- **THEN** the system uses `visualViewport` events to detect keyboard height
+- **AND** falls back to `window.innerHeight` comparison if API is unavailable
+
+#### Scenario: Focus management
+- **WHEN** a user taps on the terminal area
+- **THEN** focus is maintained on a hidden input element to keep the virtual keyboard open
+- **AND** terminal input continues to work normally
+
+### Requirement: Touch Gestures
+
+The system SHALL support touch interactions in the terminal.
+
+#### Scenario: Disable browser zoom
+- **WHEN** a user is on a mobile terminal page
+- **THEN** browser zoom is disabled via `meta viewport` tag with `user-scalable=no`
+- **AND** pinch gestures do not zoom the page
+
+#### Scenario: Terminal scroll
+- **WHEN** a user performs a two-finger swipe in the terminal
+- **THEN** the terminal scrollback buffer scrolls
+- **AND** the browser page does not scroll
+
+#### Scenario: Text selection
+- **WHEN** a user long-presses in the terminal
+- **THEN** xterm.js native selection behavior is used
+- **AND** browser native text selection UI is suppressed
+
+### Requirement: Screen Orientation
+
+The system SHALL handle device orientation changes gracefully.
+
+#### Scenario: Orientation change
+- **WHEN** a user rotates their device
+- **THEN** the terminal recalculates dimensions after a 250ms debounce
+- **AND** the new dimensions are sent to the backend via WebSocket resize message
+
+### Requirement: Copy and Paste
+
+The system SHALL provide copy and paste functionality on mobile devices.
+
+#### Scenario: Copy button
+- **WHEN** a user selects text in the terminal
+- **THEN** a "Copy" button appears in the header
+- **AND** tapping it copies the selection to clipboard
+
+#### Scenario: Paste button
+- **WHEN** a user taps a "Paste" button in the header or special keys panel
+- **THEN** the system attempts to read from the clipboard
+- **AND** pastes the content into the terminal
+
+### Requirement: Font Scaling
+
+The system SHALL provide readable font sizes on mobile devices.
+
+#### Scenario: Mobile font size
+- **WHEN** the terminal is displayed on a mobile device
+- **THEN** the font size is at least 16px
+- **AND** the font size scales proportionally with viewport width (min 16px, max 24px)
+
+#### Scenario: Font size preference
+- **WHEN** a user changes the font size
+- **THEN** the preference is persisted in localStorage
+- **AND** applied on subsequent terminal sessions
diff --git a/openspec/changes/mobile-terminal-ux/specs/tool-terminal/spec.md b/openspec/changes/mobile-terminal-ux/specs/tool-terminal/spec.md
new file mode 100644
index 0000000..92736e6
--- /dev/null
+++ b/openspec/changes/mobile-terminal-ux/specs/tool-terminal/spec.md
@@ -0,0 +1,123 @@
+## MODIFIED Requirements
+
+### Requirement: Terminal Resize
+
+The system SHALL support terminal resize events.
+
+#### Scenario: Resize terminal
+- **GIVEN** an active terminal session
+- **WHEN** the browser window is resized
+- **THEN** the terminal dimensions (COLS, ROWS) are updated
+- **AND** the shell receives the new size
+- **AND** on mobile devices, the resize is debounced by 250ms
+
+#### Scenario: Mobile keyboard resize
+- **GIVEN** an active terminal session on a mobile device
+- **WHEN** the virtual keyboard appears or disappears
+- **THEN** the terminal container height adjusts to fit the visible viewport
+- **AND** the terminal is refitted with new dimensions
+
+### Requirement: WebSocket Terminal
+
+The system SHALL provide terminal sessions via WebSocket.
+
+#### Scenario: Mobile reconnection
+- **GIVEN** a terminal session on a mobile device
+- **WHEN** the WebSocket disconnects due to network change or backgrounding
+- **THEN** the terminal shows a "Reconnecting..." status
+- **AND** attempts to reconnect automatically
+- **AND** if reconnection fails after 3 attempts, shows an error with a manual reconnect option
+
+## ADDED Requirements
+
+### Requirement: Mobile Terminal Layout
+
+The system SHALL provide a fullscreen terminal experience on mobile devices.
+
+#### Scenario: Mobile terminal page
+- **WHEN** a user navigates to an instance terminal page on a mobile device (viewport width < 768px)
+- **THEN** the AppShell chrome is collapsed to a minimal header
+- **AND** the terminal occupies the full viewport below the header
+- **AND** the header auto-hides after 3 seconds of inactivity
+- **AND** tapping the terminal area toggles header visibility
+
+#### Scenario: Collapsed AppShell header
+- **WHEN** the terminal is in mobile mode
+- **THEN** the header displays:
+ - A back button
+ - A hamburger menu toggle (reveals navigation)
+ - The instance name
+ - A close button
+- **AND** the sidebar navigation is hidden by default
+
+### Requirement: Special Keys Toolbar
+
+The system SHALL provide access to special terminal keys on mobile devices.
+
+#### Scenario: Special keys strip
+- **WHEN** a user is on a mobile terminal
+- **THEN** a strip of special keys is available at the bottom of the screen
+- **AND** the strip contains: Esc, Tab, Ctrl, Alt, Up, Down, Left, Right
+- **AND** the strip auto-hides after 3 seconds of inactivity
+- **AND** swiping up from the bottom reveals the strip
+- **AND** tapping the terminal area hides the strip
+
+#### Scenario: Expanded special keys panel
+- **WHEN** a user taps the "More" button on the special keys strip
+- **THEN** an expanded panel appears with additional keys:
+ - Home, End, Page Up, Page Down
+ - Ctrl+C, Ctrl+D, Ctrl+Z
+ - F1 through F12
+- **AND** tapping outside the panel closes it
+
+#### Scenario: Sending special keys
+- **WHEN** a user taps a special key
+- **THEN** the corresponding escape sequence is sent via WebSocket
+- **AND** the key press is visually acknowledged (brief highlight)
+
+### Requirement: Touch Gestures
+
+The system SHALL support touch interactions in the terminal.
+
+#### Scenario: Disable browser zoom
+- **WHEN** a user is on a mobile terminal page
+- **THEN** browser zoom is disabled via `meta viewport` tag with `user-scalable=no`
+- **AND** pinch gestures do not zoom the page
+
+#### Scenario: Terminal scroll
+- **WHEN** a user performs a two-finger swipe in the terminal
+- **THEN** the terminal scrollback buffer scrolls
+- **AND** the browser page does not scroll
+
+#### Scenario: Text selection
+- **WHEN** a user long-presses in the terminal
+- **THEN** xterm.js native selection behavior is used
+- **AND** browser native text selection UI is suppressed
+
+### Requirement: Copy and Paste
+
+The system SHALL provide copy and paste functionality on mobile devices.
+
+#### Scenario: Copy button
+- **WHEN** a user selects text in the terminal
+- **THEN** a "Copy" button appears in the header
+- **AND** tapping it copies the selection to clipboard
+
+#### Scenario: Paste button
+- **WHEN** a user taps a "Paste" button in the header or special keys panel
+- **THEN** the system attempts to read from the clipboard
+- **AND** pastes the content into the terminal
+
+### Requirement: Font Scaling
+
+The system SHALL provide readable font sizes on mobile devices.
+
+#### Scenario: Mobile font size
+- **WHEN** the terminal is displayed on a mobile device
+- **THEN** the font size is at least 16px
+- **AND** the font size scales proportionally with viewport width (min 16px, max 24px)
+
+#### Scenario: Font size preference
+- **WHEN** a user changes the font size
+- **THEN** the preference is persisted in localStorage
+- **AND** applied on subsequent terminal sessions
diff --git a/openspec/changes/mobile-terminal-ux/tasks.md b/openspec/changes/mobile-terminal-ux/tasks.md
new file mode 100644
index 0000000..e02c647
--- /dev/null
+++ b/openspec/changes/mobile-terminal-ux/tasks.md
@@ -0,0 +1,57 @@
+## 1. Mobile Detection and Hooks
+
+- [x] 1.1 Create `useMobileViewport` hook for detecting mobile viewport (< 768px)
+- [x] 1.2 Create `useVirtualKeyboard` hook using Visual Viewport API with fallback
+- [x] 1.3 Create `useAutoHide` hook for managing auto-hide visibility with tap/swipe detection
+- [x] 1.4 Create `useSpecialKeys` hook for mapping special keys to escape sequences
+
+## 2. Mobile Terminal Components
+
+- [x] 2.1 Create `MobileTerminalHeader` component with back button, menu toggle, instance name, close button
+- [x] 2.2 Create `SpecialKeysStrip` component with primary keys (Esc, Tab, Ctrl, Alt, Arrows)
+- [x] 2.3 Create `SpecialKeysPanel` expanded component with Home/End/PgUp/PgDn/Ctrl combos/F-keys
+- [x] 2.4 Create `MobileTerminalWrapper` component that composes header, terminal, and keys strip
+- [x] 2.5 Add hidden input element for maintaining virtual keyboard focus
+
+## 3. Terminal Component Modifications
+
+- [x] 3.1 Update `TerminalComponent` to accept mobile mode prop and adjust font size
+- [x] 3.2 Add dynamic font scaling based on viewport width (16px min, 24px max)
+- [x] 3.3 Add localStorage persistence for font size preference
+- [x] 3.4 Implement debounced resize handler (250ms) for orientation changes
+- [x] 3.5 Add touch-action: none and disable browser zoom on mobile
+- [x] 3.6 Add copy/paste buttons to terminal header for mobile
+
+## 4. AppShell and Page Integration
+
+- [x] 4.1 Update `AppShell` to detect terminal routes and render minimal header on mobile
+- [x] 4.2 Update `TerminalPage` to use `MobileTerminalWrapper` when on mobile viewport
+- [x] 4.3 Add CSS transitions for header show/hide animations
+- [x] 4.4 Ensure desktop terminal experience is unchanged
+
+## 5. WebSocket and Reconnection
+
+- [x] 5.1 Implement WebSocket reconnection with exponential backoff (max 3 attempts)
+- [x] 5.2 Add "Reconnecting..." status indicator in terminal header
+- [x] 5.3 Add manual reconnect button on connection failure
+- [x] 5.4 Use Visibility API to reconnect when app returns from background
+
+## 6. Styling
+
+- [x] 6.1 Add mobile terminal CSS variables and layout styles
+- [x] 6.2 Style special keys strip with touch-friendly targets (min 44px height)
+- [x] 6.3 Style expanded keys panel as bottom sheet
+- [x] 6.4 Add dark theme support for mobile terminal chrome
+- [x] 6.5 Ensure proper z-index layering (terminal content above keys strip above keyboard)
+
+## 7. Testing and Verification
+
+- [x] 7.1 Run `npm run typecheck` and fix errors
+- [x] 7.2 Run `npm run lint` and fix warnings
+- [x] 7.3 Run `npm run build` successfully
+- [ ] 7.4 Test on actual mobile device (iOS Safari)
+- [ ] 7.5 Test on actual mobile device (Android Chrome)
+- [x] 7.6 Verify desktop terminal is unchanged
+- [ ] 7.7 Test screen rotation handling
+- [ ] 7.8 Test virtual keyboard appearance/disappearance
+- [ ] 7.9 Verify copy/paste functionality