/* ============================================================
 * KevinOS · 触屏适配（手机 / 手表 / 平板）
 * 依据 <html data-device="phone|tablet|watch|desktop" data-touch="on|off">
 * 设备型号仅在 JS 内部识别（K.device.model），界面不展示。
 * ============================================================ */

/* ---------- 通用触屏优化 ---------- */
html[data-touch="on"] {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}
html[data-touch="on"] body { touch-action: manipulation; }
html[data-touch="on"] * { -webkit-user-select: none; user-select: none; }
html[data-touch="on"] input,
html[data-touch="on"] textarea,
html[data-touch="on"] [contenteditable="true"],
html[data-touch="on"] .selectable { -webkit-user-select: text; user-select: text; }

/* 触屏设备不需要 hover 悬浮态，避免"粘滞"效果 */
@media (hover: none) {
  .desk-icon:hover, .dock-app:hover .app-ico, .start-app:hover,
  .lp-app:hover .app-ico, .ac-toggle:hover, .btn:hover,
  .mb-st:hover, .dock-item:hover { transform: none; }
}

/* 触屏放大点击热区 */
html[data-touch="on"] .win-btn { width: 40px; height: 36px; }
html[data-touch="on"] .mb-st { min-width: 38px; height: 28px; }
html[data-touch="on"] .dock-item,
html[data-touch="on"] .dock-app { min-width: 56px; min-height: 60px; }
html[data-touch="on"] .ctx-item { padding: 12px 13px; }
html[data-touch="on"] .ctx-item .ico,
html[data-touch="on"] .ctx-item .ico svg { width: 18px; height: 18px; }

/* 触屏隐藏缩放手柄（改用最大化/全屏），保留拖动 */
html[data-touch="on"] .rs { display: none; }

/* 窗口标题栏 / 缩放手柄：禁用浏览器手势，保证拖拽不被滚动打断 */
.win-titlebar { touch-action: none; }
.rs { touch-action: none; }

/* 触屏：可点击元素禁用双击缩放，保证响应即时 */
html[data-touch="on"] .dock-item,
html[data-touch="on"] .dock-app,
html[data-touch="on"] .mb-st,
html[data-touch="on"] .start-app,
html[data-touch="on"] .lp-app,
html[data-touch="on"] .desk-icon,
html[data-touch="on"] .ctx-item,
html[data-touch="on"] .ac-toggle,
html[data-touch="on"] .start-foot-btn { touch-action: manipulation; }

/* 触屏：桌面图标允许长按选中，滚动由 touch-action 控制 */
html[data-touch="on"] .desktop-icons { touch-action: pan-y; }

/* 触屏：窗口标题栏高度加大，便于手指拖动 */
html[data-touch="on"] .win-titlebar { height: 48px; padding-top: 2px; }

/* 触屏：按钮最小点击尺寸 44px（WCAG 建议） */
html[data-touch="on"] .btn,
html[data-touch="on"] .os-dialog .btn { min-height: 44px; padding: 0 18px; }

/* 触屏：计算器按键最小高度，便于点击 */
html[data-touch="on"] .calc-key { min-height: 52px; font-size: var(--fs-20); touch-action: manipulation; }

/* 触屏：终端点击区域聚焦输入框（已有 click 监听，此处保证可点击） */
html[data-touch="on"] .term { cursor: text; }
html[data-touch="on"] .term-input { font-size: var(--fs-16); } /* 避免 iOS 聚焦时自动缩放 */

/* 触屏：Office 等应用的功能区按钮加大点击区域 */
html[data-touch="on"] .of-rbtn { min-height: 48px; padding: 4px 10px; }
html[data-touch="on"] .of-tab { height: 38px; }

/* 触屏：防止文本选择干扰拖拽，但允许输入框编辑 */
html[data-touch="on"] .win-body { -webkit-user-select: none; user-select: none; }
html[data-touch="on"] .win-body input,
html[data-touch="on"] .win-body textarea,
html[data-touch="on"] .win-body [contenteditable="true"] { -webkit-user-select: text; user-select: text; }

/* ============================================================
 * 手机
 * ============================================================ */
html[data-device="phone"] .dock {
  left: 6px; right: 6px; bottom: 6px; width: auto;
  transform: none; animation: none;
  height: 60px; padding: 0 var(--space-2); gap: var(--space-2); border-radius: var(--radius-lg);
}
html[data-device="phone"] .mb-clock-date { display: none; }

html[data-device="phone"] .start-menu,
html[data-device="phone"] .action-center,
html[data-device="phone"] .wifi-panel {
  left: 6px; right: 6px; bottom: 74px; width: auto;
  transform: translateY(14px) scale(.98);
  max-height: calc(100vh - 104px);
}
html[data-device="phone"] .start-menu.open,
html[data-device="phone"] .action-center.open { transform: none; }

html[data-device="phone"] .desktop-icons {
  inset: 40px 8px 74px 8px;
  grid-auto-columns: 84px;
  grid-template-rows: repeat(auto-fill, 92px);
  gap: 4px;
}
html[data-device="phone"] .desk-icon { width: 84px; height: 92px; }

