/* DeskMGR: phone and tablet layer.
   Everything here hangs off body.mobile (small screen) or body.coarse (touch pointer), so the
   desktop build is untouched. Loaded last, so it wins on equal specificity. */

/* ---------- touch behaviour, applies to any touch device ---------- */

body.coarse {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;                /* kills the double tap zoom delay */
}
html, body { overscroll-behavior: none; }
body.coarse .headerbar, body.coarse .resizer, body.coarse .dicon { touch-action: none; }
body.coarse .scroll, body.coarse .logview, body.coarse .sidebar,
body.coarse .term, body.coarse .notif-list { -webkit-overflow-scrolling: touch; }

/* hover only affordances have nowhere to go on a touch screen */
@media (hover: none) {
  .row .acts { opacity: 1; }
  .wall-rm { opacity: 1; }
  .tooltip { display: none !important; }
}

/* ---------- the mobile shell ---------- */

body.mobile {
  --bar-h: 40px;
  --mb-h: 58px;
  --hb-h: 50px;
  --radius: 0px;
  /* the skins write these inline, so the phone layout has to shout */
  --pad-top: calc(40px + env(safe-area-inset-top)) !important;
  --pad-bottom: calc(58px + env(safe-area-inset-bottom)) !important;
  --pad-left: 0px !important;
  --pad-right: 0px !important;
}

