/**
 * Socratic Platform - Touch & Gesture Optimization Architecture
 * Provides fine-grained touch-action boundaries, overscroll protection,
 * hardware acceleration layers, and safe-area insets for MAUI Blazor Hybrid & Web.
 */

/* ─── 1. Global Viewport & Touch Protection ─────────────────── */
html, body {
    /* Prevent rubber-banding / pull-to-refresh overscroll bounce */
    overscroll-behavior-x: none;
    overscroll-behavior-y: none;
    
    /* Eliminate default gray tap highlight on mobile WebKit/Blink */
    -webkit-tap-highlight-color: transparent;
    
    /* Disable accidental system callout on long press (iOS) */
    -webkit-touch-callout: none;
    
    /* Prevent unwanted text selection during gestures */
    -webkit-user-select: none;
    user-select: none;
}

/* Allow text selection specifically for editable inputs and reading containers */
input, textarea, [contenteditable="true"], .selectable-text {
    -webkit-user-select: text;
    user-select: text;
    -webkit-touch-callout: default;
}

/* ─── 2. Touch Action Primitives ────────────────────────────── */

/* 
 * touch-action: pan-y
 * Essential for horizontal swipers, tabs, and carousels.
 * Allows the user to freely scroll the page vertically without gesture hijacking,
 * while allowing horizontal swipes to be captured by component handlers.
 */
.touch-pan-y,
[data-gesture="swipe-horizontal"],
.swipe-container-x {
    touch-action: pan-y !important;
}

/* 
 * touch-action: pan-x
 * For vertical nested lists inside horizontally swipeable cards.
 */
.touch-pan-x,
[data-gesture="swipe-vertical"],
.swipe-container-y {
    touch-action: pan-x !important;
}

/* 
 * touch-action: none
 * For custom interactive canvases, drag-to-reorder, signature pads, and sliders.
 * Completely disables browser-level scrolling/pinch gesture handling.
 */
.touch-none,
[data-gesture="interactive-canvas"],
.drag-handle {
    touch-action: none !important;
}

/* 
 * touch-action: manipulation
 * Disables the 300ms double-tap-to-zoom delay on buttons and links.
 */
.touch-manipulation,
button,
a,
md-filled-button,
md-outlined-button,
md-text-button,
md-elevated-button,
md-icon-button,
.interactive-action {
    touch-action: manipulation;
}

/* ─── 3. Smooth Touch Scroll Containers ─────────────────────── */

.touch-scroll-x {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    touch-action: pan-y;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.touch-scroll-x::-webkit-scrollbar {
    display: none;
}

.touch-scroll-y {
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    touch-action: pan-x;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.touch-scroll-y::-webkit-scrollbar {
    display: none;
}

/* ─── 4. Hardware Acceleration & Compositor Layers ──────────── */

/* Promotes animated elements to a dedicated GPU layer (60/120 FPS) */
.gpu-layer,
.swipe-card,
.drawer-panel,
.md-drawer-backdrop {
    transform: translate3d(0, 0, 0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    perspective: 1000px;
    will-change: transform, opacity;
}

/* ─── 5. Safe Area Insets Protection (Notch, Home Pill) ─────── */

.safe-area-top {
    padding-top: env(safe-area-inset-top, 0px);
}

.safe-area-bottom {
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.safe-area-left {
    padding-left: env(safe-area-inset-left, 0px);
}

.safe-area-right {
    padding-right: env(safe-area-inset-right, 0px);
}

.safe-area-all {
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
}

/* Edge swipe guard: 16px safe buffer to prevent triggering system back gestures */
.edge-swipe-guard-left {
    margin-left: max(16px, env(safe-area-inset-left, 0px));
}

.edge-swipe-guard-right {
    margin-right: max(16px, env(safe-area-inset-right, 0px));
}