/* 手机窗口：全屏铺满（除菜单栏与 Dock） */
html[data-device="phone"] .window {
  left: 0 !important; top: 28px !important;
  width: 100% !important; height: calc(100% - 96px) !important;
  min-width: 0; min-height: 0;
  border-radius: 0; border-left: none; border-right: none;
}
html[data-device="phone"] .win-titlebar { height: var(--h-titlebar); padding-left: var(--space-4); }
html[data-device="phone"] .win-body > * { min-width: 0; }

/* 手机：隐藏桌面小组件避免拥挤 */
html[data-device="phone"] .widgets-layer { display: none; }

/* 手机启动台：4 列 */
html[data-device="phone"] .lp-page { grid-template-columns: repeat(4, 1fr); grid-auto-rows: 104px; }
html[data-device="phone"] .lp-app { width: 84px; }
html[data-device="phone"] .lp-app .app-ico { width: 58px; height: 58px; border-radius: 22%; }
html[data-device="phone"] .lp-app .app-ico svg { width: 52%; height: 52%; }
html[data-device="phone"] .lp-inner { padding: var(--space-6) var(--space-3) var(--space-5); }
html[data-device="phone"] .lp-search-wrap { width: 86vw; height: 42px; }

/* 手机对话框 */
html[data-device="phone"] .os-dialog { width: calc(100vw - 28px); }

/* 手机端应用内部横向元素更紧凑 */
html[data-device="phone"] .app-col,
html[data-device="phone"] .app-row { font-size: var(--fs-13); }

/* ============================================================
 * 平板
 * ============================================================ */
html[data-device="tablet"] .dock {
  left: 10px; right: 10px; width: auto; transform: none; animation: none;
}
html[data-device="tablet"] .start-menu,
html[data-device="tablet"] .action-center { max-height: calc(100vh - 120px); }
html[data-device="tablet"] .lp-page { grid-template-columns: repeat(6, 1fr); }
html[data-device="tablet"] .window { border-radius: var(--radius); }

/* ============================================================
 * 手表（极小屏）
 * ============================================================ */
html[data-device="watch"] .dock {
  left: 4px; right: 4px; bottom: 4px; width: auto;
  transform: none; animation: none;
  height: 50px; padding: 0 var(--space-1); gap: var(--space-1); border-radius: var(--radius-md);
}
html[data-device="watch"] .mb-clock-date,
html[data-device="watch"] .widgets-layer { display: none; }
html[data-device="watch"] .clock-time { font-size: var(--fs-11); }

html[data-device="watch"] .start-menu,
html[data-device="watch"] .action-center,
html[data-device="watch"] .wifi-panel {
  left: 4px; right: 4px; bottom: 62px; width: auto;
  max-height: calc(100vh - 96px);
  transform: translateY(10px) scale(.98);
}
html[data-device="watch"] .start-menu.open,
html[data-device="watch"] .action-center.open { transform: none; }

/* 手表窗口：单列全屏 */
html[data-device="watch"] .window {
  left: 0 !important; top: 28px !important;
  width: 100% !important; height: calc(100% - 84px) !important;
  min-width: 0; min-height: 0;
  border-radius: 0; border: none;
}
html[data-device="watch"] .win-titlebar { height: var(--h-titlebar); padding-left: var(--space-3); }
html[data-device="watch"] .win-title { font-size: var(--fs-12); }
html[data-device="watch"] .traffic { width: 10px; height: 10px; }

/* 手表启动台：3 列大图标，单屏滚动 */
html[data-device="watch"] .lp-inner { padding: 12px 6px 10px; }
html[data-device="watch"] .lp-search-wrap { width: 92vw; height: 40px; }
html[data-device="watch"] .lp-page { grid-template-columns: repeat(3, 1fr); grid-auto-rows: 88px; }
html[data-device="watch"] .lp-app { width: 74px; }
html[data-device="watch"] .lp-app .app-ico { width: 50px; height: 50px; border-radius: var(--radius-md); }
html[data-device="watch"] .lp-app .app-ico svg { width: 52%; height: 52%; }
html[data-device="watch"] .lp-app .lp-name { font-size: var(--fs-11); }
html[data-device="watch"] .lp-pages { margin-top: 8px; }

html[data-device="watch"] .desktop-icons {
  inset: 6px 6px 62px 6px;
  grid-auto-columns: 68px; grid-template-rows: repeat(auto-fill, 78px);
}
html[data-device="watch"] .desk-icon { width: 68px; height: 78px; padding: 6px 2px; }
html[data-device="watch"] .desk-icon .di-label { font-size: var(--fs-11); }
html[data-device="watch"] .os-dialog { width: calc(100vw - 20px); padding: 16px; }
html[data-device="watch"] .toast-stack { width: calc(100vw - 16px); right: 8px; bottom: 60px; }

/* 兜底：极窄视口（不足 380px）统一按手机处理 */
@media (max-width: 380px) {
  html:not([data-device="watch"]) .dock { left: 6px; right: 6px; width: auto; transform: none; animation: none; }
  html:not([data-device="watch"]) .window { left: 0 !important; top: 28px !important; width: 100% !important; height: calc(100% - 96px) !important; min-width: 0; min-height: 0; border-radius: 0; }
  html:not([data-device="watch"]) .lp-page { grid-template-columns: repeat(4, 1fr); }
}