/* one chrome for every skin: the top bar plus the bottom nav */
body.mobile #topbar {
  display: flex !important;
  height: calc(var(--bar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 8px 0;
  font-size: 14px;
}
body.mobile #dash, body.mobile #taskbar, body.mobile #snapHint { display: none !important; }
/* the window header already names the app, and this collided with the centred clock */
body.mobile #appmenu { display: none !important; }
body.mobile #topbar .topbar-item { height: 32px; padding: 0 11px; }
body.mobile #clock { font-size: 13px; }
body.mobile #clockDate { display: none; }
/* the launcher belongs to the desktop, not to the overview */
body.mobile.overview #desktop-icons { display: none !important; }
body.mobile.appgrid #windows { display: none; }
body.mobile.appgrid #wallpaper-dim { background: rgba(0,0,0,.58); }
body.mobile .status-load { min-width: 30px; }

/* The shell theme still owns the look on a phone. Every taskbar skin declares --tb-* and
   --start-* variables, so the bar picks up XP blue, the 2000 grey, the Win11 mica and so on;
   GNOME, Ubuntu and macOS leave them unset and fall back to the translucent default. */
#mobilebar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 520;
  height: calc(var(--mb-h, 58px) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: none; align-items: stretch;
  background: var(--tb-bg, rgba(0,0,0,.62));
  color: var(--tb-fg, #fff);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--tb-line, rgba(255,255,255,.12));
}
body.mobile[data-bar="taskbar"] #topbar {
  background: var(--tb-bg, rgba(0,0,0,.55));
  color: var(--tb-fg, #fff);
  border-bottom: 1px solid var(--tb-line, transparent);
}
body.mobile[data-bar="taskbar"] .topbar-item:hover,
body.mobile[data-bar="taskbar"] .topbar-item.on { background: var(--task-hover, rgba(255,255,255,.18)); }
/* a Windows skin has no Activities button, the bottom bar carries Start instead */
body.mobile[data-bar="taskbar"] #activities { display: none !important; }
#mobilebar .start-glyph { width: 20px; height: 20px; }
body.mobile #mobilebar { display: flex; }
.mb-btn {
  flex: 1; border: 0; background: transparent; color: inherit; opacity: .84;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  cursor: pointer; font-size: 10.5px; font-weight: 600; letter-spacing: .02em;
  transition: color .12s, background .12s;
}
.mb-btn:active { background: var(--task-hover, rgba(255,255,255,.14)); }
.mb-btn.on { opacity: 1; }
.mb-btn.on .mb-ico { background: var(--task-on, rgba(255,255,255,.2)); }
#mobilebar[data-bar="taskbar"] [data-m="apps"] .mb-ico { background: var(--start-bg, transparent); }
#mobilebar[data-bar="taskbar"] [data-m="apps"]:active .mb-ico { background: var(--start-bg-hover, rgba(255,255,255,.2)); }
.mb-ico {
  position: relative; width: 42px; height: 26px; border-radius: 9px;
  display: grid; place-items: center; transition: background .12s;
}
.mb-ico svg { width: 18px; height: 18px; fill: currentColor; }
.mb-badge {
  position: absolute; top: -3px; right: 4px; min-width: 15px; height: 15px; padding: 0 4px;
  border-radius: 8px; background: var(--accent); color: var(--accent-fg);
  font-size: 10px; line-height: 15px; text-align: center; font-weight: 700;
}

/* ---------- windows go full screen ---------- */

body.mobile .win {
  min-width: 0; min-height: 0;
  border-radius: 0; border: 0;
  box-shadow: none;
}
body.mobile .win .resizer { display: none; }
body.mobile .headerbar { padding: 0 6px 0 8px; gap: 6px; cursor: default; }
body.mobile .headerbar .hb-icon { width: 24px; height: 24px; }
body.mobile .hb-title { font-size: 15px; }
body.mobile .hb-title small { font-size: 11px; }
body.mobile .wbtn { width: 34px; height: 34px; }
body.mobile .wbtn svg { width: 12px; height: 12px; }
body.mobile .wbtn.maxb { display: none; }         /* already full screen */
/* the macOS traffic lights need a real tap target, and the centred title needs the room back */
body.mobile[data-skin="macos"] .wbtn { width: 26px; height: 26px; }
body.mobile[data-skin="macos"] .wbtn svg { width: 11px; height: 11px; }
body.mobile[data-skin="macos"] .hb-title { position: static; left: auto; right: auto; text-align: left; }
body.mobile .win.minimized { transform: scale(.9) translateY(30vh); }
body.mobile .win:not(.active) .headerbar { background: var(--hb-bg); color: var(--win-fg); }

/* the desktop is a launcher: bigger icons, no drag, one tap opens */
body.mobile #desktop-icons { padding: 6px 4px; }
body.mobile .dicon { padding: 8px 2px; }
body.mobile .dicon-label { font-size: 11.5px; }

/* ---------- sidebars become drawers ---------- */

body.mobile .win .app { position: relative; }
body.mobile .win .app > .sidebar {
  position: absolute; z-index: 22; top: 0; bottom: 0; left: 0;
  width: min(80%, 300px); flex: none;
  background: color-mix(in srgb, var(--win-bg) 30%, var(--hb-bg));
  border-right: 1px solid var(--line-strong);
  box-shadow: 8px 0 26px rgba(0,0,0,.4);
  transform: translateX(-102%);
  transition: transform .22s var(--ease);
  padding: 10px;
}
body.mobile .win.drawer-open .app > .sidebar { transform: none; }
.drawer-back { display: none; }
body.mobile .win.has-drawer .drawer-back {
  display: block; position: absolute; inset: 0; z-index: 21;
  background: rgba(0,0,0,.45); opacity: 0; pointer-events: none;
  transition: opacity .2s var(--ease);
}
body.mobile .win.drawer-open .drawer-back { opacity: 1; pointer-events: auto; }
.drawer-btn { display: none; }
body.mobile .win.has-drawer .drawer-btn { display: grid; }
body.mobile .side-item { padding: 12px 12px; font-size: 14px; border-radius: 10px; }
body.mobile .sidebar h4 { margin: 14px 8px 6px; }

/* the containers detail pane covers the list instead of squeezing it */
body.mobile .win .details:not([hidden]) {
  position: absolute !important; inset: 0 !important; z-index: 18;
  width: auto !important; border-left: 0 !important;
  background: var(--win-bg) !important;
}

/* ---------- app content ---------- */

body.mobile .toolbar { padding: 8px 10px; gap: 6px; }
body.mobile .toolbar .search { flex: 1 1 100%; min-width: 0; order: -1; padding: 8px 12px; }
body.mobile .toolbar .grow { display: none; }
body.mobile .toolbar .btn { padding: 9px 13px; }
body.mobile .pad { padding: 10px; }

/* two lines: name and figures up top, then chips with the actions right aligned under them.
   `order` is what keeps the stat cell on line one, the source order puts it after the chips. */
body.mobile .row { padding: 11px 12px; gap: 8px; row-gap: 7px; flex-wrap: wrap; align-items: flex-start; }
body.mobile .row > .dot { order: 0; margin-top: 5px; }
body.mobile .row .main { order: 1; flex: 1 1 55%; }
body.mobile .row .cell-stat { order: 2; flex: none; line-height: 1.35; }
body.mobile .row > .chip, body.mobile .row > span:not(.dot):not(.main) { order: 2; flex: none; }
body.mobile .row .chips { order: 3; flex: 1 1 auto; align-items: center; }
body.mobile .row .acts { order: 4; opacity: 1; margin-left: auto; gap: 8px; }
body.mobile .row .title { font-size: 14px; }
body.mobile .row .sub { font-size: 11.5px; white-space: normal; }
body.mobile .row .acts .btn.icon.tiny { padding: 9px; }
body.mobile .list-head { display: none; }
body.mobile .col-net, body.mobile .col-pids { display: none !important; }

body.mobile .kv { grid-template-columns: 1fr !important; gap: 0; }
body.mobile .kv dt { padding: 8px 0 0; border-bottom: 0; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
body.mobile .kv dd { padding: 2px 0 8px; }

body.mobile .stat-grid { grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); }
body.mobile .cat-grid { grid-template-columns: 1fr; }
body.mobile .skin-grid { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); }
body.mobile .wall-grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
body.mobile .file-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
body.mobile .settings-row { flex-wrap: wrap; padding: 13px 12px; }
body.mobile .settings-row .main { flex: 1 1 100%; }
body.mobile .settings-row > .btn, body.mobile .settings-row > .seg,
body.mobile .settings-row > select, body.mobile .settings-row > .input { margin-left: auto; }
body.mobile .tabs { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
body.mobile .tabs::-webkit-scrollbar { display: none; }
body.mobile .tab { flex: none; padding: 9px 14px; }
body.mobile .seg button { padding: 8px 13px; }
body.mobile .chart { height: 96px; }

/* iOS zooms the page when a field under 16px takes focus */
body.mobile .input, body.mobile select.input, body.mobile textarea.input,
body.mobile .search input, body.mobile .lock-card input, body.mobile #ovSearch { font-size: 16px; }
body.mobile .input, body.mobile select.input { padding: 10px 12px; }
body.mobile .btn { padding: 9px 14px; }
body.mobile .btn.tiny { padding: 6px 10px; }
body.mobile .switch { width: 50px; height: 29px; }
body.mobile .switch i::after { width: 23px; height: 23px; }
body.mobile .switch input:checked + i::after { transform: translateX(21px); }

/* ---------- overview, menus, dialogs, toasts ---------- */

body.mobile .ov-search { top: 10px; left: 10px; right: 10px; transform: none; }
body.mobile .ov-search input { width: 100%; }
body.mobile .ov-results { top: 62px; left: 10px; right: 10px; width: auto; transform: none; max-height: 62vh; }
body.mobile .ov-grid { inset: 62px 6px 14px; padding: 4px; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); grid-auto-rows: 102px; gap: 6px; }
body.mobile .ov-hint { bottom: 12px; }
body.mobile .ov-app .app-ico { width: 46px; height: 46px; }

body.mobile .ctxmenu {
  left: 0 !important; right: 0 !important; top: auto !important; bottom: 0 !important;
  min-width: 0; width: 100%; border-radius: 16px 16px 0 0;
  padding: 8px 8px calc(10px + env(safe-area-inset-bottom));
  max-height: 72vh; overflow: auto;
  animation: sheetin .18s var(--ease);
  /* a scrolling box drops the backdrop blur on some engines, so do not depend on it */
  background: var(--win-bg);
}
@keyframes sheetin { from { transform: translateY(100%); } }
body.mobile .ctxmenu button { padding: 13px 12px; font-size: 15px; gap: 12px; }
body.mobile .ctxmenu button svg { width: 17px; height: 17px; }
body.mobile .ctxmenu .label { padding: 8px 12px 6px; font-size: 12px; }

/* ---------- the skin start menus, rebuilt as sheets ---------- */

body.mobile .sm:not(.sm-win8):not(.sm-launchpad) {
  left: 8px !important; right: 8px !important; width: auto !important;
  top: auto !important; height: auto !important;
  bottom: calc(var(--mb-h) + env(safe-area-inset-bottom) + 8px) !important;
  max-height: 68dvh; overflow: auto; border-radius: 10px;
}
body.mobile .sm-win8, body.mobile .sm-launchpad {
  inset: 0 !important; width: auto !important; height: auto !important;
  padding: calc(var(--bar-h) + env(safe-area-inset-top) + 14px) 14px
           calc(var(--mb-h) + env(safe-area-inset-bottom) + 14px);
  overflow: auto;
}
body.mobile .sm-item { padding: 11px 12px; font-size: 15px; }
body.mobile .sm-item .app-ico { width: 30px; height: 30px; }
body.mobile .sm-search { padding: 11px 12px; font-size: 16px; }
body.mobile .sm-body { max-height: none; }
/* every multi column era menu stacks */
body.mobile .xp-cols, body.mobile .w7-cols, body.mobile .w10-cols, body.mobile .mint-cols { flex-direction: column; }
body.mobile .xp-left, body.mobile .xp-right, body.mobile .w7-left, body.mobile .w7-right,
body.mobile .w10-list, body.mobile .w10-tiles, body.mobile .mint-side, body.mobile .mint-main {
  width: auto !important; max-width: none; flex: none;
}
body.mobile .w10-rail { flex-direction: row !important; width: auto !important; }
/* the 2000 and ME menu keeps its vertical banner, the item column just has to fill the sheet */
body.mobile .sm-classic .sm-body { flex: 1; }
body.mobile .w8-tiles, body.mobile .w10-tile-grid, body.mobile .lp-grid, body.mobile .w11-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px;
}
body.mobile .sm-tile { width: auto !important; height: 84px; }
body.mobile .lp-app .app-ico { width: 46px; height: 46px; }

body.mobile .modal-backdrop { align-items: flex-end; }
body.mobile .modal {
  width: 100% !important; max-width: 100%; border-radius: 16px 16px 0 0;
  max-height: 90dvh; padding-bottom: env(safe-area-inset-bottom);
  animation: sheetin .2s var(--ease);
}
body.mobile .modal-foot { position: sticky; bottom: 0; background: var(--win-bg); border-top: 1px solid var(--line); }

body.mobile .popover {
  left: 8px !important; right: 8px !important; transform: none !important;
  top: auto !important; bottom: calc(var(--mb-h) + env(safe-area-inset-bottom) + 8px);
  max-height: 70dvh; overflow: auto;
  background: var(--win-bg);      /* scrolling kills the backdrop blur, keep it readable */
}
body.mobile .pop-cols { flex-direction: column; }
body.mobile .pop-notif, body.mobile .pop-cal, body.mobile .sysmenu { width: auto; }
body.mobile .sys-item { padding: 13px 12px; font-size: 15px; }
body.mobile .sys-tiles .tile { padding: 13px 4px; }

body.mobile #toasts { top: auto; bottom: calc(var(--mb-h) + env(safe-area-inset-bottom) + 12px); left: 10px; right: 10px; transform: none; }
body.mobile .toast { width: 100%; max-width: none; }
body.mobile #toasts .toast { animation: none; }

/* ---------- sign in ---------- */

body.mobile #lock { gap: 20px; padding: 0 18px; justify-content: center; }
body.mobile .lock-time { font-size: clamp(46px, 16vw, 72px); }
body.mobile .lock-date { font-size: 15px; }
body.mobile .lock-card { width: 100%; max-width: 340px; padding: 22px 20px 20px; }
body.mobile .lock-avatar { width: 66px; height: 66px; }
body.mobile .lock-card input { padding: 12px 13px; }
body.mobile .lock-foot { bottom: calc(12px + env(safe-area-inset-bottom)); font-size: 11px; }
@media (max-height: 560px) {
  body.mobile .lock-clock { display: none; }
}

/* ---------- terminal ---------- */

.term-wrap { position: relative; }
.term-input {
  position: absolute; left: 0; top: 0; width: 2px; height: 2px;
  opacity: 0; border: 0; padding: 0; margin: 0; resize: none; z-index: 1;
  font-size: 16px; background: transparent; color: transparent; caret-color: transparent;
}
.term-keys { display: none; }
body.mobile .term { font-size: 12px; padding: 6px 8px; }
body.mobile .term-keys {
  display: flex; gap: 5px; padding: 7px 8px; overflow-x: auto; flex: none;
  border-top: 1px solid rgba(255,255,255,.09); background: #17171d;
  scrollbar-width: none;
}
body.mobile .term-keys::-webkit-scrollbar { display: none; }
.tkey {
  flex: none; min-width: 40px; height: 36px; padding: 0 10px;
  border: 1px solid rgba(255,255,255,.14); border-radius: 8px;
  background: rgba(255,255,255,.08); color: #ddd;
  font-family: var(--mono); font-size: 13px; cursor: pointer;
}
.tkey:active { background: rgba(255,255,255,.2); }
.tkey.on { background: var(--accent); border-color: transparent; color: var(--accent-fg); }
body.mobile .term-bar { display: none; }

/* ---------- small phones ---------- */

@media (max-width: 380px) {
  body.mobile .mb-label { display: none; }
  body.mobile #mobilebar { height: calc(48px + env(safe-area-inset-bottom)); }
  body.mobile { --mb-h: 48px; --pad-bottom: calc(48px + env(safe-area-inset-bottom)) !important; }
  body.mobile .hb-title { font-size: 14px; }
}

/* ---------- landscape phones: the chrome eats the screen ---------- */

@media (max-height: 460px) and (orientation: landscape) {
  body.mobile { --mb-h: 46px; --pad-bottom: calc(46px + env(safe-area-inset-bottom)) !important; }
  body.mobile #mobilebar { height: calc(46px + env(safe-area-inset-bottom)); }
  body.mobile .mb-label { display: none; }
  body.mobile .term-keys { padding: 4px 8px; }
  body.mobile .tkey { height: 30px; }
}
